summaryrefslogtreecommitdiffstats
path: root/examples/graphicsview
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-04 09:42:52 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-04 13:20:04 (GMT)
commit55bda33db049d137f4a1e3349e40e8d3365748c6 (patch)
tree9ae2107bc1f3243357e3afb5561d4186d945dbf2 /examples/graphicsview
parent3eb65f48c97dc5e1a8980afa35bea8e4b16f08ba (diff)
downloadQt-55bda33db049d137f4a1e3349e40e8d3365748c6.zip
Qt-55bda33db049d137f4a1e3349e40e8d3365748c6.tar.gz
Qt-55bda33db049d137f4a1e3349e40e8d3365748c6.tar.bz2
Minor fixes to the graphicsview/flowlayout example
Diffstat (limited to 'examples/graphicsview')
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.cpp28
-rw-r--r--examples/graphicsview/flowlayout/window.cpp2
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) {