-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCColorButton.cpp
More file actions
51 lines (45 loc) · 1.67 KB
/
CColorButton.cpp
File metadata and controls
51 lines (45 loc) · 1.67 KB
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
42
43
44
45
46
47
48
49
50
51
#include "CColorButton.h"
#include <QColorDialog>
#include <QDebug>
CColorButton::CColorButton(QString a_iFirstColor, QWidget *a_pParent):
QPushButton(a_pParent),
m_oColor(ParseColor(a_iFirstColor))
{
if (a_iFirstColor == ""){
a_iFirstColor = "255,255,255,255";
}
setStyleSheet("QPushButton{background-color : rgba(" + a_iFirstColor + ");"+
"border-style: outset;"+
"border-width: 2px;"+
"border-color: (200, 200, 200);}");
connect(this, SIGNAL(clicked(bool)), this, SLOT(openColorDialog()));
}
void CColorButton::openColorDialog()
{
QColorDialog* colorDialog = new QColorDialog(m_oColor);
colorDialog->show();
connect(colorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(changeColor(QColor)));
}
void CColorButton::changeColor(const QColor &a_oColor)
{
m_oColor = a_oColor;
QString color;
color += QString::number(a_oColor.red())+","+QString::number(a_oColor.green())+","+QString::number(a_oColor.blue())+","+QString::number(a_oColor.alpha());
setStyleSheet("QPushButton{background-color : rgba(" + color + ");"+
"border-style: outset;"+
"border-width: 2px;"+
"border-color: (200, 200, 200);}");
emit colorChanged(color);
}
QColor CColorButton::ParseColor(const QString &a_sColor) const
{
QStringList oRGBAValues = a_sColor.split(",");
if (oRGBAValues.count() >= 4) // if color is not properly set, do nothing
{
return (QColor(oRGBAValues.at(0).toInt(), oRGBAValues.at(1).toInt(), oRGBAValues.at(2).toInt(), oRGBAValues.at(3).toInt()));
}
else
{
return QColor(255,255,255,255);
}
}