summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-24 16:03:39 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-26 11:35:57 +0000
commite09a8591990e5281929ca2a7bb180bb3a35556ba (patch)
tree1b0a88ff0a827266e62f312520553e42c12d288f
parent41ec11a8157b9f1cbbc75ab8f68a2e08d24280d9 (diff)
Popup: add spacing support for Dialogv5.8.0-beta1
This helps to get the dialog layout right (a separate follow-up commit), because we don't need to mess with the paddings of the header, content, and footer, based on their existence and visibility, but we can also adjust the spacing which gets automatically added between the building blocks when they exist and are visible. Change-Id: Ie8b587eeb9d0fb4a8f42baf957879d40bbd3385c Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/controls/Dialog.qml5
-rw-r--r--src/imports/controls/material/Dialog.qml5
-rw-r--r--src/imports/controls/universal/Dialog.qml5
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickdialog.cpp7
-rw-r--r--src/quicktemplates2/qquickdialog_p.h1
-rw-r--r--src/quicktemplates2/qquickpopup.cpp43
-rw-r--r--src/quicktemplates2/qquickpopup_p.h7
-rw-r--r--src/quicktemplates2/qquickpopup_p_p.h1
-rw-r--r--tests/auto/controls/data/tst_dialog.qml44
10 files changed, 113 insertions, 6 deletions
diff --git a/src/imports/controls/Dialog.qml b/src/imports/controls/Dialog.qml
index a26928c1..1cf64164 100644
--- a/src/imports/controls/Dialog.qml
+++ b/src/imports/controls/Dialog.qml
@@ -47,8 +47,9 @@ T.Dialog {
footer && footer.visible ? footer.implicitWidth : 0,
contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
- (header && header.visible ? header.implicitHeight : 0) + (footer && footer.visible ? footer.implicitHeight : 0))
- + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0)
+ (header && header.visible ? header.implicitHeight + spacing : 0)
+ + (footer && footer.visible ? footer.implicitHeight + spacing : 0)
+ + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0))
contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
diff --git a/src/imports/controls/material/Dialog.qml b/src/imports/controls/material/Dialog.qml
index ddc80895..90cda45a 100644
--- a/src/imports/controls/material/Dialog.qml
+++ b/src/imports/controls/material/Dialog.qml
@@ -48,8 +48,9 @@ T.Dialog {
footer && footer.visible ? footer.implicitWidth : 0,
contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
- (header && header.visible ? header.implicitHeight : 0) + (footer && footer.visible ? footer.implicitHeight : 0))
- + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0)
+ (header && header.visible ? header.implicitHeight + spacing : 0)
+ + (footer && footer.visible ? footer.implicitHeight + spacing : 0)
+ + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0))
contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
diff --git a/src/imports/controls/universal/Dialog.qml b/src/imports/controls/universal/Dialog.qml
index ce34fd07..f805581c 100644
--- a/src/imports/controls/universal/Dialog.qml
+++ b/src/imports/controls/universal/Dialog.qml
@@ -47,8 +47,9 @@ T.Dialog {
footer && footer.visible ? footer.implicitWidth : 0,
contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
- (header && header.visible ? header.implicitHeight : 0) + (footer && footer.visible ? footer.implicitHeight : 0))
- + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0)
+ (header && header.visible ? header.implicitHeight + spacing : 0)
+ + (footer && footer.visible ? footer.implicitHeight + spacing : 0)
+ + (contentHeight > 0 ? contentHeight + topPadding + bottomPadding : 0))
contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index 3a124860..fb8db27e 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -187,6 +187,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickDialogButtonBoxAttached>();
qmlRegisterType<QQuickMenuSeparator>(uri, 2, 1, "MenuSeparator");
qmlRegisterType<QQuickPage, 1>(uri, 2, 1, "Page");
+ qmlRegisterType<QQuickPopup, 1>(uri, 2, 1, "Popup");
qmlRegisterType<QQuickRangeSlider, 1>(uri, 2, 1, "RangeSlider");
qmlRegisterType<QQuickRoundButton, 1>(uri, 2, 1, "RoundButton");
qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider");
diff --git a/src/quicktemplates2/qquickdialog.cpp b/src/quicktemplates2/qquickdialog.cpp
index 05e0f26d..6bbe73ce 100644
--- a/src/quicktemplates2/qquickdialog.cpp
+++ b/src/quicktemplates2/qquickdialog.cpp
@@ -336,4 +336,11 @@ void QQuickDialog::paddingChange(const QMarginsF &newPadding, const QMarginsF &o
d->layout->update();
}
+void QQuickDialog::spacingChange(qreal newSpacing, qreal oldSpacing)
+{
+ Q_D(QQuickDialog);
+ QQuickPopup::spacingChange(newSpacing, oldSpacing);
+ d->layout->update();
+}
+
QT_END_NAMESPACE
diff --git a/src/quicktemplates2/qquickdialog_p.h b/src/quicktemplates2/qquickdialog_p.h
index ff8a1e79..ea03dddf 100644
--- a/src/quicktemplates2/qquickdialog_p.h
+++ b/src/quicktemplates2/qquickdialog_p.h
@@ -95,6 +95,7 @@ Q_SIGNALS:
protected:
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;
private:
Q_DISABLE_COPY(QQuickDialog)
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index 3f7d6907..63a9a0d9 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -519,6 +519,13 @@ void QQuickPopupItem::paddingChange(const QMarginsF &newPadding, const QMarginsF
d->popup->paddingChange(newPadding, oldPadding);
}
+void QQuickPopupItem::spacingChange(qreal newSpacing, qreal oldSpacing)
+{
+ Q_D(QQuickPopupItem);
+ QQuickControl::spacingChange(newSpacing, oldSpacing);
+ d->popup->spacingChange(newSpacing, oldSpacing);
+}
+
QFont QQuickPopupItem::defaultFont() const
{
Q_D(const QQuickPopupItem);
@@ -1129,6 +1136,35 @@ qreal QQuickPopup::availableHeight() const
}
/*!
+ \since QtQuick.Controls 2.1
+ \qmlproperty real QtQuick.Controls::Popup::spacing
+
+ This property holds the spacing.
+
+ Spacing is useful for popups that have multiple or repetitive building
+ blocks. For example, some styles use spacing to determine the distance
+ between the header, content, and footer of \l Dialog. Spacing is not
+ enforced by Popup, so each style may interpret it differently, and some
+ may ignore it altogether.
+*/
+qreal QQuickPopup::spacing() const
+{
+ Q_D(const QQuickPopup);
+ return d->popupItem->spacing();
+}
+
+void QQuickPopup::setSpacing(qreal spacing)
+{
+ Q_D(QQuickPopup);
+ d->popupItem->setSpacing(spacing);
+}
+
+void QQuickPopup::resetSpacing()
+{
+ setSpacing(0);
+}
+
+/*!
\qmlproperty real QtQuick.Controls::Popup::margins
This property holds the default margins around the popup.
@@ -2152,6 +2188,13 @@ void QQuickPopup::paddingChange(const QMarginsF &newPadding, const QMarginsF &ol
emit availableHeightChanged();
}
+void QQuickPopup::spacingChange(qreal newSpacing, qreal oldSpacing)
+{
+ Q_UNUSED(newSpacing);
+ Q_UNUSED(oldSpacing);
+ emit spacingChanged();
+}
+
QFont QQuickPopup::defaultFont() const
{
return QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont);
diff --git a/src/quicktemplates2/qquickpopup_p.h b/src/quicktemplates2/qquickpopup_p.h
index a024c68f..de42b793 100644
--- a/src/quicktemplates2/qquickpopup_p.h
+++ b/src/quicktemplates2/qquickpopup_p.h
@@ -84,6 +84,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPopup : public QObject, public QQml
Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL)
Q_PROPERTY(qreal availableWidth READ availableWidth NOTIFY availableWidthChanged FINAL)
Q_PROPERTY(qreal availableHeight READ availableHeight NOTIFY availableHeightChanged FINAL)
+ Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL REVISION 1)
Q_PROPERTY(qreal margins READ margins WRITE setMargins RESET resetMargins NOTIFY marginsChanged FINAL)
Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin RESET resetTopMargin NOTIFY topMarginChanged FINAL)
Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin RESET resetLeftMargin NOTIFY leftMarginChanged FINAL)
@@ -154,6 +155,10 @@ public:
qreal availableWidth() const;
qreal availableHeight() const;
+ qreal spacing() const;
+ void setSpacing(qreal spacing);
+ void resetSpacing();
+
qreal margins() const;
void setMargins(qreal margins);
void resetMargins();
@@ -293,6 +298,7 @@ Q_SIGNALS:
void contentHeightChanged();
void availableWidthChanged();
void availableHeightChanged();
+ Q_REVISION(1) void spacingChanged();
void marginsChanged();
void topMarginChanged();
void leftMarginChanged();
@@ -354,6 +360,7 @@ protected:
virtual void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data);
virtual void marginsChange(const QMarginsF &newMargins, const QMarginsF &oldMargins);
virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding);
+ virtual void spacingChange(qreal newSpacing, qreal oldSpacing);
virtual QFont defaultFont() const;
diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h
index a9eeacd8..7675b151 100644
--- a/src/quicktemplates2/qquickpopup_p_p.h
+++ b/src/quicktemplates2/qquickpopup_p_p.h
@@ -105,6 +105,7 @@ protected:
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override;
void itemChange(ItemChange change, const ItemChangeData &data) override;
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override;
+ void spacingChange(qreal newSpacing, qreal oldSpacing) override;
QFont defaultFont() const override;
diff --git a/tests/auto/controls/data/tst_dialog.qml b/tests/auto/controls/data/tst_dialog.qml
index 3c42ccf4..69c47fed 100644
--- a/tests/auto/controls/data/tst_dialog.qml
+++ b/tests/auto/controls/data/tst_dialog.qml
@@ -255,4 +255,48 @@ TestCase {
control.destroy()
}
+
+ function test_spacing_data() {
+ return [
+ { tag: "content", header: false, content: true, footer: false },
+ { tag: "header,content", header: true, content: true, footer: false },
+ { tag: "content,footer", header: false, content: true, footer: true },
+ { tag: "header,content,footer", header: true, content: true, footer: true },
+ { tag: "header,footer", header: true, content: false, footer: true },
+ { tag: "header", header: true, content: false, footer: false },
+ { tag: "footer", header: false, content: false, footer: true },
+ ]
+ }
+
+ function test_spacing(data) {
+ var control = dialog.createObject(testCase, {spacing: 20, width: 100, height: 100})
+ verify(control)
+
+ control.open()
+ waitForRendering(control.contentItem)
+ verify(control.visible)
+
+ control.contentItem.visible = data.content
+ control.header = buttonBox.createObject(control.contentItem, {visible: data.header})
+ control.footer = buttonBox.createObject(control.contentItem, {visible: data.footer})
+
+ compare(control.header.x, 0)
+ compare(control.header.y, 0)
+ compare(control.header.width, control.width)
+ verify(control.header.height > 0)
+
+ compare(control.footer.x, 0)
+ compare(control.footer.y, control.height - control.footer.height)
+ compare(control.footer.width, control.width)
+ verify(control.footer.height > 0)
+
+ compare(control.contentItem.x, control.leftPadding)
+ compare(control.contentItem.y, control.topPadding + (data.header ? control.header.height + control.spacing : 0))
+ compare(control.contentItem.width, control.availableWidth)
+ compare(control.contentItem.height, control.availableHeight
+ - (data.header ? control.header.height + control.spacing : 0)
+ - (data.footer ? control.footer.height + control.spacing : 0))
+
+ control.destroy()
+ }
}