From 301ba29eb8b08d9c040ee80c8a6e4e98bea91dee Mon Sep 17 00:00:00 2001 From: "Anselmo Lacerda S. de Melo" Date: Tue, 15 Sep 2009 12:49:53 -0300 Subject: QGraphicsAnchorLayout: Initial support for Size Policy In this commit we introduce initial support for Size Policy. The size policies supported now are: * QSizePolicy::Fixed * QSizePolicy::Minimum * QSizePolicy::Maximum * QSizePolicy::Preferred * QSizePolicy::Ignored Signed-off-by: Anselmo Lacerda S. de Melo --- src/gui/graphicsview/qgraphicsanchorlayout.cpp | 1 - src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 43 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 12124ab..78b6b53 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -434,7 +434,6 @@ void QGraphicsAnchorLayout::invalidate() */ QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { - Q_UNUSED(which); Q_UNUSED(constraint); Q_D(const QGraphicsAnchorLayout); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 23601f9..f7266e2 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -98,17 +98,52 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing) bool hasCenter = false; QGraphicsLayoutItem *item = from->m_item; + QSizePolicy policy = item->sizePolicy(); + if (QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) == QGraphicsAnchorLayoutPrivate::Horizontal) { - minSize = item->minimumWidth(); + + // minSize, prefSize and maxSize are initialized + // with item's preferred Size: this is QSizePolicy::Fixed. + // + // Then we check each flag to find the resultant QSizePolicy, + // according to the following table: + // + // constant value + // QSizePolicy::Fixed 0 + // QSizePolicy::Minimum GrowFlag + // QSizePolicy::Maximum ShrinkFlag + // QSizePolicy::Preferred GrowFlag | ShrinkFlag + // QSizePolicy::Ignored GrowFlag | ShrinkFlag | IgnoreFlag prefSize = item->preferredWidth(); - maxSize = item->maximumWidth(); + minSize = prefSize; + maxSize = prefSize; + + if (policy.horizontalPolicy() & QSizePolicy::GrowFlag) + maxSize = item->maximumWidth(); + + if (policy.horizontalPolicy() & QSizePolicy::ShrinkFlag) + minSize = item->minimumWidth(); + + if (policy.horizontalPolicy() & QSizePolicy::IgnoreFlag) + prefSize = minSize; + hasCenter = (from->m_edge == Qt::AnchorHorizontalCenter || to->m_edge == Qt::AnchorHorizontalCenter); } else { - minSize = item->minimumHeight(); prefSize = item->preferredHeight(); - maxSize = item->maximumHeight(); + minSize = prefSize; + maxSize = prefSize; + + if (policy.verticalPolicy() & QSizePolicy::GrowFlag) + maxSize = item->maximumHeight(); + + if (policy.verticalPolicy() & QSizePolicy::ShrinkFlag) + minSize = item->minimumHeight(); + + if (policy.verticalPolicy() & QSizePolicy::IgnoreFlag) + prefSize = minSize; + hasCenter = (from->m_edge == Qt::AnchorVerticalCenter || to->m_edge == Qt::AnchorVerticalCenter); } -- cgit v0.12