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

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