diff --git a/doric-Qt/example/app/demo/DoricDemoBridge.cpp b/doric-Qt/example/app/demo/DoricDemoBridge.cpp index aebcd693..c2c2924d 100644 --- a/doric-Qt/example/app/demo/DoricDemoBridge.cpp +++ b/doric-Qt/example/app/demo/DoricDemoBridge.cpp @@ -5,6 +5,7 @@ #include "DoricDemoBridge.h" #include "DoricPanel.h" #include "utils/DoricDialogBridge.h" +#include "utils/DoricDraggableBridge.h" #include "utils/DoricImageBridge.h" #include "utils/DoricInputBridge.h" #include "utils/DoricMouseAreaBridge.h" @@ -129,4 +130,6 @@ void DoricDemoBridge::navigate(QVariant route) { context->setContextProperty("slideItemBridge", slideItemBridge); DoricSliderBridge *sliderBridge = new DoricSliderBridge(); context->setContextProperty("sliderBridge", sliderBridge); + DoricDraggableBridge *draggableBridge = new DoricDraggableBridge(); + context->setContextProperty("draggableBridge", draggableBridge); } diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index a61d9c20..503ec614 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -59,6 +59,7 @@ SOURCES += \ utils/DoricConstant.cpp \ utils/DoricContextHolder.cpp \ utils/DoricDialogBridge.cpp \ + utils/DoricDraggableBridge.cpp \ utils/DoricImageBridge.cpp \ utils/DoricInputBridge.cpp \ utils/DoricLayouts.cpp \ @@ -145,6 +146,7 @@ HEADERS += \ utils/DoricContextHolder.h \ utils/DoricCountDownLatch.h \ utils/DoricDialogBridge.h \ + utils/DoricDraggableBridge.h \ utils/DoricImageBridge.h \ utils/DoricInputBridge.h \ utils/DoricLayouts.h \ diff --git a/doric-Qt/example/doric/engine/v8/JSValueHelper.cpp b/doric-Qt/example/doric/engine/v8/JSValueHelper.cpp index e40cd67f..728fc449 100644 --- a/doric-Qt/example/doric/engine/v8/JSValueHelper.cpp +++ b/doric-Qt/example/doric/engine/v8/JSValueHelper.cpp @@ -88,7 +88,8 @@ v8::Local Variant2JS(QVariant variant) { result.ToChecked(); } jsValue = array; - } else if (variant.type() == QVariant::Int) { + } else if (variant.type() == QVariant::Int || + variant.type() == QVariant::Double) { jsValue = v8::Number::New(isolate, variant.toDouble()); } else if (variant.type() == QVariant::Bool) { jsValue = v8::Boolean::New(isolate, variant.toBool()); diff --git a/doric-Qt/example/doric/resources/draggable.qml b/doric-Qt/example/doric/resources/draggable.qml index 6df9d8ec..889f90b1 100644 --- a/doric-Qt/example/doric/resources/draggable.qml +++ b/doric-Qt/example/doric/resources/draggable.qml @@ -60,6 +60,8 @@ Rectangle { let yDiff = positionToRootParent.y - positionToRoot.y console.log(tag, uuid + " onPositionChanged: " + xDiff + ", " + yDiff) + + draggableBridge.onDrag(wrapper, xDiff, yDiff) } } diff --git a/doric-Qt/example/doric/shader/DoricDraggableNode.cpp b/doric-Qt/example/doric/shader/DoricDraggableNode.cpp index 30888365..e067250b 100644 --- a/doric-Qt/example/doric/shader/DoricDraggableNode.cpp +++ b/doric-Qt/example/doric/shader/DoricDraggableNode.cpp @@ -20,8 +20,17 @@ QQuickItem *DoricDraggableNode::build() { void DoricDraggableNode::blend(QQuickItem *view, QString name, QJsonValue prop) { if (name == "onDrag") { - onDrag = prop.toString(); + onDragFunction = prop.toString(); } else { DoricStackNode::blend(view, name, prop); } } + +void DoricDraggableNode::onDrag(double x, double y) { + getLayouts()->setMarginLeft(x); + getLayouts()->setMarginTop(y); + QVariantList args; + args.append(x); + args.append(y); + callJSResponse(onDragFunction, args); +} diff --git a/doric-Qt/example/doric/shader/DoricDraggableNode.h b/doric-Qt/example/doric/shader/DoricDraggableNode.h index 5cd810e5..45899638 100644 --- a/doric-Qt/example/doric/shader/DoricDraggableNode.h +++ b/doric-Qt/example/doric/shader/DoricDraggableNode.h @@ -8,7 +8,7 @@ class DORIC_EXPORT DoricDraggableNode : public DoricStackNode { private: - QString onDrag; + QString onDragFunction; public: using DoricStackNode::DoricStackNode; @@ -16,6 +16,8 @@ public: QQuickItem *build() override; virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; + + void onDrag(double x, double y); }; #endif // DORICDRAGGABLENODE_H diff --git a/doric-Qt/example/doric/utils/DoricDraggableBridge.cpp b/doric-Qt/example/doric/utils/DoricDraggableBridge.cpp new file mode 100644 index 00000000..42a68223 --- /dev/null +++ b/doric-Qt/example/doric/utils/DoricDraggableBridge.cpp @@ -0,0 +1,12 @@ +#include "DoricDraggableBridge.h" +#include "shader/DoricDraggableNode.h" + +DoricDraggableBridge::DoricDraggableBridge(QObject *parent) : QObject(parent) {} + +void DoricDraggableBridge::onDrag(QString pointer, double x, double y) { + QObject *object = (QObject *)(pointer.toULongLong()); + DoricDraggableNode *draggableNode = + dynamic_cast(object); + + draggableNode->onDrag(x, y); +} diff --git a/doric-Qt/example/doric/utils/DoricDraggableBridge.h b/doric-Qt/example/doric/utils/DoricDraggableBridge.h new file mode 100644 index 00000000..538ddc68 --- /dev/null +++ b/doric-Qt/example/doric/utils/DoricDraggableBridge.h @@ -0,0 +1,18 @@ +#ifndef DORICDRAGGABLEBRIDGE_H +#define DORICDRAGGABLEBRIDGE_H + +#include +#include + +#include "DoricExport.h" + +class DORIC_EXPORT DoricDraggableBridge : public QObject { + Q_OBJECT +public: + explicit DoricDraggableBridge(QObject *parent = nullptr); + + Q_INVOKABLE + void onDrag(QString pointer, double x, double y); +}; + +#endif // DORICDRAGGABLEBRIDGE_H