diff --git a/doric-Qt/doric/demo/DoricDemoBridge.cpp b/doric-Qt/doric/demo/DoricDemoBridge.cpp index 0ec52424..20ec7dd8 100644 --- a/doric-Qt/doric/demo/DoricDemoBridge.cpp +++ b/doric-Qt/doric/demo/DoricDemoBridge.cpp @@ -1,9 +1,11 @@ #include +#include #include #include "DoricDemoBridge.h" #include "DoricPanel.h" #include "utils/DoricUtils.h" +#include "utils/DoricMouseAreaBridge.h" DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {} @@ -44,4 +46,8 @@ void DoricDemoBridge::navigate(QVariant route) { } view->show(); + + auto context = view->engine()->rootContext(); + DoricMouseAreaBridge *mouseAreaBridge = new DoricMouseAreaBridge(); + context->setContextProperty("mouseAreaBridge", mouseAreaBridge); } diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index a18e77e8..4afb7243 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -41,6 +41,7 @@ SOURCES += \ shader/DoricViewNode.cpp \ utils/DoricConstant.cpp \ utils/DoricContextHolder.cpp \ + utils/DoricMouseAreaBridge.cpp \ widget/flex/FlexLayout.cpp \ widget/flex/FlexLayoutConfig.cpp \ widget/flex/FlexLayoutService.cpp \ @@ -104,6 +105,7 @@ HEADERS += \ utils/DoricConstant.h \ utils/DoricContextHolder.h \ utils/DoricCountDownLatch.h \ + utils/DoricMouseAreaBridge.h \ utils/DoricObjectFactory.h \ utils/DoricThreadMode.h \ utils/DoricUtils.h \ diff --git a/doric-Qt/doric/resources/text.qml b/doric-Qt/doric/resources/text.qml index 078c6a94..c618603d 100644 --- a/doric-Qt/doric/resources/text.qml +++ b/doric-Qt/doric/resources/text.qml @@ -48,4 +48,11 @@ Rectangle { } } } + + MouseArea { + anchors.fill: parent + onClicked: { + mouseAreaBridge.onClick("index") + } + } } diff --git a/doric-Qt/doric/utils/DoricMouseAreaBridge.cpp b/doric-Qt/doric/utils/DoricMouseAreaBridge.cpp new file mode 100644 index 00000000..3041e09b --- /dev/null +++ b/doric-Qt/doric/utils/DoricMouseAreaBridge.cpp @@ -0,0 +1,7 @@ +#include "DoricMouseAreaBridge.h" + +DoricMouseAreaBridge::DoricMouseAreaBridge(QObject *parent) : QObject(parent) {} + +void DoricMouseAreaBridge::onClick(QVariant functionId) { + qCritical() << functionId; +} diff --git a/doric-Qt/doric/utils/DoricMouseAreaBridge.h b/doric-Qt/doric/utils/DoricMouseAreaBridge.h new file mode 100644 index 00000000..5316c371 --- /dev/null +++ b/doric-Qt/doric/utils/DoricMouseAreaBridge.h @@ -0,0 +1,17 @@ +#ifndef DORICMOUSEAREABRIDGE_H +#define DORICMOUSEAREABRIDGE_H + +#include +#include + +class DoricMouseAreaBridge : public QObject { + Q_OBJECT +public: + explicit DoricMouseAreaBridge(QObject *parent = nullptr); + + Q_INVOKABLE + void onClick(QVariant functionId); +signals: +}; + +#endif // DORICMOUSEAREABRIDGE_H