src/gui/kernel/qsizepolicy.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QSIZEPOLICY_H
00025 #define QSIZEPOLICY_H
00026 
00027 #include <QtCore/qobject.h>
00028 
00029 QT_BEGIN_HEADER
00030 
00031 QT_MODULE(Gui)
00032 
00033 class QVariant;
00034 
00035 class Q_GUI_EXPORT QSizePolicy
00036 {
00037     Q_GADGET
00038     Q_ENUMS(Policy)
00039 private:
00040     enum SizePolicyMasks {
00041         HSize = 4,
00042         HMask = 0x0f,
00043         VMask = HMask << HSize
00044     };
00045 public:
00046     enum PolicyFlag {
00047         GrowFlag = 1,
00048         ExpandFlag = 2,
00049         ShrinkFlag = 4,
00050         IgnoreFlag = 8
00051     };
00052 
00053     enum Policy {
00054         Fixed = 0,
00055         Minimum = GrowFlag,
00056         Maximum = ShrinkFlag,
00057         Preferred = GrowFlag | ShrinkFlag,
00058         MinimumExpanding = GrowFlag | ExpandFlag,
00059         Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
00060         Ignored = ShrinkFlag|GrowFlag|IgnoreFlag
00061     };
00062 
00063     QSizePolicy() : data(0) { }
00064 
00065     QSizePolicy(Policy horizontal, Policy vertical)
00066         : data(horizontal | (vertical<<HSize)) { }
00067 
00068     Policy horizontalPolicy() const { return static_cast<Policy>(data & HMask); }
00069     Policy verticalPolicy() const { return static_cast<Policy>((data & VMask) >> HSize); }
00070 
00071     void setHorizontalPolicy(Policy d) { data = (data & ~HMask) | d; }
00072     void setVerticalPolicy(Policy d) { data = (data & ~(HMask << HSize)) | (d << HSize); }
00073 
00074     Qt::Orientations expandingDirections() const {
00075         Qt::Orientations result;
00076         if (verticalPolicy() & ExpandFlag)
00077             result |= Qt::Vertical;
00078         if (horizontalPolicy() & ExpandFlag)
00079             result |= Qt::Horizontal;
00080         return result;
00081     }
00082 
00083     void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize));  }
00084     bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
00085 
00086     bool operator==(const QSizePolicy& s) const { return data == s.data; }
00087     bool operator!=(const QSizePolicy& s) const { return data != s.data; }
00088     operator QVariant() const; // implemented in qabstractlayout.cpp
00089 
00090     int horizontalStretch() const { return data >> 24; }
00091     int verticalStretch() const { return (data >> 16) & 0xff; }
00092     void setHorizontalStretch(uchar stretchFactor) { data = (data&0x00ffffff) | (uint(stretchFactor)<<24); }
00093     void setVerticalStretch(uchar stretchFactor) { data = (data&0xff00ffff) | (uint(stretchFactor)<<16); }
00094 
00095     void transpose();
00096 
00097 #ifdef QT3_SUPPORT
00098     typedef Policy SizeType;
00099 #ifndef qdoc
00100     typedef Qt::Orientations ExpandData;
00101     enum {
00102         NoDirection = 0,
00103         Horizontally = 1,
00104         Vertically = 2,
00105         BothDirections = Horizontally | Vertically
00106     };
00107 #else
00108     enum ExpandData {
00109         NoDirection = 0x0,
00110         Horizontally = 0x1,
00111         Vertically = 0x2,
00112         BothDirections = 0x3
00113     };
00114 #endif // qdoc
00115 
00116     inline QT3_SUPPORT bool mayShrinkHorizontally() const
00117         { return horizontalPolicy() & ShrinkFlag; }
00118     inline QT3_SUPPORT bool mayShrinkVertically() const { return verticalPolicy() & ShrinkFlag; }
00119     inline QT3_SUPPORT bool mayGrowHorizontally() const { return horizontalPolicy() & GrowFlag; }
00120     inline QT3_SUPPORT bool mayGrowVertically() const { return verticalPolicy() & GrowFlag; }
00121     inline QT3_SUPPORT Qt::Orientations expanding() const { return expandingDirections(); }
00122 
00123     QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
00124         : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
00125 
00126     QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, uchar hors, uchar vers, bool hfw = false)
00127         : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) {
00128         setHorizontalStretch(hors);
00129         setVerticalStretch(vers);
00130     }
00131 
00132     inline QT3_SUPPORT Policy horData() const { return static_cast<Policy>(data & HMask); }
00133     inline QT3_SUPPORT Policy verData() const { return static_cast<Policy>((data & VMask) >> HSize); }
00134     inline QT3_SUPPORT void setHorData(Policy d) { setHorizontalPolicy(d); }
00135     inline QT3_SUPPORT void setVerData(Policy d) { setVerticalPolicy(d); }
00136 
00137     inline QT3_SUPPORT uint horStretch() const { return horizontalStretch(); }
00138     inline QT3_SUPPORT uint verStretch() const { return verticalStretch(); }
00139     inline QT3_SUPPORT void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
00140     inline QT3_SUPPORT void setVerStretch(uchar sf) { setVerticalStretch(sf); }
00141 #endif
00142 
00143 private:
00144 #ifndef QT_NO_DATASTREAM
00145     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
00146     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
00147 #endif
00148     QSizePolicy(int i) : data(i) { }
00149 
00150     quint32 data;
00151 };
00152 
00153 // implemented in qlayout.cpp
00154 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
00155 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
00156 
00157 inline void QSizePolicy::transpose() {
00158     Policy hData = horizontalPolicy();
00159     Policy vData = verticalPolicy();
00160     uchar hStretch = horizontalStretch();
00161     uchar vStretch = verticalStretch();
00162     setHorizontalPolicy(vData);
00163     setVerticalPolicy(hData);
00164     setHorizontalStretch(vStretch);
00165     setVerticalStretch(hStretch);
00166 }
00167 
00168 QT_END_HEADER
00169 
00170 #endif // QSIZEPOLICY_H

Generated on Thu Mar 15 11:55:15 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1