handle response

This commit is contained in:
王劲鹏 2021-06-02 11:26:11 +08:00 committed by osborn
parent a0a6ebf50d
commit 80301837c3
8 changed files with 52 additions and 3 deletions

View File

@ -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);
}

View File

@ -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 \

View File

@ -88,7 +88,8 @@ v8::Local<v8::Value> 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());

View File

@ -60,6 +60,8 @@ Rectangle {
let yDiff = positionToRootParent.y - positionToRoot.y
console.log(tag, uuid + " onPositionChanged: " + xDiff + ", " + yDiff)
draggableBridge.onDrag(wrapper, xDiff, yDiff)
}
}

View File

@ -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);
}

View File

@ -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

View File

@ -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<DoricDraggableNode *>(object);
draggableNode->onDrag(x, y);
}

View File

@ -0,0 +1,18 @@
#ifndef DORICDRAGGABLEBRIDGE_H
#define DORICDRAGGABLEBRIDGE_H
#include <QObject>
#include <QVariant>
#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