summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/colordialog.cpp851
-rw-r--r--noncore/graphics/drawpad/colordialog.h77
-rw-r--r--noncore/graphics/drawpad/colorpanel.cpp120
-rw-r--r--noncore/graphics/drawpad/colorpanel.h62
4 files changed, 0 insertions, 1110 deletions
diff --git a/noncore/graphics/drawpad/colordialog.cpp b/noncore/graphics/drawpad/colordialog.cpp
deleted file mode 100644
index 6d72ff6..0000000
--- a/noncore/graphics/drawpad/colordialog.cpp
+++ b/dev/null
@@ -1,851 +0,0 @@
1/****************************************************************************
2** $Id$
3**
4** Implementation of QColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "colordialog.h"
39
40#include "qpainter.h"
41#include "qlayout.h"
42#include "qlabel.h"
43#include "qpushbutton.h"
44#include "qlineedit.h"
45#include "qimage.h"
46#include "qpixmap.h"
47#include "qdrawutil.h"
48#include "qvalidator.h"
49#include "qdragobject.h"
50#include "qapplication.h"
51#include "qdragobject.h"
52
53static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
54{
55 QColor c;
56 c.setRgb( rgb );
57 c.getHsv(h,s,v);
58}
59
60class QColorPicker : public QFrame
61{
62 Q_OBJECT
63public:
64 QColorPicker(QWidget* parent=0, const char* name=0);
65 ~QColorPicker();
66
67public slots:
68 void setCol( int h, int s );
69
70signals:
71 void newCol( int h, int s );
72
73protected:
74 QSize sizeHint() const;
75 QSizePolicy sizePolicy() const;
76 void drawContents(QPainter* p);
77 void mouseMoveEvent( QMouseEvent * );
78 void mousePressEvent( QMouseEvent * );
79
80private:
81 int hue;
82 int sat;
83
84 QPoint colPt();
85 int huePt( const QPoint &pt );
86 int satPt( const QPoint &pt );
87 void setCol( const QPoint &pt );
88
89 QPixmap *pix;
90};
91
92static int pWidth = 200;
93static int pHeight = 200;
94
95class QColorLuminancePicker : public QWidget
96{
97 Q_OBJECT
98public:
99 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
100 ~QColorLuminancePicker();
101
102public slots:
103 void setCol( int h, int s, int v );
104 void setCol( int h, int s );
105
106signals:
107 void newHsv( int h, int s, int v );
108
109protected:
110// QSize sizeHint() const;
111// QSizePolicy sizePolicy() const;
112 void paintEvent( QPaintEvent*);
113 void mouseMoveEvent( QMouseEvent * );
114 void mousePressEvent( QMouseEvent * );
115
116private:
117 enum { foff = 3, coff = 4 }; //frame and contents offset
118 int val;
119 int hue;
120 int sat;
121
122 int y2val( int y );
123 int val2y( int val );
124 void setVal( int v );
125
126 QPixmap *pix;
127};
128
129
130int QColorLuminancePicker::y2val( int y )
131{
132 int d = height() - 2*coff - 1;
133 return 255 - (y - coff)*255/d;
134}
135
136int QColorLuminancePicker::val2y( int v )
137{
138 int d = height() - 2*coff - 1;
139 return coff + (255-v)*d/255;
140}
141
142QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
143 const char* name)
144 :QWidget( parent, name )
145{
146 hue = 100; val = 100; sat = 100;
147 pix = 0;
148 // setBackgroundMode( NoBackground );
149}
150
151QColorLuminancePicker::~QColorLuminancePicker()
152{
153 delete pix;
154}
155
156void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
157{
158 setVal( y2val(m->y()) );
159}
160void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
161{
162 setVal( y2val(m->y()) );
163}
164
165void QColorLuminancePicker::setVal( int v )
166{
167 if ( val == v )
168 return;
169 val = QMAX( 0, QMIN(v,255));
170 delete pix; pix=0;
171 repaint( FALSE ); //###
172 emit newHsv( hue, sat, val );
173}
174
175//receives from a hue,sat chooser and relays.
176void QColorLuminancePicker::setCol( int h, int s )
177{
178 setCol( h, s, val );
179 emit newHsv( h, s, val );
180}
181
182void QColorLuminancePicker::paintEvent( QPaintEvent * )
183{
184 int w = width() - 5;
185
186 QRect r( 0, foff, w, height() - 2*foff );
187 int wi = r.width() - 2;
188 int hi = r.height() - 2;
189 if ( !pix || pix->height() != hi || pix->width() != wi ) {
190 delete pix;
191 QImage img( wi, hi, 32 );
192 int y;
193 for ( y = 0; y < hi; y++ ) {
194 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
195 QRgb r = c.rgb();
196 int x;
197 for ( x = 0; x < wi; x++ )
198 img.setPixel( x, y, r );
199 }
200 pix = new QPixmap;
201 pix->convertFromImage(img);
202 }
203 QPainter p(this);
204 p.drawPixmap( 1, coff, *pix );
205 QColorGroup g = colorGroup();
206 qDrawShadePanel( &p, r, g, TRUE );
207 p.setPen( g.foreground() );
208 p.setBrush( g.foreground() );
209 QPointArray a;
210 int y = val2y(val);
211 a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 );
212 erase( w, 0, 5, height() );
213 p.drawPolygon( a );
214}
215
216void QColorLuminancePicker::setCol( int h, int s , int v )
217{
218 val = v;
219 hue = h;
220 sat = s;
221 delete pix; pix=0;
222 repaint( FALSE );//####
223}
224
225QPoint QColorPicker::colPt()
226{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); }
227int QColorPicker::huePt( const QPoint &pt )
228{ return 360 - pt.x()*360/(pWidth-1); }
229int QColorPicker::satPt( const QPoint &pt )
230{ return 255 - pt.y()*255/(pHeight-1) ; }
231void QColorPicker::setCol( const QPoint &pt )
232{ setCol( huePt(pt), satPt(pt) ); }
233
234QColorPicker::QColorPicker(QWidget* parent, const char* name )
235 : QFrame( parent, name )
236{
237 hue = 0; sat = 0;
238 setCol( 150, 255 );
239
240 QImage img( pWidth, pHeight, 32 );
241 int x,y;
242 for ( y = 0; y < pHeight; y++ )
243 for ( x = 0; x < pWidth; x++ ) {
244 QPoint p( x, y );
245 img.setPixel( x, y, QColor(huePt(p), satPt(p),
246 200, QColor::Hsv).rgb() );
247 }
248 pix = new QPixmap;
249 pix->convertFromImage(img);
250 setBackgroundMode( NoBackground );
251}
252
253QColorPicker::~QColorPicker()
254{
255 delete pix;
256}
257
258QSize QColorPicker::sizeHint() const
259{
260 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
261}
262
263QSizePolicy QColorPicker::sizePolicy() const
264{
265 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
266}
267
268void QColorPicker::setCol( int h, int s )
269{
270 int nhue = QMIN( QMAX(0,h), 360 );
271 int nsat = QMIN( QMAX(0,s), 255);
272 if ( nhue == hue && nsat == sat )
273 return;
274 QRect r( colPt(), QSize(20,20) );
275 hue = nhue; sat = nsat;
276 r = r.unite( QRect( colPt(), QSize(20,20) ) );
277 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
278 // update( r );
279 repaint( r, FALSE );
280}
281
282void QColorPicker::mouseMoveEvent( QMouseEvent *m )
283{
284 QPoint p = m->pos() - contentsRect().topLeft();
285 setCol( p );
286 emit newCol( hue, sat );
287}
288
289void QColorPicker::mousePressEvent( QMouseEvent *m )
290{
291 QPoint p = m->pos() - contentsRect().topLeft();
292 setCol( p );
293 emit newCol( hue, sat );
294}
295
296void QColorPicker::drawContents(QPainter* p)
297{
298 QRect r = contentsRect();
299
300 p->drawPixmap( r.topLeft(), *pix );
301 QPoint pt = colPt() + r.topLeft();
302 p->setPen( QPen(black) );
303
304 p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
305 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
306
307}
308
309class QColorShowLabel;
310
311
312
313class QColIntValidator: public QIntValidator
314{
315public:
316 QColIntValidator( int bottom, int top,
317 QWidget * parent, const char *name = 0 )
318 :QIntValidator( bottom, top, parent, name ) {}
319
320 QValidator::State validate( QString &, int & ) const;
321};
322
323QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
324{
325 State state = QIntValidator::validate(s,pos);
326 if ( state == Valid ) {
327 long int val = s.toLong();
328 // This is not a general solution, assumes that top() > 0 and
329 // bottom >= 0
330 if ( val < 0 ) {
331 s = "0";
332 pos = 1;
333 } else if ( val > top() ) {
334 s.setNum( top() );
335 pos = s.length();
336 }
337 }
338 return state;
339}
340
341
342
343class QColNumLineEdit : public QLineEdit
344{
345public:
346 QColNumLineEdit( QWidget *parent, const char* name = 0 )
347 : QLineEdit( parent, name ) { setMaxLength( 3 );}
348 QSize sizeHint() const {
349 return QSize( 30, //#####
350 QLineEdit::sizeHint().height() ); }
351 void setNum( int i ) {
352 QString s;
353 s.setNum(i);
354 bool block = signalsBlocked();
355 blockSignals(TRUE);
356 setText( s );
357 blockSignals(block);
358 }
359 int val() const { return text().toInt(); }
360};
361
362
363class QColorShower : public QWidget
364{
365 Q_OBJECT
366public:
367 QColorShower( QWidget *parent, const char *name = 0 );
368
369 //things that don't emit signals
370 void setHsv( int h, int s, int v );
371
372 int currentAlpha() const { return alphaEd->val(); }
373 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
374 void showAlpha( bool b );
375
376
377 QRgb currentColor() const { return curCol; }
378
379public slots:
380 void setRgb( QRgb rgb );
381
382signals:
383 void newCol( QRgb rgb );
384private slots:
385 void rgbEd();
386 void hsvEd();
387private:
388 void showCurrentColor();
389 int hue, sat, val;
390 QRgb curCol;
391 QColNumLineEdit *hEd;
392 QColNumLineEdit *sEd;
393 QColNumLineEdit *vEd;
394 QColNumLineEdit *rEd;
395 QColNumLineEdit *gEd;
396 QColNumLineEdit *bEd;
397 QColNumLineEdit *alphaEd;
398 QLabel *alphaLab;
399 QColorShowLabel *lab;
400 bool rgbOriginal;
401};
402
403class QColorShowLabel : public QFrame
404{
405 Q_OBJECT
406
407public:
408 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
409 setFrameStyle( QFrame::Panel|QFrame::Sunken );
410 setBackgroundMode( PaletteBackground );
411 setAcceptDrops( TRUE );
412 mousePressed = FALSE;
413 }
414 void setColor( QColor c ) { col = c; }
415
416signals:
417 void colorDropped( QRgb );
418
419protected:
420 void drawContents( QPainter *p );
421 void mousePressEvent( QMouseEvent *e );
422 void mouseReleaseEvent( QMouseEvent *e );
423
424private:
425 QColor col;
426 bool mousePressed;
427 QPoint pressPos;
428
429};
430
431void QColorShowLabel::drawContents( QPainter *p )
432{
433 p->fillRect( contentsRect(), col );
434}
435
436void QColorShower::showAlpha( bool b )
437{
438 if ( b ) {
439 alphaLab->show();
440 alphaEd->show();
441 } else {
442 alphaLab->hide();
443 alphaEd->hide();
444 }
445}
446
447void QColorShowLabel::mousePressEvent( QMouseEvent *e )
448{
449 mousePressed = TRUE;
450 pressPos = e->pos();
451}
452
453void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
454{
455 if ( !mousePressed )
456 return;
457 mousePressed = FALSE;
458}
459
460QColorShower::QColorShower( QWidget *parent, const char *name )
461 :QWidget( parent, name)
462{
463 curCol = qRgb( -1, -1, -1 );
464 QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
465 QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
466
467 QGridLayout *gl = new QGridLayout( this, 1, 1, 2 );
468 gl->setMargin( 0 );
469 lab = new QColorShowLabel( this );
470 lab->setMinimumWidth( 60 ); //###
471 gl->addMultiCellWidget(lab, 0,-1,0,0);
472 connect( lab, SIGNAL( colorDropped( QRgb ) ),
473 this, SIGNAL( newCol( QRgb ) ) );
474 connect( lab, SIGNAL( colorDropped( QRgb ) ),
475 this, SLOT( setRgb( QRgb ) ) );
476
477 hEd = new QColNumLineEdit( this );
478 hEd->setValidator( val360 );
479 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hue:"), this );
480 l->setAlignment( AlignRight|AlignVCenter );
481 gl->addWidget( l, 0, 1 );
482 gl->addWidget( hEd, 0, 2 );
483
484 sEd = new QColNumLineEdit( this );
485 sEd->setValidator( val256 );
486 l = new QLabel( sEd, QColorDialog::tr("Sat:"), this );
487 l->setAlignment( AlignRight|AlignVCenter );
488 gl->addWidget( l, 1, 1 );
489 gl->addWidget( sEd, 1, 2 );
490
491 vEd = new QColNumLineEdit( this );
492 vEd->setValidator( val256 );
493 l = new QLabel( vEd, QColorDialog::tr("Val:"), this );
494 l->setAlignment( AlignRight|AlignVCenter );
495 gl->addWidget( l, 2, 1 );
496 gl->addWidget( vEd, 2, 2 );
497
498 rEd = new QColNumLineEdit( this );
499 rEd->setValidator( val256 );
500 l = new QLabel( rEd, QColorDialog::tr("Red:"), this );
501 l->setAlignment( AlignRight|AlignVCenter );
502 gl->addWidget( l, 0, 3 );
503 gl->addWidget( rEd, 0, 4 );
504
505 gEd = new QColNumLineEdit( this );
506 gEd->setValidator( val256 );
507 l = new QLabel( gEd, QColorDialog::tr("Green:"), this );
508 l->setAlignment( AlignRight|AlignVCenter );
509 gl->addWidget( l, 1, 3 );
510 gl->addWidget( gEd, 1, 4 );
511
512 bEd = new QColNumLineEdit( this );
513 bEd->setValidator( val256 );
514 l = new QLabel( bEd, QColorDialog::tr("Blue:"), this );
515 l->setAlignment( AlignRight|AlignVCenter );
516 gl->addWidget( l, 2, 3 );
517 gl->addWidget( bEd, 2, 4 );
518
519 alphaEd = new QColNumLineEdit( this );
520 alphaEd->setValidator( val256 );
521 alphaLab = new QLabel( alphaEd, QColorDialog::tr("Alpha channel:"), this );
522 alphaLab->setAlignment( AlignRight|AlignVCenter );
523 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
524 gl->addWidget( alphaEd, 3, 4 );
525 alphaEd->hide();
526 alphaLab->hide();
527
528 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
529 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
530 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
531
532 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
533 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
534 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
535}
536
537void QColorShower::showCurrentColor()
538{
539 lab->setColor( currentColor() );
540 lab->repaint(FALSE); //###
541}
542
543void QColorShower::rgbEd()
544{
545 rgbOriginal = TRUE;
546 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
547 rgb2hsv(currentColor(), hue, sat, val );
548
549 hEd->setNum( hue );
550 sEd->setNum( sat );
551 vEd->setNum( val );
552
553 showCurrentColor();
554 emit newCol( currentColor() );
555}
556
557void QColorShower::hsvEd()
558{
559 rgbOriginal = FALSE;
560 hue = hEd->val();
561 sat = sEd->val();
562 val = vEd->val();
563
564 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
565
566 rEd->setNum( qRed(currentColor()) );
567 gEd->setNum( qGreen(currentColor()) );
568 bEd->setNum( qBlue(currentColor()) );
569
570 showCurrentColor();
571 emit newCol( currentColor() );
572}
573
574void QColorShower::setRgb( QRgb rgb )
575{
576 rgbOriginal = TRUE;
577 curCol = rgb;
578
579 rgb2hsv( currentColor(), hue, sat, val );
580
581 hEd->setNum( hue );
582 sEd->setNum( sat );
583 vEd->setNum( val );
584
585 rEd->setNum( qRed(currentColor()) );
586 gEd->setNum( qGreen(currentColor()) );
587 bEd->setNum( qBlue(currentColor()) );
588
589 showCurrentColor();
590}
591
592void QColorShower::setHsv( int h, int s, int v )
593{
594 rgbOriginal = FALSE;
595 hue = h; val = v; sat = s; //Range check###
596 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
597
598 hEd->setNum( hue );
599 sEd->setNum( sat );
600 vEd->setNum( val );
601
602 rEd->setNum( qRed(currentColor()) );
603 gEd->setNum( qGreen(currentColor()) );
604 bEd->setNum( qBlue(currentColor()) );
605
606
607 showCurrentColor();
608}
609
610class QColorDialogPrivate : public QObject
611{
612Q_OBJECT
613public:
614 QColorDialogPrivate( QColorDialog *p );
615 QRgb currentColor() const { return cs->currentColor(); }
616 void setCurrentColor( QRgb rgb );
617
618 int currentAlpha() const { return cs->currentAlpha(); }
619 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
620 void showAlpha( bool b ) { cs->showAlpha( b ); }
621
622private slots:
623 void newHsv( int h, int s, int v );
624 void newColorTypedIn( QRgb rgb );
625private:
626 QColorPicker *cp;
627 QColorLuminancePicker *lp;
628 QColorShower *cs;
629};
630
631//sets all widgets to display h,s,v
632void QColorDialogPrivate::newHsv( int h, int s, int v )
633{
634 cs->setHsv( h, s, v );
635 cp->setCol( h, s );
636 lp->setCol( h, s, v );
637}
638
639//sets all widgets to display rgb
640void QColorDialogPrivate::setCurrentColor( QRgb rgb )
641{
642 cs->setRgb( rgb );
643 newColorTypedIn( rgb );
644}
645
646//sets all widgets exept cs to display rgb
647void QColorDialogPrivate::newColorTypedIn( QRgb rgb )
648{
649 int h, s, v;
650 rgb2hsv(rgb, h, s, v );
651 cp->setCol( h, s );
652 lp->setCol( h, s, v);
653}
654
655QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
656 QObject(dialog)
657{
658 int border = 2;
659 QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 );
660
661 QHBoxLayout *pickLay = new QHBoxLayout( topLay );
662
663
664 cp = new QColorPicker( dialog );
665 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
666 pickLay->addWidget( cp );
667
668 pickLay->addStretch();
669
670 lp = new QColorLuminancePicker( dialog );
671 lp->setFixedWidth( 20 ); //###
672 pickLay->addWidget( lp );
673
674 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
675 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
676
677 topLay->addStretch();
678
679 cs = new QColorShower( dialog );
680 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
681 topLay->addWidget( cs );
682
683}
684
685
686// BEING REVISED: jo
687/*!
688 \class QColorDialog qcolordialog.h
689 \brief The QColorDialog class provides a dialog widget for specifying colors.
690 \ingroup dialogs
691
692 The color dialog's function is to allow users to choose colors -
693 for instance, you might use this in a drawing program to allow the
694 user to set the brush color.
695
696 This version of Qt only provides modal color dialogs. The static
697 getColor() function shows the dialog and allows the user to specify a color,
698 while getRgba() does the same but allows the user to specify a color with an
699 alpha channel (transparency) value.
700
701 The user can store customCount() different custom colors. The custom
702 colors are shared by all color dialogs, and remembered during the
703 execution of the program. Use setCustomColor() to set the
704 custom colors, and customColor() to get them.
705
706 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
707*/
708
709/*!
710 Constructs a default color dialog. Use setColor() for setting an initial value.
711
712 \sa getColor()
713*/
714
715QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) :
716 QDialog(parent, name, modal )
717{
718 d = new QColorDialogPrivate( this );
719}
720
721
722/*!
723 Pops up a modal color dialog letting the user choose a color and returns
724 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
725 the dialog. All colors allocated by the dialog will be deallocated
726 before this function returns.
727*/
728
729QColor QColorDialog::getColor( QColor initial, QWidget *parent,
730 const char *name )
731{
732 int allocContext = QColor::enterAllocContext();
733 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
734 if ( parent && parent->icon() && !parent->icon()->isNull() )
735 dlg->setIcon( *parent->icon() );
736 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
737 dlg->setIcon( *qApp->mainWidget()->icon() );
738
739 dlg->setCaption( QColorDialog::tr( "Select color" ) );
740 dlg->setColor( initial );
741 dlg->showMaximized();
742 int resultCode = dlg->exec();
743 QColor::leaveAllocContext();
744 QColor result;
745 if ( resultCode == QDialog::Accepted ) {
746 result = dlg->color();
747 } else {
748 result = initial;
749 }
750 QColor::destroyAllocContext(allocContext);
751 delete dlg;
752 return result;
753}
754
755
756/*!
757 Pops up a modal color dialog, letting the user choose a color and an
758 alpha channel value. The color+alpha is initially set to \a initial.
759
760 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
761 and FALSE if the user clicked Cancel.
762
763 If the user clicks Cancel the \a initial value is returned.
764*/
765
766QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
767 QWidget *parent, const char* name )
768{
769 int allocContext = QColor::enterAllocContext();
770 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
771 dlg->setColor( initial );
772 dlg->setSelectedAlpha( qAlpha(initial) );
773 dlg->showMaximized();
774 int resultCode = dlg->exec();
775 QColor::leaveAllocContext();
776 QRgb result = initial;
777 if ( resultCode == QDialog::Accepted ) {
778 QRgb c = dlg->color().rgb();
779 int alpha = dlg->selectedAlpha();
780 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
781 }
782 if ( ok )
783 *ok = resultCode == QDialog::Accepted;
784
785 QColor::destroyAllocContext(allocContext);
786 delete dlg;
787 return result;
788}
789
790
791
792
793
794/*!
795 Returns the color currently selected in the dialog.
796
797 \sa setColor()
798*/
799
800QColor QColorDialog::color() const
801{
802 return QColor(d->currentColor());
803}
804
805
806/*! Destructs the dialog and frees any memory it allocated.
807
808*/
809
810QColorDialog::~QColorDialog()
811{
812 //d inherits QObject, so it is deleted by Qt.
813}
814
815
816/*!
817 Sets the color shown in the dialog to \a c.
818
819 \sa color()
820*/
821
822void QColorDialog::setColor( QColor c )
823{
824 d->setCurrentColor( c.rgb() );
825}
826
827
828
829
830/*!
831 Sets the initial alpha channel value to \a a, and show the alpha channel
832 entry box.
833*/
834
835void QColorDialog::setSelectedAlpha( int a )
836{
837 d->showAlpha( TRUE );
838 d->setCurrentAlpha( a );
839}
840
841
842/*!
843 Returns the value selected for the alpha channel.
844*/
845
846int QColorDialog::selectedAlpha() const
847{
848 return d->currentAlpha();
849}
850
851#include "colordialog.moc"
diff --git a/noncore/graphics/drawpad/colordialog.h b/noncore/graphics/drawpad/colordialog.h
deleted file mode 100644
index a2d4d30..0000000
--- a/noncore/graphics/drawpad/colordialog.h
+++ b/dev/null
@@ -1,77 +0,0 @@
1/****************************************************************************
2** $Id$
3**
4** Definition of QColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QCOLORDIALOG_H
39#define QCOLORDIALOG_H
40
41#ifndef QT_H
42#include <qdialog.h>
43#endif // QT_H
44
45class QColorDialogPrivate;
46
47class Q_EXPORT QColorDialog : public QDialog
48{
49 Q_OBJECT
50
51public:
52 static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor&
53 static QRgb getRgba( QRgb, bool* ok = 0,
54 QWidget *parent=0, const char* name=0 );
55
56private:
57 ~QColorDialog();
58
59 QColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE );
60 void setColor( QColor ); // ### 3.0: make const QColor&
61 QColor color() const;
62
63private:
64 void setSelectedAlpha( int );
65 int selectedAlpha() const;
66private:
67 QColorDialogPrivate *d;
68 friend class QColorDialogPrivate;
69
70 private:// Disabled copy constructor and operator=
71#if defined(Q_DISABLE_COPY)
72 QColorDialog( const QColorDialog & );
73 QColorDialog& operator=( const QColorDialog & );
74#endif
75};
76
77#endif
diff --git a/noncore/graphics/drawpad/colorpanel.cpp b/noncore/graphics/drawpad/colorpanel.cpp
deleted file mode 100644
index 9327012..0000000
--- a/noncore/graphics/drawpad/colorpanel.cpp
+++ b/dev/null
@@ -1,120 +0,0 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "colorpanel.h"
15
16#include <qlayout.h>
17#include <qpainter.h>
18
19ColorPanelButton::ColorPanelButton(const QColor& color, QWidget* parent, const char* name)
20 : QFrame(parent, name)
21{
22 m_color = color;
23
24 setFixedSize(16, 16);
25 setFrameStyle(NoFrame);
26}
27
28ColorPanelButton::~ColorPanelButton()
29{
30}
31
32void ColorPanelButton::enterEvent(QEvent* e)
33{
34 Q_UNUSED(e)
35
36 setFrameStyle(Panel | Sunken);
37}
38
39void ColorPanelButton::leaveEvent(QEvent* e)
40{
41 Q_UNUSED(e)
42
43 setFrameStyle(NoFrame);
44}
45
46void ColorPanelButton::paintEvent(QPaintEvent* e)
47{
48 QFrame::paintEvent(e);
49
50 QPainter painter;
51 painter.begin(this);
52 painter.fillRect(2, 2, 12, 12, m_color);
53 painter.setPen(Qt::black);
54 painter.drawRect(2, 2, 12, 12);
55 painter.end();
56}
57
58void ColorPanelButton::mouseReleaseEvent(QMouseEvent* e)
59{
60 Q_UNUSED(e)
61
62 emit selected(m_color);
63}
64
65ColorPanel::ColorPanel(QWidget* parent, const char* name)
66 : QWidget(parent, name)
67{
68 m_pGridLayout = new QGridLayout(this, 5, 6);
69
70 addColor(QColor(255, 255, 255), 0, 1);
71 addColor(QColor(192, 192, 192), 0, 2);
72 addColor(QColor(128, 128, 128), 0, 3);
73 addColor(QColor(64, 64, 64), 0, 4);
74 addColor(QColor(0, 0, 0), 0, 5);
75
76 addColor(QColor(255, 0, 0), 1, 0);
77 addColor(QColor(255, 128, 0), 1, 1);
78 addColor(QColor(255, 255, 0), 1, 2);
79 addColor(QColor(128, 255, 0), 1, 3);
80 addColor(QColor(0, 255, 0), 1, 4);
81 addColor(QColor(0, 255, 128), 1, 5);
82
83 addColor(QColor(128, 0, 0), 2, 0);
84 addColor(QColor(128, 64, 0), 2, 1);
85 addColor(QColor(128, 128, 0), 2, 2);
86 addColor(QColor(64, 128, 0), 2, 3);
87 addColor(QColor(0, 128, 0), 2, 4);
88 addColor(QColor(0, 128, 64), 2, 5);
89
90 addColor(QColor(0, 255, 255), 3, 0);
91 addColor(QColor(0, 128, 255), 3, 1);
92 addColor(QColor(0, 0, 255), 3, 2);
93 addColor(QColor(128, 0, 255), 3, 3);
94 addColor(QColor(255, 0, 255), 3, 4);
95 addColor(QColor(255, 0, 128), 3, 5);
96
97 addColor(QColor(0, 128, 128), 4, 0);
98 addColor(QColor(0, 64, 128), 4, 1);
99 addColor(QColor(0, 0, 128), 4, 2);
100 addColor(QColor(64, 0, 128), 4, 3);
101 addColor(QColor(128, 0, 128), 4, 4);
102 addColor(QColor(128, 0, 64), 4, 5);
103}
104
105ColorPanel::~ColorPanel()
106{
107}
108
109void ColorPanel::addColor(const QColor& color, int row, int col)
110{
111 ColorPanelButton* panelButton = new ColorPanelButton(color, this);
112 connect(panelButton, SIGNAL(selected(const QColor&)), this, SLOT(buttonSelected(const QColor&)));
113
114 m_pGridLayout->addWidget(panelButton, row, col);
115}
116
117void ColorPanel::buttonSelected(const QColor& color)
118{
119 emit colorSelected(color);
120}
diff --git a/noncore/graphics/drawpad/colorpanel.h b/noncore/graphics/drawpad/colorpanel.h
deleted file mode 100644
index 4664879..0000000
--- a/noncore/graphics/drawpad/colorpanel.h
+++ b/dev/null
@@ -1,62 +0,0 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#ifndef COLORPANEL_H
15#define COLORPANEL_H
16
17#include <qframe.h>
18#include <qwidget.h>
19
20class QGridLayout;
21
22class ColorPanelButton : public QFrame
23{
24 Q_OBJECT
25
26public:
27 ColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0);
28 ~ColorPanelButton();
29
30 void enterEvent(QEvent* e);
31 void leaveEvent(QEvent* e);
32 void paintEvent(QPaintEvent* e);
33 void mouseReleaseEvent(QMouseEvent* e);
34
35signals:
36 void selected(const QColor&);
37
38private:
39 QColor m_color;
40};
41
42class ColorPanel : public QWidget
43{
44 Q_OBJECT
45
46public:
47 ColorPanel(QWidget* parent = 0, const char* name = 0);
48 ~ColorPanel();
49
50 void addColor(const QColor& color, int row, int col);
51
52public slots:
53 void buttonSelected(const QColor& color);
54
55signals:
56 void colorSelected(const QColor&);
57
58private:
59 QGridLayout* m_pGridLayout;
60};
61
62#endif // COLORPANEL_H