Diffstat (limited to 'core/settings/light-and-power/calibration.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/light-and-power/calibration.cpp | 111 |
1 files changed, 90 insertions, 21 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 @@ #include <qpalette.h> +#include <qpixmap.h> -#define BRD 2 +#define BRD 3 Calibration::Calibration ( QWidget *parent, const char *name, WFlags fl ) - : QWidget ( parent, name, fl ) + : QWidget ( parent, name, fl | WRepaintNoErase ) { + setBackgroundMode ( NoBackground ); + m_scale = QSize ( 256, 256 ); @@ -123,4 +126,8 @@ void Calibration::checkPoints ( ) + if ( m_p [1]. x ( ) < 0 ) + m_p [1]. setX ( 0 ); if ( m_p [1]. x ( ) >= dx ) m_p [1]. setX ( dx - 1 ); + if ( m_p [0]. x ( ) < 0 ) + m_p [0]. setX ( 0 ); if ( m_p [0]. x ( ) > m_p [1]. x ( )) @@ -128,4 +135,8 @@ void Calibration::checkPoints ( ) + if ( m_p [1]. y ( ) < 0 ) + m_p [1]. setY ( 0 ); if ( m_p [1]. y ( ) >= dy ) m_p [1]. setY ( dy - 1 ); + if ( m_p [0]. y ( ) < 0 ) + m_p [0]. setY ( 0 ); if ( m_p [0]. y ( ) > m_p [1]. y ( )) @@ -135,4 +146,4 @@ void Calibration::checkPoints ( ) -#define SCALEX(x) (BRD+x*(width()- 2*BRD)/m_scale.width()) -#define SCALEY(y) (BRD+y*(height()-2*BRD)/m_scale.height()) +#define SCALEX(x) (BRD+(x)*(width()- 2*BRD)/m_scale.width()) +#define SCALEY(y) (BRD+(y)*(height()-2*BRD)/m_scale.height()) @@ -157,4 +168,4 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) - if (( QABS( e-> x ( ) - x [i] ) <= BRD ) && - ( QABS( e-> y ( ) - y [i] ) <= BRD )) { + if (( QABS( e-> x ( ) - x [i] ) <= 2 * BRD ) && + ( QABS( e-> y ( ) - y [i] ) <= 2 * BRD )) { m_dragged = i; @@ -171,3 +182,3 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) r |= around ( x [m_dragged], y [m_dragged] ); - repaint ( r ); + repaint ( r, false ); } @@ -186,6 +197,14 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) - if (( n [0]. x ( ) > n [1]. x ( )) || ( n [m_dragged]. x ( ) < 0 ) || ( n [m_dragged]. x ( ) >= m_scale. width ( ))) - n [m_dragged]. setX ( m_p [m_dragged]. x ( )); - if (( n [0]. y ( ) > n [1]. y ( )) || ( n [m_dragged]. y ( ) < 0 ) || ( n [m_dragged]. y ( ) >= m_scale. height ( ))) - n [m_dragged]. setY ( m_p [m_dragged]. y ( )); + if ( n [m_dragged]. x ( ) < 0 ) + n [m_dragged]. setX ( 0 ); + if ( n [m_dragged]. x ( ) >= m_scale. width ( )) + n [m_dragged]. setX ( m_scale. width ( ) - 1 ); + if ( n [0]. x ( ) > n [1]. x ( )) + n [m_dragged]. setX ( n [1 - m_dragged]. x ( )); + if ( n [m_dragged]. y ( ) < 0 ) + n [m_dragged]. setY ( 0 ); + if ( n [m_dragged]. y ( ) >= m_scale. height ( )) + n [m_dragged]. setY ( m_scale. height ( ) - 1 ); + if ( n [0]. y ( ) > n [1]. y ( )) + n [m_dragged]. setY ( n [1 - m_dragged]. y ( )); @@ -208,2 +227,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); + + emit startPointChanged ( startPoint ( )); } @@ -212,2 +233,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); + + emit endPointChanged ( endPoint ( )); } @@ -219,3 +242,3 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) - repaint ( r ); + repaint ( r, false ); } @@ -235,10 +258,11 @@ void Calibration::mouseReleaseEvent ( QMouseEvent *e ) - repaint ( around ( x, y )); + repaint ( around ( x, y ), false ); } -void Calibration::paintEvent ( QPaintEvent * ) +void Calibration::paintEvent ( QPaintEvent *pe ) { - QPainter p ( this ); - QColorGroup g = colorGroup ( ); - + QPixmap pix ( size ( )); + QPainter p ( &pix, this ); + QRect cr = pe-> rect ( ); + int x0 = SCALEX( m_p [0]. x ( )); @@ -251,4 +275,37 @@ void Calibration::paintEvent ( QPaintEvent * ) + // restrict steps to real x and y resolution + int st = QMIN( QMIN( m_steps, ( dx + 1 )), ( dy + 1 )); + + QString stepstr = tr( "%1 Steps" ). arg ( st ); + QRect tr = p. boundingRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD, AlignTop | AlignRight, stepstr ); + tr. setLeft ( tr. left ( ) - 20 ); + if ( p. hasClipping ( )) + p. setClipRegion ( p. clipRegion ( ) | QRegion ( tr )); + + QColorGroup g = colorGroup ( ); + + p. fillRect ( cr, g. base ( )); + p. fillRect ( tr, g. base ( )); + int ex = x0, ey = y0; + p. setPen ( g. mid ( )); + + int gx0 = SCALEX( 0 ); + int gy0 = SCALEY( 0 ); + int gx1 = SCALEX( m_scale. width ( ) - 1 ); + int gy1 = SCALEY( m_scale. height ( ) - 1 ); + + int xdiv = QMIN( 4, m_scale. width ( )); + int ydiv = QMIN( 4, m_scale. height ( )); + + xdiv = ( gx1 - gx0 + 1 ) / xdiv; + ydiv = ( gy1 - gy0 + 1 ) / ydiv; + + for ( int i = gx0 + xdiv; i <= ( gx1 - xdiv ); i += xdiv ) + p. drawLine ( i, gy0, i, gy1 ); + + for ( int i = gy0 + ydiv; i <= ( gy1 - ydiv ); i += ydiv ) + p. drawLine ( gx0, i, gx1, i ); + p. setPen ( g. highlight ( )); @@ -257,5 +314,5 @@ void Calibration::paintEvent ( QPaintEvent * ) - for ( int i = 1; i < m_steps; i++ ) { - int fx = x0 + dx * i / m_steps; - int fy = y0 + dy * i / ( m_steps - 1 ); + for ( int i = 1; i < st; i++ ) { + int fx = x0 + dx * i / st; + int fy = y0 + dy * i / ( st - 1 ); @@ -267,2 +324,6 @@ void Calibration::paintEvent ( QPaintEvent * ) } + if ( st == 1 ) { + p. drawLine ( ex, ey, ex, y1 ); + ey = y1; + } @@ -270,7 +331,15 @@ void Calibration::paintEvent ( QPaintEvent * ) + p. fillRect ( around ( x0, y0 ), m_dragged == 0 ? g. highlightedText ( ) : g. text ( )); + p. drawRect ( around ( x0, y0 )); p. fillRect ( around ( x1, y1 ), m_dragged == 1 ? g. highlightedText ( ) : g. text ( )); + p. drawRect ( around ( x1, y1 )); p. setPen ( g. text ( )); - p. drawText ( QRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD ), AlignTop | AlignRight, tr( "%1 Steps" ). arg ( m_steps )); + p. drawText ( tr, AlignTop | AlignRight, stepstr ); + + p. end ( ); + bitBlt ( this, cr. topLeft ( ), &pix, cr ); + if ( !cr. contains ( tr )) + bitBlt ( this, tr. topLeft ( ), &pix, tr ); } |