diff options
author | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-07-14 21:40:35 (GMT) |
---|---|---|
committer | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-07-22 18:04:57 (GMT) |
commit | a52114c8ca9020773081c20a1094c078cfdb81fe (patch) | |
tree | bdd5c4d0cddd0b990dd9efe10a9287ab81a07b6e /src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | |
parent | 7bf639f5484bb5fe34cab53ab1dfde048e158995 (diff) | |
download | Qt-a52114c8ca9020773081c20a1094c078cfdb81fe.zip Qt-a52114c8ca9020773081c20a1094c078cfdb81fe.tar.gz Qt-a52114c8ca9020773081c20a1094c078cfdb81fe.tar.bz2 |
QGraphicsAnchorLayout: Remove center anchors when not needed
Continuing the effort to enforcing center anchors to exist only
when needed, this commit removes the central anchors when they
are no longer used.
Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org>
Reviewed-by: Anselmo Lacerda S. de Melo <anselmo.melo@openbossa.org>
Diffstat (limited to 'src/gui/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 8a37cad..9413ec3 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -563,6 +563,67 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( removeAnchor(item, firstEdge, item, lastEdge); } +void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( + QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge) +{ + Orientation orientation; + switch (centerEdge) { + case QGraphicsAnchorLayout::HCenter: + orientation = Horizontal; + break; + case QGraphicsAnchorLayout::VCenter: + orientation = Vertical; + break; + default: + // Don't remove edges that not the center ones + return; + } + + // Check if vertex is used by other than the internal anchors + AnchorVertex *center = internalVertex(item, centerEdge); + if (graph[orientation].adjacentVertices(center).count() > 2) + return; + + // Orientation code + QGraphicsAnchorLayout::Edge firstEdge; + QGraphicsAnchorLayout::Edge lastEdge; + + if (orientation == Horizontal) { + firstEdge = QGraphicsAnchorLayout::Left; + lastEdge = QGraphicsAnchorLayout::Right; + } else { + firstEdge = QGraphicsAnchorLayout::Top; + lastEdge = QGraphicsAnchorLayout::Bottom; + } + + AnchorVertex *first = internalVertex(item, firstEdge); + AnchorVertex *last = internalVertex(item, lastEdge); + Q_ASSERT(first && last); + + // Create new anchor + AnchorData *oldData = graph[orientation].edgeData(first, center); + + int minimumSize = oldData->minSize * 2; + int preferredSize = oldData->prefSize * 2; + int maximumSize = oldData->maxSize * 2; + + AnchorData *data = new AnchorData(minimumSize, preferredSize, maximumSize); + addAnchor(item, firstEdge, item, lastEdge, data); + + // Remove center constraint + for (int i = itemCenterConstraints[orientation].count() - 1; i >= 0; --i) { + if (itemCenterConstraints[orientation][i]->variables.contains(oldData)) { + delete itemCenterConstraints[orientation].takeAt(i); + break; + } + } + + // Remove old anchors + removeAnchor(item, firstEdge, item, centerEdge); + removeAnchor(item, centerEdge, item, lastEdge); +} + + void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation) { @@ -574,12 +635,16 @@ void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem * AnchorVertex *first = internalVertex(item, orientation == Horizontal ? QGraphicsAnchorLayout::Left : QGraphicsAnchorLayout::Top); - AnchorVertex *second = internalVertex(item, orientation == Horizontal ? + AnchorVertex *center = internalVertex(item, orientation == Horizontal ? QGraphicsAnchorLayout::HCenter : QGraphicsAnchorLayout::VCenter); - Q_ASSERT(first && second); - AnchorData *internalAnchor = graph[orientation].edgeData(first, second); + // Skip if no center constraints exist + if (!center) + return; + + Q_ASSERT(first); + AnchorData *internalAnchor = graph[orientation].edgeData(first, center); // Look for our anchor in all item center constraints, then remove it for (int i = 0; i < itemCenterConstraints[orientation].size(); ++i) { |