QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSeparatorSkinlet.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSeparatorSkinlet.h"
7#include "QskSeparator.h"
8
9#include "QskGradientDirection.h"
10#include "QskAspect.h"
11
12QskSeparatorSkinlet::QskSeparatorSkinlet( QskSkin* skin )
13 : Inherited( skin )
14{
15 setNodeRoles( { PanelRole } );
16}
17
18QskSeparatorSkinlet::~QskSeparatorSkinlet() = default;
19
20QRectF QskSeparatorSkinlet::subControlRect( const QskSkinnable* skinnable,
21 const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
22{
23 const auto separator = static_cast< const QskSeparator* >( skinnable );
24
25 if ( subControl == QskSeparator::Panel )
26 {
27 return panelRect( separator, contentsRect );
28 }
29
30 return Inherited::subControlRect( skinnable, contentsRect, subControl );
31}
32
33QSGNode* QskSeparatorSkinlet::updateSubNode(
34 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
35{
36 const auto separator = static_cast< const QskSeparator* >( skinnable );
37
38 switch ( nodeRole )
39 {
40 case PanelRole:
41 {
42 using Q = QskSeparator;
43
44 const auto rect = separator->subControlRect( Q::Panel );
45
46 auto gradient = separator->gradientHint( Q::Panel );
47 if ( ( gradient.type() == QskGradient::Stops ) && !gradient.isMonochrome() )
48 {
49 // gradient in opposite orientation
50 const auto orientation = ( separator->orientation() == Qt::Vertical )
51 ? Qt::Horizontal : Qt::Vertical;
52
53 gradient.setLinearDirection( orientation );
54 }
55
56 return updateBoxNode( separator, node, rect, gradient, Q::Panel );
57 }
58 }
59
60 return Inherited::updateSubNode( skinnable, nodeRole, node );
61}
62
63QRectF QskSeparatorSkinlet::panelRect(
64 const QskSeparator* separator, const QRectF& contentsRect ) const
65{
66 const qreal extent = separator->extent();
67
68 QRectF r;
69
70 if ( separator->orientation() == Qt::Horizontal )
71 {
72 r.setWidth( contentsRect.width() );
73 r.setHeight( extent );
74 }
75 else
76 {
77 r.setHeight( contentsRect.height() );
78 r.setWidth( extent );
79 }
80
81 r.moveCenter( contentsRect.center() );
82 return r;
83}
84
85QSizeF QskSeparatorSkinlet::sizeHint( const QskSkinnable* skinnable,
86 Qt::SizeHint which, const QSizeF& ) const
87{
88 if ( which != Qt::PreferredSize )
89 return QSizeF();
90
91 const auto separator = static_cast< const QskSeparator* >( skinnable );
92
93 const qreal extent = separator->extent();
94
95 if ( separator->orientation() == Qt::Horizontal )
96 return QSizeF( -1, extent );
97 else
98 return QSizeF( extent, -1 );
99}
100
101#include "moc_QskSeparatorSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
Definition QskAspect.h:104
QRectF subControlRect(QskAspect::Subcontrol) const
Separates a group of items from adjacent items.
static const QskAspect::Subcontrol Panel
Qt::Orientation orientation
Orientation of the separator - Qt::Horizontal (the default) or Qt::Vertical.