-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqchartviewer.h
More file actions
281 lines (217 loc) · 9.45 KB
/
Copy pathqchartviewer.h
File metadata and controls
281 lines (217 loc) · 9.45 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#ifndef QCHARTVIEWER_H
#define QCHARTVIEWER_H
#include <QLabel>
#include "chartdir.h"
#ifdef CD_NAMESPACE
namespace CD_NAMESPACE
{
#endif
namespace Chart
{
//
// Mouse usage mode constants
//
enum
{
MouseUsageDefault = 0,
MouseUsageScroll = 1,
MouseUsageZoomIn = 3,
MouseUsageZoomOut = 4
};
}
#ifdef CD_NAMESPACE
}
#endif
//
// Forward declarations
//
class QMouseEvent;
class QChartViewer : public QLabel, public ViewPortManager
{
Q_OBJECT
public:
explicit QChartViewer(QWidget *parent = 0);
~QChartViewer();
//
// QChartViewer properties
//
virtual void setChart(BaseChart *c);
virtual BaseChart *getChart();
virtual void setImageMap(const char *imageMap);
virtual ImageMapHandler *getImageMapHandler();
virtual void setDefaultToolTip(QString text);
virtual void setSelectionBorderWidth(int width);
virtual int getSelectionBorderWidth();
virtual void setSelectionBorderColor(QColor c);
virtual QColor getSelectionBorderColor();
virtual void setMouseUsage(int mouseUsage);
virtual int getMouseUsage();
virtual void setZoomDirection(int direction);
virtual int getZoomDirection();
virtual void setScrollDirection(int direction);
virtual int getScrollDirection();
virtual void setZoomInRatio(double ratio);
virtual double getZoomInRatio();
virtual void setZoomOutRatio(double ratio);
virtual double getZoomOutRatio();
virtual void setMouseWheelZoomRatio(double ratio);
virtual double getMouseWheelZoomRatio();
virtual void setMinimumDrag(int offset);
virtual int getMinimumDrag();
virtual void setUpdateInterval(int interval);
virtual int getUpdateInterval();
virtual bool needUpdateChart();
virtual bool needUpdateImageMap();
virtual bool isMouseOnPlotArea();
virtual bool isInMouseMoveEvent();
virtual bool isInViewPortChangedEvent();
virtual bool isMouseDragging();
//
// QChartViewer methods
//
// Trigger the ViewPortChanged event
virtual void updateViewPort(bool needUpdateChart, bool needUpdateImageMap);
// Request CChartViewer to redisplay the chart
virtual void updateDisplay();
// Handles mouse wheel zooming
virtual bool onMouseWheelZoom(int x, int y, int zDelta);
// Set the message used to remove the dynamic layer
virtual void removeDynamicLayer(const char *msg);
// Get the mouse coordinates
virtual int getChartMouseX();
virtual int getChartMouseY();
// Get the mouse coordinates bounded to the plot area
virtual int getPlotAreaMouseX();
virtual int getPlotAreaMouseY();
protected:
//
// QChartViewer event handlers
//
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void onDelayedMouseMove();
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void leaveEvent(QEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void timerEvent (QTimerEvent *event);
virtual void onSetCursor();
private:
//
// QChartViewer configurable properties
//
BaseChart *m_currentChart; // Current BaseChart object
ImageMapHandler *m_hotSpotTester; // ImageMapHander representing the image map
QString m_defaultToolTip; // Default tool tip text
QColor m_selectBoxLineColor; // Selectiom box border color
int m_selectBoxLineWidth; // Selectiom box border width
int m_mouseUsage; // Mouse usage mode
int m_zoomDirection; // Zoom direction
int m_scrollDirection; // Scroll direction
double m_zoomInRatio; // Click zoom in ratio
double m_zoomOutRatio; // Click zoom out ratio
double m_mouseWheelZoomRatio; // Mouse wheel zoom ratio
int m_minDragAmount; // Minimum drag amount
int m_updateInterval; // Minimum interval between chart updates
bool m_needUpdateChart; // Has pending chart update request
bool m_needUpdateImageMap; // Has pending image map udpate request
//
// Keep track of mouse states
//
int m_currentHotSpot; // The hot spot under the mouse cursor.
bool m_isClickable; // Mouse is over a clickable hot spot.
bool m_isOnPlotArea; // Mouse is over the plot area.
bool m_isPlotAreaMouseDown; // Mouse left button is down in the plot area.
bool m_isDragScrolling; // Is current dragging scrolling the chart.
bool m_isMouseTracking; // Is tracking mouse leave event
bool m_isInMouseMove; // Is in mouse moeve event handler
//
// Dragging support
//
int m_plotAreaMouseDownXPos; // The starting x coordinate of the mouse drag.
int m_plotAreaMouseDownYPos; // The starting y coordinate of the mouse drag.
bool isDrag(int direction, QMouseEvent *event); // Check if mouse is dragging
void onPlotAreaMouseDrag(QMouseEvent *point); // Process mouse dragging
//
// Selection rectangle
//
QLabel *m_LeftLine; // Left edge of selection rectangle
QLabel *m_RightLine; // Right edge of selection rectangle
QLabel *m_TopLine; // Top edge of selection rectangle
QLabel *m_BottomLine; // Bottom edge of selection rectangle
void initRect(); // Initialize selection rectangle edges
void drawRect(int x, int y, int width, int height); // Draw selection rectangle
void setRectVisible(bool b); // Show/hide selection rectangle
//
// Chart update rate control
//
bool m_holdTimerActive; // Delay chart update to limit update frequency
int m_holdTimerId; // The id of the hold timer.
bool m_isInViewPortChanged; // Flag to avoid infinite update loops
int m_delayUpdateChart; // Delay chart update until the mouse event is completed
BaseChart *m_delayedChart;
void commitUpdateChart(); // Commit updating the chart.
unsigned int m_lastMouseMove; // The timestamp of the last mouse move event.
QMouseEvent *m_delayedMouseEvent; // The delayed mouse move event.
int m_delayedMouseEventTimerId; // The id of the delayed mouse move timer.
void commitMouseMove(QMouseEvent *event); // Raise the delayed mouse move event.
bool m_delayImageMapUpdate; // Delay image map update until mouse moves on plot area
//
// Track Cursor support
//
int m_currentMouseX; // Get the mouse x-pixel coordinate
int m_currentMouseY; // Get the mouse y-pixel coordinate
int m_isInMouseMovePlotArea; // flag to indicate if is in a mouse move plot area event.
//
// Dynamic Layer support
//
QString m_autoHideMsg; // The message that will trigger removing the dynamic layer.
void applyAutoHide(const char *msg); // Attempt to remove the dynamic layer with the given message.
signals:
void viewPortChanged(); // View port has changed
void clicked(QMouseEvent *event); // Mouse button clicked
void mouseMove(QMouseEvent *event); // Mouse moves over the widget
void mouseWheel(QWheelEvent *event); // Mouse wheel scrolled
void mouseMoveChart(QMouseEvent *event); // Mouse moves over the chart
void mouseLeaveChart(QEvent *event); // Mouse leaves the chart
void mouseMovePlotArea(QMouseEvent *event); // Mouse moves over the extended plot area
void mouseLeavePlotArea(QEvent *event); // Mouse leaves the extended plot area
public slots:
};
class QViewPortControl : public QLabel, public ViewPortControlBase
{
Q_OBJECT
public:
explicit QViewPortControl(QWidget *parent = 0);
~QViewPortControl();
// Set the chart to be displayed in the control
virtual void setChart(BaseChart *c);
virtual BaseChart *getChart();
// Associated QChartViewer
virtual void setViewer(QChartViewer *viewer);
virtual QChartViewer *getViewer();
// Request the CViewPortControl to update its contents
virtual void updateDisplay();
protected:
//
// QChartViewer event handlers
//
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
private slots:
virtual void onViewPortChanged();
private:
QChartViewer *m_ChartViewer; // Associated QChartViewer
BaseChart *m_Chart; // BaseChart object displayed in the control
int m_mouseDownX; // Current mouse x coordinates
int m_mouseDownY; // Current mouse y coordinates
bool isDrag(QMouseEvent *event); // Check if mouse is dragging
void paintDisplay(); // Paint the display
void syncState(); // Synchronize the CViewPortControl with CChartViewer
void updateCursor(int position); // Update the mouse cursor
void updateChartViewerIfNecessary(); // Update CChartViewer if viewport has changed
double toImageX(int x); // Convert from mouse to image x-coordinate
double toImageY(int y); // Convert from mouse to image y-coordinate
};
#endif // QCHARTVIEWER_H