Skip to content
Snippets Groups Projects
Commit 04d15f09 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlDesigner.PropertyEditor: Added missing functionality for color chooser widget

parent 20064a83
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,7 @@ QExtGroupBox { ...@@ -69,6 +69,7 @@ QExtGroupBox {
layout: HorizontalLayout { layout: HorizontalLayout {
ColorBox { ColorBox {
id: colorControl;
color: colorGroupBox.backendColor.value; color: colorGroupBox.backendColor.value;
onColorChanged: { onColorChanged: {
colorGroupBox.backendColor.value = color; colorGroupBox.backendColor.value = color;
...@@ -97,8 +98,12 @@ QExtGroupBox { ...@@ -97,8 +98,12 @@ QExtGroupBox {
text: "H" text: "H"
fixedWidth: 15 fixedWidth: 15
} }
QSpinBox {
QSpinBox {
maximum: 360
value: colorControl.hue*360;
onValueChanged: if (colorControl.hue*360 !=value)
colorControl.hue=value/360.0;
} }
} }
...@@ -111,7 +116,10 @@ QExtGroupBox { ...@@ -111,7 +116,10 @@ QExtGroupBox {
fixedWidth: 15 fixedWidth: 15
} }
QSpinBox { QSpinBox {
maximum: 255
value: colorControl.saturation*255;
onValueChanged: if (colorControl.saturation*255 !=value)
colorControl.saturation=value/255.0;
} }
} }
...@@ -123,14 +131,17 @@ QExtGroupBox { ...@@ -123,14 +131,17 @@ QExtGroupBox {
fixedWidth: 15 fixedWidth: 15
} }
QSpinBox { QSpinBox {
maximum: 255
value: colorControl.value*255;
onValueChanged: if (colorControl.value*255 !=value)
colorControl.value=value/255.0;
} }
} }
} }
QWidget { // QWidget {
} // }
} }
} }
} }
......
...@@ -86,13 +86,11 @@ namespace QmlDesigner { ...@@ -86,13 +86,11 @@ namespace QmlDesigner {
void HueControl::setCurrent(int y) void HueControl::setCurrent(int y)
{ {
QColor oldColor(m_colorString); QColor color(m_colorString);
oldColor.toHsv(); if (y<0) y=0;
QColor newColor; if (y>119) y=119;
newColor.setHsvF(qreal(y) / 120.0, oldColor.hsvSaturationF(), oldColor.valueF()); color.setHsvF(qreal(y) / 120.0, color.hsvSaturationF(), color.valueF());
setColor(color.name());
QString newColorStr = QVariant(newColor).toString();
setColor(newColorStr);
setHue(qreal(y) / 120.0); setHue(qreal(y) / 120.0);
} }
...@@ -134,10 +132,11 @@ namespace QmlDesigner { ...@@ -134,10 +132,11 @@ namespace QmlDesigner {
void ColorBox::setCurrent(int x, int y) void ColorBox::setCurrent(int x, int y)
{ {
QColor oldColor(m_colorString);
oldColor.toHsv();
QColor newColor; QColor newColor;
if (x<0) x=0;
if (x>120) x=120;
if (y<0) y=0;
if (y>120) y=120;
newColor.setHsvF(hue(), qreal(x) / 120, 1.0 - qreal(y) / 120); newColor.setHsvF(hue(), qreal(x) / 120, 1.0 - qreal(y) / 120);
QString newColorStr = QVariant(newColor).toString(); QString newColorStr = QVariant(newColor).toString();
...@@ -155,8 +154,6 @@ namespace QmlDesigner { ...@@ -155,8 +154,6 @@ namespace QmlDesigner {
m_lastHue = m_hue; m_lastHue = m_hue;
m_cache = QPixmap(120, 120); m_cache = QPixmap(120, 120);
color.toHsv();
int height = 120; int height = 120;
int width = 120; int width = 120;
......
...@@ -88,6 +88,8 @@ Q_OBJECT ...@@ -88,6 +88,8 @@ Q_OBJECT
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged) Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
public: public:
...@@ -117,11 +119,15 @@ void setColor(const QString &colorStr) ...@@ -117,11 +119,15 @@ void setColor(const QString &colorStr)
if (m_colorString == colorStr) if (m_colorString == colorStr)
return; return;
qreal oldsaturation = saturation();
qreal oldvalue = value();
m_colorString = colorStr; m_colorString = colorStr;
update(); update();
qreal newHue = QColor(m_colorString).hsvHueF(); qreal newHue = QColor(m_colorString).hsvHueF();
if (newHue >= 0) if (newHue >= 0)
setHue(newHue); setHue(newHue);
if (oldsaturation != saturation()) emit saturationChanged();
if (oldvalue != value()) emit valueChanged();
emit colorChanged(); emit colorChanged();
} }
...@@ -130,9 +136,38 @@ QString color() const ...@@ -130,9 +136,38 @@ QString color() const
return m_colorString; return m_colorString;
} }
qreal saturation() const
{
return QColor(m_colorString).hsvSaturationF();
}
qreal setSaturation(qreal newsaturation)
{
QColor color(m_colorString);
color.setHsvF(color.hsvHueF(),newsaturation,color.valueF());
m_colorString=color.name();
emit saturationChanged();
}
qreal value() const
{
return QColor(m_colorString).valueF();
}
qreal setValue(qreal newvalue)
{
QColor color(m_colorString);
color.setHsvF(color.hsvHueF(),color.hsvSaturationF(),newvalue);
m_colorString=color.name();
emit valueChanged();
}
signals: signals:
void colorChanged(); void colorChanged();
void hueChanged(); void hueChanged();
void saturationChanged();
void valueChanged();
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
...@@ -191,7 +226,6 @@ void setHue(qreal newHue) ...@@ -191,7 +226,6 @@ void setHue(qreal newHue)
m_hue = newHue; m_hue = newHue;
QColor color(m_colorString); QColor color(m_colorString);
color.toHsv();
color.setHsvF(newHue, color.hsvSaturationF(), color.valueF()); color.setHsvF(newHue, color.hsvSaturationF(), color.valueF());
m_colorString = color.name(); m_colorString = color.name();
update(); update();
...@@ -209,8 +243,7 @@ void setColor(const QString &colorStr) ...@@ -209,8 +243,7 @@ void setColor(const QString &colorStr)
return; return;
m_colorString = colorStr; m_colorString = colorStr;
QColor color(m_colorString); m_hue = QColor(m_colorString).hsvHueF();
m_hue = color.hueF();
update(); update();
emit colorChanged(); emit colorChanged();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment