QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskPopupSkinlet.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskPopupSkinlet.h"
7#include "QskPopup.h"
8#include "QskRgbValue.h"
9
10static inline QRgb qskInterpolatedRgb( QRgb rgb, qreal factor )
11{
12 return QskRgb::toTransparent( rgb, qRound( factor * qAlpha( rgb ) ) );
13}
14
15QskPopupSkinlet::QskPopupSkinlet( QskSkin* skin )
16 : Inherited( skin )
17{
18 appendNodeRoles( { OverlayRole } );
19}
20
21QskPopupSkinlet::~QskPopupSkinlet() = default;
22
23QRectF QskPopupSkinlet::subControlRect( const QskSkinnable* skinnable,
24 const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
25{
26 const auto popup = static_cast< const QskPopup* >( skinnable );
27
28 if ( subControl == QskPopup::Overlay )
29 return popup->overlayRect();
30
31 return Inherited::subControlRect( skinnable, contentsRect, subControl );
32}
33
34QSGNode* QskPopupSkinlet::updateSubNode(
35 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
36{
37 const auto popup = static_cast< const QskPopup* >( skinnable );
38
39 switch ( nodeRole )
40 {
41 case OverlayRole:
42 return updateOverlayNode( popup, node );
43 }
44
45 return Inherited::updateSubNode( skinnable, nodeRole, node );
46}
47
48QSGNode* QskPopupSkinlet::updateOverlayNode(
49 const QskPopup* popup, QSGNode* node ) const
50{
51 using Q = QskPopup;
52
53 const auto factor = popup->fadingFactor();
54 if ( factor <= 0.0 )
55 return nullptr;
56
57 const auto rect = popup->subControlRect( Q::Overlay );
58 if ( rect.isEmpty() )
59 return nullptr;
60
61 auto gradient = popup->gradientHint( Q::Overlay );
62
63 if ( gradient.isVisible() && factor != 1.0 )
64 {
65 auto stops = gradient.stops();
66
67 for ( auto& stop : stops )
68 stop.setRgb( qskInterpolatedRgb( stop.rgb(), factor ) );
69
70 gradient.setStops( stops );
71 }
72
73 return updateBoxNode( popup, node, rect, gradient, QskPopup::Overlay );
74}
75
76#include "moc_QskPopupSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
Definition QskAspect.h:104
QRectF subControlRect(QskAspect::Subcontrol) const
QskGradient gradientHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a color hint as gradient.