X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fcolorbutton.cpp;h=15e9de471a8ecde884c86991bfa8a591bcabe514;hp=3b521339a3ca58d40b960341cf7dac9de9807a36;hb=2ca0005bfda1c2eb1bb4bcd6b0abe5382f0979f1;hpb=f6e4cd5bb3612a05933c9d985aa55041a47d5756 diff --git a/src/uisupport/colorbutton.cpp b/src/uisupport/colorbutton.cpp index 3b521339..15e9de47 100644 --- a/src/uisupport/colorbutton.cpp +++ b/src/uisupport/colorbutton.cpp @@ -24,46 +24,39 @@ #include #include -ColorButton::ColorButton(QWidget *parent) : QPushButton(parent) { - +#ifdef HAVE_KDE +# include +#else +# include +#endif + +ColorButton::ColorButton(QWidget *parent) : QToolButton(parent) { + setText(""); + connect(this, SIGNAL(clicked()), SLOT(chooseColor())); } void ColorButton::setColor(const QColor &color) { _color = color; - update(); + QPixmap pixmap(QSize(32,32)); + pixmap.fill(color); + setIcon(pixmap); + + emit colorChanged(color); } QColor ColorButton::color() const { return _color; } -/* This has been heavily inspired by KDE's KColorButton, thanks! */ -void ColorButton::paintEvent(QPaintEvent *) { - QPainter painter(this); - - QStyleOptionButton opt; - initStyleOption(&opt); - opt.state |= isDown() ? QStyle::State_Sunken : QStyle::State_Raised; - opt.features = QStyleOptionButton::None; - if(isDefault()) - opt.features |= QStyleOptionButton::DefaultButton; +void ColorButton::chooseColor() { +#ifdef HAVE_KDE + QColor c; + KColorDialog::getColor(c, this); +#else + QColor c = QColorDialog::getColor(color(), this); +#endif - // Draw bevel - style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &painter, this); - - // Calc geometry - QRect labelRect = style()->subElementRect(QStyle::SE_PushButtonContents, &opt, this); - int shift = style()->pixelMetric(QStyle::PM_ButtonMargin); - labelRect.adjust(shift, shift, -shift, -shift); - int x, y, w, h; - labelRect.getRect(&x, &y, &w, &h); - - if(isChecked() || isDown()) { - x += style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); - y += style()->pixelMetric(QStyle::PM_ButtonShiftVertical); + if(c.isValid()) { + setColor(c); } - - // Draw color rect - QBrush brush = isEnabled() ? color() : palette().color(backgroundRole()); - qDrawShadePanel(&painter, x, y, w, h, palette(), true, 1, &brush); }