11#include <QtQuick/QQuickWindow>
12#include <QtCore/QCoreApplication>
13#include <QtQml/QQmlEngine>
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>
38 connect(
this, &QWindow::visibilityChanged,
this, [&]{
44 d->visibilityExplicitlySet =
false;
67 qCDebug(lcQuickWindow) <<
"Class begin for" <<
this;
68 d->componentComplete =
false;
90 qCDebug(lcQuickWindow) <<
"Component completed for" <<
this;
91 d->componentComplete =
true;
97 updateTransientParent();
98 d->receiveParentEvents =
true;
100 applyWindowVisibility();
104 connect(
this, &QWindow::transientParentChanged,
105 this, &QQuickWindowQmlImpl::applyWindowVisibility);
112 d->visibleExplicitlySet =
true;
113 if (
d->componentComplete)
114 applyWindowVisibility();
121 d->visibilityExplicitlySet =
true;
122 if (
d->componentComplete)
123 applyWindowVisibility();
131 qCDebug(lcQuickWindow) <<
"Parent of" <<
this <<
"changed to" <<
parent();
132 if (
d->visualParent) {
135 applyWindowVisibility();
138 updateTransientParent();
149void QQuickWindowQmlImpl::updateTransientParent()
156 if (!
d->componentComplete)
161 if (
d->transientParentPropertySet)
169 qCDebug(lcTransient) <<
"Applying transient parent magic to"
170 <<
this <<
"based on object parent" << objectParent <<
"🪄";
172 QWindow *transientParent =
nullptr;
173 if (
auto *windowParent = qmlobject_cast<QWindow *>(objectParent)) {
174 transientParent = windowParent;
175 }
else if (
auto *itemParent = qmlobject_cast<QQuickItem *>(objectParent)) {
176 if (!
d->itemParentWindowChangeListener) {
177 d->itemParentWindowChangeListener =
connect(
178 itemParent, &QQuickItem::windowChanged,
179 this, &QQuickWindowQmlImpl::updateTransientParent);
181 transientParent = itemParent->window();
184 if (!transientParent) {
185 qCDebug(lcTransient) <<
"No transient parent resolved from object parent";
189 qCDebug(lcTransient) <<
"Setting" << transientParent <<
"as transient parent of" <<
this;
190 setTransientParent(transientParent);
193 d->transientParentPropertySet =
false;
196void QQuickWindowQmlImpl::applyWindowVisibility()
202 const bool visible =
d->visibilityExplicitlySet
203 ?
d->visibility != Hidden :
d->visible;
205 qCDebug(lcQuickWindow) <<
"Applying visible" <<
visible <<
"for" <<
this;
208 if (
d->visualParent) {
214 qCDebug(lcQuickWindow) <<
"Waiting for visual parent to reparent us into a window";
221 if (!
d->transientParentPropertySet && itemParent && !itemParent->window()) {
222 qCDebug(lcTransient) <<
"Waiting for parent" << itemParent <<
"to resolve"
223 <<
"its window. Deferring visibility";
227 const QWindow *transientParent = QWindow::transientParent();
228 if (transientParent && !transientParentVisible()) {
231 qCDebug(lcTransient) <<
"Transient parent" << transientParent
232 <<
"not visible yet. Deferring visibility";
239 &QQuickWindowQmlImpl::applyWindowVisibility,
246 if (
d->visibleExplicitlySet &&
d->visibilityExplicitlySet &&
247 ((
d->visibility == Hidden &&
d->visible) ||
248 (
d->visibility > AutomaticVisibility && !
d->visible))) {
250 qmlWarning(
this) <<
"Conflicting properties 'visible' and 'visibility'";
253 if (
d->visibility == AutomaticVisibility) {
263 }
else if (
d->visibilityExplicitlySet) {
266 QQuickWindow::setVisibility(
d->visibility);
273bool QQuickWindowQmlImpl::transientParentVisible()
279 return rw && rw->isVisible();
320 if (
d->visualParent) {
322 d->visualParent->disconnect(
this);
327 if (
d->componentComplete)
330 emit visualParentChanged(
d->visualParent);
333void QQuickWindowQmlImpl::applyVisualParent()
338 qCDebug(lcQuickWindow) <<
"Applying" <<
this <<
"visual parent" <<
d->visualParent;
340 if (!
d->visualParent) {
341 if (
d->windowContainer) {
342 d->windowContainer->setContainedWindow(
nullptr);
343 delete std::exchange(
d->windowContainer,
nullptr);
350 if ((parentItem = qobject_cast<QQuickItem*>(
d->visualParent)))
352 else if (
auto *parentWindow = qobject_cast<QWindow*>(
d->visualParent)) {
353 if (
auto *parentQuickWindow = qobject_cast<QQuickWindow*>(parentWindow)) {
354 parentItem = parentQuickWindow->contentItem();
356 qmlWarning(
this) <<
"Parenting into non-Quick window. "
357 <<
"Stacking, position, and destruction must be handled manually";
364 qmlWarning(
this) <<
"Unsupported visual parent type"
365 <<
d->visualParent->metaObject()->className();
369 if (!parentItem->
window()) {
370 qCDebug(lcQuickWindow) <<
"No window yet. Deferring.";
371 connect(parentItem, &QQuickItem::windowChanged,
this, [
this]{
372 qCDebug(lcQuickWindow) <<
"Got window. Applying deferred visual parent item.";
378 if (qobject_cast<QQuickWindowContainer*>(
d->visualParent)) {
379 qCDebug(lcQuickWindow) <<
"Visual parent is window container, everything is in order";
383 if (!
d->windowContainer) {
386 d->windowContainer->setObjectName(
objectName() +
"Container"_L1);
389 if (objectParent == parentItem) {
399 auto windowIndex = objectChildren.indexOf(
this);
400 auto containerIndex = objectChildren.indexOf(
d->windowContainer);
401 objectChildren.move(containerIndex, windowIndex);
402 containerIndex = windowIndex;
408 for (
int i = containerIndex + 1;
i < objectChildren.size(); ++
i) {
409 if (
auto *childItem = qobject_cast<QQuickItem*>(objectChildren.at(
i))) {
410 qCDebug(lcQuickWindow) <<
"Stacking" <<
d->windowContainer
411 <<
"below" << childItem;
412 d->windowContainer->stackBefore(childItem);
419 qCDebug(lcQuickWindow) <<
"Visual parent is not object parent."
420 <<
"Can not reflect document order as stacking order.";
425 d->windowContainer->classBegin();
426 d->windowContainer->setContainedWindow(
this);
431 d->windowContainer->setPosition(
position());
432 d->windowContainer->setZ(
d->z);
433 d->windowContainer->componentComplete();
436 this, &QQuickWindowQmlImpl::zChanged);
438 d->windowContainer->setParentItem(parentItem);
445 return d->visualParent;
460 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
461 d->windowContainer->setX(
x);
469 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
470 return d->windowContainer->x();
478 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
479 d->windowContainer->setY(
y);
487 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
488 return d->windowContainer->y();
513 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
514 d->windowContainer->setZ(
z);
522 if (
Q_UNLIKELY(
d->windowContainer &&
d->windowContainer->window()))
523 return d->windowContainer->z();
538 QWindow::setScreen(screenWrapper ? screenWrapper->wrappedScreen() :
nullptr);
548#include "moc_qquickwindowmodule_p.cpp"
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static QPlatformIntegration * platformIntegration()
QV4::ExecutionEngine * handle() const
static QObjectPrivate * get(QObject *o)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QString objectName
the name of this object
void setParent(QObject *parent)
Makes the object a child of parent.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QQmlEngine class provides an environment for instantiating QML components.
QQmlIncubationController * incubationController() const
Returns the currently set incubation controller, or 0 if no controller has been set.
static void setContextForObject(QObject *, QQmlContext *)
Sets the QQmlContext for the object to context.
void setIncubationController(QQmlIncubationController *)
Sets the engine's incubation controller.
QQmlContext * rootContext() const
Returns the engine's root context.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
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.
QQuickWindowQmlImplPrivate()
bool event(QEvent *) override
\reimp
void setVisible(bool visible)
QWindow::Visibility visibility
void visibleChanged(bool arg)
void setVisualParent(QObject *parent)
\qmlproperty var QtQuick::Window::parent
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)
void setZ(qreal arg)
\qmlproperty real QtQuick::Window::z \preliminary
QObject * visualParent() const
QQuickWindowQmlImpl(QWindow *parent=nullptr)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
bool event(QEvent *) override
\reimp
int x
the x position of the window's geometry
Qt::WindowFlags flags
the window flags of the window
void visibleChanged(bool arg)
int y
the y position of the window's geometry
Visibility visibility
the screen-occupation state of the window
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)
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
QQmlEngine * qmlEngine(const QObject *obj)
QQmlContext * qmlContext(const QObject *obj)
QQuickItem * qmlobject_cast< QQuickItem * >(QObject *object)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static void ensureWrapper(ExecutionEngine *engine, QObject *object)