diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.cpp | 53 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.h | 9 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 40 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 19 |
4 files changed, 95 insertions, 26 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index db79dae..5032dc6 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -138,18 +138,6 @@ void QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::Anchor invalidate(); } -void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, - const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, - qreal spacing) -{ - Q_D(QGraphicsAnchorLayout); - - if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, spacing)) { - qWarning("setAnchorSpacing: The anchor does not exist."); - } - invalidate(); -} - /*! * Creates two anchors between \a firstItem and \a secondItem, where one is for the horizontal * edge and another one for the vertical edge that the corners \a firstCorner and \a @@ -225,17 +213,52 @@ void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem, \endcode */ +/*! + Set the spacing between the anchor point defined by \a firstItem and \a firstEdge and + \a secondItem and \a secondEdge to be \a spacing. +*/ +void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, + qreal spacing) +{ + Q_D(QGraphicsAnchorLayout); + + if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, &spacing)) { + qWarning("setAnchorSpacing: The anchor does not exist."); + } + invalidate(); +} + +/*! + Returns the spacing between the anchor point defined by \a firstItem and \a firstEdge and + \a secondItem and \a secondEdge. The anchor must exist. +*/ qreal QGraphicsAnchorLayout::anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const { - qWarning("// ### TO BE IMPLEMENTED"); - return 0; + Q_D(const QGraphicsAnchorLayout); + qreal size = 0; + if (!d->anchorSize(firstItem, firstEdge, secondItem, secondEdge, 0, &size)) { + qWarning("anchorSpacing: The anchor does not exist."); + } + return size; } +/*! + Resets the spacing between the anchor point defined by \a firstItem and \a firstEdge and + \a secondItem and \a secondEdge to be the default spacing. Depending on the anchor type, the + default spacing is either 0 or a value returned from the style. + + \sa setAnchorSpacing, anchorSpacing, addAnchor +*/ void QGraphicsAnchorLayout::unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) { - qWarning("// ### TO BE IMPLEMENTED"); + Q_D(QGraphicsAnchorLayout); + + if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, 0)) { + qWarning("unsetAnchorSpacing: The anchor does not exist."); + } invalidate(); } diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h index f2335a8..3de9ae5 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout.h @@ -65,10 +65,6 @@ public: void addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge); - void setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, - const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, - qreal spacing); - void addCornerAnchors(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner); @@ -81,8 +77,13 @@ public: inline void addAllAnchors(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem); + void setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, + qreal spacing); + qreal anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const; + void unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 436ce2c..ffece0d 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1125,17 +1125,49 @@ bool QGraphicsAnchorLayoutPrivate::setAnchorSize(const QGraphicsLayoutItem *firs Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, - qreal anchorSize) + const qreal *anchorSize) { - // ### we can avoid restoration if we really want to + // ### we can avoid restoration if we really want to, but we would have to + // search recursively through all composite anchors restoreSimplifiedGraph(edgeOrientation(firstEdge)); AnchorVertex *v1 = internalVertex(firstItem, firstEdge); AnchorVertex *v2 = internalVertex(secondItem, secondEdge); AnchorData *data = graph[edgeOrientation(firstEdge)].edgeData(v1, v2); - if (data) - data->setFixedSize(anchorSize); + if (data) { + if (anchorSize) { + data->setFixedSize(*anchorSize); + } else { + data->unsetSize(); + } + } + + return data; +} +bool QGraphicsAnchorLayoutPrivate::anchorSize(const QGraphicsLayoutItem *firstItem, + Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, + Qt::AnchorPoint secondEdge, + qreal *minSize, + qreal *prefSize, + qreal *maxSize) const +{ + Q_ASSERT(minSize || prefSize || maxSize); + QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate *>(this); + that->restoreSimplifiedGraph(edgeOrientation(firstEdge)); + AnchorVertex *v1 = internalVertex(firstItem, firstEdge); + AnchorVertex *v2 = internalVertex(secondItem, secondEdge); + + AnchorData *data = that->graph[edgeOrientation(firstEdge)].edgeData(v1, v2); + if (data) { + if (minSize) + *minSize = data->minSize; + if (prefSize) + *prefSize = data->prefSize; + if (maxSize) + *maxSize = data->maxSize; + } return data; } diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 742108d..e17bd28 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -176,6 +176,11 @@ struct AnchorData : public QSimplexVariable { hasSize = true; } + inline void unsetSize() + { + hasSize = false; + } + // Anchor is semantically directed AnchorVertex *from; AnchorVertex *to; @@ -367,7 +372,15 @@ public: Qt::AnchorPoint firstEdge, const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, - qreal anchorSize); + const qreal *anchorSize); + + bool anchorSize(const QGraphicsLayoutItem *firstItem, + Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, + Qt::AnchorPoint secondEdge, + qreal *minSize = 0, + qreal *prefSize = 0, + qreal *maxSize = 0) const; void removeAnchors(QGraphicsLayoutItem *item); @@ -394,12 +407,12 @@ public: QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors); QList<QList<QSimplexConstraint *> > getGraphParts(Orientation orientation); - inline AnchorVertex *internalVertex(const QPair<QGraphicsLayoutItem*, Qt::AnchorPoint> &itemEdge) + inline AnchorVertex *internalVertex(const QPair<QGraphicsLayoutItem*, Qt::AnchorPoint> &itemEdge) const { return m_vertexList.value(itemEdge).first; } - inline AnchorVertex *internalVertex(const QGraphicsLayoutItem *item, Qt::AnchorPoint edge) + inline AnchorVertex *internalVertex(const QGraphicsLayoutItem *item, Qt::AnchorPoint edge) const { return internalVertex(qMakePair(const_cast<QGraphicsLayoutItem *>(item), edge)); } |