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 | #endif |
33 | void saveToFile(); |
34 | void increaseGridSize() { setGridSize(m_gridSize + 1); } |
35 | void decreaseGridSize() { setGridSize(m_gridSize - 1); } |
36 | void increaseZoom(); |
37 | void decreaseZoom(); |
38 | void aboutPixelTool(); |
39 | |
40 | protected: |
41 | void timerEvent(QTimerEvent *event) override; |
42 | void paintEvent(QPaintEvent *event) override; |
43 | void keyPressEvent(QKeyEvent *event) override; |
44 | void keyReleaseEvent(QKeyEvent *event) override; |
45 | void resizeEvent(QResizeEvent *event) override; |
46 | void mouseMoveEvent(QMouseEvent *event) override; |
47 | void mousePressEvent(QMouseEvent *event) override; |
48 | void mouseReleaseEvent(QMouseEvent *event) override; |
49 | void contextMenuEvent(QContextMenuEvent *event) override; |
50 | |
51 | private: |
52 | void grabScreen(); |
53 | void startZoomVisibleTimer(); |
54 | void startGridSizeVisibleTimer(); |
55 | QString aboutText() const; |
56 | |
57 | bool m_freeze = false; |
58 | bool m_displayZoom = false; |
59 | bool m_displayGridSize = false; |
60 | bool m_mouseDown = false; |
61 | bool m_autoUpdate; |
62 | bool m_preview_mode = false; |
63 | |
64 | int m_gridActive; |
65 | int m_zoom; |
66 | int m_gridSize; |
67 | int m_lcdMode; |
68 | |
69 | int m_updateId; |
70 | int m_displayZoomId = 0; |
71 | int m_displayGridSizeId = 0; |
72 | |
73 | QRgb m_currentColor = 0; |
74 | |
75 | QPoint m_lastMousePos; |
76 | QPoint m_dragStart; |
77 | QPoint m_dragCurrent; |
78 | QPixmap m_buffer; |
79 | |
80 | QSize m_initialSize; |
81 | |
82 | QImage m_preview_image; |
83 | }; |
84 | |
85 | QT_END_NAMESPACE |
86 | |
87 | #endif // QPIXELTOOL_H |
88 |