From 548583f449432363fad8fe547ce073bb754d46be Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Thu, 13 Aug 2009 15:07:34 -0300 Subject: QGraphicsAnchorLayout: fix merging of preferredSizeHint In simplification, the preferred size of a parallel group should get the maximum preferred size (and bound it to the maximum size). This follows the principle that for an layout item: 'growing is better than shrinking', and is consistent with what our linear program also do. This patch also make sure that the sizeAt* are properly initialized to the preferred size, the idea is if there's no restriction upon an anchor, it'll keep it's preferred size no matter what. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Artur Duque de Souza --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 7e0541e..d878722 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -57,11 +57,22 @@ void ParallelAnchorData::updateChildrenSizes() void ParallelAnchorData::refreshSizeHints() { + // ### should we warn if the parallel connection is invalid? + // e.g. 1-2-3 with 10-20-30, the minimum of the latter is + // bigger than the maximum of the former. + firstEdge->refreshSizeHints(); secondEdge->refreshSizeHints(); + minSize = qMax(firstEdge->minSize, secondEdge->minSize); - prefSize = qMin(firstEdge->prefSize, secondEdge->prefSize); maxSize = qMin(firstEdge->maxSize, secondEdge->maxSize); + + prefSize = qMax(firstEdge->prefSize, secondEdge->prefSize); + prefSize = qMin(prefSize, maxSize); + + sizeAtMinimum = prefSize; + sizeAtPreferred = prefSize; + sizeAtMaximum = prefSize; } void SequentialAnchorData::updateChildrenSizes() @@ -90,6 +101,10 @@ void SequentialAnchorData::refreshSizeHints() prefSize += edge->prefSize; maxSize += edge->maxSize; } + + sizeAtMinimum = prefSize; + sizeAtPreferred = prefSize; + sizeAtMaximum = prefSize; } void AnchorData::dump(int indent) { @@ -251,8 +266,11 @@ static void simplifySequentialChunk(Graph *graph, if (AnchorData *oldAnchor = graph->takeEdge(before, after)) { newAnchor = new ParallelAnchorData(oldAnchor, sequence); min = qMax(oldAnchor->minSize, sequence->minSize); - pref = qMax(oldAnchor->prefSize, sequence->prefSize); max = qMin(oldAnchor->maxSize, sequence->maxSize); + + pref = qMax(oldAnchor->prefSize, sequence->prefSize); + pref = qMin(pref, max); + newAnchor->minSize = min; newAnchor->prefSize = pref; newAnchor->maxSize = max; -- cgit v0.12