1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qobject.h>
54 class Q_WIDGETS_EXPORT QSizePolicy
71 Preferred = GrowFlag | ShrinkFlag,
72 MinimumExpanding = GrowFlag | ExpandFlag,
73 Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
74 Ignored = ShrinkFlag | GrowFlag | IgnoreFlag
78 DefaultType = 0x00000001,
79 ButtonBox = 0x00000002,
80 CheckBox = 0x00000004,
81 ComboBox = 0x00000008,
83 GroupBox = 0x00000020,
86 LineEdit = 0x00000100,
87 PushButton = 0x00000200,
88 RadioButton = 0x00000400,
91 TabWidget = 0x00002000,
92 ToolButton = 0x00004000
94 Q_DECLARE_FLAGS(ControlTypes, ControlType)
96 QSizePolicy() : data(0) { }
98 // ### Qt 5: merge these two constructors (with type == DefaultType)
99 QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType)
101 bits.horPolicy = horizontal;
102 bits.verPolicy = vertical;
103 setControlType(type);
105 Policy horizontalPolicy() const { return static_cast<Policy>(bits.horPolicy); }
106 Policy verticalPolicy() const { return static_cast<Policy>(bits.verPolicy); }
107 ControlType controlType() const;
109 void setHorizontalPolicy(Policy d) { bits.horPolicy = d; }
110 void setVerticalPolicy(Policy d) { bits.verPolicy = d; }
111 void setControlType(ControlType type);
113 Qt::Orientations expandingDirections() const {
114 Qt::Orientations result;
115 if (verticalPolicy() & ExpandFlag)
116 result |= Qt::Vertical;
117 if (horizontalPolicy() & ExpandFlag)
118 result |= Qt::Horizontal;
122 void setHeightForWidth(bool b) { bits.hfw = b; }
123 bool hasHeightForWidth() const { return bits.hfw; }
124 void setWidthForHeight(bool b) { bits.wfh = b; }
125 bool hasWidthForHeight() const { return bits.wfh; }
127 bool operator==(const QSizePolicy& s) const { return data == s.data; }
128 bool operator!=(const QSizePolicy& s) const { return data != s.data; }
129 operator QVariant() const; // implemented in qlayoutitem.cpp
131 int horizontalStretch() const { return static_cast<int>(bits.horStretch); }
132 int verticalStretch() const { return static_cast<int>(bits.verStretch); }
133 void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
134 void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
140 #ifndef QT_NO_DATASTREAM
141 friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
142 friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
144 QSizePolicy(int i) : data(i) { }
148 quint32 horStretch : 8;
149 quint32 verStretch : 8;
150 quint32 horPolicy : 4;
151 quint32 verPolicy : 4;
155 quint32 padding : 1; // feel free to use
161 Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
163 #ifndef QT_NO_DATASTREAM
164 // implemented in qlayout.cpp
165 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
166 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
169 #ifndef QT_NO_DEBUG_STREAM
170 Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
173 inline void QSizePolicy::transpose() {
174 Policy hData = horizontalPolicy();
175 Policy vData = verticalPolicy();
176 int hStretch = horizontalStretch();
177 int vStretch = verticalStretch();
178 setHorizontalPolicy(vData);
179 setVerticalPolicy(hData);
180 setHorizontalStretch(vStretch);
181 setVerticalStretch(hStretch);
188 #endif // QSIZEPOLICY_H