Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickfluentwinui3focusframe.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 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
// Qt-Security score:significant reason:default
4
5
#
include
"qquickfluentwinui3focusframe_p.h"
6
7
#
include
<
private
/
qquickitem_p
.
h
>
8
9
#
include
<
QtCore
/
qmetaobject
.
h
>
10
11
#
include
<
QtGui
/
qguiapplication
.
h
>
12
13
#
include
<
QtQml
/
qqmlengine
.
h
>
14
#
include
<
QtQml
/
qqmlcontext
.
h
>
15
#
include
<
QtQml
/
qqmlcomponent
.
h
>
16
17
18
QT_BEGIN_NAMESPACE
19
20
QScopedPointer<QQuickItem> QQuickFluentWinUI3FocusFrame::m_focusFrame;
21
22
QQuickFluentWinUI3FocusFrame::QQuickFluentWinUI3FocusFrame()
23
{
24
connect(qGuiApp, &QGuiApplication::focusObjectChanged,
this
, [
this
](QObject *focusObject){
25
if
(QQuickControl *control = qobject_cast<QQuickControl *>(focusObject);
26
control && (control->focusReason() == Qt::FocusReason::TabFocusReason
27
|| control->focusReason() == Qt::FocusReason::BacktabFocusReason)) {
28
moveToItem(control);
29
}
else
{
30
moveToItem(
nullptr
);
31
}
32
});
33
}
34
35
QQuickItem *QQuickFluentWinUI3FocusFrame::createFocusFrame(QQmlContext *context)
36
{
37
QQmlComponent component(context->engine(),
"QtQuick.Controls.FluentWinUI3.impl"
,
"FocusFrame"
);
38
auto
frame = qobject_cast<QQuickItem *>(component.create());
39
if
(!frame)
40
return
nullptr
;
41
return
frame;
42
}
43
44
void
QQuickFluentWinUI3FocusFrame::moveToItem(QQuickControl *item)
45
{
46
if
(!m_focusFrame) {
47
const
auto
context = QQmlEngine::contextForObject(item);
48
// In certain cases like QQuickWebEngineView, the item
49
// gets focus even though it has no QQmlEngine associated with its context.
50
// We need the engine for creating the focus frame component.
51
if
(!context || !context->engine())
52
return
;
53
m_focusFrame.reset(createFocusFrame(context));
54
if
(!m_focusFrame) {
55
qWarning() <<
"Failed to create FocusFrame"
;
56
return
;
57
}
58
QQuickItemPrivate::get(m_focusFrame.get())->setTransparentForPositioner(
true
);
59
}
60
61
const
auto
target = getFocusTarget(item);
62
QMetaObject::invokeMethod(m_focusFrame.data(),
"moveToItem"
,
63
Q_ARG(QVariant, QVariant::fromValue(target)));
64
}
65
66
QQuickControl *QQuickFluentWinUI3FocusFrame::getFocusTarget(QQuickControl *focusItem)
const
67
{
68
if
(!focusItem)
69
return
nullptr
;
70
71
const
auto
parentItem = focusItem->parentItem();
72
if
(!parentItem)
73
return
nullptr
;
74
75
// The control that gets active focus can be a child of the control (e.g
76
// editable ComboBox). In that case, resolve the actual control first.
77
const
auto
proxy = focusItem->property(
"__focusFrameControl"
).value<QQuickControl *>();
78
const
auto
control = proxy ? proxy : focusItem;
79
auto
target = control->property(
"__focusFrameTarget"
).value<QQuickControl *>();
80
81
return
target;
82
}
83
84
QT_END_NAMESPACE
85
86
#
include
"moc_qquickfluentwinui3focusframe_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickcontrols
fluentwinui3
impl
qquickfluentwinui3focusframe.cpp
Generated on
for Qt by
1.18.0