From a3c1342f7741495eabc591809f3da9374d1e2a2c Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 25 Mar 2019 11:43:16 +1100 Subject: [PATCH] fixed #685 --- dialogs/preferencesdialog.cpp | 1 - ui/mainwindow.cpp | 1 - ui/viewerwindow.cpp | 35 +++++++++++++++++++++++++++++++++++ ui/viewerwindow.h | 35 ++++++++++++++++++++--------------- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/dialogs/preferencesdialog.cpp b/dialogs/preferencesdialog.cpp index 3fc27bdfb..6204a938a 100644 --- a/dialogs/preferencesdialog.cpp +++ b/dialogs/preferencesdialog.cpp @@ -60,7 +60,6 @@ KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a) void KeySequenceEditor::set_action_shortcut() { action->setShortcut(keySequence()); - action->setShortcutContext(Qt::ApplicationShortcut); } void KeySequenceEditor::reset_to_default() { diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 75f20f7a4..5f79b151b 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -341,7 +341,6 @@ void kbd_shortcut_processor(QByteArray& file, QMenu* menu, bool save, bool first } } } - a->setShortcutContext(Qt::ApplicationShortcut); } } } diff --git a/ui/viewerwindow.cpp b/ui/viewerwindow.cpp index 69bb74053..646db81f9 100644 --- a/ui/viewerwindow.cpp +++ b/ui/viewerwindow.cpp @@ -52,6 +52,41 @@ void ViewerWindow::set_texture(GLuint t, double iar, QMutex* imutex) { update(); } +void ViewerWindow::shortcut_copier(QVector& shortcuts, QMenu* menu) { + QList menu_action = menu->actions(); + for (int i=0;imenu() != nullptr) { + shortcut_copier(shortcuts, menu_action.at(i)->menu()); + } else if (!menu_action.at(i)->isSeparator() && !menu_action.at(i)->shortcut().isEmpty()) { + QShortcut* sc = new QShortcut(this); + sc->setKey(menu_action.at(i)->shortcut()); + connect(sc, SIGNAL(activated()), menu_action.at(i), SLOT(trigger())); + shortcuts.append(sc); + } + } +} + +void ViewerWindow::showEvent(QShowEvent *) +{ + // Here, we copy all shortcuts from the MainWindow to this window. I don't like this solution, but messing around + // with Qt's event system proved fruitless. Also setting the shortcuts to ApplicationShortcut rather than + // WindowShortcut caused issues elsewhere (shortcuts being picked up in comboboxes and dialog boxes - we only + // want the shortcuts to be shared to this window). Therefore, this and shortcut_copier() are so far the best + // solutions I can find. + + // Clear any existing shortcuts in case they've changed since the last showing + for (int i=0;i menubar_actions = olive::MainWindow->menuBar()->actions(); + for (int i=0;imenu()); + } +} + void ViewerWindow::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { hide(); diff --git a/ui/viewerwindow.h b/ui/viewerwindow.h index ccba77452..1257fa13e 100644 --- a/ui/viewerwindow.h +++ b/ui/viewerwindow.h @@ -29,27 +29,32 @@ class QMenu; class QShortcut; class ViewerWindow : public QOpenGLWidget { - Q_OBJECT + Q_OBJECT public: - ViewerWindow(QWidget *parent); - void set_texture(GLuint t, double iar, QMutex *imutex); + ViewerWindow(QWidget *parent); + void set_texture(GLuint t, double iar, QMutex *imutex); protected: - virtual void keyPressEvent(QKeyEvent*) override; - virtual void mousePressEvent(QMouseEvent*) override; - virtual void mouseMoveEvent(QMouseEvent*) override; + virtual void showEvent(QShowEvent*) override; + virtual void keyPressEvent(QKeyEvent*) override; + virtual void mousePressEvent(QMouseEvent*) override; + virtual void mouseMoveEvent(QMouseEvent*) override; - virtual void paintGL() override; + virtual void paintGL() override; private: - GLuint texture; - double ar; - QMutex* mutex; + GLuint texture; + double ar; + QMutex* mutex; - // exit full screen message - QTimer fullscreen_msg_timer; - bool show_fullscreen_msg; - QRect fullscreen_msg_rect; + // shortcuts + void shortcut_copier(QVector& shortcuts, QMenu* menu); + QVector shortcuts_; + + // exit full screen message + QTimer fullscreen_msg_timer; + bool show_fullscreen_msg; + QRect fullscreen_msg_rect; private slots: - void fullscreen_msg_timeout(); + void fullscreen_msg_timeout(); }; #endif // VIEWERWINDOW_H