From 34431ec739dd14fcd78d445cb8e923eea092f745 Mon Sep 17 00:00:00 2001 From: Nav Date: Fri, 22 Sep 2023 23:56:43 +0100 Subject: [PATCH] Key press event handling in certain Insight windows --- .../MemoryRegionManagerWindow.cpp | 16 ++++++++++++ .../MemoryRegionManagerWindow.hpp | 2 ++ .../CreateSnapshotWindow.cpp | 16 ++++++++++++ .../CreateSnapshotWindow.hpp | 2 ++ .../TargetRegisterInspectorWindow.cpp | 25 +++++++++++++++++++ .../TargetRegisterInspectorWindow.hpp | 4 ++- 6 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp index 6dda6c47..390502fd 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp @@ -145,6 +145,22 @@ namespace Widgets } } + void MemoryRegionManagerWindow::keyPressEvent(QKeyEvent* event) { + const auto key = event->key(); + + if (key == Qt::Key_Enter || key == Qt::Key_Return) { + this->applyButton->click(); + return; + } + + if (key == Qt::Key_Escape) { + this->close(); + return; + } + + QWidget::keyPressEvent(event); + } + void MemoryRegionManagerWindow::clearRegions() { this->selectedRegion = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp index f3cbfb2e..4b7d0cee 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ namespace Widgets protected: void showEvent(QShowEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; private: const Targets::TargetMemoryDescriptor& memoryDescriptor; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp index 86538fb3..e8ddda86 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp @@ -102,6 +102,22 @@ namespace Widgets QWidget::showEvent(event); } + void CreateSnapshotWindow::keyPressEvent(QKeyEvent* event) { + const auto key = event->key(); + + if (key == Qt::Key_Enter || key == Qt::Key_Return) { + this->captureButton->click(); + return; + } + + if (key == Qt::Key_Escape) { + this->close(); + return; + } + + QWidget::keyPressEvent(event); + } + bool CreateSnapshotWindow::captureEnabled() { if (this->targetState != Targets::TargetState::STOPPED) { return false; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp index 9b3f9e18..6684aa54 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,7 @@ namespace Widgets protected: void showEvent(QShowEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; private: QWidget* container = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp index 6f661765..cbdb26c9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp @@ -221,6 +221,31 @@ namespace Widgets ); } + void TargetRegisterInspectorWindow::keyPressEvent(QKeyEvent* event) { + const auto key = event->key(); + + if ((event->modifiers() & Qt::ControlModifier) != 0 && key == Qt::Key_R) { + this->refreshValueButton->click(); + return; + } + + if ( + (event->modifiers() & Qt::ControlModifier) != 0 + && (key == Qt::Key_Enter || key == Qt::Key_Return) + && this->registerValueTextInput->hasFocus() + ) { + this->applyButton->click(); + return; + } + + if (key == Qt::Key_Escape) { + this->close(); + return; + } + + QWidget::keyPressEvent(event); + } + bool TargetRegisterInspectorWindow::registerSupported(const Targets::TargetRegisterDescriptor& descriptor) { return (descriptor.size > 0 && descriptor.size <= 8); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp index fe693125..44fc8de7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp @@ -5,7 +5,8 @@ #include #include #include -#include +#include +#include #include #include @@ -36,6 +37,7 @@ namespace Widgets protected: void resizeEvent(QResizeEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; private: Targets::TargetRegisterDescriptor registerDescriptor;