summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsanchorlayout.cpp
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-19 09:46:06 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-19 09:46:06 (GMT)
commit14c6433781fb946aab6e7f77fd190469e5fcfb94 (patch)
tree4e42d59995885b6067c6e77dad6d6cad092ee048 /src/gui/graphicsview/qgraphicsanchorlayout.cpp
parent9da9e6f9bcead138297765b2782f73b68799827a (diff)
downloadQt-14c6433781fb946aab6e7f77fd190469e5fcfb94.zip
Qt-14c6433781fb946aab6e7f77fd190469e5fcfb94.tar.gz
Qt-14c6433781fb946aab6e7f77fd190469e5fcfb94.tar.bz2
update API to what was agreed on the API review meeting yesterday:
The changes are: * Move enums in QGraphicsAnchorLayout::Edge to Qt::AnchorPoint. Prefix them with Anchor since they are not edges in general. * Rename anchor() to addAnchor() * Rename anchorCorner() -> addCornerAnchors() * Rename anchorWidth() -> addLeftAndRightAnchors() * Rename anchorHeight() -> addTopAndBottomAnchors() * Rename anchorGeometry() -> addAllAnchors() * remove the overloads that take a spacing argument, and add setAnchorSpacing() to accommodate for that. * Added anchorSpacing() (implementation missing) * Added unsetAnchorSpacing(). (implementation missing) * made sizeHint() protected. Updated all examples and autotest to reflect this API change.
Diffstat (limited to 'src/gui/graphicsview/qgraphicsanchorlayout.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp140
1 files changed, 48 insertions, 92 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index a0e1101..db79dae 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -56,7 +56,7 @@
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
QGraphicsWidget *a = new QGraphicsWidget;
QGraphicsWidget *b = new QGraphicsWidget;
- l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left);
+ l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
\endcode
Here is the right edge of item A anchored to the left edge of item B, with the result that
@@ -114,7 +114,7 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
/*!
* Creates an anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge
* of item \a secondItem. The magnitude of the anchor is picked up from the style. Anchors
- * between a layout edge and an item edge will have a size of 0.
+ * between a layout edge and an item edge will have a size of 0.
* If there is already an anchor between the edges, the the new anchor will replace the old one.
*
* \a firstItem and \a secondItem are automatically added to the layout if they are not part
@@ -126,31 +126,27 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
* the default vertical spacing). For all other anchor combinations, the spacing will be 0.
* All anchoring functions will follow this rule.
*
- * \sa removeAnchor, anchorCorner, anchorWidth, anchorHeight, anchorGeometry
+ * The spacing can also be set manually by using setAnchorSpacing() method.
+ *
+ * \sa removeAnchor, addCornerAnchors, addLeftAndRightAnchors, addTopAndBottomAnchors, addAllAnchors
*/
-void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem,
- Edge firstEdge,
- QGraphicsLayoutItem *secondItem,
- Edge secondEdge)
+void QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
{
Q_D(QGraphicsAnchorLayout);
d->anchor(firstItem, firstEdge, secondItem, secondEdge);
invalidate();
}
-/*!
- * \overload
- *
- * By calling this function the caller can specify the magnitude of the anchor with \a spacing.
- *
- */
-void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem,
- Edge firstEdge,
- QGraphicsLayoutItem *secondItem,
- Edge secondEdge, qreal spacing)
+void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge,
+ qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing);
+
+ if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, spacing)) {
+ qWarning("setAnchorSpacing: The anchor does not exist.");
+ }
invalidate();
}
@@ -163,14 +159,14 @@ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem,
* This is a convenience function, since anchoring corners can be expressed as anchoring two edges.
* For instance,
* \code
- * layout->anchor(layout, QGraphicsAnchorLayout::Top, b, QGraphicsAnchorLayout::Top);
- * layout->anchor(layout, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Left);
+ * layout->addAnchor(layout, Qt::AnchorTop, b, Qt::AnchorTop);
+ * layout->addAnchor(layout, Qt::AnchorLeft, b, Qt::AnchorLeft);
* \endcode
*
* has the same effect as
*
* \code
- * layout->anchorCorner(layout, Qt::TopLeft, b, Qt::TopLeft);
+ * layout->addCornerAnchors(layout, Qt::TopLeft, b, Qt::TopLeft);
* \endcode
*
* If there is already an anchor between the edge pairs, it will be replaced by the anchors that
@@ -179,116 +175,76 @@ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem,
* \a firstItem and \a secondItem are automatically added to the layout if they are not part
* of the layout. This means that count() can increase with up to 2.
*/
-void QGraphicsAnchorLayout::anchorCorner(QGraphicsLayoutItem *firstItem,
- Qt::Corner firstCorner,
- QGraphicsLayoutItem *secondItem,
- Qt::Corner secondCorner)
+void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
+ Qt::Corner firstCorner,
+ QGraphicsLayoutItem *secondItem,
+ Qt::Corner secondCorner)
{
Q_D(QGraphicsAnchorLayout);
// Horizontal anchor
- QGraphicsAnchorLayout::Edge firstEdge = (firstCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left);
- QGraphicsAnchorLayout::Edge secondEdge = (secondCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left);
+ Qt::AnchorPoint firstEdge = (firstCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft);
+ Qt::AnchorPoint secondEdge = (secondCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft);
d->anchor(firstItem, firstEdge, secondItem, secondEdge);
// Vertical anchor
- firstEdge = (firstCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top);
- secondEdge = (secondCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top);
+ firstEdge = (firstCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop);
+ secondEdge = (secondCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop);
d->anchor(firstItem, firstEdge, secondItem, secondEdge);
invalidate();
}
/*!
- * \overload
- *
- * By calling this function the caller can specify the magnitude of the anchor with \a spacing.
- *
- */
-void QGraphicsAnchorLayout::anchorCorner(QGraphicsLayoutItem *firstItem,
- Qt::Corner firstCorner,
- QGraphicsLayoutItem *secondItem,
- Qt::Corner secondCorner, qreal spacing)
-{
- Q_D(QGraphicsAnchorLayout);
-
- // Horizontal anchor
- QGraphicsAnchorLayout::Edge firstEdge = (firstCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left);
- QGraphicsAnchorLayout::Edge secondEdge = (secondCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left);
- d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing);
-
- // Vertical anchor
- firstEdge = (firstCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top);
- secondEdge = (secondCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top);
- d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing);
-
- invalidate();
-}
-
-/*!
- \fn QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0)
+ \fn QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
This convenience function is equivalent to calling
\code
- if (!relativeTo)
- relativeTo = lay;
- lay->anchor(relativeTo, QGraphicsAnchorLayout::Left, item, QGraphicsAnchorLayout::Left);
- lay->anchor(relativeTo, QGraphicsAnchorLayout::Right, item, QGraphicsAnchorLayout::Right);
+ l->addAnchor(firstEdge, Qt::AnchorLeft, secondEdge, Qt::AnchorLeft);
+ l->addAnchor(firstEdge, Qt::AnchorRight, secondEdge, Qt::AnchorRight);
\endcode
*/
/*!
- \fn QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing)
-
- \overload
-
- By calling this function the caller can specify the magnitude of the anchor with \a spacing.
-*/
-
-/*!
- \fn QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0)
+ \fn QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
This convenience function is equivalent to calling
\code
- if (!relativeTo)
- relativeTo = lay;
- lay->anchor(relativeTo, QGraphicsAnchorLayout::Top, item, QGraphicsAnchorLayout::Top);
- lay->anchor(relativeTo, QGraphicsAnchorLayout::Bottom, item, QGraphicsAnchorLayout::Bottom);
+ l->addAnchor(firstEdge, Qt::AnchorTop, secondEdge, Qt::AnchorTop);
+ l->addAnchor(firstEdge, Qt::AnchorBottom, secondEdge, Qt::AnchorBottom);
\endcode
*/
/*!
- \fn QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing)
-
- \overload
-
- By calling this function the caller can specify the magnitude of the anchor with \a spacing.
-*/
-
-/*!
- \fn QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0)
+ \fn QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge)
This convenience function is equivalent to calling
\code
- anchorWidth(item, relativeTo);
- anchorHeight(item, relativeTo);
+ l->addLeftAndRightAnchors(firstEdge, secondEdge);
+ l->addTopAndBottomAnchors(firstEdge, secondEdge);
\endcode
*/
-/*!
- \fn QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing)
-
- \overload
+qreal QGraphicsAnchorLayout::anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const
+{
+ qWarning("// ### TO BE IMPLEMENTED");
+ return 0;
+}
- By calling this function the caller can specify the magnitude of the anchor with \a spacing.
-*/
+void QGraphicsAnchorLayout::unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
+{
+ qWarning("// ### TO BE IMPLEMENTED");
+ invalidate();
+}
/*!
Removes the anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge
of item \a secondItem. If such an anchor does not exist, the layout will be left unchanged.
*/
-void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Edge firstEdge,
- QGraphicsLayoutItem *secondItem, Edge secondEdge)
+void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
{
Q_D(QGraphicsAnchorLayout);
if ((firstItem == 0) || (secondItem == 0)) {