summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-08-17 22:52:17 (GMT)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-08-18 04:24:36 (GMT)
commita5a925748ff3893e4acf2d41bd8aee0d11a3285a (patch)
tree63bbe23c3f811fd6ab738f42091a54bad125ebf7 /src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
parentf127c4708db2f6825d7b37b9aa5dec52f9ee989c (diff)
downloadQt-a5a925748ff3893e4acf2d41bd8aee0d11a3285a.zip
Qt-a5a925748ff3893e4acf2d41bd8aee0d11a3285a.tar.gz
Qt-a5a925748ff3893e4acf2d41bd8aee0d11a3285a.tar.bz2
QGraphicsAnchorLayout: fix calculation of sizeAt* values for Sequential
This commit implements what's described in the previous commit QGraphicsAnchorLayout: fix expected values for parallel test When filling the sizeAt* values (the three points used for interpolation when setting geometry), now sequential anchors distribute the sizes to the children in a fair way, i.e. proportionally in relation to the existing min/pref/max hints. Each value is defined in relation of the pref (either as a shrinkage in pref or a grow in pref). In both cases the shrinking/growing factor is the same for all children. When we implement support for QSizePolicies, this distribution might be changed by setting size policies for a certain item or anchor. This makes two tests work -- so no more expected fail. Also fixed a typo in one test's expected results.
Diffstat (limited to 'src/gui/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp80
1 files changed, 73 insertions, 7 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 9f18781..d54ea8d 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -127,17 +127,83 @@ void ParallelAnchorData::refreshSizeHints(qreal effectiveSpacing)
sizeAtMaximum = prefSize;
}
+static qreal getFactor(qreal value, qreal min, qreal pref, qreal max, bool *minToPref)
+{
+ // ### Maybe remove some of the assertions? (since outside is asserting us)
+ Q_ASSERT(value > min || qFuzzyCompare(value, min));
+ Q_ASSERT(value < max || qFuzzyCompare(value, max));
+
+ if (qFuzzyCompare(value, min)) {
+ *minToPref = true;
+ return 0.0;
+
+ } else if (qFuzzyCompare(value, pref)) {
+ *minToPref = true;
+ return 1.0;
+
+ } else if (qFuzzyCompare(value, max)) {
+ *minToPref = false;
+ return 1.0;
+
+ } else if (value < pref) {
+ *minToPref = true;
+ // Since value < pref and value != pref and min <= value,
+ // we can assert that min < pref.
+ Q_ASSERT(min < pref);
+ return (value - min) / (pref - min);
+
+ } else {
+ *minToPref = false;
+ // Since value > pref and value != pref and max >= value,
+ // we can assert that max > pref.
+ Q_ASSERT(max > pref);
+ return (value - pref) / (max - pref);
+ }
+}
+
void SequentialAnchorData::updateChildrenSizes()
{
- qreal minFactor = sizeAtMinimum / minSize;
- qreal prefFactor = sizeAtPreferred / prefSize;
- qreal maxFactor = sizeAtMaximum / maxSize;
+ // ### REMOVE ME
+ // ### check whether we are guarantee to get those or we need to warn stuff at this
+ // point.
+ Q_ASSERT(sizeAtMinimum > minSize || qFuzzyCompare(sizeAtMinimum, minSize));
+ Q_ASSERT(sizeAtMinimum < maxSize || qFuzzyCompare(sizeAtMinimum, maxSize));
+ Q_ASSERT(sizeAtPreferred > minSize || qFuzzyCompare(sizeAtPreferred, minSize));
+ Q_ASSERT(sizeAtPreferred < maxSize || qFuzzyCompare(sizeAtPreferred, maxSize));
+ Q_ASSERT(sizeAtMaximum > minSize || qFuzzyCompare(sizeAtMaximum, minSize));
+ Q_ASSERT(sizeAtMaximum < maxSize || qFuzzyCompare(sizeAtMaximum, maxSize));
+
+ // Band here refers if the value is in the Minimum To Preferred
+ // band (the lower band) or the Preferred To Maximum (the upper band).
+
+ bool minLowerBand;
+ qreal minFactor = getFactor(sizeAtMinimum, minSize, prefSize, maxSize, &minLowerBand);
+
+ bool prefLowerBand;
+ qreal prefFactor = getFactor(sizeAtPreferred, minSize, prefSize, maxSize, &prefLowerBand);
+
+ bool maxLowerBand;
+ qreal maxFactor = getFactor(sizeAtMaximum, minSize, prefSize, maxSize, &maxLowerBand);
for (int i = 0; i < m_edges.count(); ++i) {
- m_edges[i]->sizeAtMinimum = m_edges[i]->minSize * minFactor;
- m_edges[i]->sizeAtPreferred = m_edges[i]->prefSize * prefFactor;
- m_edges[i]->sizeAtMaximum = m_edges[i]->maxSize * maxFactor;
- m_edges[i]->updateChildrenSizes();
+ AnchorData *e = m_edges.at(i);
+
+ if (minLowerBand)
+ e->sizeAtMinimum = e->minSize + ((e->prefSize - e->minSize) * minFactor);
+ else
+ e->sizeAtMinimum = e->prefSize + ((e->maxSize - e->prefSize) * minFactor);
+
+ if (prefLowerBand)
+ e->sizeAtPreferred = e->minSize + ((e->prefSize - e->minSize) * prefFactor);
+ else
+ e->sizeAtPreferred = e->prefSize + ((e->maxSize - e->prefSize) * prefFactor);
+
+ if (maxLowerBand)
+ e->sizeAtMaximum = e->minSize + ((e->prefSize - e->minSize) * maxFactor);
+ else
+ e->sizeAtMaximum = e->prefSize + ((e->maxSize - e->prefSize) * maxFactor);
+
+ e->updateChildrenSizes();
}
}