diff --git a/src/routeitem.cpp b/src/routeitem.cpp index 41a871aa..8608a3d0 100644 --- a/src/routeitem.cpp +++ b/src/routeitem.cpp @@ -8,7 +8,8 @@ #include "routeitem.h" -#define ROUTE_WIDTH 3 +#define ROUTE_WIDTH 3 +#define HOVER_WIDTH 5 QString RouteItem::toolTip() { @@ -23,7 +24,7 @@ QString RouteItem::toolTip() void RouteItem::updateShape() { QPainterPathStroker s; - s.setWidth(ROUTE_WIDTH * 1.0/scale()); + s.setWidth(HOVER_WIDTH * 1.0/scale()); _shape = s.createStroke(_path); } @@ -51,6 +52,7 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent) setToolTip(toolTip()); setCursor(Qt::ArrowCursor); + setAcceptHoverEvents(true); updateShape(); @@ -71,7 +73,9 @@ void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPath(_path); /* - painter->setPen(Qt::red); + QPen p = QPen(Qt::red); + p.setWidthF(1.0/scale()); + painter->setPen(p); painter->drawRect(boundingRect()); */ } @@ -130,3 +134,21 @@ void RouteItem::showWaypointLabels(bool show) } } } + +void RouteItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + _pen.setWidthF(HOVER_WIDTH * 1.0/scale()); + setZValue(1.0); + update(); +} + +void RouteItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + _pen.setWidthF(ROUTE_WIDTH * 1.0/scale()); + setZValue(0); + update(); +} diff --git a/src/routeitem.h b/src/routeitem.h index 5b174ae1..e2be4d62 100644 --- a/src/routeitem.h +++ b/src/routeitem.h @@ -30,6 +30,9 @@ public: void showWaypointLabels(bool show); private: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void updateShape(); QString toolTip(); diff --git a/src/trackitem.cpp b/src/trackitem.cpp index 373fc9ea..8160bf90 100644 --- a/src/trackitem.cpp +++ b/src/trackitem.cpp @@ -7,7 +7,8 @@ #include "trackitem.h" -#define TRACK_WIDTH 3 +#define TRACK_WIDTH 3 +#define HOVER_WIDTH 5 QString TrackItem::toolTip() { @@ -27,7 +28,7 @@ QString TrackItem::toolTip() void TrackItem::updateShape() { QPainterPathStroker s; - s.setWidth(TRACK_WIDTH * 1.0/scale()); + s.setWidth(HOVER_WIDTH * 1.0/scale()); _shape = s.createStroke(_path); } @@ -51,6 +52,7 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent) setToolTip(toolTip()); setCursor(Qt::ArrowCursor); + setAcceptHoverEvents(true); updateShape(); @@ -71,7 +73,10 @@ void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPath(_path); /* - painter->setPen(Qt::red); + QPen p = QPen(Qt::red); + p.setWidthF(1.0/scale()); + painter->setPen(p); + painter->setBrush(Qt::NoBrush); painter->drawRect(boundingRect()); */ } @@ -108,3 +113,21 @@ void TrackItem::moveMarker(qreal distance) _marker->setPos(_path.pointAtPercent(distance / _distance)); } } + +void TrackItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + _pen.setWidthF(HOVER_WIDTH * 1.0/scale()); + setZValue(1.0); + update(); +} + +void TrackItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + _pen.setWidthF(TRACK_WIDTH * 1.0/scale()); + setZValue(0); + update(); +} diff --git a/src/trackitem.h b/src/trackitem.h index 2e1ba5ac..8483070b 100644 --- a/src/trackitem.h +++ b/src/trackitem.h @@ -28,6 +28,9 @@ public: void moveMarker(qreal distance); private: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void updateShape(); QString toolTip(); diff --git a/src/waypointitem.cpp b/src/waypointitem.cpp index ddb5369b..05f78c2a 100644 --- a/src/waypointitem.cpp +++ b/src/waypointitem.cpp @@ -7,7 +7,8 @@ #include "waypointitem.h" -#define POINT_SIZE 8 +#define POINT_SIZE 8 +#define HOVER_SIZE 10 QString WaypointItem::toolTip() { @@ -35,6 +36,7 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent) { _units = Metric; _showLabel = true; + _hover = false; _waypoint = waypoint; _coordinates = ll2mercator(QPointF(waypoint.coordinates().x(), @@ -45,22 +47,27 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent) setPos(_coordinates); setToolTip(toolTip()); setCursor(Qt::ArrowCursor); + setAcceptHoverEvents(true); } void WaypointItem::updateBoundingRect() { + qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE; + if (_showLabel) { QFont font; font.setPixelSize(FONT_SIZE); font.setFamily(FONT_FAMILY); + if (_hover) + font.setBold(true); QFontMetrics fm(font); QRect ts = fm.tightBoundingRect(_waypoint.name()); - _boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width() - + POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE); + _boundingRect = QRectF(-pointSize/2, -pointSize/2, ts.width() + + pointSize, ts.height() + fm.descent() + pointSize); } else - _boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, - POINT_SIZE); + _boundingRect = QRectF(-pointSize/2, -pointSize/2, pointSize, + pointSize); } void WaypointItem::paint(QPainter *painter, @@ -69,20 +76,24 @@ void WaypointItem::paint(QPainter *painter, Q_UNUSED(option); Q_UNUSED(widget); + qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE; + if (_showLabel) { QFont font; font.setPixelSize(FONT_SIZE); font.setFamily(FONT_FAMILY); + if (_hover) + font.setBold(true); QFontMetrics fm(font); QRect ts = fm.tightBoundingRect(_waypoint.name()); painter->setFont(font); - painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + painter->drawText(pointSize/2 - qMax(ts.x(), 0), pointSize/2 + ts.height(), _waypoint.name()); } painter->setBrush(Qt::SolidPattern); - painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE); + painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize); /* painter->setPen(Qt::red); @@ -109,3 +120,23 @@ void WaypointItem::showLabel(bool show) updateBoundingRect(); setToolTip(toolTip()); } + +void WaypointItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + prepareGeometryChange(); + _hover = true; + updateBoundingRect(); + setZValue(1.0); +} + +void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + + prepareGeometryChange(); + _hover = false; + updateBoundingRect(); + setZValue(0); +} diff --git a/src/waypointitem.h b/src/waypointitem.h index deb2361f..4d8ee944 100644 --- a/src/waypointitem.h +++ b/src/waypointitem.h @@ -22,6 +22,9 @@ public: QWidget *widget); private: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void updateBoundingRect(); QString toolTip(); @@ -29,6 +32,8 @@ private: QPointF _coordinates; Waypoint _waypoint; Units _units; + + bool _hover; bool _showLabel; };