summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-09 19:42:58 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-07-22 18:04:56 (GMT)
commit7bf639f5484bb5fe34cab53ab1dfde048e158995 (patch)
tree5c212ab54b4add859ca74e26ae105d711b4656fb /src/gui
parent22a6ce9b329a081d07296533980d374b0c7ad88b (diff)
downloadQt-7bf639f5484bb5fe34cab53ab1dfde048e158995.zip
Qt-7bf639f5484bb5fe34cab53ab1dfde048e158995.tar.gz
Qt-7bf639f5484bb5fe34cab53ab1dfde048e158995.tar.bz2
QGraphicsAnchorLayout: Create center edges on demand
Since the previous commit, center anchors are no longer created when an item is added to the layout. This commit creates only the required anchors, when needed. 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')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp62
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h1
2 files changed, 63 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 1564163..8a37cad 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -505,6 +505,64 @@ void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item)
QGraphicsAnchorLayout::Bottom, data);
}
+void QGraphicsAnchorLayoutPrivate::createCenterAnchors(
+ QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge)
+{
+ Orientation orientation;
+ switch (centerEdge) {
+ case QGraphicsAnchorLayout::HCenter:
+ orientation = Horizontal;
+ break;
+ case QGraphicsAnchorLayout::VCenter:
+ orientation = Vertical;
+ break;
+ default:
+ // Don't create center edges unless needed
+ return;
+ }
+
+ // Check if vertex already exists
+ if (internalVertex(item, centerEdge))
+ 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 anchors
+ AnchorData *oldData = graph[orientation].edgeData(first, last);
+
+ int minimumSize = oldData->minSize / 2;
+ int preferredSize = oldData->prefSize / 2;
+ int maximumSize = oldData->maxSize / 2;
+
+ QSimplexConstraint *c = new QSimplexConstraint;
+ AnchorData *data = new AnchorData(minimumSize, preferredSize, maximumSize);
+ c->variables.insert(data, 1.0);
+ addAnchor(item, firstEdge, item, centerEdge, data);
+
+ data = new AnchorData(minimumSize, preferredSize, maximumSize);
+ c->variables.insert(data, -1.0);
+ addAnchor(item, centerEdge, item, lastEdge, data);
+
+ itemCenterConstraints[orientation].append(c);
+
+ // Remove old one
+ removeAnchor(item, firstEdge, item, lastEdge);
+}
+
void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *item,
Orientation orientation)
{
@@ -580,6 +638,10 @@ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem,
addChildLayoutItem(secondItem);
}
+ // Create center edges if needed
+ createCenterAnchors(firstItem, firstEdge);
+ createCenterAnchors(secondItem, secondEdge);
+
// Use heuristics to find out what the user meant with this anchor.
correctEdgeDirection(firstItem, firstEdge, secondItem, secondEdge);
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index 9e6c1bc..d036201 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -292,6 +292,7 @@ public:
void createLayoutEdges();
void deleteLayoutEdges();
void createItemEdges(QGraphicsLayoutItem *item);
+ void createCenterAnchors(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge);
void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation);
// helper function used by the 4 API functions