-rw-r--r-- | core/apps/calibrate/.cvsignore | 3 | ||||
-rw-r--r-- | core/apps/calibrate/calibrate.cpp | 243 | ||||
-rw-r--r-- | core/apps/calibrate/calibrate.h | 67 | ||||
-rw-r--r-- | core/apps/calibrate/calibrate.pro | 1 |
4 files changed, 314 insertions, 0 deletions
diff --git a/core/apps/calibrate/.cvsignore b/core/apps/calibrate/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/core/apps/calibrate/.cvsignore | |||
@@ -0,0 +1,3 @@ | |||
1 | moc_* | ||
2 | *.moc | ||
3 | Makefile | ||
diff --git a/core/apps/calibrate/calibrate.cpp b/core/apps/calibrate/calibrate.cpp new file mode 100644 index 0000000..96cd1ca --- a/dev/null +++ b/core/apps/calibrate/calibrate.cpp | |||
@@ -0,0 +1,243 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "calibrate.h" | ||
22 | |||
23 | #include <qpe/resource.h> | ||
24 | |||
25 | #include <qapplication.h> | ||
26 | |||
27 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | ||
28 | |||
29 | #include <qpainter.h> | ||
30 | #include <qtimer.h> | ||
31 | #include <qwindowsystem_qws.h> | ||
32 | #include <qgfx_qws.h> | ||
33 | |||
34 | |||
35 | Calibrate::Calibrate(QWidget* parent, const char * name, WFlags wf) : | ||
36 | QDialog( parent, name, TRUE, wf | WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop ) | ||
37 | { | ||
38 | showCross = TRUE; | ||
39 | const int offset = 30; | ||
40 | QRect desk = qApp->desktop()->geometry(); | ||
41 | setGeometry( 0, 0, desk.width(), desk.height() ); | ||
42 | if ( desk.height() < 250 ) { | ||
43 | int w = desk.height()/3; | ||
44 | logo.convertFromImage(Resource::loadImage("qtlogo").smoothScale(w,w)); | ||
45 | } else { | ||
46 | logo = Resource::loadPixmap( "qtlogo" ); | ||
47 | } | ||
48 | cd.screenPoints[QWSPointerCalibrationData::TopLeft] = QPoint( offset, offset ); | ||
49 | cd.screenPoints[QWSPointerCalibrationData::BottomLeft] = QPoint( offset, qt_screen->deviceHeight() - offset ); | ||
50 | cd.screenPoints[QWSPointerCalibrationData::BottomRight] = QPoint( qt_screen->deviceWidth() - offset, qt_screen->deviceHeight() - offset ); | ||
51 | cd.screenPoints[QWSPointerCalibrationData::TopRight] = QPoint( qt_screen->deviceWidth() - offset, offset ); | ||
52 | cd.screenPoints[QWSPointerCalibrationData::Center] = QPoint( qt_screen->deviceWidth()/2, qt_screen->deviceHeight()/2 ); | ||
53 | goodcd = cd; | ||
54 | reset(); | ||
55 | |||
56 | timer = new QTimer( this ); | ||
57 | connect( timer, SIGNAL(timeout()), this, SLOT(timeout()) ); | ||
58 | } | ||
59 | |||
60 | Calibrate::~Calibrate() | ||
61 | { | ||
62 | store(); | ||
63 | } | ||
64 | |||
65 | void Calibrate::show() | ||
66 | { | ||
67 | grabMouse(); | ||
68 | QWSServer::mouseHandler()->getCalibration(&goodcd); | ||
69 | QWSServer::mouseHandler()->clearCalibration(); | ||
70 | QDialog::show(); | ||
71 | } | ||
72 | |||
73 | void Calibrate::store() | ||
74 | { | ||
75 | QWSServer::mouseHandler()->calibrate( &goodcd ); | ||
76 | } | ||
77 | |||
78 | void Calibrate::hide() | ||
79 | { | ||
80 | if ( isVisible() ) | ||
81 | store(); | ||
82 | QDialog::hide(); | ||
83 | } | ||
84 | |||
85 | void Calibrate::reset() | ||
86 | { | ||
87 | penPos = QPoint(); | ||
88 | location = QWSPointerCalibrationData::TopLeft; | ||
89 | crossPos = fromDevice( cd.screenPoints[location] ); | ||
90 | } | ||
91 | |||
92 | QPoint Calibrate::fromDevice( const QPoint &p ) | ||
93 | { | ||
94 | return qt_screen->mapFromDevice( p, | ||
95 | QSize(qt_screen->deviceWidth(), qt_screen->deviceHeight()) ); | ||
96 | } | ||
97 | |||
98 | bool Calibrate::sanityCheck() | ||
99 | { | ||
100 | QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; | ||
101 | QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; | ||
102 | QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft]; | ||
103 | QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight]; | ||
104 | |||
105 | int vl = QABS( tl.y() - bl.y() ); | ||
106 | int vr = QABS( tr.y() - br.y() ); | ||
107 | int diff = QABS( vl - vr ); | ||
108 | int avg = ( vl + vr ) / 2; | ||
109 | if ( diff > avg / 20 ) // 5% leeway | ||
110 | return FALSE; | ||
111 | |||
112 | int ht = QABS( tl.x() - tr.x() ); | ||
113 | int hb = QABS( br.x() - bl.x() ); | ||
114 | diff = QABS( ht - hb ); | ||
115 | avg = ( ht + hb ) / 2; | ||
116 | if ( diff > avg / 20 ) // 5% leeway | ||
117 | return FALSE; | ||
118 | |||
119 | return TRUE; | ||
120 | } | ||
121 | |||
122 | void Calibrate::moveCrosshair( QPoint pt ) | ||
123 | { | ||
124 | /* | ||
125 | QPainter p( this ); | ||
126 | p.drawPixmap( crossPos.x()-8, crossPos.y()-8, saveUnder ); | ||
127 | saveUnder = QPixmap::grabWindow( winId(), pt.x()-8, pt.y()-8, 16, 16 ); | ||
128 | p.drawRect( pt.x()-1, pt.y()-8, 2, 7 ); | ||
129 | p.drawRect( pt.x()-1, pt.y()+1, 2, 7 ); | ||
130 | p.drawRect( pt.x()-8, pt.y()-1, 7, 2 ); | ||
131 | p.drawRect( pt.x()+1, pt.y()-1, 7, 2 ); | ||
132 | */ | ||
133 | showCross = FALSE; | ||
134 | repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 ); | ||
135 | showCross = TRUE; | ||
136 | crossPos = pt; | ||
137 | repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 ); | ||
138 | } | ||
139 | |||
140 | void Calibrate::paintEvent( QPaintEvent * ) | ||
141 | { | ||
142 | QPainter p( this ); | ||
143 | |||
144 | int y; | ||
145 | |||
146 | if ( !logo.isNull() ) { | ||
147 | y = height() / 2 - logo.height() - 15; | ||
148 | p.drawPixmap( (width() - logo.width())/2, y, logo ); | ||
149 | } | ||
150 | |||
151 | y = height() / 2 + 15; | ||
152 | |||
153 | p.drawText( 0, y+height()/8, width(), height() - y, AlignHCenter, | ||
154 | tr("Touch the crosshairs firmly and\n" | ||
155 | "accurately to calibrate your screen.") ); | ||
156 | |||
157 | QFont f = p.font(); f.setBold(TRUE); | ||
158 | p.setFont( f ); | ||
159 | p.drawText( 0, y, width(), height() - y, AlignHCenter|WordBreak, | ||
160 | tr("Welcome to Qtopia") ); | ||
161 | |||
162 | /* | ||
163 | saveUnder = QPixmap::grabWindow( winId(), crossPos.x()-8, crossPos.y()-8, | ||
164 | 16, 16 ); | ||
165 | moveCrosshair( crossPos ); | ||
166 | */ | ||
167 | if ( showCross ) { | ||
168 | p.drawRect( crossPos.x()-1, crossPos.y()-8, 2, 7 ); | ||
169 | p.drawRect( crossPos.x()-1, crossPos.y()+1, 2, 7 ); | ||
170 | p.drawRect( crossPos.x()-8, crossPos.y()-1, 7, 2 ); | ||
171 | p.drawRect( crossPos.x()+1, crossPos.y()-1, 7, 2 ); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | void Calibrate::mousePressEvent( QMouseEvent *e ) | ||
176 | { | ||
177 | // map to device coordinates | ||
178 | QPoint devPos = qt_screen->mapToDevice( e->pos(), | ||
179 | QSize(qt_screen->width(), qt_screen->height()) ); | ||
180 | if ( penPos.isNull() ) | ||
181 | penPos = devPos; | ||
182 | else | ||
183 | penPos = QPoint( (penPos.x() + devPos.x())/2, | ||
184 | (penPos.y() + devPos.y())/2 ); | ||
185 | } | ||
186 | |||
187 | void Calibrate::mouseReleaseEvent( QMouseEvent * ) | ||
188 | { | ||
189 | if ( timer->isActive() ) | ||
190 | return; | ||
191 | |||
192 | bool doMove = TRUE; | ||
193 | |||
194 | cd.devPoints[location] = penPos; | ||
195 | if ( location < QWSPointerCalibrationData::LastLocation ) { | ||
196 | location = (QWSPointerCalibrationData::Location)((int)location + 1); | ||
197 | } else { | ||
198 | if ( sanityCheck() ) { | ||
199 | reset(); | ||
200 | goodcd = cd; | ||
201 | hide(); | ||
202 | emit accept(); | ||
203 | doMove = FALSE; | ||
204 | } else { | ||
205 | location = QWSPointerCalibrationData::TopLeft; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | if ( doMove ) { | ||
210 | QPoint target = fromDevice( cd.screenPoints[location] ); | ||
211 | dx = (target.x() - crossPos.x())/10; | ||
212 | dy = (target.y() - crossPos.y())/10; | ||
213 | timer->start( 30 ); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | void Calibrate::timeout() | ||
218 | { | ||
219 | QPoint target = fromDevice( cd.screenPoints[location] ); | ||
220 | |||
221 | bool doneX = FALSE; | ||
222 | bool doneY = FALSE; | ||
223 | QPoint newPos( crossPos.x() + dx, crossPos.y() + dy ); | ||
224 | |||
225 | if ( QABS(crossPos.x() - target.x()) <= QABS(dx) ) { | ||
226 | newPos.setX( target.x() ); | ||
227 | doneX = TRUE; | ||
228 | } | ||
229 | |||
230 | if ( QABS(crossPos.y() - target.y()) <= QABS(dy) ) { | ||
231 | newPos.setY(target.y()); | ||
232 | doneY = TRUE; | ||
233 | } | ||
234 | |||
235 | if ( doneX && doneY ) { | ||
236 | penPos = QPoint(); | ||
237 | timer->stop(); | ||
238 | } | ||
239 | |||
240 | moveCrosshair( newPos ); | ||
241 | } | ||
242 | |||
243 | #endif // _WS_QWS_ | ||
diff --git a/core/apps/calibrate/calibrate.h b/core/apps/calibrate/calibrate.h new file mode 100644 index 0000000..97108c9 --- a/dev/null +++ b/core/apps/calibrate/calibrate.h | |||
@@ -0,0 +1,67 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qwsmouse_qws.h> | ||
22 | |||
23 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | ||
24 | |||
25 | #include <qdialog.h> | ||
26 | #include <qpixmap.h> | ||
27 | |||
28 | class QTimer; | ||
29 | |||
30 | class Calibrate : public QDialog | ||
31 | { | ||
32 | Q_OBJECT | ||
33 | public: | ||
34 | Calibrate(QWidget* parent=0, const char * name=0, WFlags=0); | ||
35 | ~Calibrate(); | ||
36 | |||
37 | void show(); | ||
38 | void hide(); | ||
39 | |||
40 | private: | ||
41 | QPoint fromDevice( const QPoint &p ); | ||
42 | bool sanityCheck(); | ||
43 | void moveCrosshair( QPoint pt ); | ||
44 | void paintEvent( QPaintEvent * ); | ||
45 | void mousePressEvent( QMouseEvent * ); | ||
46 | void mouseReleaseEvent( QMouseEvent * ); | ||
47 | |||
48 | private slots: | ||
49 | void timeout(); | ||
50 | |||
51 | private: | ||
52 | void store(); | ||
53 | void reset(); | ||
54 | QPixmap logo; | ||
55 | QWSPointerCalibrationData goodcd,cd; | ||
56 | QWSPointerCalibrationData::Location location; | ||
57 | QPoint crossPos; | ||
58 | QPoint penPos; | ||
59 | QPixmap saveUnder; | ||
60 | QTimer *timer; | ||
61 | int dx; | ||
62 | int dy; | ||
63 | bool showCross; | ||
64 | }; | ||
65 | |||
66 | #endif // _WS_QWS_ | ||
67 | |||
diff --git a/core/apps/calibrate/calibrate.pro b/core/apps/calibrate/calibrate.pro new file mode 100644 index 0000000..9769ea6 --- a/dev/null +++ b/core/apps/calibrate/calibrate.pro | |||
@@ -0,0 +1 @@ | |||
# This is part of the taskbar | |||