From 36427898cb208e780a269cf33dfa530608c031b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 19 Feb 2021 10:04:54 +0800 Subject: [PATCH] change qml component to quick item --- doric-Qt/doric/DoricPanel.cpp | 4 ++-- doric-Qt/doric/DoricPanel.h | 4 +++- doric-Qt/doric/demo/DoricDemoBridge.cpp | 14 +++++++------- doric-Qt/doric/doric.pro.user | 2 +- doric-Qt/doric/shader/DoricRootNode.cpp | 4 +++- doric-Qt/doric/shader/DoricRootNode.h | 4 +++- doric-Qt/doric/shader/DoricStackNode.cpp | 13 ++++++------- doric-Qt/doric/shader/DoricStackNode.h | 2 +- doric-Qt/doric/shader/DoricViewNode.h | 6 +++--- 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/doric-Qt/doric/DoricPanel.cpp b/doric-Qt/doric/DoricPanel.cpp index ade267fa..be515669 100644 --- a/doric-Qt/doric/DoricPanel.cpp +++ b/doric-Qt/doric/DoricPanel.cpp @@ -10,6 +10,6 @@ void DoricPanel::config(QString script, QString alias, QString extra) { void DoricPanel::config(DoricContext *context) { this->mContext = context; - this->mContext->getRootNode()->setRootView(); - this->mContext->build(960, 720); + this->mContext->getRootNode()->setRootView(this); + this->mContext->build(width(), height()); } diff --git a/doric-Qt/doric/DoricPanel.h b/doric-Qt/doric/DoricPanel.h index 12fc0137..f914635f 100644 --- a/doric-Qt/doric/DoricPanel.h +++ b/doric-Qt/doric/DoricPanel.h @@ -1,9 +1,11 @@ #ifndef PANEL_H #define PANEL_H +#include + #include "DoricContext.h" -class DoricPanel { +class DoricPanel : public QQuickItem { private: DoricContext *mContext; int renderedWidth = -1; diff --git a/doric-Qt/doric/demo/DoricDemoBridge.cpp b/doric-Qt/doric/demo/DoricDemoBridge.cpp index 261e1bc8..5786e3f2 100644 --- a/doric-Qt/doric/demo/DoricDemoBridge.cpp +++ b/doric-Qt/doric/demo/DoricDemoBridge.cpp @@ -1,5 +1,4 @@ #include -#include #include #include "DoricDemoBridge.h" @@ -15,15 +14,16 @@ void DoricDemoBridge::navigate(QVariant route) { QString script = DoricUtils::readAssetFile("/doric/bundles", name); QQuickView *view = new QQuickView(); - view->setWidth(960); - view->setHeight(720); - QColor color("blue"); - view->setColor(color); + view->setWidth(450); + view->setHeight(800); + QColor blue("blue"); + view->setColor(blue); view->show(); - view->rootObject(); - DoricPanel *panel = new DoricPanel(); + panel->setParent(view); + panel->setWidth(450); + panel->setHeight(800); panel->config(script, name, NULL); break; } diff --git a/doric-Qt/doric/doric.pro.user b/doric-Qt/doric/doric.pro.user index 47800cde..e70185e0 100644 --- a/doric-Qt/doric/doric.pro.user +++ b/doric-Qt/doric/doric.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/doric-Qt/doric/shader/DoricRootNode.cpp b/doric-Qt/doric/shader/DoricRootNode.cpp index 02b13df2..dade93c3 100644 --- a/doric-Qt/doric/shader/DoricRootNode.cpp +++ b/doric-Qt/doric/shader/DoricRootNode.cpp @@ -1,3 +1,5 @@ #include "DoricRootNode.h" -void DoricRootNode::setRootView() {} +void DoricRootNode::setRootView(QQuickItem *rootView) { + this->mView = rootView; +} diff --git a/doric-Qt/doric/shader/DoricRootNode.h b/doric-Qt/doric/shader/DoricRootNode.h index 5b00263e..4c577d61 100644 --- a/doric-Qt/doric/shader/DoricRootNode.h +++ b/doric-Qt/doric/shader/DoricRootNode.h @@ -1,13 +1,15 @@ #ifndef ROOTNODE_H #define ROOTNODE_H +#include + #include "DoricStackNode.h" class DoricRootNode : public DoricStackNode { public: using DoricStackNode::DoricStackNode; - void setRootView(); + void setRootView(QQuickItem *rootView); }; #endif // ROOTNODE_H diff --git a/doric-Qt/doric/shader/DoricStackNode.cpp b/doric-Qt/doric/shader/DoricStackNode.cpp index 156c8fa9..0e536a7b 100644 --- a/doric-Qt/doric/shader/DoricStackNode.cpp +++ b/doric-Qt/doric/shader/DoricStackNode.cpp @@ -1,14 +1,13 @@ #include "DoricStackNode.h" -QQmlComponent *DoricStackNode::build() { - QQmlComponent *component = new QQmlComponent(); +QQuickItem *DoricStackNode::build() { + QQmlComponent component; const QUrl url(QStringLiteral("qrc:/stack.qml")); - component->loadUrl(url); + component.loadUrl(url); - return component; + QQuickItem *item = qobject_cast(component.create()); + return item; } -void DoricStackNode::blendLayoutConfig() { - DoricViewNode::blendLayoutConfig(); -} +void DoricStackNode::blendLayoutConfig() { DoricViewNode::blendLayoutConfig(); } diff --git a/doric-Qt/doric/shader/DoricStackNode.h b/doric-Qt/doric/shader/DoricStackNode.h index 0df832dd..249cd37a 100644 --- a/doric-Qt/doric/shader/DoricStackNode.h +++ b/doric-Qt/doric/shader/DoricStackNode.h @@ -8,7 +8,7 @@ class DoricStackNode : public DoricGroupNode public: using DoricGroupNode::DoricGroupNode; - QQmlComponent *build() override; + QQuickItem *build() override; void blendLayoutConfig() override; }; diff --git a/doric-Qt/doric/shader/DoricViewNode.h b/doric-Qt/doric/shader/DoricViewNode.h index 52e78890..91cbe2e5 100644 --- a/doric-Qt/doric/shader/DoricViewNode.h +++ b/doric-Qt/doric/shader/DoricViewNode.h @@ -1,16 +1,16 @@ #ifndef DORICVIEWNODE_H #define DORICVIEWNODE_H -#include +#include #include "../utils/DoricContextHolder.h" class DoricViewNode : public DoricContextHolder { protected: - QQmlComponent mView; + QQuickItem *mView; - virtual QQmlComponent *build() = 0; + virtual QQuickItem *build() = 0; virtual void blendLayoutConfig();