diff --git a/doric-Qt/doric/DoricRegistry.cpp b/doric-Qt/doric/DoricRegistry.cpp index c7d4063b..e4420f08 100644 --- a/doric-Qt/doric/DoricRegistry.cpp +++ b/doric-Qt/doric/DoricRegistry.cpp @@ -1,10 +1,11 @@ #include "DoricRegistry.h" #include "plugin/DoricShaderPlugin.h" +#include "shader/DoricHLayoutNode.h" #include "shader/DoricRootNode.h" #include "shader/DoricStackNode.h" +#include "shader/DoricTextNode.h" #include "shader/DoricVLayoutNode.h" -#include "shader/DoricHLayoutNode.h" DoricRegistry::DoricRegistry() { registerNativePlugin("shader"); @@ -13,6 +14,7 @@ DoricRegistry::DoricRegistry() { registerViewNode("Stack"); registerViewNode("VLayout"); registerViewNode("HLayout"); + registerViewNode("Text"); } bool DoricRegistry::acquirePluginInfo(QString name) { diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index db523cfd..01a0510f 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -37,6 +37,7 @@ SOURCES += \ shader/DoricRootNode.cpp \ shader/DoricStackNode.cpp \ shader/DoricSuperNode.cpp \ + shader/DoricTextNode.cpp \ shader/DoricVLayoutNode.cpp \ shader/DoricViewNode.cpp \ utils/DoricConstant.cpp \ @@ -83,6 +84,7 @@ HEADERS += \ shader/DoricRootNode.h \ shader/DoricStackNode.h \ shader/DoricSuperNode.h \ + shader/DoricTextNode.h \ shader/DoricVLayoutNode.h \ shader/DoricViewNode.h \ template/DoricSingleton.h \ diff --git a/doric-Qt/doric/qml.qrc b/doric-Qt/doric/qml.qrc index 11b120ba..78b0a96e 100644 --- a/doric-Qt/doric/qml.qrc +++ b/doric-Qt/doric/qml.qrc @@ -19,5 +19,6 @@ ./resources/stack.qml ./resources/vlayout.qml ./resources/hlayout.qml + ./resources/text.qml diff --git a/doric-Qt/doric/resources/text.qml b/doric-Qt/doric/resources/text.qml new file mode 100644 index 00000000..99d468df --- /dev/null +++ b/doric-Qt/doric/resources/text.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.5 + +Text { + +} diff --git a/doric-Qt/doric/shader/DoricTextNode.cpp b/doric-Qt/doric/shader/DoricTextNode.cpp new file mode 100644 index 00000000..1adc07bd --- /dev/null +++ b/doric-Qt/doric/shader/DoricTextNode.cpp @@ -0,0 +1,23 @@ +#include "DoricTextNode.h" + +QQuickItem *DoricTextNode::build() { + QQmlComponent component(getContext()->getQmlEngine()); + + const QUrl url(QStringLiteral("qrc:/doric/qml/text.qml")); + component.loadUrl(url); + + if (component.isError()) { + qCritical() << component.errorString(); + } + + QQuickItem *item = qobject_cast(component.create()); + return item; +} + +void DoricTextNode::blend(QQuickItem *view, QString name, QJSValue prop) { + if (name == "text") { + view->setProperty("text", prop.toString()); + } else { + DoricViewNode::blend(view, name, prop); + } +} diff --git a/doric-Qt/doric/shader/DoricTextNode.h b/doric-Qt/doric/shader/DoricTextNode.h new file mode 100644 index 00000000..c53bf714 --- /dev/null +++ b/doric-Qt/doric/shader/DoricTextNode.h @@ -0,0 +1,15 @@ +#ifndef DORICTEXTNODE_H +#define DORICTEXTNODE_H + +#include "DoricViewNode.h" + +class DoricTextNode : public DoricViewNode { +public: + using DoricViewNode::DoricViewNode; + + QQuickItem *build() override; + + virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; +}; + +#endif // DORICTEXTNODE_H