| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qquickwindow.h" |
| 41 | #include "qquickitem.h" |
| 42 | #include "qquickwindowattached_p.h" |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | // QDoc comments must go in qquickwindow.cpp to avoid overwriting the Window docs |
| 47 | |
| 48 | QQuickWindowAttached::QQuickWindowAttached(QObject* attachee) |
| 49 | : QObject(attachee) |
| 50 | , m_window(nullptr) |
| 51 | { |
| 52 | m_attachee = qobject_cast<QQuickItem*>(object: attachee); |
| 53 | if (m_attachee && m_attachee->window()) // It might not be in a window yet |
| 54 | windowChange(m_attachee->window()); |
| 55 | if (m_attachee) |
| 56 | connect(sender: m_attachee, signal: &QQuickItem::windowChanged, receiver: this, slot: &QQuickWindowAttached::windowChange); |
| 57 | } |
| 58 | |
| 59 | QWindow::Visibility QQuickWindowAttached::visibility() const |
| 60 | { |
| 61 | return (m_window ? m_window->visibility() : QWindow::Hidden); |
| 62 | } |
| 63 | |
| 64 | bool QQuickWindowAttached::isActive() const |
| 65 | { |
| 66 | return (m_window ? m_window->isActive() : false); |
| 67 | } |
| 68 | |
| 69 | QQuickItem *QQuickWindowAttached::activeFocusItem() const |
| 70 | { |
| 71 | return (m_window ? m_window->activeFocusItem() : nullptr); |
| 72 | } |
| 73 | |
| 74 | QQuickItem *QQuickWindowAttached::contentItem() const |
| 75 | { |
| 76 | return (m_window ? m_window->contentItem() : nullptr); |
| 77 | } |
| 78 | |
| 79 | int QQuickWindowAttached::width() const |
| 80 | { |
| 81 | return (m_window ? m_window->width() : 0); |
| 82 | } |
| 83 | |
| 84 | int QQuickWindowAttached::height() const |
| 85 | { |
| 86 | return (m_window ? m_window->height() : 0); |
| 87 | } |
| 88 | |
| 89 | QQuickWindow *QQuickWindowAttached::window() const |
| 90 | { |
| 91 | return m_window; |
| 92 | } |
| 93 | |
| 94 | void QQuickWindowAttached::windowChange(QQuickWindow *window) |
| 95 | { |
| 96 | if (window != m_window) { |
| 97 | QQuickWindow* oldWindow = m_window; |
| 98 | m_window = window; |
| 99 | |
| 100 | if (oldWindow) |
| 101 | oldWindow->disconnect(receiver: this); |
| 102 | |
| 103 | emit windowChanged(); |
| 104 | |
| 105 | if (!oldWindow || !window || window->visibility() != oldWindow->visibility()) |
| 106 | emit visibilityChanged(); |
| 107 | if (!oldWindow || !window || window->isActive() != oldWindow->isActive()) |
| 108 | emit activeChanged(); |
| 109 | if (!oldWindow || !window || window->activeFocusItem() != oldWindow->activeFocusItem()) |
| 110 | emit activeFocusItemChanged(); |
| 111 | emit contentItemChanged(); |
| 112 | if (!oldWindow || !window || window->width() != oldWindow->width()) |
| 113 | emit widthChanged(); |
| 114 | if (!oldWindow || !window || window->height() != oldWindow->height()) |
| 115 | emit heightChanged(); |
| 116 | |
| 117 | if (!window) |
| 118 | return; |
| 119 | |
| 120 | // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even |
| 121 | // be QQuickWindowQmlImpl, but that's not what we are connecting to. |
| 122 | // So this is actual window state rather than a buffered or as-requested one. |
| 123 | // If we used the metaobject connect syntax there would be a warning: |
| 124 | // QMetaObjectPrivate::indexOfSignalRelative - QMetaObject::indexOfSignal: |
| 125 | // signal visibilityChanged(QWindow::Visibility) from QQuickWindow redefined in QQuickWindowQmlImpl |
| 126 | connect(sender: window, signal: &QQuickWindow::visibilityChanged, |
| 127 | receiver: this, slot: &QQuickWindowAttached::visibilityChanged); |
| 128 | connect(sender: window, signal: &QQuickWindow::activeChanged, |
| 129 | receiver: this, slot: &QQuickWindowAttached::activeChanged); |
| 130 | connect(sender: window, signal: &QQuickWindow::activeFocusItemChanged, |
| 131 | receiver: this, slot: &QQuickWindowAttached::activeFocusItemChanged); |
| 132 | connect(sender: window, signal: &QQuickWindow::widthChanged, |
| 133 | receiver: this, slot: &QQuickWindowAttached::widthChanged); |
| 134 | connect(sender: window, signal: &QQuickWindow::heightChanged, |
| 135 | receiver: this, slot: &QQuickWindowAttached::heightChanged); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | QT_END_NAMESPACE |
| 140 | |
| 141 | #include "moc_qquickwindowattached_p.cpp" |
| 142 | |