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
@@ -15,86 +15,88 @@
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20/* QT */ 20/* QT */
21 21
22#include <qimage.h> 22#include <qimage.h>
23#include <qdrawutil.h> 23#include <qdrawutil.h>
24 24
25/* OPIE */ 25/* OPIE */
26 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}
51 53
52 54
53OXYSelector::~OXYSelector() 55OXYSelector::~OXYSelector()
54{} 56{}
55 57
56 58
57void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) 59void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
58{ 60{
59 px = 2; 61 px = 2;
60 py = 2; 62 py = 2;
61 minX = _minX; 63 minX = _minX;
62 minY = _minY; 64 minY = _minY;
63 maxX = _maxX; 65 maxX = _maxX;
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
89{ 91{
90 return QRect( 2, 2, width()-4, height()-4 ); 92 return QRect( 2, 2, width()-4, height()-4 );
91} 93}
92 94
93void OXYSelector::paintEvent( QPaintEvent *ev ) 95void OXYSelector::paintEvent( QPaintEvent *ev )
94{ 96{
95 QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); 97 QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2);
96 QRect paintRect = ev->rect(); 98 QRect paintRect = ev->rect();
97 99
98 QPainter painter; 100 QPainter painter;
99 painter.begin( this ); 101 painter.begin( this );
100 102
@@ -237,82 +239,82 @@ QRect OSelector::contentsRect() const
237 return QRect( 5, 2, width()-10, height()-9 ); 239 return QRect( 5, 2, width()-10, height()-9 );
238} 240}
239 241
240void OSelector::paintEvent( QPaintEvent * ) 242void OSelector::paintEvent( QPaintEvent * )
241{ 243{
242 QPainter painter; 244 QPainter painter;
243 245
244 painter.begin( this ); 246 painter.begin( this );
245 247
246 drawContents( &painter ); 248 drawContents( &painter );
247 249
248 QBrush brush; 250 QBrush brush;
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() );
274} 276}
275 277
276void OSelector::wheelEvent( QWheelEvent *e ) 278void OSelector::wheelEvent( QWheelEvent *e )
277{ 279{
278 int val = value() + e->delta()/120; 280 int val = value() + e->delta()/120;
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
307 val = ( maxValue() - minValue() ) * (width()-pos.x()-3) 309 val = ( maxValue() - minValue() ) * (width()-pos.x()-3)
308 / (width()-10) + minValue(); 310 / (width()-10) + minValue();
309 311
310 if ( val > maxValue() ) 312 if ( val > maxValue() )
311 val = maxValue(); 313 val = maxValue();
312 if ( val < minValue() ) 314 if ( val < minValue() )
313 val = minValue(); 315 val = minValue();
314 316
315 emit valueChanged( val ); 317 emit valueChanged( val );
316 setValue( val ); 318 setValue( val );
317} 319}
318 320
@@ -340,88 +342,88 @@ void OSelector::drawContents( QPainter * )
340{} 342{}
341 343
342void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) 344void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
343{ 345{
344 if ( show ) 346 if ( show )
345 { 347 {
346 QPointArray array(3); 348 QPointArray array(3);
347 349
348 painter->setPen( QPen() ); 350 painter->setPen( QPen() );
349 painter->setBrush( QBrush( colorGroup().buttonText() ) ); 351 painter->setBrush( QBrush( colorGroup().buttonText() ) );
350 if ( orientation() == Vertical ) 352 if ( orientation() == Vertical )
351 { 353 {
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
378//---------------------------------------------------------------------------- 380//----------------------------------------------------------------------------
379 381
380OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) 382OGradientSelector::OGradientSelector( QWidget *parent, const char *name )
381 : OSelector( parent, name ) 383 : OSelector( parent, name )
382{ 384{
383 init(); 385 init();
384} 386}
385 387
386 388
387OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, 389OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
388 const char *name ) 390 const char *name )
389 : OSelector( o, parent, name ) 391 : OSelector( o, parent, name )
390{ 392{
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();
416 int greenDiff = color2.green() - color1.green(); 418 int greenDiff = color2.green() - color1.green();
417 int blueDiff = color2.blue() - color1.blue(); 419 int blueDiff = color2.blue() - color1.blue();
418 420
419 if ( orientation() == Vertical ) 421 if ( orientation() == Vertical )
420 { 422 {
421 for ( int y = 0; y < image.height(); y++ ) 423 for ( int y = 0; y < image.height(); y++ )
422 { 424 {
423 scale = 1.0 * y / image.height(); 425 scale = 1.0 * y / image.height();
424 col.setRgb( color1.red() + int(redDiff*scale), 426 col.setRgb( color1.red() + int(redDiff*scale),
425 color1.green() + int(greenDiff*scale), 427 color1.green() + int(greenDiff*scale),
426 color1.blue() + int(blueDiff*scale) ); 428 color1.blue() + int(blueDiff*scale) );
427 429
@@ -451,49 +453,49 @@ void OGradientSelector::drawContents( QPainter *painter )
451 QColor ditherPalette[8]; 453 QColor ditherPalette[8];
452 454
453 for ( int s = 0; s < 8; s++ ) 455 for ( int s = 0; s < 8; s++ )
454 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, 456 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
455 color1.green() + greenDiff * s / 8, 457 color1.green() + greenDiff * s / 8,
456 color1.blue() + blueDiff * s / 8 ); 458 color1.blue() + blueDiff * s / 8 );
457 459
458 OImageEffect::dither( image, ditherPalette, 8 ); 460 OImageEffect::dither( image, ditherPalette, 8 );
459 461
460 QPixmap p; 462 QPixmap p;
461 p.convertFromImage( image ); 463 p.convertFromImage( image );
462 464
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 );
488 490
489 pen.setColor( color1 ); 491 pen.setColor( color1 );
490 painter->setPen( pen ); 492 painter->setPen( pen );
491 painter->drawText( contentsRect().right() - 493 painter->drawText( contentsRect().right() -
492 painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); 494 painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
493 } 495 }
494} 496}
495 497
496//----------------------------------------------------------------------------- 498//-----------------------------------------------------------------------------
497 499
498static QColor *standardPalette = 0; 500static QColor *standardPalette = 0;
499 501