Diffstat (limited to 'core/apps/calibrate/calibrate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/calibrate/calibrate.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/core/apps/calibrate/calibrate.cpp b/core/apps/calibrate/calibrate.cpp index 5f52bdc..53388f1 100644 --- a/core/apps/calibrate/calibrate.cpp +++ b/core/apps/calibrate/calibrate.cpp | |||
@@ -31,249 +31,249 @@ | |||
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | #include <qwindowsystem_qws.h> | 33 | #include <qwindowsystem_qws.h> |
34 | #include <qgfx_qws.h> | 34 | #include <qgfx_qws.h> |
35 | 35 | ||
36 | 36 | ||
37 | Calibrate::Calibrate( QWidget* parent, const char * name, WFlags wf ) : | 37 | Calibrate::Calibrate( QWidget* parent, const char * name, WFlags wf ) : |
38 | QDialog( parent, name, TRUE, wf | WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop ) | 38 | QDialog( parent, name, TRUE, wf | WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop ) |
39 | { | 39 | { |
40 | #ifdef QWS | 40 | #ifdef QWS |
41 | showCross = TRUE; | 41 | showCross = TRUE; |
42 | const int offset = 30; | 42 | const int offset = 30; |
43 | QRect desk = qApp->desktop() ->geometry(); | 43 | QRect desk = qApp->desktop() ->geometry(); |
44 | setGeometry( 0, 0, desk.width(), desk.height() ); | 44 | setGeometry( 0, 0, desk.width(), desk.height() ); |
45 | crosshair.convertFromImage( Resource::loadImage("launcher/crosshair") ); | 45 | crosshair.convertFromImage( Resource::loadImage("launcher/crosshair") ); |
46 | 46 | ||
47 | splash.convertFromImage( Resource::loadImage("launcher/firstuse").smoothScale( width(), height() ) ); | 47 | splash.convertFromImage( Resource::loadImage("launcher/firstuse").smoothScale( width(), height() ) ); |
48 | setBackgroundPixmap( splash ); | 48 | setBackgroundPixmap( splash ); |
49 | 49 | ||
50 | cd.screenPoints[ QWSPointerCalibrationData::TopLeft ] = QPoint( offset, offset ); | 50 | cd.screenPoints[ QWSPointerCalibrationData::TopLeft ] = QPoint( offset, offset ); |
51 | cd.screenPoints[ QWSPointerCalibrationData::BottomLeft ] = QPoint( offset, qt_screen->deviceHeight() - offset ); | 51 | cd.screenPoints[ QWSPointerCalibrationData::BottomLeft ] = QPoint( offset, qt_screen->deviceHeight() - offset ); |
52 | cd.screenPoints[ QWSPointerCalibrationData::BottomRight ] = QPoint( qt_screen->deviceWidth() - offset, qt_screen->deviceHeight() - offset ); | 52 | cd.screenPoints[ QWSPointerCalibrationData::BottomRight ] = QPoint( qt_screen->deviceWidth() - offset, qt_screen->deviceHeight() - offset ); |
53 | cd.screenPoints[ QWSPointerCalibrationData::TopRight ] = QPoint( qt_screen->deviceWidth() - offset, offset ); | 53 | cd.screenPoints[ QWSPointerCalibrationData::TopRight ] = QPoint( qt_screen->deviceWidth() - offset, offset ); |
54 | cd.screenPoints[ QWSPointerCalibrationData::Center ] = QPoint( qt_screen->deviceWidth() / 2, qt_screen->deviceHeight() / 2 ); | 54 | cd.screenPoints[ QWSPointerCalibrationData::Center ] = QPoint( qt_screen->deviceWidth() / 2, qt_screen->deviceHeight() / 2 ); |
55 | goodcd = cd; | 55 | goodcd = cd; |
56 | reset(); | 56 | reset(); |
57 | 57 | ||
58 | timer = new QTimer( this ); | 58 | timer = new QTimer( this ); |
59 | connect( timer, SIGNAL( timeout() ), this, SLOT( timeout() ) ); | 59 | connect( timer, SIGNAL( timeout() ), this, SLOT( timeout() ) ); |
60 | #endif | 60 | #endif |
61 | } | 61 | } |
62 | 62 | ||
63 | Calibrate::~Calibrate() | 63 | Calibrate::~Calibrate() |
64 | { | 64 | { |
65 | store(); | 65 | store(); |
66 | } | 66 | } |
67 | 67 | ||
68 | void Calibrate::show() | 68 | void Calibrate::show() |
69 | { | 69 | { |
70 | #ifdef QWS | 70 | #ifdef QWS |
71 | grabMouse(); | 71 | grabMouse(); |
72 | QWSServer::mouseHandler() ->getCalibration( &goodcd ); | 72 | QWSServer::mouseHandler() ->getCalibration( &goodcd ); |
73 | QWSServer::mouseHandler() ->clearCalibration(); | 73 | QWSServer::mouseHandler() ->clearCalibration(); |
74 | QDialog::show(); | 74 | QDialog::show(); |
75 | #endif | 75 | #endif |
76 | } | 76 | } |
77 | 77 | ||
78 | void Calibrate::store() | 78 | void Calibrate::store() |
79 | { | 79 | { |
80 | #ifdef QWS | 80 | #ifdef QWS |
81 | QWSServer::mouseHandler() ->calibrate( &goodcd ); | 81 | QWSServer::mouseHandler() ->calibrate( &goodcd ); |
82 | #endif | 82 | #endif |
83 | } | 83 | } |
84 | 84 | ||
85 | void Calibrate::hide() | 85 | void Calibrate::hide() |
86 | { | 86 | { |
87 | if ( isVisible()) { | 87 | if ( isVisible()) { |
88 | store(); | 88 | store(); |
89 | 89 | ||
90 | // hack - calibrate is a launcher dialog, but treated like a standalone app | 90 | // hack - calibrate is a launcher dialog, but treated like a standalone app |
91 | { | 91 | { |
92 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 92 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
93 | e << QString ( "calibrate" ); | 93 | e << QString ( "calibrate" ); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | QDialog::hide(); | 96 | QDialog::hide(); |
97 | } | 97 | } |
98 | 98 | ||
99 | void Calibrate::reset() | 99 | void Calibrate::reset() |
100 | { | 100 | { |
101 | #ifdef QWS | 101 | #ifdef QWS |
102 | penPos = QPoint(); | 102 | penPos = QPoint(); |
103 | location = QWSPointerCalibrationData::TopLeft; | 103 | location = QWSPointerCalibrationData::TopLeft; |
104 | crossPos = fromDevice( cd.screenPoints[ location ] ); | 104 | crossPos = fromDevice( cd.screenPoints[ location ] ); |
105 | #endif | 105 | #endif |
106 | } | 106 | } |
107 | 107 | ||
108 | QPoint Calibrate::fromDevice( const QPoint &p ) | 108 | QPoint Calibrate::fromDevice( const QPoint &p ) |
109 | { | 109 | { |
110 | #ifdef QWS | 110 | #ifdef QWS |
111 | return qt_screen->mapFromDevice ( p, QSize( qt_screen->deviceWidth ( ), qt_screen->deviceHeight() ) ); | 111 | return qt_screen->mapFromDevice ( p, QSize( qt_screen->deviceWidth ( ), qt_screen->deviceHeight() ) ); |
112 | #else | 112 | #else |
113 | return QPoint(); | 113 | return QPoint(); |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | } | 116 | } |
117 | 117 | ||
118 | bool Calibrate::sanityCheck() | 118 | bool Calibrate::sanityCheck() |
119 | { | 119 | { |
120 | #ifdef QWS | 120 | #ifdef QWS |
121 | QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; | 121 | QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; |
122 | QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; | 122 | QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; |
123 | QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft]; | 123 | QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft]; |
124 | QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight]; | 124 | QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight]; |
125 | 125 | ||
126 | // not needed anywhere .. just calculate it, so it's there | 126 | // not needed anywhere .. just calculate it, so it's there |
127 | cd.devPoints[QWSPointerCalibrationData::Center] = QRect( tl, br ).normalize().center(); | 127 | //cd.devPoints[QWSPointerCalibrationData::Center] = QRect( tl, br ).normalize().center(); |
128 | 128 | ||
129 | int dlx = QABS( bl. x ( ) - tl. x ( )); | 129 | int dlx = QABS( bl. x ( ) - tl. x ( )); |
130 | int dly = QABS( bl. y ( ) - tl. y ( )); | 130 | int dly = QABS( bl. y ( ) - tl. y ( )); |
131 | int drx = QABS( br. x ( ) - tr. x ( )); | 131 | int drx = QABS( br. x ( ) - tr. x ( )); |
132 | int dry = QABS( br. y ( ) - tr. y ( )); | 132 | int dry = QABS( br. y ( ) - tr. y ( )); |
133 | int dtx = QABS( tr. x ( ) - tl. x ( )); | 133 | int dtx = QABS( tr. x ( ) - tl. x ( )); |
134 | int dty = QABS( tr. y ( ) - tl. y ( )); | 134 | int dty = QABS( tr. y ( ) - tl. y ( )); |
135 | int dbx = QABS( br. x ( ) - bl. x ( )); | 135 | int dbx = QABS( br. x ( ) - bl. x ( )); |
136 | int dby = QABS( br. y ( ) - bl. y ( )); | 136 | int dby = QABS( br. y ( ) - bl. y ( )); |
137 | 137 | ||
138 | int dl = (int) ::sqrt (( dlx * dlx ) + ( dly * dly )); // calculate vector lengths for all sides | 138 | int dl = (int) ::sqrt (( dlx * dlx ) + ( dly * dly )); // calculate vector lengths for all sides |
139 | int dr = (int) ::sqrt (( drx * drx ) + ( dry * dry )); | 139 | int dr = (int) ::sqrt (( drx * drx ) + ( dry * dry )); |
140 | int dt = (int) ::sqrt (( dtx * dtx ) + ( dty * dty )); | 140 | int dt = (int) ::sqrt (( dtx * dtx ) + ( dty * dty )); |
141 | int db = (int) ::sqrt (( dbx * dbx ) + ( dby * dby )); | 141 | int db = (int) ::sqrt (( dbx * dbx ) + ( dby * dby )); |
142 | 142 | ||
143 | // Calculate leeway for x/y (we do not care if diff1/diff2 is for x or y here !) | 143 | // Calculate leeway for x/y (we do not care if diff1/diff2 is for x or y here !) |
144 | int diff1 = QABS( dl - dr ); | 144 | int diff1 = QABS( dl - dr ); |
145 | int avg1 = ( dl + dr ) / 2; | 145 | int avg1 = ( dl + dr ) / 2; |
146 | int diff2 = QABS( dt - db ); | 146 | int diff2 = QABS( dt - db ); |
147 | int avg2 = ( dt + db ) / 2; | 147 | int avg2 = ( dt + db ) / 2; |
148 | 148 | ||
149 | // Calculate leeway for "real" vector length against "manhattan" vector length | 149 | // Calculate leeway for "real" vector length against "manhattan" vector length |
150 | // This is a check, if the rect is rotated (other then 0/90/180/270) | 150 | // This is a check, if the rect is rotated (other then 0/90/180/270) |
151 | // It needs to be performed only for the triange (bl, tl, tr) | 151 | // It needs to be performed only for the triange (bl, tl, tr) |
152 | int diff3 = QABS(( dlx + dly + dtx + dty ) - ( dl + dt )); | 152 | int diff3 = QABS(( dlx + dly + dtx + dty ) - ( dl + dt )); |
153 | int avg3 = (( dlx + dly + dtx + dty ) + ( dl + dt )) / 2; | 153 | int avg3 = (( dlx + dly + dtx + dty ) + ( dl + dt )) / 2; |
154 | 154 | ||
155 | if (( diff1 > ( avg1 / 20 )) || // 5% leeway | 155 | if (( diff1 > ( avg1 / 20 )) || // 5% leeway |
156 | ( diff2 > ( avg2 / 20 )) || | 156 | ( diff2 > ( avg2 / 20 )) || |
157 | ( diff3 > ( avg3 / 20 ))) | 157 | ( diff3 > ( avg3 / 20 ))) |
158 | return false; | 158 | return false; |
159 | else | 159 | else |
160 | return true; | 160 | return true; |
161 | #else | 161 | #else |
162 | return true; | 162 | return true; |
163 | #endif | 163 | #endif |
164 | } | 164 | } |
165 | 165 | ||
166 | void Calibrate::moveCrosshair( QPoint pt ) | 166 | void Calibrate::moveCrosshair( QPoint pt ) |
167 | { | 167 | { |
168 | showCross = FALSE; | 168 | showCross = FALSE; |
169 | repaint( crossPos.x() - 14, crossPos.y() - 14, 28, 28 ); | 169 | repaint( crossPos.x() - 14, crossPos.y() - 14, 28, 28 ); |
170 | showCross = TRUE; | 170 | showCross = TRUE; |
171 | crossPos = pt; | 171 | crossPos = pt; |
172 | repaint( crossPos.x() - 14, crossPos.y() - 14, 28, 28 ); | 172 | repaint( crossPos.x() - 14, crossPos.y() - 14, 28, 28 ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void Calibrate::paintEvent( QPaintEvent * ) | 175 | void Calibrate::paintEvent( QPaintEvent * ) |
176 | { | 176 | { |
177 | QPainter p( this ); | 177 | QPainter p( this ); |
178 | int y = height() / 3; | 178 | int y = height() / 2; |
179 | 179 | ||
180 | p.drawText( 0, y + height() / 8, width(), height() - y, AlignHCenter, | 180 | p.drawText( 0, y + height() / 8, width(), height() - y, AlignHCenter, |
181 | tr( "Touch the crosshairs firmly and\n" | 181 | tr( "Touch the crosshairs firmly and\n" |
182 | "accurately to calibrate your screen." ) ); | 182 | "accurately to calibrate your screen." ) ); |
183 | 183 | ||
184 | if ( !showCross ) return; | 184 | if ( !showCross ) return; |
185 | 185 | ||
186 | #if 0 | 186 | #if 0 |
187 | if ( crosshair.isNull() ) { | 187 | if ( crosshair.isNull() ) { |
188 | #endif | 188 | #endif |
189 | p.setPen( QColor( 0, 0, 155 ) ); | 189 | p.setPen( QColor( 0, 0, 155 ) ); |
190 | p.drawEllipse( crossPos.x()-8, crossPos.y()-8, 16, 16 ); | 190 | p.drawEllipse( crossPos.x()-8, crossPos.y()-8, 16, 16 ); |
191 | p.setPen( QColor( 250, 220, 220 ) ); | 191 | p.setPen( QColor( 250, 220, 220 ) ); |
192 | p.drawRoundRect( crossPos.x()-12, crossPos.y()-12, 24, 24, 75, 75 ); | 192 | p.drawRoundRect( crossPos.x()-12, crossPos.y()-12, 24, 24, 75, 75 ); |
193 | p.setPen( QColor( 0, 0, 120 ) ); | 193 | p.setPen( QColor( 0, 0, 120 ) ); |
194 | p.drawRect( crossPos.x() - 1, crossPos.y() - 14, 2, 13 ); | 194 | p.drawRect( crossPos.x() - 1, crossPos.y() - 14, 2, 13 ); |
195 | p.drawRect( crossPos.x() - 1, crossPos.y() + 1, 2, 13 ); | 195 | p.drawRect( crossPos.x() - 1, crossPos.y() + 1, 2, 13 ); |
196 | p.drawRect( crossPos.x() - 14, crossPos.y() - 1, 13, 2 ); | 196 | p.drawRect( crossPos.x() - 14, crossPos.y() - 1, 13, 2 ); |
197 | p.drawRect( crossPos.x() + 1, crossPos.y() - 1, 13, 2 ); | 197 | p.drawRect( crossPos.x() + 1, crossPos.y() - 1, 13, 2 ); |
198 | #if 0 | 198 | #if 0 |
199 | } | 199 | } |
200 | else p.drawPixmap( crossPos.x(), crossPos.y(), crosshair ); | 200 | else p.drawPixmap( crossPos.x(), crossPos.y(), crosshair ); |
201 | #endif | 201 | #endif |
202 | } | 202 | } |
203 | 203 | ||
204 | void Calibrate::mousePressEvent( QMouseEvent *e ) | 204 | void Calibrate::mousePressEvent( QMouseEvent *e ) |
205 | { | 205 | { |
206 | #ifdef QWS | 206 | #ifdef QWS |
207 | // map to device coordinates | 207 | // map to device coordinates |
208 | QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize( qt_screen->width(), qt_screen->height() ) ); | 208 | QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize( qt_screen->width(), qt_screen->height() ) ); |
209 | if ( penPos.isNull() ) | 209 | if ( penPos.isNull() ) |
210 | penPos = devPos; | 210 | penPos = devPos; |
211 | else | 211 | else |
212 | penPos = QPoint( ( penPos.x() + devPos.x() ) / 2, | 212 | penPos = QPoint( ( penPos.x() + devPos.x() ) / 2, |
213 | ( penPos.y() + devPos.y() ) / 2 ); | 213 | ( penPos.y() + devPos.y() ) / 2 ); |
214 | #endif | 214 | #endif |
215 | } | 215 | } |
216 | 216 | ||
217 | void Calibrate::mouseReleaseEvent( QMouseEvent * ) | 217 | void Calibrate::mouseReleaseEvent( QMouseEvent * ) |
218 | { | 218 | { |
219 | #ifdef QWS | 219 | #ifdef QWS |
220 | if ( timer->isActive() ) | 220 | if ( timer->isActive() ) |
221 | return ; | 221 | return ; |
222 | 222 | ||
223 | bool doMove = TRUE; | 223 | bool doMove = TRUE; |
224 | 224 | ||
225 | cd.devPoints[ location ] = penPos; | 225 | cd.devPoints[ location ] = penPos; |
226 | if ( location < QWSPointerCalibrationData::TopRight ) { | 226 | if ( location < QWSPointerCalibrationData::Center ) { |
227 | location = (QWSPointerCalibrationData::Location) ( int( location ) + 1 ); | 227 | location = (QWSPointerCalibrationData::Location) ( int( location ) + 1 ); |
228 | } | 228 | } |
229 | else { | 229 | else { |
230 | if ( sanityCheck() ) { | 230 | if ( sanityCheck() ) { |
231 | reset(); | 231 | reset(); |
232 | goodcd = cd; | 232 | goodcd = cd; |
233 | hide(); | 233 | hide(); |
234 | emit accept(); | 234 | emit accept(); |
235 | doMove = FALSE; | 235 | doMove = FALSE; |
236 | } | 236 | } |
237 | else { | 237 | else { |
238 | location = QWSPointerCalibrationData::TopLeft; | 238 | location = QWSPointerCalibrationData::TopLeft; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | if ( doMove ) { | 242 | if ( doMove ) { |
243 | QPoint target = fromDevice( cd.screenPoints[ location ] ); | 243 | QPoint target = fromDevice( cd.screenPoints[ location ] ); |
244 | dx = ( target.x() - crossPos.x() ) / 10; | 244 | dx = ( target.x() - crossPos.x() ) / 10; |
245 | dy = ( target.y() - crossPos.y() ) / 10; | 245 | dy = ( target.y() - crossPos.y() ) / 10; |
246 | timer->start( 30 ); | 246 | timer->start( 30 ); |
247 | } | 247 | } |
248 | #endif | 248 | #endif |
249 | } | 249 | } |
250 | 250 | ||
251 | void Calibrate::timeout() | 251 | void Calibrate::timeout() |
252 | { | 252 | { |
253 | #ifdef QWS | 253 | #ifdef QWS |
254 | QPoint target = fromDevice( cd.screenPoints[ location ] ); | 254 | QPoint target = fromDevice( cd.screenPoints[ location ] ); |
255 | 255 | ||
256 | bool doneX = FALSE; | 256 | bool doneX = FALSE; |
257 | bool doneY = FALSE; | 257 | bool doneY = FALSE; |
258 | QPoint newPos( crossPos.x() + dx, crossPos.y() + dy ); | 258 | QPoint newPos( crossPos.x() + dx, crossPos.y() + dy ); |
259 | 259 | ||
260 | if ( QABS( crossPos.x() - target.x() ) <= QABS( dx ) ) { | 260 | if ( QABS( crossPos.x() - target.x() ) <= QABS( dx ) ) { |
261 | newPos.setX( target.x() ); | 261 | newPos.setX( target.x() ); |
262 | doneX = TRUE; | 262 | doneX = TRUE; |
263 | } | 263 | } |
264 | 264 | ||
265 | if ( QABS( crossPos.y() - target.y() ) <= QABS( dy ) ) { | 265 | if ( QABS( crossPos.y() - target.y() ) <= QABS( dy ) ) { |
266 | newPos.setY( target.y() ); | 266 | newPos.setY( target.y() ); |
267 | doneY = TRUE; | 267 | doneY = TRUE; |
268 | } | 268 | } |
269 | 269 | ||
270 | if ( doneX && doneY ) { | 270 | if ( doneX && doneY ) { |
271 | penPos = QPoint(); | 271 | penPos = QPoint(); |
272 | timer->stop(); | 272 | timer->stop(); |
273 | } | 273 | } |
274 | 274 | ||
275 | moveCrosshair( newPos ); | 275 | moveCrosshair( newPos ); |
276 | #endif | 276 | #endif |
277 | } | 277 | } |
278 | 278 | ||
279 | //#endif // _WS_QWS_ | 279 | //#endif // _WS_QWS_ |