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
@@ -42,7 +42,8 @@ Calibrate::Calibrate(QWidget* parent, const char * name, WFlags wf) :
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 );
@@ -91,45 +92,23 @@ void Calibrate::reset()
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;
@@ -154,16 +133,12 @@ void Calibrate::paintEvent( QPaintEvent * )
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 );
@@ -175,8 +150,7 @@ void Calibrate::paintEvent( QPaintEvent * )
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
@@ -192,16 +166,18 @@ void Calibrate::mouseReleaseEvent( QMouseEvent * )
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 }