qskinny/src/common/QskSizePolicy.cpp

78 lines
2.0 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskSizePolicy.h"
2020-03-13 14:50:09 +01:00
#ifndef QT_NO_DEBUG
#include <qdebug.h>
#endif
2019-09-18 08:43:09 +02:00
2020-05-03 13:47:10 +02:00
#include <utility>
2017-07-21 18:21:34 +02:00
2020-05-03 13:47:10 +02:00
QskSizePolicy::ConstraintType QskSizePolicy::constraintType() const noexcept
{
2019-09-18 08:43:09 +02:00
constexpr unsigned char mask = IgnoreFlag | ConstrainedFlag;
#ifndef QT_NO_DEBUG
if ( ( ( m_horizontalPolicy & mask ) == mask )
|| ( ( m_verticalPolicy & mask ) == mask ) )
{
qWarning() << "invalid policy having IgnoreFlag and ConstrainedFlag";
}
#endif
if ( ( m_horizontalPolicy & mask ) == ConstrainedFlag )
return QskSizePolicy::WidthForHeight;
2019-09-18 08:43:09 +02:00
if ( ( m_verticalPolicy & mask ) == ConstrainedFlag )
return QskSizePolicy::HeightForWidth;
return QskSizePolicy::Unconstrained;
}
Qt::SizeHint QskSizePolicy::effectiveSizeHintType(
2020-05-03 13:47:10 +02:00
Qt::SizeHint which, Qt::Orientation orientation ) const noexcept
{
const auto policy = ( orientation == Qt::Horizontal )
? horizontalPolicy() : verticalPolicy();
if ( which == Qt::MinimumSize )
{
if ( !( policy & ShrinkFlag ) )
return Qt::PreferredSize;
}
else if ( which == Qt::MaximumSize )
{
if ( !( policy & ( GrowFlag | ExpandFlag ) ) )
return Qt::PreferredSize;
}
return which;
}
2020-05-03 13:47:10 +02:00
void QskSizePolicy::transpose() noexcept
2020-03-13 13:57:56 +01:00
{
std::swap( m_horizontalPolicy, m_verticalPolicy );
}
2017-07-21 18:21:34 +02:00
#ifndef QT_NO_DEBUG_STREAM
2018-07-19 14:10:48 +02:00
#include <qdebug.h>
2017-07-21 18:21:34 +02:00
QDebug operator<<( QDebug debug, const QskSizePolicy& policy )
{
QDebugStateSaver saver( debug );
debug.nospace();
debug << "SizePolicy" << '(';
debug << policy.horizontalPolicy() << ", " << policy.verticalPolicy();
debug << ')';
return debug;
}
#endif
#include "moc_QskSizePolicy.cpp"