src/declarative/graphicsitems/qdeclarativelayoutitem.cpp
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "private/qdeclarativelayoutitem_p.h"
       
    43 
       
    44 #include <QDebug>
       
    45 
       
    46 #include <limits.h>
       
    47 
       
    48 QT_BEGIN_NAMESPACE
       
    49 
       
    50 /*!
       
    51     \qmlclass LayoutItem QDeclarativeLayoutItem
       
    52     \since 4.7
       
    53     \brief The LayoutItem element allows you to place your declarative UI elements inside a classical Qt layout.
       
    54 
       
    55     LayoutItem is a variant of Item with a couple of additional properties. These properties provide the size hints
       
    56     needed for items to work in conjunction with Qt Layouts. The Qt Layout will resize the LayoutItem as appropriate,
       
    57     taking its size hints into account, and you can propagate this to the other elements in your UI via anchors and bindings.
       
    58 
       
    59     This is a QGraphicsLayoutItem subclass, and the properties merely expose the QGraphicsLayoutItem functionality to QML.
       
    60     See the QGraphicsLayoutItem documentation for further details.
       
    61 */
       
    62 
       
    63 /*!
       
    64     \internal
       
    65     \class QDeclarativeLayoutItem
       
    66     \brief The QDeclarativeLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout.
       
    67 */
       
    68 
       
    69 
       
    70 /*!
       
    71     \qmlproperty QSizeF LayoutItem::maximumSize
       
    72 
       
    73     The maximumSize property can be set to specify the maximum desired size of this LayoutItem
       
    74 */
       
    75 
       
    76 /*!
       
    77     \qmlproperty QSizeF LayoutItem::minimumSize
       
    78 
       
    79     The minimumSize property can be set to specify the minimum desired size of this LayoutItem
       
    80 */
       
    81 
       
    82 /*!
       
    83     \qmlproperty QSizeF LayoutItem::preferredSize
       
    84 
       
    85     The preferredSize property can be set to specify the preferred size of this LayoutItem
       
    86 */
       
    87 
       
    88 QDeclarativeLayoutItem::QDeclarativeLayoutItem(QDeclarativeItem* parent)
       
    89     : QDeclarativeItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(0,0)
       
    90 {
       
    91     setGraphicsItem(this);
       
    92 }
       
    93 
       
    94 void QDeclarativeLayoutItem::setGeometry(const QRectF & rect)
       
    95 {
       
    96     setX(rect.x());
       
    97     setY(rect.y());
       
    98     setWidth(rect.width());
       
    99     setHeight(rect.height());
       
   100 }
       
   101 
       
   102 QSizeF QDeclarativeLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const
       
   103 {
       
   104     Q_UNUSED(constraint);
       
   105     if(w == Qt::MinimumSize){
       
   106         return m_minimumSize;
       
   107     }else if(w == Qt::MaximumSize){
       
   108         return m_maximumSize;
       
   109     }else{
       
   110         return m_preferredSize;
       
   111     }
       
   112 }
       
   113 
       
   114 QT_END_NAMESPACE