QtBase  v6.3.1
qshortcut.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QSHORTCUT_H
41 #define QSHORTCUT_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtGui/qkeysequence.h>
45 #include <QtCore/qobject.h>
46 
48 
50 
51 class QShortcutPrivate;
52 class QWindow;
53 
54 class Q_GUI_EXPORT QShortcut : public QObject
55 {
56  Q_OBJECT
57  Q_DECLARE_PRIVATE(QShortcut)
59  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
60  Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
61  Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext)
62 public:
63  explicit QShortcut(QObject *parent);
64  explicit QShortcut(const QKeySequence& key, QObject *parent,
65  const char *member = nullptr, const char *ambiguousMember = nullptr,
68  const char *member = nullptr, const char *ambiguousMember = nullptr,
70 
71 #ifdef Q_CLANG_QDOC
72  template<typename Functor>
74  Functor functor,
75  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
76  template<typename Functor>
78  const QObject *context, Functor functor,
79  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
80  template<typename Functor, typename FunctorAmbiguous>
82  const QObject *context1, Functor functor,
83  FunctorAmbiguous functorAmbiguous,
84  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
85  template<typename Functor, typename FunctorAmbiguous>
87  const QObject *context1, Functor functor,
88  const QObject *context2, FunctorAmbiguous functorAmbiguous,
89  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
90 
91  template<typename Functor>
93  Functor functor,
94  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
95  template<typename Functor>
97  const QObject *context, Functor functor,
98  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
99  template<typename Functor, typename FunctorAmbiguous>
101  const QObject *context1, Functor functor,
102  FunctorAmbiguous functorAmbiguous,
103  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
104  template<typename Functor, typename FunctorAmbiguous>
106  const QObject *context1, Functor functor,
107  const QObject *context2, FunctorAmbiguous functorAmbiguous,
108  Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
109 #else
110  template<typename Func1>
112  Func1 slot1,
114  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
115  {
116  connect(this, &QShortcut::activated, std::move(slot1));
117  }
118  template<class Obj1, typename Func1>
120  const Obj1 *object1, Func1 slot1,
123  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
124  {
125  connect(this, &QShortcut::activated, object1, std::move(slot1));
126  }
127  template<class Obj1, typename Func1, typename Func2>
129  const Obj1 *object1, Func1 slot1, Func2 slot2,
132  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
133  {
134  connect(this, &QShortcut::activated, object1, std::move(slot1));
135  connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
136  }
137  template<class Obj1, typename Func1, class Obj2, typename Func2>
139  const Obj1 *object1, Func1 slot1,
140  const Obj2 *object2, Func2 slot2,
144  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
145  {
146  connect(this, &QShortcut::activated, object1, std::move(slot1));
147  connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
148  }
149 
150  template<typename Func1>
152  Func1 slot1,
154  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
155  {
156  connect(this, &QShortcut::activated, std::move(slot1));
157  }
158  template<class Obj1, typename Func1>
160  const Obj1 *object1, Func1 slot1,
163  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
164  {
165  connect(this, &QShortcut::activated, object1, std::move(slot1));
166  }
167  template<class Obj1, typename Func1, typename Func2>
169  const Obj1 *object1, Func1 slot1, Func2 slot2,
172  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
173  {
174  connect(this, &QShortcut::activated, object1, std::move(slot1));
175  connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
176  }
177  template<class Obj1, typename Func1, class Obj2, typename Func2>
179  const Obj1 *object1, Func1 slot1,
180  const Obj2 *object2, Func2 slot2,
184  : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
185  {
186  connect(this, &QShortcut::activated, object1, std::move(slot1));
187  connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
188  }
189 #endif
190 
191  ~QShortcut();
192 
193  void setKey(const QKeySequence& key);
194  QKeySequence key() const;
195  void setKeys(QKeySequence::StandardKey key);
196  void setKeys(const QList<QKeySequence> &keys);
197  QList<QKeySequence> keys() const;
198 
199  void setEnabled(bool enable);
200  bool isEnabled() const;
201 
202  void setContext(Qt::ShortcutContext context);
204 
205  void setAutoRepeat(bool on);
206  bool autoRepeat() const;
207 
208 #if QT_DEPRECATED_SINCE(6,0)
209  Q_DECL_DEPRECATED int id() const;
210 #endif
211 
212  void setWhatsThis(const QString &text);
213  QString whatsThis() const;
214 
215 #if QT_DEPRECATED_SINCE(6,0)
216 #ifdef Q_CLANG_QDOC
217  QWidget *parentWidget() const;
218 #else
219  template<typename T = QWidget*>
220  inline T parentWidget() const
221  { return static_cast<T>(QObject::parent()); }
222 #endif
223 #endif
224 
225 Q_SIGNALS:
226  void activated();
228 
229 protected:
230  bool event(QEvent *e) override;
231 };
232 
234 
235 #endif // QSHORTCUT_H
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:71
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
QObject * parent() const
Definition: qobject.h:409
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Definition: qobject.cpp:2772
virtual bool event(QEvent *event)
Definition: qobject.cpp:1329
The QShortcut class is used to create keyboard shortcuts.
Definition: qshortcut.h:55
QShortcut(const QKeySequence &key, QObject *parent, const Obj1 *object1, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0)
Definition: qshortcut.h:119
QShortcut(const QKeySequence &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)
Definition: qshortcut.h:128
void activatedAmbiguously()
QShortcut(QKeySequence::StandardKey key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut)
Definition: qshortcut.h:151
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)
Definition: qshortcut.h:168
QShortcut(const QKeySequence &key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut)
Definition: qshortcut.h:111
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)
Definition: qshortcut.h:159
QShortcut(const QKeySequence &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)
Definition: qshortcut.h:138
void activated()
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)
Definition: qshortcut.h:178
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
double e
QT_REQUIRE_CONFIG(shortcut)
auto it unsigned count const
Definition: hb-iter.hh:848
void slot1(const QString &a)
void slot2(const QString &a, const QString &b)
ShortcutContext
Definition: qnamespace.h:1313
@ WindowShortcut
Definition: qnamespace.h:1315
#define Q_DECL_DEPRECATED
@ text
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum type
Definition: qopengl.h:270
GLuint64 key
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLboolean enable
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SIGNALS
Definition: qtmetamacros.h:81
QStringList keys
QObject::connect nullptr
setKey(0)
[0]
Definition: main.cpp:38
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent