add navigation base on stack view

This commit is contained in:
王劲鹏 2021-06-08 11:43:34 +08:00 committed by osborn
parent 7cdef00c34
commit 5e1d67f912
4 changed files with 130 additions and 134 deletions

View File

@ -14,9 +14,32 @@
#include "utils/DoricSwitchBridge.h" #include "utils/DoricSwitchBridge.h"
#include "utils/DoricUtils.h" #include "utils/DoricUtils.h"
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {} DoricDemoBridge::DoricDemoBridge(QQmlApplicationEngine *engine, QObject *parent)
: QObject(parent) {
this->mEngine = engine;
auto context = mEngine->rootContext();
DoricMouseAreaBridge *mouseAreaBridge = new DoricMouseAreaBridge();
context->setContextProperty("mouseAreaBridge", mouseAreaBridge);
DoricDialogBridge *dialogBridge = new DoricDialogBridge();
context->setContextProperty("dialogBridge", dialogBridge);
DoricImageBridge *imageBridge = new DoricImageBridge();
context->setContextProperty("imageBridge", imageBridge);
DoricInputBridge *inputBridge = new DoricInputBridge();
context->setContextProperty("inputBridge", inputBridge);
DoricSwitchBridge *switchBridge = new DoricSwitchBridge();
context->setContextProperty("switchBridge", switchBridge);
DoricSlideItemBridge *slideItemBridge = new DoricSlideItemBridge();
context->setContextProperty("slideItemBridge", slideItemBridge);
DoricSliderBridge *sliderBridge = new DoricSliderBridge();
context->setContextProperty("sliderBridge", sliderBridge);
DoricDraggableBridge *draggableBridge = new DoricDraggableBridge();
context->setContextProperty("draggableBridge", draggableBridge);
}
void DoricDemoBridge::navigate(QVariant route) { void DoricDemoBridge::navigate(QVariant route) {
qDebug() << mEngine->rootObjects()[0]->children();
QString name; QString name;
switch (route.toInt()) { switch (route.toInt()) {
case 0: case 0:
@ -91,54 +114,16 @@ void DoricDemoBridge::navigate(QVariant route) {
} }
QString script = DoricUtils::readAssetFile("/doric/bundles", name); QString script = DoricUtils::readAssetFile("/doric/bundles", name);
QQuickView *view = new QQuickView(); QQmlComponent component(mEngine);
{ const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml")); component.loadUrl(url);
view->setSource(url); QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create());
view->setWidth(600); DoricPanel *panel = new DoricPanel(mEngine, quickItem);
view->setHeight(800); quickItem->setWidth(600);
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | quickItem->setHeight(800);
Qt::WindowTitleHint | Qt::WindowCloseButtonHint | QQuickItem *root = qobject_cast<QQuickItem *>(
Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint; mEngine->rootObjects().at(0)->children().at(1));
view->setFlags(flag); quickItem->setParentItem(root);
}
{ panel->config(script, name, NULL);
QQmlComponent component(view->engine());
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
component.loadUrl(url);
QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create());
DoricPanel *panel = new DoricPanel(view->engine(), quickItem);
quickItem->setWidth(600);
quickItem->setHeight(800);
quickItem->setParentItem(view->rootObject());
panel->config(script, name, NULL);
connect(view, &QQuickView::visibleChanged, this, [view, panel]() {
if (!view->isVisible()) {
delete panel;
}
});
}
view->show();
auto context = view->engine()->rootContext();
DoricMouseAreaBridge *mouseAreaBridge = new DoricMouseAreaBridge();
context->setContextProperty("mouseAreaBridge", mouseAreaBridge);
DoricDialogBridge *dialogBridge = new DoricDialogBridge();
context->setContextProperty("dialogBridge", dialogBridge);
DoricImageBridge *imageBridge = new DoricImageBridge();
context->setContextProperty("imageBridge", imageBridge);
DoricInputBridge *inputBridge = new DoricInputBridge();
context->setContextProperty("inputBridge", inputBridge);
DoricSwitchBridge *switchBridge = new DoricSwitchBridge();
context->setContextProperty("switchBridge", switchBridge);
DoricSlideItemBridge *slideItemBridge = new DoricSlideItemBridge();
context->setContextProperty("slideItemBridge", slideItemBridge);
DoricSliderBridge *sliderBridge = new DoricSliderBridge();
context->setContextProperty("sliderBridge", sliderBridge);
DoricDraggableBridge *draggableBridge = new DoricDraggableBridge();
context->setContextProperty("draggableBridge", draggableBridge);
} }

View File

