2021-02-04 16:59:58 +08:00
|
|
|
#include <QDebug>
|
2021-03-18 11:49:52 +08:00
|
|
|
#include <QQmlContext>
|
2021-02-09 17:42:11 +08:00
|
|
|
#include <QQuickView>
|
2021-02-04 16:59:58 +08:00
|
|
|
|
|
|
|
#include "DoricDemoBridge.h"
|
|
|
|
#include "DoricPanel.h"
|
2021-04-22 13:42:38 +08:00
|
|
|
#include "utils/DoricDialogBridge.h"
|
2021-04-23 17:56:08 +08:00
|
|
|
#include "utils/DoricImageBridge.h"
|
2021-04-22 14:54:31 +08:00
|
|
|
#include "utils/DoricMouseAreaBridge.h"
|
2021-04-09 16:39:43 +08:00
|
|
|
#include "utils/DoricUtils.h"
|
2021-02-04 16:59:58 +08:00
|
|
|
|
|
|
|
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
|
|
|
|
|
|
|
void DoricDemoBridge::navigate(QVariant route) {
|
2021-03-01 18:59:09 +08:00
|
|
|
QString name;
|
2021-02-04 16:59:58 +08:00
|
|
|
switch (route.toInt()) {
|
|
|
|
case 0:
|
2021-04-02 20:47:15 +08:00
|
|
|
name = "Counter.js";
|
2021-03-01 18:59:09 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-04-25 18:38:54 +08:00
|
|
|
name = "EffectsDemo.js";
|
2021-03-17 19:38:22 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-04-25 18:38:54 +08:00
|
|
|
name = "Gobang.js";
|
2021-03-19 19:17:11 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-04-25 18:38:54 +08:00
|
|
|
name = "ImageDemo.js";
|
2021-04-16 10:06:15 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2021-04-25 18:38:54 +08:00
|
|
|
name = "LayoutDemo.js";
|
2021-04-21 11:08:49 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2021-04-30 21:04:13 +08:00
|
|
|
name = "LayoutTestDemo.js";
|
2021-04-22 14:54:31 +08:00
|
|
|
break;
|
|
|
|
case 6:
|
2021-04-30 21:04:13 +08:00
|
|
|
name = "ModalDemo.js";
|
2021-04-22 21:20:36 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
2021-04-30 21:04:13 +08:00
|
|
|
name = "NetworkDemo.js";
|
2021-04-25 15:02:36 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
2021-04-30 21:04:13 +08:00
|
|
|
name = "PopoverDemo.js";
|
2021-04-25 18:38:54 +08:00
|
|
|
break;
|
|
|
|
case 9:
|
2021-04-30 21:04:13 +08:00
|
|
|
name = "SimpleDemo.js";
|
|
|
|
break;
|
|
|
|
case 10:
|
2021-04-02 20:47:15 +08:00
|
|
|
name = "Snake.js";
|
2021-03-01 18:59:09 +08:00
|
|
|
break;
|
2021-05-06 10:01:56 +08:00
|
|
|
case 11:
|
|
|
|
name = "StorageDemo.js";
|
|
|
|
break;
|
2021-03-01 18:59:09 +08:00
|
|
|
}
|
|
|
|
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
2021-02-09 17:42:11 +08:00
|
|
|
|
2021-03-01 18:59:09 +08:00
|
|
|
QQuickView *view = new QQuickView();
|
|
|
|
{
|
|
|
|
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
|
|
|
|
view->setSource(url);
|
2021-04-23 17:56:08 +08:00
|
|
|
view->setWidth(600);
|
|
|
|
view->setHeight(800);
|
2021-04-09 16:39:43 +08:00
|
|
|
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint |
|
|
|
|
Qt::WindowTitleHint | Qt::WindowCloseButtonHint |
|
|
|
|
Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint;
|
|
|
|
view->setFlags(flag);
|
2021-03-01 18:59:09 +08:00
|
|
|
}
|
2021-02-19 19:01:31 +08:00
|
|
|
|
2021-03-01 18:59:09 +08:00
|
|
|
{
|
|
|
|
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);
|
2021-04-23 17:56:08 +08:00
|
|
|
quickItem->setWidth(600);
|
|
|
|
quickItem->setHeight(800);
|
2021-03-01 18:59:09 +08:00
|
|
|
quickItem->setParentItem(view->rootObject());
|
2021-02-19 15:43:09 +08:00
|
|
|
|
2021-03-01 18:59:09 +08:00
|
|
|
panel->config(script, name, NULL);
|
2021-04-09 16:39:43 +08:00
|
|
|
|
|
|
|
connect(view, &QQuickView::visibleChanged, this, [view, panel]() {
|
|
|
|
if (!view->isVisible()) {
|
|
|
|
delete panel;
|
|
|
|
}
|
|
|
|
});
|
2021-02-04 16:59:58 +08:00
|
|
|
}
|
2021-03-01 18:59:09 +08:00
|
|
|
|
|
|
|
view->show();
|
2021-03-18 11:49:52 +08:00
|
|
|
|
|
|
|
auto context = view->engine()->rootContext();
|
|
|
|
DoricMouseAreaBridge *mouseAreaBridge = new DoricMouseAreaBridge();
|
|
|
|
context->setContextProperty("mouseAreaBridge", mouseAreaBridge);
|
2021-04-22 13:42:38 +08:00
|
|
|
DoricDialogBridge *dialogBridge = new DoricDialogBridge();
|
|
|
|
context->setContextProperty("dialogBridge", dialogBridge);
|
2021-04-23 17:56:08 +08:00
|
|
|
DoricImageBridge *imageBridge = new DoricImageBridge();
|
|
|
|
context->setContextProperty("imageBridge", imageBridge);
|
2021-02-04 16:59:58 +08:00
|
|
|
}
|