mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:58:03 +02:00
Merge pull request #8703 from hyperlogic/bug-fix/qml-surface-get-root-item-crash
Fix for crash bug in web entities
This commit is contained in:
commit
3612ed95c3
1 changed files with 42 additions and 28 deletions
|
@ -58,9 +58,13 @@ void WebEntityAPIHelper::emitWebEvent(const QVariant& message) {
|
||||||
} else {
|
} else {
|
||||||
// special case to handle raising and lowering the virtual keyboard
|
// special case to handle raising and lowering the virtual keyboard
|
||||||
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD" && _renderableWebEntityItem) {
|
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD" && _renderableWebEntityItem) {
|
||||||
_renderableWebEntityItem->setKeyboardRaised(true);
|
if (_renderableWebEntityItem) {
|
||||||
|
_renderableWebEntityItem->setKeyboardRaised(true);
|
||||||
|
}
|
||||||
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD" && _renderableWebEntityItem) {
|
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD" && _renderableWebEntityItem) {
|
||||||
_renderableWebEntityItem->setKeyboardRaised(false);
|
if (_renderableWebEntityItem) {
|
||||||
|
_renderableWebEntityItem->setKeyboardRaised(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
emit webEventReceived(message);
|
emit webEventReceived(message);
|
||||||
}
|
}
|
||||||
|
@ -343,7 +347,7 @@ void RenderableWebEntityItem::destroyWebSurface() {
|
||||||
|
|
||||||
// The lifetime of the QML surface MUST be managed by the main thread
|
// The lifetime of the QML surface MUST be managed by the main thread
|
||||||
// Additionally, we MUST use local variables copied by value, rather than
|
// Additionally, we MUST use local variables copied by value, rather than
|
||||||
// member variables, since they would implicitly refer to a this that
|
// member variables, since they would implicitly refer to a this that
|
||||||
// is no longer valid
|
// is no longer valid
|
||||||
auto webSurface = _webSurface;
|
auto webSurface = _webSurface;
|
||||||
AbstractViewStateInterface::instance()->postLambdaEvent([webSurface] {
|
AbstractViewStateInterface::instance()->postLambdaEvent([webSurface] {
|
||||||
|
@ -388,35 +392,40 @@ static bool equals(const QByteArray& byteArray, const uint8_t* ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
||||||
auto utf8Key = key.toUtf8();
|
auto eventHandler = getEventHandler();
|
||||||
|
if (eventHandler) {
|
||||||
|
auto utf8Key = key.toUtf8();
|
||||||
|
|
||||||
int scanCode = (int)utf8Key[0];
|
int scanCode = (int)utf8Key[0];
|
||||||
QString keyString = key;
|
QString keyString = key;
|
||||||
if (equals(utf8Key, UPWARDS_WHITE_ARROW_FROM_BAR) || equals(utf8Key, ASTERISIM) ||
|
if (equals(utf8Key, UPWARDS_WHITE_ARROW_FROM_BAR) || equals(utf8Key, ASTERISIM) ||
|
||||||
equals(utf8Key, (uint8_t*)PUNCTUATION_STRING) || equals(utf8Key, (uint8_t*)ALPHABET_STRING)) {
|
equals(utf8Key, (uint8_t*)PUNCTUATION_STRING) || equals(utf8Key, (uint8_t*)ALPHABET_STRING)) {
|
||||||
return; // ignore
|
return; // ignore
|
||||||
} else if (equals(utf8Key, LEFT_ARROW)) {
|
} else if (equals(utf8Key, LEFT_ARROW)) {
|
||||||
scanCode = Qt::Key_Backspace;
|
scanCode = Qt::Key_Backspace;
|
||||||
keyString = "\x08";
|
keyString = "\x08";
|
||||||
} else if (equals(utf8Key, RETURN_SYMBOL)) {
|
} else if (equals(utf8Key, RETURN_SYMBOL)) {
|
||||||
scanCode = Qt::Key_Return;
|
scanCode = Qt::Key_Return;
|
||||||
keyString = "\x0d";
|
keyString = "\x0d";
|
||||||
} else if (equals(utf8Key, LEFTWARD_WHITE_ARROW)) {
|
} else if (equals(utf8Key, LEFTWARD_WHITE_ARROW)) {
|
||||||
scanCode = Qt::Key_Left;
|
scanCode = Qt::Key_Left;
|
||||||
keyString = "";
|
keyString = "";
|
||||||
} else if (equals(utf8Key, RIGHTWARD_WHITE_ARROW)) {
|
} else if (equals(utf8Key, RIGHTWARD_WHITE_ARROW)) {
|
||||||
scanCode = Qt::Key_Right;
|
scanCode = Qt::Key_Right;
|
||||||
keyString = "";
|
keyString = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, scanCode, Qt::NoModifier, keyString);
|
||||||
|
QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, scanCode, Qt::NoModifier, keyString);
|
||||||
|
QCoreApplication::postEvent(eventHandler, pressEvent);
|
||||||
|
QCoreApplication::postEvent(eventHandler, releaseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, scanCode, Qt::NoModifier, keyString);
|
|
||||||
QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, scanCode, Qt::NoModifier, keyString);
|
|
||||||
QCoreApplication::postEvent(getEventHandler(), pressEvent);
|
|
||||||
QCoreApplication::postEvent(getEventHandler(), releaseEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
|
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
|
||||||
_webEntityAPIHelper->emitScriptEvent(message);
|
if (_webEntityAPIHelper) {
|
||||||
|
_webEntityAPIHelper->emitScriptEvent(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
||||||
|
@ -424,5 +433,10 @@ void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
||||||
// raise the keyboard only while in HMD mode and it's being requested.
|
// raise the keyboard only while in HMD mode and it's being requested.
|
||||||
bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
||||||
|
|
||||||
_webSurface->getRootItem()->setProperty("keyboardRaised", QVariant(value));
|
if (_webSurface) {
|
||||||
|
auto rootItem = _webSurface->getRootItem();
|
||||||
|
if (rootItem) {
|
||||||
|
rootItem->setProperty("keyboardRaised", QVariant(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue