From aa030a4fb9eb222f343e983a1d90fc698a33be62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 27 May 2021 18:02:14 +0800 Subject: [PATCH] handle tint color for on, off & thumb --- doric-Qt/example/doric/resources/switch.qml | 31 ++++++++++++++++++- .../example/doric/shader/DoricSwitchNode.cpp | 15 ++++++--- .../example/doric/shader/DoricSwitchNode.h | 4 +++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/doric-Qt/example/doric/resources/switch.qml b/doric-Qt/example/doric/resources/switch.qml index 617705aa..06655e80 100644 --- a/doric-Qt/example/doric/resources/switch.qml +++ b/doric-Qt/example/doric/resources/switch.qml @@ -1,6 +1,35 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 -Switch { +import "util.mjs" as Util +Switch { + property var wrapper + + property var uuid: Util.uuidv4() + + property var tag: "Switch" + + property var offTintColor: "#42000000" + property var onTintColor: "#00ff00" + property var thumbTintColor: "white" + + Component.onCompleted: { + this.indicator.children[1].color = thumbTintColor + } + + onThumbTintColorChanged: { + this.indicator.children[1].color = thumbTintColor + } + + onCheckedChanged: { + console.log(onTintColor) + console.log(offTintColor) + console.log(thumbTintColor) + if (checked) { + this.indicator.children[0].color = onTintColor + } else { + this.indicator.children[0].color = offTintColor + } + } } diff --git a/doric-Qt/example/doric/shader/DoricSwitchNode.cpp b/doric-Qt/example/doric/shader/DoricSwitchNode.cpp index 4d93bba5..533d0955 100644 --- a/doric-Qt/example/doric/shader/DoricSwitchNode.cpp +++ b/doric-Qt/example/doric/shader/DoricSwitchNode.cpp @@ -21,15 +21,22 @@ QQuickItem *DoricSwitchNode::build() { void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "state") { - + checkByCodeToggle = true; + view->setProperty("checked", prop.toBool()); + checkByCodeToggle = false; } else if (name == "onSwitch") { } else if (name == "offTintColor") { - + view->setProperty( + "offTintColor", + QVariant::fromValue(DoricUtils::doricColor(prop.toInt()))); } else if (name == "onTintColor") { - + view->setProperty("onTintColor", QVariant::fromValue( + DoricUtils::doricColor(prop.toInt()))); } else if (name == "thumbTintColor") { - + view->setProperty( + "thumbTintColor", + QVariant::fromValue(DoricUtils::doricColor(prop.toInt()))); } else { DoricViewNode::blend(view, name, prop); } diff --git a/doric-Qt/example/doric/shader/DoricSwitchNode.h b/doric-Qt/example/doric/shader/DoricSwitchNode.h index 2ae296ea..f6551abd 100644 --- a/doric-Qt/example/doric/shader/DoricSwitchNode.h +++ b/doric-Qt/example/doric/shader/DoricSwitchNode.h @@ -6,6 +6,10 @@ #include "DoricViewNode.h" class DORIC_EXPORT DoricSwitchNode : public DoricViewNode { + +private: + bool checkByCodeToggle = false; + public: using DoricViewNode::DoricViewNode;