Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlayoutpolicy_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QLAYOUTPOLICY_H
6#define QLAYOUTPOLICY_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <QtCore/qobject.h>
21#include <QtCore/qnamespace.h>
22
23#ifndef QT_NO_DATASTREAM
24# include <QtCore/qdatastream.h>
25#endif
26
27QT_BEGIN_NAMESPACE
28
29
30class QVariant;
31
33{
34 Q_GADGET_EXPORT(Q_GUI_EXPORT)
35
36public:
43 Q_DECLARE_FLAGS(Policy, PolicyFlag)
45
46 static constexpr inline Policy Fixed = {};
47 static constexpr inline Policy Minimum = GrowFlag;
48 static constexpr inline Policy Maximum = ShrinkFlag;
49 static constexpr inline Policy Preferred = Minimum | Maximum;
50 static constexpr inline Policy MinimumExpanding = Minimum | ExpandFlag;
51 static constexpr inline Policy Expanding = Preferred | ExpandFlag;
52 static constexpr inline Policy Ignored = Preferred | IgnoreFlag;
53
55 DefaultType = 0x00000001,
56 ButtonBox = 0x00000002,
57 CheckBox = 0x00000004,
58 ComboBox = 0x00000008,
59 Frame = 0x00000010,
60 GroupBox = 0x00000020,
61 Label = 0x00000040,
62 Line = 0x00000080,
63 LineEdit = 0x00000100,
64 PushButton = 0x00000200,
65 RadioButton = 0x00000400,
66 Slider = 0x00000800,
67 SpinBox = 0x00001000,
68 TabWidget = 0x00002000,
69 ToolButton = 0x00004000
70 };
71 Q_DECLARE_FLAGS(ControlTypes, ControlType)
72
74
81 Policy horizontalPolicy() const { return static_cast<Policy>(bits.horPolicy); }
82 Policy verticalPolicy() const { return static_cast<Policy>(bits.verPolicy); }
84
85 void setHorizontalPolicy(Policy d) { bits.horPolicy = d; }
86 void setVerticalPolicy(Policy d) { bits.verPolicy = d; }
88
90 Qt::Orientations result;
91 if (verticalPolicy() & ExpandFlag)
92 result |= Qt::Vertical;
93 if (horizontalPolicy() & ExpandFlag)
94 result |= Qt::Horizontal;
95 return result;
96 }
97
98 void setHeightForWidth(bool b) { bits.hfw = b; }
99 bool hasHeightForWidth() const { return bits.hfw; }
100 void setWidthForHeight(bool b) { bits.wfh = b; }
101 bool hasWidthForHeight() const { return bits.wfh; }
102
103 bool operator==(const QLayoutPolicy& s) const { return data == s.data; }
104 bool operator!=(const QLayoutPolicy& s) const { return data != s.data; }
105
106 int horizontalStretch() const { return static_cast<int>(bits.horStretch); }
107 int verticalStretch() const { return static_cast<int>(bits.verStretch); }
108 void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
109 void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); }
110
111 inline void transpose();
112
113
114private:
115#ifndef QT_NO_DATASTREAM
116 friend QDataStream &operator<<(QDataStream &, const QLayoutPolicy &);
117 friend QDataStream &operator>>(QDataStream &, QLayoutPolicy &);
118#endif
119 QLayoutPolicy(int i) : data(i) { }
120
121 union {
122 struct {
130 quint32 padding : 1; // feel free to use
131 } bits;
133 };
134};
135
136Q_DECLARE_OPERATORS_FOR_FLAGS(QLayoutPolicy::Policy)
137Q_DECLARE_OPERATORS_FOR_FLAGS(QLayoutPolicy::ControlTypes)
138
139#ifndef QT_NO_DATASTREAM
140QDataStream &operator<<(QDataStream &, const QLayoutPolicy &);
141QDataStream &operator>>(QDataStream &, QLayoutPolicy &);
142#endif
143
144#ifndef QT_NO_DEBUG_STREAM
145QDebug operator<<(QDebug dbg, const QLayoutPolicy &);
146#endif
147
148inline void QLayoutPolicy::transpose() {
149 Policy hData = horizontalPolicy();
150 Policy vData = verticalPolicy();
151 int hStretch = horizontalStretch();
152 int vStretch = verticalStretch();
153 setHorizontalPolicy(vData);
154 setVerticalPolicy(hData);
156 setVerticalStretch(hStretch);
157}
158
159QT_END_NAMESPACE
160
161#endif // QLAYOUTPOLICY_H
friend QDataStream & operator>>(QDataStream &, QLayoutPolicy &)
Reads the size policy from the data stream stream.
static constexpr Policy Minimum
static constexpr Policy Maximum
int verticalStretch() const
static constexpr Policy Ignored
bool operator!=(const QLayoutPolicy &s) const
friend QDataStream & operator<<(QDataStream &, const QLayoutPolicy &)
Writes the size policy to the data stream stream.
bool hasHeightForWidth() const
static constexpr Policy Expanding
static constexpr Policy Preferred
int horizontalStretch() const
void setHorizontalStretch(int stretchFactor)
void setHorizontalPolicy(Policy d)
bool hasWidthForHeight() const
void setVerticalPolicy(Policy d)
static constexpr Policy MinimumExpanding
void setVerticalStretch(int stretchFactor)
bool operator==(const QLayoutPolicy &s) const
Q_GUI_EXPORT void setControlType(ControlType type)
void setHeightForWidth(bool b)
void setWidthForHeight(bool b)
Qt::Orientations expandingDirections() const
QDebug operator<<(QDebug dbg, const QLayoutPolicy &p)