-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelementpicker.h
233 lines (169 loc) · 6.67 KB
/
elementpicker.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
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
#ifndef ELEMENTPICKER_H
#define ELEMENTPICKER_H
#include <QGraphicsObject>
#include <QCursor>
#include <QPen>
#include "basepicker.h"
#include "graphicsitemtype.h"
QT_BEGIN_NAMESPACE
class QGraphicsRectItem;
QT_END_NAMESPACE
class BaseElement;
class ElementPickerRect;
class ElementPickerOutline;
class ElementPickerRotate;
class ElementPicker;
class ElementPickerWraper;
class BaseSpace;
#define DEFAULT_ARCHOR_WIDTH 6
//ElementPicker < ElementPickerWrap < ElementPickerOutline+ElementPickerRotate < ElementPickerArchor
enum ElementPickerArchorShape
{
PS_CIRCLE,
PS_RECTANGLE
};
class ElementPickerArchor : public QGraphicsItem
{
ElementPickerOutline * m_pickRect;
PickerDirection m_direction;
ElementPickerArchorShape m_shape;
QRectF m_boundingRect;
enum { Type = QGraphicsItem::UserType + GRAPHICSITEM_TYPE_PICKER_ARCHOR };
public:
int type() const override
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
public:
ElementPickerArchor(ElementPickerOutline * parent,
PickerDirection direction,
ElementPickerArchorShape shape=ElementPickerArchorShape::PS_RECTANGLE);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
QRectF boundingRect() const override;
inline void setDirection(PickerDirection arg1) { m_direction = arg1; }
inline PickerDirection direction() const { return m_direction;}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
private:
void setPickerDirection(PickerDirection direction);
};
class ElementPickerOutline : public QGraphicsItem
{
ElementPickerWraper * m_wraper;
QRectF m_elementRect;
QPointF m_transformCenter;
QPointF m_lastPos;
ElementPickerArchor * m_archors[8];
enum { Type = QGraphicsItem::UserType + GRAPHICSITEM_TYPE_PICKER_OUTLINE };
public:
int type() const override
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
public:
ElementPickerOutline(ElementPickerWraper * parent);
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
void setElementRect(const QRectF & rect);
inline QRectF elementRect() const { return m_elementRect;}
void setPickerDirection(PickerDirection direction);
ElementTransform calcTransform(QPointF p,PickerDirection direction);
void adjust(const ElementTransform & t);
void beginAdjust(PickerDirection direction);
void setResizable(bool arg1);
ElementPickerArchor * archorAt(const QPointF & p) const;
};
class ElementPickerRotateArchor : public QGraphicsItem
{
ElementPickerRotate * m_rotate;
const qreal WIDTH = 24;
const qreal HEIGHT = 24;
QCursor m_cursor;
public:
ElementPickerRotateArchor(ElementPickerRotate * rotate);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
QRectF boundingRect() const override;
void setPickerDirection(PickerDirection direction);
BaseSpace * space() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
};
class ElementPickerRotate : public QGraphicsItem
{
ElementPickerWraper * m_wraper;
ElementPickerRotateArchor * m_archor;
public:
ElementPickerRotate(ElementPickerWraper * wraper);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
QRectF boundingRect() const override;
void setPickerDirection(PickerDirection direction);
BaseSpace * space() const;
};
class ElementPickerWraper : public QGraphicsItem
{
ElementPicker * m_picker;
ElementPickerRotate * m_rotate;
qreal m_rotate_angle;
public:
ElementPickerWraper(ElementPicker * picker);
ElementPickerOutline * m_outline;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
QRectF boundingRect() const override;
void setElementRect(const QRectF & rect);
QRectF elementRect() const;
qreal rotateAngle() const {return m_rotate_angle;}
void setDirection(PickerDirection direction);
BaseSpace *space();
ElementTransform calcTransform(QPointF pos, PickerDirection direction);
void adjust(const ElementTransform & t);
void beginAdjust(PickerDirection direction);
void rotateByCenter(qreal angle,const QPointF & cneter);
inline ElementPicker * picker() { return m_picker;}
ElementPickerArchor * archorAt(const QPointF & p) const;
};
/*!
\class ElementPicker
\brief The transformation handler for Element inherited by BaseElement
*/
class ElementPicker : public BasePicker
{
Q_OBJECT
ElementPickerWraper * m_wraper;
//record the offset between element's rect and mouse press postion
QPointF m_start_offset;
//record the initial position before rotate
QPointF m_start_pos;
//indicate the direction of adjust
PickerDirection m_direction;
enum { Type = QGraphicsItem::UserType + GRAPHICSITEM_TYPE_RECT_PICKER };
QCursor m_prevCursor;
public:
int type() const override
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
public:
explicit ElementPicker(BaseElement *element);
PickerDirection direction(const QPointF & p) const;
inline void setDirection(PickerDirection direction) { m_direction = direction;}
void setByElement() override;
QRectF boundingRect() const override;
QPainterPath shape() const override;
void setElementRotation(qreal angle,const QPointF & center) override;
void setElementRect(const QRectF & rect) override;
void beginAdjust(PickerDirection direction);
virtual void adjust(const ElementTransform &t) override;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
};
#endif // ELEMENTPICKER_H