From c6463abfb83df2a7473175c7dafe09e9df1ae1ac Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 25 Oct 2014 09:22:30 -0700 Subject: [PATCH 1/2] Prevent keys captured by script from being used as menu shortcuts --- interface/src/Application.cpp | 15 +++++++++++++++ interface/src/Application.h | 1 + 2 files changed, 16 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index da7693ed7a..a91718fa0e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -414,6 +414,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : MIDIManager& midiManagerInstance = MIDIManager::getInstance(); midiManagerInstance.openDefaultPort(); #endif + + this->installEventFilter(this); } Application::~Application() { @@ -836,6 +838,19 @@ bool Application::event(QEvent* event) { return QApplication::event(event); } +bool Application::eventFilter(QObject* object, QEvent* event) { + + if (event->type() == QEvent::ShortcutOverride) { + // Filter out captured keys before they're used for shortcut actions. + if (_controllerScriptingInterface.isKeyCaptured(static_cast(event))) { + event->accept(); + return true; + } + } + + return false; +} + void Application::keyPressEvent(QKeyEvent* event) { _keysPressed.insert(event->key()); diff --git a/interface/src/Application.h b/interface/src/Application.h index e85c4f4db5..feb9ee8fc3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -172,6 +172,7 @@ public: void dropEvent(QDropEvent *event); bool event(QEvent* event); + bool eventFilter(QObject* object, QEvent* event); void makeVoxel(glm::vec3 position, float scale, From 0fdcf381fa04e6934b540b7eb3710b63e44ed71d Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 25 Oct 2014 09:23:37 -0700 Subject: [PATCH 2/2] Code tidy --- interface/src/scripting/ControllerScriptingInterface.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index f2e65a6e28..1ca99ed2c5 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -213,10 +213,7 @@ bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const { bool ControllerScriptingInterface::isKeyCaptured(const KeyEvent& event) const { // if we've captured some combination of this key it will be in the map - if (_capturedKeys.contains(event.key, event)) { - return true; - } - return false; + return _capturedKeys.contains(event.key, event); } void ControllerScriptingInterface::captureKeyEvents(const KeyEvent& event) {