add switch node

This commit is contained in:
王劲鹏 2021-05-27 16:56:57 +08:00 committed by osborn
parent 53184e483a
commit 2328afdb01
8 changed files with 71 additions and 1 deletions

View File

@ -58,6 +58,9 @@ void DoricDemoBridge::navigate(QVariant route) {
name = "StorageDemo.js"; name = "StorageDemo.js";
break; break;
case 14: case 14:
name = "SwitchDemo.js";
break;
case 15:
name = "TextDemo.js"; name = "TextDemo.js";
break; break;
} }

View File

@ -15,7 +15,7 @@ ApplicationWindow {
ListView { ListView {
width: parent.width width: parent.width
model: 15 model: 16
delegate: Rectangle { delegate: Rectangle {
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent
@ -51,6 +51,8 @@ ApplicationWindow {
case 13: case 13:
return "StorageDemo.js" return "StorageDemo.js"
case 14: case 14:
return "SwitchDemo.js"
case 15:
return "TextDemo.js" return "TextDemo.js"
} }
} }

View File

@ -23,6 +23,7 @@
<file alias="ScrollerDemo.js">../../../doric-demo/bundle/src/ScrollerDemo.js</file> <file alias="ScrollerDemo.js">../../../doric-demo/bundle/src/ScrollerDemo.js</file>
<file alias="Snake.js">../../../doric-demo/bundle/src/Snake.js</file> <file alias="Snake.js">../../../doric-demo/bundle/src/Snake.js</file>
<file alias="StorageDemo.js">../../../doric-demo/bundle/src/StorageDemo.js</file> <file alias="StorageDemo.js">../../../doric-demo/bundle/src/StorageDemo.js</file>
<file alias="SwitchDemo.js">../../../doric-demo/bundle/src/SwitchDemo.js</file>
<file alias="TextDemo.js">../../../doric-demo/bundle/src/TextDemo.js</file> <file alias="TextDemo.js">../../../doric-demo/bundle/src/TextDemo.js</file>
</qresource> </qresource>
<qresource prefix="/doric"> <qresource prefix="/doric">
@ -41,6 +42,7 @@
<file alias="image.qml">../doric/resources/image.qml</file> <file alias="image.qml">../doric/resources/image.qml</file>
<file alias="slider.qml">../doric/resources/slider.qml</file> <file alias="slider.qml">../doric/resources/slider.qml</file>
<file alias="input.qml">../doric/resources/input.qml</file> <file alias="input.qml">../doric/resources/input.qml</file>
<file alias="switch.qml">../doric/resources/switch.qml</file>
<file alias="toast.qml">../doric/resources/toast.qml</file> <file alias="toast.qml">../doric/resources/toast.qml</file>
<file alias="alert.qml">../doric/resources/alert.qml</file> <file alias="alert.qml">../doric/resources/alert.qml</file>

View File

@ -13,6 +13,7 @@
#include "shader/DoricRootNode.h" #include "shader/DoricRootNode.h"
#include "shader/DoricScrollerNode.h" #include "shader/DoricScrollerNode.h"
#include "shader/DoricStackNode.h" #include "shader/DoricStackNode.h"
#include "shader/DoricSwitchNode.h"
#include "shader/DoricTextNode.h" #include "shader/DoricTextNode.h"
#include "shader/DoricVLayoutNode.h" #include "shader/DoricVLayoutNode.h"
#include "shader/slider/DoricSlideItemNode.h" #include "shader/slider/DoricSlideItemNode.h"
@ -35,6 +36,7 @@ DoricRegistry::DoricRegistry() {
registerViewNode<DoricSliderNode>("Slider"); registerViewNode<DoricSliderNode>("Slider");
registerViewNode<DoricSlideItemNode>("SlideItem"); registerViewNode<DoricSlideItemNode>("SlideItem");
registerViewNode<DoricInputNode>("Input"); registerViewNode<DoricInputNode>("Input");
registerViewNode<DoricSwitchNode>("Switch");
} }
bool DoricRegistry::acquirePluginInfo(QString name) { bool DoricRegistry::acquirePluginInfo(QString name) {

View File

@ -50,6 +50,7 @@ SOURCES += \
shader/DoricScrollerNode.cpp \ shader/DoricScrollerNode.cpp \
shader/DoricStackNode.cpp \ shader/DoricStackNode.cpp \
shader/DoricSuperNode.cpp \ shader/DoricSuperNode.cpp \
shader/DoricSwitchNode.cpp \
shader/DoricTextNode.cpp \ shader/DoricTextNode.cpp \
shader/DoricVLayoutNode.cpp \ shader/DoricVLayoutNode.cpp \
shader/DoricViewNode.cpp \ shader/DoricViewNode.cpp \
@ -130,6 +131,7 @@ HEADERS += \
shader/DoricScrollerNode.h \ shader/DoricScrollerNode.h \
shader/DoricStackNode.h \ shader/DoricStackNode.h \
shader/DoricSuperNode.h \ shader/DoricSuperNode.h \
shader/DoricSwitchNode.h \
shader/DoricTextNode.h \ shader/DoricTextNode.h \
shader/DoricVLayoutNode.h \ shader/DoricVLayoutNode.h \
shader/DoricViewNode.h \ shader/DoricViewNode.h \

View File

@ -0,0 +1,6 @@
import QtQuick 2.12
import QtQuick.Controls 2.5
Switch {
}

View File

@ -0,0 +1,36 @@
#include "DoricSwitchNode.h"
#include "../utils/DoricUtils.h"
QQuickItem *DoricSwitchNode::build() {
QQmlComponent component(getContext()->getQmlEngine());
const QUrl url(QStringLiteral("qrc:/doric/qml/switch.qml"));
component.loadUrl(url);
if (component.isError()) {
qCritical() << component.errorString();
}
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
this->createLayouts(item);
item->setProperty("wrapper", QString::number((qint64)this));
return item;
}
void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
if (name == "state") {
} else if (name == "onSwitch") {
} else if (name == "offTintColor") {
} else if (name == "onTintColor") {
} else if (name == "thumbTintColor") {
} else {
DoricViewNode::blend(view, name, prop);
}
}

View File

@ -0,0 +1,17 @@
#ifndef DORICSWITCHNODE_H
#define DORICSWITCHNODE_H
#include "DoricExport.h"
#include "DoricViewNode.h"
class DORIC_EXPORT DoricSwitchNode : public DoricViewNode {
public:
using DoricViewNode::DoricViewNode;
QQuickItem *build() override;
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
};
#endif // DORICSWITCHNODE_H