19 #include "kdualcolorbutton.h"
20 #include "kcolordialog.h"
21 #include "kcolordrag.h"
22 #include "dcolorarrow.xbm"
23 #include "dcolorreset.xpm"
24 #include <tdeglobalsettings.h>
25 #include <tqpainter.h>
27 #include <tqdrawutil.h>
29 class KDualColorButton::KDualColorPrivate
32 TQWidget* dialogParent;
36 : TQWidget(parent, name),
37 d (new KDualColorPrivate)
39 if (!dialogParent && parent) {
40 d->dialogParent = parent;
42 d->dialogParent = dialogParent;
45 arrowBitmap =
new TQBitmap(dcolorarrow_width, dcolorarrow_height,
46 (
const unsigned char *)dcolorarrow_bits,
true);
47 arrowBitmap->setMask(*arrowBitmap);
48 resetPixmap =
new TQPixmap((
const char **)dcolorreset_xpm);
49 fg = TQBrush(TQt::black, TQt::SolidPattern);
50 bg = TQBrush(TQt::white, TQt::SolidPattern);
51 curColor = Foreground;
60 TQWidget *parent,
const char *name, TQWidget* dialogParent)
61 : TQWidget(parent, name),
62 d (new KDualColorPrivate)
64 d->dialogParent = dialogParent;
66 arrowBitmap =
new TQBitmap(dcolorarrow_width, dcolorarrow_height,
67 (
const unsigned char *)dcolorarrow_bits,
true);
68 arrowBitmap->setMask(*arrowBitmap);
69 resetPixmap =
new TQPixmap((
const char **)dcolorreset_xpm);
70 fg = TQBrush(fgColor, TQt::SolidPattern);
71 bg = TQBrush(bgColor, TQt::SolidPattern);
72 curColor = Foreground;
80 KDualColorButton::~KDualColorButton()
104 return (curColor == Background ? bg.color() : fg.color());
109 return TQSize(34, 34);
114 fg = TQBrush(c, TQt::SolidPattern);
122 bg = TQBrush(c, TQt::SolidPattern);
130 if(curColor == Background)
131 bg = TQBrush(c, TQt::SolidPattern);
133 fg = TQBrush(c, TQt::SolidPattern);
145 fgRect = TQRect(0, 0, width()-14, height()-14);
146 bgRect = TQRect(14, 14, width()-14, height()-14);
149 void KDualColorButton::paintEvent(TQPaintEvent *)
151 TQRect fgRect, bgRect;
155 TQBrush defBrush = colorGroup().brush(TQColorGroup::Button);
157 qDrawShadeRect(&p, bgRect, colorGroup(), curColor == Background, 2, 0,
158 isEnabled() ? &bg : &defBrush);
159 qDrawShadeRect(&p, fgRect, colorGroup(), curColor == Foreground, 2, 0,
160 isEnabled() ? &fg : &defBrush);
161 p.setPen(colorGroup().shadow());
162 p.drawPixmap(fgRect.right()+2, 0, *arrowBitmap);
163 p.drawPixmap(0, fgRect.bottom()+2, *resetPixmap);
167 void KDualColorButton::dragEnterEvent(TQDragEnterEvent *ev)
172 void KDualColorButton::dropEvent(TQDropEvent *ev)
176 if(curColor == Foreground){
188 void KDualColorButton::mousePressEvent(TQMouseEvent *ev)
190 TQRect fgRect, bgRect;
195 if(fgRect.contains(mPos)){
196 curColor = Foreground;
199 else if(bgRect.contains(mPos)){
200 curColor = Background;
203 else if(ev->pos().x() > fgRect.width()){
213 else if(ev->pos().x() < bgRect.x()){
214 fg.setColor(TQt::black);
215 bg.setColor(TQt::white);
224 void KDualColorButton::mouseMoveEvent(TQMouseEvent *ev)
228 if(ev->x() >= mPos.x()+delay || ev->x() <= mPos.x()-delay ||
229 ev->y() >= mPos.y()+delay || ev->y() <= mPos.y()-delay) {
231 fg.color() : bg.color(),
239 void KDualColorButton::mouseReleaseEvent(TQMouseEvent *ev)
242 TQRect fgRect, bgRect;
247 else if(fgRect.contains(ev->pos()) && curColor == Foreground){
248 if(tmpColor == Background){
249 curColor = Foreground;
253 TQColor newColor = fg.color();
255 fg.setColor(newColor);
260 else if(bgRect.contains(ev->pos()) && curColor == Background){
261 if(tmpColor == Foreground){
262 curColor = Background;
266 TQColor newColor = bg.color();
268 bg.setColor(newColor);
280 void KDualColorButton::virtual_hook(
int,
void* )
283 #include "kdualcolorbutton.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()