6#include "QskSubWindowSkinlet.h"
7#include "QskSubWindow.h"
10#include "QskBoxBorderMetrics.h"
11#include "QskGraphic.h"
12#include "QskTextOptions.h"
14#include <qfontmetrics.h>
16QskSubWindowSkinlet::QskSubWindowSkinlet(
QskSkin* skin )
19 appendNodeRoles( { PanelRole, TitleBarRole, SymbolRole, TitleRole } );
22QskSubWindowSkinlet::~QskSubWindowSkinlet() =
default;
24QRectF QskSubWindowSkinlet::subControlRect(
const QskSkinnable* skinnable,
29 const auto subWindow =
static_cast< const QskSubWindow*
>( skinnable );
31 if ( subControl == Q::Panel )
35 else if ( subControl == Q::TitleBarPanel )
37 return titleBarRect( subWindow, contentsRect );
39 else if ( subControl == Q::TitleBarSymbol )
41 return symbolRect( subWindow, contentsRect );
43 else if ( subControl == Q::TitleBarText )
45 return titleRect( subWindow, contentsRect );
48 return Inherited::subControlRect( skinnable, contentsRect, subControl );
51QSGNode* QskSubWindowSkinlet::updateSubNode(
52 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
56 const auto subWindow =
static_cast< const QskSubWindow*
>( skinnable );
62 return updateBoxNode( subWindow, node, Q::Panel );
66 const auto decorations = subWindow->decorations();
68 if ( decorations & Q::TitleBar )
69 return updateBoxNode( subWindow, node, Q::TitleBarPanel );
75 const auto decorations = subWindow->decorations();
77 if ( ( decorations & Q::TitleBar ) && ( decorations & Q::Symbol ) )
79 return updateGraphicNode( subWindow, node,
80 subWindow->windowIcon(), Q::TitleBarSymbol );
87 const auto decorations = subWindow->decorations();
89 if ( ( decorations & Q::TitleBar ) && ( decorations & Q::Title ) )
91 return updateTextNode( subWindow, node,
92 subWindow->windowTitle(), Q::TitleBarText );
106 updateBoxNode( subWindow, node, Q::Overlay );
111 return Inherited::updateSubNode( skinnable, nodeRole, node );
114QRectF QskSubWindowSkinlet::titleBarRect(
115 const QskSubWindow* subWindow,
const QRectF& contentsRect )
const
119 QRectF r = contentsRect.marginsRemoved( border.widths() );
120 r.setHeight( titleBarHeight( subWindow ) );
125qreal QskSubWindowSkinlet::titleBarHeight(
const QskSubWindow* subWindow )
const
129 const auto decorations = subWindow->decorations();
130 if ( !( decorations & Q::TitleBar ) )
133 auto height = subWindow->
strutSizeHint( Q::TitleBarPanel ).height();
135 if ( decorations & Q::Title )
137 const auto padding = subWindow->
paddingHint( Q::TitleBarPanel );
138 const QFontMetricsF fm( subWindow->
effectiveFont( Q::TitleBarText ) );
140 const qreal h = fm.height() + padding.top() + padding.bottom();
148QRectF QskSubWindowSkinlet::symbolRect(
149 const QskSubWindow* subWindow,
const QRectF& contentsRect )
const
153 if ( !subWindow->hasDecoration( Q::Symbol ) )
158 if ( !rect.isEmpty() )
160 const auto symbol = subWindow->windowIcon();
163 if ( !symbol.isNull() )
164 w = symbol.widthForHeight( rect.height() );
172QRectF QskSubWindowSkinlet::titleRect(
173 const QskSubWindow* subWindow,
const QRectF& contentsRect )
const
177 if ( !subWindow->hasDecoration( Q::Title ) )
182 if ( !rect.isEmpty() )
184 const auto symbolRect = subControlRect( subWindow, rect, Q::TitleBarSymbol );
185 if ( !symbolRect.isEmpty() )
187 const auto spacing = subWindow->
spacingHint( Q::TitleBarPanel );
188 rect.setX( symbolRect.right() + spacing );
192 const QFontMetricsF fm( subWindow->
effectiveFont( Q::TitleBarText ) );
193 rect.setHeight( fm.height() );
200QSizeF QskSubWindowSkinlet::sizeHint(
const QskSkinnable* skinnable,
201 Qt::SizeHint which,
const QSizeF& )
const
205 if ( which != Qt::MinimumSize )
208 const auto subWindow =
static_cast< const QskSubWindow*
>( skinnable );
212 if ( subWindow->decorations() != Q::NoDecoration )
214 const auto size = subWindow->
strutSizeHint( Q::TitleBarPanel );
216 hint.rwidth() = qMax( hint.width(), size.width() );
218 if ( size.height() >= 0 )
220 hint.rheight() = qMax( hint.height(), 0.0 );
221 hint.rheight() += size.height();
228#include "moc_QskSubWindowSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlContentsRect(QskAspect::Subcontrol) const
qreal spacingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a spacing hint.
QMarginsF paddingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a padding hint.
QFont effectiveFont(QskAspect) const
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QskBoxBorderMetrics boxBorderMetricsHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a border hint.