diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> | 2009-10-16 15:26:21 (GMT) |
---|---|---|
committer | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-10-26 22:17:47 (GMT) |
commit | bee00ac4ca0865e621edaea54d079005c68f120e (patch) | |
tree | 5cef546fbe483a12d5d698fc5902224e19be36bd | |
parent | f9dfd711d104bb438da6ea281012600a897ab30c (diff) | |
download | Qt-bee00ac4ca0865e621edaea54d079005c68f120e.zip Qt-bee00ac4ca0865e621edaea54d079005c68f120e.tar.gz Qt-bee00ac4ca0865e621edaea54d079005c68f120e.tar.bz2 |
QGAL: store item and center-ness information in the anchor
We used to look for this information in the anchor's from and to
vertices, but to enable simplification of vertices, we have to store
this information in the anchor.
Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org>
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 24 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 9 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 8d13b2b..aa510f1 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -143,31 +143,25 @@ static void internalSizeHints(QSizePolicy::Policy policy, bool AnchorData::refreshSizeHints(qreal effectiveSpacing) { - const bool isInternalAnchor = from->m_item == to->m_item; - QSizePolicy::Policy policy; qreal minSizeHint; qreal prefSizeHint; qreal maxSizeHint; - if (isInternalAnchor) { + // It is an internal anchor + if (item) { const QGraphicsAnchorLayoutPrivate::Orientation orient = QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge); - const Qt::AnchorPoint centerEdge = - QGraphicsAnchorLayoutPrivate::pickEdge(Qt::AnchorHorizontalCenter, orient); - bool hasCenter = (from->m_edge == centerEdge || to->m_edge == centerEdge); if (isLayoutAnchor) { minSize = 0; prefSize = 0; expSize = 0; maxSize = QWIDGETSIZE_MAX; - if (hasCenter) + if (isCenterAnchor) maxSize /= 2; return true; } else { - - QGraphicsLayoutItem *item = from->m_item; if (orient == QGraphicsAnchorLayoutPrivate::Horizontal) { policy = item->sizePolicy().horizontalPolicy(); minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).width(); @@ -180,7 +174,7 @@ bool AnchorData::refreshSizeHints(qreal effectiveSpacing) maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).height(); } - if (hasCenter) { + if (isCenterAnchor) { minSizeHint /= 2; prefSizeHint /= 2; maxSizeHint /= 2; @@ -1063,11 +1057,13 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( AnchorData *data = new AnchorData; c->variables.insert(data, 1.0); addAnchor_helper(item, firstEdge, item, centerEdge, data); + data->isCenterAnchor = true; data->refreshSizeHints(0); data = new AnchorData; c->variables.insert(data, -1.0); addAnchor_helper(item, centerEdge, item, lastEdge, data); + data->isCenterAnchor = true; data->refreshSizeHints(0); itemCenterConstraints[orientation].append(c); @@ -1304,6 +1300,10 @@ void QGraphicsAnchorLayoutPrivate::addAnchor_helper(QGraphicsLayoutItem *firstIt removeAnchor_helper(v1, v2); } + // If its an internal anchor, set the associated item + if (firstItem == secondItem) + data->item = firstItem; + // Create a bi-directional edge in the sense it can be transversed both // from v1 or v2. "data" however is shared between the two references // so we still know that the anchor direction is from 1 to 2. @@ -2188,8 +2188,8 @@ void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData switch(ad->type) { case AnchorData::Normal: - if (ad->from->m_item == ad->to->m_item && ad->to->m_item != q) - nonFloatingItemsIdentifiedSoFar->insert(ad->to->m_item); + if (ad->item && ad->item != q) + nonFloatingItemsIdentifiedSoFar->insert(ad->item); break; case AnchorData::Sequential: foreach (const AnchorData *d, static_cast<const SequentialAnchorData *>(ad)->m_edges) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index a3de6f6..511e1ec 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -151,12 +151,13 @@ struct AnchorData : public QSimplexVariable { }; AnchorData() - : QSimplexVariable(), from(0), to(0), + : QSimplexVariable(), item(0), from(0), to(0), minSize(0), prefSize(0), expSize(0), maxSize(0), sizeAtMinimum(0), sizeAtPreferred(0), sizeAtExpanding(0), sizeAtMaximum(0), graphicsAnchor(0), skipInPreferred(0), - type(Normal), hasSize(true), isLayoutAnchor(false) {} + type(Normal), hasSize(true), isLayoutAnchor(false), + isCenterAnchor(false) {} virtual void updateChildrenSizes() {} virtual bool refreshSizeHints(qreal effectiveSpacing); @@ -180,6 +181,9 @@ struct AnchorData : public QSimplexVariable { hasSize = false; } + // Internal anchors have associated items + QGraphicsLayoutItem *item; + // Anchor is semantically directed AnchorVertex *from; AnchorVertex *to; @@ -206,6 +210,7 @@ struct AnchorData : public QSimplexVariable { uint type : 2; // either Normal, Sequential or Parallel uint hasSize : 1; // if false, get size from style. uint isLayoutAnchor : 1; // if this anchor is connected to a layout 'edge' + uint isCenterAnchor : 1; }; #ifdef QT_DEBUG |