refactor doric panel; add blend method
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| #include "DoricPanel.h" | #include "DoricPanel.h" | ||||||
| #include "shader/DoricRootNode.h" | #include "shader/DoricRootNode.h" | ||||||
|  |  | ||||||
| DoricPanel::DoricPanel() {} | DoricPanel::DoricPanel(QQuickItem *quickItem) { mQuickItem = quickItem; } | ||||||
|  |  | ||||||
| void DoricPanel::config(QString script, QString alias, QString extra) { | void DoricPanel::config(QString script, QString alias, QString extra) { | ||||||
|   DoricContext *context = DoricContext::create(script, alias, extra); |   DoricContext *context = DoricContext::create(script, alias, extra); | ||||||
| @@ -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); |   this->mContext->getRootNode()->setRootView(mQuickItem); | ||||||
|   this->mContext->build(width(), height()); |   this->mContext->build(mQuickItem->width(), mQuickItem->height()); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,14 +5,16 @@ | |||||||
|  |  | ||||||
| #include "DoricContext.h" | #include "DoricContext.h" | ||||||
|  |  | ||||||
| class DoricPanel : public QQuickItem { | class DoricPanel { | ||||||
| private: | private: | ||||||
|   DoricContext *mContext; |   DoricContext *mContext; | ||||||
|   int renderedWidth = -1; |   int renderedWidth = -1; | ||||||
|   int renderedHeight = -1; |   int renderedHeight = -1; | ||||||
|  |  | ||||||
|  |   QQuickItem *mQuickItem; | ||||||
|  |  | ||||||
| public: | public: | ||||||
|   DoricPanel(); |   DoricPanel(QQuickItem *quickItem); | ||||||
|  |  | ||||||
|   void config(QString script, QString alias, QString extra); |   void config(QString script, QString alias, QString extra); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,23 +21,18 @@ void DoricDemoBridge::navigate(QVariant route) { | |||||||
|       view->setHeight(800); |       view->setHeight(800); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     DoricPanel *panel = new DoricPanel(); |     { | ||||||
|     panel->setParentItem(view->rootObject()); |       QQmlComponent component(view->engine()); | ||||||
|     panel->setWidth(450); |       const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml")); | ||||||
|     panel->setHeight(800); |       component.loadUrl(url); | ||||||
|  |       QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create()); | ||||||
|  |       DoricPanel *panel = new DoricPanel(quickItem); | ||||||
|  |       quickItem->setWidth(450); | ||||||
|  |       quickItem->setHeight(800); | ||||||
|  |       quickItem->setParentItem(view->rootObject()); | ||||||
|  |  | ||||||
|       panel->config(script, name, NULL); |       panel->config(script, name, NULL); | ||||||
|  |  | ||||||
|     QQmlEngine *engine = view->engine(); |  | ||||||
|     QQmlComponent component(engine); |  | ||||||
|     const QUrl empty(QStringLiteral("qrc:/doric/qml/panel.qml")); |  | ||||||
|     component.loadUrl(empty); |  | ||||||
|     QQuickItem *childItem = qobject_cast<QQuickItem *>(component.create()); |  | ||||||
|  |  | ||||||
|     if (childItem == nullptr) { |  | ||||||
|       qCritical() << component.errorString(); |  | ||||||
|       return; |  | ||||||
|     } |     } | ||||||
|     childItem->setParentItem(view->rootObject()); |  | ||||||
|  |  | ||||||
|     view->show(); |     view->show(); | ||||||
|     break; |     break; | ||||||
|   | |||||||
| @@ -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.14.0, 2021-02-19T15:04:39. --> | <!-- Written by QtCreator 4.14.0, 2021-02-19T18:27:52. --> | ||||||
| <qtcreator> | <qtcreator> | ||||||
|  <data> |  <data> | ||||||
|   <variable>EnvironmentId</variable> |   <variable>EnvironmentId</variable> | ||||||
|   | |||||||
| @@ -1,8 +1,5 @@ | |||||||
| import QtQuick 2.12 | import QtQuick 2.12 | ||||||
| import QtQuick.Controls 2.5 | import QtQuick.Controls 2.5 | ||||||
|  |  | ||||||
| Rectangle { | StackView { | ||||||
|     width: 100 |  | ||||||
|     height: 100 |  | ||||||
|     color: 'red' |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1 +1,19 @@ | |||||||
| #include "DoricGroupNode.h" | #include "DoricGroupNode.h" | ||||||
|  |  | ||||||
|  | void DoricGroupNode::blend(QQuickItem *view, QString name, QJSValue prop) { | ||||||
|  |   if (name == "children") { | ||||||
|  |     mChildViewIds.clear(); | ||||||
|  |     if (prop.isArray()) { | ||||||
|  |         qDebug() << prop.toString(); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     DoricSuperNode::blend(view, name, prop); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void DoricGroupNode::blend(QJSValue jsValue) { | ||||||
|  |   DoricViewNode::blend(jsValue); | ||||||
|  |   configChildNode(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void DoricGroupNode::configChildNode() {} | ||||||
|   | |||||||
| @@ -6,6 +6,17 @@ | |||||||
| class DoricGroupNode : public DoricSuperNode { | class DoricGroupNode : public DoricSuperNode { | ||||||
| public: | public: | ||||||
|   using DoricSuperNode::DoricSuperNode; |   using DoricSuperNode::DoricSuperNode; | ||||||
|  |  | ||||||
|  |   virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; | ||||||
|  |  | ||||||
|  |   virtual void blend(QJSValue jsValue) override; | ||||||
|  |  | ||||||
|  | protected: | ||||||
|  |   QList<DoricViewNode *> mChildNodes; | ||||||
|  |  | ||||||
|  |   QList<QString> mChildViewIds; | ||||||
|  |  | ||||||
|  |   void configChildNode(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // DORICGROUPNODE_H | #endif // DORICGROUPNODE_H | ||||||
|   | |||||||
| @@ -1 +1,11 @@ | |||||||
| #include "DoricSuperNode.h" | #include "DoricSuperNode.h" | ||||||
|  |  | ||||||
|  | void DoricSuperNode::blend(QQuickItem *view, QString name, QJSValue prop) { | ||||||
|  |   if (name == "subviews") { | ||||||
|  |     if (prop.isArray()) { | ||||||
|  |       qDebug() << prop.toString(); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     DoricViewNode::blend(view, name, prop); | ||||||
|  |   } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -6,6 +6,8 @@ | |||||||
| class DoricSuperNode : public DoricViewNode { | class DoricSuperNode : public DoricViewNode { | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
|  |   virtual void blend(QQuickItem *view, QString name, QJSValue prop) override; | ||||||
|  |  | ||||||
|   void blendSubLayoutConfig(DoricViewNode *viewNode); |   void blendSubLayoutConfig(DoricViewNode *viewNode); | ||||||
|  |  | ||||||
| public: | public: | ||||||
|   | |||||||
| @@ -1,6 +1,8 @@ | |||||||
| #include "DoricViewNode.h" | #include <QJSValueIterator> | ||||||
|  |  | ||||||
| #include "../utils/DoricUtils.h" | #include "../utils/DoricUtils.h" | ||||||
| #include "DoricSuperNode.h" | #include "DoricSuperNode.h" | ||||||
|  | #include "DoricViewNode.h" | ||||||
|  |  | ||||||
| void DoricViewNode::blendLayoutConfig() {} | void DoricViewNode::blendLayoutConfig() {} | ||||||
|  |  | ||||||
| @@ -19,4 +21,18 @@ QString DoricViewNode::getId() { return mId; } | |||||||
|  |  | ||||||
| void DoricViewNode::setId(QString id) { mId = id; } | void DoricViewNode::setId(QString id) { mId = id; } | ||||||
|  |  | ||||||
| void DoricViewNode::blend(QJSValue jsValue) { qDebug() << jsValue.toString(); } | void DoricViewNode::blend(QJSValue jsValue) { | ||||||
|  |   QJSValueIterator it(jsValue); | ||||||
|  |   while (it.hasNext()) { | ||||||
|  |     it.next(); | ||||||
|  |     qDebug() << it.name() << ": " << it.value().toString(); | ||||||
|  |     blend(mView, it.name(), it.value()); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) { | ||||||
|  |   if (name == "width") { | ||||||
|  |  | ||||||
|  |   } else if (name == "height") { | ||||||
|  |   } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -33,6 +33,8 @@ public: | |||||||
|  |  | ||||||
|   void setId(QString id); |   void setId(QString id); | ||||||
|  |  | ||||||
|   void blend(QJSValue jsValue); |   virtual void blend(QJSValue jsValue); | ||||||
|  |  | ||||||
|  |   virtual void blend(QQuickItem *view, QString name, QJSValue prop); | ||||||
| }; | }; | ||||||
| #endif // DORICVIEWNODE_H | #endif // DORICVIEWNODE_H | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user