add mouse area

This commit is contained in:
王劲鹏 2021-03-18 11:49:52 +08:00 committed by osborn
parent e9de03cbed
commit 0784fa844c
5 changed files with 39 additions and 0 deletions

View File

@ -1,9 +1,11 @@
#include <QDebug> #include <QDebug>
#include <QQmlContext>
#include <QQuickView> #include <QQuickView>
#include "DoricDemoBridge.h" #include "DoricDemoBridge.h"
#include "DoricPanel.h" #include "DoricPanel.h"
#include "utils/DoricUtils.h" #include "utils/DoricUtils.h"
#include "utils/DoricMouseAreaBridge.h"
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {} DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
@ -44,4 +46,8 @@ void DoricDemoBridge::navigate(QVariant route) {
} }
view->show(); view->show();
auto context = view->engine()->rootContext();
DoricMouseAreaBridge *mouseAreaBridge = new DoricMouseAreaBridge();
context->setContextProperty("mouseAreaBridge", mouseAreaBridge);
} }

View File

@ -41,6 +41,7 @@ SOURCES += \
shader/DoricViewNode.cpp \ shader/DoricViewNode.cpp \
utils/DoricConstant.cpp \ utils/DoricConstant.cpp \
utils/DoricContextHolder.cpp \ utils/DoricContextHolder.cpp \
utils/DoricMouseAreaBridge.cpp \
widget/flex/FlexLayout.cpp \ widget/flex/FlexLayout.cpp \
widget/flex/FlexLayoutConfig.cpp \ widget/flex/FlexLayoutConfig.cpp \
widget/flex/FlexLayoutService.cpp \ widget/flex/FlexLayoutService.cpp \
@ -104,6 +105,7 @@ HEADERS += \
utils/DoricConstant.h \ utils/DoricConstant.h \
utils/DoricContextHolder.h \ utils/DoricContextHolder.h \
utils/DoricCountDownLatch.h \ utils/DoricCountDownLatch.h \
utils/DoricMouseAreaBridge.h \
utils/DoricObjectFactory.h \ utils/DoricObjectFactory.h \
utils/DoricThreadMode.h \ utils/DoricThreadMode.h \
utils/DoricUtils.h \ utils/DoricUtils.h \

View File

@ -48,4 +48,11 @@ Rectangle {
} }
} }
} }
MouseArea {
anchors.fill: parent
onClicked: {
mouseAreaBridge.onClick("index")
}
}
} }

View File

@ -0,0 +1,7 @@
#include "DoricMouseAreaBridge.h"
DoricMouseAreaBridge::DoricMouseAreaBridge(QObject *parent) : QObject(parent) {}
void DoricMouseAreaBridge::onClick(QVariant functionId) {
qCritical() << functionId;
}

View File

@ -0,0 +1,17 @@
#ifndef DORICMOUSEAREABRIDGE_H
#define DORICMOUSEAREABRIDGE_H
#include <QObject>
#include <QVariant>
class DoricMouseAreaBridge : public QObject {
Q_OBJECT
public:
explicit DoricMouseAreaBridge(QObject *parent = nullptr);
Q_INVOKABLE
void onClick(QVariant functionId);
signals:
};
#endif // DORICMOUSEAREABRIDGE_H