QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLayoutMetrics.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskLayoutMetrics.h"
7#include "QskControl.h"
8#include <qnamespace.h>
9#include <algorithm>
10
11static void qskRegisterLayoutMetrics()
12{
13 qRegisterMetaType< QskLayoutMetrics >();
14
15#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
16 QMetaType::registerEqualsComparator< QskLayoutMetrics >();
17#endif
18}
19
20Q_CONSTRUCTOR_FUNCTION( qskRegisterLayoutMetrics )
21
22void QskLayoutMetrics::setMetric( int which, qreal metric ) noexcept
23{
24 switch (which)
25 {
26 case Qt::MinimumSize:
27 m_minimum = metric;
28 break;
29
30 case Qt::PreferredSize:
31 m_preferred = metric;
32 break;
33
34 case Qt::MaximumSize:
35 m_maximum = metric;
36 break;
37
38 default:
39 break;
40 }
41}
42
43void QskLayoutMetrics::expandTo( const QskLayoutMetrics& other ) noexcept
44{
45 m_minimum = std::max( m_minimum, other.m_minimum );
46 m_preferred = std::max( m_preferred, other.m_preferred );
47 m_maximum = std::max( m_maximum, other.m_maximum );
48}
49
50void QskLayoutMetrics::normalize() noexcept
51{
52 m_minimum = std::max( m_minimum, qreal( 0.0 ) );
53 m_maximum = std::max( m_minimum, m_maximum );
54 m_preferred = qBound( m_minimum, m_preferred, m_maximum );
55}
56
57qreal QskLayoutMetrics::combined( int which, qreal value1, qreal value2 ) noexcept
58{
59 if ( which == Qt::MaximumSize )
60 {
61 if ( value1 < 0.0 )
62 return value2;
63
64 if ( value2 < 0.0 )
65 return value1;
66
67 return std::min( value1, value2 );
68 }
69
70 return std::max( value1, value2 );
71}
72
73#ifndef QT_NO_DEBUG_STREAM
74
75#include <qdebug.h>
76
77static inline QString qskHintValueString( qreal value )
78{
79 if ( value >= QskLayoutMetrics::unlimited )
80 return QStringLiteral( "unlimited" );
81 else
82 return QString::number( value );
83}
84
85QDebug operator<<( QDebug debug, const QskLayoutMetrics& metrics )
86{
87 QDebugStateSaver saver( debug );
88 debug.nospace();
89
90 debug << "LayoutMetrics" << "( "
91 << qskHintValueString( metrics.minimum() ) << ", "
92 << qskHintValueString( metrics.preferred() ) << ", "
93 << qskHintValueString( metrics.maximum() ) << " )";
94
95 return debug;
96}
97
98#endif
99
100#include "moc_QskLayoutMetrics.cpp"