diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-29 13:09:19 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-04 10:32:38 +0200 |
commit | b26fa9722f9e8c81406259f6db8044e8bbc2d50b (patch) | |
tree | 30d443ac43663e1670c82621d88052e3be29141b /src/gui/kernel/qshortcut.h | |
parent | 8fa93272f0a1526e06105ea02c7ae5ca8f8c52c0 (diff) |
Add multi key bindings to QShortcut
This makes it feature comparable with QAction, and makes it possible
to use as a backend for QAction, and fixes a few missing alternative
keybindings in qtwidgets.
Change-Id: Iaefc630b96c4743fc5ef429dc841870ddd99fc64
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/kernel/qshortcut.h')
-rw-r--r-- | src/gui/kernel/qshortcut.h | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/src/gui/kernel/qshortcut.h b/src/gui/kernel/qshortcut.h index 1b90a21925..d3db30fd4d 100644 --- a/src/gui/kernel/qshortcut.h +++ b/src/gui/kernel/qshortcut.h @@ -64,6 +64,9 @@ public: explicit QShortcut(const QKeySequence& key, QObject *parent, const char *member = nullptr, const char *ambiguousMember = nullptr, Qt::ShortcutContext context = Qt::WindowShortcut); + explicit QShortcut(QKeySequence::StandardKey key, QObject *parent, + const char *member = nullptr, const char *ambiguousMember = nullptr, + Qt::ShortcutContext context = Qt::WindowShortcut); #ifdef Q_CLANG_QDOC template<typename Functor> @@ -84,6 +87,25 @@ public: const QObject *context1, Functor functor, const QObject *context2, FunctorAmbiguous functorAmbiguous, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + + template<typename Functor> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const QObject *context, Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor, typename FunctorAmbiguous> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const QObject *context1, Functor functor, + FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor, typename FunctorAmbiguous> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const QObject *context1, Functor functor, + const QObject *context2, FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); #else template<typename Func1> QShortcut(const QKeySequence &key, QObject *parent, @@ -124,12 +146,55 @@ public: connect(this, &QShortcut::activated, object1, std::move(slot1)); connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2)); } + + template<typename Func1> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + Func1 slot1, + Qt::ShortcutContext context = Qt::WindowShortcut) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, std::move(slot1)); + } + template<class Obj1, typename Func1> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const Obj1 *object1, Func1 slot1, + Qt::ShortcutContext context = Qt::WindowShortcut, + typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + } + template<class Obj1, typename Func1, typename Func2> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const Obj1 *object1, Func1 slot1, Func2 slot2, + Qt::ShortcutContext context = Qt::WindowShortcut, + typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2)); + } + template<class Obj1, typename Func1, class Obj2, typename Func2> + QShortcut(QKeySequence::StandardKey key, QObject *parent, + const Obj1 *object1, Func1 slot1, + const Obj2 *object2, Func2 slot2, + Qt::ShortcutContext context = Qt::WindowShortcut, + typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0, + typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj2*>::Value>::type* = 0) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2)); + } #endif ~QShortcut(); void setKey(const QKeySequence& key); QKeySequence key() const; + void setKeys(QKeySequence::StandardKey key); + void setKeys(const QList<QKeySequence> &keys); + QList<QKeySequence> keys() const; void setEnabled(bool enable); bool isEnabled() const; @@ -140,7 +205,9 @@ public: void setAutoRepeat(bool on); bool autoRepeat() const; - int id() const; +#if QT_DEPRECATED_SINCE(6,0) + Q_DECL_DEPRECATED int id() const; +#endif void setWhatsThis(const QString &text); QString whatsThis() const; |