1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QWASMWINDOWTREENODE_INC
#define QWASMWINDOWTREENODE_INC
template<class Window>
QWasmWindowTreeNode<Window>::QWasmWindowTreeNode()
: m_childStack(std::bind(&QWasmWindowTreeNode<Window>::onTopWindowChanged, this))
{
}
template<class Window>
QWasmWindowTreeNode<Window>::~QWasmWindowTreeNode() = default;
template<class Window>
void QWasmWindowTreeNode<Window>::onParentChanged(QWasmWindowTreeNode *previousParent,
QWasmWindowTreeNode *currentParent,
typename QWasmWindowStack<Window>::PositionPreference positionPreference)
{
auto *window = asWasmWindow();
if (previousParent) {
previousParent->m_childStack.removeWindow(window);
previousParent->onSubtreeChanged(QWasmWindowTreeNodeChangeType::NodeRemoval, previousParent,
window);
}
if (currentParent) {
currentParent->m_childStack.pushWindow(window, positionPreference);
currentParent->onSubtreeChanged(QWasmWindowTreeNodeChangeType::NodeInsertion, currentParent,
window);
}
}
template<class Window>
Window *QWasmWindowTreeNode<Window>::asWasmWindow()
{
return nullptr;
}
template<class Window>
void QWasmWindowTreeNode<Window>::onSubtreeChanged(QWasmWindowTreeNodeChangeType changeType,
QWasmWindowTreeNode *parent, Window *child)
{
if (changeType == QWasmWindowTreeNodeChangeType::NodeInsertion && parent == this
&& m_childStack.topWindow()
&& m_childStack.topWindow()->window()) {
const auto flags = m_childStack.topWindow()->window()->flags();
const bool notToolOrPopup = ((flags & Qt::ToolTip) != Qt::ToolTip) && ((flags & Qt::Popup) != Qt::Popup);
const QVariant showWithoutActivating = m_childStack.topWindow()->window()->property("_q_showWithoutActivating");
if (!showWithoutActivating.isValid() || !showWithoutActivating.toBool()) {
if (notToolOrPopup)
m_childStack.topWindow()->requestActivateWindow();
}
}
if (parentNode())
parentNode()->onSubtreeChanged(changeType, parent, child);
}
template<class Window>
void QWasmWindowTreeNode<Window>::setWindowZOrder(Window *window, int z)
{
window->setZOrder(z);
}
template<class Window>
void QWasmWindowTreeNode<Window>::onPositionPreferenceChanged(
typename QWasmWindowStack<Window>::PositionPreference positionPreference)
{
if (parentNode()) {
parentNode()->m_childStack.windowPositionPreferenceChanged(asWasmWindow(),
positionPreference);
}
}
template<class Window>
void QWasmWindowTreeNode<Window>::setAsActiveNode()
{
if (parentNode())
parentNode()->setActiveChildNode(asWasmWindow());
// At the end, this is a recursive function
m_activeIndex = ++s_nextActiveIndex;
}
template<class Window>
void QWasmWindowTreeNode<Window>::bringToTop()
{
if (!parentNode())
return;
parentNode()->m_childStack.raise(asWasmWindow());
parentNode()->bringToTop();
}
template<class Window>
void QWasmWindowTreeNode<Window>::sendToBottom()
{
if (!parentNode())
return;
m_childStack.lower(asWasmWindow());
}
template<class Window>
void QWasmWindowTreeNode<Window>::onTopWindowChanged()
{
constexpr int zOrderForElementInFrontOfScreen = 3;
int z = zOrderForElementInFrontOfScreen;
std::for_each(m_childStack.rbegin(), m_childStack.rend(),
[this, &z](Window *window) { setWindowZOrder(window, z++); });
}
template<class Window>
void QWasmWindowTreeNode<Window>::setActiveChildNode(Window *activeChild)
{
m_activeChild = activeChild;
auto it = m_childStack.begin();
if (it == m_childStack.end())
return;
for (; it != m_childStack.end(); ++it)
(*it)->onActivationChanged(*it == m_activeChild);
setAsActiveNode();
}
#endif /* QWASMWINDOWTREENODE_INC */
|