Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickwindowmodule.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
7#include "qquickscreen_p.h"
8#include "qquickview_p.h"
10#include "qquickitem_p.h"
11#include <QtQuick/QQuickWindow>
12#include <QtCore/QCoreApplication>
13#include <QtQml/QQmlEngine>
14
15#include <private/qguiapplication_p.h>
16#include <private/qqmlengine_p.h>
17#include <private/qv4qobjectwrapper_p.h>
18#include <private/qqmlglobal_p.h>
19#include <qpa/qplatformintegration.h>
20
22
24
26
29{
30}
31
33{
35 d->visible = visible;
36 d->visibleExplicitlySet = true;
37 if (d->complete && (!transientParent() || transientParentVisible()))
39}
40
41void QQuickWindowQmlImpl::setVisibility(Visibility visibility)
42{
44 d->visibility = visibility;
45 if (d->complete)
46 QQuickWindow::setVisibility(visibility);
47}
48
50{
51 return new QQuickWindowAttached(object);
52}
53
55{
57 QQmlEngine* e = qmlEngine(this);
58
60
61 //Give QQuickView behavior when created from QML with QQmlApplicationEngine
62 if (QCoreApplication::instance()->property("__qml_using_qqmlapplicationengine") == QVariant(true)) {
63 if (e && !e->incubationController())
64 e->setIncubationController(incubationController());
65 }
66 {
67 // The content item has CppOwnership policy (set in QQuickWindow). Ensure the presence of a JS
68 // wrapper so that the garbage collector can see the policy.
69 QV4::ExecutionEngine *v4 = e->handle();
70 QV4::QObjectWrapper::wrap(v4, d->contentItem);
71 }
72}
73
75{
77 d->complete = true;
79 const bool transientParentAlreadySet = QQuickWindowPrivate::get(this)->transientParentPropertySet;
80 if (!transientParentAlreadySet && itemParent && !itemParent->window()) {
81 qCDebug(lcTransient) << "window" << title() << "has invisible Item parent" << itemParent << "transientParent"
82 << transientParent() << "declared visibility" << d->visibility << "; delaying show";
83 connect(itemParent, &QQuickItem::windowChanged, this,
84 &QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
85 } else if (transientParent() && !transientParent()->isVisible()) {
86 connect(transientParent(), &QQuickWindow::visibleChanged, this,
87 &QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
88 } else {
89 setWindowVisibility();
90 }
91}
92
94 : QQuickWindow(dd, parent)
95{
96 // These two signals are called during QWindow's dtor, thus they have to be queued connections
97 // or else our slots will be called instantly when our destructor has already run but our
98 // connections haven't been removed yet.
101 connect(this, &QWindow::visibilityChanged, this, &QQuickWindowQmlImpl::visibilityChanged,
103
105}
106
107void QQuickWindowQmlImpl::setWindowVisibility()
108{
110 if (transientParent() && !transientParentVisible())
111 return;
112
113 if (QQuickItem *senderItem = qmlobject_cast<QQuickItem *>(sender())) {
114 disconnect(senderItem, &QQuickItem::windowChanged, this, &QQuickWindowQmlImpl::setWindowVisibility);
115 } else if (sender()) {
116 disconnect(transientParent(), &QWindow::visibleChanged, this, &QQuickWindowQmlImpl::setWindowVisibility);
117 }
118
119 // We have deferred window creation until we have the full picture of what
120 // the user wanted in terms of window state, geometry, visibility, etc.
121
122 if (d->visibleExplicitlySet && ((d->visibility == Hidden && d->visible) ||
123 (d->visibility > AutomaticVisibility && !d->visible))) {
124 QQmlData *data = QQmlData::get(this);
125 Q_ASSERT(data && data->context);
126
128 error.setObject(this);
129
130 QQmlRefPointer<QQmlContextData> urlContext = data->context;
131 while (urlContext && urlContext->url().isEmpty())
132 urlContext = urlContext->parent();
133 error.setUrl(urlContext ? urlContext->url() : QUrl());
134
135 QString objectId = data->context->findObjectId(this);
136 if (!objectId.isEmpty())
137 error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
138 "Conflicting properties 'visible' and 'visibility' for Window '%1'").arg(objectId));
139 else
140 error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
141 "Conflicting properties 'visible' and 'visibility'"));
142
143 QQmlEnginePrivate::get(data->context->engine())->warning(error);
144 }
145
146 if (d->visibility == AutomaticVisibility) {
148 setVisible(d->visible);
149 } else {
150 setVisibility(d->visibility);
151 }
152}
153
155{
156 return new QQuickScreenInfo(const_cast<QQuickWindowQmlImpl *>(this), QWindow::screen());
157}
158
160{
161 QQuickScreenInfo *screenWrapper = qobject_cast<QQuickScreenInfo *>(screen);
162 QWindow::setScreen(screenWrapper ? screenWrapper->wrappedScreen() : nullptr);
163}
164
165bool QQuickWindowQmlImpl::transientParentVisible()
166{
167 Q_ASSERT(transientParent());
168 if (!transientParent()->isVisible()) {
169 // handle case where transient parent is offscreen window
170 QWindow *rw = QQuickRenderControl::renderWindowFor(qobject_cast<QQuickWindow*>(transientParent()));
171 return rw && rw->isVisible();
172 }
173 return true;
174}
175
177
178#include "moc_qquickwindowmodule_p.cpp"
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
static QPlatformIntegration * platformIntegration()
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2521
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
void warning(const QQmlError &)
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
static void setContextForObject(QObject *, QQmlContext *)
Sets the QQmlContext for the object to context.
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QQuickWindow * window() const
Returns the window in which this item is rendered.
static QWindow * renderWindowFor(QQuickWindow *win, QPoint *offset=nullptr)
Returns the real window that win is being rendered to, if any.
QScreen * wrappedScreen() const
static QQuickWindowPrivate * get(QQuickWindow *c)
QWindow::Visibility visibility
void visibleChanged(bool arg)
void classBegin() override
Invoked after class creation, but before any properties have been set.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setVisibility(QWindow::Visibility visibility)
void visibilityChanged(QWindow::Visibility visibility)
static QQuickWindowAttached * qmlAttachedProperties(QObject *object)
void setScreen(QObject *screen)
QQuickWindowQmlImpl(QWindow *parent=nullptr)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:64
bool transientParentPropertySet
Definition qwindow_p.h:136
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
void visibleChanged(bool arg)
QString title
the window's title in the windowing system
Definition qwindow.h:77
void screenChanged(QScreen *screen)
This signal is emitted when a window's screen changes, either by being set explicitly with setScreen(...
void setVisible(bool visible)
Definition qwindow.cpp:652
double e
Combined button and popup list for selecting options.
@ QueuedConnection
DBusConnection const char DBusError * error
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:76
QQuickItem * qmlobject_cast< QQuickItem * >(QObject *object)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int(*) void arg)
QScreen * screen
[1]
Definition main.cpp:29
const char property[13]
Definition qwizard.cpp:101
myObject disconnect()
[26]
edit isVisible()
w setWindowState(w->windowState() ^ Qt::WindowFullScreen)
[0]
static ReturnedValue wrap(ExecutionEngine *engine, QObject *object)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent