handle tint color for on, off & thumb

This commit is contained in:
王劲鹏 2021-05-27 18:02:14 +08:00 committed by osborn
parent 2328afdb01
commit aa030a4fb9
3 changed files with 45 additions and 5 deletions

View File

@ -1,6 +1,35 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.5 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
}
}
} }

View File

@ -21,15 +21,22 @@ QQuickItem *DoricSwitchNode::build() {
void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) { void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
if (name == "state") { if (name == "state") {
checkByCodeToggle = true;
view->setProperty("checked", prop.toBool());
checkByCodeToggle = false;
} else if (name == "onSwitch") { } else if (name == "onSwitch") {
} else if (name == "offTintColor") { } else if (name == "offTintColor") {
view->setProperty(
"offTintColor",
QVariant::fromValue(DoricUtils::doricColor(prop.toInt())));
} else if (name == "onTintColor") { } else if (name == "onTintColor") {
view->setProperty("onTintColor", QVariant::fromValue(
DoricUtils::doricColor(prop.toInt())));
} else if (name == "thumbTintColor") { } else if (name == "thumbTintColor") {
view->setProperty(
"thumbTintColor",
QVariant::fromValue(DoricUtils::doricColor(prop.toInt())));
} else { } else {
DoricViewNode::blend(view, name, prop); DoricViewNode::blend(view, name, prop);
} }

View File

@ -6,6 +6,10 @@
#include "DoricViewNode.h" #include "DoricViewNode.h"
class DORIC_EXPORT DoricSwitchNode : public DoricViewNode { class DORIC_EXPORT DoricSwitchNode : public DoricViewNode {
private:
bool checkByCodeToggle = false;
public: public:
using DoricViewNode::DoricViewNode; using DoricViewNode::DoricViewNode;