| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window); | - |
| 6 | | - |
| 7 | static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window); | - |
| 8 | | - |
| 9 | | - |
| 10 | static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window); | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context) | - |
| 19 | { | - |
| 20 | ((!(object)) ? qt_assert_x("QShortcutMap", "Shortcut has no owner. Illegal map state!",__FILE__,7379) : qt_noop()); | - |
| 21 | | - |
| 22 | QWidget *active_window = QApplication::activeWindow(); | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | if (QApplication::activePopupWidget()) | - |
| 28 | active_window = QApplication::activePopupWidget(); | - |
| 29 | | - |
| 30 | if (!active_window) { | - |
| 31 | QWindow *qwindow = QGuiApplication::focusWindow(); | - |
| 32 | if (qwindow && qwindow->isActive()) { | - |
| 33 | while (qwindow) { | - |
| 34 | QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(qwindow); | - |
| 35 | if (widgetWindow) { | - |
| 36 | active_window = widgetWindow->widget(); | - |
| 37 | break; | - |
| 38 | } | - |
| 39 | qwindow = qwindow->parent(); | - |
| 40 | } | - |
| 41 | } | - |
| 42 | } | - |
| 43 | | - |
| 44 | if (!active_window) | - |
| 45 | return false; | - |
| 46 | | - |
| 47 | | - |
| 48 | if (QAction *a = qobject_cast<QAction *>(object)) | - |
| 49 | return correctActionContext(context, a, active_window); | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | if (QGraphicsWidget *gw = qobject_cast<QGraphicsWidget *>(object)) | - |
| 54 | return correctGraphicsWidgetContext(context, gw, active_window); | - |
| 55 | | - |
| 56 | | - |
| 57 | QWidget *w = qobject_cast<QWidget *>(object); | - |
| 58 | if (!w) { | - |
| 59 | QShortcut *s = qobject_cast<QShortcut *>(object); | - |
| 60 | if (s) | - |
| 61 | w = s->parentWidget(); | - |
| 62 | } | - |
| 63 | | - |
| 64 | if (!w) { | - |
| 65 | QWindow *qwindow = qobject_cast<QWindow *>(object); | - |
| 66 | while (qwindow) { | - |
| 67 | QWidgetWindow *widget_window = qobject_cast<QWidgetWindow *>(qwindow); | - |
| 68 | if (widget_window) { | - |
| 69 | w = widget_window->widget(); | - |
| 70 | break; | - |
| 71 | } | - |
| 72 | qwindow = qwindow->parent(); | - |
| 73 | } | - |
| 74 | } | - |
| 75 | | - |
| 76 | if (!w) | - |
| 77 | return false; | - |
| 78 | | - |
| 79 | return correctWidgetContext(context, w, active_window); | - |
| 80 | } | - |
| 81 | | - |
| 82 | static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window) | - |
| 83 | { | - |
| 84 | bool visible = w->isVisible(); | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | if (!visible || !w->isEnabled()) | - |
| 91 | return false; | - |
| 92 | | - |
| 93 | if (context == Qt::ApplicationShortcut) | - |
| 94 | return QApplicationPrivate::tryModalHelper(w, 0); | - |
| 95 | | - |
| 96 | if (context == Qt::WidgetShortcut) | - |
| 97 | return w == QApplication::focusWidget(); | - |
| 98 | | - |
| 99 | if (context == Qt::WidgetWithChildrenShortcut) { | - |
| 100 | const QWidget *tw = QApplication::focusWidget(); | - |
| 101 | while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup || tw->windowType() == Qt::SubWindow)) | - |
| 102 | tw = tw->parentWidget(); | - |
| 103 | return tw == w; | - |
| 104 | } | - |
| 105 | | - |
| 106 | | - |
| 107 | QWidget *tlw = w->window(); | - |
| 108 | | - |
| 109 | if (QWExtra *topData = static_cast<QWidgetPrivate *>(QObjectPrivate::get(tlw))->extra) { | - |
| 110 | if (topData->proxyWidget) { | - |
| 111 | bool res = correctGraphicsWidgetContext(context, (QGraphicsWidget *)topData->proxyWidget, active_window); | - |
| 112 | return res; | - |
| 113 | } | - |
| 114 | } | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | if (active_window != tlw && active_window && active_window->windowType() == Qt::Tool && active_window->parentWidget()) { | - |
| 120 | active_window = active_window->parentWidget()->window(); | - |
| 121 | } | - |
| 122 | | - |
| 123 | if (active_window != tlw) | - |
| 124 | return false; | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | const QWidget* sw = w; | - |
| 129 | while (sw && !(sw->windowType() == Qt::SubWindow) && !sw->isWindow()) | - |
| 130 | sw = sw->parentWidget(); | - |
| 131 | if (sw && (sw->windowType() == Qt::SubWindow)) { | - |
| 132 | QWidget *focus_widget = QApplication::focusWidget(); | - |
| 133 | while (focus_widget && focus_widget != sw) | - |
| 134 | focus_widget = focus_widget->parentWidget(); | - |
| 135 | return sw == focus_widget; | - |
| 136 | } | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | | - |
| 141 | return true; | - |
| 142 | } | - |
| 143 | | - |
| 144 | | - |
| 145 | static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window) | - |
| 146 | { | - |
| 147 | bool visible = w->isVisible(); | - |
| 148 | | - |
| 149 | | - |
| 150 | | - |
| 151 | | - |
| 152 | | - |
| 153 | if (!visible || !w->isEnabled() || !w->scene()) | - |
| 154 | return false; | - |
| 155 | | - |
| 156 | if (context == Qt::ApplicationShortcut) { | - |
| 157 | | - |
| 158 | | - |
| 159 | | - |
| 160 | QList<QGraphicsView *> views = w->scene()->views(); | - |
| 161 | for (int i = 0; i < views.size(); ++i) { | - |
| 162 | if (QApplicationPrivate::tryModalHelper(views.at(i), 0)) | - |
| 163 | return true; | - |
| 164 | } | - |
| 165 | return false; | - |
| 166 | } | - |
| 167 | | - |
| 168 | if (context == Qt::WidgetShortcut) | - |
| 169 | return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem(); | - |
| 170 | | - |
| 171 | if (context == Qt::WidgetWithChildrenShortcut) { | - |
| 172 | const QGraphicsItem *ti = w->scene()->focusItem(); | - |
| 173 | if (ti && ti->isWidget()) { | - |
| 174 | const QGraphicsWidget *tw = static_cast<const QGraphicsWidget *>(ti); | - |
| 175 | while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup)) | - |
| 176 | tw = tw->parentWidget(); | - |
| 177 | return tw == w; | - |
| 178 | } | - |
| 179 | return false; | - |
| 180 | } | - |
| 181 | | - |
| 182 | | - |
| 183 | | - |
| 184 | | - |
| 185 | QList<QGraphicsView *> views = w->scene()->views(); | - |
| 186 | QGraphicsView *activeView = 0; | - |
| 187 | for (int i = 0; i < views.size(); ++i) { | - |
| 188 | QGraphicsView *view = views.at(i); | - |
| 189 | if (view->window() == active_window) { | - |
| 190 | activeView = view; | - |
| 191 | break; | - |
| 192 | } | - |
| 193 | } | - |
| 194 | if (!activeView) | - |
| 195 | return false; | - |
| 196 | | - |
| 197 | | - |
| 198 | | - |
| 199 | QGraphicsWidget *a = w->scene()->activeWindow(); | - |
| 200 | return !w->window() || a == w->window(); | - |
| 201 | } | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window) | - |
| 206 | { | - |
| 207 | const QList<QWidget *> &widgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->widgets; | - |
| 208 | | - |
| 209 | | - |
| 210 | | - |
| 211 | | - |
| 212 | for (int i = 0; i < widgets.size(); ++i) { | - |
| 213 | QWidget *w = widgets.at(i); | - |
| 214 | | - |
| 215 | if (QMenu *menu = qobject_cast<QMenu *>(w)) { | - |
| 216 | QAction *a = menu->menuAction(); | - |
| 217 | if (correctActionContext(context, a, active_window)) | - |
| 218 | return true; | - |
| 219 | } else | - |
| 220 | | - |
| 221 | if (correctWidgetContext(context, w, active_window)) | - |
| 222 | return true; | - |
| 223 | } | - |
| 224 | | - |
| 225 | | - |
| 226 | const QList<QGraphicsWidget *> &graphicsWidgets = static_cast<QActionPrivate *>(QObjectPrivate::get(a))->graphicsWidgets; | - |
| 227 | | - |
| 228 | | - |
| 229 | | - |
| 230 | | - |
| 231 | for (int i = 0; i < graphicsWidgets.size(); ++i) { | - |
| 232 | QGraphicsWidget *w = graphicsWidgets.at(i); | - |
| 233 | if (correctGraphicsWidgetContext(context, w, active_window)) | - |
| 234 | return true; | - |
| 235 | } | - |
| 236 | | - |
| 237 | return false; | - |
| 238 | } | - |
| 239 | class QShortcutPrivate : public QObjectPrivate | - |
| 240 | { | - |
| 241 | inline QShortcut* q_func() { return static_cast<QShortcut *>(q_ptr); } inline const QShortcut* q_func() const { return static_cast<const QShortcut *>(q_ptr); } friend class QShortcut; | - |
| 242 | public: | - |
| 243 | QShortcutPrivate() : sc_context(Qt::WindowShortcut), sc_enabled(true), sc_autorepeat(true), sc_id(0) {} | - |
| 244 | QKeySequence sc_sequence; | - |
| 245 | Qt::ShortcutContext sc_context; | - |
| 246 | bool sc_enabled; | - |
| 247 | bool sc_autorepeat; | - |
| 248 | int sc_id; | - |
| 249 | QString sc_whatsthis; | - |
| 250 | void redoGrab(QShortcutMap &map); | - |
| 251 | }; | - |
| 252 | | - |
| 253 | void QShortcutPrivate::redoGrab(QShortcutMap &map) | - |
| 254 | { | - |
| 255 | QShortcut * const q = q_func(); | - |
| 256 | if (!(__builtin_expect(!!(!| TRUE | never evaluated | | FALSE | never evaluated |
parent)), false)| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 257 | QMessageLogger(__FILE__, 414420, __PRETTY_FUNCTION__).warning("QShortcut: No widget parent defined"); | - |
| 258 | return; never executed: return; | 0 |
| 259 | } | - |
| 260 | | - |
| 261 | if (sc_id| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 262 | map.removeShortcut(sc_id, q); never executed: map.removeShortcut(sc_id, q); | 0 |
| 263 | if (sc_sequence.isEmpty()| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 264 | return; never executed: return; | 0 |
| 265 | sc_id = map.addShortcut(q, sc_sequence, sc_context, qWidgetShortcutContextMatcher); | - |
| 266 | if (!sc_enabled| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 267 | map.setShortcutEnabled(false, sc_id, q); never executed: map.setShortcutEnabled(false, sc_id, q); | 0 |
| 268 | if (!sc_autorepeat| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 269 | map.setShortcutAutoRepeat(false, sc_id, q); never executed: map.setShortcutAutoRepeat(false, sc_id, q); | 0 |
| 270 | } never executed: end of block | 0 |
| 271 | QShortcut::QShortcut(QWidget *parent) | - |
| 272 | : QObject(*new QShortcutPrivate, parent) | - |
| 273 | { | - |
| 274 | ((!(parent != 0)) ? qt_assert("parent != 0",__FILE__,439445) : qt_noop()); | - |
| 275 | } | - |
| 276 | QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, | - |
| 277 | const char *member, const char *ambiguousMember, | - |
| 278 | Qt::ShortcutContext context) | - |
| 279 | : QObject(*new QShortcutPrivate, parent) | - |
| 280 | { | - |
| 281 | if (!((__builtin_expect(!!(!(static_cast<QApplication *>(QCoreApplication::instance())))()))), false)) { QMessageLogger(__FILE__, 455461, __PRETTY_FUNCTION__).warning("QShortcut: Initialize QApplication before calling '" "QShortcut" "'."); return; }; | - |
| 282 | | - |
| 283 | QShortcutPrivate * const d = d_func(); | - |
| 284 | ((!(parent != 0)) ? qt_assert("parent != 0",__FILE__,458464) : qt_noop()); | - |
| 285 | d->sc_context = context; | - |
| 286 | d->sc_sequence = key; | - |
| 287 | d->redoGrab((static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap); | - |
| 288 | if (member) | - |
| 289 | connect(this, qFlagLocation("2""activated()" "\0" __FILE__ ":" "463""469"), parent, member); | - |
| 290 | if (ambiguousMember) | - |
| 291 | connect(this, qFlagLocation("2""activatedAmbiguously()" "\0" __FILE__ ":" "465""471"), parent, ambiguousMember); | - |
| 292 | } | - |
| 293 | | - |
| 294 | | - |
| 295 | | - |
| 296 | | - |
| 297 | QShortcut::~QShortcut() | - |
| 298 | { | - |
| 299 | QShortcutPrivate * const d = d_func(); | - |
| 300 | if ((static_cast<QApplication *>(QCoreApplication::instance()))) | - |
| 301 | (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.removeShortcut(d->sc_id, this); | - |
| 302 | } | - |
| 303 | void QShortcut::setKey(const QKeySequence &key) | - |
| 304 | { | - |
| 305 | QShortcutPrivate * const d = d_func(); | - |
| 306 | if (d->sc_sequence == key) | - |
| 307 | return; | - |
| 308 | if (!((__builtin_expect(!!(!(static_cast<QApplication *>(QCoreApplication::instance())))()))), false)) { QMessageLogger(__FILE__, 494500, __PRETTY_FUNCTION__).warning("QShortcut: Initialize QApplication before calling '" "setKey" "'."); return; }; | - |
| 309 | d->sc_sequence = key; | - |
| 310 | d->redoGrab((static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap); | - |
| 311 | } | - |
| 312 | | - |
| 313 | QKeySequence QShortcut::key() const | - |
| 314 | { | - |
| 315 | const QShortcutPrivate * const d = d_func(); | - |
| 316 | return d->sc_sequence; | - |
| 317 | } | - |
| 318 | void QShortcut::setEnabled(bool enable) | - |
| 319 | { | - |
| 320 | QShortcutPrivate * const d = d_func(); | - |
| 321 | if (d->sc_enabled == enable) | - |
| 322 | return; | - |
| 323 | if (!((__builtin_expect(!!(!(static_cast<QApplication *>(QCoreApplication::instance())))()))), false)) { QMessageLogger(__FILE__, 525531, __PRETTY_FUNCTION__).warning("QShortcut: Initialize QApplication before calling '" "setEnabled" "'."); return; }; | - |
| 324 | d->sc_enabled = enable; | - |
| 325 | (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this); | - |
| 326 | } | - |
| 327 | | - |
| 328 | bool QShortcut::isEnabled() const | - |
| 329 | { | - |
| 330 | const QShortcutPrivate * const d = d_func(); | - |
| 331 | return d->sc_enabled; | - |
| 332 | } | - |
| 333 | void QShortcut::setContext(Qt::ShortcutContext context) | - |
| 334 | { | - |
| 335 | QShortcutPrivate * const d = d_func(); | - |
| 336 | if(d->sc_context == context) | - |
| 337 | return; | - |
| 338 | if (!((__builtin_expect(!!(!(static_cast<QApplication *>(QCoreApplication::instance())))()))), false)) { QMessageLogger(__FILE__, 553559, __PRETTY_FUNCTION__).warning("QShortcut: Initialize QApplication before calling '" "setContext" "'."); return; }; | - |
| 339 | d->sc_context = context; | - |
| 340 | d->redoGrab((static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap); | - |
| 341 | } | - |
| 342 | | - |
| 343 | Qt::ShortcutContext QShortcut::context() const | - |
| 344 | { | - |
| 345 | const QShortcutPrivate * const d = d_func(); | - |
| 346 | return d->sc_context; | - |
| 347 | } | - |
| 348 | void QShortcut::setWhatsThis(const QString &text) | - |
| 349 | { | - |
| 350 | QShortcutPrivate * const d = d_func(); | - |
| 351 | d->sc_whatsthis = text; | - |
| 352 | } | - |
| 353 | | - |
| 354 | QString QShortcut::whatsThis() const | - |
| 355 | { | - |
| 356 | const QShortcutPrivate * const d = d_func(); | - |
| 357 | return d->sc_whatsthis; | - |
| 358 | } | - |
| 359 | void QShortcut::setAutoRepeat(bool on) | - |
| 360 | { | - |
| 361 | QShortcutPrivate * const d = d_func(); | - |
| 362 | if (d->sc_autorepeat == on) | - |
| 363 | return; | - |
| 364 | if (!((__builtin_expect(!!(!(static_cast<QApplication *>(QCoreApplication::instance())))()))), false)) { QMessageLogger(__FILE__, 605611, __PRETTY_FUNCTION__).warning("QShortcut: Initialize QApplication before calling '" "setAutoRepeat" "'."); return; }; | - |
| 365 | d->sc_autorepeat = on; | - |
| 366 | (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this); | - |
| 367 | } | - |
| 368 | | - |
| 369 | bool QShortcut::autoRepeat() const | - |
| 370 | { | - |
| 371 | const QShortcutPrivate * const d = d_func(); | - |
| 372 | return d->sc_autorepeat; | - |
| 373 | } | - |
| 374 | | - |
| 375 | | - |
| 376 | | - |
| 377 | | - |
| 378 | | - |
| 379 | | - |
| 380 | int QShortcut::id() const | - |
| 381 | { | - |
| 382 | const QShortcutPrivate * const d = d_func(); | - |
| 383 | return d->sc_id; | - |
| 384 | } | - |
| 385 | | - |
| 386 | | - |
| 387 | | - |
| 388 | | - |
| 389 | bool QShortcut::event(QEvent *e) | - |
| 390 | { | - |
| 391 | QShortcutPrivate * const d = d_func(); | - |
| 392 | bool handled = false; | - |
| 393 | if (d->sc_enabled && e->type() == QEvent::Shortcut) { | - |
| 394 | QShortcutEvent *se = static_cast<QShortcutEvent *>(e); | - |
| 395 | if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){ | - |
| 396 | | - |
| 397 | if (QWhatsThis::inWhatsThisMode()) { | - |
| 398 | QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); | - |
| 399 | handled = true; | - |
| 400 | } else | - |
| 401 | | - |
| 402 | if (se->isAmbiguous()) | - |
| 403 | activatedAmbiguously(); | - |
| 404 | else | - |
| 405 | activated(); | - |
| 406 | handled = true; | - |
| 407 | } | - |
| 408 | } | - |
| 409 | return handled; | - |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| | |