QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTabButtonSkinlet.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTabButtonSkinlet.h"
7#include "QskTabButton.h"
8
9#include "QskTextOptions.h"
10#include <qfontmetrics.h>
11
12QskTabButtonSkinlet::QskTabButtonSkinlet( QskSkin* skin )
13 : Inherited( skin )
14{
15 setNodeRoles( { PanelRole, TextRole } );
16}
17
18QskTabButtonSkinlet::~QskTabButtonSkinlet() = default;
19
20QRectF QskTabButtonSkinlet::subControlRect( const QskSkinnable* skinnable,
21 const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
22{
23 if ( subControl == QskTabButton::Text )
24 {
25 return skinnable->subControlContentsRect( contentsRect, QskTabButton::Panel );
26 }
27 else if ( subControl == QskTabButton::Panel )
28 {
29 return contentsRect;
30 }
31
32 return Inherited::subControlRect( skinnable, contentsRect, subControl );
33}
34
35QSGNode* QskTabButtonSkinlet::updateSubNode(
36 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
37{
38 const auto tabButton = static_cast< const QskTabButton* >( skinnable );
39
40 switch ( nodeRole )
41 {
42 case PanelRole:
43 {
44 return updateBoxNode( tabButton, node, QskTabButton::Panel );
45 }
46
47 case TextRole:
48 {
49 return updateTextNode( tabButton, node,
50 tabButton->text(), QskTabButton::Text );
51 }
52 }
53
54 return Inherited::updateSubNode( skinnable, nodeRole, node );
55}
56
57QSizeF QskTabButtonSkinlet::sizeHint( const QskSkinnable* skinnable,
58 Qt::SizeHint which, const QSizeF& ) const
59{
60 using Q = QskTabButton;
61
62 if ( which != Qt::PreferredSize )
63 return QSizeF();
64
65 const auto tabButton = static_cast< const QskTabButton* >( skinnable );
66
67 QSizeF size;
68 const auto text = tabButton->text();
69
70 if ( !text.isEmpty() )
71 {
72 const QFontMetricsF fm( tabButton->effectiveFont( QskTabButton::Text ) );
73 size = fm.size( Qt::TextShowMnemonic, text );
74 }
75
76 size = tabButton->outerBoxSize( Q::Panel, size );
77 size = size.expandedTo( tabButton->strutSizeHint( Q::Panel ) );
78 size = size.grownBy( skinnable->marginHint( Q::Panel ) );
79
80 return size;
81}
82
83#include "moc_QskTabButtonSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
Definition QskAspect.h:104
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
QRectF subControlContentsRect(const QRectF &, QskAspect::Subcontrol) const
Calculate the inner rectangle for subControl.