From 73a60f5046960d155ed6705fbb533c1ea5349189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 1 Jun 2025 11:31:38 +0200 Subject: [PATCH] Hover the areas when the legend item is selected --- src/GUI/areaitem.cpp | 10 ++++++++++ src/GUI/areaitem.h | 5 +++++ src/GUI/legenditem.cpp | 2 ++ src/GUI/mapitem.cpp | 10 ++++++++++ src/GUI/mapitem.h | 5 ++++- src/GUI/planeitem.h | 7 ++++++- 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/GUI/areaitem.cpp b/src/GUI/areaitem.cpp index 189c195c..b9700190 100644 --- a/src/GUI/areaitem.cpp +++ b/src/GUI/areaitem.cpp @@ -178,6 +178,16 @@ void AreaItem::setDigitalZoom(int zoom) _pen.setWidthF(width() * pow(2, -_digitalZoom)); } +void AreaItem::hover(bool hvr) +{ + if (hvr) + _pen.setWidthF((_width + 1) * pow(2, -_digitalZoom)); + else + _pen.setWidthF(_width * pow(2, -_digitalZoom)); + + update(); +} + void AreaItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); diff --git a/src/GUI/areaitem.h b/src/GUI/areaitem.h index 14bee989..920a80f9 100644 --- a/src/GUI/areaitem.h +++ b/src/GUI/areaitem.h @@ -6,6 +6,8 @@ class AreaItem : public PlaneItem { + Q_OBJECT + public: AreaItem(const Area &area, Map *map, GraphicsItem *parent = 0); @@ -31,6 +33,9 @@ public: const QColor color() const {return _pen.color();} const QString &name() const {return _area.name();} +public slots: + void hover(bool hvr); + protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); diff --git a/src/GUI/legenditem.cpp b/src/GUI/legenditem.cpp index 0bd7e89b..08102742 100644 --- a/src/GUI/legenditem.cpp +++ b/src/GUI/legenditem.cpp @@ -66,6 +66,8 @@ void LegendItem::addItem(PlaneItem *item) _boundingRect = QRectF(0, 0, qMax(_boundingRect.width(), li->boundingRect().width()), _items.size() * li->boundingRect().height()); + + QObject::connect(li, &LegendEntryItem::selected, item, &PlaneItem::hover); } void LegendItem::setColor(const QColor &color) diff --git a/src/GUI/mapitem.cpp b/src/GUI/mapitem.cpp index a1de70d8..8d81af43 100644 --- a/src/GUI/mapitem.cpp +++ b/src/GUI/mapitem.cpp @@ -205,6 +205,16 @@ void MapItem::setDigitalZoom(int zoom) _pen.setWidthF(_width * pow(2, -_digitalZoom)); } +void MapItem::hover(bool hvr) +{ + if (hvr) + _pen.setWidthF((_width + 1) * pow(2, -_digitalZoom)); + else + _pen.setWidthF(_width * pow(2, -_digitalZoom)); + + update(); +} + void MapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); diff --git a/src/GUI/mapitem.h b/src/GUI/mapitem.h index a61b647b..93a00d3e 100644 --- a/src/GUI/mapitem.h +++ b/src/GUI/mapitem.h @@ -6,7 +6,7 @@ class MapAction; class Projection; -class MapItem : public QObject, public PlaneItem +class MapItem : public PlaneItem { Q_OBJECT @@ -32,6 +32,9 @@ public: const QColor color() const {return _pen.color();} const QString &name() const {return _name;} +public slots: + void hover(bool hvr); + signals: void triggered(); diff --git a/src/GUI/planeitem.h b/src/GUI/planeitem.h index e24cda8a..c13a6e48 100644 --- a/src/GUI/planeitem.h +++ b/src/GUI/planeitem.h @@ -6,8 +6,10 @@ class Map; -class PlaneItem : public GraphicsItem +class PlaneItem : public QObject, public GraphicsItem { + Q_OBJECT + public: PlaneItem(GraphicsItem *parent = 0) : GraphicsItem(parent) {} @@ -23,6 +25,9 @@ public: virtual const QColor color() const = 0; virtual const QString &name() const = 0; + +public slots: + virtual void hover(bool hvr) = 0; }; #endif // PLANEITEM_H