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>
This commit is contained in:
Berthold Stoeger 2021-01-13 21:15:11 +01:00 committed by bstoeger
parent e1c0cace95
commit b1c0d42408
3 changed files with 43 additions and 12 deletions

View file

@ -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();