add switch bridge
This commit is contained in:
parent
b6033d6eb6
commit
19cc85cf1c
@ -8,6 +8,7 @@
|
|||||||
#include "utils/DoricImageBridge.h"
|
#include "utils/DoricImageBridge.h"
|
||||||
#include "utils/DoricInputBridge.h"
|
#include "utils/DoricInputBridge.h"
|
||||||
#include "utils/DoricMouseAreaBridge.h"
|
#include "utils/DoricMouseAreaBridge.h"
|
||||||
|
#include "utils/DoricSwitchBridge.h"
|
||||||
#include "utils/DoricUtils.h"
|
#include "utils/DoricUtils.h"
|
||||||
|
|
||||||
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
||||||
@ -108,4 +109,6 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
context->setContextProperty("imageBridge", imageBridge);
|
context->setContextProperty("imageBridge", imageBridge);
|
||||||
DoricInputBridge *inputBridge = new DoricInputBridge();
|
DoricInputBridge *inputBridge = new DoricInputBridge();
|
||||||
context->setContextProperty("inputBridge", inputBridge);
|
context->setContextProperty("inputBridge", inputBridge);
|
||||||
|
DoricSwitchBridge *switchBridge = new DoricSwitchBridge();
|
||||||
|
context->setContextProperty("switchBridge", switchBridge);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ SOURCES += \
|
|||||||
utils/DoricInputBridge.cpp \
|
utils/DoricInputBridge.cpp \
|
||||||
utils/DoricLayouts.cpp \
|
utils/DoricLayouts.cpp \
|
||||||
utils/DoricMouseAreaBridge.cpp \
|
utils/DoricMouseAreaBridge.cpp \
|
||||||
|
utils/DoricSwitchBridge.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 \
|
||||||
@ -148,6 +149,7 @@ HEADERS += \
|
|||||||
utils/DoricMouseAreaBridge.h \
|
utils/DoricMouseAreaBridge.h \
|
||||||
utils/DoricNetworkService.h \
|
utils/DoricNetworkService.h \
|
||||||
utils/DoricObjectFactory.h \
|
utils/DoricObjectFactory.h \
|
||||||
|
utils/DoricSwitchBridge.h \
|
||||||
utils/DoricThreadMode.h \
|
utils/DoricThreadMode.h \
|
||||||
utils/DoricUtils.h \
|
utils/DoricUtils.h \
|
||||||
widget/flex/FlexLayout.h \
|
widget/flex/FlexLayout.h \
|
||||||
|
@ -28,5 +28,6 @@ Switch {
|
|||||||
} else {
|
} else {
|
||||||
this.indicator.children[0].color = offTintColor
|
this.indicator.children[0].color = offTintColor
|
||||||
}
|
}
|
||||||
|
switchBridge.onSwitch(wrapper, checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
|||||||
view->setProperty("checked", prop.toBool());
|
view->setProperty("checked", prop.toBool());
|
||||||
checkByCodeToggle = false;
|
checkByCodeToggle = false;
|
||||||
} else if (name == "onSwitch") {
|
} else if (name == "onSwitch") {
|
||||||
|
onSwitchFuncId = prop.toString();
|
||||||
} else if (name == "offTintColor") {
|
} else if (name == "offTintColor") {
|
||||||
view->setProperty(
|
view->setProperty(
|
||||||
"offTintColor",
|
"offTintColor",
|
||||||
@ -41,3 +41,13 @@ void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
|||||||
DoricViewNode::blend(view, name, prop);
|
DoricViewNode::blend(view, name, prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoricSwitchNode::onSwitch(bool checked) {
|
||||||
|
if (checkByCodeToggle)
|
||||||
|
return;
|
||||||
|
if (!onSwitchFuncId.isEmpty()) {
|
||||||
|
QVariantList args;
|
||||||
|
args.append(checked);
|
||||||
|
callJSResponse(onSwitchFuncId, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,12 +10,16 @@ class DORIC_EXPORT DoricSwitchNode : public DoricViewNode {
|
|||||||
private:
|
private:
|
||||||
bool checkByCodeToggle = false;
|
bool checkByCodeToggle = false;
|
||||||
|
|
||||||
|
QString onSwitchFuncId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using DoricViewNode::DoricViewNode;
|
using DoricViewNode::DoricViewNode;
|
||||||
|
|
||||||
QQuickItem *build() override;
|
QQuickItem *build() override;
|
||||||
|
|
||||||
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||||
|
|
||||||
|
void onSwitch(bool checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSWITCHNODE_H
|
#endif // DORICSWITCHNODE_H
|
||||||
|
12
doric-Qt/example/doric/utils/DoricSwitchBridge.cpp
Normal file
12
doric-Qt/example/doric/utils/DoricSwitchBridge.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "DoricSwitchBridge.h"
|
||||||
|
|
||||||
|
#include "shader/DoricSwitchNode.h"
|
||||||
|
|
||||||
|
DoricSwitchBridge::DoricSwitchBridge(QObject *parent) : QObject(parent) {}
|
||||||
|
|
||||||
|
void DoricSwitchBridge::onSwitch(QString pointer, bool checked) {
|
||||||
|
QObject *object = (QObject *)(pointer.toULongLong());
|
||||||
|
DoricSwitchNode *switchNode = dynamic_cast<DoricSwitchNode *>(object);
|
||||||
|
|
||||||
|
switchNode->onSwitch(checked);
|
||||||
|
}
|
19
doric-Qt/example/doric/utils/DoricSwitchBridge.h
Normal file
19
doric-Qt/example/doric/utils/DoricSwitchBridge.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef DORICSWITCHBRIDGE_H
|
||||||
|
#define DORICSWITCHBRIDGE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "DoricExport.h"
|
||||||
|
|
||||||
|
class DORIC_EXPORT DoricSwitchBridge : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DoricSwitchBridge(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Q_INVOKABLE
|
||||||
|
void onSwitch(QString pointer, bool checked);
|
||||||
|
signals:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DORICSWITCHBRIDGE_H
|
Reference in New Issue
Block a user