qshortcut.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qshortcut.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets 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#include "qshortcut.h"-
41#include "private/qwidget_p.h"-
42-
43#ifndef QT_NO_SHORTCUT-
44#include <qevent.h>-
45#include <qwhatsthis.h>-
46#include <qmenu.h>-
47#include <qmenubar.h>-
48#include <qapplication.h>-
49#include <private/qapplication_p.h>-
50#include <private/qshortcutmap_p.h>-
51#include <private/qaction_p.h>-
52#include <private/qwidgetwindow_p.h>-
53#include <qpa/qplatformmenu.h>-
54-
55QT_BEGIN_NAMESPACE-
56-
57#define QAPP_CHECK(functionName) \-
58 if (Q_UNLIKELY(!qApp)) { \-
59 qWarning("QShortcut: Initialize QApplication before calling '" functionName "'."); \-
60 return; \-
61 }-
62-
63-
64static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window);-
65#ifndef QT_NO_GRAPHICSVIEW-
66static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window);-
67#endif-
68#ifndef QT_NO_ACTION-
69static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window);-
70#endif-
71-
72-
73/*! \internal-
74 Returns \c true if the widget \a w is a logical sub window of the current-
75 top-level widget.-
76*/-
77bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)-
78{-
79 Q_ASSERT_X(object, "QShortcutMap", "Shortcut has no owner. Illegal map state!");-
80-
81 QWidget *active_window = QApplication::activeWindow();-
82-
83 // popups do not become the active window,-
84 // so we fake it here to get the correct context-
85 // for the shortcut system.-
86 if (QApplication::activePopupWidget())
QApplication::...ePopupWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
87 active_window = QApplication::activePopupWidget();
never executed: active_window = QApplication::activePopupWidget();
0
88-
89 if (!active_window) {
!active_windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
90 QWindow *qwindow = QGuiApplication::focusWindow();-
91 if (qwindow && qwindow->isActive()) {
qwindowDescription
TRUEnever evaluated
FALSEnever evaluated
qwindow->isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
92 while (qwindow) {
qwindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
93 QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(qwindow);-
94 if (widgetWindow) {
widgetWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 active_window = widgetWindow->widget();-
96 break;
never executed: break;
0
97 }-
98 qwindow = qwindow->parent();-
99 }
never executed: end of block
0
100 }
never executed: end of block
0
101 }
never executed: end of block
0
102-
103 if (!active_window)
!active_windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
104 return false;
never executed: return false;
0
105-
106#ifndef QT_NO_ACTION-
107 if (QAction *a = qobject_cast<QAction *>(object))
QAction *a = q...ion *>(object)Description
TRUEnever evaluated
FALSEnever evaluated
0
108 return correctActionContext(context, a, active_window);
never executed: return correctActionContext(context, a, active_window);
0
109#endif-
110-
111#ifndef QT_NO_GRAPHICSVIEW-
112 if (QGraphicsWidget *gw = qobject_cast<QGraphicsWidget *>(object))
QGraphicsWidge...get *>(object)Description
TRUEnever evaluated
FALSEnever evaluated
0
113 return correctGraphicsWidgetContext(context, gw, active_window);
never executed: return correctGraphicsWidgetContext(context, gw, active_window);
0
114#endif-
115-
116 QWidget *w = qobject_cast<QWidget *>(object);-
117 if (!w) {
!wDescription
TRUEnever evaluated
FALSEnever evaluated
0
118 QShortcut *s = qobject_cast<QShortcut *>(object);-
119 if (s)
sDescription
TRUEnever evaluated
FALSEnever evaluated
0
120 w = s->parentWidget();
never executed: w = s->parentWidget();
0
121 }
never executed: end of block
0
122-
123 if (!w) {
!wDescription
TRUEnever evaluated
FALSEnever evaluated
0
124 QWindow *qwindow = qobject_cast<QWindow *>(object);-
125 while (qwindow) {
qwindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
126 QWidgetWindow *widget_window = qobject_cast<QWidgetWindow *>(qwindow);-
127 if (widget_window) {
widget_windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
128 w = widget_window->widget();-
129 break;
never executed: break;
0
130 }-
131 qwindow = qwindow->parent();-
132 }
never executed: end of block
0
133 }
never executed: end of block
0
134-
135 if (!w)
!wDescription
TRUEnever evaluated
FALSEnever evaluated
0
136 return false;
never executed: return false;
0
137-
138 return correctWidgetContext(context, w, active_window);
never executed: return correctWidgetContext(context, w, active_window);
0
139}-
140-
141static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window)-
142{-
143 bool visible = w->isVisible();-
144#ifdef Q_OS_MAC-
145 if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))-
146 visible = true;-
147#endif-
148-
149 if (!visible || !w->isEnabled())
!visibleDescription
TRUEnever evaluated
FALSEnever evaluated
!w->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
150 return false;
never executed: return false;
0
151-
152 if (context == Qt::ApplicationShortcut)
context == Qt:...cationShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
153 return QApplicationPrivate::tryModalHelper(w, 0); // true, unless w is shadowed by a modal dialog
never executed: return QApplicationPrivate::tryModalHelper(w, 0);
0
154-
155 if (context == Qt::WidgetShortcut)
context == Qt::WidgetShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
156 return w == QApplication::focusWidget();
never executed: return w == QApplication::focusWidget();
0
157-
158 if (context == Qt::WidgetWithChildrenShortcut) {
context == Qt:...ildrenShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
159 const QWidget *tw = QApplication::focusWidget();-
160 while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup || tw->windowType() == Qt::SubWindow))
twDescription
TRUEnever evaluated
FALSEnever evaluated
tw != wDescription
TRUEnever evaluated
FALSEnever evaluated
tw->windowType() == Qt::WidgetDescription
TRUEnever evaluated
FALSEnever evaluated
tw->windowType() == Qt::PopupDescription
TRUEnever evaluated
FALSEnever evaluated
tw->windowType... Qt::SubWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
161 tw = tw->parentWidget();
never executed: tw = tw->parentWidget();
0
162 return tw == w;
never executed: return tw == w;
0
163 }-
164-
165 // Below is Qt::WindowShortcut context-
166 QWidget *tlw = w->window();-
167#ifndef QT_NO_GRAPHICSVIEW-
168 if (QWExtra *topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra) {
QWExtra *topDa...t(tlw))->extraDescription
TRUEnever evaluated
FALSEnever evaluated
0
169 if (topData->proxyWidget) {
topData->proxyWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 bool res = correctGraphicsWidgetContext(context, (QGraphicsWidget *)topData->proxyWidget, active_window);-
171 return res;
never executed: return res;
0
172 }-
173 }
never executed: end of block
0
174#endif-
175-
176 /* if a floating tool window is active, keep shortcuts on the-
177 * parent working */-
178 if (active_window != tlw && active_window && active_window->windowType() == Qt::Tool && active_window->parentWidget()) {
active_window != tlwDescription
TRUEnever evaluated
FALSEnever evaluated
active_windowDescription
TRUEnever evaluated
FALSEnever evaluated
active_window-...() == Qt::ToolDescription
TRUEnever evaluated
FALSEnever evaluated
active_window->parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
179 active_window = active_window->parentWidget()->window();-
180 }
never executed: end of block
0
181-
182 if (active_window != tlw)
active_window != tlwDescription
TRUEnever evaluated
FALSEnever evaluated
0
183 return false;
never executed: return false;
0
184-
185 /* if we live in a MDI subwindow, ignore the event if we are-
186 not the active document window */-
187 const QWidget* sw = w;-
188 while (sw && !(sw->windowType() == Qt::SubWindow) && !sw->isWindow())
swDescription
TRUEnever evaluated
FALSEnever evaluated
!(sw->windowTy...Qt::SubWindow)Description
TRUEnever evaluated
FALSEnever evaluated
!sw->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
189 sw = sw->parentWidget();
never executed: sw = sw->parentWidget();
0
190 if (sw && (sw->windowType() == Qt::SubWindow)) {
swDescription
TRUEnever evaluated
FALSEnever evaluated
(sw->windowTyp...Qt::SubWindow)Description
TRUEnever evaluated
FALSEnever evaluated
0
191 QWidget *focus_widget = QApplication::focusWidget();-
192 while (focus_widget && focus_widget != sw)
focus_widgetDescription
TRUEnever evaluated
FALSEnever evaluated
focus_widget != swDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 focus_widget = focus_widget->parentWidget();
never executed: focus_widget = focus_widget->parentWidget();
0
194 return sw == focus_widget;
never executed: return sw == focus_widget;
0
195 }-
196-
197#if defined(DEBUG_QSHORTCUTMAP)-
198 qDebug().nospace() << "..true [Pass-through]";-
199#endif-
200 return true;
never executed: return true;
0
201}-
202-
203#ifndef QT_NO_GRAPHICSVIEW-
204static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window)-
205{-
206 bool visible = w->isVisible();-
207#ifdef Q_OS_MAC-
208 if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))-
209 visible = true;-
210#endif-
211-
212 if (!visible || !w->isEnabled() || !w->scene())
!visibleDescription
TRUEnever evaluated
FALSEnever evaluated
!w->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
!w->scene()Description
TRUEnever evaluated
FALSEnever evaluated
0
213 return false;
never executed: return false;
0
214-
215 if (context == Qt::ApplicationShortcut) {
context == Qt:...cationShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
216 // Applicationwide shortcuts are always reachable unless their owner-
217 // is shadowed by modality. In QGV there's no modality concept, but we-
218 // must still check if all views are shadowed.-
219 QList<QGraphicsView *> views = w->scene()->views();-
220 for (int i = 0; i < views.size(); ++i) {
i < views.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
221 if (QApplicationPrivate::tryModalHelper(views.at(i), 0))
QApplicationPr...iews.at(i), 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
222 return true;
never executed: return true;
0
223 }
never executed: end of block
0
224 return false;
never executed: return false;
0
225 }-
226-
227 if (context == Qt::WidgetShortcut)
context == Qt::WidgetShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
228 return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem();
never executed: return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem();
0
229-
230 if (context == Qt::WidgetWithChildrenShortcut) {
context == Qt:...ildrenShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
231 const QGraphicsItem *ti = w->scene()->focusItem();-
232 if (ti && ti->isWidget()) {
tiDescription
TRUEnever evaluated
FALSEnever evaluated
ti->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
233 const QGraphicsWidget *tw = static_cast<const QGraphicsWidget *>(ti);-
234 while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup))
twDescription
TRUEnever evaluated
FALSEnever evaluated
tw != wDescription
TRUEnever evaluated
FALSEnever evaluated
tw->windowType() == Qt::WidgetDescription
TRUEnever evaluated
FALSEnever evaluated
tw->windowType() == Qt::PopupDescription
TRUEnever evaluated
FALSEnever evaluated
0
235 tw = tw->parentWidget();
never executed: tw = tw->parentWidget();
0
236 return tw == w;
never executed: return tw == w;
0
237 }-
238 return false;
never executed: return false;
0
239 }-
240-
241 // Below is Qt::WindowShortcut context-
242-
243 // Find the active view (if any).-
244 QList<QGraphicsView *> views = w->scene()->views();-
245 QGraphicsView *activeView = 0;-
246 for (int i = 0; i < views.size(); ++i) {
i < views.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
247 QGraphicsView *view = views.at(i);-
248 if (view->window() == active_window) {
view->window()... active_windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
249 activeView = view;-
250 break;
never executed: break;
0
251 }-
252 }
never executed: end of block
0
253 if (!activeView)
!activeViewDescription
TRUEnever evaluated
FALSEnever evaluated
0
254 return false;
never executed: return false;
0
255-
256 // The shortcut is reachable if owned by a windowless widget, or if the-
257 // widget's window is the same as the focus item's window.-
258 QGraphicsWidget *a = w->scene()->activeWindow();-
259 return !w->window() || a == w->window();
never executed: return !w->window() || a == w->window();
0
260}-
261#endif-
262-
263#ifndef QT_NO_ACTION-
264static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window)-
265{-
266 const QList<QWidget *> &widgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->widgets;-
267#if defined(DEBUG_QSHORTCUTMAP)-
268 if (widgets.isEmpty())-
269 qDebug() << a << "not connected to any widgets; won't trigger";-
270#endif-
271 for (int i = 0; i < widgets.size(); ++i) {
i < widgets.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
272 QWidget *w = widgets.at(i);-
273#ifndef QT_NO_MENU-
274 if (QMenu *menu = qobject_cast<QMenu *>(w)) {
QMenu *menu = ...st<QMenu *>(w)Description
TRUEnever evaluated
FALSEnever evaluated
0
275#ifdef Q_OS_MAC-
276 // On Mac, menu item shortcuts are processed before reaching any window.-
277 // That means that if a menu action shortcut has not been already processed-
278 // (and reaches this point), then the menu item itself has been disabled.-
279 // This occurs at the QPA level on Mac, where we disable all the Cocoa menus-
280 // when showing a modal window. (Notice that only the QPA menu is disabled,-
281 // not the QMenu.) Since we can also reach this code by climbing the menu-
282 // hierarchy (see below), or when the shortcut is not a key-equivalent, we-
283 // need to check whether the QPA menu is actually disabled.-
284 QPlatformMenu *pm = menu->platformMenu();-
285 if (!pm || !pm->isEnabled())-
286 continue;-
287#endif-
288 QAction *a = menu->menuAction();-
289 if (correctActionContext(context, a, active_window))
correctActionC...active_window)Description
TRUEnever evaluated
FALSEnever evaluated
0
290 return true;
never executed: return true;
0
291 } else
never executed: end of block
0
292#endif-
293 if (correctWidgetContext(context, w, active_window))
correctWidgetC...active_window)Description
TRUEnever evaluated
FALSEnever evaluated
0
294 return true;
never executed: return true;
0
295 }
never executed: end of block
0
296-
297#ifndef QT_NO_GRAPHICSVIEW-
298 const QList<QGraphicsWidget *> &graphicsWidgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->graphicsWidgets;-
299#if defined(DEBUG_QSHORTCUTMAP)-
300 if (graphicsWidgets.isEmpty())-
301 qDebug() << a << "not connected to any widgets; won't trigger";-
302#endif-
303 for (int i = 0; i < graphicsWidgets.size(); ++i) {
i < graphicsWidgets.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
304 QGraphicsWidget *w = graphicsWidgets.at(i);-
305 if (correctGraphicsWidgetContext(context, w, active_window))
correctGraphic...active_window)Description
TRUEnever evaluated
FALSEnever evaluated
0
306 return true;
never executed: return true;
0
307 }
never executed: end of block
0
308#endif-
309 return false;
never executed: return false;
0
310}-
311#endif // QT_NO_ACTION-
312-
313-
314/*!-
315 \class QShortcut-
316 \brief The QShortcut class is used to create keyboard shortcuts.-
317-
318 \ingroup events-
319 \inmodule QtWidgets-
320-
321 The QShortcut class provides a way of connecting keyboard-
322 shortcuts to Qt's \l{signals and slots} mechanism, so that-
323 objects can be informed when a shortcut is executed. The shortcut-
324 can be set up to contain all the key presses necessary to-
325 describe a keyboard shortcut, including the states of modifier-
326 keys such as \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt.-
327-
328 \target mnemonic-
329-
330 On certain widgets, using '&' in front of a character will-
331 automatically create a mnemonic (a shortcut) for that character,-
332 e.g. "E&xit" will create the shortcut \uicontrol Alt+X (use '&&' to-
333 display an actual ampersand). The widget might consume and perform-
334 an action on a given shortcut. On X11 the ampersand will not be-
335 shown and the character will be underlined. On Windows, shortcuts-
336 are normally not displayed until the user presses the \uicontrol Alt-
337 key, but this is a setting the user can change. On Mac, shortcuts-
338 are disabled by default. Call \l qt_set_sequence_auto_mnemonic() to-
339 enable them. However, because mnemonic shortcuts do not fit in-
340 with Aqua's guidelines, Qt will not show the shortcut character-
341 underlined.-
342-
343 For applications that use menus, it may be more convenient to-
344 use the convenience functions provided in the QMenu class to-
345 assign keyboard shortcuts to menu items as they are created.-
346 Alternatively, shortcuts may be associated with other types of-
347 actions in the QAction class.-
348-
349 The simplest way to create a shortcut for a particular widget is-
350 to construct the shortcut with a key sequence. For example:-
351-
352 \snippet code/src_gui_kernel_qshortcut.cpp 0-
353-
354 When the user types the \l{QKeySequence}{key sequence}-
355 for a given shortcut, the shortcut's activated() signal is-
356 emitted. (In the case of ambiguity, the activatedAmbiguously()-
357 signal is emitted.) A shortcut is "listened for" by Qt's event-
358 loop when the shortcut's parent widget is receiving events.-
359-
360 A shortcut's key sequence can be set with setKey() and retrieved-
361 with key(). A shortcut can be enabled or disabled with-
362 setEnabled(), and can have "What's This?" help text set with-
363 setWhatsThis().-
364-
365 \sa QShortcutEvent, QKeySequence, QAction-
366*/-
367-
368/*!-
369 \fn QWidget *QShortcut::parentWidget() const-
370-
371 Returns the shortcut's parent widget.-
372*/-
373-
374/*!-
375 \fn void QShortcut::activated()-
376-
377 This signal is emitted when the user types the shortcut's key-
378 sequence.-
379-
380 \sa activatedAmbiguously()-
381*/-
382-
383/*!-
384 \fn void QShortcut::activatedAmbiguously()-
385-
386 When a key sequence is being typed at the keyboard, it is said to-
387 be ambiguous as long as it matches the start of more than one-
388 shortcut.-
389-
390 When a shortcut's key sequence is completed,-
391 activatedAmbiguously() is emitted if the key sequence is still-
392 ambiguous (i.e., it is the start of one or more other shortcuts).-
393 The activated() signal is not emitted in this case.-
394-
395 \sa activated()-
396*/-
397-
398/*-
399 \internal-
400 Private data accessed through d-pointer.-
401*/-
402class QShortcutPrivate : public QObjectPrivate-
403{-
404 Q_DECLARE_PUBLIC(QShortcut)-
405public:-
406 QShortcutPrivate() : sc_context(Qt::WindowShortcut), sc_enabled(true), sc_autorepeat(true), sc_id(0) {}
never executed: end of block
0
407 QKeySequence sc_sequence;-
408 Qt::ShortcutContext sc_context;-
409 bool sc_enabled;-
410 bool sc_autorepeat;-
411 int sc_id;-
412 QString sc_whatsthis;-
413 void redoGrab(QShortcutMap &map);-
414};-
415-
416void QShortcutPrivate::redoGrab(QShortcutMap &map)-
417{-
418 Q_Q(QShortcut);-
419 if (Q_UNLIKELY(!parent)) {
__builtin_expe...arent), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
420 qWarning("QShortcut: No widget parent defined");-
421 return;
never executed: return;
0
422 }-
423-
424 if (sc_id)
sc_idDescription
TRUEnever evaluated
FALSEnever evaluated
0
425 map.removeShortcut(sc_id, q);
never executed: map.removeShortcut(sc_id, q);
0
426 if (sc_sequence.isEmpty())
sc_sequence.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
427 return;
never executed: return;
0
428 sc_id = map.addShortcut(q, sc_sequence, sc_context, qWidgetShortcutContextMatcher);-
429 if (!sc_enabled)
!sc_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
430 map.setShortcutEnabled(false, sc_id, q);
never executed: map.setShortcutEnabled(false, sc_id, q);
0
431 if (!sc_autorepeat)
!sc_autorepeatDescription
TRUEnever evaluated
FALSEnever evaluated
0
432 map.setShortcutAutoRepeat(false, sc_id, q);
never executed: map.setShortcutAutoRepeat(false, sc_id, q);
0
433}
never executed: end of block
0
434-
435/*!-
436 Constructs a QShortcut object for the \a parent widget. Since no-
437 shortcut key sequence is specified, the shortcut will not emit any-
438 signals.-
439-
440 \sa setKey()-
441*/-
442QShortcut::QShortcut(QWidget *parent)-
443 : QObject(*new QShortcutPrivate, parent)-
444{-
445 Q_ASSERT(parent != 0);-
446}
never executed: end of block
0
447-
448/*!-
449 Constructs a QShortcut object for the \a parent widget. The shortcut-
450 operates on its parent, listening for \l{QShortcutEvent}s that-
451 match the \a key sequence. Depending on the ambiguity of the-
452 event, the shortcut will call the \a member function, or the \a-
453 ambiguousMember function, if the key press was in the shortcut's-
454 \a context.-
455*/-
456QShortcut::QShortcut(const QKeySequence &key, QWidget *parent,-
457 const char *member, const char *ambiguousMember,-
458 Qt::ShortcutContext context)-
459 : QObject(*new QShortcutPrivate, parent)-
460{-
461 QAPP_CHECK("QShortcut");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
462-
463 Q_D(QShortcut);-
464 Q_ASSERT(parent != 0);-
465 d->sc_context = context;-
466 d->sc_sequence = key;-
467 d->redoGrab(qApp->d_func()->shortcutMap);-
468 if (member)
memberDescription
TRUEnever evaluated
FALSEnever evaluated
0
469 connect(this, SIGNAL(activated()), parent, member);
never executed: connect(this, qFlagLocation("2""activated()" "\0" __FILE__ ":" "469"), parent, member);
0
470 if (ambiguousMember)
ambiguousMemberDescription
TRUEnever evaluated
FALSEnever evaluated
0
471 connect(this, SIGNAL(activatedAmbiguously()), parent, ambiguousMember);
never executed: connect(this, qFlagLocation("2""activatedAmbiguously()" "\0" __FILE__ ":" "471"), parent, ambiguousMember);
0
472}
never executed: end of block
0
473-
474/*!-
475 Destroys the shortcut.-
476*/-
477QShortcut::~QShortcut()-
478{-
479 Q_D(QShortcut);-
480 if (qApp)
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
0
481 qApp->d_func()->shortcutMap.removeShortcut(d->sc_id, this);
never executed: (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.removeShortcut(d->sc_id, this);
0
482}
never executed: end of block
0
483-
484/*!-
485 \property QShortcut::key-
486 \brief the shortcut's key sequence-
487-
488 This is a key sequence with an optional combination of Shift, Ctrl,-
489 and Alt. The key sequence may be supplied in a number of ways:-
490-
491 \snippet code/src_gui_kernel_qshortcut.cpp 1-
492-
493 By default, this property contains an empty key sequence.-
494*/-
495void QShortcut::setKey(const QKeySequence &key)-
496{-
497 Q_D(QShortcut);-
498 if (d->sc_sequence == key)
d->sc_sequence == keyDescription
TRUEnever evaluated
FALSEnever evaluated
0
499 return;
never executed: return;
0
500 QAPP_CHECK("setKey");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
501 d->sc_sequence = key;-
502 d->redoGrab(qApp->d_func()->shortcutMap);-
503}
never executed: end of block
0
504-
505QKeySequence QShortcut::key() const-
506{-
507 Q_D(const QShortcut);-
508 return d->sc_sequence;
never executed: return d->sc_sequence;
0
509}-
510-
511/*!-
512 \property QShortcut::enabled-
513 \brief whether the shortcut is enabled-
514-
515 An enabled shortcut emits the activated() or activatedAmbiguously()-
516 signal when a QShortcutEvent occurs that matches the shortcut's-
517 key() sequence.-
518-
519 If the application is in \c WhatsThis mode the shortcut will not emit-
520 the signals, but will show the "What's This?" text instead.-
521-
522 By default, this property is \c true.-
523-
524 \sa whatsThis-
525*/-
526void QShortcut::setEnabled(bool enable)-
527{-
528 Q_D(QShortcut);-
529 if (d->sc_enabled == enable)
d->sc_enabled == enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
530 return;
never executed: return;
0
531 QAPP_CHECK("setEnabled");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
532 d->sc_enabled = enable;-
533 qApp->d_func()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this);-
534}
never executed: end of block
0
535-
536bool QShortcut::isEnabled() const-
537{-
538 Q_D(const QShortcut);-
539 return d->sc_enabled;
never executed: return d->sc_enabled;
0
540}-
541-
542/*!-
543 \property QShortcut::context-
544 \brief the context in which the shortcut is valid-
545-
546 A shortcut's context decides in which circumstances a shortcut is-
547 allowed to be triggered. The normal context is Qt::WindowShortcut,-
548 which allows the shortcut to trigger if the parent (the widget-
549 containing the shortcut) is a subwidget of the active top-level-
550 window.-
551-
552 By default, this property is set to Qt::WindowShortcut.-
553*/-
554void QShortcut::setContext(Qt::ShortcutContext context)-
555{-
556 Q_D(QShortcut);-
557 if(d->sc_context == context)
d->sc_context == contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
558 return;
never executed: return;
0
559 QAPP_CHECK("setContext");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
560 d->sc_context = context;-
561 d->redoGrab(qApp->d_func()->shortcutMap);-
562}
never executed: end of block
0
563-
564Qt::ShortcutContext QShortcut::context() const-
565{-
566 Q_D(const QShortcut);-
567 return d->sc_context;
never executed: return d->sc_context;
0
568}-
569-
570/*!-
571 \property QShortcut::whatsThis-
572 \brief the shortcut's "What's This?" help text-
573-
574 The text will be shown when the application is in "What's-
575 This?" mode and the user types the shortcut key() sequence.-
576-
577 To set "What's This?" help on a menu item (with or without a-
578 shortcut key), set the help on the item's action.-
579-
580 By default, this property contains an empty string.-
581-
582 \sa QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis()-
583*/-
584void QShortcut::setWhatsThis(const QString &text)-
585{-
586 Q_D(QShortcut);-
587 d->sc_whatsthis = text;-
588}
never executed: end of block
0
589-
590QString QShortcut::whatsThis() const-
591{-
592 Q_D(const QShortcut);-
593 return d->sc_whatsthis;
never executed: return d->sc_whatsthis;
0
594}-
595-
596/*!-
597 \property QShortcut::autoRepeat-
598 \brief whether the shortcut can auto repeat-
599 \since 4.2-
600-
601 If true, the shortcut will auto repeat when the keyboard shortcut-
602 combination is held down, provided that keyboard auto repeat is-
603 enabled on the system.-
604 The default value is true.-
605*/-
606void QShortcut::setAutoRepeat(bool on)-
607{-
608 Q_D(QShortcut);-
609 if (d->sc_autorepeat == on)
d->sc_autorepeat == onDescription
TRUEnever evaluated
FALSEnever evaluated
0
610 return;
never executed: return;
0
611 QAPP_CHECK("setAutoRepeat");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
612 d->sc_autorepeat = on;-
613 qApp->d_func()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this);-
614}
never executed: end of block
0
615-
616bool QShortcut::autoRepeat() const-
617{-
618 Q_D(const QShortcut);-
619 return d->sc_autorepeat;
never executed: return d->sc_autorepeat;
0
620}-
621-
622/*!-
623 Returns the shortcut's ID.-
624-
625 \sa QShortcutEvent::shortcutId()-
626*/-
627int QShortcut::id() const-
628{-
629 Q_D(const QShortcut);-
630 return d->sc_id;
never executed: return d->sc_id;
0
631}-
632-
633/*!-
634 \internal-
635*/-
636bool QShortcut::event(QEvent *e)-
637{-
638 Q_D(QShortcut);-
639 bool handled = false;-
640 if (d->sc_enabled && e->type() == QEvent::Shortcut) {
d->sc_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
e->type() == QEvent::ShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
641 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);-
642 if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){
se->shortcutId() == d->sc_idDescription
TRUEnever evaluated
FALSEnever evaluated
se->key() == d->sc_sequenceDescription
TRUEnever evaluated
FALSEnever evaluated
0
643#ifndef QT_NO_WHATSTHIS-
644 if (QWhatsThis::inWhatsThisMode()) {
QWhatsThis::inWhatsThisMode()Description
TRUEnever evaluated
FALSEnever evaluated
0
645 QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis);-
646 handled = true;-
647 } else
never executed: end of block
0
648#endif-
649 if (se->isAmbiguous())
se->isAmbiguous()Description
TRUEnever evaluated
FALSEnever evaluated
0
650 emit activatedAmbiguously();
never executed: activatedAmbiguously();
0
651 else-
652 emit activated();
never executed: activated();
0
653 handled = true;-
654 }
never executed: end of block
0
655 }
never executed: end of block
0
656 return handled;
never executed: return handled;
0
657}-
658#endif // QT_NO_SHORTCUT-
659-
660QT_END_NAMESPACE-
661-
662#include "moc_qshortcut.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9