-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomqgraphicsview.h
144 lines (94 loc) · 3 KB
/
customqgraphicsview.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
#ifndef CUSTOMQGRAPHICSVIEW_H
#define CUSTOMQGRAPHICSVIEW_H
#include <QObject>
#include <QWidget>
#include <QGraphicsView>
#include <QPainter>
#include <QRectF>
#include <QEvent>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QWheelEvent>
#include <QGraphicsRectItem>
#include <QTransform>
#include <QString>
#include <QTimer>
class CustomQGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
explicit CustomQGraphicsView(QWidget *parent = 0);
protected:
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mouseMoveEvent(QMouseEvent *event);
// void mousePressEvent(QMouseEvent *event);
// void mouseReleaseEvent(QMouseEvent *event);
// void wheelEvent(QWheelEvent *event);
// void paintEvent(QPaintEvent *event);
private:
QString name;
// toolbar;
// constant floats to be initialize below by C++ standard
static const double scale_limit_max;
static const double scale_limit_min;
static const double scale_up_rate;
static const double scale_down_rate;
// Keyboard panning
static const double key_pan_delta_x;
static const double key_pan_delta_y;
qreal x0;
qreal y0;
double scale_size;
double scale_fit_factor; // sets initial zoom level
qreal last_scale_factor;
bool show_details;
bool has_focus;
bool transform_enable;
bool dolly_zoom_enable;
bool is_GL_switch_allowed;
bool is_GL;
QTimer *qTimer;
static const DragMode no_drag = QGraphicsView::RubberBandDrag;
static const DragMode yes_drag = QGraphicsView::ScrollHandDrag;
QGraphicsRectItem *scene_root_item; // the item to transform
// Modifier keys and buttons
static const int key_mod = Qt::Key_Control;
static const int button_pan = Qt::LeftButton;
static const int button_pan_alt = Qt::MidButton;
static const int button_zoom = Qt::RightButton;
//methods
void addToPressList(QObject *item);
qint32 keyPanDeltaX();
qint32 keyPanDeltaY();
void safeScale(qreal delta);
void zoomIn(qreal fractionofmax);
void zoomOut(qreal fractionofmin);
void dollyZoom(QMouseEvent *event);
void resetScale();
void zoomToFit();
void panEnable();
void panDisable();
void setViewportUpdateOn(bool isEnabled);
void activateSelection(bool isActive);
void clearGraphicsView();
void clearSelectionLockAndCallbacks();
void setGLView(bool boolval);
void resetGL();
void setupGL();
bool shouldShowDetails();
void allowGLSwitch();
void drawBackgroundGL(QPainter* painter, QRectF &rect);
// void setSelectionLock(selectionLock);
void setScaleFitFactor(qreal value);
// void setKeyPan(button);
signals:
void levelOfDetailChangedSignal(bool iszoomedout);
public slots:
};
#endif // CUSTOMQGRAPHICSVIEW_H