aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickapplicationwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/templates/qquickapplicationwindow.cpp')
-rw-r--r--src/templates/qquickapplicationwindow.cpp158
1 files changed, 113 insertions, 45 deletions
diff --git a/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp
index 9a9e5460..f0a009ff 100644
--- a/src/templates/qquickapplicationwindow.cpp
+++ b/src/templates/qquickapplicationwindow.cpp
@@ -39,6 +39,8 @@
#include "qquickcontrol_p_p.h"
#include "qquicktextarea_p.h"
#include "qquicktextfield_p.h"
+#include "qquicktoolbar_p.h"
+#include "qquicktabbar_p.h"
#include <QtCore/private/qobject_p.h>
#include <QtQuick/private/qquickitem_p.h>
@@ -97,17 +99,18 @@ class QQuickApplicationWindowPrivate : public QQuickItemChangeListener
public:
QQuickApplicationWindowPrivate()
: complete(false)
- , contentItem(Q_NULLPTR)
- , header(Q_NULLPTR)
- , footer(Q_NULLPTR)
- , overlay(Q_NULLPTR)
- , activeFocusControl(Q_NULLPTR)
+ , background(nullptr)
+ , contentItem(nullptr)
+ , header(nullptr)
+ , footer(nullptr)
+ , overlay(nullptr)
+ , activeFocusControl(nullptr)
{ }
void relayout();
- void itemImplicitWidthChanged(QQuickItem *item) Q_DECL_OVERRIDE;
- void itemImplicitHeightChanged(QQuickItem *item) Q_DECL_OVERRIDE;
+ void itemImplicitWidthChanged(QQuickItem *item) override;
+ void itemImplicitHeightChanged(QQuickItem *item) override;
void updateFont(const QFont &);
inline void setFont_helper(const QFont &f) {
@@ -121,6 +124,7 @@ public:
void setActiveFocusControl(QQuickItem *item);
bool complete;
+ QQuickItem *background;
QQuickItem *contentItem;
QQuickItem *header;
QQuickItem *footer;
@@ -165,6 +169,18 @@ void QQuickApplicationWindowPrivate::relayout()
p->widthValid = false;
}
}
+
+ if (background) {
+ QQuickItemPrivate *p = QQuickItemPrivate::get(background);
+ if (!p->widthValid && qFuzzyIsNull(background->x())) {
+ background->setWidth(q->width());
+ p->widthValid = false;
+ }
+ if (!p->heightValid && qFuzzyIsNull(background->y())) {
+ background->setHeight(q->height());
+ p->heightValid = false;
+ }
+ }
}
void QQuickApplicationWindowPrivate::itemImplicitWidthChanged(QQuickItem *item)
@@ -229,11 +245,50 @@ QQuickApplicationWindow::~QQuickApplicationWindow()
}
/*!
+ \qmlproperty Item Qt.labs.controls::ApplicationWindow::background
+
+ This property holds the background item.
+
+ The background item is stacked under the \l {contentItem}{content item},
+ but above the \l {Window::color}{background color} of the window.
+
+ \note If the background item has no explicit size specified, it automatically
+ follows the control's size. In most cases, there is no need to specify
+ width or height for a background item.
+*/
+QQuickItem *QQuickApplicationWindow::background() const
+{
+ Q_D(const QQuickApplicationWindow);
+ return d->background;
+}
+
+void QQuickApplicationWindow::setBackground(QQuickItem *background)
+{
+ Q_D(QQuickApplicationWindow);
+ if (d->background == background)
+ return;
+
+ delete d->background;
+ d->background = background;
+ if (background) {
+ background->setParentItem(QQuickWindow::contentItem());
+ if (qFuzzyIsNull(background->z()))
+ background->setZ(-1);
+ if (isComponentComplete())
+ d->relayout();
+ }
+ emit backgroundChanged();
+}
+
+/*!
\qmlproperty Item Qt.labs.controls::ApplicationWindow::header
This property holds the window header item. The header item is positioned to
the top, and resized to the width of the window. The default value is \c null.
+ \note Assigning a ToolBar or TabBar as a window header sets the respective
+ \l ToolBar::position or \l TabBar::position property automatically to \c Header.
+
\sa footer, Page::header
*/
QQuickItem *QQuickApplicationWindow::header() const
@@ -245,23 +300,28 @@ QQuickItem *QQuickApplicationWindow::header() const
void QQuickApplicationWindow::setHeader(QQuickItem *header)
{
Q_D(QQuickApplicationWindow);
- if (d->header != header) {
- if (d->header) {
- QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
- d->header->setParentItem(Q_NULLPTR);
- }
- d->header = header;
- if (header) {
- header->setParentItem(contentItem());
- QQuickItemPrivate *p = QQuickItemPrivate::get(header);
- p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
- if (qFuzzyIsNull(header->z()))
- header->setZ(1);
- if (isComponentComplete())
- d->relayout();
- }
- emit headerChanged();
+ if (d->header == header)
+ return;
+
+ if (d->header) {
+ QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+ d->header->setParentItem(nullptr);
+ }
+ d->header = header;
+ if (header) {
+ header->setParentItem(contentItem());
+ QQuickItemPrivate *p = QQuickItemPrivate::get(header);
+ p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+ if (qFuzzyIsNull(header->z()))
+ header->setZ(1);
+ if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(header))
+ toolBar->setPosition(QQuickToolBar::Header);
+ else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(header))
+ tabBar->setPosition(QQuickTabBar::Header);
+ if (isComponentComplete())
+ d->relayout();
}
+ emit headerChanged();
}
/*!
@@ -270,6 +330,9 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header)
This property holds the window footer item. The footer item is positioned to
the bottom, and resized to the width of the window. The default value is \c null.
+ \note Assigning a ToolBar or TabBar as a window footer sets the respective
+ \l ToolBar::position or \l TabBar::position property automatically to \c Footer.
+
\sa header, Page::footer
*/
QQuickItem *QQuickApplicationWindow::footer() const
@@ -281,23 +344,28 @@ QQuickItem *QQuickApplicationWindow::footer() const
void QQuickApplicationWindow::setFooter(QQuickItem *footer)
{
Q_D(QQuickApplicationWindow);
- if (d->footer != footer) {
- if (d->footer) {
- QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
- d->footer->setParentItem(Q_NULLPTR);
- }
- d->footer = footer;
- if (footer) {
- footer->setParentItem(contentItem());
- QQuickItemPrivate *p = QQuickItemPrivate::get(footer);
- p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
- if (qFuzzyIsNull(footer->z()))
- footer->setZ(1);
- if (isComponentComplete())
- d->relayout();
- }
- emit footerChanged();
+ if (d->footer == footer)
+ return;
+
+ if (d->footer) {
+ QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+ d->footer->setParentItem(nullptr);
+ }
+ d->footer = footer;
+ if (footer) {
+ footer->setParentItem(contentItem());
+ QQuickItemPrivate *p = QQuickItemPrivate::get(footer);
+ p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+ if (qFuzzyIsNull(footer->z()))
+ footer->setZ(1);
+ if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(footer))
+ toolBar->setPosition(QQuickToolBar::Footer);
+ else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(footer))
+ tabBar->setPosition(QQuickTabBar::Footer);
+ if (isComponentComplete())
+ d->relayout();
}
+ emit footerChanged();
}
/*!
@@ -483,7 +551,7 @@ class QQuickApplicationWindowAttachedPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QQuickApplicationWindowAttached)
public:
- QQuickApplicationWindowAttachedPrivate() : window(Q_NULLPTR) { }
+ QQuickApplicationWindowAttachedPrivate() : window(nullptr) { }
void windowChange(QQuickWindow *wnd);
@@ -561,7 +629,7 @@ QQuickApplicationWindow *QQuickApplicationWindowAttached::window() const
QQuickItem *QQuickApplicationWindowAttached::contentItem() const
{
Q_D(const QQuickApplicationWindowAttached);
- return d->window ? d->window->contentItem() : Q_NULLPTR;
+ return d->window ? d->window->contentItem() : nullptr;
}
/*!
@@ -578,7 +646,7 @@ QQuickItem *QQuickApplicationWindowAttached::contentItem() const
QQuickItem *QQuickApplicationWindowAttached::activeFocusControl() const
{
Q_D(const QQuickApplicationWindowAttached);
- return d->window ? d->window->activeFocusControl() : Q_NULLPTR;
+ return d->window ? d->window->activeFocusControl() : nullptr;
}
/*!
@@ -592,7 +660,7 @@ QQuickItem *QQuickApplicationWindowAttached::activeFocusControl() const
QQuickItem *QQuickApplicationWindowAttached::header() const
{
Q_D(const QQuickApplicationWindowAttached);
- return d->window ? d->window->header() : Q_NULLPTR;
+ return d->window ? d->window->header() : nullptr;
}
/*!
@@ -606,7 +674,7 @@ QQuickItem *QQuickApplicationWindowAttached::header() const
QQuickItem *QQuickApplicationWindowAttached::footer() const
{
Q_D(const QQuickApplicationWindowAttached);
- return d->window ? d->window->footer() : Q_NULLPTR;
+ return d->window ? d->window->footer() : nullptr;
}
/*!
@@ -619,7 +687,7 @@ QQuickItem *QQuickApplicationWindowAttached::footer() const
QQuickOverlay *QQuickApplicationWindowAttached::overlay() const
{
Q_D(const QQuickApplicationWindowAttached);
- return d->window ? d->window->overlay() : Q_NULLPTR;
+ return d->window ? d->window->overlay() : nullptr;
}
QT_END_NAMESPACE