• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kcolorbutton.cpp
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include <config.h>
22
23#include <tqpainter.h>
24#include <tqdrawutil.h>
25#include <tqapplication.h>
26#include <tqclipboard.h>
27#include <tqstyle.h>
28#include <tdeglobalsettings.h>
29#include <tdestdaccel.h>
30#include "kcolordialog.h"
31#include "kcolorbutton.h"
32#include "kcolordrag.h"
33
34class KColorButton::KColorButtonPrivate
35{
36public:
37 bool m_bdefaultColor;
38 TQColor m_defaultColor;
39};
40
41KColorButton::KColorButton( TQWidget *parent, const char *name )
42 : TQPushButton( parent, name )
43{
44 d = new KColorButtonPrivate;
45 d->m_bdefaultColor = false;
46 d->m_defaultColor = TQColor();
47 setAcceptDrops( true);
48
49 // 2000-10-15 (putzer): fixes broken keyboard usage
50 connect (this, TQ_SIGNAL(clicked()), this, TQ_SLOT(chooseColor()));
51}
52
53KColorButton::KColorButton( const TQColor &c, TQWidget *parent,
54 const char *name )
55 : TQPushButton( parent, name ), col(c)
56{
57 d = new KColorButtonPrivate;
58 d->m_bdefaultColor = false;
59 d->m_defaultColor = TQColor();
60 setAcceptDrops( true);
61
62 // 2000-10-15 (putzer): fixes broken keyboard usage
63 connect (this, TQ_SIGNAL(clicked()), this, TQ_SLOT(chooseColor()));
64}
65
66KColorButton::KColorButton( const TQColor &c, const TQColor &defaultColor, TQWidget *parent,
67 const char *name )
68 : TQPushButton( parent, name ), col(c)
69{
70 d = new KColorButtonPrivate;
71 d->m_bdefaultColor = true;
72 d->m_defaultColor = defaultColor;
73 setAcceptDrops( true);
74
75 // 2000-10-15 (putzer): fixes broken keyboard usage
76 connect (this, TQ_SIGNAL(clicked()), this, TQ_SLOT(chooseColor()));
77}
78
79KColorButton::~KColorButton()
80{
81 delete d;
82}
83
84void KColorButton::setColor( const TQColor &c )
85{
86 if ( col != c ) {
87 col = c;
88 repaint( false );
89 emit changed( col );
90 }
91}
92
93TQColor KColorButton::defaultColor() const
94{
95 return d->m_defaultColor;
96}
97
98void KColorButton::setDefaultColor( const TQColor &c )
99{
100 d->m_bdefaultColor = c.isValid();
101 d->m_defaultColor = c;
102}
103
104
105void KColorButton::drawButtonLabel( TQPainter *painter )
106{
107 int x, y, w, h;
108 TQRect r = style().subRect( TQStyle::SR_PushButtonContents, this );
109 r.rect(&x, &y, &w, &h);
110
111 int margin = style().pixelMetric( TQStyle::PM_ButtonMargin, this );
112 x += margin;
113 y += margin;
114 w -= 2*margin;
115 h -= 2*margin;
116
117 if (isOn() || isDown()) {
118 x += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal, this );
119 y += style().pixelMetric( TQStyle::PM_ButtonShiftVertical, this );
120 }
121
122 TQColor fillCol = isEnabled() ? col : backgroundColor();
123 qDrawShadePanel( painter, x, y, w, h, colorGroup(), true, 1, NULL);
124 if ( fillCol.isValid() )
125 painter->fillRect( x+1, y+1, w-2, h-2, fillCol );
126
127 if ( hasFocus() ) {
128 TQRect focusRect = style().subRect( TQStyle::SR_PushButtonFocusRect, this );
129 style().drawPrimitive( TQStyle::PE_FocusRect, painter, focusRect, colorGroup() );
130 }
131}
132
133TQSize KColorButton::sizeHint() const
134{
135 return style().sizeFromContents(TQStyle::CT_PushButton, this, TQSize(40, 15)).
136 expandedTo(TQApplication::globalStrut());
137}
138
139void KColorButton::dragEnterEvent( TQDragEnterEvent *event)
140{
141 event->accept( KColorDrag::canDecode( event) && isEnabled());
142}
143
144void KColorButton::dropEvent( TQDropEvent *event)
145{
146 TQColor c;
147 if( KColorDrag::decode( event, c)) {
148 setColor(c);
149 }
150}
151
152void KColorButton::keyPressEvent( TQKeyEvent *e )
153{
154 KKey key( e );
155
156 if ( TDEStdAccel::copy().contains( key ) ) {
157 TQMimeSource* mime = new KColorDrag( color() );
158 TQApplication::clipboard()->setData( mime, TQClipboard::Clipboard );
159 }
160 else if ( TDEStdAccel::paste().contains( key ) ) {
161 TQColor color;
162 KColorDrag::decode( TQApplication::clipboard()->data( TQClipboard::Clipboard ), color );
163 setColor( color );
164 }
165 else
166 TQPushButton::keyPressEvent( e );
167}
168
169void KColorButton::mousePressEvent( TQMouseEvent *e)
170{
171 mPos = e->pos();
172 TQPushButton::mousePressEvent(e);
173}
174
175void KColorButton::mouseMoveEvent( TQMouseEvent *e)
176{
177 if( (e->state() & TQt::LeftButton) &&
178 (e->pos()-mPos).manhattanLength() > TDEGlobalSettings::dndEventDelay() )
179 {
180 // Drag color object
181 KColorDrag *dg = new KColorDrag( color(), this);
182 dg->dragCopy();
183 setDown(false);
184 }
185}
186
187void KColorButton::chooseColor()
188{
189 TQColor c = color();
190 if ( d->m_bdefaultColor )
191 {
192 if( KColorDialog::getColor( c, d->m_defaultColor, this ) != TQDialog::Rejected ) {
193 setColor( c );
194 }
195 }
196 else
197 {
198 if( KColorDialog::getColor( c, this ) != TQDialog::Rejected ) {
199 setColor( c );
200 }
201 }
202}
203
204void KColorButton::virtual_hook( int, void* )
205{ /*BASE::virtual_hook( id, data );*/ }
206
207#include "kcolorbutton.moc"
KColorButton::KColorButton
KColorButton(TQWidget *parent, const char *name=0L)
Creates a color button.
Definition: kcolorbutton.cpp:41
KColorButton::defaultColor
TQColor defaultColor() const
Returns the default color or an invalid color if no default color is set.
Definition: kcolorbutton.cpp:93
KColorButton::color
TQColor color() const
Returns the currently chosen color.
Definition: kcolorbutton.h:62
KColorButton::changed
void changed(const TQColor &newColor)
Emitted when the color of the widget is changed, either with setColor() or via user selection.
KColorButton::setColor
void setColor(const TQColor &c)
Sets the current color to c.
Definition: kcolorbutton.cpp:84
KColorButton::setDefaultColor
void setDefaultColor(const TQColor &c)
Sets the default color to c.
Definition: kcolorbutton.cpp:98
KColorDialog::getColor
static int getColor(TQColor &theColor, TQWidget *parent=0L)
Creates a modal color dialog, let the user choose a color, and returns when the dialog is closed.
Definition: kcolordialog.cpp:1298
KColorDrag
A drag-and-drop object for colors.
Definition: kcolordrag.h:36
KColorDrag::decode
static bool decode(TQMimeSource *e, TQColor &col)
Decodes the MIME source e and puts the resulting color into col.
Definition: kcolordrag.cpp:89
KColorDrag::canDecode
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a color object.
Definition: kcolordrag.cpp:76
KKey
TDEGlobalSettings::dndEventDelay
static int dndEventDelay()
TDEStdAccel::copy
const TDEShortcut & copy()
TDEStdAccel::paste
const TDEShortcut & paste()
TDEStdAccel::key
int key(StdAccel id)

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.