summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp b/noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp
new file mode 100644
index 0000000..5d21f15
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/microkde/kcolorbtn.cpp
@@ -0,0 +1,84 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 Copyright (C) 1999 Cristian Tibirna (ctibirna@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qdialog.h>
22#include <qpainter.h>
23#include <qdrawutil.h>
24#include <qapplication.h>
25#include <kglobalsettings.h>
26#include "kcolordialog.h"
27#include "kcolorbtn.h"
28
29KColorButton::KColorButton( QWidget *parent, const char *name )
30 : QPushButton( parent, name ), dragFlag(false)
31{
32 // 2000-10-15 (putzer): fixes broken keyboard usage
33 connect (this, SIGNAL(clicked()), this, SLOT(chooseColor()));
34}
35
36KColorButton::KColorButton( const QColor &c, QWidget *parent,
37 const char *name )
38 : QPushButton( parent, name ), col(c), dragFlag(false)
39{
40
41 // 2000-10-15 (putzer): fixes broken keyboard usage
42 connect (this, SIGNAL(clicked()), this, SLOT(chooseColor()));
43}
44
45void KColorButton::setColor( const QColor &c )
46{
47 col = c;
48 repaint( false );
49}
50
51void KColorButton::drawButtonLabel( QPainter *painter )
52{
53 QRect r = QApplication::style().buttonRect( 0, 0, width(), height() );
54 int l = r.x();
55 int t = r.y();
56 int w = r.width();
57 int h = r.height();
58 int b = 5;
59
60 QColor lnCol = colorGroup().text();
61 QColor fillCol = isEnabled() ? col : backgroundColor();
62
63 if ( isDown() ) {
64 qDrawPlainRect( painter, l+b+1, t+b+1, w-b*2, h-b*2, lnCol, 1, 0 );
65 b++;
66 painter->fillRect( l+b+1, t+b+1, w-b*2, h-b*2, fillCol );
67 } else {
68 qDrawPlainRect( painter, l+b, t+b, w-b*2, h-b*2, lnCol, 1, 0 );
69 b++;
70 painter->fillRect( l+b, t+b, w-b*2, h-b*2, fillCol );
71 }
72}
73
74void KColorButton::chooseColor()
75{
76 if( KColorDialog::getColor( col) == QDialog::Rejected )
77 {
78 return;
79 }
80
81 repaint( false );
82 emit changed( col );
83}
84