diff options
Diffstat (limited to 'examples/graphicsview/flowlayout/flowlayout.cpp')
-rw-r--r-- | examples/graphicsview/flowlayout/flowlayout.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/graphicsview/flowlayout/flowlayout.cpp b/examples/graphicsview/flowlayout/flowlayout.cpp index d4fc49d..32a2830 100644 --- a/examples/graphicsview/flowlayout/flowlayout.cpp +++ b/examples/graphicsview/flowlayout/flowlayout.cpp @@ -98,12 +98,10 @@ void FlowLayout::setGeometry(const QRectF &geom) qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const { - QPointF tl = geom.topLeft(); - qreal maxw = geom.width(); - qreal left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); - maxw = maxw - left - right; + const qreal maxw = geom.width() - left - right; + qreal x = 0; qreal y = 0; qreal maxRowHeight = 0; @@ -139,9 +137,11 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const QSizeF size(0, 0); qreal left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); - if (constraint.width() > 0) { // height for width - qreal height = doLayout(QRectF(QPointF(0,0), constraint), false); + if (constraint.width() >= 0) { // height for width + const qreal height = doLayout(QRectF(QPointF(0,0), constraint), false); size = QSizeF(constraint.width(), height); + } else if (constraint.height() >= 0) { // width for height? + // not supported } else { QGraphicsLayoutItem *item; foreach (item, m_items) @@ -153,8 +153,8 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const QSizeF FlowLayout::prefSize() const { - qreal left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); + qreal left, right; + getContentsMargins(&left, 0, &right, 0); QGraphicsLayoutItem *item; qreal maxh = 0; @@ -196,15 +196,19 @@ QSizeF FlowLayout::maxSize() const QSizeF FlowLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { + QSizeF sh = constraint; switch (which) { case Qt::PreferredSize: - return prefSize(); + sh = prefSize(); + break; case Qt::MinimumSize: - return minSize(constraint); + sh = minSize(constraint); + break; case Qt::MaximumSize: - return maxSize(); + sh = maxSize(); + break; default: break; } - return constraint; + return sh; } |