Diffstat (limited to 'libopie2/opieui/oselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/oselector.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp index 05543c5..936dfe6 100644 --- a/libopie2/opieui/oselector.cpp +++ b/libopie2/opieui/oselector.cpp @@ -14,257 +14,257 @@ You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* QT */ #include <qimage.h> #include <qdrawutil.h> /* OPIE */ #include <opie2/oimageeffect.h> #include <opie2/oselector.h> #define STORE_W 8 #define STORE_W2 STORE_W * 2 //----------------------------------------------------------------------------- /* * 2D value selector. * The contents of the selector are drawn by derived class. */ using namespace Opie::Ui; OXYSelector::OXYSelector( QWidget *parent, const char *name ) : QWidget( parent, name ) { xPos = 0; yPos = 0; minX = 0; minY = 0; maxX = 100; maxY = 100; store.setOptimization( QPixmap::BestOptim ); store.resize( STORE_W2, STORE_W2 ); } OXYSelector::~OXYSelector() {} void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) { px = 2; py = 2; minX = _minX; minY = _minY; maxX = _maxX; maxY = _maxY; } void OXYSelector::setValues( int _xPos, int _yPos ) { xPos = _xPos; yPos = _yPos; if ( xPos > maxX ) xPos = maxX; else if ( xPos < minX ) xPos = minX; if ( yPos > maxY ) yPos = maxY; else if ( yPos < minY ) yPos = minY; int xp = 2 + (width() - 4) * xPos / (maxX - minX); int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); setPosition( xp, yp ); } QRect OXYSelector::contentsRect() const { return QRect( 2, 2, width()-4, height()-4 ); } void OXYSelector::paintEvent( QPaintEvent *ev ) { QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); QRect paintRect = ev->rect(); QPainter painter; painter.begin( this ); QBrush brush; qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), TRUE, 2, &brush ); drawContents( &painter ); if (paintRect.contains(cursorRect)) { bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, STORE_W2, STORE_W2, CopyROP ); drawCursor( &painter, px, py ); } else if (paintRect.intersects(cursorRect)) { repaint( cursorRect, false); } painter.end(); } void OXYSelector::mousePressEvent( QMouseEvent *e ) { int xVal, yVal; valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); setValues( xVal, yVal ); emit valueChanged( xPos, yPos ); } void OXYSelector::mouseMoveEvent( QMouseEvent *e ) { int xVal, yVal; valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); setValues( xVal, yVal ); emit valueChanged( xPos, yPos ); } void OXYSelector::wheelEvent( QWheelEvent *e ) { - #if QT_VERSION > 290 + #if QT_VERSION >= 0x030000 if ( e->orientation() == Qt::Horizontal ) setValues( xValue() + e->delta()/120, yValue() ); else setValues( xValue(), yValue() + e->delta()/120 ); emit valueChanged( xPos, yPos ); #else Q_UNUSED( e ) #endif } void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const { xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); if ( xVal > maxX ) xVal = maxX; else if ( xVal < minX ) xVal = minX; if ( yVal > maxY ) yVal = maxY; else if ( yVal < minY ) yVal = minY; } void OXYSelector::setPosition( int xp, int yp ) { if ( xp < 2 ) xp = 2; else if ( xp > width() - 2 ) xp = width() - 2; if ( yp < 2 ) yp = 2; else if ( yp > height() - 2 ) yp = height() - 2; QPainter painter; painter.begin( this ); bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, STORE_W2, STORE_W2, CopyROP ); bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, STORE_W2, STORE_W2, CopyROP ); drawCursor( &painter, xp, yp ); px = xp; py = yp; painter.end(); } void OXYSelector::drawContents( QPainter * ) {} void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) { p->setPen( QPen( white ) ); p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); } //----------------------------------------------------------------------------- /* * 1D value selector with contents drawn by derived class. * See OColorDialog for example. */ OSelector::OSelector( QWidget *parent, const char *name ) : QWidget( parent, name ), QRangeControl() { _orientation = Horizontal; _indent = TRUE; } OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) : QWidget( parent, name ), QRangeControl() { _orientation = o; _indent = TRUE; } OSelector::~OSelector() {} QRect OSelector::contentsRect() const { if ( orientation() == Vertical ) return QRect( 2, 5, width()-9, height()-10 ); else return QRect( 5, 2, width()-10, height()-9 ); } void OSelector::paintEvent( QPaintEvent * ) { QPainter painter; painter.begin( this ); drawContents( &painter ); QBrush brush; if ( indent() ) { if ( orientation() == Vertical ) qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, colorGroup(), TRUE, 2, &brush ); else qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, colorGroup(), TRUE, 2, &brush ); } QPoint pos = calcArrowPos( value() ); drawArrow( &painter, TRUE, pos ); painter.end(); } void OSelector::mousePressEvent( QMouseEvent *e ) |