summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/graphicsview/qgraphicsgridlayout.cpp11
-rw-r--r--src/gui/graphicsview/qgraphicslinearlayout.cpp4
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp185
-rw-r--r--src/gui/graphicsview/qgridlayoutengine_p.h7
-rw-r--r--tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp366
-rw-r--r--tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp118
6 files changed, 587 insertions, 104 deletions
diff --git a/src/gui/graphicsview/qgraphicsgridlayout.cpp b/src/gui/graphicsview/qgraphicsgridlayout.cpp
index 3fc7f10..20ebab6 100644
--- a/src/gui/graphicsview/qgraphicsgridlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsgridlayout.cpp
@@ -64,6 +64,17 @@
removeAt() will remove an item from the layout, without
destroying it.
+ \section1 Size Hints and Size Policies in QGraphicsGridLayout
+
+ QGraphicsGridLayout respects each item's size hints and size policies,
+ and when a cell in the grid has more space than the items can fill, each item
+ is arranged according to the layout's alignment for that item. You can set
+ an alignment for each item by calling setAlignment(), and check the
+ alignment for any item by calling alignment(). You can also set the alignment
+ for an entire row or column by calling setRowAlignment() and setColumnAlignment()
+ respectively. By default, items are aligned to the top left.
+
+
\sa QGraphicsLinearLayout, QGraphicsWidget
*/
diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp
index 7e8d19f..244a728 100644
--- a/src/gui/graphicsview/qgraphicslinearlayout.cpp
+++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp
@@ -75,7 +75,7 @@
is arranged according to the layout's alignment for that item. You can set
an alignment for each item by calling setAlignment(), and check the
alignment for any item by calling alignment(). By default, items are
- centered both vertically and horizontally.
+ aligned to the top left.
\section1 Spacing within QGraphicsLinearLayout
@@ -446,7 +446,7 @@ void QGraphicsLinearLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignmen
/*!
Returns the alignment for \a item. The default alignment is
- Qt::AlignCenter.
+ Qt::AlignTop | Qt::AlignLeft.
The alignment decides how the item is positioned within its assigned space
in the case where there's more space available in the layout than the
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index e486b4d..f1055ba 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -166,7 +166,7 @@ void QGridLayoutRowData::reset(int count)
hasIgnoreFlag = false;
}
-void QGridLayoutRowData::distributeMultiCells()
+void QGridLayoutRowData::distributeMultiCells(const QGridLayoutRowInfo &rowInfo)
{
MultiCellMap::const_iterator i = multiCellMap.constBegin();
for (; i != multiCellMap.constEnd(); ++i) {
@@ -185,7 +185,7 @@ void QGridLayoutRowData::distributeMultiCells()
qreal extra = compare(box, totalBox, j);
if (extra > 0.0) {
calculateGeometries(start, end, box.q_sizes(j), dummy.data(), newSizes.data(),
- 0, totalBox);
+ 0, totalBox, rowInfo);
for (int k = 0; k < span; ++k)
extras[k].q_sizes(j) = newSizes[k];
@@ -202,11 +202,12 @@ void QGridLayoutRowData::distributeMultiCells()
void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSize, qreal *positions,
qreal *sizes, qreal *descents,
- const QGridLayoutBox &totalBox)
+ const QGridLayoutBox &totalBox,
+ const QGridLayoutRowInfo &rowInfo)
{
Q_ASSERT(end > start);
- targetSize = qBound(totalBox.q_minimumSize, targetSize, totalBox.q_maximumSize);
+ targetSize = qMax(totalBox.q_minimumSize, targetSize);
int n = end - start;
QVarLengthArray<qreal> newSizes(n);
@@ -246,16 +247,22 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
}
}
} else {
- stealBox(start, end, PreferredSize, positions, sizes);
+ bool isLargerThanMaximum = (targetSize > totalBox.q_maximumSize);
+ if (isLargerThanMaximum) {
+ stealBox(start, end, MaximumSize, positions, sizes);
+ sumAvailable = targetSize - totalBox.q_maximumSize;
+ } else {
+ stealBox(start, end, PreferredSize, positions, sizes);
+ sumAvailable = targetSize - totalBox.q_preferredSize;
+ }
- sumAvailable = targetSize - totalBox.q_preferredSize;
if (sumAvailable > 0.0) {
qreal sumCurrentAvailable = sumAvailable;
bool somethingHasAMaximumSize = false;
- qreal sumPreferredSizes = 0.0;
+ qreal sumSizes = 0.0;
for (int i = 0; i < n; ++i)
- sumPreferredSizes += sizes[i];
+ sumSizes += sizes[i];
for (int i = 0; i < n; ++i) {
if (ignore.testBit(start + i)) {
@@ -265,7 +272,16 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
}
const QGridLayoutBox &box = boxes.at(start + i);
- qreal desired = box.q_maximumSize - box.q_preferredSize;
+ qreal boxSize;
+
+ qreal desired;
+ if (isLargerThanMaximum) {
+ boxSize = box.q_maximumSize;
+ desired = rowInfo.boxes.value(start + i).q_maximumSize - boxSize;
+ } else {
+ boxSize = box.q_preferredSize;
+ desired = box.q_maximumSize - boxSize;
+ }
if (desired == 0.0) {
newSizes[i] = sizes[i];
factors[i] = 0.0;
@@ -284,17 +300,17 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
} else if (stretch <= 0) {
factors[i] = 0.0;
} else {
- qreal ultimatePreferredSize;
- qreal ultimateSumPreferredSizes;
- qreal x = ((stretch * sumPreferredSizes)
- - (sumStretches * box.q_preferredSize))
+ qreal ultimateSize;
+ qreal ultimateSumSizes;
+ qreal x = ((stretch * sumSizes)
+ - (sumStretches * boxSize))
/ (sumStretches - stretch);
if (x >= 0.0) {
- ultimatePreferredSize = box.q_preferredSize + x;
- ultimateSumPreferredSizes = sumPreferredSizes + x;
+ ultimateSize = boxSize + x;
+ ultimateSumSizes = sumSizes + x;
} else {
- ultimatePreferredSize = box.q_preferredSize;
- ultimateSumPreferredSizes = (sumStretches * box.q_preferredSize)
+ ultimateSize = boxSize;
+ ultimateSumSizes = (sumStretches * boxSize)
/ stretch;
}
@@ -303,17 +319,17 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
(at the expense of the stretch factors, which are not fully respected
during the transition).
*/
- ultimatePreferredSize = ultimatePreferredSize * 3 / 2;
- ultimateSumPreferredSizes = ultimateSumPreferredSizes * 3 / 2;
+ ultimateSize = ultimateSize * 3 / 2;
+ ultimateSumSizes = ultimateSumSizes * 3 / 2;
- qreal beta = ultimateSumPreferredSizes - sumPreferredSizes;
+ qreal beta = ultimateSumSizes - sumSizes;
if (!beta) {
factors[i] = 1;
} else {
qreal alpha = qMin(sumCurrentAvailable, beta);
- qreal ultimateFactor = (stretch * ultimateSumPreferredSizes / sumStretches)
- - (box.q_preferredSize);
- qreal transitionalFactor = sumCurrentAvailable * (ultimatePreferredSize - box.q_preferredSize) / beta;
+ qreal ultimateFactor = (stretch * ultimateSumSizes / sumStretches)
+ - (boxSize);
+ qreal transitionalFactor = sumCurrentAvailable * (ultimateSize - boxSize) / beta;
factors[i] = ((alpha * ultimateFactor)
+ ((beta - alpha) * transitionalFactor)) / beta;
@@ -336,11 +352,16 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
if (newSizes[i] >= 0.0)
continue;
- const QGridLayoutBox &box = boxes.at(start + i);
+ qreal maxBoxSize;
+ if (isLargerThanMaximum)
+ maxBoxSize = rowInfo.boxes.value(start + i).q_maximumSize;
+ else
+ maxBoxSize = boxes.at(start + i).q_maximumSize;
+
qreal avail = sumCurrentAvailable * factors[i] / sumFactors;
- if (sizes[i] + avail >= box.q_maximumSize) {
- newSizes[i] = box.q_maximumSize;
- sumCurrentAvailable -= box.q_maximumSize - sizes[i];
+ if (sizes[i] + avail >= maxBoxSize) {
+ newSizes[i] = maxBoxSize;
+ sumCurrentAvailable -= maxBoxSize - sizes[i];
sumFactors -= factors[i];
keepGoing = (sumCurrentAvailable > 0.0);
if (!keepGoing)
@@ -637,7 +658,7 @@ QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal heig
if (dynamicConstraintOrientation() == Qt::Vertical) {
if (size.width() > cellWidth)
size = effectiveMaxSize(QSizeF(cellWidth, -1));
- } else if(size.height() > cellHeight) {
+ } else if (size.height() > cellHeight) {
size = effectiveMaxSize(QSizeF(-1, cellHeight));
}
}
@@ -1107,63 +1128,58 @@ QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHi
{
QGridLayoutBox sizehint_totalBoxes[NOrientations];
- if(rowCount() < 1 || columnCount() < 1 || !hasDynamicConstraint()) {
+ bool sizeHintCalculated = false;
+
+ if (hasDynamicConstraint() && rowCount() > 0 && columnCount() > 0) {
+ if (constraintOrientation() == Qt::Vertical) {
+ //We have items whose height depends on their width
+ if (constraint.width() >= 0) {
+ if (q_cachedDataForStyleInfo != styleInfo)
+ ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
+ else
+ sizehint_totalBoxes[Hor] = q_totalBoxes[Hor];
+ QVector<qreal> sizehint_xx;
+ QVector<qreal> sizehint_widths;
+
+ sizehint_xx.resize(columnCount());
+ sizehint_widths.resize(columnCount());
+ qreal width = constraint.width();
+ //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as
+ //constraints to find the row heights
+ q_columnData.calculateGeometries(0, columnCount(), width, sizehint_xx.data(), sizehint_widths.data(),
+ 0, sizehint_totalBoxes[Hor], q_infos[Hor]);
+ ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, sizehint_xx.data(), sizehint_widths.data(), Qt::Vertical);
+ sizeHintCalculated = true;
+ }
+ } else {
+ if (constraint.height() >= 0) {
+ //We have items whose width depends on their height
+ ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
+ QVector<qreal> sizehint_yy;
+ QVector<qreal> sizehint_heights;
+
+ sizehint_yy.resize(rowCount());
+ sizehint_heights.resize(rowCount());
+ qreal height = constraint.height();
+ //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as
+ //constraints to find the column widths
+ q_rowData.calculateGeometries(0, rowCount(), height, sizehint_yy.data(), sizehint_heights.data(),
+ 0, sizehint_totalBoxes[Ver], q_infos[Ver]);
+ ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, sizehint_yy.data(), sizehint_heights.data(), Qt::Vertical);
+ sizeHintCalculated = true;
+ }
+ }
+ }
+
+ if (!sizeHintCalculated) {
//No items with height for width, so it doesn't matter which order we do these in
- if(q_cachedDataForStyleInfo != styleInfo) {
+ if (q_cachedDataForStyleInfo != styleInfo) {
ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
} else {
sizehint_totalBoxes[Hor] = q_totalBoxes[Hor];
sizehint_totalBoxes[Ver] = q_totalBoxes[Ver];
}
- } else if(constraintOrientation() == Qt::Vertical) {
- //We have items whose width depends on their height
- if(q_cachedDataForStyleInfo != styleInfo)
- ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
- else
- sizehint_totalBoxes[Hor] = q_totalBoxes[Hor];
- QVector<qreal> sizehint_xx;
- QVector<qreal> sizehint_widths;
-
- sizehint_xx.resize(columnCount());
- sizehint_widths.resize(columnCount());
- qreal width = constraint.width();
- if(width < 0) {
- /* It's not obvious what the behaviour should be. */
-/* if(which == Qt::MaximumSize)
- width = sizehint_totalBoxes[Hor].q_maximumSize;
- else if(which == Qt::MinimumSize)
- width = sizehint_totalBoxes[Hor].q_minimumSize;
- else*/
- width = sizehint_totalBoxes[Hor].q_preferredSize;
- }
- //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as
- //constraints to find the row heights
- q_columnData.calculateGeometries(0, columnCount(), width, sizehint_xx.data(), sizehint_widths.data(),
- 0, sizehint_totalBoxes[Hor]);
- ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, sizehint_xx.data(), sizehint_widths.data(), Qt::Vertical);
- } else {
- //We have items whose height depends on their width
- ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
- QVector<qreal> sizehint_yy;
- QVector<qreal> sizehint_heights;
-
- sizehint_yy.resize(rowCount());
- sizehint_heights.resize(rowCount());
- qreal height = constraint.height();
- if(height < 0) {
-/* if(which == Qt::MaximumSize)
- height = sizehint_totalBoxes[Ver].q_maximumSize;
- else if(which == Qt::MinimumSize)
- height = sizehint_totalBoxes[Ver].q_minimumSize;
- else*/
- height = sizehint_totalBoxes[Ver].q_preferredSize;
- }
- //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as
- //constraints to find the column widths
- q_rowData.calculateGeometries(0, rowCount(), height, sizehint_yy.data(), sizehint_heights.data(),
- 0, sizehint_totalBoxes[Ver]);
- ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, sizehint_yy.data(), sizehint_heights.data(), Qt::Vertical);
}
switch (which) {
@@ -1622,7 +1638,8 @@ void QGridLayoutEngine::ensureColumnAndRowData(QGridLayoutRowData *rowData, QGri
{
rowData->reset(rowCount(orientation));
fillRowData(rowData, styleInfo, colPositions, colSizes, orientation);
- rowData->distributeMultiCells();
+ const QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical];
+ rowData->distributeMultiCells(rowInfo);
*totalBox = rowData->totalBox(0, rowCount(orientation));
//We have items whose width depends on their height
}
@@ -1685,28 +1702,28 @@ void QGridLayoutEngine::ensureGeometries(const QLayoutStyleInfo &styleInfo,
q_heights.resize(rowCount());
q_descents.resize(rowCount());
- if(constraintOrientation() != Qt::Horizontal) {
+ if (constraintOrientation() != Qt::Horizontal) {
//We might have items whose width depends on their height
ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], styleInfo, NULL, NULL, Qt::Horizontal);
//Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as
//constraints to find the row heights
q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(),
- 0, q_totalBoxes[Hor]);
+ 0, q_totalBoxes[Hor], q_infos[Hor] );
ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], styleInfo, q_xx.data(), q_widths.data(), Qt::Vertical);
//Calculate row heights and positions, and put results in q_yy.data() and q_heights.data()
q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(),
- q_descents.data(), q_totalBoxes[Ver]);
+ q_descents.data(), q_totalBoxes[Ver], q_infos[Ver]);
} else {
//We have items whose height depends on their width
ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], styleInfo, NULL, NULL, Qt::Vertical);
//Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as
//constraints to find the column widths
q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(),
- q_descents.data(), q_totalBoxes[Ver]);
+ q_descents.data(), q_totalBoxes[Ver], q_infos[Ver]);
ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], styleInfo, q_yy.data(), q_heights.data(), Qt::Horizontal);
//Calculate row heights and positions, and put results in q_yy.data() and q_heights.data()
q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(),
- 0, q_totalBoxes[Hor]);
+ 0, q_totalBoxes[Hor], q_infos[Hor]);
}
}
diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h
index 02c74b0..44efbba 100644
--- a/src/gui/graphicsview/qgridlayoutengine_p.h
+++ b/src/gui/graphicsview/qgridlayoutengine_p.h
@@ -224,13 +224,16 @@ public:
typedef QMap<QPair<int, int>, QGridLayoutMultiCellData> MultiCellMap;
+class QGridLayoutRowInfo;
+
class QGridLayoutRowData
{
public:
void reset(int count);
- void distributeMultiCells();
+ void distributeMultiCells(const QGridLayoutRowInfo &rowInfo);
void calculateGeometries(int start, int end, qreal targetSize, qreal *positions, qreal *sizes,
- qreal *descents, const QGridLayoutBox &totalBox);
+ qreal *descents, const QGridLayoutBox &totalBox,
+ const QGridLayoutRowInfo &rowInfo);
QGridLayoutBox totalBox(int start, int end) const;
void stealBox(int start, int end, int which, qreal *positions, qreal *sizes);
diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index 174e4aa..2e52c4e 100644
--- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -122,6 +122,8 @@ private slots:
void task236367_maxSizeHint();
void heightForWidth();
void heightForWidthWithSpanning();
+ void stretchAndHeightForWidth();
+ void testDefaultAlignment();
};
class RectWidget : public QGraphicsWidget
@@ -699,6 +701,10 @@ void tst_QGraphicsGridLayout::columnMaximumWidth()
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
+ QCOMPARE(layout->minimumSize(), QSizeF(10+10+10, 10+10));
+ QCOMPARE(layout->preferredSize(), QSizeF(25+25+25, 25+25));
+ QCOMPARE(layout->maximumSize(), QSizeF(50+50+50, 50+50));
+
// should at least be a very large number
QVERIFY(layout->columnMaximumWidth(0) >= 10000);
QCOMPARE(layout->columnMaximumWidth(0), layout->columnMaximumWidth(1));
@@ -706,17 +712,65 @@ void tst_QGraphicsGridLayout::columnMaximumWidth()
layout->setColumnMaximumWidth(0, 20);
layout->setColumnMaximumWidth(2, 60);
- view.show();
- widget->show();
+ QCOMPARE(layout->minimumSize(), QSizeF(10+10+10, 10+10));
+ QCOMPARE(layout->preferredSize(), QSizeF(20+25+25, 25+25));
+ QCOMPARE(layout->maximumSize(), QSizeF(20+50+60, 50+50));
+ QCOMPARE(layout->maximumSize(), widget->maximumSize());
+
widget->resize(widget->effectiveSizeHint(Qt::PreferredSize));
- QApplication::processEvents();
+ layout->activate();
- QCOMPARE(layout->itemAt(0,0)->geometry().width(), 20.0);
- QCOMPARE(layout->itemAt(1,0)->geometry().width(), 20.0);
- QCOMPARE(layout->itemAt(0,1)->geometry().width(), 25.0);
- QCOMPARE(layout->itemAt(1,1)->geometry().width(), 25.0);
- QCOMPARE(layout->itemAt(0,2)->geometry().width(), 25.0);
- QCOMPARE(layout->itemAt(1,2)->geometry().width(), 25.0);
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 20, 25));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 25, 20, 25));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(20, 0, 25, 25));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(20, 25, 25, 25));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(45, 0, 25, 25));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(45, 25, 25, 25));
+
+ layout->setColumnAlignment(2, Qt::AlignCenter);
+ widget->resize(widget->effectiveSizeHint(Qt::MaximumSize));
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,20+50+60, 50+50));
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 20, 50));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 50, 20, 50));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(20, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(20, 50, 50, 50));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(75, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(75, 50, 50, 50));
+
+ for (int i = 0; i < layout->count(); i++)
+ layout->setAlignment(layout->itemAt(i), Qt::AlignRight | Qt::AlignBottom);
+ layout->activate();
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 20, 50));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 50, 20, 50));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(20, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(20, 50, 50, 50));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(80, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(80, 50, 50, 50));
+ for (int i = 0; i < layout->count(); i++)
+ layout->setAlignment(layout->itemAt(i), Qt::AlignCenter);
+
+ layout->setMaximumSize(layout->maximumSize() + QSizeF(60,60));
+ widget->resize(widget->effectiveSizeHint(Qt::MaximumSize));
+ layout->activate();
+
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 15, 20, 50));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 95, 20, 50));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(20+30, 15, 50, 50));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(20+30, 95, 50, 50));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(20+60+50+5, 15, 50, 50));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(20+60+50+5, 95, 50, 50));
+
+ layout->setMaximumSize(layout->preferredSize() + QSizeF(20,20));
+ widget->resize(widget->effectiveSizeHint(Qt::MaximumSize));
+ layout->activate();
+
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 20, 35));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 35, 20, 35));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(20, 0, 35, 35));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(20, 35, 35, 35));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(55, 0, 35, 35));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(55, 35, 35, 35));
delete widget;
}
@@ -2306,6 +2360,11 @@ static QSizeF hfw1(Qt::SizeHint, const QSizeF &constraint)
return result;
}
+static QSizeF hfw2(Qt::SizeHint /*which*/, const QSizeF &constraint)
+{
+ return QSizeF(constraint.width(), constraint.width());
+}
+
void tst_QGraphicsGridLayout::geometries_data()
{
@@ -2361,6 +2420,31 @@ void tst_QGraphicsGridLayout::geometries_data()
<< QRectF(0, 1, 50,100) << QRectF(50, 1, 50,400)
);
+
+ QTest::newRow("hfw-h408") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .sizeHint(Qt::MinimumSize, QSizeF(40,40))
+ .sizeHint(Qt::PreferredSize, QSizeF(50,400))
+ .sizeHint(Qt::MaximumSize, QSizeF(500, 500))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(100, 408)
+ << (RectList()
+ << QRectF(0, 0, 50, 8) << QRectF(50, 0, 50, 8)
+ << QRectF(0, 8, 50,100) << QRectF(50, 8, 50,400)
+ );
QTest::newRow("hfw-h410") << (ItemList()
<< ItemDesc(0,0)
.minSize(QSizeF(1,1))
@@ -2386,6 +2470,150 @@ void tst_QGraphicsGridLayout::geometries_data()
<< QRectF(0, 10, 50,100) << QRectF(50, 10, 50,400)
);
+ QTest::newRow("hfw-h470") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .sizeHint(Qt::MinimumSize, QSizeF(40,40))
+ .sizeHint(Qt::PreferredSize, QSizeF(50,400))
+ .sizeHint(Qt::MaximumSize, QSizeF(500,500))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(100, 470)
+ << (RectList()
+ << QRectF(0, 0, 50,70) << QRectF(50, 0, 50,70)
+ << QRectF(0, 70, 50,100) << QRectF(50, 70, 50,400)
+ );
+
+
+ // change layout width and verify
+ QTest::newRow("hfw-w100") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .sizeHint(Qt::MinimumSize, QSizeF(40,40))
+ .sizeHint(Qt::PreferredSize, QSizeF(50,400))
+ .sizeHint(Qt::MaximumSize, QSizeF(5000,5000))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(100, 401)
+ << (RectList()
+ << QRectF( 0, 0, 50, 1) << QRectF( 50, 0, 50, 1)
+ << QRectF( 0, 1, 50, 100) << QRectF( 50, 1, 50, 400)
+ );
+
+ QTest::newRow("hfw-w160") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .sizeHint(Qt::MinimumSize, QSizeF(40,40))
+ .sizeHint(Qt::PreferredSize, QSizeF(50,400))
+ .sizeHint(Qt::MaximumSize, QSizeF(5000,5000))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(160, 401)
+ << (RectList()
+ << QRectF( 0, 0, 80, 100) << QRectF( 80, 0, 80, 100)
+ << QRectF( 0, 100, 80, 100) << QRectF( 80, 100, 80, 250)
+ );
+
+ QTest::newRow("hfw-w500") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .sizeHint(Qt::MinimumSize, QSizeF(40,40))
+ .sizeHint(Qt::PreferredSize, QSizeF(50,400))
+ .sizeHint(Qt::MaximumSize, QSizeF(5000,5000))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(500, 401)
+ << (RectList()
+ << QRectF( 0, 0, 100, 100) << QRectF(100, 0, 100, 100)
+ << QRectF( 0, 100, 100, 100) << QRectF(100, 100, 400, 50)
+ );
+
+ QTest::newRow("hfw-alignment-defaults") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(100, 100))
+ .maxSize(QSizeF(100, 100))
+ .heightForWidth(hfw2)
+ << ItemDesc(1,0)
+ .minSize(QSizeF(200, 200))
+ .maxSize(QSizeF(200, 200))
+ .heightForWidth(hfw2)
+ << ItemDesc(2,0)
+ .minSize(QSizeF(300, 300))
+ .maxSize(QSizeF(300, 300))
+ )
+ << QSizeF(300, 600)
+ << (RectList()
+ << QRectF(0, 0, 100, 100)
+ << QRectF(0, 100, 200, 200)
+ << QRectF(0, 300, 300, 300)
+ );
+
+ QTest::newRow("hfw-alignment2") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(100, 100))
+ .maxSize(QSizeF(100, 100))
+ .heightForWidth(hfw2)
+ .alignment(Qt::AlignRight)
+ << ItemDesc(1,0)
+ .minSize(QSizeF(200, 200))
+ .maxSize(QSizeF(200, 200))
+ .heightForWidth(hfw2)
+ .alignment(Qt::AlignHCenter)
+ << ItemDesc(2,0)
+ .minSize(QSizeF(300, 300))
+ .maxSize(QSizeF(300, 300))
+ )
+ << QSizeF(300, 600)
+ << (RectList()
+ << QRectF(200, 0, 100, 100)
+ << QRectF( 50, 100, 200, 200)
+ << QRectF( 0, 300, 300, 300)
+ );
+
}
void tst_QGraphicsGridLayout::geometries()
@@ -2556,8 +2784,9 @@ void tst_QGraphicsGridLayout::heightForWidth()
w11->setSizePolicy(sp);
layout->addItem(w11, 1, 1);
- QSizeF prefSize = layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1));
- QCOMPARE(prefSize, QSizeF(10+200, 10+100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(2, 2));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(210, 110));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(30100, 30100));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 20001));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 20010));
@@ -2610,23 +2839,128 @@ void tst_QGraphicsGridLayout::heightForWidthWithSpanning()
w->setSizePolicy(sp);
layout->addItem(w, 0,0,2,2);
- QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(1, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(1, 1));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(200, 100));
- QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+ QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(30000, 30000));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
- QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, QWIDGETSIZE_MAX));
+ QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 10000));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 10000));
- QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, QWIDGETSIZE_MAX));
+ QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, 10000));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
- QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, QWIDGETSIZE_MAX));
+ QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 10000));
+}
+
+void tst_QGraphicsGridLayout::stretchAndHeightForWidth()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout;
+ widget->setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+
+ RectWidget *w1 = new RectWidget;
+ w1->setSizeHint(Qt::MinimumSize, QSizeF(10, 10));
+ w1->setSizeHint(Qt::PreferredSize, QSizeF(100, 100));
+ w1->setSizeHint(Qt::MaximumSize, QSizeF(500, 500));
+ layout->addItem(w1, 0,0,1,1);
+
+ RectWidget *w2 = new RectWidget;
+ w2->setSizeHint(Qt::MinimumSize, QSizeF(10, 10));
+ w2->setSizeHint(Qt::PreferredSize, QSizeF(100, 100));
+ w2->setSizeHint(Qt::MaximumSize, QSizeF(500, 500));
+ layout->addItem(w2, 0,1,1,1);
+ layout->setColumnStretchFactor(1, 2);
+
+ QApplication::sendPostedEvents();
+ QGraphicsScene scene;
+ QGraphicsView *view = new QGraphicsView(&scene);
+
+ scene.addItem(widget);
+
+ view->show();
+
+ widget->resize(500, 100);
+ // w1 should stay at its preferred size
+ QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 100));
+ QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 100));
+
+
+ // only w1 has hfw
+ w1->setConstraintFunction(hfw);
+ QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ sp.setHeightForWidth(true);
+ w1->setSizePolicy(sp);
+ QApplication::sendPostedEvents();
+
+ QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 200));
+ QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 200));
+
+ // only w2 has hfw
+ w2->setConstraintFunction(hfw);
+ w2->setSizePolicy(sp);
+
+ w1->setConstraintFunction(0);
+ sp.setHeightForWidth(false);
+ w1->setSizePolicy(sp);
+ QApplication::sendPostedEvents();
+
+ QCOMPARE(w1->geometry(), QRectF(0, 0, 100, 100));
+ QCOMPARE(w2->geometry(), QRectF(100, 0, 400, 50));
+
}
+void tst_QGraphicsGridLayout::testDefaultAlignment()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout(widget);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+
+ QGraphicsWidget *w = new QGraphicsWidget;
+ w->setMinimumSize(50,50);
+ w->setMaximumSize(50,50);
+ layout->addItem(w,0,0);
+
+ //Default alignment should be to the top-left
+
+ //First, check by forcing the layout to be bigger
+ layout->setMinimumSize(100,100);
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,100,100));
+ QCOMPARE(w->geometry(), QRectF(0,0,50,50));
+ layout->setMinimumSize(-1,-1);
+
+ //Second, check by forcing the column and row to be bigger instead
+ layout->setColumnMinimumWidth(0, 100);
+ layout->setRowMinimumHeight(0, 100);
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,100,100));
+ QCOMPARE(w->geometry(), QRectF(0,0,50,50));
+ layout->setMinimumSize(-1,-1);
+ layout->setColumnMinimumWidth(0, 0);
+ layout->setRowMinimumHeight(0, 0);
+
+
+ //Third, check by adding a larger item in the column
+ QGraphicsWidget *w2 = new QGraphicsWidget;
+ w2->setMinimumSize(100,100);
+ w2->setMaximumSize(100,100);
+ layout->addItem(w2,1,0);
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,100,150));
+ QCOMPARE(w->geometry(), QRectF(0,0,50,50));
+ QCOMPARE(w2->geometry(), QRectF(0,50,100,100));
+}
QTEST_MAIN(tst_QGraphicsGridLayout)
#include "tst_qgraphicsgridlayout.moc"
diff --git a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
index 6107fa1..965e340 100644
--- a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
+++ b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
@@ -103,6 +103,9 @@ private slots:
void removeLayout();
void avoidRecursionInInsertItem();
void styleInfoLeak();
+ void testAlignmentInLargerLayout();
+ void testOffByOneInLargerLayout();
+ void testDefaultAlignment();
// Task specific tests
void task218400_insertStretchCrash();
@@ -1465,6 +1468,121 @@ void tst_QGraphicsLinearLayout::task218400_insertStretchCrash()
form->setLayout(layout); // crash
}
+void tst_QGraphicsLinearLayout::testAlignmentInLargerLayout()
+{
+ QGraphicsScene *scene = new QGraphicsScene;
+ QGraphicsWidget *form = new QGraphicsWidget;
+ scene->addItem(form);
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, form);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
+
+ QGraphicsWidget *a = new QGraphicsWidget;
+ a->setMaximumSize(100,100);
+ layout->addItem(a);
+
+ QCOMPARE(form->maximumSize(), QSizeF(100,100));
+ QCOMPARE(layout->maximumSize(), QSizeF(100,100));
+ layout->setMinimumSize(QSizeF(200,200));
+ layout->setMaximumSize(QSizeF(200,200));
+
+ layout->setAlignment(a, Qt::AlignCenter);
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(50,50,100,100));
+
+ layout->setAlignment(a, Qt::AlignRight | Qt::AlignBottom);
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(100,100,100,100));
+
+ layout->setAlignment(a, Qt::AlignHCenter | Qt::AlignTop);
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(50,0,100,100));
+
+ QGraphicsWidget *b = new QGraphicsWidget;
+ b->setMaximumSize(100,100);
+ layout->addItem(b);
+
+ layout->setAlignment(a, Qt::AlignCenter);
+ layout->setAlignment(b, Qt::AlignCenter);
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(50,0,100,100));
+ QCOMPARE(b->geometry(), QRectF(50,100,100,100));
+
+ layout->setAlignment(a, Qt::AlignRight | Qt::AlignBottom);
+ layout->setAlignment(b, Qt::AlignLeft | Qt::AlignTop);
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(100,0,100,100));
+ QCOMPARE(b->geometry(), QRectF(0,100,100,100));
+}
+
+void tst_QGraphicsLinearLayout::testOffByOneInLargerLayout() {
+ QGraphicsScene *scene = new QGraphicsScene;
+ QGraphicsWidget *form = new QGraphicsWidget;
+ scene->addItem(form);
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, form);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
+
+ QGraphicsWidget *a = new QGraphicsWidget;
+ QGraphicsWidget *b = new QGraphicsWidget;
+ a->setMaximumSize(100,100);
+ b->setMaximumSize(100,100);
+ layout->addItem(a);
+ layout->addItem(b);
+
+ layout->setAlignment(a, Qt::AlignRight | Qt::AlignBottom);
+ layout->setAlignment(b, Qt::AlignLeft | Qt::AlignTop);
+ layout->setMinimumSize(QSizeF(101,201));
+ layout->setMaximumSize(QSizeF(101,201));
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(1,0.5,100,100));
+ QCOMPARE(b->geometry(), QRectF(0,100.5,100,100));
+
+ layout->setMinimumSize(QSizeF(100,200));
+ layout->setMaximumSize(QSizeF(100,200));
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(0,0,100,100));
+ QCOMPARE(b->geometry(), QRectF(0,100,100,100));
+
+ layout->setMinimumSize(QSizeF(99,199));
+ layout->setMaximumSize(QSizeF(99,199));
+ layout->activate();
+ QCOMPARE(a->geometry(), QRectF(0,0,99,99.5));
+ QCOMPARE(b->geometry(), QRectF(0,99.5,99,99.5));
+}
+void tst_QGraphicsLinearLayout::testDefaultAlignment()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, widget);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+
+ QGraphicsWidget *w = new QGraphicsWidget;
+ w->setMinimumSize(50,50);
+ w->setMaximumSize(50,50);
+ layout->addItem(w);
+
+ //Default alignment should be to the top-left
+ QCOMPARE(layout->alignment(w), 0);
+
+ //First, check by forcing the layout to be bigger
+ layout->setMinimumSize(100,100);
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,100,100));
+ QCOMPARE(w->geometry(), QRectF(0,0,50,50));
+ layout->setMinimumSize(-1,-1);
+
+ //Second, check by adding a larger item in the column
+ QGraphicsWidget *w2 = new QGraphicsWidget;
+ w2->setMinimumSize(100,100);
+ w2->setMaximumSize(100,100);
+ layout->addItem(w2);
+ layout->activate();
+ QCOMPARE(layout->geometry(), QRectF(0,0,100,150));
+ QCOMPARE(w->geometry(), QRectF(0,0,50,50));
+ QCOMPARE(w2->geometry(), QRectF(0,50,100,100));
+}
+
QTEST_MAIN(tst_QGraphicsLinearLayout)
#include "tst_qgraphicslinearlayout.moc"