From d3d455e6d019a381b338c24b3c2593b2e12215cb Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 23 Jun 2009 10:45:49 -0300 Subject: QGraphicsAnchorLayout: Add convencience "fill" methods Adding "fillWidth()", "fillHeight()" and "fill()". These convenience methods simplify the creation of anchor setups where some items are meant to use the full width and/or height of the layout. For instance, instead of creating four anchors (bottom, top, left, right) between an item and the layout, to make it use the full layout area, the user can call layout->fill(item). It is also possible to make an item assume the same width or height of another item, calling layout->fill(firstItem, secondItem). Signed-off-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraphicsanchorlayout.h | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h index cd1c080..74075ff 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout.h @@ -78,6 +78,13 @@ public: void removeAnchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, QGraphicsLayoutItem *secondItem, Edge secondEdge); + inline void fillWidth(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo = 0); + inline void fillHeight(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo = 0); + inline void fill(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo = 0); + void setSpacing(qreal spacing, Qt::Orientations orientations = Qt::Horizontal|Qt::Vertical); qreal spacing(Qt::Orientation) const; @@ -98,6 +105,35 @@ private: Q_DECLARE_PRIVATE(QGraphicsAnchorLayout) }; +void QGraphicsAnchorLayout::fillWidth(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo) +{ + if (!relativeTo) + relativeTo = this; + + anchor(relativeTo, Left, item, Left); + anchor(item, Right, relativeTo, Right); +} + +void QGraphicsAnchorLayout::fillHeight(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo) +{ + if (!relativeTo) + relativeTo = this; + + anchor(relativeTo, Top, item, Top); + anchor(item, Bottom, relativeTo, Bottom); +} + +void QGraphicsAnchorLayout::fill(QGraphicsLayoutItem *item, + QGraphicsLayoutItem *relativeTo) +{ + if (!relativeTo) + relativeTo = this; + + fillWidth(item, relativeTo); + fillHeight(item, relativeTo); +} #endif -- cgit v0.12