diff options
author | John Tapsell <john.tapsell.ext@basyskom.de> | 2010-09-08 01:06:27 +0900 |
---|---|---|
committer | Jörgen Scheibengruber <jorgen.scheibengruber@nokia.com> | 2010-09-09 16:20:16 +0300 |
commit | ae8b6f303dc978715231265d23d3a1ac496d9c7d (patch) | |
tree | ea70e6880e23092b94cbafbd9d05bb59a187e4e2 | |
parent | 4aa5863cf246ac008a3c44b08318e97c63bdadbd (diff) |
Changes: MFlowLayoutPolicy - only pass constraint if the item hasHeightForWidth()
RevBy: Jörgen
Details: Provide a workaround for NB#189826
-rw-r--r-- | src/corelib/layout/mflowlayoutpolicy.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/corelib/layout/mflowlayoutpolicy.cpp b/src/corelib/layout/mflowlayoutpolicy.cpp index 8b771fa3..2f0c0079 100644 --- a/src/corelib/layout/mflowlayoutpolicy.cpp +++ b/src/corelib/layout/mflowlayoutpolicy.cpp @@ -55,6 +55,19 @@ void MFlowLayoutPolicy::removeAt(int index) d->alignments.removeAt(index); Q_ASSERT(count() == d->alignments.count()); } +//Convience function to get the width of the item, obeying heightForWidth if needed +static QSizeF getItemPreferredSize(const QGraphicsLayoutItem *item, qreal constraintWidth) { + QSizeF size = item->effectiveSizeHint(Qt::PreferredSize); + if (size.width() > constraintWidth) { + if (item->sizePolicy().hasHeightForWidth()) { + //If the object's preferred size is too big to fit, try constraining it + size = item->effectiveSizeHint(Qt::PreferredSize, QSizeF(constraintWidth, -1)); + } else { + size.setWidth(constraintWidth); + } + } + return size; +} QSizeF MFlowLayoutPolicy::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_D(const MFlowLayoutPolicy); @@ -110,9 +123,7 @@ QSizeF MFlowLayoutPolicy::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const QGraphicsLayoutItem *item = itemAt(i); //We use the preferredsize for both the minimum and preferred sizeHints since //doing otherwise would make this code a lot more complicated - QSizeF size = item->effectiveSizeHint(Qt::PreferredSize); - if (size.width() > constraintWidth) - size = item->effectiveSizeHint(Qt::PreferredSize, QSizeF(constraintWidth, -1)); + QSizeF size = getItemPreferredSize(item, constraintWidth); bool sameRow = d->roomForItemOnCurrentRow(size, constraintWidth, ¤t_position, ¤t_rowheight); if (sameRow) { //It fits on the same row @@ -173,11 +184,7 @@ void MFlowLayoutPolicy::relayout() int row_start = i; //The item index at the start of a row while (i < count()) { QGraphicsLayoutItem *item = itemAt(i); - QSizeF size = item->effectiveSizeHint(Qt::PreferredSize); - if (size.width() > constraintWidth) { - //If the object's preferred size is too big to fit, try constraining it - size = item->effectiveSizeHint(Qt::PreferredSize, QSizeF(constraintWidth, -1)); - } + QSizeF size = getItemPreferredSize(item, constraintWidth); bool sameRow = d->roomForItemOnCurrentRow(size, constraintWidth, ¤t_position, ¤t_rowheight); //check if we have finished with this row if (sameRow) { @@ -201,9 +208,7 @@ void MFlowLayoutPolicy::relayout() for (int j = row_start; j < i; ++j) { QGraphicsLayoutItem *item = itemAt(j); //get the size again - QSizeF size = item->effectiveSizeHint(Qt::PreferredSize); - if (size.width() > constraintWidth) - size = item->effectiveSizeHint(Qt::PreferredSize, QSizeF(constraintWidth, -1)); + QSizeF size = getItemPreferredSize(item, constraintWidth); d->roomForItemOnCurrentRow(size, constraintWidth, ¤t_position); // Q_ASSERT(sameRow); |