Warning, file /include/QtWidgets/qsizepolicy.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QSIZEPOLICY_H
0005 #define QSIZEPOLICY_H
0006
0007 #include <QtWidgets/qtwidgetsglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtCore/qalgorithms.h>
0010 #include <QtCore/qhashfunctions.h>
0011
0012 QT_BEGIN_NAMESPACE
0013
0014 class QVariant;
0015 class QSizePolicy;
0016
0017 class Q_WIDGETS_EXPORT QSizePolicy
0018 {
0019 Q_GADGET
0020
0021 public:
0022 enum PolicyFlag {
0023 GrowFlag = 1,
0024 ExpandFlag = 2,
0025 ShrinkFlag = 4,
0026 IgnoreFlag = 8
0027 };
0028
0029 enum Policy {
0030 Fixed = 0,
0031 Minimum = GrowFlag,
0032 Maximum = ShrinkFlag,
0033 Preferred = GrowFlag | ShrinkFlag,
0034 MinimumExpanding = GrowFlag | ExpandFlag,
0035 Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
0036 Ignored = ShrinkFlag | GrowFlag | IgnoreFlag
0037 };
0038 Q_ENUM(Policy)
0039
0040 enum ControlType {
0041 DefaultType = 0x00000001,
0042 ButtonBox = 0x00000002,
0043 CheckBox = 0x00000004,
0044 ComboBox = 0x00000008,
0045 Frame = 0x00000010,
0046 GroupBox = 0x00000020,
0047 Label = 0x00000040,
0048 Line = 0x00000080,
0049 LineEdit = 0x00000100,
0050 PushButton = 0x00000200,
0051 RadioButton = 0x00000400,
0052 Slider = 0x00000800,
0053 SpinBox = 0x00001000,
0054 TabWidget = 0x00002000,
0055 ToolButton = 0x00004000
0056 };
0057 Q_DECLARE_FLAGS(ControlTypes, ControlType)
0058 Q_FLAG(ControlTypes)
0059
0060 constexpr QSizePolicy() noexcept : data(0) { }
0061
0062 constexpr QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) noexcept
0063 : bits{0, 0, quint32(horizontal), quint32(vertical),
0064 type == DefaultType ? 0 : toControlTypeFieldValue(type), 0, 0, 0}
0065 {}
0066 constexpr Policy horizontalPolicy() const noexcept { return static_cast<Policy>(bits.horPolicy); }
0067 constexpr Policy verticalPolicy() const noexcept { return static_cast<Policy>(bits.verPolicy); }
0068 ControlType controlType() const noexcept;
0069
0070 constexpr void setHorizontalPolicy(Policy d) noexcept { bits.horPolicy = d; }
0071 constexpr void setVerticalPolicy(Policy d) noexcept { bits.verPolicy = d; }
0072 void setControlType(ControlType type) noexcept;
0073
0074
0075 constexpr Qt::Orientations expandingDirections() const noexcept {
0076 return ( (verticalPolicy() & static_cast<Policy>(ExpandFlag)) ? Qt::Vertical : Qt::Orientations() )
0077 | ( (horizontalPolicy() & static_cast<Policy>(ExpandFlag)) ? Qt::Horizontal : Qt::Orientations() ) ;
0078 }
0079
0080 constexpr void setHeightForWidth(bool b) noexcept { bits.hfw = b; }
0081 constexpr bool hasHeightForWidth() const noexcept { return bits.hfw; }
0082 constexpr void setWidthForHeight(bool b) noexcept { bits.wfh = b; }
0083 constexpr bool hasWidthForHeight() const noexcept { return bits.wfh; }
0084
0085 constexpr bool operator==(const QSizePolicy& s) const noexcept { return data == s.data; }
0086 constexpr bool operator!=(const QSizePolicy& s) const noexcept { return data != s.data; }
0087
0088 friend Q_DECL_CONST_FUNCTION size_t qHash(QSizePolicy key, size_t seed = 0) noexcept { return qHash(key.data, seed); }
0089
0090 operator QVariant() const;
0091
0092 constexpr int horizontalStretch() const noexcept { return static_cast<int>(bits.horStretch); }
0093 constexpr int verticalStretch() const noexcept { return static_cast<int>(bits.verStretch); }
0094 constexpr void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
0095 constexpr void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
0096
0097 constexpr bool retainSizeWhenHidden() const noexcept { return bits.retainSizeWhenHidden; }
0098 constexpr void setRetainSizeWhenHidden(bool retainSize) noexcept { bits.retainSizeWhenHidden = retainSize; }
0099
0100 constexpr void transpose() noexcept { *this = transposed(); }
0101 [[nodiscard]] constexpr QSizePolicy transposed() const noexcept
0102 {
0103 return QSizePolicy(bits.transposed());
0104 }
0105
0106 private:
0107 #ifndef QT_NO_DATASTREAM
0108 friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
0109 friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
0110 #endif
0111 constexpr QSizePolicy(int i) noexcept : data(i) { }
0112 struct Bits;
0113 constexpr explicit QSizePolicy(Bits b) noexcept : bits(b) { }
0114
0115 static constexpr quint32 toControlTypeFieldValue(ControlType type) noexcept
0116 {
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 return qCountTrailingZeroBits(static_cast<quint32>(type));
0132 }
0133
0134 struct Bits {
0135 quint32 horStretch : 8;
0136 quint32 verStretch : 8;
0137 quint32 horPolicy : 4;
0138 quint32 verPolicy : 4;
0139 quint32 ctype : 5;
0140 quint32 hfw : 1;
0141 quint32 wfh : 1;
0142 quint32 retainSizeWhenHidden : 1;
0143
0144 constexpr Bits transposed() const noexcept
0145 {
0146 return {verStretch,
0147 horStretch,
0148 verPolicy,
0149 horPolicy,
0150 ctype,
0151 hfw,
0152 wfh,
0153 retainSizeWhenHidden};
0154 }
0155 };
0156 union {
0157 Bits bits;
0158 quint32 data;
0159 };
0160 };
0161
0162 Q_DECLARE_TYPEINFO(QSizePolicy, Q_PRIMITIVE_TYPE);
0163
0164 Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
0165 Q_DECLARE_MIXED_ENUM_OPERATORS(int, QSizePolicy::Policy, QSizePolicy::PolicyFlag)
0166
0167 #ifndef QT_NO_DATASTREAM
0168 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
0169 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
0170 #endif
0171
0172 #ifndef QT_NO_DEBUG_STREAM
0173 Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
0174 #endif
0175
0176 QT_END_NAMESPACE
0177
0178 #endif