From d34655db073bb8b1c00b3315e0bdedaad60d5fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 1 Jun 2021 19:30:37 +0800 Subject: [PATCH] add slider bridge --- doric-Qt/example/app/demo/DoricDemoBridge.cpp | 3 +++ doric-Qt/example/doric/doric.pro | 2 ++ doric-Qt/example/doric/resources/slider.qml | 1 + .../doric/shader/slider/DoricSliderNode.cpp | 9 ++++++++- .../doric/shader/slider/DoricSliderNode.h | 4 +++- .../example/doric/utils/DoricSliderBridge.cpp | 11 +++++++++++ .../example/doric/utils/DoricSliderBridge.h | 18 ++++++++++++++++++ 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 doric-Qt/example/doric/utils/DoricSliderBridge.cpp create mode 100644 doric-Qt/example/doric/utils/DoricSliderBridge.h diff --git a/doric-Qt/example/app/demo/DoricDemoBridge.cpp b/doric-Qt/example/app/demo/DoricDemoBridge.cpp index 92d3f03c..d48ec9ac 100644 --- a/doric-Qt/example/app/demo/DoricDemoBridge.cpp +++ b/doric-Qt/example/app/demo/DoricDemoBridge.cpp @@ -9,6 +9,7 @@ #include "utils/DoricInputBridge.h" #include "utils/DoricMouseAreaBridge.h" #include "utils/DoricSlideItemBridge.h" +#include "utils/DoricSliderBridge.h" #include "utils/DoricSwitchBridge.h" #include "utils/DoricUtils.h" @@ -123,4 +124,6 @@ void DoricDemoBridge::navigate(QVariant route) { context->setContextProperty("switchBridge", switchBridge); DoricSlideItemBridge *slideItemBridge = new DoricSlideItemBridge(); context->setContextProperty("slideItemBridge", slideItemBridge); + DoricSliderBridge *sliderBridge = new DoricSliderBridge(); + context->setContextProperty("sliderBridge", sliderBridge); } diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index 43aa88e1..52c4e13f 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -63,6 +63,7 @@ SOURCES += \ utils/DoricLayouts.cpp \ utils/DoricMouseAreaBridge.cpp \ utils/DoricSlideItemBridge.cpp \ + utils/DoricSliderBridge.cpp \ utils/DoricSwitchBridge.cpp \ widget/flex/FlexLayout.cpp \ widget/flex/FlexLayoutConfig.cpp \ @@ -149,6 +150,7 @@ HEADERS += \ utils/DoricNetworkService.h \ utils/DoricObjectFactory.h \ utils/DoricSlideItemBridge.h \ + utils/DoricSliderBridge.h \ utils/DoricSwitchBridge.h \ utils/DoricThreadMode.h \ utils/DoricUtils.h \ diff --git a/doric-Qt/example/doric/resources/slider.qml b/doric-Qt/example/doric/resources/slider.qml index 17bf3616..11205e26 100644 --- a/doric-Qt/example/doric/resources/slider.qml +++ b/doric-Qt/example/doric/resources/slider.qml @@ -43,6 +43,7 @@ SwipeView { onCurrentIndexChanged: { console.log(tag, uuid + " onCurrentIndexChanged: " + this.currentIndex) + sliderBridge.onPageSlided(wrapper) } } diff --git a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp index 546f91ed..6516a38a 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp +++ b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp @@ -47,7 +47,7 @@ void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) { } else if (name == "batchCount") { this->batchCount = prop.toInt(); } else if (name == "onPageSlided") { - this->onPageSelectedFuncId = prop.toString(); + this->onPageSlidedFuncId = prop.toString(); } else if (name == "loop") { this->loop = prop.toBool(); } else { @@ -88,3 +88,10 @@ void DoricSliderNode::afterBlended(QJsonValue prop) { } } } + +void DoricSliderNode::onPageSlided() { + int currentIndex = mView->property("currentIndex").toInt(); + QVariantList args; + args.append(currentIndex); + callJSResponse(this->onPageSlidedFuncId, args); +} diff --git a/doric-Qt/example/doric/shader/slider/DoricSliderNode.h b/doric-Qt/example/doric/shader/slider/DoricSliderNode.h index 068086b6..84a381ee 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSliderNode.h +++ b/doric-Qt/example/doric/shader/slider/DoricSliderNode.h @@ -12,7 +12,7 @@ private: int itemCount = 0; QString renderPageFuncId; int batchCount = 15; - QString onPageSelectedFuncId; + QString onPageSlidedFuncId; bool loop = false; QList childNodes; @@ -28,6 +28,8 @@ public: virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; virtual void afterBlended(QJsonValue prop) override; + + void onPageSlided(); }; #endif // DORICSLIDERNODE_H diff --git a/doric-Qt/example/doric/utils/DoricSliderBridge.cpp b/doric-Qt/example/doric/utils/DoricSliderBridge.cpp new file mode 100644 index 00000000..c3d7405f --- /dev/null +++ b/doric-Qt/example/doric/utils/DoricSliderBridge.cpp @@ -0,0 +1,11 @@ +#include "DoricSliderBridge.h" +#include "shader/slider/DoricSliderNode.h" + +DoricSliderBridge::DoricSliderBridge(QObject *parent) : QObject(parent) {} + +void DoricSliderBridge::onPageSlided(QString pointer) { + QObject *object = (QObject *)(pointer.toULongLong()); + DoricSliderNode *sliderNode = dynamic_cast(object); + + sliderNode->onPageSlided(); +} diff --git a/doric-Qt/example/doric/utils/DoricSliderBridge.h b/doric-Qt/example/doric/utils/DoricSliderBridge.h new file mode 100644 index 00000000..66f07ff1 --- /dev/null +++ b/doric-Qt/example/doric/utils/DoricSliderBridge.h @@ -0,0 +1,18 @@ +#ifndef DORICSLIDERBRIDGE_H +#define DORICSLIDERBRIDGE_H + +#include +#include + +#include "DoricExport.h" + +class DORIC_EXPORT DoricSliderBridge : public QObject { + Q_OBJECT +public: + explicit DoricSliderBridge(QObject *parent = nullptr); + + Q_INVOKABLE + void onPageSlided(QString pointer); +}; + +#endif // DORICSLIDERBRIDGE_H