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/example/app/demo/DoricDemoBridge.cpp

60 lines
2.4 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-04 16:59:58 +08:00
#include "DoricDemoBridge.h"
#include "DoricPanel.h"
2021-06-10 11:05:31 +08:00
#include "loader/DoricJSLoaderManager.h"
2021-04-22 13:42:38 +08:00
#include "utils/DoricDialogBridge.h"
2021-06-02 11:26:11 +08:00
#include "utils/DoricDraggableBridge.h"
2021-04-23 17:56:08 +08:00
#include "utils/DoricImageBridge.h"
2021-05-27 10:56:58 +08:00
#include "utils/DoricInputBridge.h"
2021-04-22 14:54:31 +08:00
#include "utils/DoricMouseAreaBridge.h"
2021-05-31 19:28:45 +08:00
#include "utils/DoricSlideItemBridge.h"
2021-06-01 19:30:37 +08:00
#include "utils/DoricSliderBridge.h"
2021-05-27 18:18:30 +08:00
#include "utils/DoricSwitchBridge.h"
2021-04-09 16:39:43 +08:00
#include "utils/DoricUtils.h"
2021-02-04 16:59:58 +08:00
2021-06-08 11:43:34 +08:00
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);
}
2021-02-04 16:59:58 +08:00
2021-06-10 14:06:36 +08:00
void DoricDemoBridge::navigate(QVariant source, QVariant alias) {
2021-06-10 11:05:31 +08:00
std::shared_ptr<DoricAsyncResult> asyncResult =
2021-06-10 14:06:36 +08:00
DoricJSLoaderManager::getInstance()->request(source.toString());
2021-06-10 11:05:31 +08:00
QString script = asyncResult->getResult();
2021-02-09 17:42:11 +08:00
2021-06-08 11:43:34 +08:00
QQmlComponent component(mEngine);
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
component.loadUrl(url);
QObject *object = component.create();
QQuickItem *quickItem = qobject_cast<QQuickItem *>(object);
2021-06-08 11:43:34 +08:00
DoricPanel *panel = new DoricPanel(mEngine, quickItem);
quickItem->setWidth(600);
quickItem->setHeight(800);
2021-06-10 14:06:36 +08:00
panel->config(script, alias.toString(), NULL);
QObject *window = mEngine->rootObjects().at(0);
QVariant arg = QVariant::fromValue(object);
QMetaObject::invokeMethod(window, "navigatorPush", Q_ARG(QVariant, arg));
2021-02-04 16:59:58 +08:00
}