16#include "colorinspector.h"
17#include "ui_colorinspector.h"
22#include "colorslider.h"
25#include "colormanager.h"
29ColorInspector::ColorInspector(
QWidget *parent) :
33 setWindowTitle(tr(
"Color Inspector",
"Window title of color inspector"));
35 ui =
new Ui::ColorInspector;
36 ui->setupUi(innerWidget);
37 setWidget(innerWidget);
40ColorInspector::~ColorInspector()
45void ColorInspector::initUI()
47 mCurrentColor = editor()->color()->
frontColor();
50 isRgbColors = settings.value(
"isRgb").toBool();
53 ui->colorSpecTabWidget->setCurrentWidget(ui->rgbTab);
55 ui->colorSpecTabWidget->setCurrentWidget(ui->hsvTab);
59 ui->redSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::RED, mCurrentColor, 0.0, 255.0);
60 ui->greenSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::GREEN, mCurrentColor, 0.0, 255.0);
61 ui->blueSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::BLUE, mCurrentColor, 0.0, 255.0);
62 ui->rgbAlphaSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::ALPHA, mCurrentColor, 0.0, 255.0);
64 ui->hueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::HUE, mCurrentColor, 0.0, 359.0);
65 ui->saturationSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::SAT, mCurrentColor, 0.0, 255.0);
66 ui->valueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::VAL, mCurrentColor, 0.0, 255.0);
67 ui->hsvAlphaSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::ALPHA, mCurrentColor, 0.0, 255.0);
69 QPalette p1 = ui->colorWrapper->palette();
71 ui->colorWrapper->setPalette(p1);
75 ui->color->setPalette(p2);
79 auto onColorChangedSlider =
static_cast<void(
ColorInspector::*)(
const QColor&)
>(&ColorInspector::onColorChanged);
80 connect(ui->redSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
81 connect(ui->greenSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
82 connect(ui->blueSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
83 connect(ui->rgbAlphaSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
84 connect(ui->hueSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
85 connect(ui->saturationSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
86 connect(ui->valueSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
87 connect(ui->hsvAlphaSlider, &ColorSlider::valueChanged,
this, onColorChangedSlider);
90 auto onColorChangedSpinBox =
static_cast<void(
ColorInspector::*)()
>(&ColorInspector::onColorChanged);
91 connect(ui->redSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
92 clearFocusOnFinished(ui->redSpinBox);
93 connect(ui->greenSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
94 clearFocusOnFinished(ui->greenSpinBox);
95 connect(ui->blueSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
96 clearFocusOnFinished(ui->blueSpinBox);
97 connect(ui->rgbAlphaSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
98 clearFocusOnFinished(ui->rgbAlphaSpinBox);
99 connect(ui->hueSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
100 clearFocusOnFinished(ui->hueSpinBox);
101 connect(ui->saturationSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
102 clearFocusOnFinished(ui->saturationSpinBox);
103 connect(ui->valueSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
104 clearFocusOnFinished(ui->valueSpinBox);
105 connect(ui->hsvAlphaSpinBox, spinBoxChanged,
this, onColorChangedSpinBox);
106 clearFocusOnFinished(ui->hsvAlphaSpinBox);
108 connect(editor(), &Editor::objectLoaded,
this, &ColorInspector::updateUI);
111void ColorInspector::updateUI()
117void ColorInspector::setColor(
QColor newColor)
120 newColor = (isRgbColors) ? newColor.
toRgb() : newColor.
toHsv();
122 if (newColor == mCurrentColor)
127 mCurrentColor = newColor;
132QColor ColorInspector::color()
134 return mCurrentColor;
137void ColorInspector::updateControls()
147 ui->redSlider->setRgb(mCurrentColor);
148 ui->greenSlider->setRgb(mCurrentColor);
149 ui->blueSlider->setRgb(mCurrentColor);
150 ui->rgbAlphaSlider->setRgb(mCurrentColor);
157 ui->redSpinBox->setValue(mCurrentColor.
red());
158 ui->greenSpinBox->setValue(mCurrentColor.
green());
159 ui->blueSpinBox->setValue(mCurrentColor.
blue());
160 ui->rgbAlphaSpinBox->setValue(mCurrentColor.
alpha());
167 ui->hueSlider->setHsv(mCurrentColor);
168 ui->saturationSlider->setHsv(mCurrentColor);
169 ui->valueSlider->setHsv(mCurrentColor);
170 ui->hsvAlphaSlider->setHsv(mCurrentColor);
177 ui->hueSpinBox->setValue(mCurrentColor.
hue());
178 ui->saturationSpinBox->setValue(qRound(mCurrentColor.
saturation() / 2.55));
179 ui->valueSpinBox->setValue(qRound(mCurrentColor.
value() / 2.55));
180 ui->hsvAlphaSpinBox->setValue(qRound(mCurrentColor.
alpha() / 2.55));
184 ui->color->setPalette(p);
189void ColorInspector::onColorSpecChanged()
192 isRgbColors = ui->colorSpecTabWidget->currentWidget() == ui->rgbTab;
195 settings.setValue(
"isRgb", isRgbColors);
199 mCurrentColor = mCurrentColor.
toRgb();
203 mCurrentColor = mCurrentColor.
toHsv();
208 emit colorSpecChanged(isRgbColors);
211void ColorInspector::onColorChanged()
215 ui->redSpinBox->value(),
216 ui->greenSpinBox->value(),
217 ui->blueSpinBox->value(),
218 ui->rgbAlphaSpinBox->value());
221 ui->hueSpinBox->value(),
222 static_cast<int>(ui->saturationSpinBox->value() * 2.55),
223 static_cast<int>(ui->valueSpinBox->value() * 2.55),
224 static_cast<int>(ui->hsvAlphaSpinBox->value() * 2.55));
229 emit colorChanged(mCurrentColor);
232void ColorInspector::onColorChanged(
const QColor& color)
234 mCurrentColor = color;
238 emit colorChanged(color);
QColor frontColor(bool useIndexedColor=true)
frontColor
int saturation() const const
void setHsv(int h, int s, int v, int a)
void setRgb(int r, int g, int b, int a)
QColor toHsv() const const
QColor toRgb() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setBrush(QPalette::ColorRole role, const QBrush &brush)
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)