/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include "colorbutton.h"
#include <QPainter>
-#include <QDebug>
-#include <QPaintEvent>
-#include <QApplication>
#include <QStyle>
#include <QStyleOptionFrame>
-ColorButton::ColorButton(QWidget *parent) :
- QPushButton(parent),
- _color(QColor()) //default is white;
- {
+#ifdef HAVE_KDE
+# include <KColorDialog>
+#else
+# include <QColorDialog>
+#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;
}
-void ColorButton::paintEvent(QPaintEvent *event) {
- QPushButton::paintEvent(event);
- QPainter painter(this);
- int border = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin);
- painter.fillRect(rect().adjusted(border+1, border+1, -border-1, -border-1), QBrush(_color));
- QStyleOptionFrame option;
- option.state = QStyle::State_Sunken;
- option.rect = rect().adjusted(border, border, -border, -border);
- //TODO: setBackground instead of the fillRect()
- //painter.setBackground(_color);
- //painter.setBackgroundMode(Qt::OpaqueMode);
- //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color));
- //qDebug() << option << QApplication::style()->subElementRect(QStyle::SE_PushButtonContents, &option);
- QApplication::style()->drawPrimitive(QStyle::PE_Frame, &option, &painter);
- //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color));
- //border += QStyle::PM_DefaultFrameWidth;
- //painter.fillRect(rect().adjusted(border, border, -border, -border), QBrush(_color));
+void ColorButton::chooseColor() {
+#ifdef HAVE_KDE
+ QColor c = color();
+ KColorDialog::getColor(c, this);
+#else
+ QColor c = QColorDialog::getColor(color(), this);
+#endif
+
+ if(c.isValid()) {
+ setColor(c);
+ }
}