]> git.cworth.org Git - apitrace/blob - gui/pixelwidget.h
gui: Implement a new surface viewer
[apitrace] / gui / pixelwidget.h
1 /**
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
47 #ifndef PIXELWIDGET_H
48 #define PIXELWIDGET_H
49
50 #include <qwidget.h>
51 #include <qpixmap.h>
52
53 class PixelWidget : public QWidget
54 {
55     Q_OBJECT
56 public:
57     PixelWidget(QWidget *parent = 0);
58     ~PixelWidget();
59     
60     void setSurface(const QImage &image);
61
62     QColor colorAtCurrentPosition() const;
63
64 signals:
65     void zoomChanged(int);
66     void mousePosition(int x, int y);
67     void gridGeometry(const QRect &rect);
68
69 public:
70     void timerEvent(QTimerEvent *event);
71     void paintEvent(QPaintEvent *event);
72     void keyPressEvent(QKeyEvent *event);
73     void keyReleaseEvent(QKeyEvent *event);
74     void resizeEvent(QResizeEvent *event);
75     void mouseMoveEvent(QMouseEvent *event);
76     void mousePressEvent(QMouseEvent *event);
77     void mouseReleaseEvent(QMouseEvent *event);
78     void contextMenuEvent(QContextMenuEvent *event);
79
80     QSize sizeHint() const;
81
82 public slots:
83     void setZoom(int zoom);
84     void setGridSize(int gridSize);
85     void toggleGrid();
86     void copyToClipboard();
87     void saveToFile();
88     void increaseGridSize() { setGridSize(m_gridSize + 1); }
89     void decreaseGridSize() { setGridSize(m_gridSize - 1); }
90     void increaseZoom() { setZoom(m_zoom + 1); }
91     void decreaseZoom() { setZoom(m_zoom - 1); }
92
93 private:
94     void startGridSizeVisibleTimer();
95     double zoomValue() const { return m_zoom; }
96
97     bool m_displayGridSize;
98     bool m_mouseDown;
99
100     int m_gridActive;
101     int m_zoom;
102     int m_gridSize;
103
104     int m_displayZoomId;
105     int m_displayGridSizeId;
106
107     QPoint m_lastMousePos;
108     QPoint m_dragStart;
109     QPoint m_dragCurrent;
110     QImage m_surface;
111
112     QSize m_initialSize;
113     QColor m_currentColor;
114 };
115
116 #endif // PIXELWIDGET_H