1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qlayout.h"
|
---|
43 |
|
---|
44 | #include "qapplication.h"
|
---|
45 | #include "qlayoutengine_p.h"
|
---|
46 | #include "qmenubar.h"
|
---|
47 | #include "qtoolbar.h"
|
---|
48 | #include "qevent.h"
|
---|
49 | #include "qstyle.h"
|
---|
50 | #include "qvariant.h"
|
---|
51 | #include "qwidget_p.h"
|
---|
52 |
|
---|
53 | QT_BEGIN_NAMESPACE
|
---|
54 |
|
---|
55 | inline static QRect fromLayoutItemRect(QWidgetPrivate *priv, const QRect &rect)
|
---|
56 | {
|
---|
57 | return priv->fromOrToLayoutItemRect(rect, -1);
|
---|
58 | }
|
---|
59 |
|
---|
60 | inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
|
---|
61 | {
|
---|
62 | return fromLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size();
|
---|
63 | }
|
---|
64 |
|
---|
65 | inline static QRect toLayoutItemRect(QWidgetPrivate *priv, const QRect &rect)
|
---|
66 | {
|
---|
67 | return priv->fromOrToLayoutItemRect(rect, +1);
|
---|
68 | }
|
---|
69 |
|
---|
70 | inline static QSize toLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
|
---|
71 | {
|
---|
72 | return toLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size();
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*!
|
---|
76 | Returns a QVariant storing this QSizePolicy.
|
---|
77 | */
|
---|
78 | QSizePolicy::operator QVariant() const
|
---|
79 | {
|
---|
80 | return QVariant(QVariant::SizePolicy, this);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*!
|
---|
84 | \class QLayoutItem
|
---|
85 | \brief The QLayoutItem class provides an abstract item that a
|
---|
86 | QLayout manipulates.
|
---|
87 |
|
---|
88 | \ingroup appearance
|
---|
89 | \ingroup geomanagement
|
---|
90 |
|
---|
91 | This is used by custom layouts.
|
---|
92 |
|
---|
93 | Pure virtual functions are provided to return information about
|
---|
94 | the layout, including, sizeHint(), minimumSize(), maximumSize()
|
---|
95 | and expanding().
|
---|
96 |
|
---|
97 | The layout's geometry can be set and retrieved with setGeometry()
|
---|
98 | and geometry(), and its alignment with setAlignment() and
|
---|
99 | alignment().
|
---|
100 |
|
---|
101 | isEmpty() returns whether the layout item is empty. If the
|
---|
102 | concrete item is a QWidget, it can be retrieved using widget().
|
---|
103 | Similarly for layout() and spacerItem().
|
---|
104 |
|
---|
105 | Some layouts have width and height interdependencies. These can
|
---|
106 | be expressed using hasHeightForWidth(), heightForWidth(), and
|
---|
107 | minimumHeightForWidth(). For more explanation see the \e{Qt
|
---|
108 | Quarterly} article
|
---|
109 | \l{http://doc.trolltech.com/qq/qq04-height-for-width.html}{Trading
|
---|
110 | Height for Width}.
|
---|
111 |
|
---|
112 | \sa QLayout
|
---|
113 | */
|
---|
114 |
|
---|
115 | /*!
|
---|
116 | \class QSpacerItem
|
---|
117 | \ingroup appearance
|
---|
118 | \ingroup geomanagement
|
---|
119 | \brief The QSpacerItem class provides blank space in a layout.
|
---|
120 |
|
---|
121 | Normally, you don't need to use this class directly. Qt's
|
---|
122 | built-in layout managers provide the following functions for
|
---|
123 | manipulating empty space in layouts:
|
---|
124 |
|
---|
125 | \table
|
---|
126 | \header \o Class
|
---|
127 | \o Functions
|
---|
128 | \row \o QHBoxLayout
|
---|
129 | \o \l{QBoxLayout::addSpacing()}{addSpacing()},
|
---|
130 | \l{QBoxLayout::addStretch()}{addStretch()},
|
---|
131 | \l{QBoxLayout::insertSpacing()}{insertSpacing()},
|
---|
132 | \l{QBoxLayout::insertStretch()}{insertStretch()}
|
---|
133 | \row \o QGridLayout
|
---|
134 | \o \l{QGridLayout::setRowMinimumHeight()}{setRowMinimumHeight()},
|
---|
135 | \l{QGridLayout::setRowStretch()}{setRowStretch()},
|
---|
136 | \l{QGridLayout::setColumnMinimumWidth()}{setColumnMinimumWidth()},
|
---|
137 | \l{QGridLayout::setColumnStretch()}{setColumnStretch()}
|
---|
138 | \endtable
|
---|
139 |
|
---|
140 | \sa QLayout, QWidgetItem, QLayoutItem::spacerItem()
|
---|
141 | */
|
---|
142 |
|
---|
143 | /*!
|
---|
144 | \class QWidgetItem
|
---|
145 | \ingroup appearance
|
---|
146 | \ingroup geomanagement
|
---|
147 | \brief The QWidgetItem class is a layout item that represents a widget.
|
---|
148 |
|
---|
149 | Normally, you don't need to use this class directly. Qt's
|
---|
150 | built-in layout managers provide the following functions for
|
---|
151 | manipulating widgets in layouts:
|
---|
152 |
|
---|
153 | \table
|
---|
154 | \header \o Class
|
---|
155 | \o Functions
|
---|
156 | \row \o QBoxLayout
|
---|
157 | \o \l{QBoxLayout::addWidget()}{addWidget()},
|
---|
158 | \l{QBoxLayout::insertWidget()}{insertWidget()},
|
---|
159 | \l{QBoxLayout::setStretchFactor()}{setStretchFactor()}
|
---|
160 | \row \o QGridLayout
|
---|
161 | \o \l{QGridLayout::addWidget()}{addWidget()}
|
---|
162 | \row \o QStackedLayout
|
---|
163 | \o \l{QStackedLayout::addWidget()}{addWidget()},
|
---|
164 | \l{QStackedLayout::insertWidget()}{insertWidget()},
|
---|
165 | \l{QStackedLayout::currentWidget()}{currentWidget()},
|
---|
166 | \l{QStackedLayout::setCurrentWidget()}{setCurrentWidget()},
|
---|
167 | \l{QStackedLayout::widget()}{widget()}
|
---|
168 | \endtable
|
---|
169 |
|
---|
170 | \sa QLayout, QSpacerItem, QLayoutItem::widget()
|
---|
171 | */
|
---|
172 |
|
---|
173 | /*!
|
---|
174 | \fn QLayoutItem::QLayoutItem(Qt::Alignment alignment)
|
---|
175 |
|
---|
176 | Constructs a layout item with an \a alignment.
|
---|
177 | Not all subclasses support alignment.
|
---|
178 | */
|
---|
179 |
|
---|
180 | /*!
|
---|
181 | \fn Qt::Alignment QLayoutItem::alignment() const
|
---|
182 |
|
---|
183 | Returns the alignment of this item.
|
---|
184 | */
|
---|
185 |
|
---|
186 | /*!
|
---|
187 | Sets the alignment of this item to \a alignment.
|
---|
188 |
|
---|
189 | \bold{Note:} Item alignment is only supported by QLayoutItem subclasses
|
---|
190 | where it would have a visual effect. Except for QSpacerItem, which provides
|
---|
191 | blank space for layouts, all public Qt classes that inherit QLayoutItem
|
---|
192 | support item alignment.
|
---|
193 | */
|
---|
194 | void QLayoutItem::setAlignment(Qt::Alignment alignment)
|
---|
195 | {
|
---|
196 | align = alignment;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /*!
|
---|
200 | \fn QSize QLayoutItem::maximumSize() const
|
---|
201 |
|
---|
202 | Implemented in subclasses to return the maximum size of this item.
|
---|
203 | */
|
---|
204 |
|
---|
205 | /*!
|
---|
206 | \fn QSize QLayoutItem::minimumSize() const
|
---|
207 |
|
---|
208 | Implemented in subclasses to return the minimum size of this item.
|
---|
209 | */
|
---|
210 |
|
---|
211 | /*!
|
---|
212 | \fn QSize QLayoutItem::sizeHint() const
|
---|
213 |
|
---|
214 | Implemented in subclasses to return the preferred size of this item.
|
---|
215 | */
|
---|
216 |
|
---|
217 | /*!
|
---|
218 | \fn Qt::Orientations QLayoutItem::expandingDirections() const
|
---|
219 |
|
---|
220 | Returns whether this layout item can make use of more space than
|
---|
221 | sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that
|
---|
|
---|