23 #include <tqpainter.h>
24 #include <tqdrawutil.h>
25 #include <tqapplication.h>
26 #include <tqclipboard.h>
28 #include <tdeglobalsettings.h>
29 #include <tdestdaccel.h>
30 #include "kcolordialog.h"
31 #include "kcolorbutton.h"
32 #include "kcolordrag.h"
34 class KColorButton::KColorButtonPrivate
38 TQColor m_defaultColor;
42 : TQPushButton( parent, name )
44 d =
new KColorButtonPrivate;
45 d->m_bdefaultColor =
false;
46 d->m_defaultColor = TQColor();
47 setAcceptDrops(
true);
50 connect (
this, TQ_SIGNAL(clicked()),
this, TQ_SLOT(chooseColor()));
55 : TQPushButton( parent, name ), col(c)
57 d =
new KColorButtonPrivate;
58 d->m_bdefaultColor =
false;
59 d->m_defaultColor = TQColor();
60 setAcceptDrops(
true);
63 connect (
this, TQ_SIGNAL(clicked()),
this, TQ_SLOT(chooseColor()));
68 : TQPushButton( parent, name ), col(c)
70 d =
new KColorButtonPrivate;
71 d->m_bdefaultColor =
true;
73 setAcceptDrops(
true);
76 connect (
this, TQ_SIGNAL(clicked()),
this, TQ_SLOT(chooseColor()));
79 KColorButton::~KColorButton()
95 return d->m_defaultColor;
100 d->m_bdefaultColor = c.isValid();
101 d->m_defaultColor = c;
105 void KColorButton::drawButtonLabel( TQPainter *painter )
108 TQRect r = style().subRect( TQStyle::SR_PushButtonContents,
this );
109 r.rect(&x, &y, &w, &h);
111 int margin = style().pixelMetric( TQStyle::PM_ButtonMargin,
this );
117 if (isOn() || isDown()) {
118 x += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal,
this );
119 y += style().pixelMetric( TQStyle::PM_ButtonShiftVertical,
this );
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 );
128 TQRect focusRect = style().subRect( TQStyle::SR_PushButtonFocusRect,
this );
129 style().drawPrimitive( TQStyle::PE_FocusRect, painter, focusRect, colorGroup() );
133 TQSize KColorButton::sizeHint()
const
135 return style().sizeFromContents(TQStyle::CT_PushButton,
this, TQSize(40, 15)).
136 expandedTo(TQApplication::globalStrut());
139 void KColorButton::dragEnterEvent( TQDragEnterEvent *event)
144 void KColorButton::dropEvent( TQDropEvent *event)
152 void KColorButton::keyPressEvent( TQKeyEvent *e )
158 TQApplication::clipboard()->setData( mime, TQClipboard::Clipboard );
166 TQPushButton::keyPressEvent( e );
169 void KColorButton::mousePressEvent( TQMouseEvent *e)
172 TQPushButton::mousePressEvent(e);
175 void KColorButton::mouseMoveEvent( TQMouseEvent *e)
177 if( (e->state() & TQt::LeftButton) &&
187 void KColorButton::chooseColor()
190 if ( d->m_bdefaultColor )
204 void KColorButton::virtual_hook(
int,
void* )
207 #include "kcolorbutton.moc"
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.
A drag-and-drop object for colors.
static bool decode(TQMimeSource *e, TQColor &col)
Decodes the MIME source e and puts the resulting color into col.
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a color object.
static int dndEventDelay()
const TDEShortcut & copy()
const TDEShortcut & paste()