-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGLGraph.h
129 lines (103 loc) · 3.98 KB
/
GLGraph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef GLGraph_H
#define GLGraph_H
#include <QGLWidget>
#include <QColor>
#include <vector>
#include <QVariant>
class QMutex;
#include "VecWrapBuffer.h"
struct GLGraphState
{
QMutex *ptsMut;
QColor bg_Color, graph_Color, grid_Color, highlight_Color;
unsigned nHGridLines, nVGridLines;
double min_x, max_x, yscale;
unsigned short gridLineStipplePattern;
const Vec2fWrapBuffer *pointsWB;
QVariant tagData;
double selectionBegin, selectionEnd;
bool hasSelection;
bool highlighted;
QString objectName;
QString toString() const;
void fromString(const QString &);
};
class GLGraph : public QGLWidget
{
Q_OBJECT
public:
//GLGraph(QGLContext *ctx, QWidget *parent = 0, QMutex *ptsMutex = 0);
//GLGraph(QWidget *parent, QGLWidget *shareWidget, QMutex *ptsMutex = 0);
//GLGraph(QGLContext *c, QWidget *parent=0, QGLWidget *shareWidget=0, QMutex *ptsMutex = 0);
GLGraph(QWidget *parent = 0, QMutex *ptsMutex = 0);
//GLGraph(const QGLFormat & f, QWidget *p = 0, QMutex *mut = 0);
virtual ~GLGraph();
/// Reset the graph to default params, as if it were freshly constructed
void reset(QMutex *ptsMutex = 0);
// associate whatever to this graph
QVariant tag() const { return tagData; }
void setTag(const QVariant & v) { tagData = v; }
void setPoints(const Vec2fWrapBuffer *pointsBuf);
QColor & bgColor() { return bg_Color; }
QColor & graphColor() { return graph_Color; }
QColor & gridColor() { return grid_Color; }
QColor & highlightColor() { return highlight_Color; }
double & minx() { return min_x; }
double & maxx() { return max_x; }
double yScale() const { return yscale; }
void setYScale(double);
unsigned numVGridLines() const { return nVGridLines; }
void setNumVGridLines(unsigned);
unsigned numHGridLines() const { return nHGridLines; }
void setNumHGridLines(unsigned);
unsigned short & gridLineStipple() { return gridLineStipplePattern; }
bool autoUpdate() const { return auto_update; }
void setAutoUpdate(bool b) { auto_update = b; }
bool needsUpdateGL() const { return need_update; }
void setSelectionRange(double begin_x, double end_x);
void setSelectionEnabled(bool onoff);
bool isSelectionEnabled() const { return hasSelection; }
bool isSelectionVisible() const;
GLGraphState getState() const;
void setState(const GLGraphState & state);
bool isHighlighted() const { return highlighted; }
void setHighlighted(bool onoff);
signals:
/// like cursorOver(), except emitted x,y units are in window coordinates, not graph coordinates
void cursorOverWindowCoords(int x, int y);
/// like clicked(), except emitted x,y units are in window coordinates
void clickedWindowCoords(int x, int y);
void clickReleasedWindowCoords(int x, int y);
/// for all the below: x is a time value, y is a graph Y-pos in range [-1,1]
void cursorOver(double x, double y);
void clicked(double x, double y); ///< this only emitted on Left mouse button clicks
void clickReleased(double x, double y); ///< this only emitted on Right mouse button clicks
void doubleClicked(double x, double y); ///< this only emitted on Left dbl-click
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
Vec2f pos2Vec(const QPoint & pos);
void mouseMoveEvent(QMouseEvent *evt);
void mousePressEvent(QMouseEvent *evt);
void mouseReleaseEvent(QMouseEvent *evt);
void mouseDoubleClickEvent(QMouseEvent *evt);
private:
void drawGrid() const;
void drawPoints() const;
void drawSelection() const;
QMutex *ptsMut;
QColor bg_Color, graph_Color, grid_Color, highlight_Color;
unsigned nHGridLines, nVGridLines;
double min_x, max_x, yscale;
unsigned short gridLineStipplePattern;
const Vec2fWrapBuffer *pointsWB;
mutable QVector<Vec2f> pointsDisplayBuf;
std::vector<Vec2f> gridVs, gridHs;
bool auto_update, need_update;
QVariant tagData;
double selectionBegin, selectionEnd;
bool hasSelection;
bool highlighted;
};
#endif