@ -2,16 +2,19 @@
#define DEMOBRIDGE_H #define DEMOBRIDGE_H
#include <QObject> #include <QObject>
#include <QVariant> #include <QQmlApplicationEngine>
class DoricDemoBridge : public QObject { class DoricDemoBridge : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit DoricDemoBridge(QObject *parent = nullptr); explicit DoricDemoBridge(QQmlApplicationEngine *engine,
QObject *parent = nullptr);
Q_INVOKABLE Q_INVOKABLE
void navigate(QVariant route); void navigate(QVariant route);
signals:
private:
QQmlApplicationEngine *mEngine;
}; };
#endif // DEMOBRIDGE_H #endif // DEMOBRIDGE_H

View File

@ -1,7 +1,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QMovie>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlContext> #include <QQmlContext>
#include <QMovie>
#include "demo/DoricDemoBridge.h" #include "demo/DoricDemoBridge.h"
#include "widget/flex/FlexLayoutService.h" #include "widget/flex/FlexLayoutService.h"
@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
Qt::QueuedConnection); Qt::QueuedConnection);
auto context = engine.rootContext(); auto context = engine.rootContext();
DoricDemoBridge *demoBridge = new DoricDemoBridge(); DoricDemoBridge *demoBridge = new DoricDemoBridge(&engine);
context->setContextProperty("demoBridge", demoBridge); context->setContextProperty("demoBridge", demoBridge);
qDebug() << QMovie::supportedFormats(); qDebug() << QMovie::supportedFormats();

View File

@ -7,88 +7,96 @@ ApplicationWindow {
height: 800 height: 800
title: qsTr("Doric Demo") title: qsTr("Doric Demo")
Rectangle {
anchors.fill: parent
ScrollView {
id: entry
anchors.fill: parent
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
ListView {
width: parent.width
model: 23
delegate: Rectangle {
Column {
anchors.centerIn: parent
Text {
text: {
switch (index) {
case 0:
return "ComponetDemo.js"
case 1:
return "Counter.js"
case 2:
return "DraggableDemo.js"
case 3:
return "EffectsDemo.js"
case 4:
return "FlexDemo.js"
case 5:
return "Gobang.js"
case 6:
return "ImageDemo.js"
case 7:
return "InputDemo.js"
case 8:
return "LayoutDemo.js"
case 9:
return "LayoutTestDemo.js"
case 10:
return "ModalDemo.js"
case 11:
return "ModularDemo.js"
case 12:
return "NavigatorDemo.js"
case 13:
return "NetworkDemo.js"
case 14:
return "NotificationDemo.js"
case 15:
return "PopoverDemo.js"
case 16:
return "ScrollerDemo.js"
case 17:
return "SimpleDemo.js"
case 18:
return "SliderDemo.js"
case 19:
return "Snake.js"
case 20:
return "StorageDemo.js"
case 21:
return "SwitchDemo.js"
case 22:
return "TextDemo.js"
}
}
}
}
width: parent.width
height: 60
MouseArea {
anchors.fill: parent
onClicked: {
demoBridge.navigate(index)
}
}
}
}
}
onChildrenChanged: {
stack.push(this.children[this.children.length - 1])
}
}
StackView { StackView {
id: stack id: stack
initialItem: entry initialItem: entry
anchors.fill: parent anchors.fill: parent
} }
ScrollView {
id: entry
anchors.fill: parent
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
ListView {
width: parent.width
model: 23
delegate: Rectangle {
Column {
anchors.centerIn: parent
Text {
text: {
switch (index) {
case 0:
return "ComponetDemo.js"
case 1:
return "Counter.js"
case 2:
return "DraggableDemo.js"
case 3:
return "EffectsDemo.js"
case 4:
return "FlexDemo.js"
case 5:
return "Gobang.js"
case 6:
return "ImageDemo.js"
case 7:
return "InputDemo.js"
case 8:
return "LayoutDemo.js"
case 9:
return "LayoutTestDemo.js"
case 10:
return "ModalDemo.js"
case 11:
return "ModularDemo.js"
case 12:
return "NavigatorDemo.js"
case 13:
return "NetworkDemo.js"
case 14:
return "NotificationDemo.js"
case 15:
return "PopoverDemo.js"
case 16:
return "ScrollerDemo.js"
case 17:
return "SimpleDemo.js"
case 18:
return "SliderDemo.js"
case 19:
return "Snake.js"
case 20:
return "StorageDemo.js"
case 21:
return "SwitchDemo.js"
case 22:
return "TextDemo.js"
}
}
}
}
width: parent.width
height: 60
MouseArea {
anchors.fill: parent
onClicked: {
demoBridge.navigate(index)
}
}
}
}
}
} }