diff options
Diffstat (limited to 'src/templates/qquickpage.cpp')
-rw-r--r-- | src/templates/qquickpage.cpp | 94 |
1 files changed, 56 insertions, 38 deletions
diff --git a/src/templates/qquickpage.cpp b/src/templates/qquickpage.cpp index 6a65e7c4..a4225028 100644 --- a/src/templates/qquickpage.cpp +++ b/src/templates/qquickpage.cpp @@ -36,6 +36,8 @@ #include "qquickpage_p.h" #include "qquickcontrol_p_p.h" +#include "qquicktoolbar_p.h" +#include "qquicktabbar_p.h" #include <QtQuick/private/qquickitemchangelistener_p.h> @@ -47,7 +49,7 @@ QT_BEGIN_NAMESPACE \instantiates QQuickPage \inqmlmodule Qt.labs.controls \ingroup qtlabscontrols-containers - \brief A page control. + \brief A control that makes it convenient to add a header and footer to a page. Page is a container control which makes it convenient to add a \l header and \l footer item to a page. @@ -91,14 +93,14 @@ public: 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; QQuickItem *header; QQuickItem *footer; }; -QQuickPagePrivate::QQuickPagePrivate() : header(Q_NULLPTR), footer(Q_NULLPTR) +QQuickPagePrivate::QQuickPagePrivate() : header(nullptr), footer(nullptr) { } @@ -148,6 +150,9 @@ QQuickPage::QQuickPage(QQuickItem *parent) : This property holds the page header item. The header item is positioned to the top, and resized to the width of the page. The default value is \c null. + \note Assigning a ToolBar or TabBar as a page header sets the respective + \l ToolBar::position or \l TabBar::position property automatically to \c Header. + \sa footer, ApplicationWindow::header */ QQuickItem *QQuickPage::header() const @@ -159,23 +164,28 @@ QQuickItem *QQuickPage::header() const void QQuickPage::setHeader(QQuickItem *header) { Q_D(QQuickPage); - 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(this); - 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(this); + 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(); } /*! @@ -184,6 +194,9 @@ void QQuickPage::setHeader(QQuickItem *header) This property holds the page footer item. The footer item is positioned to the bottom, and resized to the width of the page. The default value is \c null. + \note Assigning a ToolBar or TabBar as a page footer sets the respective + \l ToolBar::position or \l TabBar::position property automatically to \c Footer. + \sa header, ApplicationWindow::footer */ QQuickItem *QQuickPage::footer() const @@ -195,23 +208,28 @@ QQuickItem *QQuickPage::footer() const void QQuickPage::setFooter(QQuickItem *footer) { Q_D(QQuickPage); - 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(this); - 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(this); + 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(); } /*! @@ -225,7 +243,7 @@ void QQuickPage::setFooter(QQuickItem *footer) QQmlListProperty<QObject> QQuickPage::contentData() { Q_D(QQuickPage); - return QQmlListProperty<QObject>(d->contentItem, Q_NULLPTR, + return QQmlListProperty<QObject>(d->contentItem, nullptr, QQuickItemPrivate::data_append, QQuickItemPrivate::data_count, QQuickItemPrivate::data_at, @@ -242,7 +260,7 @@ QQmlListProperty<QObject> QQuickPage::contentData() QQmlListProperty<QQuickItem> QQuickPage::contentChildren() { Q_D(QQuickPage); - return QQmlListProperty<QQuickItem>(d->contentItem, Q_NULLPTR, + return QQmlListProperty<QQuickItem>(d->contentItem, nullptr, QQuickItemPrivate::children_append, QQuickItemPrivate::children_count, QQuickItemPrivate::children_at, |