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 "QskBox.h"
|
|
|
|
|
|
|
|
QSK_SUBCONTROL( QskBox, Panel )
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskBox::QskBox( QQuickItem* parent )
|
2019-05-10 07:44:13 +02:00
|
|
|
: QskBox( true, parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskBox::QskBox( bool hasPanel, QQuickItem* parent )
|
2018-08-03 08:15:28 +02:00
|
|
|
: Inherited( parent )
|
2019-05-10 07:44:13 +02:00
|
|
|
, m_hasPanel( hasPanel )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskBox::~QskBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:44:13 +02:00
|
|
|
void QskBox::setPanel( bool on )
|
|
|
|
{
|
|
|
|
if ( on != m_hasPanel )
|
|
|
|
{
|
|
|
|
m_hasPanel = on;
|
|
|
|
|
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskBox::hasPanel() const
|
|
|
|
{
|
|
|
|
return m_hasPanel;
|
|
|
|
}
|
|
|
|
|
2019-09-20 07:04:17 +02:00
|
|
|
void QskBox::setPadding( qreal padding )
|
|
|
|
{
|
|
|
|
setPadding( QMarginsF( padding, padding, padding, padding ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskBox::setPadding( const QMarginsF& padding )
|
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
|
|
|
const QMarginsF pd(
|
|
|
|
qMax( qreal( padding.left() ), qreal( 0.0 ) ),
|
|
|
|
qMax( qreal( padding.top() ), qreal( 0.0 ) ),
|
|
|
|
qMax( qreal( padding.right() ), qreal( 0.0 ) ),
|
|
|
|
qMax( qreal( padding.bottom() ), qreal( 0.0 ) ) );
|
|
|
|
|
|
|
|
if ( pd != this->padding() )
|
|
|
|
{
|
|
|
|
const auto subControl = effectiveSubcontrol( QskBox::Panel );
|
|
|
|
|
|
|
|
setMarginsHint( subControl | Padding, pd );
|
|
|
|
resetImplicitSize();
|
|
|
|
|
|
|
|
if ( polishOnResize() || autoLayoutChildren() )
|
|
|
|
polish();
|
|
|
|
|
|
|
|
Q_EMIT paddingChanged( pd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskBox::resetPadding()
|
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
2019-12-14 13:34:30 +01:00
|
|
|
if ( resetHint( QskBox::Panel | Metric | Padding ) )
|
2019-09-20 07:04:17 +02:00
|
|
|
{
|
2019-12-14 13:34:30 +01:00
|
|
|
resetImplicitSize();
|
2019-09-20 07:04:17 +02:00
|
|
|
|
2019-12-14 13:34:30 +01:00
|
|
|
if ( polishOnResize() || autoLayoutChildren() )
|
|
|
|
polish();
|
2019-09-20 07:04:17 +02:00
|
|
|
|
2019-12-14 13:34:30 +01:00
|
|
|
Q_EMIT paddingChanged( padding() );
|
2019-09-20 07:04:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QMarginsF QskBox::padding() const
|
|
|
|
{
|
|
|
|
return marginsHint( QskBox::Panel | QskAspect::Padding );
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:09:59 +02:00
|
|
|
QRectF QskBox::layoutRectForSize( const QSizeF& size ) const
|
2018-08-03 08:15:28 +02:00
|
|
|
{
|
2019-05-10 07:44:13 +02:00
|
|
|
if ( !m_hasPanel )
|
|
|
|
return Inherited::layoutRectForSize( size );
|
|
|
|
|
2019-04-26 18:09:59 +02:00
|
|
|
return innerBox( Panel, subControlRect( size, Panel ) );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
QSizeF QskBox::contentsSizeHint(
|
|
|
|
Qt::SizeHint which, const QSizeF& constraint ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-09-10 17:01:47 +02:00
|
|
|
if ( m_hasPanel && which == Qt::PreferredSize )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-09-10 17:01:47 +02:00
|
|
|
return QSizeF(
|
|
|
|
metric( Panel | QskAspect::MinimumWidth ),
|
|
|
|
metric( Panel | QskAspect::MinimumHeight ) );
|
2018-08-03 08:15:28 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
return Inherited::contentsSizeHint( which, constraint );
|
2018-08-03 08:15:28 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include "moc_QskBox.cpp"
|