From a38b998b6073d716d588eba6f78b52b5853ecac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 23 Feb 2021 14:28:08 +0800 Subject: [PATCH] add vlayout node & stack node --- doric-Qt/doric/DoricContext.cpp | 4 + doric-Qt/doric/DoricContext.h | 6 + doric-Qt/doric/DoricPanel.cpp | 6 +- doric-Qt/doric/DoricPanel.h | 3 +- doric-Qt/doric/DoricRegistry.cpp | 2 + doric-Qt/doric/demo/DoricDemoBridge.cpp | 2 +- doric-Qt/doric/doric.pro | 2 + doric-Qt/doric/doric.pro.user | 32 +-- doric-Qt/doric/doric.pro.user.a49b4ab | 319 +++++++++++++++++++++ doric-Qt/doric/qml.qrc | 1 + doric-Qt/doric/resources/vlayout.qml | 15 + doric-Qt/doric/shader/DoricStackNode.cpp | 4 +- doric-Qt/doric/shader/DoricVLayoutNode.cpp | 13 + doric-Qt/doric/shader/DoricVLayoutNode.h | 13 + 14 files changed, 402 insertions(+), 20 deletions(-) create mode 100644 doric-Qt/doric/doric.pro.user.a49b4ab create mode 100644 doric-Qt/doric/resources/vlayout.qml create mode 100644 doric-Qt/doric/shader/DoricVLayoutNode.cpp create mode 100644 doric-Qt/doric/shader/DoricVLayoutNode.h diff --git a/doric-Qt/doric/DoricContext.cpp b/doric-Qt/doric/DoricContext.cpp index 7e4dc5c1..486765a9 100644 --- a/doric-Qt/doric/DoricContext.cpp +++ b/doric-Qt/doric/DoricContext.cpp @@ -73,3 +73,7 @@ QObject *DoricContext::obtainPlugin(QString name) { return plugin; } } + +void DoricContext::setQmlEngine(QQmlEngine *engine) { mQmlEngine = engine; } + +QQmlEngine *DoricContext::getQmlEngine() { return mQmlEngine; } diff --git a/doric-Qt/doric/DoricContext.h b/doric-Qt/doric/DoricContext.h index cebb8c2e..5a70ee9a 100644 --- a/doric-Qt/doric/DoricContext.h +++ b/doric-Qt/doric/DoricContext.h @@ -1,6 +1,7 @@ #ifndef CONTEXT_H #define CONTEXT_H +#include #include #include "DoricInterfaceDriver.h" @@ -17,6 +18,7 @@ private: QString extra; QVariant initParams; DoricInterfaceDriver *driver = NULL; + QQmlEngine *mQmlEngine; public: DoricContext(QString contextId, QString source, QString extra); @@ -34,6 +36,10 @@ public: DoricRootNode *getRootNode(); QObject *obtainPlugin(QString name); + + void setQmlEngine(QQmlEngine *engine); + + QQmlEngine *getQmlEngine(); }; #endif // CONTEXT_H diff --git a/doric-Qt/doric/DoricPanel.cpp b/doric-Qt/doric/DoricPanel.cpp index 24102b26..47a8bc46 100644 --- a/doric-Qt/doric/DoricPanel.cpp +++ b/doric-Qt/doric/DoricPanel.cpp @@ -1,7 +1,10 @@ #include "DoricPanel.h" #include "shader/DoricRootNode.h" -DoricPanel::DoricPanel(QQuickItem *quickItem) { mQuickItem = quickItem; } +DoricPanel::DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem) { + mQmlEngine = qmlEngine; + mQuickItem = quickItem; +} void DoricPanel::config(QString script, QString alias, QString extra) { DoricContext *context = DoricContext::create(script, alias, extra); @@ -10,6 +13,7 @@ void DoricPanel::config(QString script, QString alias, QString extra) { void DoricPanel::config(DoricContext *context) { this->mContext = context; + this->mContext->setQmlEngine(mQmlEngine); this->mContext->getRootNode()->setRootView(mQuickItem); this->mContext->build(mQuickItem->width(), mQuickItem->height()); } diff --git a/doric-Qt/doric/DoricPanel.h b/doric-Qt/doric/DoricPanel.h index 7d5f47d9..729c16bd 100644 --- a/doric-Qt/doric/DoricPanel.h +++ b/doric-Qt/doric/DoricPanel.h @@ -11,10 +11,11 @@ private: int renderedWidth = -1; int renderedHeight = -1; + QQmlEngine *mQmlEngine; QQuickItem *mQuickItem; public: - DoricPanel(QQuickItem *quickItem); + DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem); void config(QString script, QString alias, QString extra); diff --git a/doric-Qt/doric/DoricRegistry.cpp b/doric-Qt/doric/DoricRegistry.cpp index f1337941..9c638534 100644 --- a/doric-Qt/doric/DoricRegistry.cpp +++ b/doric-Qt/doric/DoricRegistry.cpp @@ -3,12 +3,14 @@ #include "plugin/DoricShaderPlugin.h" #include "shader/DoricRootNode.h" #include "shader/DoricStackNode.h" +#include "shader/DoricVLayoutNode.h" DoricRegistry::DoricRegistry() { registerNativePlugin("shader"); registerViewNode("Root"); registerViewNode("Stack"); + registerViewNode("VLayout"); } bool DoricRegistry::acquirePluginInfo(QString name) { diff --git a/doric-Qt/doric/demo/DoricDemoBridge.cpp b/doric-Qt/doric/demo/DoricDemoBridge.cpp index ecddd254..c17f078d 100644 --- a/doric-Qt/doric/demo/DoricDemoBridge.cpp +++ b/doric-Qt/doric/demo/DoricDemoBridge.cpp @@ -26,7 +26,7 @@ void DoricDemoBridge::navigate(QVariant route) { const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml")); component.loadUrl(url); QQuickItem *quickItem = qobject_cast(component.create()); - DoricPanel *panel = new DoricPanel(quickItem); + DoricPanel *panel = new DoricPanel(view->engine(), quickItem); quickItem->setWidth(450); quickItem->setHeight(800); quickItem->setParentItem(view->rootObject()); diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index 6c1041d9..ac9a444d 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -35,6 +35,7 @@ SOURCES += \ shader/DoricRootNode.cpp \ shader/DoricStackNode.cpp \ shader/DoricSuperNode.cpp \ + shader/DoricVLayoutNode.cpp \ shader/DoricViewNode.cpp \ utils/DoricConstant.cpp \ utils/DoricContextHolder.cpp @@ -78,6 +79,7 @@ HEADERS += \ shader/DoricRootNode.h \ shader/DoricStackNode.h \ shader/DoricSuperNode.h \ + shader/DoricVLayoutNode.h \ shader/DoricViewNode.h \ template/DoricSingleton.h \ utils/DoricConstant.h \ diff --git a/doric-Qt/doric/doric.pro.user b/doric-Qt/doric/doric.pro.user index 8139dfbc..2960dd31 100644 --- a/doric-Qt/doric/doric.pro.user +++ b/doric-Qt/doric/doric.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {a49b4abd-08cf-4556-b46e-b0f44132419f} + {8f962447-7124-415a-9ec4-51e877569548} ProjectExplorer.Project.ActiveTarget @@ -67,7 +67,9 @@ 0 true - + + -fno-delayed-template-parsing + true Builtin.Questionable @@ -86,16 +88,16 @@ ProjectExplorer.Project.Target.0 Desktop - Desktop Qt 6.0.1 clang 64bit - Desktop Qt 6.0.1 clang 64bit - qt.qt6.601.clang_64_kit + Desktop Qt 6.0.1 MinGW 64-bit + Desktop Qt 6.0.1 MinGW 64-bit + qt.qt6.601.win64_mingw81_kit 0 0 0 0 - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug + C:\Users\maverick\Workspace\Doric\doric-Qt\build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Debug + C:/Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Debug true @@ -134,8 +136,8 @@ 0 - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Release - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Release + C:\Users\maverick\Workspace\Doric\doric-Qt\build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Release + C:/Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Release true @@ -176,8 +178,8 @@ 0 - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Profile - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Profile + C:\Users\maverick\Workspace\Doric\doric-Qt\build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Profile + C:/Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_MinGW_64_bit-Profile true @@ -292,14 +294,12 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/Users/maverick/Workspace/Doric/doric-Qt/doric/doric.pro - /Users/maverick/Workspace/Doric/doric-Qt/doric/doric.pro + ProjectExplorer.CustomExecutableRunConfiguration + false true - true false true - /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug/doric.app/Contents/MacOS 1 diff --git a/doric-Qt/doric/doric.pro.user.a49b4ab b/doric-Qt/doric/doric.pro.user.a49b4ab new file mode 100644 index 00000000..8139dfbc --- /dev/null +++ b/doric-Qt/doric/doric.pro.user.a49b4ab @@ -0,0 +1,319 @@ + + + + + + EnvironmentId + {a49b4abd-08cf-4556-b46e-b0f44132419f} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + true + Builtin.Questionable + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.0.1 clang 64bit + Desktop Qt 6.0.1 clang 64bit + qt.qt6.601.clang_64_kit + 0 + 0 + 0 + + 0 + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 0 + + + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Release + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + + 0 + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Profile + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/Users/maverick/Workspace/Doric/doric-Qt/doric/doric.pro + /Users/maverick/Workspace/Doric/doric-Qt/doric/doric.pro + false + true + true + false + true + /Users/maverick/Workspace/Doric/doric-Qt/build-doric-Desktop_Qt_6_0_1_clang_64bit-Debug/doric.app/Contents/MacOS + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/doric-Qt/doric/qml.qrc b/doric-Qt/doric/qml.qrc index 164c2d3a..b2fa49ad 100644 --- a/doric-Qt/doric/qml.qrc +++ b/doric-Qt/doric/qml.qrc @@ -17,5 +17,6 @@ ./resources/view.qml ./resources/panel.qml ./resources/stack.qml + ./resources/vlayout.qml diff --git a/doric-Qt/doric/resources/vlayout.qml b/doric-Qt/doric/resources/vlayout.qml new file mode 100644 index 00000000..3c464374 --- /dev/null +++ b/doric-Qt/doric/resources/vlayout.qml @@ -0,0 +1,15 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.5 + +Row { + Rectangle { + width: 50 + height: 50 + color: "blue" + } + Rectangle { + width: 50 + height: 50 + color: "green" + } +} diff --git a/doric-Qt/doric/shader/DoricStackNode.cpp b/doric-Qt/doric/shader/DoricStackNode.cpp index c63542ee..2ff3321f 100644 --- a/doric-Qt/doric/shader/DoricStackNode.cpp +++ b/doric-Qt/doric/shader/DoricStackNode.cpp @@ -1,11 +1,13 @@ #include "DoricStackNode.h" QQuickItem *DoricStackNode::build() { - QQmlComponent component; + QQmlComponent component(getContext()->getQmlEngine()); const QUrl url(QStringLiteral("qrc:/doric/qml/stack.qml")); component.loadUrl(url); + qCritical() << component.errorString(); + QQuickItem *item = qobject_cast(component.create()); return item; } diff --git a/doric-Qt/doric/shader/DoricVLayoutNode.cpp b/doric-Qt/doric/shader/DoricVLayoutNode.cpp new file mode 100644 index 00000000..46de707d --- /dev/null +++ b/doric-Qt/doric/shader/DoricVLayoutNode.cpp @@ -0,0 +1,13 @@ +#include "DoricVLayoutNode.h" + +QQuickItem *DoricVLayoutNode::build() { + QQmlComponent component(getContext()->getQmlEngine()); + + const QUrl url(QStringLiteral("qrc:/doric/qml/vlayout.qml")); + component.loadUrl(url); + + qCritical() << component.errorString(); + + QQuickItem *item = qobject_cast(component.create()); + return item; +} diff --git a/doric-Qt/doric/shader/DoricVLayoutNode.h b/doric-Qt/doric/shader/DoricVLayoutNode.h new file mode 100644 index 00000000..8a5c1f40 --- /dev/null +++ b/doric-Qt/doric/shader/DoricVLayoutNode.h @@ -0,0 +1,13 @@ +#ifndef DORICVLAYOUTNODE_H +#define DORICVLAYOUTNODE_H + +#include "DoricGroupNode.h" + +class DoricVLayoutNode : public DoricGroupNode { +public: + using DoricGroupNode::DoricGroupNode; + + QQuickItem *build() override; +}; + +#endif // DORICVLAYOUTNODE_H