add on focus change

This commit is contained in:
王劲鹏 2021-05-27 14:00:19 +08:00 committed by osborn
parent 2782552b41
commit 6f5174df60
6 changed files with 21 additions and 2 deletions

View File

@ -90,6 +90,8 @@ v8::Local<v8::Value> Variant2JS(QVariant variant) {
jsValue = array; jsValue = array;
} else if (variant.type() == QVariant::Int) { } else if (variant.type() == QVariant::Int) {
jsValue = v8::Number::New(isolate, variant.toDouble()); jsValue = v8::Number::New(isolate, variant.toDouble());
} else if (variant.type() == QVariant::Bool) {
jsValue = v8::Boolean::New(isolate, variant.toBool());
} else if (variant.type() == QVariant::Invalid) { } else if (variant.type() == QVariant::Invalid) {
jsValue = v8::Undefined(isolate); jsValue = v8::Undefined(isolate);
} }

View File

@ -67,6 +67,11 @@ TextArea {
inputBridge.onTextChange(wrapper, this.text) inputBridge.onTextChange(wrapper, this.text)
} }
onFocusChanged: {
console.log(tag, uuid + " onFocusChanged: " + this.focus)
inputBridge.onFocusChange(wrapper, this.focus)
}
property var borderWidth: 0 property var borderWidth: 0
onBorderWidthChanged: { onBorderWidthChanged: {
bg.border.width = borderWidth bg.border.width = borderWidth

View File

@ -64,3 +64,11 @@ void DoricInputNode::onTextChange(QString text) {
callJSResponse(onTextChangeId, args); callJSResponse(onTextChangeId, args);
} }
} }
void DoricInputNode::onFocusChange(bool hasFocus) {
if (!onFocusChangeId.isEmpty()) {
QVariantList args;
args.append(hasFocus);
callJSResponse(onFocusChangeId, args);
}
}

View File

@ -20,6 +20,8 @@ public:
QSizeF sizeThatFits(QSizeF size); QSizeF sizeThatFits(QSizeF size);
void onTextChange(QString text); void onTextChange(QString text);
void onFocusChange(bool hasFocus);
}; };
#endif // DORICINPUTNODE_H #endif // DORICINPUTNODE_H

View File

@ -11,7 +11,9 @@ void DoricInputBridge::onTextChange(QString pointer, QString text) {
inputNode->onTextChange(text); inputNode->onTextChange(text);
} }
void DoricInputBridge::onFocusChange(QString pointer) { void DoricInputBridge::onFocusChange(QString pointer, bool hasFocus) {
QObject *object = (QObject *)(pointer.toULongLong()); QObject *object = (QObject *)(pointer.toULongLong());
DoricInputNode *inputNode = dynamic_cast<DoricInputNode *>(object); DoricInputNode *inputNode = dynamic_cast<DoricInputNode *>(object);
inputNode->onFocusChange(hasFocus);
} }

View File

@ -15,7 +15,7 @@ public:
void onTextChange(QString pointer, QString text); void onTextChange(QString pointer, QString text);
Q_INVOKABLE Q_INVOKABLE
void onFocusChange(QString pointer); void onFocusChange(QString pointer, bool hasFocus);
signals: signals:
}; };