00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdialog.h>
00022 #include <qpainter.h>
00023 #include <qdrawutil.h>
00024 #include <qapplication.h>
00025 #include <kglobalsettings.h>
00026 #include "kcolorbtn.h"
00027
00028 #include <opie2/qcolordialog.h>
00029
00030 KColorButton::KColorButton( QWidget *parent, const char *name )
00031 : QPushButton( parent, name ), dragFlag(false)
00032 {
00033
00034 connect (this, SIGNAL(clicked()), this, SLOT(chooseColor()));
00035 }
00036
00037 KColorButton::KColorButton( const QColor &c, QWidget *parent,
00038 const char *name )
00039 : QPushButton( parent, name ), col(c), dragFlag(false)
00040 {
00041
00042
00043 connect (this, SIGNAL(clicked()), this, SLOT(chooseColor()));
00044 }
00045
00046 void KColorButton::setColor( const QColor &c )
00047 {
00048 col = c;
00049 repaint( false );
00050 }
00051
00052 void KColorButton::drawButtonLabel( QPainter *painter )
00053 {
00054 QRect r = QApplication::style().buttonRect( 0, 0, width(), height() );
00055 int l = r.x();
00056 int t = r.y();
00057 int w = r.width();
00058 int h = r.height();
00059 int b = 5;
00060
00061 QColor lnCol = colorGroup().text();
00062 QColor fillCol = isEnabled() ? col : backgroundColor();
00063
00064 if ( isDown() ) {
00065 qDrawPlainRect( painter, l+b+1, t+b+1, w-b*2, h-b*2, lnCol, 1, 0 );
00066 b++;
00067 painter->fillRect( l+b+1, t+b+1, w-b*2, h-b*2, fillCol );
00068 } else {
00069 qDrawPlainRect( painter, l+b, t+b, w-b*2, h-b*2, lnCol, 1, 0 );
00070 b++;
00071 painter->fillRect( l+b, t+b, w-b*2, h-b*2, fillCol );
00072 }
00073 }
00074
00075 void KColorButton::chooseColor()
00076 {
00077 QColor newCol=QColorDialog::getColor( col);
00078 if( newCol != QDialog::Rejected )
00079 {
00080 col=newCol;
00081 repaint( false );
00082 emit changed( col );
00083 }
00084 }