src/gui/graphicsview/qgraphicslayoutitem.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    46 #include "qgraphicslayout.h"
    46 #include "qgraphicslayout.h"
    47 #include "qgraphicsscene.h"
    47 #include "qgraphicsscene.h"
    48 #include "qgraphicslayoutitem.h"
    48 #include "qgraphicslayoutitem.h"
    49 #include "qgraphicslayoutitem_p.h"
    49 #include "qgraphicslayoutitem_p.h"
    50 #include "qwidget.h"
    50 #include "qwidget.h"
       
    51 #include "qgraphicswidget.h"
    51 
    52 
    52 #include <QtDebug>
    53 #include <QtDebug>
    53 
    54 
    54 QT_BEGIN_NAMESPACE
    55 QT_BEGIN_NAMESPACE
    55 
    56 
   137 {
   138 {
   138     Q_Q(const QGraphicsLayoutItem);
   139     Q_Q(const QGraphicsLayoutItem);
   139     if (!sizeHintCacheDirty && cachedConstraint == constraint)
   140     if (!sizeHintCacheDirty && cachedConstraint == constraint)
   140         return cachedSizeHints;
   141         return cachedSizeHints;
   141 
   142 
       
   143     const bool hasConstraint = constraint.width() >= 0 || constraint.height() >= 0;
       
   144 
   142     for (int i = 0; i < Qt::NSizeHints; ++i) {
   145     for (int i = 0; i < Qt::NSizeHints; ++i) {
   143         cachedSizeHints[i] = constraint;
   146         cachedSizeHints[i] = constraint;
   144         if (userSizeHints)
   147         if (userSizeHints && !hasConstraint)
   145             combineSize(cachedSizeHints[i], userSizeHints[i]);
   148             combineSize(cachedSizeHints[i], userSizeHints[i]);
   146     }
   149     }
   147 
   150 
   148     QSizeF &minS = cachedSizeHints[Qt::MinimumSize];
   151     QSizeF &minS = cachedSizeHints[Qt::MinimumSize];
   149     QSizeF &prefS = cachedSizeHints[Qt::PreferredSize];
   152     QSizeF &prefS = cachedSizeHints[Qt::PreferredSize];
   255         : userSizeHints[which].rheight();
   258         : userSizeHints[which].rheight();
   256     if (value == userValue)
   259     if (value == userValue)
   257         return;
   260         return;
   258     userValue = value;
   261     userValue = value;
   259     q->updateGeometry();
   262     q->updateGeometry();
       
   263 }
       
   264 
       
   265 
       
   266 bool QGraphicsLayoutItemPrivate::hasHeightForWidth() const
       
   267 {
       
   268     Q_Q(const QGraphicsLayoutItem);
       
   269     if (isLayout) {
       
   270         const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
       
   271         for (int i = l->count() - 1; i >= 0; --i) {
       
   272             if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasHeightForWidth())
       
   273                 return true;
       
   274         }
       
   275     } else if (QGraphicsItem *item = q->graphicsItem()) {
       
   276         if (item->isWidget()) {
       
   277             QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
       
   278             if (w->layout()) {
       
   279                 return QGraphicsLayoutItemPrivate::get(w->layout())->hasHeightForWidth();
       
   280             }
       
   281         }
       
   282     }
       
   283     return q->sizePolicy().hasHeightForWidth();
       
   284 }
       
   285 
       
   286 bool QGraphicsLayoutItemPrivate::hasWidthForHeight() const
       
   287 {
       
   288     // enable this code when we add QSizePolicy::hasWidthForHeight() (For 4.8)
       
   289 #if 1
       
   290     return false;
       
   291 #else
       
   292     Q_Q(const QGraphicsLayoutItem);
       
   293     if (isLayout) {
       
   294         const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
       
   295         for (int i = l->count() - 1; i >= 0; --i) {
       
   296             if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasWidthForHeight())
       
   297                 return true;
       
   298         }
       
   299     } else if (QGraphicsItem *item = q->graphicsItem()) {
       
   300         if (item->isWidget()) {
       
   301             QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
       
   302             if (w->layout()) {
       
   303                 return QGraphicsLayoutItemPrivate::get(w->layout())->hasWidthForHeight();
       
   304             }
       
   305         }
       
   306     }
       
   307     return q->sizePolicy().hasWidthForHeight();
       
   308 #endif
   260 }
   309 }
   261 
   310 
   262 /*!
   311 /*!
   263     \class QGraphicsLayoutItem
   312     \class QGraphicsLayoutItem
   264     \brief The QGraphicsLayoutItem class can be inherited to allow your custom
   313     \brief The QGraphicsLayoutItem class can be inherited to allow your custom