summaryrefslogtreecommitdiff
authorsandman <sandman>2002-11-21 02:27:43 (UTC)
committer sandman <sandman>2002-11-21 02:27:43 (UTC)
commitba08c640278399f412e66f906283068a099a2f03 (patch) (unidiff)
treeb4237f428c02ba4277561e765a0be51e300032b1
parenta65963a06def8cb064bf7d99ff2776877f5f6315 (diff)
downloadopie-ba08c640278399f412e66f906283068a099a2f03.zip
opie-ba08c640278399f412e66f906283068a099a2f03.tar.gz
opie-ba08c640278399f412e66f906283068a099a2f03.tar.bz2
The light sensor can now be calibrated "reverse" - less backlight in the
dark and more backlight in the light
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/light-and-power/calibration.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/settings/light-and-power/calibration.cpp b/core/settings/light-and-power/calibration.cpp
index aed2bc8..c5377d0 100644
--- a/core/settings/light-and-power/calibration.cpp
+++ b/core/settings/light-and-power/calibration.cpp
@@ -110,200 +110,200 @@ QPoint Calibration::startPoint ( ) const
110void Calibration::setEndPoint ( const QPoint &p ) 110void Calibration::setEndPoint ( const QPoint &p )
111{ 111{
112 m_p [1] = QPoint ( p. x ( ), m_scale. height ( ) - p. y ( ) - 1 ); 112 m_p [1] = QPoint ( p. x ( ), m_scale. height ( ) - p. y ( ) - 1 );
113 checkPoints ( ); 113 checkPoints ( );
114 update ( ); 114 update ( );
115} 115}
116 116
117QPoint Calibration::endPoint ( ) const 117QPoint Calibration::endPoint ( ) const
118{ 118{
119 return QPoint ( m_p [1]. x ( ), m_scale. height ( ) - m_p [1]. y ( ) - 1 ); 119 return QPoint ( m_p [1]. x ( ), m_scale. height ( ) - m_p [1]. y ( ) - 1 );
120} 120}
121 121
122void Calibration::checkPoints ( ) 122void Calibration::checkPoints ( )
123{ 123{
124 int dx = m_scale. width ( ); 124 int dx = m_scale. width ( );
125 int dy = m_scale. height ( ); 125 int dy = m_scale. height ( );
126 126
127 if ( m_p [1]. x ( ) < 0 ) 127 if ( m_p [1]. x ( ) < 0 )
128 m_p [1]. setX ( 0 ); 128 m_p [1]. setX ( 0 );
129 if ( m_p [1]. x ( ) >= dx ) 129 if ( m_p [1]. x ( ) >= dx )
130 m_p [1]. setX ( dx - 1 ); 130 m_p [1]. setX ( dx - 1 );
131 if ( m_p [0]. x ( ) < 0 ) 131 if ( m_p [0]. x ( ) < 0 )
132 m_p [0]. setX ( 0 ); 132 m_p [0]. setX ( 0 );
133 if ( m_p [0]. x ( ) > m_p [1]. x ( )) 133 if ( m_p [0]. x ( ) > m_p [1]. x ( ))
134 m_p [0]. setX ( m_p [1]. x ( )); 134 m_p [0]. setX ( m_p [1]. x ( ));
135 135
136 if ( m_p [1]. y ( ) < 0 ) 136 if ( m_p [1]. y ( ) < 0 )
137 m_p [1]. setY ( 0 ); 137 m_p [1]. setY ( 0 );
138 if ( m_p [1]. y ( ) >= dy ) 138 if ( m_p [1]. y ( ) >= dy )
139 m_p [1]. setY ( dy - 1 ); 139 m_p [1]. setY ( dy - 1 );
140 if ( m_p [0]. y ( ) < 0 ) 140 if ( m_p [0]. y ( ) < 0 )
141 m_p [0]. setY ( 0 ); 141 m_p [0]. setY ( 0 );
142 if ( m_p [0]. y ( ) > m_p [1]. y ( )) 142 if ( m_p [0]. y ( ) >= dy )
143 m_p [0]. setY ( m_p [1]. y ( )); 143 m_p [0]. setY ( dy - 1 );
144} 144}
145 145
146 146
147#define SCALEX(x) (BRD+(x)*(width()- 2*BRD)/m_scale.width()) 147#define SCALEX(x) (BRD+(x)*(width()- 2*BRD)/m_scale.width())
148#define SCALEY(y) (BRD+(y)*(height()-2*BRD)/m_scale.height()) 148#define SCALEY(y) (BRD+(y)*(height()-2*BRD)/m_scale.height())
149 149
150 150
151static QRect around ( int x, int y ) 151static QRect around ( int x, int y )
152{ 152{
153 return QRect ( x - BRD, y - BRD, 2 * BRD + 1, 2 * BRD + 1 ); 153 return QRect ( x - BRD, y - BRD, 2 * BRD + 1, 2 * BRD + 1 );
154} 154}
155 155
156void Calibration::mousePressEvent ( QMouseEvent *e ) 156void Calibration::mousePressEvent ( QMouseEvent *e )
157{ 157{
158 if ( e-> button ( ) != LeftButton ) 158 if ( e-> button ( ) != LeftButton )
159 return QWidget::mousePressEvent ( e ); 159 return QWidget::mousePressEvent ( e );
160 160
161 int olddragged = m_dragged; 161 int olddragged = m_dragged;
162 int x [2], y [2]; 162 int x [2], y [2];
163 163
164 m_dragged = -1; 164 m_dragged = -1;
165 for ( int i = 0; i < 2; i++ ) { 165 for ( int i = 0; i < 2; i++ ) {
166 x [i] = SCALEX( m_p [i]. x ( )); 166 x [i] = SCALEX( m_p [i]. x ( ));
167 y [i] = SCALEY( m_p [i]. y ( )); 167 y [i] = SCALEY( m_p [i]. y ( ));
168 168
169 if (( QABS( e-> x ( ) - x [i] ) <= 2 * BRD ) && 169 if (( QABS( e-> x ( ) - x [i] ) <= 2 * BRD ) &&
170 ( QABS( e-> y ( ) - y [i] ) <= 2 * BRD )) { 170 ( QABS( e-> y ( ) - y [i] ) <= 2 * BRD )) {
171 m_dragged = i; 171 m_dragged = i;
172 break; 172 break;
173 } 173 }
174 } 174 }
175 175
176 if ( m_dragged != olddragged ) { 176 if ( m_dragged != olddragged ) {
177 QRect r; 177 QRect r;
178 178
179 if ( olddragged >= 0 ) 179 if ( olddragged >= 0 )
180 r |= around ( x [olddragged], y [olddragged] ); 180 r |= around ( x [olddragged], y [olddragged] );
181 if ( m_dragged >= 0 ) 181 if ( m_dragged >= 0 )
182 r |= around ( x [m_dragged], y [m_dragged] ); 182 r |= around ( x [m_dragged], y [m_dragged] );
183 repaint ( r, false ); 183 repaint ( r, false );
184 } 184 }
185} 185}
186 186
187void Calibration::mouseMoveEvent ( QMouseEvent *e ) 187void Calibration::mouseMoveEvent ( QMouseEvent *e )
188{ 188{
189 if ( m_dragged < 0 ) 189 if ( m_dragged < 0 )
190 return; 190 return;
191 191
192 QPoint n [2]; 192 QPoint n [2];
193 193
194 n [m_dragged]. setX (( e-> x ( ) - BRD ) * m_scale. width ( ) / ( width ( ) - 2 * BRD )); 194 n [m_dragged]. setX (( e-> x ( ) - BRD ) * m_scale. width ( ) / ( width ( ) - 2 * BRD ));
195 n [m_dragged]. setY (( e-> y ( ) - BRD ) * m_scale. height ( ) / ( height ( ) - 2 * BRD )); 195 n [m_dragged]. setY (( e-> y ( ) - BRD ) * m_scale. height ( ) / ( height ( ) - 2 * BRD ));
196 n [1 - m_dragged] = m_p [1 - m_dragged]; 196 n [1 - m_dragged] = m_p [1 - m_dragged];
197 197
198 if ( n [m_dragged]. x ( ) < 0 ) 198 if ( n [m_dragged]. x ( ) < 0 )
199 n [m_dragged]. setX ( 0 ); 199 n [m_dragged]. setX ( 0 );
200 if ( n [m_dragged]. x ( ) >= m_scale. width ( )) 200 if ( n [m_dragged]. x ( ) >= m_scale. width ( ))
201 n [m_dragged]. setX ( m_scale. width ( ) - 1 ); 201 n [m_dragged]. setX ( m_scale. width ( ) - 1 );
202 if ( n [0]. x ( ) > n [1]. x ( )) 202 if ( n [0]. x ( ) > n [1]. x ( ))
203 n [m_dragged]. setX ( n [1 - m_dragged]. x ( )); 203 n [m_dragged]. setX ( n [1 - m_dragged]. x ( ));
204 if ( n [m_dragged]. y ( ) < 0 ) 204 if ( n [m_dragged]. y ( ) < 0 )
205 n [m_dragged]. setY ( 0 ); 205 n [m_dragged]. setY ( 0 );
206 if ( n [m_dragged]. y ( ) >= m_scale. height ( )) 206 if ( n [m_dragged]. y ( ) >= m_scale. height ( ))
207 n [m_dragged]. setY ( m_scale. height ( ) - 1 ); 207 n [m_dragged]. setY ( m_scale. height ( ) - 1 );
208 if ( n [0]. y ( ) > n [1]. y ( )) 208 //if ( n [0]. y ( ) > n [1]. y ( ))
209 n [m_dragged]. setY ( n [1 - m_dragged]. y ( )); 209 // n [m_dragged]. setY ( n [1 - m_dragged]. y ( ));
210 210
211 QRect r; 211 QRect r;
212 int ox [2], oy [2], nx [2], ny [2]; 212 int ox [2], oy [2], nx [2], ny [2];
213 213
214 for ( int i = 0; i < 2; i++ ) { 214 for ( int i = 0; i < 2; i++ ) {
215 nx [i] = SCALEX( n [i]. x ( )); 215 nx [i] = SCALEX( n [i]. x ( ));
216 ny [i] = SCALEY( n [i]. y ( )); 216 ny [i] = SCALEY( n [i]. y ( ));
217 ox [i] = SCALEX( m_p [i]. x ( )); 217 ox [i] = SCALEX( m_p [i]. x ( ));
218 oy [i] = SCALEY( m_p [i]. y ( )); 218 oy [i] = SCALEY( m_p [i]. y ( ));
219 219
220 if ( n [i] != m_p [i] ){ 220 if ( n [i] != m_p [i] ){
221 r |= around ( nx [i], ny [i] ); 221 r |= around ( nx [i], ny [i] );
222 r |= around ( ox [i], oy [i] ); 222 r |= around ( ox [i], oy [i] );
223 m_p [i] = n [i]; 223 m_p [i] = n [i];
224 224
225 if ( i == 0 ) { 225 if ( i == 0 ) {
226 r |= QRect ( 0, ny [0], nx [0] - 0 + 1, 1 ); 226 r |= QRect ( 0, ny [0], nx [0] - 0 + 1, 1 );
227 r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); 227 r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 );
228 228
229 emit startPointChanged ( startPoint ( )); 229 emit startPointChanged ( startPoint ( ));
230 } 230 }
231 else if ( i == 1 ) { 231 else if ( i == 1 ) {
232 r |= QRect ( nx [1], ny [1], width ( ) - nx [1], 1 ); 232 r |= QRect ( nx [1], ny [1], width ( ) - nx [1], 1 );
233 r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); 233 r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 );
234 234
235 emit endPointChanged ( endPoint ( )); 235 emit endPointChanged ( endPoint ( ));
236 } 236 }
237 } 237 }
238 } 238 }
239 if ( r. isValid ( )) { 239 if ( r. isValid ( )) {
240 r |= QRect ( nx [0], ny [0], nx [1] - nx [0] + 1, ny [1] - ny [0] + 1 ); 240 r |= QRect ( nx [0], ny [0], nx [1] - nx [0] + 1, ny [1] - ny [0] + 1 ). normalize ( );
241 r |= QRect ( ox [0], oy [0], ox [1] - ox [0] + 1, oy [1] - oy [0] + 1 ); 241 r |= QRect ( ox [0], oy [0], ox [1] - ox [0] + 1, oy [1] - oy [0] + 1 ). normalize ( );
242 242
243 repaint ( r, false ); 243 repaint ( r, false );
244 } 244 }
245} 245}
246 246
247void Calibration::mouseReleaseEvent ( QMouseEvent *e ) 247void Calibration::mouseReleaseEvent ( QMouseEvent *e )
248{ 248{
249 if ( e-> button ( ) != LeftButton ) 249 if ( e-> button ( ) != LeftButton )
250 return QWidget::mouseReleaseEvent ( e ); 250 return QWidget::mouseReleaseEvent ( e );
251 251
252 if ( m_dragged < 0 ) 252 if ( m_dragged < 0 )
253 return; 253 return;
254 254
255 int x = SCALEX( m_p [m_dragged]. x ( )); 255 int x = SCALEX( m_p [m_dragged]. x ( ));
256 int y = SCALEY( m_p [m_dragged]. y ( )); 256 int y = SCALEY( m_p [m_dragged]. y ( ));
257 m_dragged = -1; 257 m_dragged = -1;
258 258
259 repaint ( around ( x, y ), false ); 259 repaint ( around ( x, y ), false );
260} 260}
261 261
262void Calibration::paintEvent ( QPaintEvent *pe ) 262void Calibration::paintEvent ( QPaintEvent *pe )
263{ 263{
264 QPixmap pix ( size ( )); 264 QPixmap pix ( size ( ));
265 QPainter p ( &pix, this ); 265 QPainter p ( &pix, this );
266 QRect cr = pe-> rect ( ); 266 QRect cr = pe-> rect ( );
267 267
268 int x0 = SCALEX( m_p [0]. x ( )); 268 int x0 = SCALEX( m_p [0]. x ( ));
269 int y0 = SCALEY( m_p [0]. y ( )); 269 int y0 = SCALEY( m_p [0]. y ( ));
270 int x1 = SCALEX( m_p [1]. x ( )); 270 int x1 = SCALEX( m_p [1]. x ( ));
271 int y1 = SCALEY( m_p [1]. y ( )); 271 int y1 = SCALEY( m_p [1]. y ( ));
272 272
273 int dx = x1 - x0; 273 int dx = x1 - x0;
274 int dy = y1 - y0; 274 int dy = y1 - y0;
275 275
276 // restrict steps to real x and y resolution 276 // restrict steps to real x and y resolution
277 int st = QMIN( QMIN( m_steps, ( dx + 1 )), ( dy + 1 )); 277 int st = QMIN( QMIN( m_steps, ( dx + 1 )), ( QABS( dy ) + 1 ));
278 278
279 QString stepstr = tr( "%1 Steps" ). arg ( st ); 279 QString stepstr = tr( "%1 Steps" ). arg ( st );
280 QRect tr = p. boundingRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD, AlignTop | AlignRight, stepstr ); 280 QRect tr = p. boundingRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD, AlignTop | AlignRight, stepstr );
281 tr. setLeft ( tr. left ( ) - 20 ); 281 tr. setLeft ( tr. left ( ) - 20 );
282 if ( p. hasClipping ( )) 282 if ( p. hasClipping ( ))
283 p. setClipRegion ( p. clipRegion ( ) | QRegion ( tr )); 283 p. setClipRegion ( p. clipRegion ( ) | QRegion ( tr ));
284 284
285 QColorGroup g = colorGroup ( ); 285 QColorGroup g = colorGroup ( );
286 286
287 p. fillRect ( cr, g. base ( )); 287 p. fillRect ( cr, g. base ( ));
288 p. fillRect ( tr, g. base ( )); 288 p. fillRect ( tr, g. base ( ));
289 289
290 int ex = x0, ey = y0; 290 int ex = x0, ey = y0;
291 291
292 p. setPen ( g. mid ( )); 292 p. setPen ( g. mid ( ));
293 293
294 int gx0 = SCALEX( 0 ); 294 int gx0 = SCALEX( 0 );
295 int gy0 = SCALEY( 0 ); 295 int gy0 = SCALEY( 0 );
296 int gx1 = SCALEX( m_scale. width ( ) - 1 ); 296 int gx1 = SCALEX( m_scale. width ( ) - 1 );
297 int gy1 = SCALEY( m_scale. height ( ) - 1 ); 297 int gy1 = SCALEY( m_scale. height ( ) - 1 );
298 298
299 int xdiv = QMIN( 4, m_scale. width ( )); 299 int xdiv = QMIN( 4, m_scale. width ( ));
300 int ydiv = QMIN( 4, m_scale. height ( )); 300 int ydiv = QMIN( 4, m_scale. height ( ));
301 301
302 xdiv = ( gx1 - gx0 + 1 ) / xdiv; 302 xdiv = ( gx1 - gx0 + 1 ) / xdiv;
303 ydiv = ( gy1 - gy0 + 1 ) / ydiv; 303 ydiv = ( gy1 - gy0 + 1 ) / ydiv;
304 304
305 for ( int i = gx0 + xdiv; i <= ( gx1 - xdiv ); i += xdiv ) 305 for ( int i = gx0 + xdiv; i <= ( gx1 - xdiv ); i += xdiv )
306 p. drawLine ( i, gy0, i, gy1 ); 306 p. drawLine ( i, gy0, i, gy1 );
307 307
308 for ( int i = gy0 + ydiv; i <= ( gy1 - ydiv ); i += ydiv ) 308 for ( int i = gy0 + ydiv; i <= ( gy1 - ydiv ); i += ydiv )
309 p. drawLine ( gx0, i, gx1, i ); 309 p. drawLine ( gx0, i, gx1, i );