16 #include "colorinspector.h"
17 #include "ui_colorinspector.h"
21 ColorInspector::ColorInspector(QWidget *parent) :
30 parent->setMaximumSize(500,height());
32 connect(ui->RedspinBox, SIGNAL(valueChanged(
int)),
33 this, SLOT(onColorChanged()));
34 connect(ui->GreenspinBox, SIGNAL(valueChanged(
int)),
35 this, SLOT(onColorChanged()));
36 connect(ui->BluespinBox, SIGNAL(valueChanged(
int)),
37 this, SLOT(onColorChanged()));
38 connect(ui->AlphaspinBox, SIGNAL(valueChanged(
int)),
39 this, SLOT(onColorChanged()));
40 connect(ui->rgb, SIGNAL(toggled(
bool)),
41 this, SLOT(onModeChanged()));
44 ColorInspector::~ColorInspector()
49 void ColorInspector::setColor(
const QColor &newColor)
51 if (newColor == m_color)
59 ui->RedspinBox->setValue(newColor.red());
60 ui->GreenspinBox->setValue(newColor.green());
61 ui->BluespinBox->setValue(newColor.blue());
62 ui->AlphaspinBox->setValue(newColor.alpha());
66 ui->RedspinBox->setValue( qBound(0.0, newColor.hsvHueF() * 359, 359.0) );
67 ui->GreenspinBox->setValue( qBound(0.0, newColor.hsvSaturationF() * 100, 100.0) );
68 ui->BluespinBox->setValue( qBound(0.0, newColor.valueF() * 100, 100.0) );
69 ui->AlphaspinBox->setValue( qBound(0.0, newColor.alphaF() * 100, 100.0) );
73 QPalette p1 = ui->colorWrapper->palette(), p2 = ui->color->palette();
74 p1.setBrush(QPalette::Background, QBrush(QImage(
":/background/checkerboard.png")));
75 p2.setColor(QPalette::Background, m_color);
76 ui->colorWrapper->setPalette(p1);
77 ui->color->setPalette(p2);
79 noColorUpdate =
false;
82 QColor ColorInspector::color()
87 void ColorInspector::onModeChanged()
89 bool newValue = ui->rgb->isChecked();
90 if (isRgbColors == newValue)
95 isRgbColors = newValue;
100 ui->red->setText(tr(
"Hue"));
101 ui->green->setText(tr(
"Saturation"));
102 ui->blue->setText(tr(
"Value"));
103 ui->alpha->setText(tr(
"Alpha"));
105 ui->RedspinBox->setRange(0,359);
106 ui->GreenspinBox->setRange(0,100);
107 ui->GreenspinBox->setSuffix(
"%");
108 ui->BluespinBox->setRange(0,100);
109 ui->BluespinBox->setSuffix(
"%");
110 ui->AlphaspinBox->setRange(0,100);
111 ui->AlphaspinBox->setSuffix(
"%");
113 m_color = m_color.toHsv();
114 ui->RedspinBox->setValue( qBound(0.0, m_color.hsvHueF()*359, 359.0) );
115 ui->GreenspinBox->setValue( qBound(0.0, m_color.hsvSaturationF()*100, 100.0) );
116 ui->BluespinBox->setValue( qBound(0.0, m_color.valueF()*100, 100.0) );
117 ui->AlphaspinBox->setValue( qBound(0.0, m_color.alphaF()*100, 100.0) );
121 ui->red->setText(tr(
"Red"));
122 ui->green->setText(tr(
"Green"));
123 ui->blue->setText(tr(
"Blue"));
124 ui->alpha->setText(tr(
"Alpha"));
126 ui->RedspinBox->setRange(0,255);
127 ui->GreenspinBox->setRange(0,255);
128 ui->GreenspinBox->setSuffix(
"");
129 ui->BluespinBox->setRange(0,255);
130 ui->BluespinBox->setSuffix(
"");
131 ui->AlphaspinBox->setRange(0,255);
132 ui->AlphaspinBox->setSuffix(
"");
133 m_color = m_color.toRgb();
134 ui->RedspinBox->setValue(m_color.red());
135 ui->GreenspinBox->setValue(m_color.green());
136 ui->BluespinBox->setValue(m_color.blue());
137 ui->AlphaspinBox->setValue(m_color.alpha());
139 noColorUpdate =
false;
140 emit modeChange(isRgbColors);
143 void ColorInspector::onColorChanged()
145 if(noColorUpdate)
return;
149 c = QColor::fromRgb(ui->RedspinBox->value(),
150 ui->GreenspinBox->value(),
151 ui->BluespinBox->value(),
152 ui->AlphaspinBox->value()
155 c = QColor::fromHsvF(qBound(0.0,
156 ui->RedspinBox->value()/359.0,
159 ui->GreenspinBox->value()/100.0,
162 ui->BluespinBox->value()/100.0,
165 ui->AlphaspinBox->value()/100.0,
171 emit colorChanged(c);