qgraphicslayoutitem.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QGRAPHICSLAYOUTITEM_H
00043 #define QGRAPHICSLAYOUTITEM_H
00044 
00045 #include <QtCore/qscopedpointer.h>
00046 #include <QtGui/qsizepolicy.h>
00047 #include <QtGui/qevent.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
00056 
00057 class QGraphicsLayoutItemPrivate;
00058 class QGraphicsItem;
00059 class Q_GUI_EXPORT QGraphicsLayoutItem
00060 {
00061 public:
00062     QGraphicsLayoutItem(QGraphicsLayoutItem *parent = 0, bool isLayout = false);
00063     virtual ~QGraphicsLayoutItem();
00064 
00065     void setSizePolicy(const QSizePolicy &policy);
00066     void setSizePolicy(QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType = QSizePolicy::DefaultType);
00067     QSizePolicy sizePolicy() const;
00068 
00069     void setMinimumSize(const QSizeF &size);
00070     inline void setMinimumSize(qreal w, qreal h);
00071     QSizeF minimumSize() const;
00072     void setMinimumWidth(qreal width);
00073     inline qreal minimumWidth() const;
00074     void setMinimumHeight(qreal height);
00075     inline qreal minimumHeight() const;
00076 
00077     void setPreferredSize(const QSizeF &size);
00078     inline void setPreferredSize(qreal w, qreal h);
00079     QSizeF preferredSize() const;
00080     void setPreferredWidth(qreal width);
00081     inline qreal preferredWidth() const;
00082     void setPreferredHeight(qreal height);
00083     inline qreal preferredHeight() const;
00084 
00085     void setMaximumSize(const QSizeF &size);
00086     inline void setMaximumSize(qreal w, qreal h);
00087     QSizeF maximumSize() const;
00088     void setMaximumWidth(qreal width);
00089     inline qreal maximumWidth() const;
00090     void setMaximumHeight(qreal height);
00091     inline qreal maximumHeight() const;
00092 
00093     virtual void setGeometry(const QRectF &rect);
00094     QRectF geometry() const;
00095     virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
00096     QRectF contentsRect() const;
00097 
00098     QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
00099 
00100     virtual void updateGeometry();  //### rename to sizeHintChanged()
00101 
00102     QGraphicsLayoutItem *parentLayoutItem() const;
00103     void setParentLayoutItem(QGraphicsLayoutItem *parent);
00104 
00105     bool isLayout() const;
00106     // ###Qt5: Make automatic reparenting work regardless of item/object/widget type.
00107     QGraphicsItem *graphicsItem() const;
00108     bool ownedByLayout() const;
00109 
00110 protected:
00111     void setGraphicsItem(QGraphicsItem *item);
00112     void setOwnedByLayout(bool ownedByLayout);
00113     QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd);
00114 
00115     virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const = 0;
00116     QScopedPointer<QGraphicsLayoutItemPrivate> d_ptr;
00117 
00118 private:
00119     QSizeF *effectiveSizeHints(const QSizeF &constraint) const;
00120     Q_DECLARE_PRIVATE(QGraphicsLayoutItem)
00121     
00122     friend class QGraphicsLayout;
00123 };
00124 
00125 Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "com.trolltech.Qt.QGraphicsLayoutItem")
00126 
00127 inline void QGraphicsLayoutItem::setMinimumSize(qreal aw, qreal ah)
00128 { setMinimumSize(QSizeF(aw, ah)); }
00129 inline void QGraphicsLayoutItem::setPreferredSize(qreal aw, qreal ah)
00130 { setPreferredSize(QSizeF(aw, ah)); }
00131 inline void QGraphicsLayoutItem::setMaximumSize(qreal aw, qreal ah)
00132 { setMaximumSize(QSizeF(aw, ah)); }
00133 
00134 inline qreal QGraphicsLayoutItem::minimumWidth() const
00135 { return effectiveSizeHint(Qt::MinimumSize).width(); }
00136 inline qreal QGraphicsLayoutItem::minimumHeight() const
00137 { return effectiveSizeHint(Qt::MinimumSize).height(); }
00138 
00139 inline qreal QGraphicsLayoutItem::preferredWidth() const
00140 { return effectiveSizeHint(Qt::PreferredSize).width(); }
00141 inline qreal QGraphicsLayoutItem::preferredHeight() const
00142 { return effectiveSizeHint(Qt::PreferredSize).height(); }
00143 
00144 inline qreal QGraphicsLayoutItem::maximumWidth() const
00145 { return effectiveSizeHint(Qt::MaximumSize).width(); }
00146 inline qreal QGraphicsLayoutItem::maximumHeight() const
00147 { return effectiveSizeHint(Qt::MaximumSize).height(); }
00148 
00149 #endif
00150 
00151 QT_END_NAMESPACE
00152 
00153 QT_END_HEADER
00154 
00155 #endif