-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectionwindow.hxx
217 lines (167 loc) · 4.4 KB
/
selectionwindow.hxx
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#ifndef SELECTIONWINDOW_HXX
#define SELECTIONWINDOW_HXX
#include <QGraphicsPixmapItem>
#include <QGraphicsView>
#include <QLabel>
#include <QLayout>
#include <QPushButton>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
#include <QUndoStack>
#include <QWidget>
#include "platform.hxx"
class SelectionWindow;
class DragHandle : public QLabel {
Q_OBJECT
private:
Q_DISABLE_COPY(DragHandle)
public:
explicit DragHandle(QWidget *moveParent);
virtual ~DragHandle();
virtual void mousePressEvent(QMouseEvent *) override;
virtual void mouseMoveEvent(QMouseEvent *) override;
QWidget *moveParent;
QPoint dragStart;
};
class ColorSwatch : public QWidget {
Q_OBJECT
private:
Q_DISABLE_COPY(ColorSwatch)
QColor color;
protected:
virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
public:
ColorSwatch(QWidget *parent = nullptr);
virtual ~ColorSwatch();
virtual QSize sizeHint() const override;
void setColor(QColor color);
};
class ColorCopyButton : public QPushButton {
Q_OBJECT
public:
enum Format {
CSS_HEX,
CSS_RGB,
};
private:
Q_DISABLE_COPY(ColorCopyButton)
Format format;
QColor color;
QString formatString() const;
void copyString() const;
public:
ColorCopyButton(QWidget *parent = nullptr);
virtual ~ColorCopyButton();
void setFormat(Format format);
void setColor(QColor color);
void copyStringIfActive() const;
};
class ZoomTooltip : public QWidget {
Q_OBJECT
private:
Q_DISABLE_COPY(ZoomTooltip)
QPixmap img;
int scale;
void doResize();
protected:
virtual void paintEvent(QPaintEvent *) override;
public:
ZoomTooltip(QWidget *parent = nullptr);
virtual ~ZoomTooltip();
void setImage(QPixmap image);
void setScale(int scale);
};
class ShotItem : public QGraphicsPixmapItem {
public:
ShotItem(SelectionWindow *);
virtual ~ShotItem();
protected:
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *) override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
private:
SelectionWindow *win;
};
class PenDrawing : public QAbstractGraphicsShapeItem {
QPainterPath rawPath;
QRectF bounds;
QPainterPath strokedPath;
void updateStrokedPath();
public:
PenDrawing(QPen pen, QPoint start);
virtual ~PenDrawing();
void addPoint(QPoint);
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
class DrawingUndoItem : public QUndoCommand {
SelectionWindow *parent;
QGraphicsItem *item;
bool owned;
public:
explicit DrawingUndoItem(SelectionWindow *parent, QGraphicsItem *item);
virtual ~DrawingUndoItem();
void undo() override;
void redo() override;
};
class SelectionWindow : public QWidget {
Q_OBJECT
private:
Q_DISABLE_COPY(SelectionWindow)
friend ShotItem;
friend DrawingUndoItem;
public:
explicit SelectionWindow(QWidget *parent = nullptr);
virtual ~SelectionWindow();
void setPicking(bool picking);
virtual void setVisible(bool visible) override;
protected:
virtual bool event(QEvent *) override;
virtual void moveEvent(QMoveEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
signals:
void pickColorChanged(QColor color);
void pickColorSelected(QColor color);
private:
void geometryChanged(QEvent *);
QPixmap pixmap();
void saveTo(QString path);
QString savePath();
bool picking;
bool pickedLock;
QPoint pickPos;
void pickMoved();
void pickSelected();
ZoomTooltip *pickTooltip;
QToolBar *shotToolbar;
QAction *togglePicker;
QAction *showCursor;
QAction *selectArea;
QAction *penTool;
QToolBar *pickToolbar;
QGraphicsView *selectionView;
QGraphicsScene *scene;
QGraphicsPathItem *selectionItem;
ShotItem *shotItem;
QGraphicsPixmapItem *cursorItem;
QRect desktopGeometry;
qint8 recursingGeometry;
QList<OpenWindow> openWindows;
QPoint selectionStart;
QPoint selectionEnd;
QRect selection;
void selectionMoved();
QPixmap shot;
QPoint cursorPosition;
QPixmap cursor;
QUndoStack *undoStack;
PenDrawing *activeDrawing;
};
#endif