Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickshortcutcontext.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qquickoverlay_p_p.h"
6#include "qquicktooltip_p.h"
7#include <QtQmlModels/private/qtqmlmodels-config_p.h>
8#if QT_CONFIG(qml_object_model)
9#include "qquickmenu_p.h"
10#include "qquickmenu_p_p.h"
11#endif
12#include "qquickpopup_p.h"
13
14#include <QtCore/qloggingcategory.h>
15#include <QtGui/qguiapplication.h>
16#include <QtQuick/qquickrendercontrol.h>
17
19
20Q_LOGGING_CATEGORY(lcContextMatcher, "qt.quick.controls.shortcutcontext.matcher")
21
23{
24 if (!item || !item->window())
25 return false;
26
28 const auto popups = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups();
29 for (QQuickPopup *popup : popups) {
30 if (qobject_cast<QQuickToolTip *>(popup))
31 continue; // ignore tooltips (QTBUG-60492)
32 if (popup->isModal() || popup->closePolicy() & QQuickPopup::CloseOnEscape) {
33 qCDebug(lcContextMatcher) << popup << "is modal or has a CloseOnEscape policy;"
34 << "if the following are both true," << item << "will be blocked by it:"
35 << (item != popup->popupItem()) << !popup->popupItem()->isAncestorOf(item);
36 return item != popup->popupItem() && !popup->popupItem()->isAncestorOf(item);
37 }
38 }
39
40 return false;
41}
42
44{
45 QQuickItem *item = nullptr;
46 switch (context) {
48 return true;
50 while (obj && !obj->isWindowType()) {
52 if (item && item->window()) {
53 obj = item->window();
54 break;
55 } else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(obj)) {
56 obj = popup->window();
57 item = popup->popupItem();
58
59#if QT_CONFIG(qml_object_model)
60 if (!obj) {
61 // The popup has no associated window (yet). However, sub-menus,
62 // unlike top-level menus, will not have an associated window
63 // until their parent menu is opened. So, check if this is a sub-menu
64 // so that actions within it can grab shortcuts.
65 if (auto *menu = qobject_cast<QQuickMenu *>(popup)) {
66 auto parentMenu = QQuickMenuPrivate::get(menu)->parentMenu;
67 while (!obj && parentMenu)
68 obj = parentMenu->window();
69 }
70 }
71#endif
72 break;
73 }
74 obj = obj->parent();
75 }
76 if (QWindow *renderWindow = QQuickRenderControl::renderWindowFor(qobject_cast<QQuickWindow *>(obj)))
77 obj = renderWindow;
78 qCDebug(lcContextMatcher) << "obj" << obj << "item" << item << "focusWindow" << QGuiApplication::focusWindow()
79 << "!isBlockedByPopup(item)" << !isBlockedByPopup(item);
80 return obj && qobject_cast<QWindow*>(obj)->isActive() && !isBlockedByPopup(item);
81 default:
82 return false;
83 }
84}
85
QGraphicsWidget * window() const
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child's parent,...
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
\inmodule QtCore
Definition qobject.h:103
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
static QQuickMenuPrivate * get(QQuickMenu *menu)
static QQuickOverlayPrivate * get(QQuickOverlay *overlay)
static QQuickOverlay * overlay(QQuickWindow *window)
static QWindow * renderWindowFor(QQuickWindow *win, QPoint *offset=nullptr)
Returns the real window that win is being rendered to, if any.
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
ShortcutContext
@ WindowShortcut
@ ApplicationShortcut
static void * context
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLhandleARB obj
[2]
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
static QT_BEGIN_NAMESPACE bool isBlockedByPopup(QQuickItem *item)
QWindow * qobject_cast< QWindow * >(QObject *o)
Definition qwindow.h:367
QGraphicsItem * item
QMenu menu
[5]
static bool matcher(QObject *object, Qt::ShortcutContext context)