diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/graphicsview/flowlayout/flowlayout.cpp | 28 | ||||
-rw-r--r-- | examples/graphicsview/flowlayout/window.cpp | 2 |
2 files changed, 17 insertions, 13 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; } diff --git a/examples/graphicsview/flowlayout/window.cpp b/examples/graphicsview/flowlayout/window.cpp index 2d98026..017659a 100644 --- a/examples/graphicsview/flowlayout/window.cpp +++ b/examples/graphicsview/flowlayout/window.cpp @@ -49,7 +49,7 @@ Window::Window() { FlowLayout *lay = new FlowLayout; QLatin1String wiseWords("I am not bothered by the fact that I am unknown." - "I am bothered when I do not know others. (Confucius)"); + " I am bothered when I do not know others. (Confucius)"); QString sentence(wiseWords); QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts); for (int i = 0; i < words.count(); ++i) { |