diff --git a/src/graphitem.cpp b/src/graphitem.cpp index a56b14dd..3f07115b 100644 --- a/src/graphitem.cpp +++ b/src/graphitem.cpp @@ -2,6 +2,9 @@ #include "graphitem.h" +#define GRAPH_WIDTH 1 +#define HOVER_WIDTH 2 + static qreal yAtX(const QPainterPath &path, qreal x) { int low = 0; @@ -46,9 +49,11 @@ GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent) : QGraphicsObject(parent) { _id = 0; - _pen = QPen(QBrush(Qt::SolidPattern), 0); _type = Distance; + _pen.setWidth(GRAPH_WIDTH); + _pen.setCosmetic(true); + _distancePath.moveTo(graph.first().s(), -graph.first().y()); for (int i = 1; i < graph.size(); i++) _distancePath.lineTo(graph.at(i).s(), -graph.at(i).y()); @@ -68,12 +73,18 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->setPen(_pen); painter->drawPath((_type == Distance) ? _distancePath : _timePath); + +/* + QPen p = QPen(QBrush(Qt::red), 0); + painter->setPen(p); + painter->drawRect(boundingRect()); +*/ } void GraphItem::setColor(const QColor &color) { - QBrush brush(color, Qt::SolidPattern); - _pen.setBrush(brush); + _pen.setColor(color); + update(); } qreal GraphItem::yAtX(qreal x) @@ -125,3 +136,16 @@ void GraphItem::emitSliderPositionChanged(qreal pos) } else emit sliderPositionChanged(pos); } + +void GraphItem::selected(bool selected) +{ + if (selected) { + _pen.setWidth(HOVER_WIDTH); + setZValue(zValue() + 1.0); + } else { + _pen.setWidth(GRAPH_WIDTH); + setZValue(zValue() - 1.0); + } + + update(); +} diff --git a/src/graphitem.h b/src/graphitem.h index 21eb59b6..6342b728 100644 --- a/src/graphitem.h +++ b/src/graphitem.h @@ -31,6 +31,7 @@ signals: public slots: void emitSliderPositionChanged(qreal); + void selected(bool selected); private: int _id; diff --git a/src/graphview.cpp b/src/graphview.cpp index 36035dda..d56642fd 100644 --- a/src/graphview.cpp +++ b/src/graphview.cpp @@ -178,6 +178,7 @@ void GraphView::loadGraph(const Graph &graph, PathItem *path, int id) SLOT(emitSliderPositionChanged(qreal))); connect(gi, SIGNAL(sliderPositionChanged(qreal)), path, SLOT(moveMarker(qreal))); + connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool))); _graphs.append(gi); diff --git a/src/pathitem.h b/src/pathitem.h index de883bfd..14763c6e 100644 --- a/src/pathitem.h +++ b/src/pathitem.h @@ -14,6 +14,9 @@ public: public slots: virtual void moveMarker(qreal distance) = 0; + +signals: + void selected(bool); }; #endif // PATHITEM_H diff --git a/src/trackitem.cpp b/src/trackitem.cpp index 9e0b71e0..9d095d17 100644 --- a/src/trackitem.cpp +++ b/src/trackitem.cpp @@ -124,6 +124,8 @@ void TrackItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) _pen.setWidthF(HOVER_WIDTH * 1.0/scale()); setZValue(zValue() + 1.0); update(); + + emit selected(true); } void TrackItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) @@ -133,4 +135,6 @@ void TrackItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) _pen.setWidthF(TRACK_WIDTH * 1.0/scale()); setZValue(zValue() - 1.0); update(); + + emit selected(false); }