qskinny/src/controls/QskPopupSkinlet.cpp

77 lines
2.1 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 "QskPopupSkinlet.h"
#include "QskPopup.h"
#include "QskRgbValue.h"
static inline QRgb qskInterpolatedRgb( QRgb rgb, qreal factor )
{
return QskRgb::toTransparent( rgb, qRound( factor * qAlpha( rgb ) ) );
}
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
QskPopupSkinlet::QskPopupSkinlet( QskSkin* skin )
: Inherited( skin )
2017-07-21 16:21:34 +00:00
{
appendNodeRoles( { OverlayRole } );
2017-07-21 16:21:34 +00:00
}
QskPopupSkinlet::~QskPopupSkinlet() = default;
QRectF QskPopupSkinlet::subControlRect( const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
2017-07-21 16:21:34 +00:00
{
const auto popup = static_cast< const QskPopup* >( skinnable );
if ( subControl == QskPopup::Overlay )
return popup->overlayRect();
return Inherited::subControlRect( skinnable, contentsRect, subControl );
2017-07-21 16:21:34 +00:00
}
2018-08-03 06:15:28 +00:00
QSGNode* QskPopupSkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
2017-07-21 16:21:34 +00:00
{
const auto popup = static_cast< const QskPopup* >( skinnable );
2018-08-03 06:15:28 +00:00
switch ( nodeRole )
2017-07-21 16:21:34 +00:00
{
case OverlayRole:
return updateOverlayNode( popup, node );
2017-07-21 16:21:34 +00:00
}
2017-09-01 09:55:55 +00:00
return Inherited::updateSubNode( skinnable, nodeRole, node );
2017-07-21 16:21:34 +00:00
}
QSGNode* QskPopupSkinlet::updateOverlayNode(
const QskPopup* popup, QSGNode* node ) const
{
using Q = QskPopup;
const auto factor = popup->fadingFactor();
if ( factor <= 0.0 )
return nullptr;
const auto rect = popup->subControlRect( Q::Overlay );
if ( rect.isEmpty() )
return nullptr;
auto gradient = popup->gradientHint( Q::Overlay );
if ( gradient.isVisible() && factor != 1.0 )
{
auto stops = gradient.stops();
for ( auto& stop : stops )
stop.setRgb( qskInterpolatedRgb( stop.rgb(), factor ) );
gradient.setStops( stops );
}
return updateBoxNode( popup, node, rect, gradient, QskPopup::Overlay );
}
2017-07-21 16:21:34 +00:00
#include "moc_QskPopupSkinlet.cpp"