1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-25 12:15:54 +01:00
GPXSee/src/GUI/graphitem.h

69 lines
1.4 KiB
C
Raw Normal View History

#ifndef GRAPHITEM_H
#define GRAPHITEM_H
2016-09-19 00:56:10 +02:00
#include <QGraphicsObject>
#include <QPen>
2017-11-26 18:54:03 +01:00
#include "data/graph.h"
#include "units.h"
2016-09-19 00:56:10 +02:00
class GraphItem : public QGraphicsObject
{
2016-09-19 00:56:10 +02:00
Q_OBJECT
public:
2017-10-04 23:15:39 +02:00
GraphItem(const Graph &graph, GraphType type, QGraphicsItem *parent = 0);
2018-03-08 00:57:09 +01:00
virtual ~GraphItem() {}
2016-09-19 00:56:10 +02:00
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
2016-09-19 00:56:10 +02:00
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QRectF &bounds() const {return _bounds;}
2017-10-04 23:15:39 +02:00
void setScale(qreal sx, qreal sy);
2016-09-25 18:08:39 +02:00
void setGraphType(GraphType type);
2016-08-19 19:48:44 +02:00
int id() const {return _id;}
void setId(int id) {_id = id;}
2016-08-19 19:48:44 +02:00
void setColor(const QColor &color);
2016-12-06 01:48:26 +01:00
void setWidth(int width);
2017-10-04 23:15:39 +02:00
virtual void setUnits(Units units) {Q_UNUSED(units);}
2016-09-19 00:56:10 +02:00
qreal yAtX(qreal x);
qreal distanceAtTime(qreal time);
2017-10-04 23:15:39 +02:00
void redraw();
2016-09-19 00:56:10 +02:00
signals:
void sliderPositionChanged(qreal);
void selected(bool);
2016-09-19 00:56:10 +02:00
public slots:
void emitSliderPositionChanged(qreal);
void hover(bool hover);
2016-09-19 00:56:10 +02:00
private:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void updatePath();
void updateShape();
void updateBounds();
int _id;
2016-09-19 00:56:10 +02:00
QPen _pen;
2016-12-06 01:48:26 +01:00
int _width;
Graph _graph;
2016-09-19 23:35:04 +02:00
GraphType _type;
QPainterPath _path;
QPainterPath _shape;
QRectF _bounds;
qreal _sx, _sy;
2017-05-22 18:42:23 +02:00
bool _time;
};
#endif // GRAPHITEM_H