-rw-r--r-- | core/apps/calibrate/calibrate.cpp | 37 | ||||
-rw-r--r-- | core/apps/calibrate/calibrate.h | 6 |
2 files changed, 34 insertions, 9 deletions
diff --git a/core/apps/calibrate/calibrate.cpp b/core/apps/calibrate/calibrate.cpp index a5f8792..e079195 100644 --- a/core/apps/calibrate/calibrate.cpp +++ b/core/apps/calibrate/calibrate.cpp | |||
@@ -25,9 +25,9 @@ | |||
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | #include <qapplication.h> | 27 | #include <qapplication.h> |
28 | 28 | ||
29 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 29 | //#if defined(Q_WS_QWS) || defined(_WS_QWS_) |
30 | 30 | ||
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> |
@@ -36,8 +36,9 @@ | |||
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 | showCross = TRUE; | 41 | showCross = TRUE; |
41 | const int offset = 30; | 42 | const int offset = 30; |
42 | QRect desk = qApp->desktop() ->geometry(); | 43 | QRect desk = qApp->desktop() ->geometry(); |
43 | setGeometry( 0, 0, desk.width(), desk.height() ); | 44 | setGeometry( 0, 0, desk.width(), desk.height() ); |
@@ -57,8 +58,9 @@ Calibrate::Calibrate( QWidget* parent, const char * name, WFlags wf ) : | |||
57 | reset(); | 58 | reset(); |
58 | 59 | ||
59 | timer = new QTimer( this ); | 60 | timer = new QTimer( this ); |
60 | connect( timer, SIGNAL( timeout() ), this, SLOT( timeout() ) ); | 61 | connect( timer, SIGNAL( timeout() ), this, SLOT( timeout() ) ); |
62 | #endif | ||
61 | } | 63 | } |
62 | 64 | ||
63 | Calibrate::~Calibrate() | 65 | Calibrate::~Calibrate() |
64 | { | 66 | { |
@@ -66,17 +68,21 @@ Calibrate::~Calibrate() | |||
66 | } | 68 | } |
67 | 69 | ||
68 | void Calibrate::show() | 70 | void Calibrate::show() |
69 | { | 71 | { |
72 | #ifdef QWS | ||
70 | grabMouse(); | 73 | grabMouse(); |
71 | QWSServer::mouseHandler() ->getCalibration( &goodcd ); | 74 | QWSServer::mouseHandler() ->getCalibration( &goodcd ); |
72 | QWSServer::mouseHandler() ->clearCalibration(); | 75 | QWSServer::mouseHandler() ->clearCalibration(); |
73 | QDialog::show(); | 76 | QDialog::show(); |
77 | #endif | ||
74 | } | 78 | } |
75 | 79 | ||
76 | void Calibrate::store() | 80 | void Calibrate::store() |
77 | { | 81 | { |
82 | #ifdef QWS | ||
78 | QWSServer::mouseHandler() ->calibrate( &goodcd ); | 83 | QWSServer::mouseHandler() ->calibrate( &goodcd ); |
84 | #endif | ||
79 | } | 85 | } |
80 | 86 | ||
81 | void Calibrate::hide() | 87 | void Calibrate::hide() |
82 | { | 88 | { |
@@ -86,27 +92,35 @@ void Calibrate::hide() | |||
86 | // hack - calibrate is a launcher dialog, but treated like a standalone app | 92 | // hack - calibrate is a launcher dialog, but treated like a standalone app |
87 | { | 93 | { |
88 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 94 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
89 | e << QString ( "calibrate" ); | 95 | e << QString ( "calibrate" ); |
90 | } | 96 | } |
91 | } | 97 | } |
92 | QDialog::hide(); | 98 | QDialog::hide(); |
93 | } | 99 | } |
94 | 100 | ||
95 | void Calibrate::reset() | 101 | void Calibrate::reset() |
96 | { | 102 | { |
103 | #ifdef QWS | ||
97 | penPos = QPoint(); | 104 | penPos = QPoint(); |
98 | location = QWSPointerCalibrationData::TopLeft; | 105 | location = QWSPointerCalibrationData::TopLeft; |
99 | crossPos = fromDevice( cd.screenPoints[ location ] ); | 106 | crossPos = fromDevice( cd.screenPoints[ location ] ); |
107 | #endif | ||
100 | } | 108 | } |
101 | 109 | ||
102 | QPoint Calibrate::fromDevice( const QPoint &p ) | 110 | QPoint Calibrate::fromDevice( const QPoint &p ) |
103 | { | 111 | { |
112 | #ifdef QWS | ||
104 | return qt_screen->mapFromDevice ( p, QSize( qt_screen->deviceWidth ( ), qt_screen->deviceHeight() ) ); | 113 | return qt_screen->mapFromDevice ( p, QSize( qt_screen->deviceWidth ( ), qt_screen->deviceHeight() ) ); |
114 | #else | ||
115 | return QPoint(); | ||
116 | #endif | ||
117 | |||
105 | } | 118 | } |
106 | 119 | ||
107 | bool Calibrate::sanityCheck() | 120 | bool Calibrate::sanityCheck() |
108 | { | 121 | { |
122 | #ifdef QWS | ||
109 | QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; | 123 | QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; |
110 | QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; | 124 | QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; |
111 | QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft]; | 125 | QPoint bl = cd.devPoints[QWSPointerCalibrationData::BottomLeft]; |
112 | QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight]; | 126 | QPoint br = cd.devPoints[QWSPointerCalibrationData::BottomRight]; |
@@ -126,28 +140,31 @@ bool Calibrate::sanityCheck() | |||
126 | int dl = (int) ::sqrt (( dlx * dlx ) + ( dly * dly )); // calculate vector lengths for all sides | 140 | int dl = (int) ::sqrt (( dlx * dlx ) + ( dly * dly )); // calculate vector lengths for all sides |
127 | int dr = (int) ::sqrt (( drx * drx ) + ( dry * dry )); | 141 | int dr = (int) ::sqrt (( drx * drx ) + ( dry * dry )); |
128 | int dt = (int) ::sqrt (( dtx * dtx ) + ( dty * dty )); | 142 | int dt = (int) ::sqrt (( dtx * dtx ) + ( dty * dty )); |
129 | int db = (int) ::sqrt (( dbx * dbx ) + ( dby * dby )); | 143 | int db = (int) ::sqrt (( dbx * dbx ) + ( dby * dby )); |
130 | 144 | ||
131 | // Calculate leeway for x/y (we do not care if diff1/diff2 is for x or y here !) | 145 | // Calculate leeway for x/y (we do not care if diff1/diff2 is for x or y here !) |
132 | int diff1 = QABS( dl - dr ); | 146 | int diff1 = QABS( dl - dr ); |
133 | int avg1 = ( dl + dr ) / 2; | 147 | int avg1 = ( dl + dr ) / 2; |
134 | int diff2 = QABS( dt - db ); | 148 | int diff2 = QABS( dt - db ); |
135 | int avg2 = ( dt + db ) / 2; | 149 | int avg2 = ( dt + db ) / 2; |
136 | 150 | ||
137 | // Calculate leeway for "real" vector length against "manhattan" vector length | 151 | // Calculate leeway for "real" vector length against "manhattan" vector length |
138 | // This is a check, if the rect is rotated (other then 0/90/180/270) | 152 | // This is a check, if the rect is rotated (other then 0/90/180/270) |
139 | // It needs to be performed only for the triange (bl, tl, tr) | 153 | // It needs to be performed only for the triange (bl, tl, tr) |
140 | int diff3 = QABS(( dlx + dly + dtx + dty ) - ( dl + dt )); | 154 | int diff3 = QABS(( dlx + dly + dtx + dty ) - ( dl + dt )); |
141 | int avg3 = (( dlx + dly + dtx + dty ) + ( dl + dt )) / 2; | 155 | int avg3 = (( dlx + dly + dtx + dty ) + ( dl + dt )) / 2; |
142 | 156 | ||
143 | if (( diff1 > ( avg1 / 20 )) || // 5% leeway | 157 | if (( diff1 > ( avg1 / 20 )) || // 5% leeway |
144 | ( diff2 > ( avg2 / 20 )) || | 158 | ( diff2 > ( avg2 / 20 )) || |
145 | ( diff3 > ( avg3 / 20 ))) | 159 | ( diff3 > ( avg3 / 20 ))) |
146 | return false; | 160 | return false; |
147 | else | 161 | else |
148 | return true; | 162 | return true; |
149 | } | 163 | #else |
164 | return true; | ||
165 | #endif | ||
166 | } | ||
150 | 167 | ||
151 | void Calibrate::moveCrosshair( QPoint pt ) | 168 | void Calibrate::moveCrosshair( QPoint pt ) |
152 | { | 169 | { |
153 | showCross = FALSE; | 170 | showCross = FALSE; |
@@ -189,19 +206,22 @@ void Calibrate::paintEvent( QPaintEvent * ) | |||
189 | } | 206 | } |
190 | 207 | ||
191 | void Calibrate::mousePressEvent( QMouseEvent *e ) | 208 | void Calibrate::mousePressEvent( QMouseEvent *e ) |
192 | { | 209 | { |
210 | #ifdef QWS | ||
193 | // map to device coordinates | 211 | // map to device coordinates |
194 | QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize( qt_screen->width(), qt_screen->height() ) ); | 212 | QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize( qt_screen->width(), qt_screen->height() ) ); |
195 | if ( penPos.isNull() ) | 213 | if ( penPos.isNull() ) |
196 | penPos = devPos; | 214 | penPos = devPos; |
197 | else | 215 | else |
198 | penPos = QPoint( ( penPos.x() + devPos.x() ) / 2, | 216 | penPos = QPoint( ( penPos.x() + devPos.x() ) / 2, |
199 | ( penPos.y() + devPos.y() ) / 2 ); | 217 | ( penPos.y() + devPos.y() ) / 2 ); |
218 | #endif | ||
200 | } | 219 | } |
201 | 220 | ||
202 | void Calibrate::mouseReleaseEvent( QMouseEvent * ) | 221 | void Calibrate::mouseReleaseEvent( QMouseEvent * ) |
203 | { | 222 | { |
223 | #ifdef QWS | ||
204 | if ( timer->isActive() ) | 224 | if ( timer->isActive() ) |
205 | return ; | 225 | return ; |
206 | 226 | ||
207 | bool doMove = TRUE; | 227 | bool doMove = TRUE; |
@@ -228,12 +248,14 @@ void Calibrate::mouseReleaseEvent( QMouseEvent * ) | |||
228 | dx = ( target.x() - crossPos.x() ) / 10; | 248 | dx = ( target.x() - crossPos.x() ) / 10; |
229 | dy = ( target.y() - crossPos.y() ) / 10; | 249 | dy = ( target.y() - crossPos.y() ) / 10; |
230 | timer->start( 30 ); | 250 | timer->start( 30 ); |
231 | } | 251 | } |
252 | #endif | ||
232 | } | 253 | } |
233 | 254 | ||
234 | void Calibrate::timeout() | 255 | void Calibrate::timeout() |
235 | { | 256 | { |
257 | #ifdef QWS | ||
236 | QPoint target = fromDevice( cd.screenPoints[ location ] ); | 258 | QPoint target = fromDevice( cd.screenPoints[ location ] ); |
237 | 259 | ||
238 | bool doneX = FALSE; | 260 | bool doneX = FALSE; |
239 | bool doneY = FALSE; | 261 | bool doneY = FALSE; |
@@ -254,7 +276,8 @@ void Calibrate::timeout() | |||
254 | timer->stop(); | 276 | timer->stop(); |
255 | } | 277 | } |
256 | 278 | ||
257 | moveCrosshair( newPos ); | 279 | moveCrosshair( newPos ); |
280 | #endif | ||
258 | } | 281 | } |
259 | 282 | ||
260 | #endif // _WS_QWS_ | 283 | //#endif // _WS_QWS_ |
diff --git a/core/apps/calibrate/calibrate.h b/core/apps/calibrate/calibrate.h index 97108c9..06aa0c9 100644 --- a/core/apps/calibrate/calibrate.h +++ b/core/apps/calibrate/calibrate.h | |||
@@ -19,9 +19,9 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qwsmouse_qws.h> | 21 | #include <qwsmouse_qws.h> |
22 | 22 | ||
23 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 23 | //#if defined(Q_WS_QWS) || defined(_WS_QWS_) |
24 | 24 | ||
25 | #include <qdialog.h> | 25 | #include <qdialog.h> |
26 | #include <qpixmap.h> | 26 | #include <qpixmap.h> |
27 | 27 | ||
@@ -51,10 +51,12 @@ private slots: | |||
51 | private: | 51 | private: |
52 | void store(); | 52 | void store(); |
53 | void reset(); | 53 | void reset(); |
54 | QPixmap logo; | 54 | QPixmap logo; |
55 | #ifdef QWS | ||
55 | QWSPointerCalibrationData goodcd,cd; | 56 | QWSPointerCalibrationData goodcd,cd; |
56 | QWSPointerCalibrationData::Location location; | 57 | QWSPointerCalibrationData::Location location; |
58 | #endif | ||
57 | QPoint crossPos; | 59 | QPoint crossPos; |
58 | QPoint penPos; | 60 | QPoint penPos; |
59 | QPixmap saveUnder; | 61 | QPixmap saveUnder; |
60 | QTimer *timer; | 62 | QTimer *timer; |
@@ -62,6 +64,6 @@ private: | |||
62 | int dy; | 64 | int dy; |
63 | bool showCross; | 65 | bool showCross; |
64 | }; | 66 | }; |
65 | 67 | ||
66 | #endif // _WS_QWS_ | 68 | //#endif // _WS_QWS_ |
67 | 69 | ||