Diffstat (limited to 'core/settings/light-and-power/calibration.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/settings/light-and-power/calibration.cpp | 109 |
1 files changed, 89 insertions, 20 deletions
diff --git a/core/settings/light-and-power/calibration.cpp b/core/settings/light-and-power/calibration.cpp index 6a3360f..aed2bc8 100644 --- a/core/settings/light-and-power/calibration.cpp +++ b/core/settings/light-and-power/calibration.cpp | |||
@@ -31,8 +31,11 @@ | |||
31 | #include <qpalette.h> | 31 | #include <qpalette.h> |
32 | #include <qpixmap.h> | ||
32 | 33 | ||
33 | #define BRD 2 | 34 | #define BRD 3 |
34 | 35 | ||
35 | Calibration::Calibration ( QWidget *parent, const char *name, WFlags fl ) | 36 | Calibration::Calibration ( QWidget *parent, const char *name, WFlags fl ) |
36 | : QWidget ( parent, name, fl ) | 37 | : QWidget ( parent, name, fl | WRepaintNoErase ) |
37 | { | 38 | { |
39 | setBackgroundMode ( NoBackground ); | ||
40 | |||
38 | m_scale = QSize ( 256, 256 ); | 41 | m_scale = QSize ( 256, 256 ); |
@@ -123,4 +126,8 @@ void Calibration::checkPoints ( ) | |||
123 | 126 | ||
127 | if ( m_p [1]. x ( ) < 0 ) | ||
128 | m_p [1]. setX ( 0 ); | ||
124 | if ( m_p [1]. x ( ) >= dx ) | 129 | if ( m_p [1]. x ( ) >= dx ) |
125 | m_p [1]. setX ( dx - 1 ); | 130 | m_p [1]. setX ( dx - 1 ); |
131 | if ( m_p [0]. x ( ) < 0 ) | ||
132 | m_p [0]. setX ( 0 ); | ||
126 | if ( m_p [0]. x ( ) > m_p [1]. x ( )) | 133 | if ( m_p [0]. x ( ) > m_p [1]. x ( )) |
@@ -128,4 +135,8 @@ void Calibration::checkPoints ( ) | |||
128 | 135 | ||
136 | if ( m_p [1]. y ( ) < 0 ) | ||
137 | m_p [1]. setY ( 0 ); | ||
129 | if ( m_p [1]. y ( ) >= dy ) | 138 | if ( m_p [1]. y ( ) >= dy ) |
130 | m_p [1]. setY ( dy - 1 ); | 139 | m_p [1]. setY ( dy - 1 ); |
140 | if ( m_p [0]. y ( ) < 0 ) | ||
141 | m_p [0]. setY ( 0 ); | ||
131 | if ( m_p [0]. y ( ) > m_p [1]. y ( )) | 142 | if ( m_p [0]. y ( ) > m_p [1]. y ( )) |
@@ -135,4 +146,4 @@ void Calibration::checkPoints ( ) | |||
135 | 146 | ||
136 | #define SCALEX(x) (BRD+x*(width()- 2*BRD)/m_scale.width()) | 147 | #define SCALEX(x) (BRD+(x)*(width()- 2*BRD)/m_scale.width()) |
137 | #define SCALEY(y) (BRD+y*(height()-2*BRD)/m_scale.height()) | 148 | #define SCALEY(y) (BRD+(y)*(height()-2*BRD)/m_scale.height()) |
138 | 149 | ||
@@ -157,4 +168,4 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) | |||
157 | 168 | ||
158 | if (( QABS( e-> x ( ) - x [i] ) <= BRD ) && | 169 | if (( QABS( e-> x ( ) - x [i] ) <= 2 * BRD ) && |
159 | ( QABS( e-> y ( ) - y [i] ) <= BRD )) { | 170 | ( QABS( e-> y ( ) - y [i] ) <= 2 * BRD )) { |
160 | m_dragged = i; | 171 | m_dragged = i; |
@@ -171,3 +182,3 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) | |||
171 | r |= around ( x [m_dragged], y [m_dragged] ); | 182 | r |= around ( x [m_dragged], y [m_dragged] ); |
172 | repaint ( r ); | 183 | repaint ( r, false ); |
173 | } | 184 | } |
@@ -186,6 +197,14 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) | |||
186 | 197 | ||
187 | if (( n [0]. x ( ) > n [1]. x ( )) || ( n [m_dragged]. x ( ) < 0 ) || ( n [m_dragged]. x ( ) >= m_scale. width ( ))) | 198 | if ( n [m_dragged]. x ( ) < 0 ) |
188 | n [m_dragged]. setX ( m_p [m_dragged]. x ( )); | 199 | n [m_dragged]. setX ( 0 ); |
189 | if (( n [0]. y ( ) > n [1]. y ( )) || ( n [m_dragged]. y ( ) < 0 ) || ( n [m_dragged]. y ( ) >= m_scale. height ( ))) | 200 | if ( n [m_dragged]. x ( ) >= m_scale. width ( )) |
190 | n [m_dragged]. setY ( m_p [m_dragged]. y ( )); | 201 | n [m_dragged]. setX ( m_scale. width ( ) - 1 ); |
202 | if ( n [0]. x ( ) > n [1]. x ( )) | ||
203 | n [m_dragged]. setX ( n [1 - m_dragged]. x ( )); | ||
204 | if ( n [m_dragged]. y ( ) < 0 ) | ||
205 | n [m_dragged]. setY ( 0 ); | ||
206 | if ( n [m_dragged]. y ( ) >= m_scale. height ( )) | ||
207 | n [m_dragged]. setY ( m_scale. height ( ) - 1 ); | ||
208 | if ( n [0]. y ( ) > n [1]. y ( )) | ||
209 | n [m_dragged]. setY ( n [1 - m_dragged]. y ( )); | ||
191 | 210 | ||
@@ -208,2 +227,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) | |||
208 | r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); | 227 | r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); |
228 | |||
229 | emit startPointChanged ( startPoint ( )); | ||
209 | } | 230 | } |
@@ -212,2 +233,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) | |||
212 | r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); | 233 | r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); |
234 | |||
235 | emit endPointChanged ( endPoint ( )); | ||
213 | } | 236 | } |
@@ -219,3 +242,3 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) | |||
219 | 242 | ||
220 | repaint ( r ); | 243 | repaint ( r, false ); |
221 | } | 244 | } |
@@ -235,9 +258,10 @@ void Calibration::mouseReleaseEvent ( QMouseEvent *e ) | |||
235 | 258 | ||
236 | repaint ( around ( x, y )); | 259 | repaint ( around ( x, y ), false ); |
237 | } | 260 | } |
238 | 261 | ||
239 | void Calibration::paintEvent ( QPaintEvent * ) | 262 | void Calibration::paintEvent ( QPaintEvent *pe ) |
240 | { | 263 | { |
241 | QPainter p ( this ); | 264 | QPixmap pix ( size ( )); |
242 | QColorGroup g = colorGroup ( ); | 265 | QPainter p ( &pix, this ); |
266 | QRect cr = pe-> rect ( ); | ||
243 | 267 | ||
@@ -251,4 +275,37 @@ void Calibration::paintEvent ( QPaintEvent * ) | |||
251 | 275 | ||
276 | // restrict steps to real x and y resolution | ||
277 | int st = QMIN( QMIN( m_steps, ( dx + 1 )), ( dy + 1 )); | ||
278 | |||
279 | QString stepstr = tr( "%1 Steps" ). arg ( st ); | ||
280 | QRect tr = p. boundingRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD, AlignTop | AlignRight, stepstr ); | ||
281 | tr. setLeft ( tr. left ( ) - 20 ); | ||
282 | if ( p. hasClipping ( )) | ||
283 | p. setClipRegion ( p. clipRegion ( ) | QRegion ( tr )); | ||
284 | |||
285 | QColorGroup g = colorGroup ( ); | ||
286 | |||
287 | p. fillRect ( cr, g. base ( )); | ||
288 | p. fillRect ( tr, g. base ( )); | ||
289 | |||
252 | int ex = x0, ey = y0; | 290 | int ex = x0, ey = y0; |
253 | 291 | ||
292 | p. setPen ( g. mid ( )); | ||
293 | |||
294 | int gx0 = SCALEX( 0 ); | ||
295 | int gy0 = SCALEY( 0 ); | ||
296 | int gx1 = SCALEX( m_scale. width ( ) - 1 ); | ||
297 | int gy1 = SCALEY( m_scale. height ( ) - 1 ); | ||
298 | |||
299 | int xdiv = QMIN( 4, m_scale. width ( )); | ||
300 | int ydiv = QMIN( 4, m_scale. height ( )); | ||
301 | |||
302 | xdiv = ( gx1 - gx0 + 1 ) / xdiv; | ||
303 | ydiv = ( gy1 - gy0 + 1 ) / ydiv; | ||
304 | |||
305 | for ( int i = gx0 + xdiv; i <= ( gx1 - xdiv ); i += xdiv ) | ||
306 | p. drawLine ( i, gy0, i, gy1 ); | ||
307 | |||
308 | for ( int i = gy0 + ydiv; i <= ( gy1 - ydiv ); i += ydiv ) | ||
309 | p. drawLine ( gx0, i, gx1, i ); | ||
310 | |||
254 | p. setPen ( g. highlight ( )); | 311 | p. setPen ( g. highlight ( )); |
@@ -257,5 +314,5 @@ void Calibration::paintEvent ( QPaintEvent * ) | |||
257 | 314 | ||
258 | for ( int i = 1; i < m_steps; i++ ) { | 315 | for ( int i = 1; i < st; i++ ) { |
259 | int fx = x0 + dx * i / m_steps; | 316 | int fx = x0 + dx * i / st; |
260 | int fy = y0 + dy * i / ( m_steps - 1 ); | 317 | int fy = y0 + dy * i / ( st - 1 ); |
261 | 318 | ||
@@ -267,2 +324,6 @@ void Calibration::paintEvent ( QPaintEvent * ) | |||
267 | } | 324 | } |
325 | if ( st == 1 ) { | ||
326 | p. drawLine ( ex, ey, ex, y1 ); | ||
327 | ey = y1; | ||
328 | } | ||
268 | 329 | ||
@@ -270,7 +331,15 @@ void Calibration::paintEvent ( QPaintEvent * ) | |||
270 | 331 | ||
332 | |||
271 | p. fillRect ( around ( x0, y0 ), m_dragged == 0 ? g. highlightedText ( ) : g. text ( )); | 333 | p. fillRect ( around ( x0, y0 ), m_dragged == 0 ? g. highlightedText ( ) : g. text ( )); |
334 | p. drawRect ( around ( x0, y0 )); | ||
272 | p. fillRect ( around ( x1, y1 ), m_dragged == 1 ? g. highlightedText ( ) : g. text ( )); | 335 | p. fillRect ( around ( x1, y1 ), m_dragged == 1 ? g. highlightedText ( ) : g. text ( )); |
336 | p. drawRect ( around ( x1, y1 )); | ||
273 | 337 | ||
274 | p. setPen ( g. text ( )); | 338 | p. setPen ( g. text ( )); |
275 | p. drawText ( QRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD ), AlignTop | AlignRight, tr( "%1 Steps" ). arg ( m_steps )); | 339 | p. drawText ( tr, AlignTop | AlignRight, stepstr ); |
340 | |||
341 | p. end ( ); | ||
342 | bitBlt ( this, cr. topLeft ( ), &pix, cr ); | ||
343 | if ( !cr. contains ( tr )) | ||
344 | bitBlt ( this, tr. topLeft ( ), &pix, tr ); | ||
276 | } | 345 | } |