This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/demo/DoricDemoBridge.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

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-03-18 11:49:52 +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-02 20:47:15 +08:00
name = "Gobang.js";
2021-03-17 19:38:22 +08:00
break;
case 2:
2021-04-16 10:06:15 +08:00
name = "LayoutDemo.js";
2021-03-19 19:17:11 +08:00
break;
case 3:
2021-04-21 11:08:49 +08:00
name = "ModalDemo.js";
2021-04-16 10:06:15 +08:00
break;
case 4:
2021-04-21 11:08:49 +08:00
name = "SimpleDemo.js";
break;
case 5:
2021-04-02 20:47:15 +08:00
name = "Snake.js";
2021-03-01 18:59:09 +08:00
break;
}
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);
view->setWidth(405);
view->setHeight(720);
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);
quickItem->setWidth(405);
quickItem->setHeight(720);
2021-03-01 18:59:09 +08:00
quickItem->setParentItem(view->rootObject());
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-02-04 16:59:58 +08:00
}