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

45 lines
1.1 KiB
C++
Raw Normal View History

2021-02-04 16:59:58 +08:00
#include <QDebug>
2021-02-09 17:42:11 +08:00
#include <QQuickView>
2021-02-04 16:59:58 +08:00
#include "DoricDemoBridge.h"
#include "DoricPanel.h"
#include "utils/DoricUtils.h"
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-03-01 18:59:09 +08:00
name = "SimpleDemo.es5.js";
break;
case 1:
name = "Snake.es5.js";
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(450);
view->setHeight(800);
}
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(450);
quickItem->setHeight(800);
quickItem->setParentItem(view->rootObject());
2021-03-01 18:59:09 +08:00
panel->config(script, name, NULL);
2021-02-04 16:59:58 +08:00
}
2021-03-01 18:59:09 +08:00
view->show();
2021-02-04 16:59:58 +08:00
}