X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fcolorbutton.cpp;h=22e03836e2f3bf7f10e5a9c68099fffdf3ff3b20;hp=3b521339a3ca58d40b960341cf7dac9de9807a36;hb=1a45f16a9734820fba42fe1db3f38dd1eee49df6;hpb=f824db0e31b54969e0b7fa0b5405b1e9173d482c diff --git a/src/uisupport/colorbutton.cpp b/src/uisupport/colorbutton.cpp index 3b521339..22e03836 100644 --- a/src/uisupport/colorbutton.cpp +++ b/src/uisupport/colorbutton.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,55 +15,45 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "colorbutton.h" +#include #include #include #include -ColorButton::ColorButton(QWidget *parent) : QPushButton(parent) { +ColorButton::ColorButton(QWidget *parent) : QToolButton(parent) +{ + setText(""); + connect(this, SIGNAL(clicked()), SLOT(chooseColor())); } -void ColorButton::setColor(const QColor &color) { - _color = color; - update(); -} - -QColor ColorButton::color() const { - return _color; -} -/* This has been heavily inspired by KDE's KColorButton, thanks! */ -void ColorButton::paintEvent(QPaintEvent *) { - QPainter painter(this); +void ColorButton::setColor(const QColor &color) +{ + _color = color; + QPixmap pixmap(QSize(32, 32)); + pixmap.fill(color); + setIcon(pixmap); - QStyleOptionButton opt; - initStyleOption(&opt); - opt.state |= isDown() ? QStyle::State_Sunken : QStyle::State_Raised; - opt.features = QStyleOptionButton::None; - if(isDefault()) - opt.features |= QStyleOptionButton::DefaultButton; + emit colorChanged(color); +} - // 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); +QColor ColorButton::color() const +{ + return _color; +} - if(isChecked() || isDown()) { - x += style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); - y += style()->pixelMetric(QStyle::PM_ButtonShiftVertical); - } - // Draw color rect - QBrush brush = isEnabled() ? color() : palette().color(backgroundRole()); - qDrawShadePanel(&painter, x, y, w, h, palette(), true, 1, &brush); +void ColorButton::chooseColor() +{ + QColor c = QColorDialog::getColor(color(), this); + if (c.isValid()) { + setColor(c); + } }