mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
Added graph highlighting on track select
This commit is contained in:
parent
19c44f56d6
commit
7e365cb990
@ -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();
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
void emitSliderPositionChanged(qreal);
|
||||
void selected(bool selected);
|
||||
|
||||
private:
|
||||
int _id;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -14,6 +14,9 @@ public:
|
||||
|
||||
public slots:
|
||||
virtual void moveMarker(qreal distance) = 0;
|
||||
|
||||
signals:
|
||||
void selected(bool);
|
||||
};
|
||||
|
||||
#endif // PATHITEM_H
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user