From 36770522d7ff43847b67b85ffdae33f6b5644cd1 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 4 Feb 2019 14:16:09 +0000 Subject: [PATCH] Fix shaderviewer shortcuts using QShortcut which doesn't work well --- qrenderdoc/Windows/MainWindow.cpp | 21 +++++++++++++++++++++ qrenderdoc/Windows/MainWindow.h | 2 ++ qrenderdoc/Windows/ShaderViewer.cpp | 29 +++++++++++++++-------------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index cd8da3fa1..5fb774968 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include "Code/QRDUtils.h" @@ -2032,6 +2033,12 @@ void MainWindow::RegisterShortcut(const rdcstr &shortcut, QWidget *widget, Short if(widget) { + // we need to create a Qt shortcut for this widget. Even though we don't actually use the + // callback, unless a shortcut exists Qt might not properly send the ShortcutOverride event to + // our eventFilter - an example is on windows where Shift-F10 might go straight to a + // ContextEvent. So we create a shortcut on this widget & key-sequence to force Qt to process it + m_QtShortcuts.push_back(new QShortcut(ks, widget)); + m_WidgetShortcutCallbacks[ks][widget] = callback; } else @@ -2050,6 +2057,20 @@ void MainWindow::UnregisterShortcut(const rdcstr &shortcut, QWidget *widget) { if(widget) { + // delete any Qt shortcuts we created for this widget + for(auto it = m_QtShortcuts.begin(); it != m_QtShortcuts.end();) + { + if((*it)->parent() == widget) + { + delete *it; + it = m_QtShortcuts.erase(it); + } + else + { + ++it; + } + } + if(shortcut.isEmpty()) { // if no shortcut is specified, remove all shortcuts for this widget diff --git a/qrenderdoc/Windows/MainWindow.h b/qrenderdoc/Windows/MainWindow.h index 4f82fdc55..f8b2c51be 100644 --- a/qrenderdoc/Windows/MainWindow.h +++ b/qrenderdoc/Windows/MainWindow.h @@ -41,6 +41,7 @@ class RDLabel; class LambdaThread; class QMimeData; class QProgressBar; +class QShortcut; class QToolButton; class CaptureDialog; class LiveCapture; @@ -194,6 +195,7 @@ private: QMap m_GlobalShortcutCallbacks; QMap> m_WidgetShortcutCallbacks; + QList m_QtShortcuts; RDLabel *statusIcon; RDLabel *statusText; diff --git a/qrenderdoc/Windows/ShaderViewer.cpp b/qrenderdoc/Windows/ShaderViewer.cpp index f56362afc..e15d8bb4c 100644 --- a/qrenderdoc/Windows/ShaderViewer.cpp +++ b/qrenderdoc/Windows/ShaderViewer.cpp @@ -584,20 +584,21 @@ void ShaderViewer::debugShader(const ShaderBindpointMapping *bind, const ShaderR QObject::connect(edit, &ScintillaEdit::dwellEnd, this, &ShaderViewer::disasm_tooltipHide); } - // register the shortcuts globally for this shader viewer so it works regardless of the active - // scintilla - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F10), this), &QShortcut::activated, this, - &ShaderViewer::stepNext); - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F10 | Qt::ShiftModifier), this), - &QShortcut::activated, this, &ShaderViewer::stepBack); - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F10 | Qt::ControlModifier), this), - &QShortcut::activated, this, &ShaderViewer::runToCursor); - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F5), this), &QShortcut::activated, this, - &ShaderViewer::run); - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F5 | Qt::ShiftModifier), this), - &QShortcut::activated, this, &ShaderViewer::runBack); - QObject::connect(new QShortcut(QKeySequence(Qt::Key_F9), this), &QShortcut::activated, - [this]() { ToggleBreakpoint(); }); + // register the shortcuts via MainWindow so that it works regardless of the active scintilla but + // still handles multiple shader viewers being present (the one with focus will get the input) + m_Ctx.GetMainWindow()->RegisterShortcut(QKeySequence(Qt::Key_F10).toString(), this, + [this](QWidget *) { stepNext(); }); + m_Ctx.GetMainWindow()->RegisterShortcut(QKeySequence(Qt::Key_F10 | Qt::ShiftModifier).toString(), + this, [this](QWidget *) { stepBack(); }); + m_Ctx.GetMainWindow()->RegisterShortcut( + QKeySequence(Qt::Key_F10 | Qt::ControlModifier).toString(), this, + [this](QWidget *) { runToCursor(); }); + m_Ctx.GetMainWindow()->RegisterShortcut(QKeySequence(Qt::Key_F5).toString(), this, + [this](QWidget *) { run(); }); + m_Ctx.GetMainWindow()->RegisterShortcut(QKeySequence(Qt::Key_F5 | Qt::ShiftModifier).toString(), + this, [this](QWidget *) { runBack(); }); + m_Ctx.GetMainWindow()->RegisterShortcut(QKeySequence(Qt::Key_F9).toString(), this, + [this](QWidget *) { ToggleBreakpoint(); }); // event filter to pick up tooltip events ui->constants->installEventFilter(this);