change qml component to quick item

This commit is contained in:
王劲鹏 2021-02-19 10:04:54 +08:00 committed by osborn
parent 3eeb062d2e
commit 36427898cb
9 changed files with 29 additions and 24 deletions

View File

@ -10,6 +10,6 @@ void DoricPanel::config(QString script, QString alias, QString extra) {
void DoricPanel::config(DoricContext *context) { void DoricPanel::config(DoricContext *context) {
this->mContext = context; this->mContext = context;
this->mContext->getRootNode()->setRootView(); this->mContext->getRootNode()->setRootView(this);
this->mContext->build(960, 720); this->mContext->build(width(), height());
} }

View File

@ -1,9 +1,11 @@
#ifndef PANEL_H #ifndef PANEL_H
#define PANEL_H #define PANEL_H
#include <QQuickItem>
#include "DoricContext.h" #include "DoricContext.h"
class DoricPanel { class DoricPanel : public QQuickItem {
private: private:
DoricContext *mContext; DoricContext *mContext;
int renderedWidth = -1; int renderedWidth = -1;

View File

@ -1,5 +1,4 @@
#include <QDebug> #include <QDebug>
#include <QQuickItem>
#include <QQuickView> #include <QQuickView>
#include "DoricDemoBridge.h" #include "DoricDemoBridge.h"
@ -15,15 +14,16 @@ void DoricDemoBridge::navigate(QVariant route) {
QString script = DoricUtils::readAssetFile("/doric/bundles", name); QString script = DoricUtils::readAssetFile("/doric/bundles", name);
QQuickView *view = new QQuickView(); QQuickView *view = new QQuickView();
view->setWidth(960); view->setWidth(450);
view->setHeight(720); view->setHeight(800);
QColor color("blue"); QColor blue("blue");
view->setColor(color); view->setColor(blue);
view->show(); view->show();
view->rootObject();
DoricPanel *panel = new DoricPanel(); DoricPanel *panel = new DoricPanel();
panel->setParent(view);
panel->setWidth(450);
panel->setHeight(800);
panel->config(script, name, NULL); panel->config(script, name, NULL);
break; break;
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2021-02-05T15:58:19. --> <!-- Written by QtCreator 4.11.1, 2021-02-10T15:05:52. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -1,3 +1,5 @@
#include "DoricRootNode.h" #include "DoricRootNode.h"
void DoricRootNode::setRootView() {} void DoricRootNode::setRootView(QQuickItem *rootView) {
this->mView = rootView;
}

View File

@ -1,13 +1,15 @@
#ifndef ROOTNODE_H #ifndef ROOTNODE_H
#define ROOTNODE_H #define ROOTNODE_H
#include <QQuickItem>
#include "DoricStackNode.h" #include "DoricStackNode.h"
class DoricRootNode : public DoricStackNode { class DoricRootNode : public DoricStackNode {
public: public:
using DoricStackNode::DoricStackNode; using DoricStackNode::DoricStackNode;
void setRootView(); void setRootView(QQuickItem *rootView);
}; };
#endif // ROOTNODE_H #endif // ROOTNODE_H

View File

@ -1,14 +1,13 @@
#include "DoricStackNode.h" #include "DoricStackNode.h"
QQmlComponent *DoricStackNode::build() { QQuickItem *DoricStackNode::build() {
QQmlComponent *component = new QQmlComponent(); QQmlComponent component;
const QUrl url(QStringLiteral("qrc:/stack.qml")); const QUrl url(QStringLiteral("qrc:/stack.qml"));
component->loadUrl(url); component.loadUrl(url);
return component; QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
return item;
} }
void DoricStackNode::blendLayoutConfig() { void DoricStackNode::blendLayoutConfig() { DoricViewNode::blendLayoutConfig(); }
DoricViewNode::blendLayoutConfig();
}

View File

@ -8,7 +8,7 @@ class DoricStackNode : public DoricGroupNode
public: public:
using DoricGroupNode::DoricGroupNode; using DoricGroupNode::DoricGroupNode;
QQmlComponent *build() override; QQuickItem *build() override;
void blendLayoutConfig() override; void blendLayoutConfig() override;
}; };

View File

@ -1,16 +1,16 @@
#ifndef DORICVIEWNODE_H #ifndef DORICVIEWNODE_H
#define DORICVIEWNODE_H #define DORICVIEWNODE_H
#include <QQmlComponent> #include <QQuickItem>
#include "../utils/DoricContextHolder.h" #include "../utils/DoricContextHolder.h"
class DoricViewNode : public DoricContextHolder { class DoricViewNode : public DoricContextHolder {
protected: protected:
QQmlComponent mView; QQuickItem *mView;
virtual QQmlComponent *build() = 0; virtual QQuickItem *build() = 0;
virtual void blendLayoutConfig(); virtual void blendLayoutConfig();