kdualcolorbutton.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef __KDUALCOLORBTN_H 00019 #define __KDUALCOLORBTN_H 00020 00021 class QBitmap; 00022 #include <qbrush.h> 00023 #include <qwidget.h> 00024 00025 #include <kdelibs_export.h> 00026 00048 class KDEUI_EXPORT KDualColorButton : public QWidget 00049 { 00050 Q_OBJECT 00051 Q_ENUMS( DualColor ) 00052 Q_PROPERTY( QColor foreground READ foreground WRITE setForeground ) 00053 Q_PROPERTY( QColor background READ background WRITE setBackground ) 00054 Q_PROPERTY( QColor currentColor READ currentColor WRITE setCurrentColor STORED false DESIGNABLE false ) 00055 Q_PROPERTY( DualColor current READ current WRITE setCurrent ) 00056 00057 public: 00058 00059 enum DualColor { Foreground, Background }; 00067 KDualColorButton(QWidget *parent=0, const char *name=0, QWidget* dialogParent=0); 00068 00073 KDualColorButton(const QColor &fgColor, const QColor &bgColor, 00074 QWidget *parent=0, const char *name=0, QWidget* dialogParent=0); 00075 00076 ~KDualColorButton(); 00080 QColor foreground() const; 00084 QColor background() const; 00088 DualColor current() const; 00092 QColor currentColor() const; 00097 virtual QSize sizeHint() const; 00098 public slots: 00102 void setForeground(const QColor &c); 00106 void setBackground(const QColor &c); 00110 void setCurrent(DualColor s); 00114 void setCurrentColor(const QColor &c); 00115 signals: 00119 void fgChanged(const QColor &c); 00123 void bgChanged(const QColor &c); 00127 void currentChanged(KDualColorButton::DualColor s); 00128 protected: 00136 virtual void metrics(QRect &fgRect, QRect &bgRect); 00137 virtual void paintEvent(QPaintEvent *ev); 00138 virtual void mousePressEvent(QMouseEvent *ev); 00139 virtual void mouseMoveEvent(QMouseEvent *ev); 00140 virtual void mouseReleaseEvent(QMouseEvent *ev); 00141 // Dnd 00142 virtual void dragEnterEvent(QDragEnterEvent *ev); 00143 virtual void dropEvent(QDropEvent *ev); 00144 private: 00145 QBitmap *arrowBitmap; 00146 QPixmap *resetPixmap; 00147 QBrush fg, bg; 00148 QPoint mPos; 00149 bool dragFlag, miniCtlFlag; 00150 DualColor curColor, tmpColor; 00151 00152 protected: 00153 virtual void virtual_hook( int id, void* data ); 00154 private: 00155 class KDualColorPrivate; 00156 KDualColorPrivate *d; 00157 }; 00158 00159 #endif