//
// C++ Implementation: KColorButton
//
// Description: A Push button associated with a QColorDialog
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "kcolorbutton.h"
#include <QColorDialog>
#include <QPixmap>
#include "k9common.h"
KColorButton::KColorButton(QWidget *parent) :
    QPushButton(parent)
{
    k9Config config;
    setColor(config.getPrefButtonTextColor());
    connect(this,SIGNAL(pressed()),this,SLOT(pressed()));
}

void KColorButton::pressed() {
    QColor c=QColorDialog::getColor(m_color,this);
    if (c.isValid()) {
        setColor(c);
        emit changed(c);
    }
}

void KColorButton::setColor(const QColor &color) {
    m_color=color;
    QSize s(50,14);
    QPixmap pix(s);
    pix.fill(color);
    setIconSize(s);
    setIcon(QIcon(pix));

}

QColor KColorButton::color() {
    return m_color;
}

void KColorButton::resizeEvent(QResizeEvent *) {
    if (m_color.isValid())
        setColor(m_color);
}
