qskinny/src/layouts/QskLayoutMetrics.cpp

90 lines
2.2 KiB
C++
Raw Normal View History

2019-07-13 09:01:27 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskLayoutMetrics.h"
#include "QskControl.h"
2019-06-04 06:00:00 +00:00
#include <qnamespace.h>
2020-05-02 10:38:44 +00:00
#include <algorithm>
2019-06-04 06:00:00 +00:00
void QskLayoutMetrics::setMetric( int which, qreal metric ) noexcept
2019-06-04 06:00:00 +00:00
{
switch (which)
{
case Qt::MinimumSize:
m_minimum = metric;
2019-06-04 06:00:00 +00:00
break;
case Qt::PreferredSize:
m_preferred = metric;
2019-06-04 06:00:00 +00:00
break;
case Qt::MaximumSize:
m_maximum = metric;
2019-06-04 06:00:00 +00:00
break;
default:
break;
}
}
void QskLayoutMetrics::expandTo( const QskLayoutMetrics& other ) noexcept
2019-07-29 15:34:24 +00:00
{
2020-05-02 10:38:44 +00:00
m_minimum = std::max( m_minimum, other.m_minimum );
m_preferred = std::max( m_preferred, other.m_preferred );
m_maximum = std::max( m_maximum, other.m_maximum );
2019-07-29 15:34:24 +00:00
}
void QskLayoutMetrics::normalize() noexcept
2019-06-04 06:00:00 +00:00
{
2020-05-02 10:38:44 +00:00
m_minimum = std::max( m_minimum, qreal( 0.0 ) );
m_maximum = std::max( m_minimum, m_maximum );
2019-06-04 06:00:00 +00:00
m_preferred = qBound( m_minimum, m_preferred, m_maximum );
}
2019-06-19 11:26:29 +00:00
qreal QskLayoutMetrics::combined( int which, qreal value1, qreal value2 ) noexcept
{
2019-09-20 05:44:39 +00:00
if ( which == Qt::MaximumSize )
{
if ( value1 < 0.0 )
return value2;
2019-09-20 05:44:39 +00:00
if ( value2 < 0.0 )
return value1;
2020-05-02 10:38:44 +00:00
return std::min( value1, value2 );
2019-09-20 05:44:39 +00:00
}
2020-05-02 10:38:44 +00:00
return std::max( value1, value2 );
2019-07-09 12:49:24 +00:00
}
2019-06-19 11:26:29 +00:00
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
2019-07-02 16:17:57 +00:00
static inline QString qskHintValueString( qreal value )
{
if ( value >= QskLayoutMetrics::unlimited )
2019-07-02 16:17:57 +00:00
return QStringLiteral( "unlimited" );
else
return QString::number( value );
}
QDebug operator<<( QDebug debug, const QskLayoutMetrics& metrics )
2019-06-19 11:26:29 +00:00
{
QDebugStateSaver saver( debug );
debug.nospace();
debug << "LayoutMetrics" << "( "
<< qskHintValueString( metrics.minimum() ) << ", "
<< qskHintValueString( metrics.preferred() ) << ", "
<< qskHintValueString( metrics.maximum() ) << " )";
2019-06-19 11:26:29 +00:00
return debug;
}
#endif
2020-05-02 10:38:44 +00:00
#include "moc_QskLayoutMetrics.cpp"