forked from qt-creator/qt-creator
QmlDesigner: Add support for colors defined with vector3d property
Some QtQuick3D effects specify colors as vector3d. Added support for vector3d colors to ColorEditor. Support can be enabled by setting isVector3D property to true. The colors are still displayed as regular "#ffffff" style color strings in the ColorEditor. Task-number: QDS-2114 Change-Id: If62152b0351e452d753eb6da9d90cd59fe2c4c59 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -42,7 +42,13 @@ Column {
|
||||
|
||||
property variant backendValue
|
||||
|
||||
property variant value: backendValue.value
|
||||
property variant value: {
|
||||
if (isVector3D)
|
||||
return Qt.rgba(backendValue.value.x, backendValue.value.y, backendValue.value.z, 1);
|
||||
else
|
||||
return backendValue.value;
|
||||
|
||||
}
|
||||
|
||||
property alias gradientPropertyName: gradientLine.gradientPropertyName
|
||||
|
||||
@@ -52,6 +58,8 @@ Column {
|
||||
|
||||
property color originalColor
|
||||
|
||||
property bool isVector3D: false
|
||||
|
||||
function isNotInGradientMode() {
|
||||
return (buttonRow.checkedIndex === 0 || transparent)
|
||||
}
|
||||
@@ -70,8 +78,15 @@ Column {
|
||||
interval: 100
|
||||
running: false
|
||||
onTriggered: {
|
||||
if (backendValue !== undefined)
|
||||
backendValue.value = colorEditor.color
|
||||
if (colorEditor.backendValue !== undefined) {
|
||||
if (isVector3D) {
|
||||
colorEditor.backendValue.value = Qt.vector3d(colorEditor.color.r,
|
||||
colorEditor.color.g,
|
||||
colorEditor.color.b);
|
||||
} else {
|
||||
colorEditor.backendValue.value = colorEditor.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +246,15 @@ Column {
|
||||
|
||||
onCommitData: {
|
||||
colorEditor.color = colorFromString(textField.text)
|
||||
if (isNotInGradientMode())
|
||||
backendValue.value = colorEditor.color
|
||||
if (isNotInGradientMode()) {
|
||||
if (colorEditor.isVector3D) {
|
||||
backendValue.value = Qt.vector3d(colorEditor.color.r,
|
||||
colorEditor.color.g,
|
||||
colorEditor.color.b);
|
||||
} else {
|
||||
backendValue.value = colorEditor.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
@@ -98,13 +98,22 @@ PropertyEditorContextObject::PropertyEditorContextObject(QObject *parent) :
|
||||
|
||||
}
|
||||
|
||||
QString PropertyEditorContextObject::convertColorToString(const QColor &color)
|
||||
QString PropertyEditorContextObject::convertColorToString(const QVariant &color)
|
||||
{
|
||||
QString colorString = color.name();
|
||||
QString colorString;
|
||||
QColor theColor;
|
||||
if (color.canConvert(QVariant::Color)) {
|
||||
theColor = color.value<QColor>();
|
||||
} else if (color.canConvert(QVariant::Vector3D)) {
|
||||
auto vec = color.value<QVector3D>();
|
||||
theColor = QColor::fromRgbF(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
if (color.alpha() != 255) {
|
||||
QString hexAlpha = QString("%1").arg(color.alpha(), 2, 16, QLatin1Char('0'));
|
||||
colorString.remove(0,1);
|
||||
colorString = theColor.name();
|
||||
|
||||
if (theColor.alpha() != 255) {
|
||||
QString hexAlpha = QString("%1").arg(theColor.alpha(), 2, 16, QLatin1Char('0'));
|
||||
colorString.remove(0, 1);
|
||||
colorString.prepend(hexAlpha);
|
||||
colorString.prepend(QStringLiteral("#"));
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
QQmlPropertyMap* backendValues() const { return m_backendValues; }
|
||||
|
||||
Q_INVOKABLE QString convertColorToString(const QColor &color);
|
||||
Q_INVOKABLE QString convertColorToString(const QVariant &color);
|
||||
Q_INVOKABLE QColor colorFromString(const QString &colorString);
|
||||
Q_INVOKABLE QString translateFunction();
|
||||
|
||||
|
@@ -225,7 +225,9 @@ void PropertyEditorView::changeValue(const QString &name)
|
||||
if (!value->value().isValid()) { //reset
|
||||
removePropertyFromModel(propertyName);
|
||||
} else {
|
||||
if (castedValue.isValid() && !castedValue.isNull()) {
|
||||
// QVector3D(0, 0, 0) detects as null variant though it is valid value
|
||||
if (castedValue.isValid() && (!castedValue.isNull()
|
||||
|| castedValue.type() == QVariant::Vector3D)) {
|
||||
commitVariantValueToModel(propertyName, castedValue);
|
||||
}
|
||||
}
|
||||
|
@@ -1067,6 +1067,9 @@ QVariant::Type NodeMetaInfoPrivate::variantTypeId(const PropertyName &propertyNa
|
||||
if (typeName == "var")
|
||||
return QVariant::UserType;
|
||||
|
||||
if (typeName == "vector3d")
|
||||
return QVariant::Vector3D;
|
||||
|
||||
return QVariant::nameToType(typeName.data());
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QVariant>
|
||||
#include <QColor>
|
||||
#include <QVector3D>
|
||||
|
||||
#include "bindingproperty.h"
|
||||
#include "signalhandlerproperty.h"
|
||||
@@ -149,6 +150,10 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
|
||||
case QMetaType::QString:
|
||||
case QMetaType::QChar:
|
||||
return QStringLiteral("\"%1\"").arg(escape(unicodeEscape(stringValue)));
|
||||
case QMetaType::QVector3D: {
|
||||
auto vec = value.value<QVector3D>();
|
||||
return QStringLiteral("Qt.vector3d(%1, %2, %3)").arg(vec.x()).arg(vec.y()).arg(vec.z());
|
||||
}
|
||||
default:
|
||||
return QStringLiteral("\"%1\"").arg(escape(stringValue));
|
||||
}
|
||||
|
@@ -57,7 +57,8 @@ void VariantProperty::setValue(const QVariant &value)
|
||||
if (isDynamic())
|
||||
qWarning() << "Calling VariantProperty::setValue on dynamic property.";
|
||||
|
||||
if (value.isNull())
|
||||
// QVector3D(0, 0, 0) detects as null variant though it is valid value
|
||||
if (value.isNull() && value.type() != QVariant::Vector3D)
|
||||
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name());
|
||||
|
||||
if (internalNode()->hasProperty(name())) { //check if oldValue != value
|
||||
|
Reference in New Issue
Block a user