/
QtColorPicker.cpp
115 lines (97 loc) · 3.15 KB
/
QtColorPicker.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
// Project: Espina Volume Editor
// Author: Félix de las Pozas Alvarez
//
// File: QtColorPicker.cpp
// Purpose: pick a color by selecting it's RGB components
// Notes:
///////////////////////////////////////////////////////////////////////////////////////////////////
// Qt includes
#include "QtColorPicker.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// QtColorPicker class
//
QtColorPicker::QtColorPicker(QWidget *parent, Qt::WindowFlags f)
: QDialog {parent, f}
, m_modified{false}
, m_data {nullptr}
, m_color {QColor::fromRgbF(0.5,0.5,0.5)}
{
setupUi(this); // this sets up GUI
Rslider->setSliderPosition(m_color.red());
Gslider->setSliderPosition(m_color.green());
Bslider->setSliderPosition(m_color.blue());
connect(Rslider, SIGNAL(valueChanged(int)), this, SLOT(RValueChanged(int)));
connect(Gslider, SIGNAL(valueChanged(int)), this, SLOT(GValueChanged(int)));
connect(Bslider, SIGNAL(valueChanged(int)), this, SLOT(BValueChanged(int)));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(AcceptedData()));
// want to make the dialog appear centered
move(parent->geometry().center() - rect().center());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::SetInitialOptions(std::shared_ptr<DataManager> data)
{
m_data = data;
MakeColor();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool QtColorPicker::ModifiedData() const
{
return m_modified;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::AcceptedData()
{
m_modified = true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::RValueChanged(int value)
{
m_color.setRed(value);
MakeColor();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::GValueChanged(int value)
{
m_color.setGreen(value);
MakeColor();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::BValueChanged(int value)
{
m_color.setBlue(value);
MakeColor();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtColorPicker::MakeColor()
{
double rgba[4];
double temprgba[4];
bool match = false;
QPixmap icon(172, 31);
icon.fill(m_color);
colorlabel->setPixmap(icon);
for (unsigned int i = 0; i < m_data->GetNumberOfColors(); i++)
{
if(m_color == m_data->GetColorComponents(i))
{
match = true;
break;
}
}
if (match == true)
{
buttonBox->setEnabled(false);
label->setText("Color already in use");
}
else
{
buttonBox->setEnabled(true);
label->setText("Color selected");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
const QColor QtColorPicker::GetColor() const
{
return m_color;
}