00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QSIZEPOLICY_H
00043 #define QSIZEPOLICY_H
00044
00045 #include <QtCore/qobject.h>
00046
00047 QT_BEGIN_HEADER
00048
00049 QT_BEGIN_NAMESPACE
00050
00051 QT_MODULE(Gui)
00052
00053 class QVariant;
00054
00055 class Q_GUI_EXPORT QSizePolicy
00056 {
00057 Q_GADGET
00058 Q_ENUMS(Policy)
00059
00060 private:
00061 enum SizePolicyMasks {
00062 HSize = 4,
00063 HMask = 0x0f,
00064 VMask = HMask << HSize,
00065 CTShift = 9,
00066 CTSize = 5,
00067 WFHShift = CTShift + CTSize,
00068 CTMask = ((0x1 << CTSize) - 1) << CTShift,
00069 UnusedShift = CTShift + CTSize,
00070 UnusedSize = 2
00071 };
00072
00073 public:
00074 enum PolicyFlag {
00075 GrowFlag = 1,
00076 ExpandFlag = 2,
00077 ShrinkFlag = 4,
00078 IgnoreFlag = 8
00079 };
00080
00081 enum Policy {
00082 Fixed = 0,
00083 Minimum = GrowFlag,
00084 Maximum = ShrinkFlag,
00085 Preferred = GrowFlag | ShrinkFlag,
00086 MinimumExpanding = GrowFlag | ExpandFlag,
00087 Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
00088 Ignored = ShrinkFlag | GrowFlag | IgnoreFlag
00089 };
00090
00091 enum ControlType {
00092 DefaultType = 0x00000001,
00093 ButtonBox = 0x00000002,
00094 CheckBox = 0x00000004,
00095 ComboBox = 0x00000008,
00096 Frame = 0x00000010,
00097 GroupBox = 0x00000020,
00098 Label = 0x00000040,
00099 Line = 0x00000080,
00100 LineEdit = 0x00000100,
00101 PushButton = 0x00000200,
00102 RadioButton = 0x00000400,
00103 Slider = 0x00000800,
00104 SpinBox = 0x00001000,
00105 TabWidget = 0x00002000,
00106 ToolButton = 0x00004000
00107 };
00108 Q_DECLARE_FLAGS(ControlTypes, ControlType)
00109
00110 QSizePolicy() : data(0) { }
00111
00112
00113 QSizePolicy(Policy horizontal, Policy vertical)
00114 : data(horizontal | (vertical << HSize)) { }
00115 QSizePolicy(Policy horizontal, Policy vertical, ControlType type)
00116 : data(horizontal | (vertical << HSize)) { setControlType(type); }
00117
00118 Policy horizontalPolicy() const { return static_cast<Policy>(data & HMask); }
00119 Policy verticalPolicy() const { return static_cast<Policy>((data & VMask) >> HSize); }
00120 ControlType controlType() const;
00121
00122 void setHorizontalPolicy(Policy d) { data = (data & ~HMask) | d; }
00123 void setVerticalPolicy(Policy d) { data = (data & ~(HMask << HSize)) | (d << HSize); }
00124 void setControlType(ControlType type);
00125
00126 Qt::Orientations expandingDirections() const {
00127 Qt::Orientations result;
00128 if (verticalPolicy() & ExpandFlag)
00129 result |= Qt::Vertical;
00130 if (horizontalPolicy() & ExpandFlag)
00131 result |= Qt::Horizontal;
00132 return result;
00133 }
00134
00135 void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize)); }
00136 bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
00137
00138 bool operator==(const QSizePolicy& s) const { return data == s.data; }
00139 bool operator!=(const QSizePolicy& s) const { return data != s.data; }
00140 operator QVariant() const;
00141
00142 int horizontalStretch() const { return data >> 24; }
00143 int verticalStretch() const { return (data >> 16) & 0xff; }
00144 void setHorizontalStretch(uchar stretchFactor) { data = (data&0x00ffffff) | (uint(stretchFactor)<<24); }
00145 void setVerticalStretch(uchar stretchFactor) { data = (data&0xff00ffff) | (uint(stretchFactor)<<16); }
00146
00147 void transpose();
00148
00149 #ifdef QT3_SUPPORT
00150 typedef Policy SizeType;
00151 #ifndef qdoc
00152 typedef Qt::Orientations ExpandData;
00153 enum {
00154 NoDirection = 0,
00155 Horizontally = 1,
00156 Vertically = 2,
00157 BothDirections = Horizontally | Vertically
00158 };
00159 #else
00160 enum ExpandData {
00161 NoDirection = 0x0,
00162 Horizontally = 0x1,
00163 Vertically = 0x2,
00164 BothDirections = 0x3
00165 };
00166 #endif // qdoc
00167
00168 inline QT3_SUPPORT bool mayShrinkHorizontally() const
00169 { return horizontalPolicy() & ShrinkFlag; }
00170 inline QT3_SUPPORT bool mayShrinkVertically() const { return verticalPolicy() & ShrinkFlag; }
00171 inline QT3_SUPPORT bool mayGrowHorizontally() const { return horizontalPolicy() & GrowFlag; }
00172 inline QT3_SUPPORT bool mayGrowVertically() const { return verticalPolicy() & GrowFlag; }
00173 inline QT3_SUPPORT Qt::Orientations expanding() const { return expandingDirections(); }
00174
00175 QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
00176 : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
00177
00178 QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, uchar hors, uchar vers, bool hfw = false)
00179 : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) {
00180 setHorizontalStretch(hors);
00181 setVerticalStretch(vers);
00182 }
00183
00184 inline QT3_SUPPORT Policy horData() const { return static_cast<Policy>(data & HMask); }
00185 inline QT3_SUPPORT Policy verData() const { return static_cast<Policy>((data & VMask) >> HSize); }
00186 inline QT3_SUPPORT void setHorData(Policy d) { setHorizontalPolicy(d); }
00187 inline QT3_SUPPORT void setVerData(Policy d) { setVerticalPolicy(d); }
00188
00189 inline QT3_SUPPORT uint horStretch() const { return horizontalStretch(); }
00190 inline QT3_SUPPORT uint verStretch() const { return verticalStretch(); }
00191 inline QT3_SUPPORT void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
00192 inline QT3_SUPPORT void setVerStretch(uchar sf) { setVerticalStretch(sf); }
00193 #endif
00194
00195 private:
00196 #ifndef QT_NO_DATASTREAM
00197 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
00198 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
00199 #endif
00200 QSizePolicy(int i) : data(i) { }
00201
00202 quint32 data;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 };
00215
00216 Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
00217
00218 #ifndef QT_NO_DATASTREAM
00219
00220 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
00221 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
00222 #endif
00223
00224 inline void QSizePolicy::transpose() {
00225 Policy hData = horizontalPolicy();
00226 Policy vData = verticalPolicy();
00227 uchar hStretch = uchar(horizontalStretch());
00228 uchar vStretch = uchar(verticalStretch());
00229 setHorizontalPolicy(vData);
00230 setVerticalPolicy(hData);
00231 setHorizontalStretch(vStretch);
00232 setVerticalStretch(hStretch);
00233 }
00234
00235 QT_END_NAMESPACE
00236
00237 QT_END_HEADER
00238
00239 #endif // QSIZEPOLICY_H