1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the gui module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qobject.h"
33
#include "QtCore/qobjectdefs.h"
37
class Q_GUI_EXPORT QSizePolicy
42
enum SizePolicyMasks {
45
VMask = HMask << HSize
59
Preferred = GrowFlag | ShrinkFlag,
60
MinimumExpanding = GrowFlag | ExpandFlag,
61
Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
62
Ignored = ShrinkFlag|GrowFlag|IgnoreFlag
65
QSizePolicy() : data(0) { }
67
QSizePolicy(Policy horizontal, Policy vertical)
68
: data(horizontal | (vertical<<HSize)) { }
70
Policy horizontalPolicy() const { return static_cast<Policy>(data & HMask); }
71
Policy verticalPolicy() const { return static_cast<Policy>((data & VMask) >> HSize); }
73
void setHorizontalPolicy(Policy d) { data = (data & ~HMask) | d; }
74
void setVerticalPolicy(Policy d) { data = (data & ~(HMask << HSize)) | (d << HSize); }
76
Qt::Orientations expandingDirections() const {
77
Qt::Orientations result;
78
if (verticalPolicy() & ExpandFlag)
79
result |= Qt::Vertical;
80
if (horizontalPolicy() & ExpandFlag)
81
result |= Qt::Horizontal;
85
void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize)); }
86
bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
88
bool operator==(const QSizePolicy& s) const { return data == s.data; }
89
bool operator!=(const QSizePolicy& s) const { return data != s.data; }
90
operator QVariant() const; // implemented in qabstractlayout.cpp
92
int horizontalStretch() const { return data >> 24; }
93
int verticalStretch() const { return (data >> 16) & 0xff; }
94
void setHorizontalStretch(uchar stretchFactor) { data = (data&0x00ffffff) | (uint(stretchFactor)<<24); }
95
void setVerticalStretch(uchar stretchFactor) { data = (data&0xff00ffff) | (uint(stretchFactor)<<16); }
100
typedef Policy SizeType;
102
typedef Qt::Orientations ExpandData;
107
BothDirections = Horizontally | Vertically
118
inline QT3_SUPPORT bool mayShrinkHorizontally() const
119
{ return horizontalPolicy() & ShrinkFlag; }
120
inline QT3_SUPPORT bool mayShrinkVertically() const { return verticalPolicy() & ShrinkFlag; }
121
inline QT3_SUPPORT bool mayGrowHorizontally() const { return horizontalPolicy() & GrowFlag; }
122
inline QT3_SUPPORT bool mayGrowVertically() const { return verticalPolicy() & GrowFlag; }
123
inline QT3_SUPPORT Qt::Orientations expanding() const { return expandingDirections(); }
125
QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
126
: data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
128
QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, uchar hors, uchar vers, bool hfw = false)
129
: data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) {
130
setHorizontalStretch(hors);
131
setVerticalStretch(vers);
134
inline QT3_SUPPORT Policy horData() const { return static_cast<Policy>(data & HMask); }
135
inline QT3_SUPPORT Policy verData() const { return static_cast<Policy>((data & VMask) >> HSize); }
136
inline QT3_SUPPORT void setHorData(Policy d) { setHorizontalPolicy(d); }
137
inline QT3_SUPPORT void setVerData(Policy d) { setVerticalPolicy(d); }
139
inline QT3_SUPPORT uint horStretch() const { return horizontalStretch(); }
140
inline QT3_SUPPORT uint verStretch() const { return verticalStretch(); }
141
inline QT3_SUPPORT void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
142
inline QT3_SUPPORT void setVerStretch(uchar sf) { setVerticalStretch(sf); }
146
QSizePolicy(int i) : data(i) { }
151
inline void QSizePolicy::transpose() {
152
Policy hData = horizontalPolicy();
153
Policy vData = verticalPolicy();
154
uchar hStretch = horizontalStretch();
155
uchar vStretch = verticalStretch();
156
setHorizontalPolicy(vData);
157
setVerticalPolicy(hData);
158
setHorizontalStretch(vStretch);
159
setVerticalStretch(hStretch);
162
#endif // QSIZEPOLICY_H