1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 |
|
---|
44 | #include "mainwindow.h"
|
---|
45 | #include "tabletcanvas.h"
|
---|
46 |
|
---|
47 | //! [0]
|
---|
48 | MainWindow::MainWindow(TabletCanvas *canvas)
|
---|
49 | {
|
---|
50 | myCanvas = canvas;
|
---|
51 | createActions();
|
---|
52 | createMenus();
|
---|
53 |
|
---|
54 | myCanvas->setColor(Qt::red);
|
---|
55 | myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
|
---|
56 | myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
|
---|
57 | myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
|
---|
58 |
|
---|
59 | setWindowTitle(tr("Tablet Example"));
|
---|
60 | setCentralWidget(myCanvas);
|
---|
61 | }
|
---|
62 | //! [0]
|
---|
63 |
|
---|
64 | //! [1]
|
---|
65 | void MainWindow::brushColorAct()
|
---|
66 | {
|
---|
67 | QColor color = QColorDialog::getColor(myCanvas->color());
|
---|
68 |
|
---|
69 | if (color.isValid())
|
---|
70 | myCanvas->setColor(color);
|
---|
71 | }
|
---|
72 | //! [1]
|
---|
73 |
|
---|
74 | //! [2]
|
---|
75 | void MainWindow::alphaActionTriggered(QAction *action)
|
---|
76 | {
|
---|
77 | if (action == alphaChannelPressureAction) {
|
---|
78 | myCanvas->setAlphaChannelType(TabletCanvas::AlphaPressure);
|
---|
79 | } else if (action == alphaChannelTiltAction) {
|
---|
80 | myCanvas->setAlphaChannelType(TabletCanvas::AlphaTilt);
|
---|
81 | } else {
|
---|
82 | myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | //! [2]
|
---|
86 |
|
---|
87 | //! [3]
|
---|
88 | void MainWindow::lineWidthActionTriggered(QAction *action)
|
---|
89 | {
|
---|
90 | if (action == lineWidthPressureAction) {
|
---|
91 | myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
|
---|
92 | } else if (action == lineWidthTiltAction) {
|
---|
93 | myCanvas->setLineWidthType(TabletCanvas::LineWidthTilt);
|
---|
94 | } else {
|
---|
95 | myCanvas->setLineWidthType(TabletCanvas::NoLineWidth);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | //! [3]
|
---|
99 |
|
---|
100 | //! [4]
|
---|
101 | void MainWindow::saturationActionTriggered(QAction *action)
|
---|
102 | {
|
---|
103 | if (action == colorSaturationVTiltAction) {
|
---|
104 | myCanvas->setColorSaturationType(TabletCanvas::SaturationVTilt);
|
---|
105 | } else if (action == colorSaturationHTiltAction) {
|
---|
106 | myCanvas->setColorSaturationType(TabletCanvas::SaturationHTilt);
|
---|
107 | } else if (action == colorSaturationPressureAction) {
|
---|
108 | myCanvas->setColorSaturationType(TabletCanvas::SaturationPressure);
|
---|
109 | } else {
|
---|
110 | myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | //! [4]
|
---|
114 |
|
---|
115 | //! [5]
|
---|
116 | void MainWindow::saveAct()
|
---|
117 | {
|
---|
118 | QString path = QDir::currentPath() + "/untitled.png";
|
---|
119 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save Picture"),
|
---|
120 | path);
|
---|
121 |
|
---|
122 | if (!myCanvas->saveImage(fileName))
|
---|
123 | QMessageBox::information(this, "Error Saving Picture",
|
---|
124 | "Could not save the image");
|
---|
125 | }
|
---|
126 | //! [5]
|
---|
127 |
|
---|
128 | //! [6]
|
---|
129 | void MainWindow::loadAct()
|
---|
130 | {
|
---|
131 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open Picture"),
|
---|
132 | QDir::currentPath());
|
---|
133 |
|
---|
134 | if (!myCanvas->loadImage(fileName))
|
---|
135 | QMessageBox::information(this, "Error Opening Picture",
|
---|
136 | "Could not open picture");
|
---|
137 | }
|
---|
138 | //! [6]
|
---|
139 |
|
---|
140 | //! [7]
|
---|
141 | void MainWindow::aboutAct()
|
---|
142 | {
|
---|
143 | QMessageBox::about(this, tr("About Tablet Example"),
|
---|
144 | tr("This example shows use of a Wacom tablet in Qt"));
|
---|
145 | }
|
---|
146 | //! [7]
|
---|
147 |
|
---|
148 | //! [8]
|
---|
149 | void MainWindow::createActions()
|
---|
150 | {
|
---|
151 | //! [8]
|
---|
152 | brushColorAction = new QAction(tr("&Brush Color..."), this);
|
---|
153 | brushColorAction->setShortcut(tr("Ctrl+C"));
|
---|
154 | connect(brushColorAction, SIGNAL(triggered()),
|
---|
155 | this, SLOT(brushColorAct()));
|
---|
156 |
|
---|
157 | //! [9]
|
---|
158 | alphaChannelPressureAction = new QAction(tr("&Pressure"), this);
|
---|
159 | alphaChannelPressureAction->setCheckable(true);
|
---|
160 |
|
---|
161 | alphaChannelTiltAction = new QAction(tr("&Tilt"), this);
|
---|
162 | alphaChannelTiltAction->setCheckable(true);
|
---|
163 |
|
---|
164 | noAlphaChannelAction = new QAction(tr("No Alpha Channel"), this);
|
---|
165 | noAlphaChannelAction->setCheckable(true);
|
---|
166 | noAlphaChannelAction->setChecked(true);
|
---|
167 |
|
---|
168 | alphaChannelGroup = new QActionGroup(this);
|
---|
169 | alphaChannelGroup->addAction(alphaChannelPressureAction);
|
---|
170 | alphaChannelGroup->addAction(alphaChannelTiltAction);
|
---|
171 | alphaChannelGroup->addAction(noAlphaChannelAction);
|
---|
172 | connect(alphaChannelGroup, SIGNAL(triggered(QAction*)),
|
---|
173 | this, SLOT(alphaActionTriggered(QAction*)));
|
---|
174 |
|
---|
175 | //! [9]
|
---|
176 | colorSaturationVTiltAction = new QAction(tr("&Vertical Tilt"), this);
|
---|
177 | colorSaturationVTiltAction->setCheckable(true);
|
---|
178 |
|
---|
179 | colorSaturationHTiltAction = new QAction(tr("&Horizontal Tilt"), this);
|
---|
180 | colorSaturationHTiltAction->setCheckable(true);
|
---|
181 |
|
---|
182 | colorSaturationPressureAction = new QAction(tr("&Pressure"), this);
|
---|
183 | colorSaturationPressureAction->setCheckable(true);
|
---|
184 |
|
---|
185 | noColorSaturationAction = new QAction(tr("&No Color Saturation"), this);
|
---|
186 | noColorSaturationAction->setCheckable(true);
|
---|
187 | noColorSaturationAction->setChecked(true);
|
---|
188 |
|
---|
189 | colorSaturationGroup = new QActionGroup(this);
|
---|
190 | colorSaturationGroup->addAction(colorSaturationVTiltAction);
|
---|
191 | colorSaturationGroup->addAction(colorSaturationHTiltAction);
|
---|
192 | colorSaturationGroup->addAction(colorSaturationPressureAction);
|
---|
193 | colorSaturationGroup->addAction(noColorSaturationAction);
|
---|
194 | connect(colorSaturationGroup, SIGNAL(triggered(QAction*)),
|
---|
195 | this, SLOT(saturationActionTriggered(QAction*)));
|
---|
196 |
|
---|
197 | lineWidthPressureAction = new QAction(tr("&Pressure"), this);
|
---|
198 | lineWidthPressureAction->setCheckable(true);
|
---|
199 | lineWidthPressureAction->setChecked(true);
|
---|
200 |
|
---|
201 | lineWidthTiltAction = new QAction(tr("&Tilt"), this);
|
---|
202 | lineWidthTiltAction->setCheckable(true);
|
---|
203 |
|
---|
204 | lineWidthFixedAction = new QAction(tr("&Fixed"), this);
|
---|
205 | lineWidthFixedAction->setCheckable(true);
|
---|
206 |
|
---|
207 | lineWidthGroup = new QActionGroup(this);
|
---|
208 | lineWidthGroup->addAction(lineWidthPressureAction);
|
---|
209 | lineWidthGroup->addAction(lineWidthTiltAction);
|
---|
210 | lineWidthGroup->addAction(lineWidthFixedAction);
|
---|
211 | connect(lineWidthGroup, SIGNAL(triggered(QAction*)),
|
---|
212 | this, SLOT(lineWidthActionTriggered(QAction*)));
|
---|
213 |
|
---|
214 | exitAction = new QAction(tr("E&xit"), this);
|
---|
215 | exitAction->setShortcuts(QKeySequence::Quit);
|
---|
216 | connect(exitAction, SIGNAL(triggered()),
|
---|
217 | this, SLOT(close()));
|
---|
218 |
|
---|
219 | loadAction = new QAction(tr("&Open..."), this);
|
---|
220 | loadAction->setShortcuts(QKeySequence::Open);
|
---|
221 | connect(loadAction, SIGNAL(triggered()),
|
---|
222 | this, SLOT(loadAct()));
|
---|
223 |
|
---|
224 | saveAction = new QAction(tr("&Save As..."), this);
|
---|
225 | saveAction->setShortcuts(QKeySequence::SaveAs);
|
---|
226 | connect(saveAction, SIGNAL(triggered()),
|
---|
227 | this, SLOT(saveAct()));
|
---|
228 |
|
---|
229 | aboutAction = new QAction(tr("A&bout"), this);
|
---|
230 | aboutAction->setShortcut(tr("Ctrl+B"));
|
---|
231 | connect(aboutAction, SIGNAL(triggered()),
|
---|
232 | this, SLOT(aboutAct()));
|
---|
233 |
|
---|
234 | aboutQtAction = new QAction(tr("About &Qt"), this);
|
---|
235 | aboutQtAction->setShortcut(tr("Ctrl+Q"));
|
---|
236 | connect(aboutQtAction, SIGNAL(triggered()),
|
---|
237 | qApp, SLOT(aboutQt()));
|
---|
238 | //! [10]
|
---|
239 | }
|
---|
240 | //! [10]
|
---|
241 |
|
---|
242 | //! [11]
|
---|
243 | void MainWindow::createMenus()
|
---|
244 | {
|
---|
245 | fileMenu = menuBar()->addMenu(tr("&File"));
|
---|
246 | fileMenu->addAction(loadAction);
|
---|
247 | fileMenu->addAction(saveAction);
|
---|
248 | fileMenu->addSeparator();
|
---|
249 | fileMenu->addAction(exitAction);
|
---|
250 |
|
---|
251 | brushMenu = menuBar()->addMenu(tr("&Brush"));
|
---|
252 | brushMenu->addAction(brushColorAction);
|
---|
253 |
|
---|
254 | tabletMenu = menuBar()->addMenu(tr("&Tablet"));
|
---|
255 |
|
---|
256 | lineWidthMenu = tabletMenu->addMenu(tr("&Line Width"));
|
---|
257 | lineWidthMenu->addAction(lineWidthPressureAction);
|
---|
258 | lineWidthMenu->addAction(lineWidthTiltAction);
|
---|
259 | lineWidthMenu->addAction(lineWidthFixedAction);
|
---|
260 |
|
---|
261 | alphaChannelMenu = tabletMenu->addMenu(tr("&Alpha Channel"));
|
---|
262 | alphaChannelMenu->addAction(alphaChannelPressureAction);
|
---|
263 | alphaChannelMenu->addAction(alphaChannelTiltAction);
|
---|
264 | alphaChannelMenu->addAction(noAlphaChannelAction);
|
---|
265 |
|
---|
266 | colorSaturationMenu = tabletMenu->addMenu(tr("&Color Saturation"));
|
---|
267 | colorSaturationMenu->addAction(colorSaturationVTiltAction);
|
---|
268 | colorSaturationMenu->addAction(colorSaturationHTiltAction);
|
---|
269 | colorSaturationMenu->addAction(noColorSaturationAction);
|
---|
270 |
|
---|
271 | helpMenu = menuBar()->addMenu("&Help");
|
---|
272 | helpMenu->addAction(aboutAction);
|
---|
273 | helpMenu->addAction(aboutQtAction);
|
---|
274 | }
|
---|
275 | //! [11]
|
---|