add navigation base on stack view
This commit is contained in:
parent
7cdef00c34
commit
5e1d67f912
@ -14,9 +14,32 @@
|
||||
#include "utils/DoricSwitchBridge.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) {
|
||||
qDebug() << mEngine->rootObjects()[0]->children();
|
||||
|
||||
QString name;
|
||||
switch (route.toInt()) {
|
||||
case 0:
|
||||
@ -91,54 +114,16 @@ void DoricDemoBridge::navigate(QVariant route) {
|
||||
}
|
||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||
|
||||
QQuickView *view = new QQuickView();
|
||||
{
|
||||
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
|
||||
view->setSource(url);
|
||||
view->setWidth(600);
|
||||
view->setHeight(800);
|
||||
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint |
|
||||
Qt::WindowTitleHint | Qt::WindowCloseButtonHint |
|
||||
Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint;
|
||||
view->setFlags(flag);
|
||||
}
|
||||
QQmlComponent component(mEngine);
|
||||
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
|
||||
component.loadUrl(url);
|
||||
QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create());
|
||||
DoricPanel *panel = new DoricPanel(mEngine, quickItem);
|
||||
quickItem->setWidth(600);
|
||||
quickItem->setHeight(800);
|
||||
QQuickItem *root = qobject_cast<QQuickItem *>(
|
||||
mEngine->rootObjects().at(0)->children().at(1));
|
||||
quickItem->setParentItem(root);
|
||||
|
||||
{
|
||||
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);
|
||||
panel->config(script, name, NULL);
|
||||
}
|
||||
|
@ -2,16 +2,19 @@
|
||||
#define DEMOBRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
class DoricDemoBridge : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DoricDemoBridge(QObject *parent = nullptr);
|
||||
explicit DoricDemoBridge(QQmlApplicationEngine *engine,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE
|
||||
void navigate(QVariant route);
|
||||
signals:
|
||||
|
||||
private:
|
||||
QQmlApplicationEngine *mEngine;
|
||||
};
|
||||
|
||||
#endif // DEMOBRIDGE_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QMovie>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QMovie>
|
||||
|
||||
#include "demo/DoricDemoBridge.h"
|
||||
#include "widget/flex/FlexLayoutService.h"
|
||||
@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
|
||||
Qt::QueuedConnection);
|
||||
|
||||
auto context = engine.rootContext();
|
||||
DoricDemoBridge *demoBridge = new DoricDemoBridge();
|
||||
DoricDemoBridge *demoBridge = new DoricDemoBridge(&engine);
|
||||
context->setContextProperty("demoBridge", demoBridge);
|
||||
|
||||
qDebug() << QMovie::supportedFormats();
|
||||
|
@ -7,88 +7,96 @@ ApplicationWindow {
|
||||
height: 800
|
||||
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 {
|
||||
id: stack
|
||||
initialItem: entry
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user