1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QPIXELTOOL_H |
5 | #define QPIXELTOOL_H |
6 | |
7 | #include <qwidget.h> |
8 | #include <qpixmap.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class QPixelTool : public QWidget |
13 | { |
14 | Q_OBJECT |
15 | public: |
16 | explicit QPixelTool(QWidget *parent = nullptr); |
17 | ~QPixelTool(); |
18 | |
19 | void setPreviewImage(const QImage &image); |
20 | |
21 | QSize sizeHint() const override; |
22 | |
23 | public slots: |
24 | void setZoom(int zoom); |
25 | void setGridSize(int gridSize); |
26 | void toggleGrid(); |
27 | void toggleFreeze(); |
28 | void setZoomVisible(bool visible); |
29 | #if QT_CONFIG(clipboard) |
30 | void copyToClipboard(); |
31 | void copyColorToClipboard(); |
32 | void copyScreenShotToClipboard(); |
33 | void copyScreenInfoToClipboard(); |
34 | #endif |
35 | void saveToFile(); |
36 | void increaseGridSize() { setGridSize(m_gridSize + 1); } |
37 | void decreaseGridSize() { setGridSize(m_gridSize - 1); } |
38 | void increaseZoom(); |
39 | void decreaseZoom(); |
40 | void aboutPixelTool(); |
41 | |
42 | protected: |
43 | void timerEvent(QTimerEvent *event) override; |
44 | void paintEvent(QPaintEvent *event) override; |
45 | void keyPressEvent(QKeyEvent *event) override; |
46 | void keyReleaseEvent(QKeyEvent *event) override; |
47 | void resizeEvent(QResizeEvent *event) override; |
48 | void mouseMoveEvent(QMouseEvent *event) override; |
49 | void mousePressEvent(QMouseEvent *event) override; |
50 | void mouseReleaseEvent(QMouseEvent *event) override; |
51 | void (QContextMenuEvent *event) override; |
52 | |
53 | private: |
54 | void grabScreen(); |
55 | void startZoomVisibleTimer(); |
56 | void startGridSizeVisibleTimer(); |
57 | QString aboutText() const; |
58 | |
59 | bool m_freeze = false; |
60 | bool m_displayZoom = false; |
61 | bool m_displayGridSize = false; |
62 | bool m_mouseDown = false; |
63 | bool m_autoUpdate; |
64 | bool m_preview_mode = false; |
65 | |
66 | int m_gridActive; |
67 | int m_zoom; |
68 | int m_gridSize; |
69 | int m_lcdMode; |
70 | |
71 | int m_updateId = 0; |
72 | int m_displayZoomId = 0; |
73 | int m_displayGridSizeId = 0; |
74 | |
75 | QRgb m_currentColor = 0; |
76 | |
77 | QPoint m_lastMousePos; |
78 | QPoint m_dragStart; |
79 | QPoint m_dragCurrent; |
80 | QPixmap m_buffer; |
81 | |
82 | QSize m_initialSize; |
83 | |
84 | QImage m_preview_image; |
85 | }; |
86 | |
87 | QT_END_NAMESPACE |
88 | |
89 | #endif // QPIXELTOOL_H |
90 | |