kernel/qshortcut.cpp

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

Generated by Squish Coco Non-Commercial