summaryrefslogtreecommitdiff
path: root/libopie2/opieui/oselector.cpp
Unidiff
Diffstat (limited to 'libopie2/opieui/oselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oselector.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index 23b3ce3..5f6f10f 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -27,24 +27,26 @@
27#include <opie2/oimageeffect.h> 27#include <opie2/oimageeffect.h>
28#include <opie2/oselector.h> 28#include <opie2/oselector.h>
29 29
30#define STORE_W 8 30#define STORE_W 8
31#define STORE_W2 STORE_W * 2 31#define STORE_W2 STORE_W * 2
32 32
33//----------------------------------------------------------------------------- 33//-----------------------------------------------------------------------------
34/* 34/*
35 * 2D value selector. 35 * 2D value selector.
36 * The contents of the selector are drawn by derived class. 36 * The contents of the selector are drawn by derived class.
37 */ 37 */
38 38
39using namespace Opie::Ui;
40
39OXYSelector::OXYSelector( QWidget *parent, const char *name ) 41OXYSelector::OXYSelector( QWidget *parent, const char *name )
40 : QWidget( parent, name ) 42 : QWidget( parent, name )
41{ 43{
42 xPos = 0; 44 xPos = 0;
43 yPos = 0; 45 yPos = 0;
44 minX = 0; 46 minX = 0;
45 minY = 0; 47 minY = 0;
46 maxX = 100; 48 maxX = 100;
47 maxY = 100; 49 maxY = 100;
48 store.setOptimization( QPixmap::BestOptim ); 50 store.setOptimization( QPixmap::BestOptim );
49 store.resize( STORE_W2, STORE_W2 ); 51 store.resize( STORE_W2, STORE_W2 );
50} 52}
@@ -64,25 +66,25 @@ void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
64 maxY = _maxY; 66 maxY = _maxY;
65} 67}
66 68
67void OXYSelector::setValues( int _xPos, int _yPos ) 69void OXYSelector::setValues( int _xPos, int _yPos )
68{ 70{
69 xPos = _xPos; 71 xPos = _xPos;
70 yPos = _yPos; 72 yPos = _yPos;
71 73
72 if ( xPos > maxX ) 74 if ( xPos > maxX )
73 xPos = maxX; 75 xPos = maxX;
74 else if ( xPos < minX ) 76 else if ( xPos < minX )
75 xPos = minX; 77 xPos = minX;
76 78
77 if ( yPos > maxY ) 79 if ( yPos > maxY )
78 yPos = maxY; 80 yPos = maxY;
79 else if ( yPos < minY ) 81 else if ( yPos < minY )
80 yPos = minY; 82 yPos = minY;
81 83
82 int xp = 2 + (width() - 4) * xPos / (maxX - minX); 84 int xp = 2 + (width() - 4) * xPos / (maxX - minX);
83 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); 85 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY);
84 86
85 setPosition( xp, yp ); 87 setPosition( xp, yp );
86} 88}
87 89
88QRect OXYSelector::contentsRect() const 90QRect OXYSelector::contentsRect() const
@@ -249,25 +251,25 @@ void OSelector::paintEvent( QPaintEvent * )
249 251
250 if ( indent() ) 252 if ( indent() )
251 { 253 {
252 if ( orientation() == Vertical ) 254 if ( orientation() == Vertical )
253 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, 255 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6,
254 colorGroup(), TRUE, 2, &brush ); 256 colorGroup(), TRUE, 2, &brush );
255 else 257 else
256 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, 258 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5,
257 colorGroup(), TRUE, 2, &brush ); 259 colorGroup(), TRUE, 2, &brush );
258 } 260 }
259 261
260 QPoint pos = calcArrowPos( value() ); 262 QPoint pos = calcArrowPos( value() );
261 drawArrow( &painter, TRUE, pos ); 263 drawArrow( &painter, TRUE, pos );
262 264
263 painter.end(); 265 painter.end();
264} 266}
265 267
266void OSelector::mousePressEvent( QMouseEvent *e ) 268void OSelector::mousePressEvent( QMouseEvent *e )
267{ 269{
268 moveArrow( e->pos() ); 270 moveArrow( e->pos() );
269} 271}
270 272
271void OSelector::mouseMoveEvent( QMouseEvent *e ) 273void OSelector::mouseMoveEvent( QMouseEvent *e )
272{ 274{
273 moveArrow( e->pos() ); 275 moveArrow( e->pos() );
@@ -279,28 +281,28 @@ void OSelector::wheelEvent( QWheelEvent *e )
279 emit valueChanged( val ); 281 emit valueChanged( val );
280 setValue( val ); 282 setValue( val );
281} 283}
282 284
283void OSelector::valueChange() 285void OSelector::valueChange()
284{ 286{
285 QPainter painter; 287 QPainter painter;
286 QPoint pos; 288 QPoint pos;
287 289
288 painter.begin( this ); 290 painter.begin( this );
289 291
290 pos = calcArrowPos( prevValue() ); 292 pos = calcArrowPos( prevValue() );
291 drawArrow( &painter, FALSE, pos ); 293 drawArrow( &painter, FALSE, pos );
292 294
293 pos = calcArrowPos( value() ); 295 pos = calcArrowPos( value() );
294 drawArrow( &painter, TRUE, pos ); 296 drawArrow( &painter, TRUE, pos );
295 297
296 painter.end(); 298 painter.end();
297} 299}
298 300
299void OSelector::moveArrow( const QPoint &pos ) 301void OSelector::moveArrow( const QPoint &pos )
300{ 302{
301 int val; 303 int val;
302 304
303 if ( orientation() == Vertical ) 305 if ( orientation() == Vertical )
304 val = ( maxValue() - minValue() ) * (height()-pos.y()-3) 306 val = ( maxValue() - minValue() ) * (height()-pos.y()-3)
305 / (height()-10) + minValue(); 307 / (height()-10) + minValue();
306 else 308 else
@@ -352,26 +354,26 @@ void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
352 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 354 array.setPoint( 0, pos.x()+0, pos.y()+0 );
353 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 355 array.setPoint( 1, pos.x()+5, pos.y()+5 );
354 array.setPoint( 2, pos.x()+5, pos.y()-5 ); 356 array.setPoint( 2, pos.x()+5, pos.y()-5 );
355 } 357 }
356 else 358 else
357 { 359 {
358 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 360 array.setPoint( 0, pos.x()+0, pos.y()+0 );
359 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 361 array.setPoint( 1, pos.x()+5, pos.y()+5 );
360 array.setPoint( 2, pos.x()-5, pos.y()+5 ); 362 array.setPoint( 2, pos.x()-5, pos.y()+5 );
361 } 363 }
362 364
363 painter->drawPolygon( array ); 365 painter->drawPolygon( array );
364 } 366 }
365 else 367 else
366 { 368 {
367 if ( orientation() == Vertical ) 369 if ( orientation() == Vertical )
368 { 370 {
369 repaint(pos.x(), pos.y()-5, 6, 11, true); 371 repaint(pos.x(), pos.y()-5, 6, 11, true);
370 } 372 }
371 else 373 else
372 { 374 {
373 repaint(pos.x()-5, pos.y(), 11, 6, true); 375 repaint(pos.x()-5, pos.y(), 11, 6, true);
374 } 376 }
375 } 377 }
376} 378}
377 379
@@ -391,25 +393,25 @@ OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
391 init(); 393 init();
392} 394}
393 395
394 396
395OGradientSelector::~OGradientSelector() 397OGradientSelector::~OGradientSelector()
396{} 398{}
397 399
398 400
399void OGradientSelector::init() 401void OGradientSelector::init()
400{ 402{
401 color1.setRgb( 0, 0, 0 ); 403 color1.setRgb( 0, 0, 0 );
402 color2.setRgb( 255, 255, 255 ); 404 color2.setRgb( 255, 255, 255 );
403 405
404 text1 = text2 = ""; 406 text1 = text2 = "";
405} 407}
406 408
407 409
408void OGradientSelector::drawContents( QPainter *painter ) 410void OGradientSelector::drawContents( QPainter *painter )
409{ 411{
410 QImage image( contentsRect().width(), contentsRect().height(), 32 ); 412 QImage image( contentsRect().width(), contentsRect().height(), 32 );
411 413
412 QColor col; 414 QColor col;
413 float scale; 415 float scale;
414 416
415 int redDiff = color2.red() - color1.red(); 417 int redDiff = color2.red() - color1.red();
@@ -463,25 +465,25 @@ void OGradientSelector::drawContents( QPainter *painter )
463 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); 465 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p );
464 466
465 if ( orientation() == Vertical ) 467 if ( orientation() == Vertical )
466 { 468 {
467 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; 469 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2;
468 int xPos = contentsRect().left() + (contentsRect().width() - 470 int xPos = contentsRect().left() + (contentsRect().width() -
469 painter->fontMetrics().width( text2 )) / 2; 471 painter->fontMetrics().width( text2 )) / 2;
470 QPen pen( color2 ); 472 QPen pen( color2 );
471 painter->setPen( pen ); 473 painter->setPen( pen );
472 painter->drawText( xPos, yPos, text2 ); 474 painter->drawText( xPos, yPos, text2 );
473 475
474 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; 476 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2;
475 xPos = contentsRect().left() + (contentsRect().width() - 477 xPos = contentsRect().left() + (contentsRect().width() -
476 painter->fontMetrics().width( text1 )) / 2; 478 painter->fontMetrics().width( text1 )) / 2;
477 pen.setColor( color1 ); 479 pen.setColor( color1 );
478 painter->setPen( pen ); 480 painter->setPen( pen );
479 painter->drawText( xPos, yPos, text1 ); 481 painter->drawText( xPos, yPos, text1 );
480 } 482 }
481 else 483 else
482 { 484 {
483 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; 485 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2;
484 486
485 QPen pen( color2 ); 487 QPen pen( color2 );
486 painter->setPen( pen ); 488 painter->setPen( pen );
487 painter->drawText( contentsRect().left() + 2, yPos, text1 ); 489 painter->drawText( contentsRect().left() + 2, yPos, text1 );