6#include "QskPushButtonSkinlet.h"
7#include "QskPushButton.h"
8#include "QskTextOptions.h"
10#include "QskAnimationHint.h"
11#include "QskGraphic.h"
12#include "QskSubcontrolLayoutEngine.h"
15static inline Qt::Orientation qskOrientation(
const QskPushButton* button )
19 const auto direction = button->
flagHint(
23 return Qt::Horizontal;
36 setSpacing( button->
spacingHint( QskPushButton::Panel ) );
38 setGraphicTextElements( button,
39 QskPushButton::Text, button->text(),
40 QskPushButton::Icon, button->icon().defaultSize() );
43 QskPushButton::Panel, Qt::AlignCenter );
45 setFixedContent( QskPushButton::Text, Qt::Horizontal, alignment );
50QskPushButtonSkinlet::QskPushButtonSkinlet(
QskSkin* skin )
53 setNodeRoles( { PanelRole, SplashRole, IconRole, TextRole } );
56QskPushButtonSkinlet::~QskPushButtonSkinlet() =
default;
58QRectF QskPushButtonSkinlet::subControlRect(
const QskSkinnable* skinnable,
63 const auto button =
static_cast< const QskPushButton*
>( skinnable );
65 if ( subControl == Q::Panel )
68 if ( subControl == Q::Splash )
69 return splashRect( button, contentsRect );
71 if ( ( subControl == Q::Text ) || ( subControl == Q::Icon ) )
75 LayoutEngine layoutEngine( button );
76 layoutEngine.setGeometries( r );
78 return layoutEngine.subControlRect( subControl );
81 return Inherited::subControlRect( skinnable, contentsRect, subControl );
84QSGNode* QskPushButtonSkinlet::updateSubNode(
85 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
89 const auto button =
static_cast< const QskPushButton*
>( skinnable );
94 return updateBoxNode( button, node, Q::Panel );
97 return updateSplashNode( button, node );
100 return updateTextNode( button, node );
103 return updateGraphicNode( button, node, button->icon(), Q::Icon );
106 return Inherited::updateSubNode( skinnable, nodeRole, node );
109QRectF QskPushButtonSkinlet::splashRect(
110 const QskPushButton* button,
const QRectF& contentsRect )
const
119 rect = subControlRect( button, contentsRect, Q::Panel );
121 const auto pos = button->positionHint( Q::Splash );
122 const qreal w = 2.0 * rect.width() * ratio;
124 rect.setX( pos - 0.5 * w );
131QSGNode* QskPushButtonSkinlet::updateTextNode(
136 const auto rect = button->
subControlRect( Q::Text ).toAlignedRect();
138 const auto textHeight = button->effectiveFontHeight( Q::Text );
139 if ( !button->clip() && ( rect.height() < textHeight ) )
142 const auto alignment = button->
alignmentHint( Q::Text, Qt::AlignCenter );
144 return QskSkinlet::updateTextNode( button, node, rect,
145 alignment, button->text(), Q::Text );
148QSGNode* QskPushButtonSkinlet::updateSplashNode(
154 if ( splashRect.isEmpty() )
157 auto clipNode = updateBoxClipNode( button, node,
162 auto boxNode = QskSGNode::findChildNode( clipNode, SplashRole );
163 boxNode = updateBoxNode( button, boxNode, splashRect, Q::Splash );
165 if ( boxNode ==
nullptr )
168 QskSGNode::setNodeRole( boxNode, SplashRole );
169 if ( boxNode->parent() != clipNode )
170 clipNode->appendChildNode( boxNode );
176QSizeF QskPushButtonSkinlet::sizeHint(
const QskSkinnable* skinnable,
177 Qt::SizeHint which,
const QSizeF& )
const
181 if ( which != Qt::PreferredSize )
184 const auto button =
static_cast< const QskPushButton*
>( skinnable );
186 LayoutEngine layoutEngine( button );
188 auto size = layoutEngine.sizeHint( which, QSizeF() );
191 size = size.grownBy( skinnable->
marginHint( Q::Panel ) );
196#include "moc_QskPushButtonSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
QRectF subControlContentsRect(QskAspect::Subcontrol) const
qreal spacingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a spacing hint.
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QSizeF outerBoxSize(QskAspect, const QSizeF &innerBoxSize) const
Calculate the size, when being expanded by paddings, indentations.
T flagHint(QskAspect, T=T()) const
Retrieves a flag hint.
qreal metric(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a metric hint.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.