Commit 04d15f09 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlDesigner.PropertyEditor: Added missing functionality for color chooser widget

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