diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index a6d7019858ff48408836428f2070470a38da36c3..e55e4c466df02506846f184b7a999fd46046fc1c 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -96,6 +96,22 @@ static bool cleverColorCompare(QVariant value1, QVariant value2) return false; } + +/* "red" is the same color as "#ff0000" + To simplify editing we convert all explicit color names in the hash format */ +static void fixAmbigousColorNames(const QmlDesigner::ModelNode &modelNode, const QString &name, QVariant *value) +{ + if (modelNode.isValid() && modelNode.metaInfo().isValid() + && (modelNode.metaInfo().propertyTypeName(name) == "QColor" + || modelNode.metaInfo().propertyTypeName(name) == "color")) { + if ((value->type() == QVariant::Color)) { + *value = QColor(value->value<QColor>().name()); + } else { + *value = QColor(value->toString()).name(); + } + } +} + void PropertyEditorValue::setValueWithEmit(const QVariant &value) { if (m_value != value || isBound()) { @@ -125,6 +141,8 @@ void PropertyEditorValue::setValue(const QVariant &value) m_value = value; + fixAmbigousColorNames(modelNode(), name(), &m_value); + if (m_value.isValid()) emit valueChangedQml(); emit isBoundChanged();