1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef QPIXELTOOL_H
30#define QPIXELTOOL_H
31
32#include <qwidget.h>
33#include <qpixmap.h>
34
35QT_BEGIN_NAMESPACE
36
37class QPixelTool : public QWidget
38{
39 Q_OBJECT
40public:
41 explicit QPixelTool(QWidget *parent = nullptr);
42 ~QPixelTool();
43
44 void setPreviewImage(const QImage &image);
45
46 QSize sizeHint() const override;
47
48public slots:
49 void setZoom(int zoom);
50 void setGridSize(int gridSize);
51 void toggleGrid();
52 void toggleFreeze();
53 void setZoomVisible(bool visible);
54#if QT_CONFIG(clipboard)
55 void copyToClipboard();
56 void copyColorToClipboard();
57#endif
58 void saveToFile();
59 void increaseGridSize() { setGridSize(m_gridSize + 1); }
60 void decreaseGridSize() { setGridSize(m_gridSize - 1); }
61 void increaseZoom();
62 void decreaseZoom();
63 void aboutPixelTool();
64
65protected:
66 void timerEvent(QTimerEvent *event) override;
67 void paintEvent(QPaintEvent *event) override;
68 void keyPressEvent(QKeyEvent *event) override;
69 void keyReleaseEvent(QKeyEvent *event) override;
70 void resizeEvent(QResizeEvent *event) override;
71 void mouseMoveEvent(QMouseEvent *event) override;
72 void mousePressEvent(QMouseEvent *event) override;
73 void mouseReleaseEvent(QMouseEvent *event) override;
74 void contextMenuEvent(QContextMenuEvent *event) override;
75
76private:
77 void grabScreen();
78 void startZoomVisibleTimer();
79 void startGridSizeVisibleTimer();
80 QString aboutText() const;
81
82 bool m_freeze = false;
83 bool m_displayZoom = false;
84 bool m_displayGridSize = false;
85 bool m_mouseDown = false;
86 bool m_autoUpdate;
87 bool m_preview_mode = false;
88
89 int m_gridActive;
90 int m_zoom;
91 int m_gridSize;
92 int m_lcdMode;
93
94 int m_updateId;
95 int m_displayZoomId;
96 int m_displayGridSizeId = 0;
97
98 QRgb m_currentColor = 0;
99
100 QPoint m_lastMousePos;
101 QPoint m_dragStart;
102 QPoint m_dragCurrent;
103 QPixmap m_buffer;
104
105 QSize m_initialSize;
106
107 QImage m_preview_image;
108};
109
110QT_END_NAMESPACE
111
112#endif // QPIXELTOOL_H
113

source code of qttools/src/pixeltool/qpixeltool.h