forked from jahnf/Projecteur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorselector.cc
41 lines (35 loc) · 937 Bytes
/
colorselector.cc
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
41
// This file is part of Projecteur - https://github.com/jahnf/projecteur - See LICENSE.md and README.md
#include "colorselector.h"
#include <QColorDialog>
ColorSelector::ColorSelector(QWidget* parent)
: ColorSelector(Qt::black, parent)
{
}
ColorSelector::ColorSelector(const QColor& color, QWidget* parent)
: QPushButton( parent )
, m_color(color)
{
setMinimumWidth(30);
updateButton();
connect(this, &QPushButton::clicked, [this](){
const QColor c = QColorDialog::getColor(m_color,this, tr("Select Dot Color"));
if (c.isValid())
setColor(c);
});
}
void ColorSelector::setColor(const QColor& color)
{
if (m_color == color)
return;
m_color = color;
updateButton();
emit colorChanged( color );
}
void ColorSelector::updateButton()
{
QPalette p(palette());
p.setColor(QPalette::Button, m_color);
p.setColor(QPalette::ButtonText, m_color);
setPalette(p);
setToolTip(m_color.name());
}