blob: f2ee3ae38b9022ebfaa19abac473bf429db695a0 [file] [log] [blame]
Zack Rusin66ce10a2013-09-10 20:30:59 -04001/**
2 * The source code is based on qpixeltool.h.
3 * Original license follows.
4 */
5
6/****************************************************************************
7**
8** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
9** Contact: http://www.qt-project.org/legal
10**
11** This file is part of the tools applications of the Qt Toolkit.
12**
13** $QT_BEGIN_LICENSE:LGPL$
14** Commercial License Usage
15** Licensees holding valid commercial Qt licenses may use this file in
16** accordance with the commercial license agreement provided with the
17** Software or, alternatively, in accordance with the terms contained in
18** a written agreement between you and Digia. For licensing terms and
19** conditions see http://qt.digia.com/licensing. For further information
20** use the contact form at http://qt.digia.com/contact-us.
21**
22** GNU Lesser General Public License Usage
23** Alternatively, this file may be used under the terms of the GNU Lesser
24** General Public License version 2.1 as published by the Free Software
25** Foundation and appearing in the file LICENSE.LGPL included in the
26** packaging of this file. Please review the following information to
27** ensure the GNU Lesser General Public License version 2.1 requirements
28** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
29**
30** In addition, as a special exception, Digia gives you certain additional
31** rights. These rights are described in the Digia Qt LGPL Exception
32** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
33**
34** GNU General Public License Usage
35** Alternatively, this file may be used under the terms of the GNU
36** General Public License version 3.0 as published by the Free Software
37** Foundation and appearing in the file LICENSE.GPL included in the
38** packaging of this file. Please review the following information to
39** ensure the GNU General Public License version 3.0 requirements will be
40** met: http://www.gnu.org/copyleft/gpl.html.
41**
42**
43** $QT_END_LICENSE$
44**
45****************************************************************************/
46
Jose Fonseca9653f952015-05-19 16:32:43 +010047#pragma once
Zack Rusin66ce10a2013-09-10 20:30:59 -040048
49#include <qwidget.h>
50#include <qpixmap.h>
51
52class PixelWidget : public QWidget
53{
54 Q_OBJECT
55public:
56 PixelWidget(QWidget *parent = 0);
57 ~PixelWidget();
58
59 void setSurface(const QImage &image);
60
61 QColor colorAtCurrentPosition() const;
62
63signals:
64 void zoomChanged(int);
65 void mousePosition(int x, int y);
66 void gridGeometry(const QRect &rect);
67
68public:
Jose Fonseca010f9962016-03-05 14:45:41 +000069 void timerEvent(QTimerEvent *event) override;
70 void paintEvent(QPaintEvent *event) override;
71 void keyPressEvent(QKeyEvent *event) override;
72 void keyReleaseEvent(QKeyEvent *event) override;
73 void resizeEvent(QResizeEvent *event) override;
74 void mouseMoveEvent(QMouseEvent *event) override;
75 void mousePressEvent(QMouseEvent *event) override;
76 void mouseReleaseEvent(QMouseEvent *event) override;
77 void contextMenuEvent(QContextMenuEvent *event) override;
Zack Rusin66ce10a2013-09-10 20:30:59 -040078
Jose Fonseca010f9962016-03-05 14:45:41 +000079 QSize sizeHint() const override;
Zack Rusin66ce10a2013-09-10 20:30:59 -040080
81public slots:
82 void setZoom(int zoom);
83 void setGridSize(int gridSize);
84 void toggleGrid();
85 void copyToClipboard();
86 void saveToFile();
87 void increaseGridSize() { setGridSize(m_gridSize + 1); }
88 void decreaseGridSize() { setGridSize(m_gridSize - 1); }
89 void increaseZoom() { setZoom(m_zoom + 1); }
90 void decreaseZoom() { setZoom(m_zoom - 1); }
91
92private:
93 void startGridSizeVisibleTimer();
94 double zoomValue() const { return m_zoom; }
95
96 bool m_displayGridSize;
97 bool m_mouseDown;
98
99 int m_gridActive;
100 int m_zoom;
101 int m_gridSize;
102
Zack Rusin66ce10a2013-09-10 20:30:59 -0400103 int m_displayGridSizeId;
104
105 QPoint m_lastMousePos;
106 QPoint m_dragStart;
107 QPoint m_dragCurrent;
108 QImage m_surface;
109
110 QSize m_initialSize;
111 QColor m_currentColor;
112};