aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/common/colorbutton.cpp
blob: 005de4c73540e9f24bdf80bc4864f856b035267c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "colorbutton.h"
#include <QResizeEvent>
#include <QColorDialog>

ColorButton::ColorButton(QWidget *parent) :
    QPushButton(parent)
{
    setFixedWidth(height()*2);
    setColor(Qt::black);
    connect(this, SIGNAL(clicked()), this, SLOT(pickColor()));
}

QColor ColorButton::getColor() const
{
    return color;
}

void ColorButton::setColor(const QColor& value)
{
    color = value;
    QPixmap pix(iconSize());
    pix.fill(color);
    setIcon(pix);
    emit colorChanged(color);
}

void ColorButton::pickColor()
{
    QColor newColor = QColorDialog::getColor(color, parentWidget(), tr("Pick a color"));
    if (!newColor.isValid())
        return;

    setColor(newColor);
}

void ColorButton::resizeEvent(QResizeEvent* e)
{
    setFixedWidth(e->size().height()*2);
}