-
Notifications
You must be signed in to change notification settings - Fork 0
/
qchartviewer.h
157 lines (121 loc) · 4.83 KB
/
qchartviewer.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
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
#ifndef QCHARTVIEWER_H
#define QCHARTVIEWER_H
#include <QLabel>
#include "chartdir.h"
//
// Mouse usage mode constants
//
namespace Chart
{
enum
{
MouseUsageDefault = 0,
MouseUsageScroll = 1,
MouseUsageZoomIn = 3,
MouseUsageZoomOut = 4
};
}
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 setMinimumDrag(int offset);
virtual int getMinimumDrag();
virtual void setUpdateInterval(int interval);
virtual int getUpdateInterval();
virtual bool needUpdateChart();
virtual bool needUpdateImageMap();
//
// QChartViewer methods
//
// Trigger the ViewPortChanged event
virtual void updateViewPort(bool needUpdateChart, bool needUpdateImageMap);
protected:
//
// QChartViewer event handlers
//
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *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; // Zoom in ratio
double m_zoomOutRatio; // Zoom out 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.
//
// 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; // Chart is in on-hold state.
int m_holdTimerId; // The id of the hold timer.
bool m_isInViewPortChanged; // Flag to avoid infinite update loops
signals:
void viewPortChanged();
void clicked(QMouseEvent *event);
void mouseMove(QMouseEvent *event);
public slots:
};
#endif // QCHARTVIEWER_H