author | zecke <zecke> | 2003-04-13 16:57:28 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-13 16:57:28 (UTC) |
commit | 0b311079ff19798866291034663757103c6ba935 (patch) (unidiff) | |
tree | 70ddccf3a3147475050fa06cc2d807a71ab1d5ee /libopie/colordialog.cpp | |
parent | 1537ccb435ca725c793db6e94e0b9e83484b57e7 (diff) | |
download | opie-0b311079ff19798866291034663757103c6ba935.zip opie-0b311079ff19798866291034663757103c6ba935.tar.gz opie-0b311079ff19798866291034663757103c6ba935.tar.bz2 |
Jumbo API documentation update
and some API fixed
ColorDialog is now OColorDialog!!! keep the namespace tidy!
ColorPopupMenu is now OColorPopupMenu!!! keep the namespace tidy
ColorDialog TT couldn't break bc we can so make it const QColor&
OTimePicker add some convience methods
more I might have forgot
-rw-r--r-- | libopie/colordialog.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libopie/colordialog.cpp b/libopie/colordialog.cpp index 684d6ea..35f15d6 100644 --- a/libopie/colordialog.cpp +++ b/libopie/colordialog.cpp | |||
@@ -12,96 +12,101 @@ | |||
12 | ** This file may be distributed under the terms of the Q Public License | 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 | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "colordialog.h" | 38 | #include "colordialog.h" |
39 | 39 | ||
40 | #include "qpainter.h" | 40 | #include "qpainter.h" |
41 | #include "qlayout.h" | 41 | #include "qlayout.h" |
42 | #include "qlabel.h" | 42 | #include "qlabel.h" |
43 | #include "qpushbutton.h" | 43 | #include "qpushbutton.h" |
44 | #include "qlineedit.h" | 44 | #include "qlineedit.h" |
45 | #include "qimage.h" | 45 | #include "qimage.h" |
46 | #include "qpixmap.h" | 46 | #include "qpixmap.h" |
47 | #include "qdrawutil.h" | 47 | #include "qdrawutil.h" |
48 | #include "qvalidator.h" | 48 | #include "qvalidator.h" |
49 | #include "qdragobject.h" | 49 | #include "qdragobject.h" |
50 | #include "qapplication.h" | 50 | #include "qapplication.h" |
51 | #include "qdragobject.h" | 51 | #include "qdragobject.h" |
52 | 52 | ||
53 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) | 53 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) |
54 | { | 54 | { |
55 | QColor c; | 55 | QColor c; |
56 | c.setRgb( rgb ); | 56 | c.setRgb( rgb ); |
57 | c.getHsv(h,s,v); | 57 | c.getHsv(h,s,v); |
58 | } | 58 | } |
59 | 59 | ||
60 | /* | ||
61 | * avoid clashes with the original Qt | ||
62 | */ | ||
63 | namespace { | ||
64 | |||
60 | class QColorPicker : public QFrame | 65 | class QColorPicker : public QFrame |
61 | { | 66 | { |
62 | Q_OBJECT | 67 | Q_OBJECT |
63 | public: | 68 | public: |
64 | QColorPicker(QWidget* parent=0, const char* name=0); | 69 | QColorPicker(QWidget* parent=0, const char* name=0); |
65 | ~QColorPicker(); | 70 | ~QColorPicker(); |
66 | 71 | ||
67 | public slots: | 72 | public slots: |
68 | void setCol( int h, int s ); | 73 | void setCol( int h, int s ); |
69 | 74 | ||
70 | signals: | 75 | signals: |
71 | void newCol( int h, int s ); | 76 | void newCol( int h, int s ); |
72 | 77 | ||
73 | protected: | 78 | protected: |
74 | QSize sizeHint() const; | 79 | QSize sizeHint() const; |
75 | QSizePolicy sizePolicy() const; | 80 | QSizePolicy sizePolicy() const; |
76 | void drawContents(QPainter* p); | 81 | void drawContents(QPainter* p); |
77 | void mouseMoveEvent( QMouseEvent * ); | 82 | void mouseMoveEvent( QMouseEvent * ); |
78 | void mousePressEvent( QMouseEvent * ); | 83 | void mousePressEvent( QMouseEvent * ); |
79 | 84 | ||
80 | private: | 85 | private: |
81 | int hue; | 86 | int hue; |
82 | int sat; | 87 | int sat; |
83 | 88 | ||
84 | QPoint colPt(); | 89 | QPoint colPt(); |
85 | int huePt( const QPoint &pt ); | 90 | int huePt( const QPoint &pt ); |
86 | int satPt( const QPoint &pt ); | 91 | int satPt( const QPoint &pt ); |
87 | void setCol( const QPoint &pt ); | 92 | void setCol( const QPoint &pt ); |
88 | 93 | ||
89 | QPixmap *pix; | 94 | QPixmap *pix; |
90 | }; | 95 | }; |
91 | 96 | ||
92 | static int pWidth = 200; | 97 | static int pWidth = 200; |
93 | static int pHeight = 200; | 98 | static int pHeight = 200; |
94 | 99 | ||
95 | class QColorLuminancePicker : public QWidget | 100 | class QColorLuminancePicker : public QWidget |
96 | { | 101 | { |
97 | Q_OBJECT | 102 | Q_OBJECT |
98 | public: | 103 | public: |
99 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); | 104 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); |
100 | ~QColorLuminancePicker(); | 105 | ~QColorLuminancePicker(); |
101 | 106 | ||
102 | public slots: | 107 | public slots: |
103 | void setCol( int h, int s, int v ); | 108 | void setCol( int h, int s, int v ); |
104 | void setCol( int h, int s ); | 109 | void setCol( int h, int s ); |
105 | 110 | ||
106 | signals: | 111 | signals: |
107 | void newHsv( int h, int s, int v ); | 112 | void newHsv( int h, int s, int v ); |
@@ -562,290 +567,292 @@ void QColorShower::hsvEd() | |||
562 | val = vEd->val(); | 567 | val = vEd->val(); |
563 | 568 | ||
564 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | 569 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); |
565 | 570 | ||
566 | rEd->setNum( qRed(currentColor()) ); | 571 | rEd->setNum( qRed(currentColor()) ); |
567 | gEd->setNum( qGreen(currentColor()) ); | 572 | gEd->setNum( qGreen(currentColor()) ); |
568 | bEd->setNum( qBlue(currentColor()) ); | 573 | bEd->setNum( qBlue(currentColor()) ); |
569 | 574 | ||
570 | showCurrentColor(); | 575 | showCurrentColor(); |
571 | emit newCol( currentColor() ); | 576 | emit newCol( currentColor() ); |
572 | } | 577 | } |
573 | 578 | ||
574 | void QColorShower::setRgb( QRgb rgb ) | 579 | void QColorShower::setRgb( QRgb rgb ) |
575 | { | 580 | { |
576 | rgbOriginal = TRUE; | 581 | rgbOriginal = TRUE; |
577 | curCol = rgb; | 582 | curCol = rgb; |
578 | 583 | ||
579 | rgb2hsv( currentColor(), hue, sat, val ); | 584 | rgb2hsv( currentColor(), hue, sat, val ); |
580 | 585 | ||
581 | hEd->setNum( hue ); | 586 | hEd->setNum( hue ); |
582 | sEd->setNum( sat ); | 587 | sEd->setNum( sat ); |
583 | vEd->setNum( val ); | 588 | vEd->setNum( val ); |
584 | 589 | ||
585 | rEd->setNum( qRed(currentColor()) ); | 590 | rEd->setNum( qRed(currentColor()) ); |
586 | gEd->setNum( qGreen(currentColor()) ); | 591 | gEd->setNum( qGreen(currentColor()) ); |
587 | bEd->setNum( qBlue(currentColor()) ); | 592 | bEd->setNum( qBlue(currentColor()) ); |
588 | 593 | ||
589 | showCurrentColor(); | 594 | showCurrentColor(); |
590 | } | 595 | } |
591 | 596 | ||
592 | void QColorShower::setHsv( int h, int s, int v ) | 597 | void QColorShower::setHsv( int h, int s, int v ) |
593 | { | 598 | { |
594 | rgbOriginal = FALSE; | 599 | rgbOriginal = FALSE; |
595 | hue = h; val = v; sat = s; //Range check### | 600 | hue = h; val = v; sat = s; //Range check### |
596 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | 601 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); |
597 | 602 | ||
598 | hEd->setNum( hue ); | 603 | hEd->setNum( hue ); |
599 | sEd->setNum( sat ); | 604 | sEd->setNum( sat ); |
600 | vEd->setNum( val ); | 605 | vEd->setNum( val ); |
601 | 606 | ||
602 | rEd->setNum( qRed(currentColor()) ); | 607 | rEd->setNum( qRed(currentColor()) ); |
603 | gEd->setNum( qGreen(currentColor()) ); | 608 | gEd->setNum( qGreen(currentColor()) ); |
604 | bEd->setNum( qBlue(currentColor()) ); | 609 | bEd->setNum( qBlue(currentColor()) ); |
605 | 610 | ||
606 | 611 | ||
607 | showCurrentColor(); | 612 | showCurrentColor(); |
608 | } | 613 | } |
609 | 614 | ||
615 | } | ||
616 | |||
610 | class OColorDialogPrivate : public QObject | 617 | class OColorDialogPrivate : public QObject |
611 | { | 618 | { |
612 | Q_OBJECT | 619 | Q_OBJECT |
613 | public: | 620 | public: |
614 | OColorDialogPrivate( OColorDialog *p ); | 621 | OColorDialogPrivate( OColorDialog *p ); |
615 | QRgb currentColor() const { return cs->currentColor(); } | 622 | QRgb currentColor() const { return cs->currentColor(); } |
616 | void setCurrentColor( QRgb rgb ); | 623 | void setCurrentColor( const QRgb& rgb ); |
617 | 624 | ||
618 | int currentAlpha() const { return cs->currentAlpha(); } | 625 | int currentAlpha() const { return cs->currentAlpha(); } |
619 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } | 626 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } |
620 | void showAlpha( bool b ) { cs->showAlpha( b ); } | 627 | void showAlpha( bool b ) { cs->showAlpha( b ); } |
621 | 628 | ||
622 | private slots: | 629 | private slots: |
623 | void newHsv( int h, int s, int v ); | 630 | void newHsv( int h, int s, int v ); |
624 | void newColorTypedIn( QRgb rgb ); | 631 | void newColorTypedIn( QRgb rgb ); |
625 | private: | 632 | private: |
626 | QColorPicker *cp; | 633 | QColorPicker *cp; |
627 | QColorLuminancePicker *lp; | 634 | QColorLuminancePicker *lp; |
628 | QColorShower *cs; | 635 | QColorShower *cs; |
629 | }; | 636 | }; |
630 | 637 | ||
631 | //sets all widgets to display h,s,v | 638 | //sets all widgets to display h,s,v |
632 | void OColorDialogPrivate::newHsv( int h, int s, int v ) | 639 | void OColorDialogPrivate::newHsv( int h, int s, int v ) |
633 | { | 640 | { |
634 | cs->setHsv( h, s, v ); | 641 | cs->setHsv( h, s, v ); |
635 | cp->setCol( h, s ); | 642 | cp->setCol( h, s ); |
636 | lp->setCol( h, s, v ); | 643 | lp->setCol( h, s, v ); |
637 | } | 644 | } |
638 | 645 | ||
639 | //sets all widgets to display rgb | 646 | //sets all widgets to display rgb |
640 | void OColorDialogPrivate::setCurrentColor( QRgb rgb ) | 647 | void OColorDialogPrivate::setCurrentColor( const QRgb& rgb ) |
641 | { | 648 | { |
642 | cs->setRgb( rgb ); | 649 | cs->setRgb( rgb ); |
643 | newColorTypedIn( rgb ); | 650 | newColorTypedIn( rgb ); |
644 | } | 651 | } |
645 | 652 | ||
646 | //sets all widgets exept cs to display rgb | 653 | //sets all widgets exept cs to display rgb |
647 | void OColorDialogPrivate::newColorTypedIn( QRgb rgb ) | 654 | void OColorDialogPrivate::newColorTypedIn( QRgb rgb ) |
648 | { | 655 | { |
649 | int h, s, v; | 656 | int h, s, v; |
650 | rgb2hsv(rgb, h, s, v ); | 657 | rgb2hsv(rgb, h, s, v ); |
651 | cp->setCol( h, s ); | 658 | cp->setCol( h, s ); |
652 | lp->setCol( h, s, v); | 659 | lp->setCol( h, s, v); |
653 | } | 660 | } |
654 | 661 | ||
655 | OColorDialogPrivate::OColorDialogPrivate( OColorDialog *dialog ) : | 662 | OColorDialogPrivate::OColorDialogPrivate( OColorDialog *dialog ) : |
656 | QObject(dialog) | 663 | QObject(dialog) |
657 | { | 664 | { |
658 | int border = 2; | 665 | int border = 2; |
659 | QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 ); | 666 | QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 ); |
660 | 667 | ||
661 | QHBoxLayout *pickLay = new QHBoxLayout( topLay ); | 668 | QHBoxLayout *pickLay = new QHBoxLayout( topLay ); |
662 | 669 | ||
663 | 670 | ||
664 | cp = new QColorPicker( dialog ); | 671 | cp = new QColorPicker( dialog ); |
665 | cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); | 672 | cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); |
666 | pickLay->addWidget( cp ); | 673 | pickLay->addWidget( cp ); |
667 | 674 | ||
668 | pickLay->addStretch(); | 675 | pickLay->addStretch(); |
669 | 676 | ||
670 | lp = new QColorLuminancePicker( dialog ); | 677 | lp = new QColorLuminancePicker( dialog ); |
671 | lp->setFixedWidth( 20 ); //### | 678 | lp->setFixedWidth( 20 ); //### |
672 | pickLay->addWidget( lp ); | 679 | pickLay->addWidget( lp ); |
673 | 680 | ||
674 | connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); | 681 | 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)) ); | 682 | connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); |
676 | 683 | ||
677 | topLay->addStretch(); | 684 | topLay->addStretch(); |
678 | 685 | ||
679 | cs = new QColorShower( dialog ); | 686 | cs = new QColorShower( dialog ); |
680 | connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); | 687 | connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); |
681 | topLay->addWidget( cs ); | 688 | topLay->addWidget( cs ); |
682 | 689 | ||
683 | } | 690 | } |
684 | 691 | ||
685 | 692 | ||
686 | // BEING REVISED: jo | 693 | // BEING REVISED: jo |
687 | /*! | 694 | /*! |
688 | \class OColorDialog OColorDialog.h | 695 | \class OColorDialog OColorDialog.h |
689 | \brief The OColorDialog class provides a dialog widget for specifying colors. | 696 | \brief The OColorDialog class provides a dialog widget for specifying colors. |
690 | \ingroup dialogs | 697 | \ingroup dialogs |
691 | 698 | ||
692 | The color dialog's function is to allow users to choose colors - | 699 | 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 | 700 | for instance, you might use this in a drawing program to allow the |
694 | user to set the brush color. | 701 | user to set the brush color. |
695 | 702 | ||
696 | This version of Qt only provides modal color dialogs. The static | 703 | 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, | 704 | 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 | 705 | while getRgba() does the same but allows the user to specify a color with an |
699 | alpha channel (transparency) value. | 706 | alpha channel (transparency) value. |
700 | 707 | ||
701 | The user can store customCount() different custom colors. The custom | 708 | The user can store customCount() different custom colors. The custom |
702 | colors are shared by all color dialogs, and remembered during the | 709 | colors are shared by all color dialogs, and remembered during the |
703 | execution of the program. Use setCustomColor() to set the | 710 | execution of the program. Use setCustomColor() to set the |
704 | custom colors, and customColor() to get them. | 711 | custom colors, and customColor() to get them. |
705 | 712 | ||
706 | <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> | 713 | <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> |
707 | */ | 714 | */ |
708 | 715 | ||
709 | /*! | 716 | /*! |
710 | Constructs a default color dialog. Use setColor() for setting an initial value. | 717 | Constructs a default color dialog. Use setColor() for setting an initial value. |
711 | 718 | ||
712 | \sa getColor() | 719 | \sa getColor() |
713 | */ | 720 | */ |
714 | 721 | ||
715 | OColorDialog::OColorDialog(QWidget* parent, const char* name, bool modal) : | 722 | OColorDialog::OColorDialog(QWidget* parent, const char* name, bool modal) : |
716 | QDialog(parent, name, modal ) | 723 | QDialog(parent, name, modal ) |
717 | { | 724 | { |
718 | d = new OColorDialogPrivate( this ); | 725 | d = new OColorDialogPrivate( this ); |
719 | } | 726 | } |
720 | 727 | ||
721 | 728 | ||
722 | /*! | 729 | /*! |
723 | Pops up a modal color dialog letting the user choose a color and returns | 730 | 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 | 731 | 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 | 732 | the dialog. All colors allocated by the dialog will be deallocated |
726 | before this function returns. | 733 | before this function returns. |
727 | */ | 734 | */ |
728 | 735 | ||
729 | QColor OColorDialog::getColor( QColor initial, QWidget *parent, | 736 | QColor OColorDialog::getColor( const QColor& initial, QWidget *parent, |
730 | const char *name ) | 737 | const char *name ) |
731 | { | 738 | { |
732 | int allocContext = QColor::enterAllocContext(); | 739 | int allocContext = QColor::enterAllocContext(); |
733 | OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal | 740 | OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal |
734 | if ( parent && parent->icon() && !parent->icon()->isNull() ) | 741 | if ( parent && parent->icon() && !parent->icon()->isNull() ) |
735 | dlg->setIcon( *parent->icon() ); | 742 | dlg->setIcon( *parent->icon() ); |
736 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) | 743 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) |
737 | dlg->setIcon( *qApp->mainWidget()->icon() ); | 744 | dlg->setIcon( *qApp->mainWidget()->icon() ); |
738 | 745 | ||
739 | dlg->setCaption( OColorDialog::tr( "Select color" ) ); | 746 | dlg->setCaption( OColorDialog::tr( "Select color" ) ); |
740 | dlg->setColor( initial ); | 747 | dlg->setColor( initial ); |
741 | dlg->showMaximized(); | 748 | dlg->showMaximized(); |
742 | int resultCode = dlg->exec(); | 749 | int resultCode = dlg->exec(); |
743 | QColor::leaveAllocContext(); | 750 | QColor::leaveAllocContext(); |
744 | QColor result; | 751 | QColor result; |
745 | if ( resultCode == QDialog::Accepted ) { | 752 | if ( resultCode == QDialog::Accepted ) { |
746 | result = dlg->color(); | 753 | result = dlg->color(); |
747 | } else { | 754 | } else { |
748 | result = initial; | 755 | result = initial; |
749 | } | 756 | } |
750 | QColor::destroyAllocContext(allocContext); | 757 | QColor::destroyAllocContext(allocContext); |
751 | delete dlg; | 758 | delete dlg; |
752 | return result; | 759 | return result; |
753 | } | 760 | } |
754 | 761 | ||
755 | 762 | ||
756 | /*! | 763 | /*! |
757 | Pops up a modal color dialog, letting the user choose a color and an | 764 | 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. | 765 | alpha channel value. The color+alpha is initially set to \a initial. |
759 | 766 | ||
760 | If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, | 767 | 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. | 768 | and FALSE if the user clicked Cancel. |
762 | 769 | ||
763 | If the user clicks Cancel the \a initial value is returned. | 770 | If the user clicks Cancel the \a initial value is returned. |
764 | */ | 771 | */ |
765 | 772 | ||
766 | QRgb OColorDialog::getRgba( QRgb initial, bool *ok, | 773 | QRgb OColorDialog::getRgba( const QRgb& initial, bool *ok, |
767 | QWidget *parent, const char* name ) | 774 | QWidget *parent, const char* name ) |
768 | { | 775 | { |
769 | int allocContext = QColor::enterAllocContext(); | 776 | int allocContext = QColor::enterAllocContext(); |
770 | OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal | 777 | OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal |
771 | dlg->setColor( initial ); | 778 | dlg->setColor( initial ); |
772 | dlg->setSelectedAlpha( qAlpha(initial) ); | 779 | dlg->setSelectedAlpha( qAlpha(initial) ); |
773 | dlg->showMaximized(); | 780 | dlg->showMaximized(); |
774 | int resultCode = dlg->exec(); | 781 | int resultCode = dlg->exec(); |
775 | QColor::leaveAllocContext(); | 782 | QColor::leaveAllocContext(); |
776 | QRgb result = initial; | 783 | QRgb result = initial; |
777 | if ( resultCode == QDialog::Accepted ) { | 784 | if ( resultCode == QDialog::Accepted ) { |
778 | QRgb c = dlg->color().rgb(); | 785 | QRgb c = dlg->color().rgb(); |
779 | int alpha = dlg->selectedAlpha(); | 786 | int alpha = dlg->selectedAlpha(); |
780 | result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); | 787 | result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); |
781 | } | 788 | } |
782 | if ( ok ) | 789 | if ( ok ) |
783 | *ok = resultCode == QDialog::Accepted; | 790 | *ok = resultCode == QDialog::Accepted; |
784 | 791 | ||
785 | QColor::destroyAllocContext(allocContext); | 792 | QColor::destroyAllocContext(allocContext); |
786 | delete dlg; | 793 | delete dlg; |
787 | return result; | 794 | return result; |
788 | } | 795 | } |
789 | 796 | ||
790 | 797 | ||
791 | 798 | ||
792 | 799 | ||
793 | 800 | ||
794 | /*! | 801 | /*! |
795 | Returns the color currently selected in the dialog. | 802 | Returns the color currently selected in the dialog. |
796 | 803 | ||
797 | \sa setColor() | 804 | \sa setColor() |
798 | */ | 805 | */ |
799 | 806 | ||
800 | QColor OColorDialog::color() const | 807 | QColor OColorDialog::color() const |
801 | { | 808 | { |
802 | return QColor(d->currentColor()); | 809 | return QColor(d->currentColor()); |
803 | } | 810 | } |
804 | 811 | ||
805 | 812 | ||
806 | /*! Destructs the dialog and frees any memory it allocated. | 813 | /*! Destructs the dialog and frees any memory it allocated. |
807 | 814 | ||
808 | */ | 815 | */ |
809 | 816 | ||
810 | OColorDialog::~OColorDialog() | 817 | OColorDialog::~OColorDialog() |
811 | { | 818 | { |
812 | //d inherits QObject, so it is deleted by Qt. | 819 | //d inherits QObject, so it is deleted by Qt. |
813 | } | 820 | } |
814 | 821 | ||
815 | 822 | ||
816 | /*! | 823 | /*! |
817 | Sets the color shown in the dialog to \a c. | 824 | Sets the color shown in the dialog to \a c. |
818 | 825 | ||
819 | \sa color() | 826 | \sa color() |
820 | */ | 827 | */ |
821 | 828 | ||
822 | void OColorDialog::setColor( QColor c ) | 829 | void OColorDialog::setColor( const QColor& c ) |
823 | { | 830 | { |
824 | d->setCurrentColor( c.rgb() ); | 831 | d->setCurrentColor( c.rgb() ); |
825 | } | 832 | } |
826 | 833 | ||
827 | 834 | ||
828 | 835 | ||
829 | 836 | ||
830 | /*! | 837 | /*! |
831 | Sets the initial alpha channel value to \a a, and show the alpha channel | 838 | Sets the initial alpha channel value to \a a, and show the alpha channel |
832 | entry box. | 839 | entry box. |
833 | */ | 840 | */ |
834 | 841 | ||
835 | void OColorDialog::setSelectedAlpha( int a ) | 842 | void OColorDialog::setSelectedAlpha( int a ) |
836 | { | 843 | { |
837 | d->showAlpha( TRUE ); | 844 | d->showAlpha( TRUE ); |
838 | d->setCurrentAlpha( a ); | 845 | d->setCurrentAlpha( a ); |
839 | } | 846 | } |
840 | 847 | ||
841 | 848 | ||
842 | /*! | 849 | /*! |
843 | Returns the value selected for the alpha channel. | 850 | Returns the value selected for the alpha channel. |
844 | */ | 851 | */ |
845 | 852 | ||
846 | int OColorDialog::selectedAlpha() const | 853 | int OColorDialog::selectedAlpha() const |
847 | { | 854 | { |
848 | return d->currentAlpha(); | 855 | return d->currentAlpha(); |
849 | } | 856 | } |
850 | 857 | ||
851 | #include "colordialog.moc" | 858 | #include "colordialog.moc" |