Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:epopov:branches:openSUSE:Factory
spectacle
2001-fix-shortcuts.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2001-fix-shortcuts.patch of Package spectacle
diff --git a/src/Gui/CaptureWindow.cpp b/src/Gui/CaptureWindow.cpp index 7d3df41bf3f63ca9420001f493bf12f4cec88196..d282e1d59f53a9e064e779a8ee329964c48352eb 100644 --- a/src/Gui/CaptureWindow.cpp +++ b/src/Gui/CaptureWindow.cpp @@ -70,6 +70,27 @@ CaptureWindow::CaptureWindow(Mode mode, QScreen *screen, QQmlEngine *engine, QWi if (auto rootItem = rootObject()) { rootItem->installEventFilter(selectionEditor); } + + addShortcut(QKeySequence::Save, this, &CaptureWindow::save); + addShortcut(QKeySequence::SaveAs, this, &CaptureWindow::saveAs); + addShortcut(QKeySequence::Copy, this, &CaptureWindow::copyImage); + addShortcut(QKeySequence::Print, this, &CaptureWindow::showPrintDialog); + addShortcut(QKeySequence::Undo, this, [this]() { + if (isAnnotating()) { + auto document = SpectacleCore::instance()->annotationDocument(); + if (document->undoStackDepth() > 0) { + document->undo(); + } + } + }); + addShortcut(QKeySequence::Redo, this, [this]() { + if (isAnnotating()) { + auto document = SpectacleCore::instance()->annotationDocument(); + if (document->redoStackDepth() > 0) { + document->redo(); + } + } + }); } CaptureWindow::~CaptureWindow() @@ -152,37 +173,6 @@ void CaptureWindow::mousePressEvent(QMouseEvent *event) SpectacleWindow::mousePressEvent(event); } -void CaptureWindow::keyReleaseEvent(QKeyEvent *event) -{ - SpectacleWindow::keyReleaseEvent(event); - if (event->isAccepted()) { - return; - } - if (event->matches(QKeySequence::Save)) { - event->accept(); - save(); - } else if (event->matches(QKeySequence::SaveAs)) { - event->accept(); - saveAs(); - } else if (event->matches(QKeySequence::Copy)) { - event->accept(); - copyImage(); - } else if (event->matches(QKeySequence::Print)) { - event->accept(); - showPrintDialog(); - } - auto document = SpectacleCore::instance()->annotationDocument(); - if (!event->isAccepted() && document) { - if (document->undoStackDepth() > 0 && event->matches(QKeySequence::Undo)) { - event->accept(); - document->undo(); - } else if (document->redoStackDepth() > 0 && event->matches(QKeySequence::Redo)) { - event->accept(); - document->redo(); - } - } -} - void CaptureWindow::showEvent(QShowEvent *event) { SpectacleWindow::showEvent(event); diff --git a/src/Gui/CaptureWindow.h b/src/Gui/CaptureWindow.h index c8c62f027d29eb0c54730b9e5209cf72e0ed6075..b5e87a8340297d774e73dfce771023f47ba0db90 100644 --- a/src/Gui/CaptureWindow.h +++ b/src/Gui/CaptureWindow.h @@ -44,7 +44,6 @@ Q_SIGNALS: protected: void mousePressEvent(QMouseEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; void showEvent(QShowEvent *event) override; private: diff --git a/src/Gui/SpectacleWindow.cpp b/src/Gui/SpectacleWindow.cpp index df277b534b478a0be9008bffaa5d089080e161ab..7006257d39401b4ab486d5aa643a9164bb236c9e 100644 --- a/src/Gui/SpectacleWindow.cpp +++ b/src/Gui/SpectacleWindow.cpp @@ -59,6 +59,13 @@ SpectacleWindow::SpectacleWindow(QQmlEngine *engine, QWindow *parent) // set up QML setResizeMode(QQuickView::SizeRootObjectToView); m_context->setContextProperty(u"contextWindow"_s, this); + + addShortcut(QKeySequence::Cancel, QKeySequence::Close, QKeySequence::Quit, SpectacleCore::instance(), &SpectacleCore::cancelScreenshot); + addShortcut(QKeySequence::Preferences, this, &SpectacleWindow::showPreferencesDialog); + addShortcut(QKeySequence::New, this, []() { + SpectacleCore::instance()->takeNewScreenshot(); + }); + addShortcut(QKeySequence::HelpContents, HelpMenu::instance(), &HelpMenu::showAppHelp); } SpectacleWindow::~SpectacleWindow() @@ -431,46 +438,4 @@ void SpectacleWindow::mousePressEvent(QMouseEvent *event) } } -void SpectacleWindow::keyPressEvent(QKeyEvent *event) -{ - // Events need to be processed normally first for events to reach items - QQuickView::keyPressEvent(event); - if (event->isAccepted()) { - return; - } - m_pressedKeys = event->key() | event->modifiers(); -} - -void SpectacleWindow::keyReleaseEvent(QKeyEvent *event) -{ - // Events need to be processed normally first for events to reach items - QQuickView::keyReleaseEvent(event); - if (event->isAccepted()) { - return; - } - // Cancel defaults to Escape in QPlatformTheme. - // Handling this here fixes https://bugs.kde.org/show_bug.cgi?id=428478 - if ((event->matches(QKeySequence::Quit) - || event->matches(QKeySequence::Close) - || event->matches(QKeySequence::Cancel)) - // We need to check if these were pressed previously or else pressing escape - // in a dialog will quit spectacle when you release the escape key. - && m_pressedKeys == event->key() | event->modifiers() - ) { - event->accept(); - auto spectacleCore = SpectacleCore::instance(); - spectacleCore->cancelScreenshot(); - } else if (event->matches(QKeySequence::Preferences)) { - event->accept(); - showPreferencesDialog(); - } else if (event->matches(QKeySequence::New)) { - event->accept(); - SpectacleCore::instance()->takeNewScreenshot(); - } else if (event->matches(QKeySequence::HelpContents)) { - event->accept(); - HelpMenu::instance()->showAppHelp(); - } - m_pressedKeys = {}; -} - #include "moc_SpectacleWindow.cpp" diff --git a/src/Gui/SpectacleWindow.h b/src/Gui/SpectacleWindow.h index fa84d8246c30ba8e01143b3b6c6cccab4d75aa09..62f23de55d22dbc3b49ed5aab79998869ce387ea 100644 --- a/src/Gui/SpectacleWindow.h +++ b/src/Gui/SpectacleWindow.h @@ -7,6 +7,7 @@ #pragma once #include <QQuickView> +#include <QShortcut> #include <QQmlContext> class SpectacleWindowPrivate; @@ -78,6 +79,26 @@ public: */ Q_INVOKABLE QString baseFileName(const QUrl &url) const; + template<typename Func> + void addShortcut(const QKeySequence &key, const QObject *context, Func func) + { + addShortcut(key, QKeySequence(), context, func); + } + + template<typename Func> + void addShortcut(const QKeySequence &key1, const QKeySequence &key2, const QObject *context, Func func) + { + addShortcut(key1, key2, QKeySequence(), context, func); + } + + template<typename Func> + void addShortcut(const QKeySequence &key1, const QKeySequence &key2, const QKeySequence &key3, const QObject *context, Func func) + { + QShortcut *shortcut = new QShortcut(this); + shortcut->setKeys(QList<QKeySequence>() << key1 << key2 << key3); + connect(shortcut, &QShortcut::activated, context, func); + } + public Q_SLOTS: virtual void save(); virtual void saveAs(); @@ -108,8 +129,6 @@ protected: void setSource(const QUrl &source, const QVariantMap &initialProperties); void mousePressEvent(QMouseEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; static QList<SpectacleWindow *> s_spectacleWindowInstances; static bool s_synchronizingVisibility; @@ -121,6 +140,4 @@ protected: const std::unique_ptr<QQmlContext> m_context; std::unique_ptr<QQmlComponent> m_component; - - QKeySequence m_pressedKeys; }; diff --git a/src/Gui/ViewerWindow.cpp b/src/Gui/ViewerWindow.cpp index 288b19411c1c3bd144c02883f1faff8566256a59..4b742a84423e839aadd6243d1f8054b24ea84ef3 100644 --- a/src/Gui/ViewerWindow.cpp +++ b/src/Gui/ViewerWindow.cpp @@ -39,6 +39,27 @@ ViewerWindow::ViewerWindow(Mode mode, QQmlEngine *engine, QWindow *parent) setResizeMode(QQuickView::SizeRootObjectToView); setMode(mode); // sets source and other stuff based on mode. m_oldWindowStates = windowStates(); + + addShortcut(QKeySequence::Save, this, &ViewerWindow::save); + addShortcut(QKeySequence::SaveAs, this, &ViewerWindow::saveAs); + addShortcut(QKeySequence::Copy, this, &ViewerWindow::copyImage); + addShortcut(QKeySequence::Print, this, &ViewerWindow::showPrintDialog); + addShortcut(QKeySequence::Undo, this, [this]() { + if (isAnnotating()) { + auto document = SpectacleCore::instance()->annotationDocument(); + if (document->undoStackDepth() > 0) { + document->undo(); + } + } + }); + addShortcut(QKeySequence::Redo, this, [this]() { + if (isAnnotating()) { + auto document = SpectacleCore::instance()->annotationDocument(); + if (document->redoStackDepth() > 0) { + document->redo(); + } + } + }); } ViewerWindow::~ViewerWindow() @@ -293,35 +314,4 @@ void ViewerWindow::resizeEvent(QResizeEvent *event) } } -void ViewerWindow::keyReleaseEvent(QKeyEvent *event) -{ - SpectacleWindow::keyReleaseEvent(event); - if (event->isAccepted() || m_mode == Dialog) { - return; - } - if (event->matches(QKeySequence::Save)) { - event->accept(); - save(); - } else if (event->matches(QKeySequence::SaveAs)) { - event->accept(); - saveAs(); - } else if (event->matches(QKeySequence::Copy)) { - event->accept(); - copyImage(); - } else if (event->matches(QKeySequence::Print)) { - event->accept(); - showPrintDialog(); - } - auto document = SpectacleCore::instance()->annotationDocument(); - if (!event->isAccepted() && document) { - if (document->undoStackDepth() > 0 && event->matches(QKeySequence::Undo)) { - event->accept(); - document->undo(); - } else if (document->redoStackDepth() > 0 && event->matches(QKeySequence::Redo)) { - event->accept(); - document->redo(); - } - } -} - #include "moc_ViewerWindow.cpp" diff --git a/src/Gui/ViewerWindow.h b/src/Gui/ViewerWindow.h index 1c405981842e54970add8991f30ecd6937068244..1f4fcc640fedb276e03f68a0a0377e275f3865ba 100644 --- a/src/Gui/ViewerWindow.h +++ b/src/Gui/ViewerWindow.h @@ -47,7 +47,6 @@ public: protected: bool event(QEvent *event) override; void resizeEvent(QResizeEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; private: explicit ViewerWindow(Mode mode, QQmlEngine *engine, QWindow *parent = nullptr);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor