qskinny/src/controls/QskSeparatorSkinlet.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 16:21:34 +00:00
*****************************************************************************/
#include "QskSeparatorSkinlet.h"
2018-08-03 06:15:28 +00:00
#include "QskSeparator.h"
2017-07-21 16:21:34 +00:00
#include "QskGradientDirection.h"
2018-08-03 06:30:23 +00:00
#include "QskAspect.h"
2018-08-03 06:15:28 +00:00
QskSeparatorSkinlet::QskSeparatorSkinlet( QskSkin* skin )
: Inherited( skin )
2017-07-21 16:21:34 +00:00
{
setNodeRoles( { PanelRole } );
}
QskSeparatorSkinlet::~QskSeparatorSkinlet() = default;
QRectF QskSeparatorSkinlet::subControlRect( const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
2018-08-03 06:15:28 +00:00
{
2017-07-21 16:21:34 +00:00
const auto separator = static_cast< const QskSeparator* >( skinnable );
2018-08-03 06:15:28 +00:00
2017-07-21 16:21:34 +00:00
if ( subControl == QskSeparator::Panel )
{
return panelRect( separator, contentsRect );
2017-07-21 16:21:34 +00:00
}
2018-08-03 06:15:28 +00:00
return Inherited::subControlRect( skinnable, contentsRect, subControl );
2017-09-01 09:55:55 +00:00
}
QSGNode* QskSeparatorSkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
{
const auto separator = static_cast< const QskSeparator* >( skinnable );
2018-08-03 06:15:28 +00:00
switch ( nodeRole )
2017-09-01 09:55:55 +00:00
{
case PanelRole:
{
using Q = QskSeparator;
const auto rect = separator->subControlRect( Q::Panel );
auto gradient = separator->gradientHint( Q::Panel );
if ( ( gradient.type() == QskGradient::Stops ) && !gradient.isMonochrome() )
{
// gradient in opposite orientation
const auto orientation = ( separator->orientation() == Qt::Vertical )
? Qt::Horizontal : Qt::Vertical;
gradient.setLinearDirection( orientation );
}
return updateBoxNode( separator, node, rect, gradient, Q::Panel );
2017-09-01 09:55:55 +00:00
}
}
return Inherited::updateSubNode( skinnable, nodeRole, node );
}
2017-07-21 16:21:34 +00:00
QRectF QskSeparatorSkinlet::panelRect(
const QskSeparator* separator, const QRectF& contentsRect ) const
2017-07-21 16:21:34 +00:00
{
2020-12-17 07:53:44 +00:00
const qreal extent = separator->extent();
2017-07-21 16:21:34 +00:00
QRectF r;
if ( separator->orientation() == Qt::Horizontal )
{
r.setWidth( contentsRect.width() );
2020-12-17 07:53:44 +00:00
r.setHeight( extent );
2017-07-21 16:21:34 +00:00
}
else
{
r.setHeight( contentsRect.height() );
2020-12-17 07:53:44 +00:00
r.setWidth( extent );
2017-07-21 16:21:34 +00:00
}
r.moveCenter( contentsRect.center() );
2017-07-21 16:21:34 +00:00
return r;
}
QSizeF QskSeparatorSkinlet::sizeHint( const QskSkinnable* skinnable,
Qt::SizeHint which, const QSizeF& ) const
{
if ( which != Qt::PreferredSize )
return QSizeF();
const auto separator = static_cast< const QskSeparator* >( skinnable );
const qreal extent = separator->extent();
if ( separator->orientation() == Qt::Horizontal )
return QSizeF( -1, extent );
else
return QSizeF( extent, -1 );
}
2017-07-21 16:21:34 +00:00
#include "moc_QskSeparatorSkinlet.cpp"