aboutsummaryrefslogtreecommitdiffstats
path: root/stats/legend.h
blob: a9d42bf391aa980f89a9f47d638bdeb50ec3d3bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-2.0
// A legend box, which is shown on the chart.
#ifndef STATS_LEGEND_H
#define STATS_LEGEND_H

#include "chartitem.h"

#include <memory>
#include <vector>
#include <QFont>

class QFontMetrics;

class Legend : public ChartRectItem {
public:
	Legend(StatsView &view, const std::vector<QString> &names);
	void hover(QPointF pos);
	void resize(); // called when the chart size changes.
private:
	// Each entry is a text besides a rectangle showing the color
	struct Entry {
		QString name;
		QBrush rectBrush;
		QPointF pos;
		double width;
		Entry(const QString &name, int idx, int numBins, const QFontMetrics &fm);
	};
	int displayedItems;
	double width;
	double height;
	QFont font;
	int fontHeight;
	std::vector<Entry> entries;
	void hide();
};

#endif