From 8bb931a6bff959279189662299ad6f8516de1789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Wed, 22 Jul 2009 10:25:26 +0200 Subject: Make sure that internal center anchors are not simplified. --- examples/layouts/anchorlayout/xml/center.xml | 57 ++++++++++++++++++++++++ src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 21 ++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 examples/layouts/anchorlayout/xml/center.xml diff --git a/examples/layouts/anchorlayout/xml/center.xml b/examples/layouts/anchorlayout/xml/center.xml new file mode 100644 index 0000000..cf857fc --- /dev/null +++ b/examples/layouts/anchorlayout/xml/center.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 0bf974f..9023344 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -220,7 +220,6 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O Q_Q(QGraphicsAnchorLayout); Graph &g = graph[orientation]; AnchorVertex *v = g.rootVertex(); - QGraphicsAnchorLayout::Edge layoutEdge = oppositeEdge(v->m_edge); if (!v) return; @@ -229,6 +228,9 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O stack.push(v); QVector candidates; + const QGraphicsAnchorLayout::Edge centerEdge = pickEdge(QGraphicsAnchorLayout::HCenter, orientation); + const QGraphicsAnchorLayout::Edge layoutEdge = oppositeEdge(v->m_edge); + // walk depth-first. while (!stack.isEmpty()) { v = stack.pop(); @@ -295,8 +297,23 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O // after the sequential anchor. if (intervalTo - intervalFrom >= 2) { // simplify in the range [intervalFrom, intervalTo] + + // Trim off internal center anchors (Left-Center/Center-Right) from the + // start and the end of the sequence. We never want to simplify internal + // center anchors where there is an external anchor connected to the center. AnchorVertex *intervalVertexFrom = intervalFrom == 0 ? beforeSequence : candidates.at(intervalFrom - 1); + if (intervalVertexFrom->m_edge == centerEdge + && intervalVertexFrom->m_item == candidates.at(intervalFrom)->m_item) { + ++intervalFrom; + intervalVertexFrom = candidates.at(intervalFrom - 1); + } AnchorVertex *intervalVertexTo = intervalTo <= candidates.count() ? candidates.at(intervalTo - 1) : afterSequence; + if (intervalVertexTo->m_edge == centerEdge + && intervalVertexTo->m_item == candidates.at(intervalTo - 2)->m_item) { + --intervalTo; + intervalVertexTo = candidates.at(intervalTo - 1); + } + QVector subCandidates; if (forward) { subCandidates = candidates.mid(intervalFrom, intervalTo - intervalFrom - 1); @@ -323,7 +340,6 @@ void QGraphicsAnchorLayoutPrivate::simplifyGraph(QGraphicsAnchorLayoutPrivate::O if (endOfSequence) candidates.clear(); - QGraphicsAnchorLayout::Edge centerEdge = pickEdge(QGraphicsAnchorLayout::HCenter, orientation); for (int i = 0; i < count; ++i) { AnchorVertex *next = vertices.at(i); if (next->m_item == q && next->m_edge == centerEdge) @@ -800,6 +816,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs() //simplifyGraph(Horizontal); //simplifyGraph(Vertical); + //Q_Q(QGraphicsAnchorLayout); //q->dumpGraph(); //restoreSimplifiedGraph(Horizontal); // should not be here, but currently crashes if not //restoreSimplifiedGraph(Vertical); // should not be here, but currently crashes if not -- cgit v0.12