mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
b5aac29cea
To enable rudimentary theming, collect all colors in a new theme class. The class has to be passed down to the various items. In general the items save a reference to the them in the constructor. Alternatively, they might also just query the StatsView everytime they need to access a color. For now, it's hard the say what is preferred: a reference per item or a function call per invokation? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
// 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 StatsTheme;
|
|
|
|
class Legend : public ChartRectItem {
|
|
public:
|
|
Legend(StatsView &view, const std::vector<QString> &names);
|
|
void resize(); // called when the chart size changes.
|
|
void setPos(QPointF pos); // Attention: not virtual - always call on this class.
|
|
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, const StatsTheme &);
|
|
};
|
|
int displayedItems;
|
|
double width;
|
|
double height;
|
|
const StatsTheme &theme; // Set once in constructor.
|
|
QFont font;
|
|
// The position is specified with respect to the center and in relative terms
|
|
// with respect to the canvas.
|
|
QPointF centerPos;
|
|
bool posInitialized;
|
|
int fontHeight;
|
|
std::vector<Entry> entries;
|
|
void hide();
|
|
};
|
|
|
|
#endif
|