add click response callback
This commit is contained in:
parent
ace6d87bda
commit
2b277a44f4
@ -56,6 +56,14 @@ QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.push_back(arg);
|
args.push_back(arg);
|
||||||
|
} else if (variant.type() == QVariant::StringList) {
|
||||||
|
QStringList array = variant.toStringList();
|
||||||
|
QJSValue arg = mJSEngine.newArray(array.size());
|
||||||
|
|
||||||
|
for (int i = 0; i != array.size(); i++) {
|
||||||
|
arg.setProperty(i, array.at(i));
|
||||||
|
}
|
||||||
|
args.push_back(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <QJSValueIterator>
|
#include <QJSValueIterator>
|
||||||
|
|
||||||
|
#include "../utils/DoricConstant.h"
|
||||||
#include "../utils/DoricUtils.h"
|
#include "../utils/DoricUtils.h"
|
||||||
#include "DoricSuperNode.h"
|
#include "DoricSuperNode.h"
|
||||||
#include "DoricViewNode.h"
|
#include "DoricViewNode.h"
|
||||||
@ -115,9 +116,41 @@ void DoricViewNode::blend(QQuickItem *view, QString name, QJSValue prop) {
|
|||||||
view->setProperty("y", prop.toInt());
|
view->setProperty("y", prop.toInt());
|
||||||
} else if (name == "corners") {
|
} else if (name == "corners") {
|
||||||
view->setProperty("radius", prop.toInt());
|
view->setProperty("radius", prop.toInt());
|
||||||
} else if (name == "layoutConfig") {
|
} else if (name == "onClick") {
|
||||||
|
if (prop.isString())
|
||||||
|
clickFunction = prop.toString();
|
||||||
} else {
|
} else {
|
||||||
qCritical() << name << ": " << prop.toString();
|
qCritical() << name << ": " << prop.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QString> DoricViewNode::getIdList() {
|
||||||
|
QList<QString> ids;
|
||||||
|
|
||||||
|
DoricViewNode *viewNode = this;
|
||||||
|
do {
|
||||||
|
ids.append(viewNode->mId);
|
||||||
|
viewNode = viewNode->mSuperNode;
|
||||||
|
} while (viewNode != nullptr);
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricViewNode::callJSResponse(QString funcId, QVariantList args) {
|
||||||
|
QVariantList nArgs;
|
||||||
|
QList<QString> idList = getIdList();
|
||||||
|
nArgs.append(idList);
|
||||||
|
nArgs.append(funcId);
|
||||||
|
foreach (const QVariant &arg, args)
|
||||||
|
nArgs.append(arg);
|
||||||
|
|
||||||
|
return getContext()->callEntity(DoricConstant::DORIC_ENTITY_RESPONSE, nArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricViewNode::onClick() {
|
||||||
|
if (clickFunction.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QVariantList args;
|
||||||
|
callJSResponse(clickFunction, args);
|
||||||
|
}
|
||||||
|
@ -23,6 +23,10 @@ private:
|
|||||||
|
|
||||||
QJSValue mLayoutConfig;
|
QJSValue mLayoutConfig;
|
||||||
|
|
||||||
|
QList<QString> getIdList();
|
||||||
|
|
||||||
|
QString clickFunction;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString mType;
|
QString mType;
|
||||||
|
|
||||||
@ -58,5 +62,9 @@ public:
|
|||||||
virtual void blend(QQuickItem *view, QString name, QJSValue prop);
|
virtual void blend(QQuickItem *view, QString name, QJSValue prop);
|
||||||
|
|
||||||
virtual void blendLayoutConfig(QJSValue jsObject);
|
virtual void blendLayoutConfig(QJSValue jsObject);
|
||||||
|
|
||||||
|
void onClick();
|
||||||
|
|
||||||
|
void callJSResponse(QString funcId, QVariantList args);
|
||||||
};
|
};
|
||||||
#endif // DORICVIEWNODE_H
|
#endif // DORICVIEWNODE_H
|
||||||
|
@ -6,5 +6,5 @@ DoricMouseAreaBridge::DoricMouseAreaBridge(QObject *parent) : QObject(parent) {}
|
|||||||
void DoricMouseAreaBridge::onClick(qint64 pointer) {
|
void DoricMouseAreaBridge::onClick(qint64 pointer) {
|
||||||
QObject *object = (QObject *)(pointer);
|
QObject *object = (QObject *)(pointer);
|
||||||
DoricViewNode *viewNode = dynamic_cast<DoricViewNode *>(object);
|
DoricViewNode *viewNode = dynamic_cast<DoricViewNode *>(object);
|
||||||
qCritical() << viewNode;
|
viewNode->onClick();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user