From 9a926abd7623d530376e6faabdc5f75cd76069fd Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 10 Jun 2019 20:27:03 -0700 Subject: [PATCH] Implement BUGZ-226: Forward keypresses made while Top Bar is in focus --- .../simplifiedUI/topBar/SimplifiedTopBar.qml | 12 +++++++++++- interface/src/ui/InteractiveWindow.cpp | 16 +++++++++++++++- interface/src/ui/InteractiveWindow.h | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml index 36c882beb1..b1e2f7bcd2 100644 --- a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml +++ b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml @@ -18,6 +18,16 @@ import "qrc:////qml//hifi//models" as HifiModels // Absolute path so the same c Rectangle { 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 { id: simplifiedUI @@ -455,5 +465,5 @@ Rectangle { break; } } - signal sendToScript(var message); + signal sendToScript(var message) } diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index 2fbb665c48..84d24ddeae 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -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(modifiers)); + QCoreApplication::postEvent(QCoreApplication::instance(), event); +} + +void InteractiveWindow::forwardKeyReleaseEvent(int key, int modifiers) { + QKeyEvent* event = new QKeyEvent(QEvent::KeyRelease, key, static_cast(modifiers)); + QCoreApplication::postEvent(QCoreApplication::instance(), event); +} + /**jsdoc * A set of properties used when creating an InteractiveWindow. * @typedef {object} InteractiveWindow.Properties @@ -152,12 +162,16 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap _dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this); QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), 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()); } }); + _dockWidget->setSource(QUrl(sourceUrl)); - mainWindow->addDockWidget(dockArea, _dockWidget.get()); } else { auto offscreenUi = DependencyManager::get(); diff --git a/interface/src/ui/InteractiveWindow.h b/interface/src/ui/InteractiveWindow.h index fd0a3376fb..c7b3631dde 100644 --- a/interface/src/ui/InteractiveWindow.h +++ b/interface/src/ui/InteractiveWindow.h @@ -287,6 +287,9 @@ protected slots: */ void qmlToScript(const QVariant& message); + void forwardKeyPressEvent(int key, int modifiers); + void forwardKeyReleaseEvent(int key, int modifiers); + private: QPointer _qmlWindow; std::shared_ptr _dockWidget { nullptr };