QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskPlacementPolicy.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_PLACEMENT_POLICY_H
7#define QSK_PLACEMENT_POLICY_H
8
9#include "QskGlobal.h"
10#include "QskNamespace.h"
11#include <qmetaobject.h>
12
13class QSK_EXPORT QskPlacementPolicy
14{
15 Q_GADGET
16
17 Q_PROPERTY( Policy visiblePolicy READ visiblePolicy WRITE setVisiblePolicy )
18 Q_PROPERTY( Policy hiddenPolicy READ hiddenPolicy WRITE setHiddenPolicy )
19
20 public:
21
22 enum Policy
23 {
26 Adjust
27 };
28 Q_ENUM( Policy )
29
30 constexpr QskPlacementPolicy() noexcept;
31 constexpr QskPlacementPolicy( Policy ) noexcept;
32 constexpr QskPlacementPolicy( Policy visiblePolicy, Policy hiddenPolicy ) noexcept;
33 constexpr QskPlacementPolicy( Qsk::Visibilities, Policy ) noexcept;
34
35 constexpr bool operator==( const QskPlacementPolicy& ) const noexcept;
36 constexpr bool operator!=( const QskPlacementPolicy& ) const noexcept;
37
38 void setPolicy( Qsk::Visibilities, Policy ) noexcept;
39 constexpr Policy policy( Qsk::Visibility ) const noexcept;
40
41 constexpr bool isEffective() const noexcept;
42
43 constexpr bool isIgnoring( Qsk::Visibility ) const noexcept;
44 constexpr bool isAdjusting( Qsk::Visibility ) const noexcept;
45
46 void setVisiblePolicy( Policy ) noexcept;
47 constexpr Policy visiblePolicy() const noexcept;
48
49 void setHiddenPolicy( Policy ) noexcept;
50 constexpr Policy hiddenPolicy() const noexcept;
51
52 private:
53 Policy m_visiblePolicy : 3;
54 Policy m_hiddenPolicy : 3;
55};
56
57inline constexpr QskPlacementPolicy::QskPlacementPolicy() noexcept
58 : m_visiblePolicy( Adjust )
59 , m_hiddenPolicy( Ignore )
60{
61}
62
64 Policy visiblePolicy, Policy hiddenPolicy ) noexcept
65 : m_visiblePolicy( visiblePolicy )
66 , m_hiddenPolicy( hiddenPolicy )
67{
68}
69
71 : m_visiblePolicy( policy )
72 , m_hiddenPolicy( policy )
73{
74}
75
77 Qsk::Visibilities visibilities, Policy policy ) noexcept
78 : m_visiblePolicy( visibilities & Qsk::Visible ? policy : Adjust )
79 , m_hiddenPolicy( visibilities & Qsk::Hidden ? policy : Ignore )
80{
81}
82
83inline constexpr bool QskPlacementPolicy::operator==(
84 const QskPlacementPolicy& other ) const noexcept
85{
86 return ( other.m_visiblePolicy == m_visiblePolicy ) &&
87 ( other.m_hiddenPolicy == m_hiddenPolicy );
88}
89
90inline constexpr bool QskPlacementPolicy::operator!=(
91 const QskPlacementPolicy& other ) const noexcept
92{
93 return !( *this == other );
94}
95
96inline void QskPlacementPolicy::setPolicy(
97 Qsk::Visibilities visibilities, Policy policy ) noexcept
98{
99 if ( visibilities & Qsk::Visible )
100 m_visiblePolicy = policy;
101
102 if ( visibilities & Qsk::Hidden )
103 m_hiddenPolicy = policy;
104}
105
106inline constexpr QskPlacementPolicy::Policy
107QskPlacementPolicy::policy( Qsk::Visibility visibility ) const noexcept
108{
109 return ( visibility == Qsk::Hidden ) ? m_hiddenPolicy : m_visiblePolicy;
110}
111
112inline void QskPlacementPolicy::setVisiblePolicy( Policy policy ) noexcept
113{
114 m_visiblePolicy = policy;
115}
116
118{
119 return m_visiblePolicy;
120}
121
122inline void QskPlacementPolicy::setHiddenPolicy( Policy policy ) noexcept
123{
124 m_hiddenPolicy = policy;
125}
126
127inline constexpr QskPlacementPolicy::Policy QskPlacementPolicy::hiddenPolicy() const noexcept
128{
129 return m_hiddenPolicy;
130}
131
132inline constexpr bool QskPlacementPolicy::isEffective() const noexcept
133{
134 return ( m_visiblePolicy != Ignore ) || ( m_hiddenPolicy != Ignore );
135}
136
137inline constexpr bool QskPlacementPolicy::isIgnoring( Qsk::Visibility visibility ) const noexcept
138{
139 return ( visibility == Qsk::Visible )
140 ? ( m_visiblePolicy == Ignore ) : ( m_hiddenPolicy == Ignore );
141}
142
143inline constexpr bool QskPlacementPolicy::isAdjusting( Qsk::Visibility visibility ) const noexcept
144{
145 return ( visibility == Qsk::Visible )
146 ? ( m_visiblePolicy == Adjust ) : ( m_hiddenPolicy == Adjust );
147}
148
149Q_DECLARE_TYPEINFO( QskPlacementPolicy, Q_MOVABLE_TYPE );
150Q_DECLARE_METATYPE( QskPlacementPolicy )
151
152#ifndef QT_NO_DEBUG_STREAM
153
154 class QDebug;
155 QSK_EXPORT QDebug operator<<( QDebug, QskPlacementPolicy );
156
157#endif
158
159#endif
constexpr bool isAdjusting(Qsk::Visibility) const noexcept
void setHiddenPolicy(Policy) noexcept
constexpr bool operator!=(const QskPlacementPolicy &) const noexcept
constexpr bool operator==(const QskPlacementPolicy &) const noexcept
constexpr bool isIgnoring(Qsk::Visibility) const noexcept
Policy hiddenPolicy
Policy for the item, when being hidden ( to its parent )
constexpr QskPlacementPolicy() noexcept
Default constructor.
Policy visiblePolicy
Policy for the item, when being visible ( to its parent )
constexpr bool isEffective() const noexcept
void setVisiblePolicy(Policy) noexcept
Global definitions.
Visibility
Visibility of an object.
@ Visible
@ Hidden