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

134 lines
3.6 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 11:05:31 +08:00
void DoricDemoBridge::navigate(QVariant path, QVariant index) {
2021-03-01 18:59:09 +08:00
QString name;
2021-06-10 11:05:31 +08:00
switch (index.toInt()) {
2021-02-04 16:59:58 +08:00
case 0:
2021-05-27 18:27:08 +08:00
name = "ComponetDemo.js";
2021-03-01 18:59:09 +08:00
break;
case 1:
2021-05-27 18:27:08 +08:00
name = "Counter.js";
2021-03-17 19:38:22 +08:00
break;
case 2:
2021-06-02 09:53:58 +08:00
name = "DraggableDemo.js";
2021-03-19 19:17:11 +08:00
break;
case 3:
2021-06-02 09:53:58 +08:00
name = "EffectsDemo.js";
2021-04-16 10:06:15 +08:00
break;
case 4:
2021-06-02 16:34:38 +08:00
name = "FlexDemo.js";
2021-04-21 11:08:49 +08:00
break;
case 5:
2021-06-02 16:34:38 +08:00
name = "Gobang.js";
2021-04-22 14:54:31 +08:00
break;
case 6:
2021-06-02 16:34:38 +08:00
name = "ImageDemo.js";
2021-04-22 21:20:36 +08:00
break;
case 7:
2021-06-02 16:34:38 +08:00
name = "InputDemo.js";
2021-04-25 15:02:36 +08:00
break;
case 8:
2021-06-02 16:34:38 +08:00
name = "LayoutDemo.js";
2021-04-25 18:38:54 +08:00
break;
case 9:
2021-06-02 16:34:38 +08:00
name = "LayoutTestDemo.js";
2021-04-30 21:04:13 +08:00
break;
case 10:
2021-06-02 16:34:38 +08:00
name = "ModalDemo.js";
2021-03-01 18:59:09 +08:00
break;
2021-05-06 10:01:56 +08:00
case 11:
2021-06-02 16:34:38 +08:00
name = "ModularDemo.js";
2021-05-06 16:47:12 +08:00
break;
case 12:
2021-06-08 10:25:36 +08:00
name = "NavigatorDemo.js";
2021-05-06 10:01:56 +08:00
break;
2021-05-25 11:08:19 +08:00
case 13:
2021-06-08 10:25:36 +08:00
name = "NetworkDemo.js";
2021-05-25 16:51:39 +08:00
break;
case 14:
2021-06-08 10:25:36 +08:00
name = "NotificationDemo.js";
2021-05-27 16:56:57 +08:00
break;
case 15:
2021-06-08 10:25:36 +08:00
name = "PopoverDemo.js";
2021-05-27 18:27:08 +08:00
break;
case 16:
2021-06-08 10:25:36 +08:00
name = "ScrollerDemo.js";
2021-05-27 18:42:33 +08:00
break;
case 17:
2021-06-08 10:25:36 +08:00
name = "SimpleDemo.js";
2021-05-31 16:00:06 +08:00
break;
case 18:
2021-06-08 10:25:36 +08:00
name = "SliderDemo.js";
2021-06-02 09:53:58 +08:00
break;
case 19:
2021-06-08 10:25:36 +08:00
name = "Snake.js";
2021-06-02 16:34:38 +08:00
break;
case 20:
2021-06-08 10:25:36 +08:00
name = "StorageDemo.js";
2021-06-07 16:23:31 +08:00
break;
case 21:
2021-06-08 10:25:36 +08:00
name = "SwitchDemo.js";
break;
case 22:
2021-05-25 11:08:19 +08:00
name = "TextDemo.js";
break;
2021-03-01 18:59:09 +08:00
}
2021-06-10 11:05:31 +08:00
QString resourcePath = path.toString();
std::shared_ptr<DoricAsyncResult> asyncResult =
DoricJSLoaderManager::getInstance()->request(resourcePath + name);
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);
panel->config(script, name, 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
}