summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-07-22 08:25:26 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-22 18:04:47 (GMT)
commit8bb931a6bff959279189662299ad6f8516de1789 (patch)
treeb222292a9f19c5818c14ae31acc0ed7ca674f186
parent4a03627703af9119e02024239cfdb464c5013396 (diff)
downloadQt-8bb931a6bff959279189662299ad6f8516de1789.zip
Qt-8bb931a6bff959279189662299ad6f8516de1789.tar.gz
Qt-8bb931a6bff959279189662299ad6f8516de1789.tar.bz2
Make sure that internal center anchors are not simplified.
-rw-r--r--examples/layouts/anchorlayout/xml/center.xml57
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp21
2 files changed, 76 insertions, 2 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<anchorlayout>
+ <item id="item_1">
+ <property name="minimumSize">
+ <size width="0" height="0"/>
+ </property>
+ <property name="preferredSize">
+ <size width="50" height="50"/>
+ </property>
+ <property name="maximumSize">
+ <size width="1.67772e+07" height="1.67772e+07"/>
+ </property>
+ </item>
+ <item id="item_2">
+ <property name="minimumSize">
+ <size width="0" height="0"/>
+ </property>
+ <property name="preferredSize">
+ <size width="50" height="50"/>
+ </property>
+ <property name="maximumSize">
+ <size width="1.67772e+07" height="1.67772e+07"/>
+ </property>
+ </item>
+ <item id="item_3">
+ <property name="minimumSize">
+ <size width="0" height="0"/>
+ </property>
+ <property name="preferredSize">
+ <size width="50" height="50"/>
+ </property>
+ <property name="maximumSize">
+ <size width="1.67772e+07" height="1.67772e+07"/>
+ </property>
+ </item>
+ <item id="item_4">
+ <property name="minimumSize">
+ <size width="0" height="0"/>
+ </property>
+ <property name="preferredSize">
+ <size width="50" height="50"/>
+ </property>
+ <property name="maximumSize">
+ <size width="1.67772e+07" height="1.67772e+07"/>
+ </property>
+ </item>
+ <anchor first="this.Left" second="item_1.Left"/>
+ <anchor first="item_1.Right" second="item_2.Left"/>
+ <anchor first="item_2.Right" second="item_3.Left"/>
+ <anchor first="item_3.Right" second="this.Right"/>
+ <anchor first="item_2.HCenter" second="item_4.Left"/>
+ <anchor first="item_4.Right" second="this.Right"/>
+ <anchor first="this.Top" second="item_1.Top"/>
+ <anchor first="this.Top" second="item_2.Top"/>
+ <anchor first="this.Top" second="item_3.Top"/>
+ <anchor first="item_1.Bottom" second="item_4.Top"/>
+</anchorlayout>
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<AnchorVertex, AnchorData> &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<AnchorVertex*> 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<AnchorVertex*> 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