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
|
|
|
class QFontMetrics;
|
2021-02-16 16:05:39 +00:00
|
|
|
class StatsTheme;
|
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.
|
2021-01-13 20:15:11 +00:00
|
|
|
void setPos(QPointF pos); // Attention: not virtual - always call on this class.
|
2021-01-01 16:55:44 +00:00
|
|
|
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-02-16 16:05:39 +00:00
|
|
|
Entry(const QString &name, int idx, int numBins, const QFontMetrics &fm, const StatsTheme &);
|
2021-01-01 16:55:44 +00:00
|
|
|
};
|
|
|
|
int displayedItems;
|
|
|
|
double width;
|
|
|
|
double height;
|
2021-02-16 16:05:39 +00:00
|
|
|
const StatsTheme &theme; // Set once in constructor.
|
2021-01-13 20:15:11 +00:00
|
|
|
// The position is specified with respect to the center and in relative terms
|
|
|
|
// with respect to the canvas.
|
|
|
|
QPointF centerPos;
|
|
|
|
bool posInitialized;
|
2021-01-01 16:55:44 +00:00
|
|
|
int fontHeight;
|
|
|
|
std::vector<Entry> entries;
|
|
|
|
void hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|