summaryrefslogtreecommitdiffstats
path: root/tdeui/kcolorbutton.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-06 15:56:40 -0600
committerTimothy Pearson <[email protected]>2011-11-06 15:56:40 -0600
commite16866e072f94410321d70daedbcb855ea878cac (patch)
treeee3f52eabde7da1a0e6ca845fb9c2813cf1558cf /tdeui/kcolorbutton.cpp
parenta58c20c1a7593631a1b50213c805507ebc16adaf (diff)
downloadtdelibs-e16866e072f94410321d70daedbcb855ea878cac.tar.gz
tdelibs-e16866e072f94410321d70daedbcb855ea878cac.zip
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdeui/kcolorbutton.cpp')
-rw-r--r--tdeui/kcolorbutton.cpp207
1 files changed, 207 insertions, 0 deletions
diff --git a/tdeui/kcolorbutton.cpp b/tdeui/kcolorbutton.cpp
new file mode 100644
index 000000000..c208d96f4
--- /dev/null
+++ b/tdeui/kcolorbutton.cpp
@@ -0,0 +1,207 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 1997 Martin Jones ([email protected])
+ Copyright (C) 1999 Cristian Tibirna ([email protected])
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <config.h>
+
+#include <tqpainter.h>
+#include <tqdrawutil.h>
+#include <tqapplication.h>
+#include <tqclipboard.h>
+#include <tqstyle.h>
+#include <kglobalsettings.h>
+#include <kstdaccel.h>
+#include "kcolordialog.h"
+#include "kcolorbutton.h"
+#include "kcolordrag.h"
+
+class KColorButton::KColorButtonPrivate
+{
+public:
+ bool m_bdefaultColor;
+ TQColor m_defaultColor;
+};
+
+KColorButton::KColorButton( TQWidget *parent, const char *name )
+ : TQPushButton( parent, name )
+{
+ d = new KColorButtonPrivate;
+ d->m_bdefaultColor = false;
+ d->m_defaultColor = TQColor();
+ setAcceptDrops( true);
+
+ // 2000-10-15 (putzer): fixes broken keyboard usage
+ connect (this, TQT_SIGNAL(clicked()), this, TQT_SLOT(chooseColor()));
+}
+
+KColorButton::KColorButton( const TQColor &c, TQWidget *parent,
+ const char *name )
+ : TQPushButton( parent, name ), col(c)
+{
+ d = new KColorButtonPrivate;
+ d->m_bdefaultColor = false;
+ d->m_defaultColor = TQColor();
+ setAcceptDrops( true);
+
+ // 2000-10-15 (putzer): fixes broken keyboard usage
+ connect (this, TQT_SIGNAL(clicked()), this, TQT_SLOT(chooseColor()));
+}
+
+KColorButton::KColorButton( const TQColor &c, const TQColor &defaultColor, TQWidget *parent,
+ const char *name )
+ : TQPushButton( parent, name ), col(c)
+{
+ d = new KColorButtonPrivate;
+ d->m_bdefaultColor = true;
+ d->m_defaultColor = defaultColor;
+ setAcceptDrops( true);
+
+ // 2000-10-15 (putzer): fixes broken keyboard usage
+ connect (this, TQT_SIGNAL(clicked()), this, TQT_SLOT(chooseColor()));
+}
+
+KColorButton::~KColorButton()
+{
+ delete d;
+}
+
+void KColorButton::setColor( const TQColor &c )
+{
+ if ( col != c ) {
+ col = c;
+ tqrepaint( false );
+ emit changed( col );
+ }
+}
+
+TQColor KColorButton::defaultColor() const
+{
+ return d->m_defaultColor;
+}
+
+void KColorButton::setDefaultColor( const TQColor &c )
+{
+ d->m_bdefaultColor = c.isValid();
+ d->m_defaultColor = c;
+}
+
+
+void KColorButton::drawButtonLabel( TQPainter *painter )
+{
+ int x, y, w, h;
+ TQRect r = tqstyle().subRect( TQStyle::SR_PushButtonContents, this );
+ r.rect(&x, &y, &w, &h);
+
+ int margin = tqstyle().tqpixelMetric( TQStyle::PM_ButtonMargin, this );
+ x += margin;
+ y += margin;
+ w -= 2*margin;
+ h -= 2*margin;
+
+ if (isOn() || isDown()) {
+ x += tqstyle().tqpixelMetric( TQStyle::PM_ButtonShiftHorizontal, this );
+ y += tqstyle().tqpixelMetric( TQStyle::PM_ButtonShiftVertical, this );
+ }
+
+ TQColor fillCol = isEnabled() ? col : backgroundColor();
+ qDrawShadePanel( painter, x, y, w, h, tqcolorGroup(), true, 1, NULL);
+ if ( fillCol.isValid() )
+ painter->fillRect( x+1, y+1, w-2, h-2, fillCol );
+
+ if ( hasFocus() ) {
+ TQRect focusRect = tqstyle().subRect( TQStyle::SR_PushButtonFocusRect, this );
+ tqstyle().tqdrawPrimitive( TQStyle::PE_FocusRect, painter, focusRect, tqcolorGroup() );
+ }
+}
+
+TQSize KColorButton::tqsizeHint() const
+{
+ return tqstyle().tqsizeFromContents(TQStyle::CT_PushButton, this, TQSize(40, 15)).
+ expandedTo(TQApplication::globalStrut());
+}
+
+void KColorButton::dragEnterEvent( TQDragEnterEvent *event)
+{
+ event->accept( KColorDrag::canDecode( event) && isEnabled());
+}
+
+void KColorButton::dropEvent( TQDropEvent *event)
+{
+ TQColor c;
+ if( KColorDrag::decode( event, c)) {
+ setColor(c);
+ }
+}
+
+void KColorButton::keyPressEvent( TQKeyEvent *e )
+{
+ KKey key( e );
+
+ if ( KStdAccel::copy().contains( key ) ) {
+ TQMimeSource* mime = new KColorDrag( color() );
+ TQApplication::tqclipboard()->setData( mime, TQClipboard::Clipboard );
+ }
+ else if ( KStdAccel::paste().contains( key ) ) {
+ TQColor color;
+ KColorDrag::decode( TQApplication::tqclipboard()->data( TQClipboard::Clipboard ), color );
+ setColor( color );
+ }
+ else
+ TQPushButton::keyPressEvent( e );
+}
+
+void KColorButton::mousePressEvent( TQMouseEvent *e)
+{
+ mPos = e->pos();
+ TQPushButton::mousePressEvent(e);
+}
+
+void KColorButton::mouseMoveEvent( TQMouseEvent *e)
+{
+ if( (e->state() & Qt::LeftButton) &&
+ (e->pos()-mPos).manhattanLength() > KGlobalSettings::dndEventDelay() )
+ {
+ // Drag color object
+ KColorDrag *dg = new KColorDrag( color(), this);
+ dg->dragCopy();
+ setDown(false);
+ }
+}
+
+void KColorButton::chooseColor()
+{
+ TQColor c = color();
+ if ( d->m_bdefaultColor )
+ {
+ if( KColorDialog::getColor( c, d->m_defaultColor, this ) != TQDialog::Rejected ) {
+ setColor( c );
+ }
+ }
+ else
+ {
+ if( KColorDialog::getColor( c, this ) != TQDialog::Rejected ) {
+ setColor( c );
+ }
+ }
+}
+
+void KColorButton::virtual_hook( int, void* )
+{ /*BASE::virtual_hook( id, data );*/ }
+
+#include "kcolorbutton.moc"