summaryrefslogtreecommitdiff
path: root/libopie/colordialog.cpp
Unidiff
Diffstat (limited to 'libopie/colordialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie/colordialog.cpp17
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
@@ -48,24 +48,29 @@
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
53static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) 53static 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 */
63namespace {
64
60class QColorPicker : public QFrame 65class QColorPicker : public QFrame
61{ 66{
62 Q_OBJECT 67 Q_OBJECT
63public: 68public:
64 QColorPicker(QWidget* parent=0, const char* name=0); 69 QColorPicker(QWidget* parent=0, const char* name=0);
65 ~QColorPicker(); 70 ~QColorPicker();
66 71
67public slots: 72public slots:
68 void setCol( int h, int s ); 73 void setCol( int h, int s );
69 74
70signals: 75signals:
71 void newCol( int h, int s ); 76 void newCol( int h, int s );
@@ -598,55 +603,57 @@ void QColorShower::setHsv( int h, int s, int v )
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
610class OColorDialogPrivate : public QObject 617class OColorDialogPrivate : public QObject
611{ 618{
612Q_OBJECT 619Q_OBJECT
613public: 620public:
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
622private slots: 629private 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 );
625private: 632private:
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
632void OColorDialogPrivate::newHsv( int h, int s, int v ) 639void 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
640void OColorDialogPrivate::setCurrentColor( QRgb rgb ) 647void 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
647void OColorDialogPrivate::newColorTypedIn( QRgb rgb ) 654void 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);
@@ -717,25 +724,25 @@ OColorDialog::OColorDialog(QWidget* parent, const char* name, bool 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
729QColor OColorDialog::getColor( QColor initial, QWidget *parent, 736QColor 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();
@@ -754,25 +761,25 @@ QColor OColorDialog::getColor( QColor initial, QWidget *parent,
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
766QRgb OColorDialog::getRgba( QRgb initial, bool *ok, 773QRgb 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();
@@ -810,25 +817,25 @@ QColor OColorDialog::color() const
810OColorDialog::~OColorDialog() 817OColorDialog::~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
822void OColorDialog::setColor( QColor c ) 829void 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