add text node

This commit is contained in:
王劲鹏 2021-02-25 19:04:14 +08:00 committed by osborn
parent 46ecc85ece
commit fc0df69ed4
6 changed files with 50 additions and 1 deletions

View File

@ -1,10 +1,11 @@
#include "DoricRegistry.h" #include "DoricRegistry.h"
#include "plugin/DoricShaderPlugin.h" #include "plugin/DoricShaderPlugin.h"
#include "shader/DoricHLayoutNode.h"
#include "shader/DoricRootNode.h" #include "shader/DoricRootNode.h"
#include "shader/DoricStackNode.h" #include "shader/DoricStackNode.h"
#include "shader/DoricTextNode.h"
#include "shader/DoricVLayoutNode.h" #include "shader/DoricVLayoutNode.h"
#include "shader/DoricHLayoutNode.h"
DoricRegistry::DoricRegistry() { DoricRegistry::DoricRegistry() {
registerNativePlugin<DoricShaderPlugin>("shader"); registerNativePlugin<DoricShaderPlugin>("shader");
@ -13,6 +14,7 @@ DoricRegistry::DoricRegistry() {
registerViewNode<DoricStackNode>("Stack"); registerViewNode<DoricStackNode>("Stack");
registerViewNode<DoricVLayoutNode>("VLayout"); registerViewNode<DoricVLayoutNode>("VLayout");
registerViewNode<DoricHLayoutNode>("HLayout"); registerViewNode<DoricHLayoutNode>("HLayout");
registerViewNode<DoricTextNode>("Text");
} }
bool DoricRegistry::acquirePluginInfo(QString name) { bool DoricRegistry::acquirePluginInfo(QString name) {

View File

@ -37,6 +37,7 @@ SOURCES += \
shader/DoricRootNode.cpp \ shader/DoricRootNode.cpp \
shader/DoricStackNode.cpp \ shader/DoricStackNode.cpp \
shader/DoricSuperNode.cpp \ shader/DoricSuperNode.cpp \
shader/DoricTextNode.cpp \
shader/DoricVLayoutNode.cpp \ shader/DoricVLayoutNode.cpp \
shader/DoricViewNode.cpp \ shader/DoricViewNode.cpp \
utils/DoricConstant.cpp \ utils/DoricConstant.cpp \
@ -83,6 +84,7 @@ HEADERS += \
shader/DoricRootNode.h \ shader/DoricRootNode.h \
shader/DoricStackNode.h \ shader/DoricStackNode.h \
shader/DoricSuperNode.h \ shader/DoricSuperNode.h \
shader/DoricTextNode.h \
shader/DoricVLayoutNode.h \ shader/DoricVLayoutNode.h \
shader/DoricViewNode.h \ shader/DoricViewNode.h \
template/DoricSingleton.h \ template/DoricSingleton.h \

View File

@ -19,5 +19,6 @@
<file alias="stack.qml">./resources/stack.qml</file> <file alias="stack.qml">./resources/stack.qml</file>
<file alias="vlayout.qml">./resources/vlayout.qml</file> <file alias="vlayout.qml">./resources/vlayout.qml</file>
<file alias="hlayout.qml">./resources/hlayout.qml</file> <file alias="hlayout.qml">./resources/hlayout.qml</file>
<file alias="text.qml">./resources/text.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

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

View File

@ -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<QQuickItem *>(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);
}
}

View File

@ -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