summaryrefslogtreecommitdiffstats
path: root/stats/legend.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-13 21:15:11 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2021-01-20 08:47:18 +0100
commitb1c0d424081530161c1637a1a24ff07a4b021097 (patch)
tree6db7322173e4ffd183534cc409e61ee6ed0ea3c8 /stats/legend.h
parente1c0cace95d6ed19dff37a524c7f4b2288d258d7 (diff)
downloadsubsurface-b1c0d424081530161c1637a1a24ff07a4b021097.tar.gz
statistics: remember position of legend when resizing
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>
Diffstat (limited to 'stats/legend.h')
-rw-r--r--stats/legend.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/stats/legend.h b/stats/legend.h
index 1e38f705a..fb88920bd 100644
--- a/stats/legend.h
+++ b/stats/legend.h
@@ -15,6 +15,7 @@ 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 {
@@ -28,6 +29,10 @@ private:
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();