aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickapplicationwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates/qquickapplicationwindow.cpp')
-rw-r--r--src/quicktemplates/qquickapplicationwindow.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/quicktemplates/qquickapplicationwindow.cpp b/src/quicktemplates/qquickapplicationwindow.cpp
index 582b5dd31a..56e4b5c217 100644
--- a/src/quicktemplates/qquickapplicationwindow.cpp
+++ b/src/quicktemplates/qquickapplicationwindow.cpp
@@ -8,8 +8,11 @@
#include "qquicktextarea_p.h"
#include "qquicktextfield_p.h"
#include "qquicktoolbar_p.h"
+#include <private/qtquicktemplates2-config_p.h>
+#if QT_CONFIG(quicktemplates2_container)
#include "qquicktabbar_p.h"
#include "qquickdialogbuttonbox_p.h"
+#endif
#include "qquickdeferredexecute_p_p.h"
#include "qquickdeferredpointer_p_p.h"
@@ -87,18 +90,13 @@ QT_BEGIN_NAMESPACE
static const QQuickItemPrivate::ChangeTypes ItemChanges = QQuickItemPrivate::Visibility
| QQuickItemPrivate::Geometry | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight;
-class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickApplicationWindowPrivate
+class Q_QUICKTEMPLATES2_EXPORT QQuickApplicationWindowPrivate
: public QQuickWindowQmlImplPrivate
, public QQuickItemChangeListener
{
Q_DECLARE_PUBLIC(QQuickApplicationWindow)
public:
- QQuickApplicationWindowPrivate()
- {
- complete = true;
- }
-
static QQuickApplicationWindowPrivate *get(QQuickApplicationWindow *window)
{
return window->d_func();
@@ -112,6 +110,7 @@ public:
void itemVisibilityChanged(QQuickItem *item) override;
void itemImplicitWidthChanged(QQuickItem *item) override;
void itemImplicitHeightChanged(QQuickItem *item) override;
+ QPalette windowPalette() const override { return defaultPalette(); }
void updateFont(const QFont &f);
inline void setFont_helper(const QFont &f) {
@@ -149,6 +148,8 @@ public:
QLocale locale;
QQuickItem *activeFocusControl = nullptr;
bool insideRelayout = false;
+ bool hasBackgroundWidth = false;
+ bool hasBackgroundHeight = false;
};
static void layoutItem(QQuickItem *item, qreal y, qreal width)
@@ -167,7 +168,7 @@ static void layoutItem(QQuickItem *item, qreal y, qreal width)
void QQuickApplicationWindowPrivate::relayout()
{
Q_Q(QQuickApplicationWindow);
- if (!complete || insideRelayout)
+ if (!componentComplete || insideRelayout)
return;
QScopedValueRollback<bool> guard(insideRelayout, true);
@@ -185,23 +186,25 @@ void QQuickApplicationWindowPrivate::relayout()
layoutItem(footer, content->height(), q->width());
if (background) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(background);
- if (!p->widthValid() && qFuzzyIsNull(background->x())) {
+ if (!hasBackgroundWidth && qFuzzyIsNull(background->x()))
background->setWidth(q->width());
- p->widthValidFlag = false;
- }
- if (!p->heightValid() && qFuzzyIsNull(background->y())) {
+ if (!hasBackgroundHeight && qFuzzyIsNull(background->y()))
background->setHeight(q->height());
- p->heightValidFlag = false;
- }
}
}
void QQuickApplicationWindowPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff)
{
- Q_UNUSED(item);
- Q_UNUSED(change);
Q_UNUSED(diff);
+
+ if (!insideRelayout && item == background && change.sizeChange()) {
+ // Any time the background is resized (excluding our own resizing),
+ // we should respect it if it's explicit by storing the values of the flags.
+ QQuickItemPrivate *backgroundPrivate = QQuickItemPrivate::get(background);
+ hasBackgroundWidth = backgroundPrivate->widthValid();
+ hasBackgroundHeight = backgroundPrivate->heightValid();
+ }
+
relayout();
}
@@ -280,8 +283,6 @@ void QQuickApplicationWindowPrivate::contentData_append(QQmlListProperty<QObject
QQuickPopupPrivate::get(popup)->setWindow(static_cast<QQuickApplicationWindow *>(prop->data));
}
-static inline QString backgroundName() { return QStringLiteral("background"); }
-
void QQuickApplicationWindowPrivate::cancelBackground()
{
Q_Q(QQuickApplicationWindow);
@@ -359,12 +360,24 @@ void QQuickApplicationWindow::setBackground(QQuickItem *background)
if (!d->background.isExecuting())
d->cancelBackground();
+ if (d->background) {
+ d->hasBackgroundWidth = false;
+ d->hasBackgroundHeight = false;
+ }
QQuickControlPrivate::hideOldItem(d->background);
+
d->background = background;
+
if (background) {
background->setParentItem(QQuickWindow::contentItem());
+
if (qFuzzyIsNull(background->z()))
background->setZ(-1);
+
+ QQuickItemPrivate *backgroundPrivate = QQuickItemPrivate::get(background);
+ d->hasBackgroundWidth = backgroundPrivate->widthValid();
+ d->hasBackgroundHeight = backgroundPrivate->heightValid();
+
if (isComponentComplete())
d->relayout();
}
@@ -418,10 +431,12 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header)
header->setZ(1);
if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header))
toolBar->setPosition(QQuickToolBar::Header);
+#if QT_CONFIG(quicktemplates2_container)
else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header))
tabBar->setPosition(QQuickTabBar::Header);
else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(header))
buttonBox->setPosition(QQuickDialogButtonBox::Header);
+#endif
}
if (isComponentComplete())
d->relayout();
@@ -473,10 +488,12 @@ void QQuickApplicationWindow::setFooter(QQuickItem *footer)
footer->setZ(1);
if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer))
toolBar->setPosition(QQuickToolBar::Footer);
+#if QT_CONFIG(quicktemplates2_container)
else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer))
tabBar->setPosition(QQuickTabBar::Footer);
else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(footer))
buttonBox->setPosition(QQuickDialogButtonBox::Footer);
+#endif
}
if (isComponentComplete())
d->relayout();
@@ -685,13 +702,13 @@ void QQuickApplicationWindow::setMenuBar(QQuickItem *menuBar)
bool QQuickApplicationWindow::isComponentComplete() const
{
Q_D(const QQuickApplicationWindow);
- return d->complete;
+ return d->componentComplete;
}
void QQuickApplicationWindow::classBegin()
{
Q_D(QQuickApplicationWindow);
- d->complete = false;
+ d->componentComplete = false;
QQuickWindowQmlImpl::classBegin();
d->resolveFont();
}
@@ -699,7 +716,7 @@ void QQuickApplicationWindow::classBegin()
void QQuickApplicationWindow::componentComplete()
{
Q_D(QQuickApplicationWindow);
- d->complete = true;
+ d->componentComplete = true;
d->executeBackground(true);
QQuickWindowQmlImpl::componentComplete();
d->relayout();