mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
b1c0d42408
The position of the legend was reset when resizing. This was OK as long as the legend wasn't movable. To avoid resetting the position, store the center position of the legend relatively to the size of the canvas. On resize restore the center to the same relative size. To avoid code duplication, move the sanitizing of the coordinates from the StatsView to the Legend. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
41 lines
996 B
C++
41 lines
996 B
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 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);
|
|
};
|
|
int displayedItems;
|
|
double width;
|
|
double height;
|
|
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
|