X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fcolorbutton.cpp;h=22e03836e2f3bf7f10e5a9c68099fffdf3ff3b20;hp=4a833d06dd06ab2b793b5c19d12012a558f4c505;hb=158443f71d48215eea8b47b836b61afd77654b78;hpb=68efe6df6d72f1ac498d0594866455418552665d diff --git a/src/uisupport/colorbutton.cpp b/src/uisupport/colorbutton.cpp index 4a833d06..22e03836 100644 --- a/src/uisupport/colorbutton.cpp +++ b/src/uisupport/colorbutton.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * 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,54 +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 -#include #include #include -ColorButton::ColorButton(QWidget *parent) : - QPushButton(parent), - _color(QColor()) //default is white; - { +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; +void ColorButton::setColor(const QColor &color) +{ + _color = color; + QPixmap pixmap(QSize(32, 32)); + pixmap.fill(color); + setIcon(pixmap); + + emit colorChanged(color); } -void ColorButton::paintEvent(QPaintEvent *event) { - //TODO: work on a good button style solution - QPushButton::paintEvent(event); - QPainter painter(this); - int border = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin); - // if twice buttonMargin (+2 px from the adjust) is greater than the button height - // then set the border to a third of the button height. - if(2*border+2 >= event->rect().height()) border = event->rect().height()/3; +QColor ColorButton::color() const +{ + return _color; +} - QBrush brush; - if(isEnabled()) { - brush = QBrush(_color); - } else { - brush = QBrush(_color, Qt::Dense4Pattern); - } - painter.fillRect(rect().adjusted(border+1, border+1, -border-1, -border-1), brush); - QStyleOptionFrame option; - option.state = QStyle::State_Sunken; - option.rect = rect().adjusted(border, border, -border, -border); - QApplication::style()->drawPrimitive(QStyle::PE_Frame, &option, &painter); +void ColorButton::chooseColor() +{ + QColor c = QColorDialog::getColor(color(), this); + if (c.isValid()) { + setColor(c); + } }