summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/apps/calibrate/calibrate.cpp60
1 files changed, 18 insertions, 42 deletions
diff --git a/core/apps/calibrate/calibrate.cpp b/core/apps/calibrate/calibrate.cpp
index 7b60e64..54fa8ec 100644
--- a/core/apps/calibrate/calibrate.cpp
+++ b/core/apps/calibrate/calibrate.cpp
@@ -39,13 +39,14 @@ Calibrate::Calibrate(QWidget* parent, const char * name, WFlags wf) :
39 const int offset = 30; 39 const int offset = 30;
40 QRect desk = qApp->desktop()->geometry(); 40 QRect desk = qApp->desktop()->geometry();
41 setGeometry( 0, 0, desk.width(), desk.height() ); 41 setGeometry( 0, 0, desk.width(), desk.height() );
42 if ( desk.height() < 250 ) { 42 if ( desk.height() < 250 ) {
43 int w = desk.height()/3; 43 int w = desk.height()/3;
44 logo.convertFromImage(Resource::loadImage("launcher/opielogo").smoothScale(w,w)); 44 logo.convertFromImage(Resource::loadImage("launcher/opielogo").smoothScale(w,w));
45 } else { 45 }
46 else {
46 logo = Resource::loadPixmap( "launcher/opielogo" ); 47 logo = Resource::loadPixmap( "launcher/opielogo" );
47 } 48 }
48 cd.screenPoints[QWSPointerCalibrationData::TopLeft] = QPoint( offset, offset ); 49 cd.screenPoints[QWSPointerCalibrationData::TopLeft] = QPoint( offset, offset );
49 cd.screenPoints[QWSPointerCalibrationData::BottomLeft] = QPoint( offset, qt_screen->deviceHeight() - offset ); 50 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::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::TopRight] = QPoint( qt_screen->deviceWidth() - offset, offset );
@@ -88,51 +89,29 @@ void Calibrate::reset()
88 location = QWSPointerCalibrationData::TopLeft; 89 location = QWSPointerCalibrationData::TopLeft;
89 crossPos = fromDevice( cd.screenPoints[location] ); 90 crossPos = fromDevice( cd.screenPoints[location] );
90} 91}
91 92
92QPoint Calibrate::fromDevice( const QPoint &p ) 93QPoint Calibrate::fromDevice( const QPoint &p )
93{ 94{
94 return qt_screen->mapFromDevice( p, 95 return qt_screen->mapFromDevice ( p, QSize( qt_screen->deviceWidth ( ), qt_screen->deviceHeight() ) );
95 QSize(qt_screen->deviceWidth(), qt_screen->deviceHeight()) );
96} 96}
97 97
98bool Calibrate::sanityCheck() 98bool Calibrate::sanityCheck()
99{ 99{
100 QPoint tl = cd.devPoints[QWSPointerCalibrationData::TopLeft]; 100 QRect r ( cd.devPoints[ QWSPointerCalibrationData::TopLeft ], cd.devPoints[ QWSPointerCalibrationData::BottomRight ] );
101 QPoint tr = cd.devPoints[QWSPointerCalibrationData::TopRight]; 101 r = r. normalize ( ); // This should also handle rotated TS controllers
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 102
112 int ht = QABS( tl.x() - tr.x() ); 103 cd. devPoints [QWSPointerCalibrationData::TopRight] = r. topRight ( );
113 int hb = QABS( br.x() - bl.x() ); 104 cd. devPoints [QWSPointerCalibrationData::BottomLeft] = r. bottomLeft ( );
114 diff = QABS( ht - hb ); 105 cd. devPoints [QWSPointerCalibrationData::Center] = r. center ( );
115 avg = ( ht + hb ) / 2;
116 if ( diff > avg / 20 ) // 5% leeway
117 return FALSE;
118 106
119 return TRUE; 107 return true;
120} 108}
121 109
122void Calibrate::moveCrosshair( QPoint pt ) 110void Calibrate::moveCrosshair( QPoint pt )
123{ 111{
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; 112 showCross = FALSE;
134 repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 ); 113 repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 );
135 showCross = TRUE; 114 showCross = TRUE;
136 crossPos = pt; 115 crossPos = pt;
137 repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 ); 116 repaint( crossPos.x()-8, crossPos.y()-8, 16, 16 );
138} 117}
@@ -151,35 +130,30 @@ void Calibrate::paintEvent( QPaintEvent * )
151 y = height() / 2 + 15; 130 y = height() / 2 + 15;
152 131
153 p.drawText( 0, y+height()/8, width(), height() - y, AlignHCenter, 132 p.drawText( 0, y+height()/8, width(), height() - y, AlignHCenter,
154 tr("Touch the crosshairs firmly and\n" 133 tr("Touch the crosshairs firmly and\n"
155 "accurately to calibrate your screen.") ); 134 "accurately to calibrate your screen.") );
156 135
157 QFont f = p.font(); f.setBold(TRUE); 136 QFont f = p.font();
137 f.setBold( TRUE );
158 p.setFont( f ); 138 p.setFont( f );
159 p.drawText( 0, y, width(), height() - y, AlignHCenter|WordBreak, 139 p.drawText( 0, y, width(), height() - y, AlignHCenter|WordBreak,
160 tr("Welcome to Opie") ); 140 tr("Welcome to Opie") );
161 141
162/*
163 saveUnder = QPixmap::grabWindow( winId(), crossPos.x()-8, crossPos.y()-8,
164 16, 16 );
165 moveCrosshair( crossPos );
166*/
167 if ( showCross ) { 142 if ( showCross ) {
168 p.drawRect( crossPos.x()-1, crossPos.y()-8, 2, 7 ); 143 p.drawRect( crossPos.x()-1, crossPos.y()-8, 2, 7 );
169 p.drawRect( crossPos.x()-1, crossPos.y()+1, 2, 7 ); 144 p.drawRect( crossPos.x()-1, crossPos.y()+1, 2, 7 );
170 p.drawRect( crossPos.x()-8, crossPos.y()-1, 7, 2 ); 145 p.drawRect( crossPos.x()-8, crossPos.y()-1, 7, 2 );
171 p.drawRect( crossPos.x()+1, crossPos.y()-1, 7, 2 ); 146 p.drawRect( crossPos.x()+1, crossPos.y()-1, 7, 2 );
172 } 147 }
173} 148}
174 149
175void Calibrate::mousePressEvent( QMouseEvent *e ) 150void Calibrate::mousePressEvent( QMouseEvent *e )
176{ 151{
177 // map to device coordinates 152 // map to device coordinates
178 QPoint devPos = qt_screen->mapToDevice( e->pos(), 153 QPoint devPos = qt_screen->mapToDevice( e->pos(), QSize( qt_screen->width(), qt_screen->height() ) );
179 QSize(qt_screen->width(), qt_screen->height()) );
180 if ( penPos.isNull() ) 154 if ( penPos.isNull() )
181 penPos = devPos; 155 penPos = devPos;
182 else 156 else
183 penPos = QPoint( (penPos.x() + devPos.x())/2, 157 penPos = QPoint( (penPos.x() + devPos.x())/2,
184 (penPos.y() + devPos.y())/2 ); 158 (penPos.y() + devPos.y())/2 );
185} 159}
@@ -189,22 +163,24 @@ void Calibrate::mouseReleaseEvent( QMouseEvent * )
189 if ( timer->isActive() ) 163 if ( timer->isActive() )
190 return; 164 return;
191 165
192 bool doMove = TRUE; 166 bool doMove = TRUE;
193 167
194 cd.devPoints[location] = penPos; 168 cd.devPoints[location] = penPos;
195 if ( location < QWSPointerCalibrationData::LastLocation ) { 169 if ( location == QWSPointerCalibrationData::TopLeft ) {
196 location = (QWSPointerCalibrationData::Location)((int)location + 1); 170 location = QWSPointerCalibrationData::BottomRight;
197 } else { 171 }
172 else {
198 if ( sanityCheck() ) { 173 if ( sanityCheck() ) {
199 reset(); 174 reset();
200 goodcd = cd; 175 goodcd = cd;
201 hide(); 176 hide();
202 emit accept(); 177 emit accept();
203 doMove = FALSE; 178 doMove = FALSE;
204 } else { 179 }
180 else {
205 location = QWSPointerCalibrationData::TopLeft; 181 location = QWSPointerCalibrationData::TopLeft;
206 } 182 }
207 } 183 }
208 184
209 if ( doMove ) { 185 if ( doMove ) {
210 QPoint target = fromDevice( cd.screenPoints[location] ); 186 QPoint target = fromDevice( cd.screenPoints[location] );