diff options
Diffstat (limited to 'stats/legend.h')
-rw-r--r-- | stats/legend.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/stats/legend.h b/stats/legend.h new file mode 100644 index 000000000..e6c5af1e0 --- /dev/null +++ b/stats/legend.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +// A legend box, which is shown on the chart. +#ifndef STATS_LEGEND_H +#define STATS_LEGEND_H + +#include <memory> +#include <vector> +#include <QGraphicsRectItem> + +class QGraphicsSceneMouseEvent; + +class Legend : public QGraphicsRectItem { +public: + Legend(QGraphicsWidget *chart, 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 { + std::unique_ptr<QGraphicsRectItem> rect; + std::unique_ptr<QGraphicsSimpleTextItem> text; + QPointF pos; + double width; + Entry(const QString &name, int idx, int numBins, QGraphicsItem *parent); + }; + QGraphicsWidget *chart; + int displayedItems; + double width; + double height; + int fontHeight; + std::vector<Entry> entries; + void updatePosition(); + void hide(); +}; + +#endif |