aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-05-11 11:56:38 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-05-18 12:00:48 +0000
commitf52025af7a1c62f4c0f580c39ce255a798e91655 (patch)
tree9963ca74a30f28ec2367a4e0201e27a8f2f502d7
parenta8d532eb1d46cb4487988df939a176f662c7a1af (diff)
Column, Row, Grid, Flow: add support for padding
[ChangeLog][QtQuick] Added padding, leftPadding, topPadding, rightPadding and bottomPadding properties in Positioners, including Column, Row, Grid and Flow. Task-number: QTBUG-41559 Change-Id: If3be7b2243a79c01dad0a5600e22d30eeea43c8a Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
-rw-r--r--src/quick/items/qquickitemsmodule.cpp6
-rw-r--r--src/quick/items/qquickpositioners.cpp298
-rw-r--r--src/quick/items/qquickpositioners_p.h38
-rw-r--r--src/quick/items/qquickpositioners_p_p.h25
-rw-r--r--tests/auto/quick/qquickpositioners/data/allInvisible.qml40
-rw-r--r--tests/auto/quick/qquickpositioners/data/flowtest-padding.qml44
-rw-r--r--tests/auto/quick/qquickpositioners/data/gridtest-padding.qml47
-rw-r--r--tests/auto/quick/qquickpositioners/data/horizontal-padding.qml30
-rw-r--r--tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml53
-rw-r--r--tests/auto/quick/qquickpositioners/data/repeatertest.qml18
-rw-r--r--tests/auto/quick/qquickpositioners/data/transitions-padding.qml239
-rw-r--r--tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp2000
12 files changed, 2754 insertions, 84 deletions
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index 94ff781937..c736244b0e 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -263,6 +263,12 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickText, 6>(uri, 2, 6, "Text");
qmlRegisterType<QQuickTextEdit, 6>(uri, 2, 6, "TextEdit");
qmlRegisterType<QQuickTextInput, 6>(uri, 2, 6, "TextInput");
+ qmlRegisterUncreatableType<QQuickBasePositioner, 6>(uri, 2, 6, "Positioner",
+ QStringLiteral("Positioner is an abstract type that is only available as an attached property."));
+ qmlRegisterType<QQuickColumn, 6>(uri, 2, 6, "Column");
+ qmlRegisterType<QQuickRow, 6>(uri, 2, 6, "Row");
+ qmlRegisterType<QQuickGrid, 6>(uri, 2, 6, "Grid");
+ qmlRegisterType<QQuickFlow, 6>(uri, 2, 6, "Flow");
}
static void initResources()
diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp
index 887d317069..c2eb7a9ac3 100644
--- a/src/quick/items/qquickpositioners.cpp
+++ b/src/quick/items/qquickpositioners.cpp
@@ -70,6 +70,10 @@ QQuickBasePositioner::PositionedItem::PositionedItem(QQuickItem *i)
, index(-1)
, isNew(false)
, isVisible(true)
+ , topPadding(0)
+ , leftPadding(0)
+ , rightPadding(0)
+ , bottomPadding(0)
{
}
@@ -116,6 +120,14 @@ void QQuickBasePositioner::PositionedItem::startTransition(QQuickItemViewTransit
transitionableItem->startTransition(transitioner, index);
}
+void QQuickBasePositioner::PositionedItem::updatePadding(qreal lp, qreal tp, qreal rp, qreal bp)
+{
+ leftPadding = lp;
+ topPadding = tp;
+ rightPadding = rp;
+ bottomPadding = bp;
+}
+
QQuickBasePositioner::QQuickBasePositioner(PositionerType at, QQuickItem *parent)
: QQuickImplicitSizeItem(*(new QQuickBasePositionerPrivate), parent)
@@ -388,11 +400,8 @@ void QQuickBasePositioner::prePositioning()
void QQuickBasePositioner::positionItem(qreal x, qreal y, PositionedItem *target)
{
- Q_D(QQuickBasePositioner);
- if ( (target->itemX() != x || target->itemY() != y)
- && d->type == Both) {
+ if ( target->itemX() != x || target->itemY() != y )
target->moveTo(QPointF(x, y));
- }
}
void QQuickBasePositioner::positionItemX(qreal x, PositionedItem *target)
@@ -503,6 +512,163 @@ void QQuickBasePositioner::updateAttachedProperties(QQuickPositionerAttached *sp
}
}
+qreal QQuickBasePositioner::padding() const
+{
+ Q_D(const QQuickBasePositioner);
+ return d->padding;
+}
+
+void QQuickBasePositioner::setPadding(qreal padding)
+{
+ Q_D(QQuickBasePositioner);
+ if (qFuzzyCompare(d->padding, padding))
+ return;
+ d->padding = padding;
+ d->setPositioningDirty();
+ emit paddingChanged();
+ if (!d->explicitTopPadding)
+ emit topPaddingChanged();
+ if (!d->explicitLeftPadding)
+ emit leftPaddingChanged();
+ if (!d->explicitRightPadding)
+ emit rightPaddingChanged();
+ if (!d->explicitBottomPadding)
+ emit bottomPaddingChanged();
+}
+
+void QQuickBasePositioner::resetPadding()
+{
+ setPadding(0);
+}
+
+qreal QQuickBasePositioner::topPadding() const
+{
+ Q_D(const QQuickBasePositioner);
+ if (d->explicitTopPadding)
+ return d->topPadding;
+ return d->padding;
+}
+
+void QQuickBasePositioner::setTopPadding(qreal padding)
+{
+ Q_D(QQuickBasePositioner);
+ d->setTopPadding(padding);
+}
+
+void QQuickBasePositioner::resetTopPadding()
+{
+ Q_D(QQuickBasePositioner);
+ d->setTopPadding(0, true);
+}
+
+qreal QQuickBasePositioner::leftPadding() const
+{
+ Q_D(const QQuickBasePositioner);
+ if (d->explicitLeftPadding)
+ return d->leftPadding;
+ return d->padding;
+}
+
+void QQuickBasePositioner::setLeftPadding(qreal padding)
+{
+ Q_D(QQuickBasePositioner);
+ d->setLeftPadding(padding);
+}
+
+void QQuickBasePositioner::resetLeftPadding()
+{
+ Q_D(QQuickBasePositioner);
+ d->setLeftPadding(0, true);
+}
+
+qreal QQuickBasePositioner::rightPadding() const
+{
+ Q_D(const QQuickBasePositioner);
+ if (d->explicitRightPadding)
+ return d->rightPadding;
+ return d->padding;
+}
+
+void QQuickBasePositioner::setRightPadding(qreal padding)
+{
+ Q_D(QQuickBasePositioner);
+ d->setRightPadding(padding);
+}
+
+void QQuickBasePositioner::resetRightPadding()
+{
+ Q_D(QQuickBasePositioner);
+ d->setRightPadding(0, true);
+}
+
+qreal QQuickBasePositioner::bottomPadding() const
+{
+ Q_D(const QQuickBasePositioner);
+ if (d->explicitBottomPadding)
+ return d->bottomPadding;
+ return d->padding;
+}
+
+void QQuickBasePositioner::setBottomPadding(qreal padding)
+{
+ Q_D(QQuickBasePositioner);
+ d->setBottomPadding(padding);
+}
+
+void QQuickBasePositioner::resetBottomPadding()
+{
+ Q_D(QQuickBasePositioner);
+ d->setBottomPadding(0, true);
+}
+
+void QQuickBasePositionerPrivate::setTopPadding(qreal value, bool reset)
+{
+ Q_Q(QQuickBasePositioner);
+ qreal tmp = q->topPadding();
+ topPadding = value;
+ explicitTopPadding = !reset;
+ if ((!reset && !qFuzzyCompare(tmp, value)) || (reset && !qFuzzyCompare(tmp, padding))) {
+ setPositioningDirty();
+ emit q->topPaddingChanged();
+ }
+}
+
+void QQuickBasePositionerPrivate::setLeftPadding(qreal value, bool reset)
+{
+ Q_Q(QQuickBasePositioner);
+ qreal tmp = q->leftPadding();
+ leftPadding = value;
+ explicitLeftPadding = !reset;
+ if ((!reset && !qFuzzyCompare(tmp, value)) || (reset && !qFuzzyCompare(tmp, padding))) {
+ setPositioningDirty();
+ emit q->leftPaddingChanged();
+ }
+}
+
+void QQuickBasePositionerPrivate::setRightPadding(qreal value, bool reset)
+{
+ Q_Q(QQuickBasePositioner);
+ qreal tmp = q->rightPadding();
+ rightPadding = value;
+ explicitRightPadding = !reset;
+ if ((!reset && !qFuzzyCompare(tmp, value)) || (reset && !qFuzzyCompare(tmp, padding))) {
+ setPositioningDirty();
+ emit q->rightPaddingChanged();
+ }
+}
+
+void QQuickBasePositionerPrivate::setBottomPadding(qreal value, bool reset)
+{
+ Q_Q(QQuickBasePositioner);
+ qreal tmp = q->bottomPadding();
+ bottomPadding = value;
+ explicitBottomPadding = !reset;
+ if ((!reset && !qFuzzyCompare(tmp, value)) || (reset && !qFuzzyCompare(tmp, padding))) {
+ setPositioningDirty();
+ emit q->bottomPaddingChanged();
+ }
+}
+
/*!
\qmltype Positioner
\instantiates QQuickPositionerAttached
@@ -640,6 +806,16 @@ void QQuickPositionerAttached::setIsLastItem(bool isLastItem)
\sa Row, Grid, Flow, Positioner, ColumnLayout, {Qt Quick Examples - Positioners}
*/
/*!
+ \since 5.6
+ \qmlproperty real QtQuick::Column::padding
+ \qmlproperty real QtQuick::Column::topPadding
+ \qmlproperty real QtQuick::Column::leftPadding
+ \qmlproperty real QtQuick::Column::bottomPadding
+ \qmlproperty real QtQuick::Column::rightPadding
+
+ These properties hold the padding around the content.
+*/
+/*!
\qmlproperty Transition QtQuick::Column::populate
This property holds the transition to be run for items that are part of
@@ -715,20 +891,23 @@ QQuickColumn::QQuickColumn(QQuickItem *parent)
void QQuickColumn::doPositioning(QSizeF *contentSize)
{
//Precondition: All items in the positioned list have a valid item pointer and should be positioned
- qreal voffset = 0;
+ qreal voffset = topPadding();
+ const qreal padding = leftPadding() + rightPadding();
+ contentSize->setWidth(qMax(contentSize->width(), padding));
for (int ii = 0; ii < positionedItems.count(); ++ii) {
PositionedItem &child = positionedItems[ii];
- positionItemY(voffset, &child);
- contentSize->setWidth(qMax(contentSize->width(), child.item->width()));
+ positionItem(child.itemX() + leftPadding() - child.leftPadding, voffset, &child);
+ child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding());
+ contentSize->setWidth(qMax(contentSize->width(), child.item->width() + padding));
voffset += child.item->height();
voffset += spacing();
}
- if (voffset != 0)//If we positioned any items, undo the spacing from the last item
+ if (voffset - topPadding() != 0)//If we positioned any items, undo the spacing from the last item
voffset -= spacing();
- contentSize->setHeight(voffset);
+ contentSize->setHeight(voffset + bottomPadding());
}
void QQuickColumn::reportConflictingAnchors()
@@ -794,6 +973,16 @@ void QQuickColumn::reportConflictingAnchors()
\sa Column, Grid, Flow, Positioner, RowLayout, {Qt Quick Examples - Positioners}
*/
/*!
+ \since 5.6
+ \qmlproperty real QtQuick::Row::padding
+ \qmlproperty real QtQuick::Row::topPadding
+ \qmlproperty real QtQuick::Row::leftPadding
+ \qmlproperty real QtQuick::Row::bottomPadding
+ \qmlproperty real QtQuick::Row::rightPadding
+
+ These properties hold the padding around the content.
+*/
+/*!
\qmlproperty Transition QtQuick::Row::populate
This property holds the transition to be run for items that are part of
@@ -940,27 +1129,34 @@ void QQuickRow::doPositioning(QSizeF *contentSize)
{
//Precondition: All items in the positioned list have a valid item pointer and should be positioned
QQuickBasePositionerPrivate *d = static_cast<QQuickBasePositionerPrivate* >(QQuickBasePositionerPrivate::get(this));
- qreal hoffset = 0;
+ qreal hoffset1 = leftPadding();
+ qreal hoffset2 = rightPadding();
+ if (!d->isLeftToRight())
+ qSwap(hoffset1, hoffset2);
+ qreal hoffset = hoffset1;
+ const qreal padding = topPadding() + bottomPadding();
+ contentSize->setHeight(qMax(contentSize->height(), padding));
QList<qreal> hoffsets;
for (int ii = 0; ii < positionedItems.count(); ++ii) {
PositionedItem &child = positionedItems[ii];
if (d->isLeftToRight()) {
- positionItemX(hoffset, &child);
+ positionItem(hoffset, child.itemY() + topPadding() - child.topPadding, &child);
+ child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding());
} else {
hoffsets << hoffset;
}
- contentSize->setHeight(qMax(contentSize->height(), child.item->height()));
+ contentSize->setHeight(qMax(contentSize->height(), child.item->height() + padding));
hoffset += child.item->width();
hoffset += spacing();
}
- if (hoffset != 0)//If we positioned any items, undo the extra spacing from the last item
+ if (hoffset - hoffset1 != 0)//If we positioned any items, undo the extra spacing from the last item
hoffset -= spacing();
- contentSize->setWidth(hoffset);
+ contentSize->setWidth(hoffset + hoffset2);
if (d->isLeftToRight())
return;
@@ -976,7 +1172,8 @@ void QQuickRow::doPositioning(QSizeF *contentSize)
for (int ii = 0; ii < positionedItems.count(); ++ii) {
PositionedItem &child = positionedItems[ii];
hoffset = end - hoffsets[acc++] - child.item->width();
- positionItemX(hoffset, &child);
+ positionItem(hoffset, child.itemY() + topPadding() - child.topPadding, &child);
+ child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding());
}
}
@@ -1044,6 +1241,16 @@ void QQuickRow::reportConflictingAnchors()
\sa Flow, Row, Column, Positioner, GridLayout, {Qt Quick Examples - Positioners}
*/
/*!
+ \since 5.6
+ \qmlproperty real QtQuick::Grid::padding
+ \qmlproperty real QtQuick::Grid::topPadding
+ \qmlproperty real QtQuick::Grid::leftPadding
+ \qmlproperty real QtQuick::Grid::bottomPadding
+ \qmlproperty real QtQuick::Grid::rightPadding
+
+ These properties hold the padding around the content.
+*/
+/*!
\qmlproperty Transition QtQuick::Grid::populate
This property holds the transition to be run for items that are part of
@@ -1423,8 +1630,11 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
c = (numVisible+(m_rows-1))/m_rows;
}
- if (r == 0 || c == 0)
- return; //Nothing to do
+ if (r == 0 || c == 0) {
+ contentSize->setHeight(topPadding() + bottomPadding());
+ contentSize->setWidth(leftPadding() + rightPadding());
+ return; //Nothing else to do
+ }
QList<qreal> maxColWidth;
QList<qreal> maxRowHeight;
@@ -1476,6 +1686,7 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
widthSum += columnSpacing;
widthSum += maxColWidth[j];
}
+ widthSum += leftPadding() + rightPadding();
qreal heightSum = 0;
for (int i = 0; i < maxRowHeight.size(); i++) {
@@ -1483,6 +1694,7 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
heightSum += rowSpacing;
heightSum += maxRowHeight[i];
}
+ heightSum += topPadding() + bottomPadding();
contentSize->setHeight(heightSum);
contentSize->setWidth(widthSum);
@@ -1493,10 +1705,10 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
else
end = widthSum;
- qreal xoffset = 0;
+ qreal xoffset = leftPadding();
if (!d->isLeftToRight())
- xoffset = end;
- qreal yoffset = 0;
+ xoffset = end - rightPadding();
+ qreal yoffset = topPadding();
int curRow =0;
int curCol =0;
for (int i = 0; i < positionedItems.count(); ++i) {
@@ -1518,6 +1730,7 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
alignYOffset += maxRowHeight[curRow] - child.item->height();
positionItem(childXOffset, alignYOffset, &child);
+ child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding());
if (m_flow == LeftToRight) {
if (d->isLeftToRight())
@@ -1529,9 +1742,9 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
if (!curCol) {
yoffset += maxRowHeight[curRow]+rowSpacing;
if (d->isLeftToRight())
- xoffset = 0;
+ xoffset = leftPadding();
else
- xoffset = end;
+ xoffset = end - rightPadding();
curRow++;
if (curRow>=r)
break;
@@ -1545,7 +1758,7 @@ void QQuickGrid::doPositioning(QSizeF *contentSize)
xoffset += maxColWidth[curCol]+columnSpacing;
else
xoffset -= maxColWidth[curCol]+columnSpacing;
- yoffset = 0;
+ yoffset = topPadding();
curCol++;
if (curCol>=c)
break;
@@ -1603,6 +1816,16 @@ void QQuickGrid::reportConflictingAnchors()
\sa Column, Row, Grid, Positioner, {Qt Quick Examples - Positioners}
*/
/*!
+ \since 5.6
+ \qmlproperty real QtQuick::Flow::padding
+ \qmlproperty real QtQuick::Flow::topPadding
+ \qmlproperty real QtQuick::Flow::leftPadding
+ \qmlproperty real QtQuick::Flow::bottomPadding
+ \qmlproperty real QtQuick::Flow::rightPadding
+
+ These properties hold the padding around the content.
+*/
+/*!
\qmlproperty Transition QtQuick::Flow::populate
This property holds the transition to be run for items that are part of
@@ -1786,23 +2009,30 @@ void QQuickFlow::doPositioning(QSizeF *contentSize)
//Precondition: All items in the positioned list have a valid item pointer and should be positioned
Q_D(QQuickFlow);
- qreal hoffset = 0;
- qreal voffset = 0;
+ qreal hoffset1 = leftPadding();
+ qreal hoffset2 = rightPadding();
+ if (!d->isLeftToRight())
+ qSwap(hoffset1, hoffset2);
+ qreal hoffset = hoffset1;
+ const qreal voffset1 = topPadding();
+ qreal voffset = voffset1;
qreal linemax = 0;
QList<qreal> hoffsets;
+ contentSize->setWidth(qMax(contentSize->width(), hoffset1 + hoffset2));
+ contentSize->setHeight(qMax(contentSize->height(), voffset + bottomPadding()));
for (int i = 0; i < positionedItems.count(); ++i) {
PositionedItem &child = positionedItems[i];
if (d->flow == LeftToRight) {
- if (widthValid() && hoffset && hoffset + child.item->width() > width()) {
- hoffset = 0;
+ if (widthValid() && hoffset != hoffset1 && hoffset + child.item->width() + hoffset2 > width()) {
+ hoffset = hoffset1;
voffset += linemax + spacing();
linemax = 0;
}
} else {
- if (heightValid() && voffset && voffset + child.item->height() > height()) {
- voffset = 0;
+ if (heightValid() && voffset != voffset1 && voffset + child.item->height() + bottomPadding() > height()) {
+ voffset = voffset1;
hoffset += linemax + spacing();
linemax = 0;
}
@@ -1810,13 +2040,16 @@ void QQuickFlow::doPositioning(QSizeF *contentSize)
if (d->isLeftToRight()) {
positionItem(hoffset, voffset, &child);
+ child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding());
} else {
hoffsets << hoffset;
positionItemY(voffset, &child);
+ child.topPadding = topPadding();
+ child.bottomPadding = bottomPadding();
}
- contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width()));
- contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height()));
+ contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width() + hoffset2));
+ contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height() + bottomPadding()));
if (d->flow == LeftToRight) {
hoffset += child.item->width();
@@ -1828,6 +2061,7 @@ void QQuickFlow::doPositioning(QSizeF *contentSize)
linemax = qMax(linemax, child.item->width());
}
}
+
if (d->isLeftToRight())
return;
@@ -1841,6 +2075,8 @@ void QQuickFlow::doPositioning(QSizeF *contentSize)
PositionedItem &child = positionedItems[i];
hoffset = end - hoffsets[acc++] - child.item->width();
positionItemX(hoffset, &child);
+ child.leftPadding = leftPadding();
+ child.rightPadding = rightPadding();
}
}
diff --git a/src/quick/items/qquickpositioners_p.h b/src/quick/items/qquickpositioners_p.h
index ea779695eb..6323405022 100644
--- a/src/quick/items/qquickpositioners_p.h
+++ b/src/quick/items/qquickpositioners_p.h
@@ -86,6 +86,12 @@ class Q_QUICK_PRIVATE_EXPORT QQuickBasePositioner : public QQuickImplicitSizeIte
Q_PROPERTY(QQuickTransition *populate READ populate WRITE setPopulate NOTIFY populateChanged)
Q_PROPERTY(QQuickTransition *move READ move WRITE setMove NOTIFY moveChanged)
Q_PROPERTY(QQuickTransition *add READ add WRITE setAdd NOTIFY addChanged)
+
+ Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION 6)
+ Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION 6)
+ Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION 6)
+ Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION 6)
+ Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION 6)
public:
enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
@@ -108,6 +114,26 @@ public:
void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const;
+ qreal padding() const;
+ void setPadding(qreal padding);
+ void resetPadding();
+
+ qreal topPadding() const;
+ void setTopPadding(qreal padding);
+ void resetTopPadding();
+
+ qreal leftPadding() const;
+ void setLeftPadding(qreal padding);
+ void resetLeftPadding();
+
+ qreal rightPadding() const;
+ void setRightPadding(qreal padding);
+ void resetRightPadding();
+
+ qreal bottomPadding() const;
+ void setBottomPadding(qreal padding);
+ void resetBottomPadding();
+
protected:
QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
void componentComplete() Q_DECL_OVERRIDE;
@@ -120,6 +146,11 @@ Q_SIGNALS:
void populateChanged();
void moveChanged();
void addChanged();
+ Q_REVISION(6) void paddingChanged();
+ Q_REVISION(6) void topPaddingChanged();
+ Q_REVISION(6) void leftPaddingChanged();
+ Q_REVISION(6) void rightPaddingChanged();
+ Q_REVISION(6) void bottomPaddingChanged();
protected Q_SLOTS:
void prePositioning();
@@ -144,11 +175,18 @@ protected:
bool prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds);
void startTransition(QQuickItemViewTransitioner *transitioner);
+ void updatePadding(qreal lp, qreal tp, qreal rp, qreal bp);
+
QQuickItem *item;
QQuickItemViewTransitionableItem *transitionableItem;
int index;
bool isNew;
bool isVisible;
+
+ qreal topPadding;
+ qreal leftPadding;
+ qreal rightPadding;
+ qreal bottomPadding;
};
QPODVector<PositionedItem,8> positionedItems;
diff --git a/src/quick/items/qquickpositioners_p_p.h b/src/quick/items/qquickpositioners_p_p.h
index 3a8fe20351..a58f79ac0a 100644
--- a/src/quick/items/qquickpositioners_p_p.h
+++ b/src/quick/items/qquickpositioners_p_p.h
@@ -69,6 +69,16 @@ public:
: spacing(0), type(QQuickBasePositioner::None)
, transitioner(0), positioningDirty(false)
, doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
+ , padding(0)
+ , topPadding(0)
+ , leftPadding(0)
+ , rightPadding(0)
+ , bottomPadding(0)
+ , explicitTopPadding(false)
+ , explicitLeftPadding(false)
+ , explicitRightPadding(false)
+ , explicitBottomPadding(false)
+
{
}
@@ -98,6 +108,16 @@ public:
Qt::LayoutDirection layoutDirection;
+ qreal padding;
+ qreal topPadding;
+ qreal leftPadding;
+ qreal rightPadding;
+ qreal bottomPadding;
+ bool explicitTopPadding;
+ bool explicitLeftPadding;
+ bool explicitRightPadding;
+ bool explicitBottomPadding;
+
void mirrorChange() Q_DECL_OVERRIDE {
effectiveLayoutDirectionChange();
}
@@ -149,6 +169,11 @@ public:
virtual void effectiveLayoutDirectionChange()
{
}
+
+ void setTopPadding(qreal value, bool reset = false);
+ void setLeftPadding(qreal value, bool reset = false);
+ void setRightPadding(qreal value, bool reset = false);
+ void setBottomPadding(qreal value, bool reset = false);
};
QT_END_NAMESPACE
diff --git a/tests/auto/quick/qquickpositioners/data/allInvisible.qml b/tests/auto/quick/qquickpositioners/data/allInvisible.qml
index 5894171434..3b95a5e1da 100644
--- a/tests/auto/quick/qquickpositioners/data/allInvisible.qml
+++ b/tests/auto/quick/qquickpositioners/data/allInvisible.qml
@@ -1,4 +1,4 @@
-import QtQuick 2.0
+import QtQuick 2.6
Item{
width: 400
@@ -41,4 +41,42 @@ Item{
visible: false
}
}
+ Grid{
+ spacing: 20
+ objectName: "grid"
+ Item{
+ width: 0
+ height: 20
+ visible: false
+ }
+ Item{
+ width: 20
+ height: 0
+ visible: false
+ }
+ Item{
+ width: 20
+ height: 20
+ visible: false
+ }
+ }
+ Flow{
+ spacing: 20
+ objectName: "flow"
+ Item{
+ width: 0
+ height: 20
+ visible: false
+ }
+ Item{
+ width: 20
+ height: 0
+ visible: false
+ }
+ Item{
+ width: 20
+ height: 20
+ visible: false
+ }
+ }
}
diff --git a/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml
new file mode 100644
index 0000000000..a85e7a5c52
--- /dev/null
+++ b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.6
+
+Item {
+ width: 90
+ height: 480
+ property bool testRightToLeft: false
+
+ Flow {
+ objectName: "flow"
+ width: parent.width
+ layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "green"
+ width: 20
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "blue"
+ width: 50
+ height: 20
+ }
+ Rectangle {
+ objectName: "four"
+ color: "cyan"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "five"
+ color: "magenta"
+ width: 10
+ height: 10
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml
new file mode 100644
index 0000000000..46244ecef5
--- /dev/null
+++ b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml
@@ -0,0 +1,47 @@
+import QtQuick 2.6
+
+Item {
+ width: 640
+ height: 480
+ property bool testRightToLeft: false
+ property int testHAlignment: Grid.AlignLeft;
+ property int testVAlignment: Grid.AlignTop;
+ Grid {
+ layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight
+ horizontalItemAlignment: testHAlignment
+ verticalItemAlignment: testVAlignment
+ objectName: "grid"
+ columns: 3
+ padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "green"
+ width: 20
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "blue"
+ width: 30
+ height: 20
+ }
+ Rectangle {
+ objectName: "four"
+ color: "cyan"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "five"
+ color: "magenta"
+ width: 10
+ height: 10
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml
new file mode 100644
index 0000000000..d320c4789f
--- /dev/null
+++ b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml
@@ -0,0 +1,30 @@
+import QtQuick 2.6
+
+Item {
+ width: 640
+ height: 480
+ property bool testRightToLeft: false
+ Row {
+ objectName: "row"
+ layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight
+ padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "red"
+ width: 20
+ height: 10
+ }
+ Rectangle {
+ objectName: "three"
+ color: "red"
+ width: 40
+ height: 20
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml
new file mode 100644
index 0000000000..577d4ef0b7
--- /dev/null
+++ b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml
@@ -0,0 +1,53 @@
+import QtQuick 2.6
+
+Item {
+ width: 640
+ height: 480
+ Row {
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Repeater{ model: 3;
+ delegate: Component {
+ Rectangle {
+ color: "red"
+ width: 50
+ height: 50
+ z: {
+ if (index == 0)
+ return 2;
+ else if (index == 1)
+ return 1;
+ else
+ return 3;
+ }
+ objectName: {
+ if (index == 0)
+ return "one";
+ else if (index == 1)
+ return "two";
+ else
+ return "three";
+ }
+ }
+ }
+ }
+ }
+
+ //This crashed once (QTBUG-16959) because the repeater ended up on the end of the list
+ //If this grid just instantiates without crashing, then it has not regressed.
+ Grid {
+ id: grid
+ rows: 2
+ flow: Grid.TopToBottom
+
+ Repeater {
+ model: 13
+ Rectangle {
+ color: "goldenrod"
+ width: 100
+ height: 100
+ radius: 10
+ border.width: 1
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest.qml b/tests/auto/quick/qquickpositioners/data/repeatertest.qml
index d90e1cf160..ae3d961c75 100644
--- a/tests/auto/quick/qquickpositioners/data/repeatertest.qml
+++ b/tests/auto/quick/qquickpositioners/data/repeatertest.qml
@@ -10,8 +10,22 @@ Item {
color: "red"
width: 50
height: 50
- z: {if(index == 0){2;}else if(index == 1){1;} else{3;}}
- objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}}
+ z: {
+ if (index == 0)
+ return 2;
+ else if (index == 1)
+ return 1;
+ else
+ return 3;
+ }
+ objectName: {
+ if (index == 0)
+ return "one";
+ else if (index == 1)
+ return "two";
+ else
+ return "three";
+ }
}
}
}
diff --git a/tests/auto/quick/qquickpositioners/data/transitions-padding.qml b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml
new file mode 100644
index 0000000000..e3175c480c
--- /dev/null
+++ b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml
@@ -0,0 +1,239 @@
+import QtQuick 2.6
+
+Rectangle {
+ id: root
+ width: 500
+ height: 500
+
+ property int duration: 50
+
+ property real incrementalSize: 5
+
+ property int populateTransitionsDone
+ property int addTransitionsDone
+ property int displaceTransitionsDone
+
+ property var targetTrans_items: new Object()
+ property var targetTrans_targetIndexes: new Array()
+ property var targetTrans_targetItems: new Array()
+
+ property var displacedTrans_items: new Object()
+ property var displacedTrans_targetIndexes: new Array()
+ property var displacedTrans_targetItems: new Array()
+
+ // for QQmlListProperty types
+ function copyList(propList) {
+ var temp = new Array()
+ for (var i=0; i<propList.length; i++)
+ temp.push(propList[i])
+ return temp
+ }
+
+ function checkPos(x, y, name) {
+ if (Qt.point(x, y) == targetItems_transitionFrom)
+ model_targetItems_transitionFrom.addItem(name, "")
+ if (Qt.point(x, y) == displacedItems_transitionVia)
+ model_displacedItems_transitionVia.addItem(name, "")
+ }
+
+ Component.onCompleted: {
+ if (dynamicallyPopulate) {
+ for (var i=0; i<30; i++)
+ testModel.addItem("item " + i, "")
+ }
+ }
+
+ Transition {
+ id: populateTransition
+ enabled: usePopulateTransition
+
+ SequentialAnimation {
+ ScriptAction {
+ script: {
+ root.targetTrans_items[populateTransition.ViewTransition.item.nameData] = populateTransition.ViewTransition.index
+ root.targetTrans_targetIndexes.push(populateTransition.ViewTransition.targetIndexes)
+ root.targetTrans_targetItems.push(root.copyList(populateTransition.ViewTransition.targetItems))
+ }
+ }
+ ParallelAnimation {
+ NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration }
+ NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration }
+ }
+
+ ScriptAction { script: root.populateTransitionsDone += 1 }
+ }
+ }
+
+ Transition {
+ id: addTransition
+ enabled: enableAddTransition
+
+ SequentialAnimation {
+ ScriptAction {
+ script: {
+ root.targetTrans_items[addTransition.ViewTransition.item.nameData] = addTransition.ViewTransition.index
+ root.targetTrans_targetIndexes.push(addTransition.ViewTransition.targetIndexes)
+ root.targetTrans_targetItems.push(root.copyList(addTransition.ViewTransition.targetItems))
+ }
+ }
+ ParallelAnimation {
+ NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration }
+ NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration }
+ }
+
+ ScriptAction { script: root.addTransitionsDone += 1 }
+ }
+ }
+
+ Transition {
+ id: displaced
+
+ SequentialAnimation {
+ ScriptAction {
+ script: {
+ root.displacedTrans_items[displaced.ViewTransition.item.nameData] = displaced.ViewTransition.index
+ root.displacedTrans_targetIndexes.push(displaced.ViewTransition.targetIndexes)
+ root.displacedTrans_targetItems.push(root.copyList(displaced.ViewTransition.targetItems))
+ }
+ }
+ ParallelAnimation {
+ NumberAnimation { properties: "x"; duration: root.duration; to: displacedItems_transitionVia.x }
+ NumberAnimation { properties: "y"; duration: root.duration; to: displacedItems_transitionVia.y }
+ }
+ NumberAnimation { properties: "x,y"; duration: root.duration }
+
+ ScriptAction { script: root.displaceTransitionsDone += 1 }
+ }
+
+ }
+
+ Row {
+ objectName: "row"
+
+ property int count: children.length - 1 // omit Repeater
+
+ x: 50; y: 50
+ width: 400; height: 400
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Repeater {
+ objectName: "repeater"
+ model: testedPositioner == "row" ? testModel : undefined
+ Rectangle {
+ property string nameData: name
+ objectName: "wrapper"
+ width: 30 + index*root.incrementalSize
+ height: 30 + index*root.incrementalSize
+ border.width: 1
+ Column {
+ Text { text: index }
+ Text { objectName: "name"; text: name }
+ Text { text: parent.parent.y }
+ }
+ onXChanged: root.checkPos(x, y, name)
+ onYChanged: root.checkPos(x, y, name)
+ }
+ }
+
+ populate: populateTransition
+ add: addTransition
+ move: displaced
+ }
+
+ Column {
+ objectName: "column"
+
+ property int count: children.length - 1 // omit Repeater
+
+ x: 50; y: 50
+ width: 400; height: 400
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Repeater {
+ objectName: "repeater"
+ model: testedPositioner == "column" ? testModel : undefined
+ Rectangle {
+ property string nameData: name
+ objectName: "wrapper"
+ width: 30 + index*root.incrementalSize
+ height: 30 + index*root.incrementalSize
+ border.width: 1
+ Column {
+ Text { text: index }
+ Text { objectName: "name"; text: name }
+ Text { text: parent.parent.y }
+ }
+ onXChanged: root.checkPos(x, y, name)
+ onYChanged: root.checkPos(x, y, name)
+ }
+ }
+
+ populate: populateTransition
+ add: addTransition
+ move: displaced
+ }
+
+ Grid {
+ objectName: "grid"
+
+ property int count: children.length - 1 // omit Repeater
+
+ x: 50; y: 50
+ width: 400; height: 400
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Repeater {
+ objectName: "repeater"
+ model: testedPositioner == "grid" ? testModel : undefined
+ Rectangle {
+ property string nameData: name
+ objectName: "wrapper"
+ width: 30 + index*root.incrementalSize
+ height: 30 + index*root.incrementalSize
+ border.width: 1
+ Column {
+ Text { text: index }
+ Text { objectName: "name"; text: name }
+ Text { text: parent.parent.y }
+ }
+
+ onXChanged: root.checkPos(x, y, name)
+ onYChanged: root.checkPos(x, y, name)
+ }
+ }
+
+ populate: populateTransition
+ add: addTransition
+ move: displaced
+ }
+
+ Flow {
+ objectName: "flow"
+
+ property int count: children.length - 1 // omit Repeater
+
+ x: 50; y: 50
+ width: 400; height: 400
+ padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5
+ Repeater {
+ objectName: "repeater"
+ model: testedPositioner == "flow" ? testModel : undefined
+ Rectangle {
+ property string nameData: name
+ objectName: "wrapper"
+ width: 30 + index*root.incrementalSize
+ height: 30 + index*root.incrementalSize
+ border.width: 1
+ Column {
+ Text { text: index }
+ Text { objectName: "name"; text: name }
+ Text { text: parent.parent.x + " " + parent.parent.y }
+ }
+ onXChanged: root.checkPos(x, y, name)
+ onYChanged: root.checkPos(x, y, name)
+ }
+ }
+
+ populate: populateTransition
+ add: addTransition
+ move: displaced
+ }
+}
+
diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
index 3c44041ca5..c68f58383b 100644
--- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
+++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
@@ -53,33 +53,50 @@ public:
private slots:
void test_horizontal();
+ void test_horizontal_padding();
void test_horizontal_rtl();
void test_horizontal_spacing();
void test_horizontal_spacing_rightToLeft();
void test_horizontal_animated();
+ void test_horizontal_animated_padding();
void test_horizontal_animated_rightToLeft();
+ void test_horizontal_animated_rightToLeft_padding();
void test_horizontal_animated_disabled();
+ void test_horizontal_animated_disabled_padding();
void test_vertical();
+ void test_vertical_padding();
void test_vertical_spacing();
void test_vertical_animated();
+ void test_vertical_animated_padding();
void test_grid();
+ void test_grid_padding();
void test_grid_topToBottom();
void test_grid_rightToLeft();
void test_grid_spacing();
void test_grid_row_column_spacing();
void test_grid_animated();
+ void test_grid_animated_padding();
void test_grid_animated_rightToLeft();
+ void test_grid_animated_rightToLeft_padding();
void test_grid_zero_columns();
void test_grid_H_alignment();
+ void test_grid_H_alignment_padding();
void test_grid_V_alignment();
+ void test_grid_V_alignment_padding();
void test_propertychanges();
void test_repeater();
+ void test_repeater_padding();
void test_flow();
+ void test_flow_padding();
void test_flow_rightToLeft();
void test_flow_topToBottom();
+ void test_flow_topToBottom_padding();
void test_flow_resize();
+ void test_flow_resize_padding();
void test_flow_resize_rightToLeft();
+ void test_flow_resize_rightToLeft_padding();
void test_flow_implicit_resize();
+ void test_flow_implicit_resize_padding();
void test_conflictinganchors();
void test_mirroring();
void test_allInvisible();
@@ -198,18 +215,25 @@ void tst_qquickpositioners::addTransitions_grid_data()
// (adding items further down the grid can cause displace transitions at
// previous indexes, since grid is auto-resized to tightly fit all of its items)
+ QTest::addColumn<QString>("qmlFile");
QTest::addColumn<int>("initialItemCount");
QTest::addColumn<int>("insertionIndex");
QTest::addColumn<int>("insertionCount");
QTest::addColumn<ListRange>("expectedDisplacedIndexes");
- QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9);
- QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9);
- QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7);
+ QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9);
+ QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9);
+ QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7);
+ QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9);
+ QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9);
+ QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7);
- QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9);
- QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9);
- QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9);
+ QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9);
+ QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9);
+ QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9);
+ QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9);
+ QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9);
+ QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9);
}
void tst_qquickpositioners::addTransitions_flow()
@@ -253,17 +277,24 @@ void tst_qquickpositioners::moveTransitions_grid_data()
// (removing items further down the grid can cause displace transitions at
// previous indexes, since grid is auto-resized to tightly fit all of its items)
+ QTest::addColumn<QString>("qmlFile");
QTest::addColumn<int>("initialItemCount");
QTest::addColumn<ListChange>("change");
QTest::addColumn<ListRange>("expectedDisplacedIndexes");
- QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
- QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9);
- QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7);
+ QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
+ QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9);
+ QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7);
+ QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
+ QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9);
+ QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7);
- QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
- QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9);
- QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6);
+ QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
+ QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9);
+ QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6);
+ QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
+ QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9);
+ QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6);
}
void tst_qquickpositioners::moveTransitions_flow()
@@ -305,6 +336,185 @@ void tst_qquickpositioners::test_horizontal()
QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
QCOMPARE(row->width(), 110.0);
QCOMPARE(row->height(), 50.0);
+
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 117.0);
+ QCOMPARE(row->height(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+}
+
+void tst_qquickpositioners::test_horizontal_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("horizontal.qml")));
+
+ window->rootObject()->setProperty("testRightToLeft", false);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 70.0);
+ QCOMPARE(three->y(), 0.0);
+
+ QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
+ QCOMPARE(row->width(), 110.0);
+ QCOMPARE(row->height(), 50.0);
+
+ QQuickRow *obj = qobject_cast<QQuickRow*>(row);
+ QVERIFY(obj != 0);
+
+ QCOMPARE(row->property("padding").toDouble(), 0.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 0.0);
+
+ obj->setPadding(1.0);
+
+ QCOMPARE(row->property("padding").toDouble(), 1.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(row->width(), 112.0);
+ QCOMPARE(row->height(), 52.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 1.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 1.0);
+ QCOMPARE(three->x(), 71.0);
+ QCOMPARE(three->y(), 1.0);
+
+ obj->setTopPadding(2.0);
+
+ QCOMPARE(row->property("padding").toDouble(), 1.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(row->height(), 53.0);
+ QCOMPARE(row->width(), 112.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 71.0);
+ QCOMPARE(three->y(), 2.0);
+
+ obj->setLeftPadding(3.0);
+
+ QCOMPARE(row->property("padding").toDouble(), 1.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(row->width(), 114.0);
+ QCOMPARE(row->height(), 53.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+
+ obj->setRightPadding(4.0);
+
+ QCOMPARE(row->property("padding").toDouble(), 1.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(row->width(), 117.0);
+ QCOMPARE(row->height(), 53.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+
+ obj->setBottomPadding(5.0);
+
+ QCOMPARE(row->property("padding").toDouble(), 1.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 5.0);
+
+ QTRY_COMPARE(row->height(), 57.0);
+ QCOMPARE(row->width(), 117.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+
+ obj->resetBottomPadding();
+ QCOMPARE(row->property("bottomPadding").toDouble(), 1.0);
+ QTRY_COMPARE(row->height(), 53.0);
+ QCOMPARE(row->width(), 117.0);
+
+ obj->resetRightPadding();
+ QCOMPARE(row->property("rightPadding").toDouble(), 1.0);
+ QTRY_COMPARE(row->width(), 114.0);
+ QCOMPARE(row->height(), 53.0);
+
+ obj->resetLeftPadding();
+ QCOMPARE(row->property("leftPadding").toDouble(), 1.0);
+ QTRY_COMPARE(row->width(), 112.0);
+ QCOMPARE(row->height(), 53.0);
+
+ obj->resetTopPadding();
+ QCOMPARE(row->property("topPadding").toDouble(), 1.0);
+ QTRY_COMPARE(row->height(), 52.0);
+ QCOMPARE(row->width(), 112.0);
+
+ obj->resetPadding();
+ QCOMPARE(row->property("padding").toDouble(), 0.0);
+ QCOMPARE(row->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(row->property("bottomPadding").toDouble(), 0.0);
+ QTRY_COMPARE(row->height(), 50.0);
+ QCOMPARE(row->width(), 110.0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 70.0);
+ QCOMPARE(three->y(), 0.0);
}
void tst_qquickpositioners::test_horizontal_rtl()
@@ -333,6 +543,36 @@ void tst_qquickpositioners::test_horizontal_rtl()
QCOMPARE(row->width(), 110.0);
QCOMPARE(row->height(), 50.0);
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 117.0);
+ QCOMPARE(row->height(), 57.0);
+
+ QCOMPARE(one->x(), 63.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 43.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 2.0);
+
+ row->setProperty("topPadding", 0);
+ row->setProperty("leftPadding", 0);
+ row->setProperty("rightPadding", 0);
+ row->setProperty("bottomPadding", 0);
+ row->setProperty("padding", 0);
+
+ QTRY_COMPARE(one->x(), 60.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 40.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 0.0);
+
// Change the width of the row and check that items stay to the right
row->setWidth(200);
QTRY_COMPARE(one->x(), 150.0);
@@ -342,6 +582,18 @@ void tst_qquickpositioners::test_horizontal_rtl()
QCOMPARE(three->x(), 90.0);
QCOMPARE(three->y(), 0.0);
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(one->x(), 146.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 126.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 86.0);
+ QCOMPARE(three->y(), 2.0);
}
void tst_qquickpositioners::test_horizontal_spacing()
@@ -370,6 +622,22 @@ void tst_qquickpositioners::test_horizontal_spacing()
QCOMPARE(row->width(), 130.0);
QCOMPARE(row->height(), 50.0);
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 137.0);
+ QCOMPARE(row->height(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 63.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 93.0);
+ QCOMPARE(three->y(), 2.0);
}
void tst_qquickpositioners::test_horizontal_spacing_rightToLeft()
@@ -391,13 +659,29 @@ void tst_qquickpositioners::test_horizontal_spacing_rightToLeft()
QCOMPARE(one->y(), 0.0);
QCOMPARE(two->x(), 50.0);
QCOMPARE(two->y(), 0.0);
- QCOMPARE(three->x(), 00.0);
+ QCOMPARE(three->x(), 0.0);
QCOMPARE(three->y(), 0.0);
QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
QCOMPARE(row->width(), 130.0);
QCOMPARE(row->height(), 50.0);
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 137.0);
+ QCOMPARE(row->height(), 57.0);
+
+ QCOMPARE(one->x(), 83.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 2.0);
}
void tst_qquickpositioners::test_horizontal_animated()
@@ -453,6 +737,70 @@ void tst_qquickpositioners::test_horizontal_animated()
}
+void tst_qquickpositioners::test_horizontal_animated_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false));
+
+ window->rootObject()->setProperty("testRightToLeft", false);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+
+ //Note that they animate in
+ QCOMPARE(one->x(), -100.0);
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(three->x(), -100.0);
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn
+
+ QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
+ QVERIFY(row);
+ QCOMPARE(row->width(), 100.0);
+ QCOMPARE(row->height(), 50.0);
+
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 107.0);
+ QCOMPARE(row->height(), 57.0);
+
+ //QTRY_COMPARE used instead of waiting for the expected time of animation completion
+ //Note that this means the duration of the animation is NOT tested
+
+ QTRY_COMPARE(one->x(), 3.0);
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(two->isVisible(), false);
+ QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
+ QTRY_COMPARE(two->y(), 0.0);
+ QTRY_COMPARE(three->x(), 53.0);
+ QTRY_COMPARE(three->y(), 2.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QTRY_COMPARE(two->isVisible(), true);
+ QTRY_COMPARE(row->width(), 157.0);
+ QTRY_COMPARE(row->height(), 57.0);
+
+ QTest::qWait(0);//Let the animation start
+ QVERIFY(two->x() >= -100.0 && two->x() < 53.0);
+ QVERIFY(three->x() >= 53.0 && three->x() < 103.0);
+
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(two->x(), 53.0);
+ QTRY_COMPARE(three->x(), 103.0);
+
+}
+
void tst_qquickpositioners::test_horizontal_animated_rightToLeft()
{
QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false));
@@ -508,6 +856,72 @@ void tst_qquickpositioners::test_horizontal_animated_rightToLeft()
}
+void tst_qquickpositioners::test_horizontal_animated_rightToLeft_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false));
+
+ window->rootObject()->setProperty("testRightToLeft", true);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+
+ //Note that they animate in
+ QCOMPARE(one->x(), -100.0);
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(three->x(), -100.0);
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn
+
+ QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
+ QVERIFY(row);
+ QCOMPARE(row->width(), 100.0);
+ QCOMPARE(row->height(), 50.0);
+
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 107.0);
+ QCOMPARE(row->height(), 57.0);
+
+ //QTRY_COMPARE used instead of waiting for the expected time of animation completion
+ //Note that this means the duration of the animation is NOT tested
+
+ QTRY_COMPARE(one->x(), 53.0);
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(two->isVisible(), false);
+ QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
+ QTRY_COMPARE(two->y(), 0.0);
+ QTRY_COMPARE(three->x(), 3.0);
+ QTRY_COMPARE(three->y(), 2.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QTRY_COMPARE(two->isVisible(), true);
+
+ // New size should propagate after visible change
+ QTRY_COMPARE(row->width(), 157.0);
+ QTRY_COMPARE(row->height(), 57.0);
+
+ QTest::qWait(0);//Let the animation start
+ QVERIFY(one->x() >= 53.0 && one->x() < 100);
+ QVERIFY(two->x() >= -100.0 && two->x() < 53.0);
+
+ QTRY_COMPARE(one->x(), 103.0);
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(two->x(), 53.0);
+
+}
+
void tst_qquickpositioners::test_horizontal_animated_disabled()
{
QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml")));
@@ -526,6 +940,54 @@ void tst_qquickpositioners::test_horizontal_animated_disabled()
qApp->processEvents();
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->width(), 107.0);
+ QCOMPARE(row->height(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->isVisible(), false);
+ QCOMPARE(two->x(), -100.0);//Not 'in' yet
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 53.0);
+ QCOMPARE(three->y(), 2.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QCOMPARE(two->isVisible(), true);
+ QTRY_COMPARE(row->width(), 157.0);
+ QTRY_COMPARE(row->height(), 57.0);
+
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(two->x(), 53.0);
+ QTRY_COMPARE(three->x(), 103.0);
+
+}
+
+void tst_qquickpositioners::test_horizontal_animated_disabled_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml")));
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row");
+ QVERIFY(row);
+
+ qApp->processEvents();
+
QCOMPARE(one->x(), 0.0);
QCOMPARE(one->y(), 0.0);
QCOMPARE(two->isVisible(), false);
@@ -547,6 +1009,7 @@ void tst_qquickpositioners::test_horizontal_animated_disabled()
void tst_qquickpositioners::populateTransitions(const QString &positionerObjectName)
{
+ QFETCH(QString, qmlFile);
QFETCH(bool, dynamicallyPopulate);
QFETCH(bool, usePopulateTransition);
@@ -574,7 +1037,7 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN
ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom);
ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
ctxt->setContextProperty("testedPositioner", positionerObjectName);
- window->setSource(testFileUrl("transitions.qml"));
+ window->setSource(testFileUrl(qmlFile));
QQuickItem *positioner = window->rootObject()->findChild<QQuickItem*>(positionerObjectName);
QVERIFY(positioner);
@@ -619,18 +1082,24 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN
void tst_qquickpositioners::populateTransitions_data()
{
+ QTest::addColumn<QString>("qmlFile");
QTest::addColumn<bool>("dynamicallyPopulate");
QTest::addColumn<bool>("usePopulateTransition");
- QTest::newRow("statically populate") << false << true;
- QTest::newRow("statically populate, no populate transition") << false << false;
+ QTest::newRow("statically populate") << "transitions.qml" << false << true;
+ QTest::newRow("statically populate, no populate transition") << "transitions.qml" << false << false;
+ QTest::newRow("padding, statically populate") << "transitions-padding.qml" << false << true;
+ QTest::newRow("padding, statically populate, no populate transition") << "transitions-padding.qml" << false << false;
- QTest::newRow("dynamically populate") << true << true;
- QTest::newRow("dynamically populate, no populate transition") << true << false;
+ QTest::newRow("dynamically populate") << "transitions.qml" << true << true;
+ QTest::newRow("dynamically populate, no populate transition") << "transitions.qml" << true << false;
+ QTest::newRow("padding, dynamically populate") << "transitions-padding.qml" << true << true;
+ QTest::newRow("padding, dynamically populate, no populate transition") << "transitions-padding.qml" << true << false;
}
void tst_qquickpositioners::addTransitions(const QString &positionerObjectName)
{
+ QFETCH(QString, qmlFile);
QFETCH(int, initialItemCount);
QFETCH(int, insertionIndex);
QFETCH(int, insertionCount);
@@ -654,7 +1123,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName)
ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom);
ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
ctxt->setContextProperty("testedPositioner", QString());
- window->setSource(testFileUrl("transitions.qml"));
+ window->setSource(testFileUrl(qmlFile));
window->show();
QTest::qWaitForWindowExposed(window.data());
qApp->processEvents();
@@ -729,22 +1198,30 @@ void tst_qquickpositioners::addTransitions_data()
{
// If this data changes, update addTransitions_grid_data() also
+ QTest::addColumn<QString>("qmlFile");
QTest::addColumn<int>("initialItemCount");
QTest::addColumn<int>("insertionIndex");
QTest::addColumn<int>("insertionCount");
QTest::addColumn<ListRange>("expectedDisplacedIndexes");
- QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9);
- QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(5, 9);
- QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange();
+ QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9);
+ QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(5, 9);
+ QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange();
+ QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9);
+ QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(5, 9);
+ QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange();
- QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9);
- QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(5, 9);
- QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange();
+ QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9);
+ QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(5, 9);
+ QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange();
+ QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9);
+ QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(5, 9);
+ QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange();
}
void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName)
{
+ QFETCH(QString, qmlFile);
QFETCH(int, initialItemCount);
QFETCH(ListChange, change);
QFETCH(ListRange, expectedDisplacedIndexes);
@@ -769,7 +1246,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName)
ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom);
ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia);
ctxt->setContextProperty("testedPositioner", QString());
- window->setSource(testFileUrl("transitions.qml"));
+ window->setSource(testFileUrl(qmlFile));
window->show();
QTest::qWaitForWindowExposed(window.data());
qApp->processEvents();
@@ -840,27 +1317,36 @@ void tst_qquickpositioners::moveTransitions_data()
{
// If this data changes, update moveTransitions_grid_data() also
+ QTest::addColumn<QString>("qmlFile");
QTest::addColumn<int>("initialItemCount");
QTest::addColumn<ListChange>("change");
QTest::addColumn<ListRange>("expectedDisplacedIndexes");
- QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
- QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(5, 9);
- QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange();
+ QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
+ QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9);
+ QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange();
+ QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9);
+ QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9);
+ QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange();
- QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
- QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(7, 9);
- QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange();
+ QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
+ QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9);
+ QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange();
+ QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9);
+ QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9);
+ QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange();
}
-
void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel *model, qreal incrementalSize)
{
QVERIFY(model->count() > 0);
+
+ QQuickBasePositioner *p = qobject_cast<QQuickBasePositioner*>(positioner);
+
qreal padding = 0;
qreal currentSize = 30;
- qreal rowX = 0;
- qreal rowY = 0;
+ qreal rowX = p->leftPadding();
+ qreal rowY = p->topPadding();
for (int i=0; i<model->count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(positioner, "wrapper", i);
@@ -870,11 +1356,11 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel
QCOMPARE(item->height(), currentSize);
if (qobject_cast<QQuickRow*>(positioner)) {
- QCOMPARE(item->x(), (i * 30.0) + padding);
- QCOMPARE(item->y(), 0.0);
+ QCOMPARE(item->x(), (i * 30.0) + padding + p->leftPadding());
+ QCOMPARE(item->y(), p->topPadding());
} else if (qobject_cast<QQuickColumn*>(positioner)) {
- QCOMPARE(item->x(), 0.0);
- QCOMPARE(item->y(), (i * 30.0) + padding);
+ QCOMPARE(item->x(), p->leftPadding());
+ QCOMPARE(item->y(), (i * 30.0) + padding + p->topPadding());
} else if (qobject_cast<QQuickGrid*>(positioner)) {
int columns = 4;
int rows = qCeil(model->count() / qreal(columns));
@@ -886,20 +1372,20 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel
QVERIFY(finalAlignedRowItem);
QCOMPARE(item->x(), finalAlignedRowItem->x());
} else {
- QCOMPARE(item->x(), 0.0);
+ QCOMPARE(item->x(), p->leftPadding());
}
if (i / columns > 0) {
QQuickItem *prevRowLastItem = findItem<QQuickItem>(positioner, "wrapper", (i/columns * columns) - 1);
QVERIFY(prevRowLastItem);
QCOMPARE(item->y(), prevRowLastItem->y() + prevRowLastItem->height());
} else {
- QCOMPARE(item->y(), 0.0);
+ QCOMPARE(item->y(), p->topPadding());
}
} else if (qobject_cast<QQuickFlow*>(positioner)) {
if (rowX + item->width() > positioner->width()) {
QQuickItem *prevItem = findItem<QQuickItem>(positioner, "wrapper", i-1);
QVERIFY(prevItem);
- rowX = 0;
+ rowX = p->leftPadding();
rowY = prevItem->y() + prevItem->height();
}
QCOMPARE(item->x(), rowX);
@@ -942,6 +1428,183 @@ void tst_qquickpositioners::test_vertical()
QCOMPARE(column->height(), 80.0);
QCOMPARE(column->width(), 50.0);
+ // test padding
+ column->setProperty("padding", 1);
+ column->setProperty("topPadding", 2);
+ column->setProperty("leftPadding", 3);
+ column->setProperty("rightPadding", 4);
+ column->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(column->height(), 87.0);
+ QCOMPARE(column->width(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 62.0);
+}
+
+void tst_qquickpositioners::test_vertical_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("vertical.qml")));
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(two->y(), 50.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 60.0);
+
+ QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column");
+ QVERIFY(column);
+ QCOMPARE(column->height(), 80.0);
+ QCOMPARE(column->width(), 50.0);
+
+ QQuickColumn *obj = qobject_cast<QQuickColumn*>(column);
+ QVERIFY(obj != 0);
+
+ QCOMPARE(column->property("padding").toDouble(), 0.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 0.0);
+
+ obj->setPadding(1.0);
+
+ QCOMPARE(column->property("padding").toDouble(), 1.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(column->height(), 82.0);
+ QCOMPARE(column->width(), 52.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 1.0);
+ QCOMPARE(two->x(), 1.0);
+ QCOMPARE(two->y(), 51.0);
+ QCOMPARE(three->x(), 1.0);
+ QCOMPARE(three->y(), 61.0);
+
+ obj->setTopPadding(2.0);
+
+ QCOMPARE(column->property("padding").toDouble(), 1.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(column->height(), 83.0);
+ QCOMPARE(column->width(), 52.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 1.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 1.0);
+ QCOMPARE(three->y(), 62.0);
+
+ obj->setLeftPadding(3.0);
+
+ QCOMPARE(column->property("padding").toDouble(), 1.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(column->width(), 54.0);
+ QCOMPARE(column->height(), 83.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 62.0);
+
+ obj->setRightPadding(4.0);
+
+ QCOMPARE(column->property("padding").toDouble(), 1.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(column->width(), 57.0);
+ QCOMPARE(column->height(), 83.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 62.0);
+
+ obj->setBottomPadding(5.0);
+
+ QCOMPARE(column->property("padding").toDouble(), 1.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 5.0);
+
+ QTRY_COMPARE(column->height(), 87.0);
+ QCOMPARE(column->width(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 62.0);
+
+ obj->resetBottomPadding();
+ QCOMPARE(column->property("bottomPadding").toDouble(), 1.0);
+ QTRY_COMPARE(column->height(), 83.0);
+ QCOMPARE(column->width(), 57.0);
+
+ obj->resetRightPadding();
+ QCOMPARE(column->property("rightPadding").toDouble(), 1.0);
+ QTRY_COMPARE(column->width(), 54.0);
+ QCOMPARE(column->height(), 83.0);
+
+ obj->resetLeftPadding();
+ QCOMPARE(column->property("leftPadding").toDouble(), 1.0);
+ QTRY_COMPARE(column->width(), 52.0);
+ QCOMPARE(column->height(), 83.0);
+
+ obj->resetTopPadding();
+ QCOMPARE(column->property("topPadding").toDouble(), 1.0);
+ QTRY_COMPARE(column->height(), 82.0);
+ QCOMPARE(column->width(), 52.0);
+
+ obj->resetPadding();
+ QCOMPARE(column->property("padding").toDouble(), 0.0);
+ QCOMPARE(column->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(column->property("bottomPadding").toDouble(), 0.0);
+ QTRY_COMPARE(column->height(), 80.0);
+ QCOMPARE(column->width(), 50.0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(two->y(), 50.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 60.0);
}
void tst_qquickpositioners::test_vertical_spacing()
@@ -968,6 +1631,22 @@ void tst_qquickpositioners::test_vertical_spacing()
QCOMPARE(column->height(), 100.0);
QCOMPARE(column->width(), 50.0);
+ // test padding
+ column->setProperty("padding", 1);
+ column->setProperty("topPadding", 2);
+ column->setProperty("leftPadding", 3);
+ column->setProperty("rightPadding", 4);
+ column->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(column->height(), 107.0);
+ QCOMPARE(column->width(), 57.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 62.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 82.0);
}
void tst_qquickpositioners::test_vertical_animated()
@@ -1019,6 +1698,66 @@ void tst_qquickpositioners::test_vertical_animated()
}
+void tst_qquickpositioners::test_vertical_animated_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("vertical-animated.qml"), false));
+
+ //Note that they animate in
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->y(), -100.0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->y(), -100.0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->y(), -100.0);
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn
+
+ QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column");
+ QVERIFY(column);
+ QCOMPARE(column->height(), 100.0);
+ QCOMPARE(column->width(), 50.0);
+
+ // test padding
+ column->setProperty("padding", 1);
+ column->setProperty("topPadding", 2);
+ column->setProperty("leftPadding", 3);
+ column->setProperty("rightPadding", 4);
+ column->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(column->height(), 107.0);
+ QCOMPARE(column->width(), 57.0);
+
+ //QTRY_COMPARE used instead of waiting for the expected time of animation completion
+ //Note that this means the duration of the animation is NOT tested
+
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(one->x(), 3.0);
+ QTRY_COMPARE(two->isVisible(), false);
+ QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet
+ QTRY_COMPARE(two->x(), 0.0);
+ QTRY_COMPARE(three->y(), 52.0);
+ QTRY_COMPARE(three->x(), 3.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QTRY_COMPARE(two->isVisible(), true);
+ QTRY_COMPARE(column->height(), 157.0);
+ QTRY_COMPARE(column->width(), 57.0);
+ QTest::qWait(0);//Let the animation start
+ QVERIFY(two->y() >= -100.0 && two->y() < 52.0);
+ QVERIFY(three->y() >= 52.0 && three->y() < 102.0);
+
+ QTRY_COMPARE(two->x(), 3.0);
+ QTRY_COMPARE(two->y(), 52.0);
+ QTRY_COMPARE(three->y(), 102.0);
+
+}
+
void tst_qquickpositioners::test_grid()
{
QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml")));
@@ -1050,6 +1789,214 @@ void tst_qquickpositioners::test_grid()
QCOMPARE(grid->width(), 100.0);
QCOMPARE(grid->height(), 100.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 52.0);
+}
+
+void tst_qquickpositioners::test_grid_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml")));
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 70.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 50.0);
+
+ QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid");
+ QCOMPARE(grid->flow(), QQuickGrid::LeftToRight);
+ QCOMPARE(grid->width(), 100.0);
+ QCOMPARE(grid->height(), 100.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 0.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0);
+
+ grid->setPadding(1.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 1.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(grid->width(), 102.0);
+ QCOMPARE(grid->height(), 102.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 1.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 1.0);
+ QCOMPARE(three->x(), 71.0);
+ QCOMPARE(three->y(), 1.0);
+ QCOMPARE(four->x(), 1.0);
+ QCOMPARE(four->y(), 51.0);
+ QCOMPARE(five->x(), 51.0);
+ QCOMPARE(five->y(), 51.0);
+
+ grid->setTopPadding(2.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 1.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(grid->height(), 103.0);
+ QCOMPARE(grid->width(), 102.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 71.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 1.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 51.0);
+ QCOMPARE(five->y(), 52.0);
+
+ grid->setLeftPadding(3.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 1.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(grid->width(), 104.0);
+ QCOMPARE(grid->height(), 103.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 52.0);
+
+ grid->setRightPadding(4.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 1.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 103.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 52.0);
+
+ grid->setBottomPadding(5.0);
+
+ QCOMPARE(grid->property("padding").toDouble(), 1.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 5.0);
+
+ QTRY_COMPARE(grid->height(), 107.0);
+ QCOMPARE(grid->width(), 107.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 52.0);
+
+ grid->resetBottomPadding();
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0);
+ QTRY_COMPARE(grid->height(), 103.0);
+ QCOMPARE(grid->width(), 107.0);
+
+ grid->resetRightPadding();
+ QCOMPARE(grid->property("rightPadding").toDouble(), 1.0);
+ QTRY_COMPARE(grid->width(), 104.0);
+ QCOMPARE(grid->height(), 103.0);
+
+ grid->resetLeftPadding();
+ QCOMPARE(grid->property("leftPadding").toDouble(), 1.0);
+ QTRY_COMPARE(grid->width(), 102.0);
+ QCOMPARE(grid->height(), 103.0);
+
+ grid->resetTopPadding();
+ QCOMPARE(grid->property("topPadding").toDouble(), 1.0);
+ QTRY_COMPARE(grid->height(), 102.0);
+ QCOMPARE(grid->width(), 102.0);
+
+ grid->resetPadding();
+ QCOMPARE(grid->property("padding").toDouble(), 0.0);
+ QCOMPARE(grid->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0);
+ QTRY_COMPARE(grid->height(), 100.0);
+ QCOMPARE(grid->width(), 100.0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 70.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 50.0);
}
void tst_qquickpositioners::test_grid_topToBottom()
@@ -1083,6 +2030,26 @@ void tst_qquickpositioners::test_grid_topToBottom()
QCOMPARE(grid->width(), 100.0);
QCOMPARE(grid->height(), 120.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 127.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 3.0);
+ QCOMPARE(two->y(), 52.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 102.0);
+ QCOMPARE(four->x(), 53.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 52.0);
}
void tst_qquickpositioners::test_grid_rightToLeft()
@@ -1118,6 +2085,44 @@ void tst_qquickpositioners::test_grid_rightToLeft()
QCOMPARE(grid->width(), 100.0);
QCOMPARE(grid->height(), 100.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ QCOMPARE(one->x(), 53.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 33.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 53.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 43.0);
+ QCOMPARE(five->y(), 52.0);
+
+ grid->setProperty("topPadding", 0);
+ grid->setProperty("leftPadding", 0);
+ grid->setProperty("rightPadding", 0);
+ grid->setProperty("bottomPadding", 0);
+ grid->setProperty("padding", 0);
+
+ QTRY_COMPARE(one->x(), 50.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 30.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 50.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 40.0);
+ QCOMPARE(five->y(), 50.0);
+
// Change the width of the grid and check that items stay to the right
grid->setWidth(200);
QTRY_COMPARE(one->x(), 150.0);
@@ -1131,6 +2136,22 @@ void tst_qquickpositioners::test_grid_rightToLeft()
QCOMPARE(five->x(), 140.0);
QCOMPARE(five->y(), 50.0);
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(one->x(), 146.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 126.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 96.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 146.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 136.0);
+ QCOMPARE(five->y(), 52.0);
}
void tst_qquickpositioners::test_grid_spacing()
@@ -1163,6 +2184,26 @@ void tst_qquickpositioners::test_grid_spacing()
QCOMPARE(grid->width(), 128.0);
QCOMPARE(grid->height(), 104.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 135.0);
+ QCOMPARE(grid->height(), 111.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 57.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 81.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 56.0);
+ QCOMPARE(five->x(), 57.0);
+ QCOMPARE(five->y(), 56.0);
}
void tst_qquickpositioners::test_grid_row_column_spacing()
@@ -1195,6 +2236,26 @@ void tst_qquickpositioners::test_grid_row_column_spacing()
QCOMPARE(grid->width(), 142.0);
QCOMPARE(grid->height(), 107.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 149.0);
+ QCOMPARE(grid->height(), 114.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 64.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 95.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 59.0);
+ QCOMPARE(five->x(), 64.0);
+ QCOMPARE(five->y(), 59.0);
}
void tst_qquickpositioners::test_grid_animated()
@@ -1281,6 +2342,100 @@ void tst_qquickpositioners::test_grid_animated()
}
+void tst_qquickpositioners::test_grid_animated_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false));
+
+ window->rootObject()->setProperty("testRightToLeft", false);
+
+ //Note that all animate in
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->x(), -100.0);
+ QCOMPARE(one->y(), -100.0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(two->y(), -100.0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->x(), -100.0);
+ QCOMPARE(three->y(), -100.0);
+
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QCOMPARE(four->x(), -100.0);
+ QCOMPARE(four->y(), -100.0);
+
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+ QCOMPARE(five->x(), -100.0);
+ QCOMPARE(five->y(), -100.0);
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn
+
+ QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid");
+ QVERIFY(grid);
+ QCOMPARE(grid->width(), 150.0);
+ QCOMPARE(grid->height(), 100.0);
+
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 157.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ //QTRY_COMPARE used instead of waiting for the expected time of animation completion
+ //Note that this means the duration of the animation is NOT tested
+
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(one->x(), 3.0);
+ QTRY_COMPARE(two->isVisible(), false);
+ QTRY_COMPARE(two->y(), -100.0);
+ QTRY_COMPARE(two->x(), -100.0);
+ QTRY_COMPARE(three->y(), 2.0);
+ QTRY_COMPARE(three->x(), 53.0);
+ QTRY_COMPARE(four->y(), 2.0);
+ QTRY_COMPARE(four->x(), 103.0);
+ QTRY_COMPARE(five->y(), 52.0);
+ QTRY_COMPARE(five->x(), 3.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QCOMPARE(two->isVisible(), true);
+ QCOMPARE(grid->width(), 157.0);
+ QCOMPARE(grid->height(), 107.0);
+ QTest::qWait(0);//Let the animation start
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(two->y(), -100.0);
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(three->x(), 53.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 103.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 3.0);
+ QCOMPARE(five->y(), 52.0);
+ //Let the animation complete
+ QTRY_COMPARE(two->x(), 53.0);
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(one->x(), 3.0);
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(three->x(), 103.0);
+ QTRY_COMPARE(three->y(), 2.0);
+ QTRY_COMPARE(four->x(), 3.0);
+ QTRY_COMPARE(four->y(), 52.0);
+ QTRY_COMPARE(five->x(), 53.0);
+ QTRY_COMPARE(five->y(), 52.0);
+
+}
+
void tst_qquickpositioners::test_grid_animated_rightToLeft()
{
QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false));
@@ -1365,6 +2520,100 @@ void tst_qquickpositioners::test_grid_animated_rightToLeft()
}
+void tst_qquickpositioners::test_grid_animated_rightToLeft_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false));
+
+ window->rootObject()->setProperty("testRightToLeft", true);
+
+ //Note that all animate in
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->x(), -100.0);
+ QCOMPARE(one->y(), -100.0);
+
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(two->y(), -100.0);
+
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->x(), -100.0);
+ QCOMPARE(three->y(), -100.0);
+
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QCOMPARE(four->x(), -100.0);
+ QCOMPARE(four->y(), -100.0);
+
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+ QCOMPARE(five->x(), -100.0);
+ QCOMPARE(five->y(), -100.0);
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn
+
+ QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid");
+ QVERIFY(grid);
+ QCOMPARE(grid->width(), 150.0);
+ QCOMPARE(grid->height(), 100.0);
+
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 157.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ //QTRY_COMPARE used instead of waiting for the expected time of animation completion
+ //Note that this means the duration of the animation is NOT tested
+
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(one->x(), 103.0);
+ QTRY_COMPARE(two->isVisible(), false);
+ QTRY_COMPARE(two->y(), -100.0);
+ QTRY_COMPARE(two->x(), -100.0);
+ QTRY_COMPARE(three->y(), 2.0);
+ QTRY_COMPARE(three->x(), 53.0);
+ QTRY_COMPARE(four->y(), 2.0);
+ QTRY_COMPARE(four->x(), 3.0);
+ QTRY_COMPARE(five->y(), 52.0);
+ QTRY_COMPARE(five->x(), 103.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QCOMPARE(two->isVisible(), true);
+ QCOMPARE(grid->width(), 157.0);
+ QCOMPARE(grid->height(), 107.0);
+ QTest::qWait(0);//Let the animation start
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(two->y(), -100.0);
+ QCOMPARE(one->x(), 103.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(three->x(), 53.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 103.0);
+ QCOMPARE(five->y(), 52.0);
+ //Let the animation complete
+ QTRY_COMPARE(two->x(), 53.0);
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(one->x(), 103.0);
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(three->x(), 3.0);
+ QTRY_COMPARE(three->y(), 2.0);
+ QTRY_COMPARE(four->x(), 103.0);
+ QTRY_COMPARE(four->y(), 52.0);
+ QTRY_COMPARE(five->x(), 53.0);
+ QTRY_COMPARE(five->y(), 52.0);
+
+}
+
void tst_qquickpositioners::test_grid_zero_columns()
{
QScopedPointer<QQuickView> window(createView(testFile("gridzerocolumns.qml")));
@@ -1395,6 +2644,26 @@ void tst_qquickpositioners::test_grid_zero_columns()
QCOMPARE(grid->width(), 170.0);
QCOMPARE(grid->height(), 60.0);
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 177.0);
+ QCOMPARE(grid->height(), 67.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 123.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 3.0);
+ QCOMPARE(five->y(), 52.0);
}
void tst_qquickpositioners::test_grid_H_alignment()
@@ -1476,6 +2745,95 @@ void tst_qquickpositioners::test_grid_H_alignment()
}
+void tst_qquickpositioners::test_grid_H_alignment_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml")));
+
+ window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 70.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 55.0);
+ QCOMPARE(five->y(), 50.0);
+
+ QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid");
+ QCOMPARE(grid->width(), 100.0);
+ QCOMPARE(grid->height(), 100.0);
+
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignRight);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 63.0);
+ QCOMPARE(five->y(), 52.0);
+ QCOMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ window->rootObject()->setProperty("testRightToLeft", true);
+
+ QCOMPARE(one->x(), 53.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 33.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 53.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 33.0);
+ QCOMPARE(five->y(), 52.0);
+ QCOMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter);
+
+ QCOMPARE(one->x(), 53.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 33.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 2.0);
+ QCOMPARE(four->x(), 53.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 38.0);
+ QCOMPARE(five->y(), 52.0);
+ QCOMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+}
+
void tst_qquickpositioners::test_grid_V_alignment()
{
QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml")));
@@ -1519,6 +2877,63 @@ void tst_qquickpositioners::test_grid_V_alignment()
}
+void tst_qquickpositioners::test_grid_V_alignment_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml")));
+
+ window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignVCenter);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid");
+ QCOMPARE(grid->width(), 100.0);
+ QCOMPARE(grid->height(), 100.0);
+
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->width(), 107.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 17.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 72.0);
+
+ window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignBottom);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 73.0);
+ QCOMPARE(three->y(), 32.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 92.0);
+
+}
+
void tst_qquickpositioners::test_propertychanges()
{
QScopedPointer<QQuickView> window(createView(testFile("propertychangestest.qml")));
@@ -1599,6 +3014,28 @@ void tst_qquickpositioners::test_repeater()
}
+void tst_qquickpositioners::test_repeater_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("repeatertest-padding.qml")));
+
+ QQuickRectangle *one = findItem<QQuickRectangle>(window->contentItem(), "one");
+ QVERIFY(one != 0);
+
+ QQuickRectangle *two = findItem<QQuickRectangle>(window->contentItem(), "two");
+ QVERIFY(two != 0);
+
+ QQuickRectangle *three = findItem<QQuickRectangle>(window->contentItem(), "three");
+ QVERIFY(three != 0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 103.0);
+ QCOMPARE(three->y(), 2.0);
+
+}
+
void tst_qquickpositioners::test_flow()
{
QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml")));
@@ -1632,6 +3069,219 @@ void tst_qquickpositioners::test_flow()
QCOMPARE(flow->width(), 90.0);
QCOMPARE(flow->height(), 120.0);
+ // test padding
+ flow->setProperty("padding", 1);
+ flow->setProperty("topPadding", 2);
+ flow->setProperty("leftPadding", 3);
+ flow->setProperty("rightPadding", 4);
+ flow->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(flow->height(), 127.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 72.0);
+}
+
+void tst_qquickpositioners::test_flow_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml")));
+
+ window->rootObject()->setProperty("testRightToLeft", false);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 50.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 70.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 70.0);
+
+ QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow");
+ QVERIFY(flow);
+ QCOMPARE(flow->width(), 90.0);
+ QCOMPARE(flow->height(), 120.0);
+
+ QQuickFlow *obj = qobject_cast<QQuickFlow*>(flow);
+ QVERIFY(obj != 0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 0.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0);
+
+ obj->setPadding(1.0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 1.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(flow->height(), 122.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 1.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 1.0);
+ QCOMPARE(three->x(), 1.0);
+ QCOMPARE(three->y(), 51.0);
+ QCOMPARE(four->x(), 1.0);
+ QCOMPARE(four->y(), 71.0);
+ QCOMPARE(five->x(), 51.0);
+ QCOMPARE(five->y(), 71.0);
+
+ obj->setTopPadding(2.0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 1.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0);
+
+ QTRY_COMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 1.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 1.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 1.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 51.0);
+ QCOMPARE(five->y(), 72.0);
+
+ obj->setLeftPadding(3.0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 1.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 1.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0);
+
+ QCOMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QTRY_COMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 72.0);
+
+ obj->setRightPadding(4.0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 1.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0);
+
+ QCOMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QTRY_COMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 72.0);
+
+ obj->setBottomPadding(5.0);
+
+ QCOMPARE(flow->property("padding").toDouble(), 1.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 2.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 3.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 4.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 5.0);
+
+ QTRY_COMPARE(flow->height(), 127.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 3.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 53.0);
+ QCOMPARE(five->y(), 72.0);
+
+ obj->resetBottomPadding();
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0);
+ QTRY_COMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ obj->resetRightPadding();
+ QCOMPARE(flow->property("rightPadding").toDouble(), 1.0);
+ QTRY_COMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ obj->resetLeftPadding();
+ QCOMPARE(flow->property("leftPadding").toDouble(), 1.0);
+ QTRY_COMPARE(flow->height(), 123.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ obj->resetTopPadding();
+ QCOMPARE(flow->property("topPadding").toDouble(), 1.0);
+ QTRY_COMPARE(flow->height(), 122.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ obj->resetPadding();
+ QCOMPARE(flow->property("padding").toDouble(), 0.0);
+ QCOMPARE(flow->property("topPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("leftPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("rightPadding").toDouble(), 0.0);
+ QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0);
+ QTRY_COMPARE(flow->height(), 120.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 0.0);
+ QCOMPARE(three->y(), 50.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 70.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 70.0);
}
void tst_qquickpositioners::test_flow_rightToLeft()
@@ -1667,6 +3317,26 @@ void tst_qquickpositioners::test_flow_rightToLeft()
QCOMPARE(flow->width(), 90.0);
QCOMPARE(flow->height(), 120.0);
+ // test padding
+ flow->setProperty("padding", 1);
+ flow->setProperty("topPadding", 2);
+ flow->setProperty("leftPadding", 3);
+ flow->setProperty("rightPadding", 4);
+ flow->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(flow->height(), 127.0);
+ QCOMPARE(flow->width(), 90.0);
+
+ QCOMPARE(one->x(), 36.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 16.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 36.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 36.0);
+ QCOMPARE(four->y(), 72.0);
+ QCOMPARE(five->x(), 26.0);
+ QCOMPARE(five->y(), 72.0);
}
void tst_qquickpositioners::test_flow_topToBottom()
@@ -1693,7 +3363,7 @@ void tst_qquickpositioners::test_flow_topToBottom()
QCOMPARE(three->x(), 50.0);
QCOMPARE(three->y(), 50.0);
QCOMPARE(four->x(), 100.0);
- QCOMPARE(four->y(), 00.0);
+ QCOMPARE(four->y(), 0.0);
QCOMPARE(five->x(), 100.0);
QCOMPARE(five->y(), 50.0);
@@ -1721,6 +3391,79 @@ void tst_qquickpositioners::test_flow_topToBottom()
}
+void tst_qquickpositioners::test_flow_topToBottom_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("flowtest-toptobottom.qml")));
+
+ window->rootObject()->setProperty("testRightToLeft", false);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(three->y(), 50.0);
+ QCOMPARE(four->x(), 100.0);
+ QCOMPARE(four->y(), 0.0);
+ QCOMPARE(five->x(), 100.0);
+ QCOMPARE(five->y(), 50.0);
+
+ QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow");
+ QVERIFY(flow);
+ QCOMPARE(flow->height(), 90.0);
+ QCOMPARE(flow->width(), 150.0);
+
+ // test padding
+ flow->setProperty("padding", 1);
+ flow->setProperty("topPadding", 2);
+ flow->setProperty("leftPadding", 3);
+ flow->setProperty("rightPadding", 4);
+ flow->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(flow->width(), 157.0);
+ QCOMPARE(flow->height(), 90.0);
+
+ QCOMPARE(one->x(), 3.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 53.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 53.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 103.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 103.0);
+ QCOMPARE(five->y(), 52.0);
+
+ window->rootObject()->setProperty("testRightToLeft", true);
+
+ QVERIFY(flow);
+ QTRY_COMPARE(flow->width(), 157.0);
+ QCOMPARE(flow->height(), 90.0);
+
+ QCOMPARE(one->x(), 103.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 83.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 53.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 3.0);
+ QCOMPARE(four->y(), 2.0);
+ QCOMPARE(five->x(), 43.0);
+ QCOMPARE(five->y(), 52.0);
+
+}
+
void tst_qquickpositioners::test_flow_resize()
{
QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml")));
@@ -1754,6 +3497,39 @@ void tst_qquickpositioners::test_flow_resize()
}
+void tst_qquickpositioners::test_flow_resize_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml")));
+
+ QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject());
+ QVERIFY(root);
+ root->setWidth(125);
+ root->setProperty("testRightToLeft", false);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QVERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QTRY_COMPARE(one->x(), 3.0);
+ QTRY_COMPARE(one->y(), 2.0);
+ QTRY_COMPARE(two->x(), 53.0);
+ QTRY_COMPARE(two->y(), 2.0);
+ QTRY_COMPARE(three->x(), 3.0);
+ QTRY_COMPARE(three->y(), 52.0);
+ QTRY_COMPARE(four->x(), 53.0);
+ QTRY_COMPARE(four->y(), 52.0);
+ QTRY_COMPARE(five->x(), 103.0);
+ QTRY_COMPARE(five->y(), 52.0);
+
+}
+
void tst_qquickpositioners::test_flow_resize_rightToLeft()
{
QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml")));
@@ -1787,6 +3563,39 @@ void tst_qquickpositioners::test_flow_resize_rightToLeft()
}
+void tst_qquickpositioners::test_flow_resize_rightToLeft_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml")));
+
+ QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject());
+ QVERIFY(root);
+ root->setWidth(125);
+ root->setProperty("testRightToLeft", true);
+
+ QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one");
+ QTRY_VERIFY(one != 0);
+ QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two");
+ QVERIFY(two != 0);
+ QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three");
+ QVERIFY(three != 0);
+ QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four");
+ QVERIFY(four != 0);
+ QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 71.0);
+ QCOMPARE(one->y(), 2.0);
+ QCOMPARE(two->x(), 51.0);
+ QCOMPARE(two->y(), 2.0);
+ QCOMPARE(three->x(), 71.0);
+ QCOMPARE(three->y(), 52.0);
+ QCOMPARE(four->x(), 21.0);
+ QCOMPARE(four->y(), 52.0);
+ QCOMPARE(five->x(), 11.0);
+ QCOMPARE(five->y(), 52.0);
+
+}
+
void tst_qquickpositioners::test_flow_implicit_resize()
{
QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml")));
@@ -1815,6 +3624,44 @@ void tst_qquickpositioners::test_flow_implicit_resize()
}
+void tst_qquickpositioners::test_flow_implicit_resize_padding()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml")));
+ QVERIFY(window->rootObject() != 0);
+
+ QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow");
+ QVERIFY(flow != 0);
+
+ QCOMPARE(flow->width(), 100.0);
+ QCOMPARE(flow->height(), 120.0);
+
+ // test padding
+ flow->setProperty("padding", 1);
+ flow->setProperty("topPadding", 2);
+ flow->setProperty("leftPadding", 3);
+ flow->setProperty("rightPadding", 4);
+ flow->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(flow->width(), 107.0);
+ QCOMPARE(flow->height(), 127.0);
+
+ window->rootObject()->setProperty("flowLayout", 0);
+ QCOMPARE(flow->flow(), QQuickFlow::LeftToRight);
+ QCOMPARE(flow->width(), 227.0);
+ QCOMPARE(flow->height(), 57.0);
+
+ window->rootObject()->setProperty("flowLayout", 1);
+ QCOMPARE(flow->flow(), QQuickFlow::TopToBottom);
+ QCOMPARE(flow->width(), 107.0);
+ QCOMPARE(flow->height(), 127.0);
+
+ window->rootObject()->setProperty("flowLayout", 2);
+ QCOMPARE(flow->layoutDirection(), Qt::RightToLeft);
+ QCOMPARE(flow->width(), 227.0);
+ QCOMPARE(flow->height(), 57.0);
+
+}
+
void tst_qquickpositioners::test_conflictinganchors()
{
QQmlTestMessageHandler messageHandler;
@@ -1924,7 +3771,9 @@ void tst_qquickpositioners::test_conflictinganchors()
void tst_qquickpositioners::test_mirroring()
{
QList<QString> qmlFiles;
- qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml";
+ qmlFiles << "horizontal.qml" << "horizontal-padding.qml"
+ << "gridtest.qml" << "gridtest-padding.qml"
+ << "flowtest.qml" << "flowtest-padding.qml";
QList<QString> objectNames;
objectNames << "one" << "two" << "three" << "four" << "five";
@@ -1942,8 +3791,8 @@ void tst_qquickpositioners::test_mirroring()
// LTR != RTL
foreach (const QString objectName, objectNames) {
- // horizontal.qml only has three items
- if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
+ // horizontal.qml and horizontal-padding.qml only have three items
+ if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four"))
break;
QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName);
QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName);
@@ -1957,8 +3806,8 @@ void tst_qquickpositioners::test_mirroring()
// RTL == mirror
foreach (const QString objectName, objectNames) {
- // horizontal.qml only has three items
- if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
+ // horizontal.qml and horizontal-padding.qml only have three items
+ if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four"))
break;
QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName);
QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName);
@@ -1978,8 +3827,8 @@ void tst_qquickpositioners::test_mirroring()
// LTR == RTL + mirror
foreach (const QString objectName, objectNames) {
- // horizontal.qml only has three items
- if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
+ // horizontal.qml and horizontal-padding.qml only have three items
+ if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four"))
break;
QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName);
QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName);
@@ -2000,10 +3849,61 @@ void tst_qquickpositioners::test_allInvisible()
QVERIFY(row != 0);
QVERIFY(row->width() == 0);
QVERIFY(row->height() == 0);
+
+ // test padding
+ row->setProperty("padding", 1);
+ row->setProperty("topPadding", 2);
+ row->setProperty("leftPadding", 3);
+ row->setProperty("rightPadding", 4);
+ row->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(row->height(), 7.0);
+ QCOMPARE(row->width(), 7.0);
+
QQuickColumn *column = window->rootObject()->findChild<QQuickColumn*>("column");
QVERIFY(column != 0);
QVERIFY(column->width() == 0);
QVERIFY(column->height() == 0);
+
+ // test padding
+ column->setProperty("padding", 1);
+ column->setProperty("topPadding", 2);
+ column->setProperty("leftPadding", 3);
+ column->setProperty("rightPadding", 4);
+ column->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(column->height(), 7.0);
+ QCOMPARE(column->width(), 7.0);
+
+ QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid");
+ QVERIFY(grid != 0);
+ QVERIFY(grid->width() == 0);
+ QVERIFY(grid->height() == 0);
+
+ // test padding
+ grid->setProperty("padding", 1);
+ grid->setProperty("topPadding", 2);
+ grid->setProperty("leftPadding", 3);
+ grid->setProperty("rightPadding", 4);
+ grid->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(grid->height(), 7.0);
+ QCOMPARE(grid->width(), 7.0);
+
+ QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow");
+ QVERIFY(flow != 0);
+ QVERIFY(flow->width() == 0);
+ QVERIFY(flow->height() == 0);
+
+ // test padding
+ flow->setProperty("padding", 1);
+ flow->setProperty("topPadding", 2);
+ flow->setProperty("leftPadding", 3);
+ flow->setProperty("rightPadding", 4);
+ flow->setProperty("bottomPadding", 5);
+
+ QTRY_COMPARE(flow->height(), 7.0);
+ QCOMPARE(flow->width(), 7.0);
}
void tst_qquickpositioners::test_attachedproperties()