1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "colorbutton.h"
25 #include <QPaintEvent>
26 #include <QApplication>
28 #include <QStyleOptionFrame>
30 ColorButton::ColorButton(QWidget *parent) :
32 _color(QColor()) //default is white;
37 void ColorButton::setColor(const QColor &color) {
42 QColor ColorButton::color() const {
46 void ColorButton::paintEvent(QPaintEvent *event) {
47 QPushButton::paintEvent(event);
48 QPainter painter(this);
49 int border = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin);
50 painter.fillRect(rect().adjusted(border+1, border+1, -border-1, -border-1), QBrush(_color));
51 QStyleOptionFrame option;
52 option.state = QStyle::State_Sunken;
53 option.rect = rect().adjusted(border, border, -border, -border);
54 //TODO: setBackground instead of the fillRect()
55 //painter.setBackground(_color);
56 //painter.setBackgroundMode(Qt::OpaqueMode);
57 //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color));
58 //qDebug() << option << QApplication::style()->subElementRect(QStyle::SE_PushButtonContents, &option);
59 QApplication::style()->drawPrimitive(QStyle::PE_Frame, &option, &painter);
60 //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color));
61 //border += QStyle::PM_DefaultFrameWidth;
62 //painter.fillRect(rect().adjusted(border, border, -border, -border), QBrush(_color));