summaryrefslogtreecommitdiff
path: root/libopie2/opieui/oselector.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opieui/oselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oselector.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index 5f6f10f..05543c5 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -53,192 +53,194 @@ OXYSelector::OXYSelector( QWidget *parent, const char *name )
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 ( 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;