diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-03-09 14:37:24 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-03-09 15:57:07 +0000 |
commit | 2f4726883b17fe2c935ac2e5d1bfa9b2bca8b5e3 (patch) | |
tree | 7c8671b18f1ad739d6172bdc6ec10fc274efa036 | |
parent | 87dec648804bfa974a297c37542dd77de9f72e9f (diff) |
Inherit QQuickPage from QQuickPane
This allows us to remove a lot of duplicate code, and Page gets the
same automatic content size calculation that was added to Pane.
Change-Id: I98dc3a5070d61c1720dc11003bc4076aba481b3a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/controls/Page.qml | 3 | ||||
-rw-r--r-- | src/imports/controls/fusion/Page.qml | 3 | ||||
-rw-r--r-- | src/imports/controls/imagine/Page.qml | 3 | ||||
-rw-r--r-- | src/imports/controls/material/Page.qml | 3 | ||||
-rw-r--r-- | src/imports/controls/universal/Page.qml | 3 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpage.cpp | 148 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpage_p.h | 22 |
7 files changed, 11 insertions, 174 deletions
diff --git a/src/imports/controls/Page.qml b/src/imports/controls/Page.qml index b081dd5c..3950d702 100644 --- a/src/imports/controls/Page.qml +++ b/src/imports/controls/Page.qml @@ -51,9 +51,6 @@ T.Page { + (header && header.visible ? header.implicitHeight + spacing : 0) + (footer && footer.visible ? footer.implicitHeight + spacing : 0)) - contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) - contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) - background: Rectangle { color: control.palette.window } diff --git a/src/imports/controls/fusion/Page.qml b/src/imports/controls/fusion/Page.qml index d89426f6..cdc473e5 100644 --- a/src/imports/controls/fusion/Page.qml +++ b/src/imports/controls/fusion/Page.qml @@ -53,9 +53,6 @@ T.Page { + (header && header.visible ? header.implicitHeight + spacing : 0) + (footer && footer.visible ? footer.implicitHeight + spacing : 0)) - contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) - contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) - background: Rectangle { color: palette.window } diff --git a/src/imports/controls/imagine/Page.qml b/src/imports/controls/imagine/Page.qml index 06badf67..8dcd6dfc 100644 --- a/src/imports/controls/imagine/Page.qml +++ b/src/imports/controls/imagine/Page.qml @@ -51,9 +51,6 @@ T.Page { + (header && header.visible ? header.implicitHeight + spacing : 0) + (footer && footer.visible ? footer.implicitHeight + spacing : 0)) - contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) - contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) - topPadding: background ? background.topPadding : 0 leftPadding: background ? background.leftPadding : 0 rightPadding: background ? background.rightPadding : 0 diff --git a/src/imports/controls/material/Page.qml b/src/imports/controls/material/Page.qml index 44403828..71420ed1 100644 --- a/src/imports/controls/material/Page.qml +++ b/src/imports/controls/material/Page.qml @@ -50,9 +50,6 @@ T.Page { + (header && header.visible ? header.implicitHeight + spacing : 0) + (footer && footer.visible ? footer.implicitHeight + spacing : 0)) - contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) - contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) - background: Rectangle { color: control.Material.backgroundColor } diff --git a/src/imports/controls/universal/Page.qml b/src/imports/controls/universal/Page.qml index 957ae194..7eda011e 100644 --- a/src/imports/controls/universal/Page.qml +++ b/src/imports/controls/universal/Page.qml @@ -50,9 +50,6 @@ T.Page { + (header && header.visible ? header.implicitHeight + spacing : 0) + (footer && footer.visible ? footer.implicitHeight + spacing : 0)) - contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) - contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) - background: Rectangle { color: control.Universal.background } diff --git a/src/quicktemplates2/qquickpage.cpp b/src/quicktemplates2/qquickpage.cpp index 907b01e9..7f7cd5ad 100644 --- a/src/quicktemplates2/qquickpage.cpp +++ b/src/quicktemplates2/qquickpage.cpp @@ -35,14 +35,14 @@ ****************************************************************************/ #include "qquickpage_p.h" -#include "qquickcontrol_p_p.h" +#include "qquickpane_p_p.h" #include "qquickpagelayout_p_p.h" QT_BEGIN_NAMESPACE /*! \qmltype Page - \inherits Control + \inherits Pane \instantiates QQuickPage \inqmlmodule QtQuick.Controls \since 5.7 @@ -82,44 +82,19 @@ QT_BEGIN_NAMESPACE \sa ApplicationWindow, {Container Controls} */ -class QQuickPagePrivate : public QQuickControlPrivate +class QQuickPagePrivate : public QQuickPanePrivate { Q_DECLARE_PUBLIC(QQuickPage) public: - QQuickPagePrivate(); - - QQuickItem *getContentItem() override; - - qreal contentWidth; - qreal contentHeight; QString title; QScopedPointer<QQuickPageLayout> layout; }; -QQuickPagePrivate::QQuickPagePrivate() - : contentWidth(0), - contentHeight(0) -{ -} - -QQuickItem *QQuickPagePrivate::getContentItem() -{ - Q_Q(QQuickPage); - if (QQuickItem *item = QQuickControlPrivate::getContentItem()) - return item; - return new QQuickItem(q); -} - QQuickPage::QQuickPage(QQuickItem *parent) - : QQuickControl(*(new QQuickPagePrivate), parent) + : QQuickPane(*(new QQuickPagePrivate), parent) { Q_D(QQuickPage); - setFlag(ItemIsFocusScope); - setAcceptedMouseButtons(Qt::AllButtons); -#if QT_CONFIG(cursor) - setCursor(Qt::ArrowCursor); -#endif d->layout.reset(new QQuickPageLayout(this)); } @@ -232,136 +207,31 @@ void QQuickPage::setFooter(QQuickItem *footer) emit footerChanged(); } -/*! - \qmlproperty list<Object> QtQuick.Controls::Page::contentData - \default - - This property holds the list of content data. - - The list contains all objects that have been declared in QML as children - of the container. - - \note Unlike \c contentChildren, \c contentData does include non-visual QML - objects. - - \sa Item::data, contentChildren -*/ -QQmlListProperty<QObject> QQuickPage::contentData() -{ - return QQmlListProperty<QObject>(contentItem(), nullptr, - QQuickItemPrivate::data_append, - QQuickItemPrivate::data_count, - QQuickItemPrivate::data_at, - QQuickItemPrivate::data_clear); -} - -/*! - \qmlproperty list<Item> QtQuick.Controls::Page::contentChildren - - This property holds the list of content children. - - The list contains all items that have been declared in QML as children - of the page. - - \note Unlike \c contentData, \c contentChildren does not include non-visual - QML objects. - - \sa Item::children, contentData -*/ -QQmlListProperty<QQuickItem> QQuickPage::contentChildren() -{ - return QQmlListProperty<QQuickItem>(contentItem(), nullptr, - QQuickItemPrivate::children_append, - QQuickItemPrivate::children_count, - QQuickItemPrivate::children_at, - QQuickItemPrivate::children_clear); -} - -/*! - \qmlproperty real QtQuick.Controls::Page::contentWidth - \since QtQuick.Controls 2.1 (Qt 5.8) - - This property holds the content width. It is used for calculating the total - implicit width of the page. - - \sa contentHeight -*/ -qreal QQuickPage::contentWidth() const -{ - Q_D(const QQuickPage); - return d->contentWidth; -} - -void QQuickPage::setContentWidth(qreal width) -{ - Q_D(QQuickPage); - if (qFuzzyCompare(d->contentWidth, width)) - return; - - d->contentWidth = width; - emit contentWidthChanged(); -} - -/*! - \qmlproperty real QtQuick.Controls::Page::contentHeight - \since QtQuick.Controls 2.1 (Qt 5.8) - - This property holds the content height. It is used for calculating the total - implicit height of the page. - - \sa contentWidth -*/ -qreal QQuickPage::contentHeight() const -{ - Q_D(const QQuickPage); - return d->contentHeight; -} - -void QQuickPage::setContentHeight(qreal height) -{ - Q_D(QQuickPage); - if (qFuzzyCompare(d->contentHeight, height)) - return; - - d->contentHeight = height; - emit contentHeightChanged(); -} - void QQuickPage::componentComplete() { Q_D(QQuickPage); - QQuickControl::componentComplete(); + QQuickPane::componentComplete(); d->layout->update(); } -void QQuickPage::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -{ - QQuickControl::contentItemChange(newItem, oldItem); - if (oldItem) - disconnect(oldItem, &QQuickItem::childrenChanged, this, &QQuickPage::contentChildrenChanged); - if (newItem) - connect(newItem, &QQuickItem::childrenChanged, this, &QQuickPage::contentChildrenChanged); - emit contentChildrenChanged(); -} - void QQuickPage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickPage); - QQuickControl::geometryChanged(newGeometry, oldGeometry); + QQuickPane::geometryChanged(newGeometry, oldGeometry); d->layout->update(); } void QQuickPage::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickPage); - QQuickControl::paddingChange(newPadding, oldPadding); + QQuickPane::paddingChange(newPadding, oldPadding); d->layout->update(); } void QQuickPage::spacingChange(qreal newSpacing, qreal oldSpacing) { Q_D(QQuickPage); - QQuickControl::spacingChange(newSpacing, oldSpacing); + QQuickPane::spacingChange(newSpacing, oldSpacing); d->layout->update(); } @@ -374,7 +244,7 @@ QAccessible::Role QQuickPage::accessibleRole() const void QQuickPage::accessibilityActiveChanged(bool active) { Q_D(QQuickPage); - QQuickControl::accessibilityActiveChanged(active); + QQuickPane::accessibilityActiveChanged(active); if (active) setAccessibleName(d->title); diff --git a/src/quicktemplates2/qquickpage_p.h b/src/quicktemplates2/qquickpage_p.h index 0789e996..49f9f85f 100644 --- a/src/quicktemplates2/qquickpage_p.h +++ b/src/quicktemplates2/qquickpage_p.h @@ -48,25 +48,22 @@ // We mean it. // -#include <QtQuickTemplates2/private/qquickcontrol_p.h> +#include <QtQuickTemplates2/private/qquickpane_p.h> #include <QtQml/qqmllist.h> QT_BEGIN_NAMESPACE class QQuickPagePrivate; -class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPage : public QQuickControl +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPage : public QQuickPane { Q_OBJECT Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) - Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) - Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) // 2.1 (Qt 5.8) Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL REVISION 1) Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL REVISION 1) - Q_CLASSINFO("DefaultProperty", "contentData") public: explicit QQuickPage(QQuickItem *parent = nullptr); @@ -80,29 +77,14 @@ public: QQuickItem *footer() const; void setFooter(QQuickItem *footer); - QQmlListProperty<QObject> contentData(); - QQmlListProperty<QQuickItem> contentChildren(); - - // 2.1 (Qt 5.8) - qreal contentWidth() const; - void setContentWidth(qreal width); - - qreal contentHeight() const; - void setContentHeight(qreal height); - Q_SIGNALS: void titleChanged(); void headerChanged(); void footerChanged(); - void contentChildrenChanged(); - // 2.1 (Qt 5.8) - Q_REVISION(1) void contentWidthChanged(); - Q_REVISION(1) void contentHeightChanged(); protected: void componentComplete() override; - void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override; void spacingChange(qreal newSpacing, qreal oldSpacing) override; |