Qt 6.x
The Qt SDK
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 "qquickmenu_p.h"
8#include "qquickmenu_p_p.h"
9#include "qquickpopup_p.h"
10
11#include <QtCore/qloggingcategory.h>
12#include <QtGui/qguiapplication.h>
13#include <QtQuick/qquickrendercontrol.h>
14
16
17Q_LOGGING_CATEGORY(lcContextMatcher, "qt.quick.controls.shortcutcontext.matcher")
18
20{
21 if (!item || !item->window())
22 return false;
23
25 const auto popups = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups();
26 for (QQuickPopup *popup : popups) {
27 if (qobject_cast<QQuickToolTip *>(popup))
28 continue; // ignore tooltips (QTBUG-60492)
29 if (popup->isModal() || popup->closePolicy() & QQuickPopup::CloseOnEscape) {
30 qCDebug(lcContextMatcher) << popup << "is modal or has a CloseOnEscape policy;"
31 << "if the following are both true," << item << "will be blocked by it:"
32 << (item != popup->popupItem()) << !popup->popupItem()->isAncestorOf(item);
33 return item != popup->popupItem() && !popup->popupItem()->isAncestorOf(item);
34 }
35 }
36
37 return false;
38}
39
41{
42 QQuickItem *item = nullptr;
43 switch (context) {
45 return true;
47 while (obj && !obj->isWindowType()) {
49 if (item && item->window()) {
50 obj = item->window();
51 break;
52 } else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(obj)) {
53 obj = popup->window();
54 item = popup->popupItem();
55
56 if (!obj) {
57 // The popup has no associated window (yet). However, sub-menus,
58 // unlike top-level menus, will not have an associated window
59 // until their parent menu is opened. So, check if this is a sub-menu
60 // so that actions within it can grab shortcuts.
61 if (auto *menu = qobject_cast<QQuickMenu *>(popup)) {
62 auto parentMenu = QQuickMenuPrivate::get(menu)->parentMenu;
63 while (!obj && parentMenu)
64 obj = parentMenu->window();
65 }
66 }
67 break;
68 }
69 obj = obj->parent();
70 }
71 if (QWindow *renderWindow = QQuickRenderControl::renderWindowFor(qobject_cast<QQuickWindow *>(obj)))
72 obj = renderWindow;
73 qCDebug(lcContextMatcher) << "obj" << obj << "item" << item << "focusWindow" << QGuiApplication::focusWindow()
74 << "!isBlockedByPopup(item)" << !isBlockedByPopup(item);
76 default:
77 return false;
78 }
79}
80
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:90
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QPointer< QQuickMenu > parentMenu
static QQuickMenuPrivate * get(QQuickMenu *menu)
QList< QQuickPopup * > stackingOrderPopups() const
A window overlay for popups.
static QQuickOverlayPrivate * get(QQuickOverlay *overlay)
static QQuickOverlay * overlay(QQuickWindow *window)
QQuickItem * parent
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:483
static QT_BEGIN_NAMESPACE bool isBlockedByPopup(QQuickItem *item)
QGraphicsItem * item
QMenu menu
[5]
static bool matcher(QObject *object, Qt::ShortcutContext context)