summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-14 21:40:35 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-22 18:04:57 (GMT)
commita52114c8ca9020773081c20a1094c078cfdb81fe (patch)
treebdd5c4d0cddd0b990dd9efe10a9287ab81a07b6e /src
parent7bf639f5484bb5fe34cab53ab1dfde048e158995 (diff)
downloadQt-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')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp71
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h1
3 files changed, 71 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index 31cc911..fe335e8 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -200,6 +200,8 @@ void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Edge fi
}
d->removeAnchor(firstItem, firstEdge, secondItem, secondEdge);
+ d->removeCenterAnchors(firstItem, firstEdge);
+ d->removeCenterAnchors(secondItem, secondEdge);
invalidate();
}
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) {
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index d036201..2f1aa97 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -293,6 +293,7 @@ public:
void deleteLayoutEdges();
void createItemEdges(QGraphicsLayoutItem *item);
void createCenterAnchors(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge);
+ void removeCenterAnchors(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge);
void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation);
// helper function used by the 4 API functions