QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSizePolicy.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSizePolicy.h"
7
8#ifndef QT_NO_DEBUG
9#include <qdebug.h>
10#endif
11
12#include <utility>
13
14static void qskRegisterSizePolicy()
15{
16 qRegisterMetaType< QskSizePolicy >();
17
18#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
19 QMetaType::registerEqualsComparator< QskSizePolicy >();
20#endif
21}
22
23Q_CONSTRUCTOR_FUNCTION( qskRegisterSizePolicy )
24
25QskSizePolicy::ConstraintType QskSizePolicy::constraintType() const noexcept
26{
27 constexpr unsigned char mask = IgnoreFlag | ConstrainedFlag;
28
29#ifndef QT_NO_DEBUG
30 if ( ( ( m_horizontalPolicy & mask ) == mask )
31 || ( ( m_verticalPolicy & mask ) == mask ) )
32 {
33 qWarning() << "invalid policy having IgnoreFlag and ConstrainedFlag";
34 }
35#endif
36
37 if ( ( m_horizontalPolicy & mask ) == ConstrainedFlag )
38 return QskSizePolicy::WidthForHeight;
39
40 if ( ( m_verticalPolicy & mask ) == ConstrainedFlag )
41 return QskSizePolicy::HeightForWidth;
42
43 return QskSizePolicy::Unconstrained;
44}
45
46Qt::SizeHint QskSizePolicy::effectiveSizeHintType(
47 Qt::SizeHint which, Qt::Orientation orientation ) const noexcept
48{
49 const auto policy = ( orientation == Qt::Horizontal )
50 ? horizontalPolicy() : verticalPolicy();
51
52 if ( which == Qt::MinimumSize )
53 {
54 if ( !( policy & ShrinkFlag ) )
55 return Qt::PreferredSize;
56 }
57 else if ( which == Qt::MaximumSize )
58 {
59 if ( !( policy & ( GrowFlag | ExpandFlag ) ) )
60 return Qt::PreferredSize;
61 }
62
63 return which;
64}
65
66void QskSizePolicy::transpose() noexcept
67{
68 std::swap( m_horizontalPolicy, m_verticalPolicy );
69}
70
71#ifndef QT_NO_DEBUG_STREAM
72
73#include <qdebug.h>
74
75QDebug operator<<( QDebug debug, const QskSizePolicy& policy )
76{
77 QDebugStateSaver saver( debug );
78 debug.nospace();
79 debug << "SizePolicy" << '(';
80 debug << policy.horizontalPolicy() << ", " << policy.verticalPolicy();
81 debug << ')';
82
83 return debug;
84}
85
86#endif
87
88#include "moc_QskSizePolicy.cpp"