mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 21:29:33 +02:00
Merge pull request #15731 from zfox23/SUI/forwardKeyEvents
Implement BUGZ-226: Forward keypresses made while Top Bar is in focus
This commit is contained in:
commit
b62ab2ea82
3 changed files with 29 additions and 2 deletions
|
@ -18,6 +18,16 @@ import "qrc:////qml//hifi//models" as HifiModels // Absolute path so the same c
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: root
|
id: root
|
||||||
|
focus: true
|
||||||
|
|
||||||
|
signal keyPressEvent(int key, int modifiers)
|
||||||
|
Keys.onPressed: {
|
||||||
|
keyPressEvent(event.key, event.modifiers);
|
||||||
|
}
|
||||||
|
signal keyReleaseEvent(int key, int modifiers)
|
||||||
|
Keys.onReleased: {
|
||||||
|
keyReleaseEvent(event.key, event.modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
SimplifiedConstants.SimplifiedConstants {
|
SimplifiedConstants.SimplifiedConstants {
|
||||||
id: simplifiedUI
|
id: simplifiedUI
|
||||||
|
@ -455,5 +465,5 @@ Rectangle {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal sendToScript(var message);
|
signal sendToScript(var message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,16 @@ void interactiveWindowPointerFromScriptValue(const QScriptValue& object, Interac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InteractiveWindow::forwardKeyPressEvent(int key, int modifiers) {
|
||||||
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, static_cast<Qt::KeyboardModifiers>(modifiers));
|
||||||
|
QCoreApplication::postEvent(QCoreApplication::instance(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InteractiveWindow::forwardKeyReleaseEvent(int key, int modifiers) {
|
||||||
|
QKeyEvent* event = new QKeyEvent(QEvent::KeyRelease, key, static_cast<Qt::KeyboardModifiers>(modifiers));
|
||||||
|
QCoreApplication::postEvent(QCoreApplication::instance(), event);
|
||||||
|
}
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* A set of properties used when creating an <code>InteractiveWindow</code>.
|
* A set of properties used when creating an <code>InteractiveWindow</code>.
|
||||||
* @typedef {object} InteractiveWindow.Properties
|
* @typedef {object} InteractiveWindow.Properties
|
||||||
|
@ -152,12 +162,16 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
|
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
|
||||||
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)),
|
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)),
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
QObject::connect(rootItem, SIGNAL(keyReleaseEvent(int, int)), this, SLOT(forwardKeyReleaseEvent(int, int)),
|
||||||
|
Qt::QueuedConnection);
|
||||||
emit mainWindow->windowGeometryChanged(qApp->getWindow()->geometry());
|
emit mainWindow->windowGeometryChanged(qApp->getWindow()->geometry());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_dockWidget->setSource(QUrl(sourceUrl));
|
_dockWidget->setSource(QUrl(sourceUrl));
|
||||||
|
|
||||||
|
|
||||||
mainWindow->addDockWidget(dockArea, _dockWidget.get());
|
mainWindow->addDockWidget(dockArea, _dockWidget.get());
|
||||||
} else {
|
} else {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
|
|
@ -287,6 +287,9 @@ protected slots:
|
||||||
*/
|
*/
|
||||||
void qmlToScript(const QVariant& message);
|
void qmlToScript(const QVariant& message);
|
||||||
|
|
||||||
|
void forwardKeyPressEvent(int key, int modifiers);
|
||||||
|
void forwardKeyReleaseEvent(int key, int modifiers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QObject> _qmlWindow;
|
QPointer<QObject> _qmlWindow;
|
||||||
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
||||||
|
|
Loading…
Reference in a new issue