summaryrefslogtreecommitdiffstats
path: root/examples/graphicsview/flowlayout/flowlayout.cpp
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-04 11:42:52 +0200
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-04 15:20:04 +0200
commit55bda33db049d137f4a1e3349e40e8d3365748c6 (patch)
tree9ae2107bc1f3243357e3afb5561d4186d945dbf2 /examples/graphicsview/flowlayout/flowlayout.cpp
parent3eb65f48c97dc5e1a8980afa35bea8e4b16f08ba (diff)
Minor fixes to the graphicsview/flowlayout example
Diffstat (limited to 'examples/graphicsview/flowlayout/flowlayout.cpp')
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/graphicsview/flowlayout/flowlayout.cpp b/examples/graphicsview/flowlayout/flowlayout.cpp
index d4fc49da0a..32a2830929 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;
}