2021-01-01 16:55:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// A legend box, which is shown on the chart.
|
|
|
|
#ifndef STATS_LEGEND_H
|
|
|
|
#define STATS_LEGEND_H
|
|
|
|
|
2021-01-12 14:20:05 +00:00
|
|
|
#include "chartitem.h"
|
2021-01-03 11:49:26 +00:00
|
|
|
|
2021-01-01 16:55:44 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2021-01-12 14:20:05 +00:00
|
|
|
#include <QFont>
|
2021-01-01 16:55:44 +00:00
|
|
|
|
2021-01-12 14:20:05 +00:00
|
|
|
class QFontMetrics;
|
2021-01-01 16:55:44 +00:00
|
|
|
|
2021-01-12 14:20:05 +00:00
|
|
|
class Legend : public ChartRectItem {
|
2021-01-01 16:55:44 +00:00
|
|
|
public:
|
2021-01-12 14:20:05 +00:00
|
|
|
Legend(StatsView &view, const std::vector<QString> &names);
|
2021-01-01 16:55:44 +00:00
|
|
|
void resize(); // called when the chart size changes.
|
|
|
|
private:
|
|
|
|
// Each entry is a text besides a rectangle showing the color
|
|
|
|
struct Entry {
|
2021-01-12 14:20:05 +00:00
|
|
|
QString name;
|
|
|
|
QBrush rectBrush;
|
2021-01-01 16:55:44 +00:00
|
|
|
QPointF pos;
|
|
|
|
double width;
|
2021-01-12 14:20:05 +00:00
|
|
|
Entry(const QString &name, int idx, int numBins, const QFontMetrics &fm);
|
2021-01-01 16:55:44 +00:00
|
|
|
};
|
|
|
|
int displayedItems;
|
|
|
|
double width;
|
|
|
|
double height;
|
2021-01-12 14:20:05 +00:00
|
|
|
QFont font;
|
2021-01-01 16:55:44 +00:00
|
|
|
int fontHeight;
|
|
|
|
std::vector<Entry> entries;
|
|
|
|
void hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|