Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickwindowattached.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qquickwindow.h"
6#include "qquickitem.h"
8
10
11// QDoc comments must go in qquickwindow.cpp to avoid overwriting the Window docs
12
13QQuickWindowAttached::QQuickWindowAttached(QObject* attachee)
14 : QObject(attachee)
15 , m_window(nullptr)
16{
17 m_attachee = qobject_cast<QQuickItem*>(attachee);
18 if (!m_attachee) {
19 qmlWarning(attachee)
20 << "Window.window does only support types deriving from Item";
21 return;
22 }
23 if (m_attachee->window()) // It might not be in a window yet
24 windowChange(m_attachee->window());
25 connect(m_attachee, &QQuickItem::windowChanged, this, &QQuickWindowAttached::windowChange);
26}
27
28QWindow::Visibility QQuickWindowAttached::visibility() const
29{
30 return (m_window ? m_window->visibility() : QWindow::Hidden);
31}
32
33bool QQuickWindowAttached::isActive() const
34{
35 return (m_window ? m_window->isActive() : false);
36}
37
38QQuickItem *QQuickWindowAttached::activeFocusItem() const
39{
40 return (m_window ? m_window->activeFocusItem() : nullptr);
41}
42
43QQuickItem *QQuickWindowAttached::contentItem() const
44{
45 return (m_window ? m_window->contentItem() : nullptr);
46}
47
48int QQuickWindowAttached::width() const
49{
50 return (m_window ? m_window->width() : 0);
51}
52
53int QQuickWindowAttached::height() const
54{
55 return (m_window ? m_window->height() : 0);
56}
57
58QQuickWindow *QQuickWindowAttached::window() const
59{
60 return m_window;
61}
62
63void QQuickWindowAttached::windowChange(QQuickWindow *window)
64{
65 if (window != m_window) {
66 QQuickWindow* oldWindow = m_window;
67 m_window = window;
68
69 if (oldWindow)
70 oldWindow->disconnect(this);
71
72 emit windowChanged();
73
74 if (!oldWindow || !window || window->visibility() != oldWindow->visibility())
75 emit visibilityChanged();
76 if (!oldWindow || !window || window->isActive() != oldWindow->isActive())
77 emit activeChanged();
78 if (!oldWindow || !window || window->activeFocusItem() != oldWindow->activeFocusItem())
79 emit activeFocusItemChanged();
80 emit contentItemChanged();
81 if (!oldWindow || !window || window->width() != oldWindow->width())
82 emit widthChanged();
83 if (!oldWindow || !window || window->height() != oldWindow->height())
84 emit heightChanged();
85
86 if (!window)
87 return;
88
89 // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even
90 // be QQuickWindowQmlImpl, but that's not what we are connecting to.
91 // So this is actual window state rather than a buffered or as-requested one.
92 // If we used the metaobject connect syntax there would be a warning:
93 // QMetaObjectPrivate::indexOfSignalRelative - QMetaObject::indexOfSignal:
94 // signal visibilityChanged(QWindow::Visibility) from QQuickWindow redefined in QQuickWindowQmlImpl
95 connect(window, &QQuickWindow::visibilityChanged,
96 this, &QQuickWindowAttached::visibilityChanged);
97 connect(window, &QQuickWindow::activeChanged,
98 this, &QQuickWindowAttached::activeChanged);
99 connect(window, &QQuickWindow::activeFocusItemChanged,
100 this, &QQuickWindowAttached::activeFocusItemChanged);
101 connect(window, &QQuickWindow::widthChanged,
102 this, &QQuickWindowAttached::widthChanged);
103 connect(window, &QQuickWindow::heightChanged,
104 this, &QQuickWindowAttached::heightChanged);
105 }
106}
107
108QT_END_NAMESPACE
109
110#include "moc_qquickwindowattached_p.cpp"