Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

kcolorbtn.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002     Copyright (C) 1997 Martin Jones (mjones@kde.org)
00003     Copyright (C) 1999 Cristian Tibirna (ctibirna@kde.org)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
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   // 2000-10-15 (putzer): fixes broken keyboard usage
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   // 2000-10-15 (putzer): fixes broken keyboard usage
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 }

Generated on Sat Nov 5 16:17:11 2005 for OPIE by  doxygen 1.4.2