QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSizePolicy.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SIZE_POLICY_H
7#define QSK_SIZE_POLICY_H
8
9#include "QskGlobal.h"
10#include <qnamespace.h>
11#include <qmetatype.h>
12
13class QSK_EXPORT QskSizePolicy
14{
15 Q_GADGET
16
17 Q_PROPERTY( Policy horizontal READ horizontalPolicy WRITE setHorizontalPolicy )
18 Q_PROPERTY( Policy vertical READ verticalPolicy WRITE setVerticalPolicy )
19
20 public:
21 enum Flag : quint8
22 {
23 GrowFlag = 1 << 0,
24 ExpandFlag = 1 << 1,
25 ShrinkFlag = 1 << 2,
26 IgnoreFlag = 1 << 3,
27 ConstrainedFlag = 1 << 4
28 };
29
30 enum Policy : quint8
31 {
32 Fixed = 0,
33
34 Minimum = GrowFlag,
35 Maximum = ShrinkFlag,
36 Preferred = GrowFlag | ShrinkFlag,
37 MinimumExpanding = GrowFlag | ExpandFlag,
38 Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
39
40 Ignored = ShrinkFlag | GrowFlag | IgnoreFlag,
41
42 Constrained = ConstrainedFlag,
43
44 ConstrainedMinimum = ConstrainedFlag | Minimum,
45 ConstrainedMaximum = ConstrainedFlag | Maximum,
46 ConstrainedPreferred = ConstrainedFlag | Preferred,
47 ConstrainedMinimumExpanding = ConstrainedFlag | MinimumExpanding,
48 ConstrainedExpanding = ConstrainedFlag | Expanding
49 };
50
51 enum ConstraintType : quint8
52 {
53 Unconstrained = 0,
54
55 WidthForHeight = 1 << 0,
56 HeightForWidth = 1 << 1
57 };
58
59 Q_ENUM( Flag )
60 Q_ENUM( Policy )
61 Q_ENUM( ConstraintType )
62
63 constexpr QskSizePolicy() noexcept = default;
64 constexpr QskSizePolicy( Policy horizontalPolicy, Policy verticalPolicy ) noexcept;
65
66 constexpr bool operator==( const QskSizePolicy& ) const noexcept;
67 constexpr bool operator!=( const QskSizePolicy& ) const noexcept;
68
69 void setHorizontalPolicy( Policy ) noexcept;
70 constexpr Policy horizontalPolicy() const noexcept;
71
72 void setVerticalPolicy( Policy ) noexcept;
73 constexpr Policy verticalPolicy() const noexcept;
74
75 void setPolicy( Qt::Orientation, Policy ) noexcept;
76 constexpr Policy policy( Qt::Orientation ) const noexcept;
77
78 ConstraintType constraintType() const noexcept;
79 constexpr bool isConstrained( Qt::Orientation ) const noexcept;
80
81 Qt::SizeHint effectiveSizeHintType(
82 Qt::SizeHint, Qt::Orientation ) const noexcept;
83
84 constexpr QskSizePolicy transposed() const noexcept;
85 void transpose() noexcept;
86
87 private:
88 Policy m_horizontalPolicy = Ignored;
89 Policy m_verticalPolicy = Ignored;
90};
91
92inline constexpr QskSizePolicy::QskSizePolicy(
93 Policy horizontalPolicy, Policy verticalPolicy ) noexcept
94 : m_horizontalPolicy( horizontalPolicy )
95 , m_verticalPolicy( verticalPolicy )
96{
97}
98
99inline constexpr bool QskSizePolicy::operator==(
100 const QskSizePolicy& other ) const noexcept
101{
102 return ( other.m_horizontalPolicy == m_horizontalPolicy ) &&
103 ( other.m_verticalPolicy == m_verticalPolicy );
104}
105
106inline constexpr bool QskSizePolicy::operator!=(
107 const QskSizePolicy& other ) const noexcept
108{
109 return !( *this == other );
110}
111
112inline void QskSizePolicy::setHorizontalPolicy( Policy policy ) noexcept
113{
114 m_horizontalPolicy = policy;
115}
116
117inline constexpr QskSizePolicy::Policy QskSizePolicy::horizontalPolicy() const noexcept
118{
119 return m_horizontalPolicy;
120}
121
122inline void QskSizePolicy::setVerticalPolicy( Policy policy ) noexcept
123{
124 m_verticalPolicy = policy;
125}
126
127inline constexpr QskSizePolicy::Policy QskSizePolicy::verticalPolicy() const noexcept
128{
129 return m_verticalPolicy;
130}
131
132inline constexpr QskSizePolicy::Policy QskSizePolicy::policy(
133 Qt::Orientation orientation ) const noexcept
134{
135 return ( orientation == Qt::Horizontal ) ? m_horizontalPolicy : m_verticalPolicy;
136}
137
138inline void QskSizePolicy::setPolicy(
139 Qt::Orientation orientation, Policy policy ) noexcept
140{
141 if ( orientation == Qt::Horizontal )
142 m_horizontalPolicy = policy;
143 else
144 m_verticalPolicy = policy;
145}
146
147inline constexpr bool QskSizePolicy::isConstrained(
148 Qt::Orientation orientation ) const noexcept
149{
150 return ( policy( orientation ) & ConstrainedFlag );
151}
152
153inline constexpr QskSizePolicy QskSizePolicy::transposed() const noexcept
154{
155 return QskSizePolicy( m_verticalPolicy, m_horizontalPolicy );
156}
157
158#ifndef QT_NO_DEBUG_STREAM
159class QDebug;
160QSK_EXPORT QDebug operator<<( QDebug, const QskSizePolicy& );
161#endif
162
163Q_DECLARE_TYPEINFO( QskSizePolicy, Q_MOVABLE_TYPE );
164Q_DECLARE_METATYPE( QskSizePolicy )
165
166#endif