2016-08-16 00:27:54 +02:00
|
|
|
#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"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "units.h"
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
class GraphItem : public QGraphicsObject
|
2016-08-16 00:27:54 +02:00
|
|
|
{
|
2016-09-19 00:56:10 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
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
|
|
|
|
2017-09-24 19:54:13 +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);
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2016-10-12 20:38:18 +02:00
|
|
|
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;}
|
2016-08-16 00:27:54 +02:00
|
|
|
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-08-16 00:27:54 +02:00
|
|
|
|
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();
|
2017-09-24 19:54:13 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
signals:
|
|
|
|
void sliderPositionChanged(qreal);
|
2017-09-24 19:54:13 +02:00
|
|
|
void selected(bool);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void emitSliderPositionChanged(qreal);
|
2017-09-24 19:54:13 +02:00
|
|
|
void hover(bool hover);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
private:
|
2017-09-24 19:54:13 +02:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
|
2016-10-12 20:38:18 +02:00
|
|
|
void updatePath();
|
2017-09-24 19:54:13 +02:00
|
|
|
void updateShape();
|
2016-10-12 20:38:18 +02:00
|
|
|
void updateBounds();
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
int _id;
|
2016-09-19 00:56:10 +02:00
|
|
|
QPen _pen;
|
2016-12-06 01:48:26 +01:00
|
|
|
int _width;
|
2016-10-12 20:38:18 +02:00
|
|
|
|
|
|
|
Graph _graph;
|
2016-09-19 23:35:04 +02:00
|
|
|
GraphType _type;
|
2016-10-12 20:38:18 +02:00
|
|
|
|
|
|
|
QPainterPath _path;
|
2017-09-24 19:54:13 +02:00
|
|
|
QPainterPath _shape;
|
2016-10-12 20:38:18 +02:00
|
|
|
QRectF _bounds;
|
|
|
|
qreal _sx, _sy;
|
2017-05-22 18:42:23 +02:00
|
|
|
|
|
|
|
bool _time;
|
2016-08-16 00:27:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GRAPHITEM_H
|