-
-
Notifications
You must be signed in to change notification settings - Fork 557
/
Copy pathcolorpicker.cpp
41 lines (31 loc) · 856 Bytes
/
colorpicker.cpp
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
40
#include "colorpicker.h"
ColorPicker::ColorPicker(QWidget *parent) :
QWidget(parent)
{
m_layout = new QHBoxLayout(this);
m_frame = new QFrame(this);
m_button = new QToolButton(this);
m_frame->setFrameShape(QFrame::Box);
m_button->setText("...");
m_layout->setMargin(0);
m_layout->addWidget(m_frame, 1);
m_layout->addWidget(m_button);
connect(m_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QColor ColorPicker::color() const
{
return m_color;
}
void ColorPicker::setColor(const QColor &color)
{
m_color = color;
m_frame->setStyleSheet(QString("background-color: %1").arg(color.name()));
}
void ColorPicker::onButtonClicked()
{
QColor color = QColorDialog::getColor(m_color, this);
if (color.isValid()) {
setColor(color);
emit colorSelected(color);
}
}