aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-06-15 23:39:57 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-06-28 09:17:17 +0000
commit31074d7767949832475bc7c9c643f80d97050ac4 (patch)
tree3511d94941118cf1b686fd130610be83560d5310 /src/quicktemplates2
parent9d7ae28fcc683c185ee0f90728a21e0371e45e2d (diff)
Add internal QQuickPageLayout helper
Does the header/content/footer layout for Page, and will be shared with the upcoming Dialog. Change-Id: Ic550a87b5f4bb4eb44e2d08a4c977183f3b5bbff Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickpage.cpp130
-rw-r--r--src/quicktemplates2/qquickpagelayout.cpp188
-rw-r--r--src/quicktemplates2/qquickpagelayout_p_p.h86
-rw-r--r--src/quicktemplates2/quicktemplates2.pri2
4 files changed, 289 insertions, 117 deletions
diff --git a/src/quicktemplates2/qquickpage.cpp b/src/quicktemplates2/qquickpage.cpp
index 56a9f86e..9c0c22ec 100644
--- a/src/quicktemplates2/qquickpage.cpp
+++ b/src/quicktemplates2/qquickpage.cpp
@@ -36,11 +36,7 @@
#include "qquickpage_p.h"
#include "qquickcontrol_p_p.h"
-#include "qquicktoolbar_p.h"
-#include "qquicktabbar_p.h"
-#include "qquickdialogbuttonbox_p.h"
-
-#include <QtQuick/private/qquickitemchangelistener_p.h>
+#include "qquickpagelayout_p_p.h"
QT_BEGIN_NAMESPACE
@@ -86,81 +82,23 @@ QT_BEGIN_NAMESPACE
\sa ApplicationWindow, {Container Controls}
*/
-class QQuickPagePrivate : public QQuickControlPrivate, public QQuickItemChangeListener
+class QQuickPagePrivate : public QQuickControlPrivate
{
Q_DECLARE_PUBLIC(QQuickPage)
public:
- QQuickPagePrivate();
-
- void relayout();
-
- void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect) override;
- void itemVisibilityChanged(QQuickItem *item) override;
- void itemImplicitWidthChanged(QQuickItem *item) override;
- void itemImplicitHeightChanged(QQuickItem *item) override;
-
QString title;
- QQuickItem *header;
- QQuickItem *footer;
+ QScopedPointer<QQuickPageLayout> layout;
};
-QQuickPagePrivate::QQuickPagePrivate() : header(nullptr), footer(nullptr)
-{
-}
-
-void QQuickPagePrivate::relayout()
-{
- Q_Q(QQuickPage);
- QQuickItem *content = q->contentItem();
- const qreal hh = header ? header->height() : 0;
- const qreal fh = footer ? footer->height() : 0;
-
- content->setY(hh + q->topPadding());
- content->setX(q->leftPadding());
- content->setWidth(q->availableWidth());
- content->setHeight(q->availableHeight() - hh - fh);
-
- if (header)
- header->setWidth(q->width());
-
- if (footer) {
- footer->setY(q->height() - fh);
- footer->setWidth(q->width());
- }
-}
-
-void QQuickPagePrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect)
-{
- Q_UNUSED(item)
- Q_UNUSED(newRect)
- Q_UNUSED(oldRect)
- relayout();
-}
-
-void QQuickPagePrivate::itemVisibilityChanged(QQuickItem *item)
-{
- Q_UNUSED(item);
- relayout();
-}
-
-void QQuickPagePrivate::itemImplicitWidthChanged(QQuickItem *item)
-{
- Q_UNUSED(item);
- relayout();
-}
-
-void QQuickPagePrivate::itemImplicitHeightChanged(QQuickItem *item)
-{
- Q_UNUSED(item);
- relayout();
-}
QQuickPage::QQuickPage(QQuickItem *parent) :
QQuickControl(*(new QQuickPagePrivate), parent)
{
+ Q_D(QQuickPage);
setFlag(ItemIsFocusScope);
setAcceptedMouseButtons(Qt::AllButtons);
+ d->layout.reset(new QQuickPageLayout(this));
}
/*!
@@ -199,37 +137,16 @@ void QQuickPage::setTitle(const QString &title)
QQuickItem *QQuickPage::header() const
{
Q_D(const QQuickPage);
- return d->header;
+ return d->layout->header();
}
void QQuickPage::setHeader(QQuickItem *header)
{
Q_D(QQuickPage);
- if (d->header == header)
+ if (!d->layout->setHeader(header))
return;
-
- if (d->header) {
- QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::Geometry | QQuickItemPrivate::Visibility |
- 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::Geometry | QQuickItemPrivate::Visibility |
- 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);
- else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(header))
- buttonBox->setPosition(QQuickDialogButtonBox::Header);
- }
if (isComponentComplete())
- d->relayout();
+ d->layout->update();
emit headerChanged();
}
@@ -248,37 +165,16 @@ void QQuickPage::setHeader(QQuickItem *header)
QQuickItem *QQuickPage::footer() const
{
Q_D(const QQuickPage);
- return d->footer;
+ return d->layout->footer();
}
void QQuickPage::setFooter(QQuickItem *footer)
{
Q_D(QQuickPage);
- if (d->footer == footer)
+ if (!d->layout->setFooter(footer))
return;
-
- if (d->footer) {
- QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::Geometry | QQuickItemPrivate::Visibility |
- 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::Geometry | QQuickItemPrivate::Visibility |
- 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);
- else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(footer))
- buttonBox->setPosition(QQuickDialogButtonBox::Header);
- }
if (isComponentComplete())
- d->relayout();
+ d->layout->update();
emit footerChanged();
}
@@ -331,14 +227,14 @@ void QQuickPage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo
{
Q_D(QQuickPage);
QQuickControl::geometryChanged(newGeometry, oldGeometry);
- d->relayout();
+ d->layout->update();
}
void QQuickPage::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
{
Q_D(QQuickPage);
QQuickControl::paddingChange(newPadding, oldPadding);
- d->relayout();
+ d->layout->update();
}
#ifndef QT_NO_ACCESSIBILITY
diff --git a/src/quicktemplates2/qquickpagelayout.cpp b/src/quicktemplates2/qquickpagelayout.cpp
new file mode 100644
index 00000000..552cf3f7
--- /dev/null
+++ b/src/quicktemplates2/qquickpagelayout.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickpagelayout_p_p.h"
+#include "qquickcontrol_p.h"
+#include "qquicktoolbar_p.h"
+#include "qquicktabbar_p.h"
+#include "qquickdialogbuttonbox_p.h"
+
+#include <QtQuick/private/qquickitem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static const QQuickItemPrivate::ChangeTypes ItemChanges = QQuickItemPrivate::Geometry | QQuickItemPrivate::Visibility | QQuickItemPrivate::Destroyed
+ | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight;
+
+namespace {
+ enum Position {
+ Header,
+ Footer
+ };
+
+ Q_STATIC_ASSERT(int(Header) == int(QQuickTabBar::Header));
+ Q_STATIC_ASSERT(int(Footer) == int(QQuickTabBar::Footer));
+
+ Q_STATIC_ASSERT(int(Header) == int(QQuickToolBar::Header));
+ Q_STATIC_ASSERT(int(Footer) == int(QQuickToolBar::Footer));
+
+ Q_STATIC_ASSERT(int(Header) == int(QQuickDialogButtonBox::Header));
+ Q_STATIC_ASSERT(int(Footer) == int(QQuickDialogButtonBox::Footer));
+}
+
+static void setPosition(QQuickItem *item, Position position)
+{
+ if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(item))
+ toolBar->setPosition(static_cast<QQuickToolBar::Position>(position));
+ else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(item))
+ tabBar->setPosition(static_cast<QQuickTabBar::Position>(position));
+ else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(item))
+ buttonBox->setPosition(static_cast<QQuickDialogButtonBox::Position>(position));
+}
+
+QQuickPageLayout::QQuickPageLayout(QQuickControl *control)
+ : m_header(nullptr), m_footer(nullptr), m_control(control)
+{
+}
+
+QQuickPageLayout::~QQuickPageLayout()
+{
+ if (m_header)
+ QQuickItemPrivate::get(m_header)->removeItemChangeListener(this, ItemChanges);
+ if (m_footer)
+ QQuickItemPrivate::get(m_footer)->removeItemChangeListener(this, ItemChanges);
+}
+
+QQuickItem *QQuickPageLayout::header() const
+{
+ return m_header;
+}
+
+bool QQuickPageLayout::setHeader(QQuickItem *header)
+{
+ if (m_header == header)
+ return false;
+
+ if (m_header) {
+ QQuickItemPrivate::get(m_header)->removeItemChangeListener(this, ItemChanges);
+ m_header->setParentItem(nullptr);
+ }
+ m_header = header;
+ if (header) {
+ header->setParentItem(m_control);
+ QQuickItemPrivate::get(header)->addItemChangeListener(this, ItemChanges);
+ if (qFuzzyIsNull(header->z()))
+ header->setZ(1);
+ setPosition(header, Header);
+ }
+ return true;
+}
+
+QQuickItem *QQuickPageLayout::footer() const
+{
+ return m_footer;
+}
+
+bool QQuickPageLayout::setFooter(QQuickItem *footer)
+{
+ if (m_footer == footer)
+ return false;
+
+ if (m_footer) {
+ QQuickItemPrivate::get(m_footer)->removeItemChangeListener(this, ItemChanges);
+ m_footer->setParentItem(nullptr);
+ }
+ m_footer = footer;
+ if (footer) {
+ footer->setParentItem(m_control);
+ QQuickItemPrivate::get(footer)->addItemChangeListener(this, ItemChanges);
+ if (qFuzzyIsNull(footer->z()))
+ footer->setZ(1);
+ setPosition(footer, Footer);
+ }
+ return true;
+}
+
+void QQuickPageLayout::update()
+{
+ QQuickItem *content = m_control->contentItem();
+
+ const qreal hh = m_header ? m_header->height() : 0;
+ const qreal fh = m_footer ? m_footer->height() : 0;
+
+ content->setY(hh + m_control->topPadding());
+ content->setX(m_control->leftPadding());
+ content->setWidth(m_control->availableWidth());
+ content->setHeight(m_control->availableHeight() - hh - fh);
+
+ if (m_header)
+ m_header->setWidth(m_control->width());
+
+ if (m_footer) {
+ m_footer->setY(m_control->height() - fh);
+ m_footer->setWidth(m_control->width());
+ }
+}
+
+void QQuickPageLayout::itemVisibilityChanged(QQuickItem *)
+{
+ update();
+}
+
+void QQuickPageLayout::itemImplicitWidthChanged(QQuickItem *)
+{
+ update();
+}
+
+void QQuickPageLayout::itemImplicitHeightChanged(QQuickItem *)
+{
+ update();
+}
+
+void QQuickPageLayout::itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &)
+{
+ update();
+}
+
+void QQuickPageLayout::itemDestroyed(QQuickItem *item)
+{
+ if (item == m_header)
+ m_header = nullptr;
+ else if (item == m_footer)
+ m_footer = nullptr;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quicktemplates2/qquickpagelayout_p_p.h b/src/quicktemplates2/qquickpagelayout_p_p.h
new file mode 100644
index 00000000..baaf53e7
--- /dev/null
+++ b/src/quicktemplates2/qquickpagelayout_p_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKPAGELAYOUT_P_P_H
+#define QQUICKPAGELAYOUT_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qquickitemchangelistener_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickControl;
+
+class QQuickPageLayout : public QQuickItemChangeListener
+{
+public:
+ explicit QQuickPageLayout(QQuickControl *control);
+ ~QQuickPageLayout();
+
+ QQuickItem *header() const;
+ bool setHeader(QQuickItem *header);
+
+ QQuickItem *footer() const;
+ bool setFooter(QQuickItem *footer);
+
+ void update();
+
+protected:
+ void itemVisibilityChanged(QQuickItem *item) override;
+ void itemImplicitWidthChanged(QQuickItem *item) override;
+ void itemImplicitHeightChanged(QQuickItem *item) override;
+ void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect) override;
+ void itemDestroyed(QQuickItem *item) override;
+
+private:
+ QQuickItem *m_header;
+ QQuickItem *m_footer;
+ QQuickControl *m_control;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKPAGELAYOUT_P_P_H
diff --git a/src/quicktemplates2/quicktemplates2.pri b/src/quicktemplates2/quicktemplates2.pri
index df036ed9..4f3f6af0 100644
--- a/src/quicktemplates2/quicktemplates2.pri
+++ b/src/quicktemplates2/quicktemplates2.pri
@@ -31,6 +31,7 @@ HEADERS += \
$$PWD/qquickoverlay_p.h \
$$PWD/qquickpage_p.h \
$$PWD/qquickpageindicator_p.h \
+ $$PWD/qquickpagelayout_p_p.h \
$$PWD/qquickpane_p.h \
$$PWD/qquickpane_p_p.h \
$$PWD/qquickpopup_p.h \
@@ -85,6 +86,7 @@ SOURCES += \
$$PWD/qquickoverlay.cpp \
$$PWD/qquickpage.cpp \
$$PWD/qquickpageindicator.cpp \
+ $$PWD/qquickpagelayout.cpp \
$$PWD/qquickpane.cpp \
$$PWD/qquickpopup.cpp \
$$PWD/qquickpresshandler.cpp \