mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 01:04:06 +02:00
Make script event bridge available to OverlayWindow
This commit is contained in:
parent
c578cd4b6d
commit
8ccf645d1c
4 changed files with 58 additions and 53 deletions
|
@ -31,51 +31,6 @@ QScriptValue QmlWebWindowClass::constructor(QScriptContext* context, QScriptEngi
|
|||
return engine->newQObject(retVal);
|
||||
}
|
||||
|
||||
void QmlWebWindowClass::emitScriptEvent(const QVariant& scriptMessage) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitScriptEvent", Qt::QueuedConnection, Q_ARG(QVariant, scriptMessage));
|
||||
} else {
|
||||
emit scriptEventReceived(scriptMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWebWindowClass::emitWebEvent(const QVariant& webMessage) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitWebEvent", Qt::QueuedConnection, Q_ARG(QVariant, webMessage));
|
||||
} else {
|
||||
// Special case to handle raising and lowering the virtual keyboard.
|
||||
const QString RAISE_KEYBOARD = "_RAISE_KEYBOARD";
|
||||
const QString RAISE_KEYBOARD_NUMERIC = "_RAISE_KEYBOARD_NUMERIC";
|
||||
const QString LOWER_KEYBOARD = "_LOWER_KEYBOARD";
|
||||
QString messageString = webMessage.type() == QVariant::String ? webMessage.toString() : "";
|
||||
if (messageString.left(RAISE_KEYBOARD.length()) == RAISE_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), true, messageString == RAISE_KEYBOARD_NUMERIC);
|
||||
} else if (messageString == LOWER_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), false);
|
||||
} else {
|
||||
emit webEventReceived(webMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWebWindowClass::setKeyboardRaised(QObject* object, bool raised, bool numeric) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickItem* item = dynamic_cast<QQuickItem*>(object);
|
||||
while (item) {
|
||||
if (item->property("keyboardRaised").isValid()) {
|
||||
if (item->property("punctuationMode").isValid()) {
|
||||
item->setProperty("punctuationMode", QVariant(numeric));
|
||||
}
|
||||
item->setProperty("keyboardRaised", QVariant(raised));
|
||||
return;
|
||||
}
|
||||
item = dynamic_cast<QQuickItem*>(item->parentItem());
|
||||
}
|
||||
}
|
||||
|
||||
QString QmlWebWindowClass::getURL() const {
|
||||
QVariant result = DependencyManager::get<OffscreenUi>()->returnFromUiThread([&]()->QVariant {
|
||||
if (_qmlWindow.isNull()) {
|
||||
|
|
|
@ -23,19 +23,11 @@ public slots:
|
|||
QString getURL() const;
|
||||
void setURL(const QString& url);
|
||||
|
||||
void emitScriptEvent(const QVariant& scriptMessage);
|
||||
void emitWebEvent(const QVariant& webMessage);
|
||||
|
||||
signals:
|
||||
void urlChanged();
|
||||
void scriptEventReceived(const QVariant& message);
|
||||
void webEventReceived(const QVariant& message);
|
||||
|
||||
protected:
|
||||
QString qmlSource() const override { return "QmlWebWindow.qml"; }
|
||||
|
||||
private:
|
||||
void setKeyboardRaised(QObject* object, bool raised, bool numeric = false);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -150,6 +150,52 @@ void QmlWindowClass::sendToQml(const QVariant& message) {
|
|||
QMetaObject::invokeMethod(asQuickItem(), "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
}
|
||||
|
||||
|
||||
void QmlWindowClass::emitScriptEvent(const QVariant& scriptMessage) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitScriptEvent", Qt::QueuedConnection, Q_ARG(QVariant, scriptMessage));
|
||||
} else {
|
||||
emit scriptEventReceived(scriptMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWindowClass::emitWebEvent(const QVariant& webMessage) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitWebEvent", Qt::QueuedConnection, Q_ARG(QVariant, webMessage));
|
||||
} else {
|
||||
// Special case to handle raising and lowering the virtual keyboard.
|
||||
const QString RAISE_KEYBOARD = "_RAISE_KEYBOARD";
|
||||
const QString RAISE_KEYBOARD_NUMERIC = "_RAISE_KEYBOARD_NUMERIC";
|
||||
const QString LOWER_KEYBOARD = "_LOWER_KEYBOARD";
|
||||
QString messageString = webMessage.type() == QVariant::String ? webMessage.toString() : "";
|
||||
if (messageString.left(RAISE_KEYBOARD.length()) == RAISE_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), true, messageString == RAISE_KEYBOARD_NUMERIC);
|
||||
} else if (messageString == LOWER_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), false);
|
||||
} else {
|
||||
emit webEventReceived(webMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWindowClass::setKeyboardRaised(QObject* object, bool raised, bool numeric) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickItem* item = dynamic_cast<QQuickItem*>(object);
|
||||
while (item) {
|
||||
if (item->property("keyboardRaised").isValid()) {
|
||||
if (item->property("punctuationMode").isValid()) {
|
||||
item->setProperty("punctuationMode", QVariant(numeric));
|
||||
}
|
||||
item->setProperty("keyboardRaised", QVariant(raised));
|
||||
return;
|
||||
}
|
||||
item = dynamic_cast<QQuickItem*>(item->parentItem());
|
||||
}
|
||||
}
|
||||
|
||||
QmlWindowClass::~QmlWindowClass() {
|
||||
close();
|
||||
}
|
||||
|
|
|
@ -51,6 +51,10 @@ public slots:
|
|||
// Scripts can use this to send a message to the QML object
|
||||
void sendToQml(const QVariant& message);
|
||||
|
||||
// QmlWindow content may include WebView requiring EventBridge.
|
||||
void emitScriptEvent(const QVariant& scriptMessage);
|
||||
void emitWebEvent(const QVariant& webMessage);
|
||||
|
||||
signals:
|
||||
void visibleChanged();
|
||||
void positionChanged();
|
||||
|
@ -61,6 +65,10 @@ signals:
|
|||
// Scripts can connect to this signal to receive messages from the QML object
|
||||
void fromQml(const QVariant& message);
|
||||
|
||||
// QmlWindow content may include WebView requiring EventBridge.
|
||||
void scriptEventReceived(const QVariant& message);
|
||||
void webEventReceived(const QVariant& message);
|
||||
|
||||
protected slots:
|
||||
void hasMoved(QVector2D);
|
||||
void hasClosed();
|
||||
|
@ -81,6 +89,10 @@ protected:
|
|||
bool _toolWindow { false };
|
||||
QPointer<QObject> _qmlWindow;
|
||||
QString _source;
|
||||
|
||||
private:
|
||||
// QmlWindow content may include WebView requiring EventBridge.
|
||||
void setKeyboardRaised(QObject* object, bool raised, bool numeric = false);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue