author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Mon, 19 Apr 2010 10:15:19 +0300 | |
branch | RCL_3 |
changeset 9 | b5b118452c7d |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "calibration.h" |
|
43 |
||
44 |
#include <QWSPointerCalibrationData> |
|
45 |
#include <QPainter> |
|
46 |
#include <QFile> |
|
47 |
#include <QTimer> |
|
48 |
#include <QApplication> |
|
49 |
#include <QDesktopWidget> |
|
50 |
#include <QMouseEvent> |
|
51 |
#include <QScreen> |
|
52 |
#include <QWSServer> |
|
53 |
||
54 |
//! [0] |
|
55 |
Calibration::Calibration() |
|
56 |
{ |
|
57 |
QRect desktop = QApplication::desktop()->geometry(); |
|
58 |
desktop.moveTo(QPoint(0, 0)); |
|
59 |
setGeometry(desktop); |
|
60 |
||
61 |
setFocusPolicy(Qt::StrongFocus); |
|
62 |
setFocus(); |
|
63 |
setModal(true); |
|
64 |
//! [0] |
|
65 |
||
66 |
//! [1] |
|
67 |
int width = qt_screen->deviceWidth(); |
|
68 |
int height = qt_screen->deviceHeight(); |
|
69 |
||
70 |
int dx = width / 10; |
|
71 |
int dy = height / 10; |
|
72 |
||
73 |
QPoint *points = data.screenPoints; |
|
74 |
points[QWSPointerCalibrationData::TopLeft] = QPoint(dx, dy); |
|
75 |
points[QWSPointerCalibrationData::BottomLeft] = QPoint(dx, height - dy); |
|
76 |
points[QWSPointerCalibrationData::BottomRight] = QPoint(width - dx, height - dy); |
|
77 |
points[QWSPointerCalibrationData::TopRight] = QPoint(width - dx, dy); |
|
78 |
points[QWSPointerCalibrationData::Center] = QPoint(width / 2, height / 2); |
|
79 |
//! [1] |
|
80 |
||
81 |
//! [2] |
|
82 |
pressCount = 0; |
|
83 |
} |
|
84 |
//! [2] |
|
85 |
||
86 |
//! [3] |
|
87 |
Calibration::~Calibration() |
|
88 |
{ |
|
89 |
} |
|
90 |
//! [3] |
|
91 |
||
92 |
//! [4] |
|
93 |
int Calibration::exec() |
|
94 |
{ |
|
95 |
QWSServer::mouseHandler()->clearCalibration(); |
|
96 |
grabMouse(); |
|
97 |
activateWindow(); |
|
98 |
int ret = QDialog::exec(); |
|
99 |
releaseMouse(); |
|
100 |
return ret; |
|
101 |
} |
|
102 |
//! [4] |
|
103 |
||
104 |
//! [5] |
|
105 |
void Calibration::paintEvent(QPaintEvent*) |
|
106 |
{ |
|
107 |
QPainter p(this); |
|
108 |
p.fillRect(rect(), Qt::white); |
|
109 |
||
110 |
QPoint point = data.screenPoints[pressCount]; |
|
111 |
||
112 |
// Map to logical coordinates in case the screen is transformed |
|
113 |
QSize screenSize(qt_screen->deviceWidth(), qt_screen->deviceHeight()); |
|
114 |
point = qt_screen->mapFromDevice(point, screenSize); |
|
115 |
||
116 |
p.fillRect(point.x() - 6, point.y() - 1, 13, 3, Qt::black); |
|
117 |
p.fillRect(point.x() - 1, point.y() - 6, 3, 13, Qt::black); |
|
118 |
} |
|
119 |
//! [5] |
|
120 |
||
121 |
//! [6] |
|
122 |
void Calibration::mouseReleaseEvent(QMouseEvent *event) |
|
123 |
{ |
|
124 |
// Map from device coordinates in case the screen is transformed |
|
125 |
QSize screenSize(qt_screen->width(), qt_screen->height()); |
|
126 |
QPoint p = qt_screen->mapToDevice(event->pos(), screenSize); |
|
127 |
||
128 |
data.devPoints[pressCount] = p; |
|
129 |
||
130 |
if (++pressCount < 5) |
|
131 |
repaint(); |
|
132 |
else |
|
133 |
accept(); |
|
134 |
} |
|
135 |
//! [6] |
|
136 |
||
137 |
//! [7] |
|
138 |
void Calibration::accept() |
|
139 |
{ |
|
140 |
Q_ASSERT(pressCount == 5); |
|
141 |
QWSServer::mouseHandler()->calibrate(&data); |
|
142 |
QDialog::accept(); |
|
143 |
} |
|
144 |
//! [7] |
|
145 |