qskinny/src/controls/QskSubWindowSkinlet.cpp

165 lines
4.8 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskSubWindowSkinlet.h"
2018-08-03 08:30:23 +02:00
#include "QskSubWindow.h"
2017-07-21 18:21:34 +02:00
#include "QskAspect.h"
#include "QskBoxBorderMetrics.h"
2018-10-29 20:11:48 +01:00
#include "QskGraphic.h"
#include "QskTextOptions.h"
2017-07-21 18:21:34 +02:00
2018-07-19 14:10:48 +02:00
#include <qfontmetrics.h>
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
QskSubWindowSkinlet::QskSubWindowSkinlet( QskSkin* skin )
: Inherited( skin )
2017-07-21 18:21:34 +02:00
{
2018-10-29 20:11:48 +01:00
appendNodeRoles( { PanelRole, TitleBarRole, SymbolRole, TitleRole } );
2017-07-21 18:21:34 +02:00
}
QskSubWindowSkinlet::~QskSubWindowSkinlet() = default;
QRectF QskSubWindowSkinlet::subControlRect( const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
2017-07-21 18:21:34 +02:00
{
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
2018-10-29 20:11:48 +01:00
if ( subControl == QskSubWindow::Panel )
{
return contentsRect;
2018-10-29 20:11:48 +01:00
}
else if ( subControl == QskSubWindow::TitleBar )
2017-07-21 18:21:34 +02:00
{
return titleBarRect( subWindow, contentsRect );
2017-07-21 18:21:34 +02:00
}
2018-10-29 20:11:48 +01:00
else if ( subControl == QskSubWindow::TitleBarSymbol )
2017-07-21 18:21:34 +02:00
{
return symbolRect( subWindow, contentsRect );
2018-10-29 20:11:48 +01:00
}
else if ( subControl == QskSubWindow::TitleBarText )
{
return titleRect( subWindow, contentsRect );
2017-07-21 18:21:34 +02:00
}
return Inherited::subControlRect( skinnable, contentsRect, subControl );
2017-07-21 18:21:34 +02:00
}
2018-08-03 08:15:28 +02:00
QSGNode* QskSubWindowSkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
2017-07-21 18:21:34 +02:00
{
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
2018-08-03 08:15:28 +02:00
switch ( nodeRole )
2017-07-21 18:21:34 +02:00
{
case PanelRole:
2018-10-29 20:11:48 +01:00
{
return updateBoxNode( subWindow, node, QskSubWindow::Panel );
2018-10-29 20:11:48 +01:00
}
2017-07-21 18:21:34 +02:00
case TitleBarRole:
2018-10-29 20:11:48 +01:00
{
if ( subWindow->isDecorated() )
return updateBoxNode( subWindow, node, QskSubWindow::TitleBar );
return nullptr;
}
case SymbolRole:
{
if ( subWindow->isDecorated() )
{
return updateGraphicNode( subWindow, node,
subWindow->windowIcon(), QskSubWindow::TitleBarSymbol );
}
return nullptr;
}
case TitleRole:
{
if ( subWindow->isDecorated() )
{
return updateTextNode( subWindow, node, subWindow->windowTitle(),
subWindow->windowTitleTextOptions(), QskSubWindow::TitleBarText );
}
return nullptr;
}
2017-07-21 18:21:34 +02:00
}
2017-09-01 11:55:55 +02:00
return Inherited::updateSubNode( skinnable, nodeRole, node );
2017-07-21 18:21:34 +02:00
}
QRectF QskSubWindowSkinlet::titleBarRect(
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
2017-07-21 18:21:34 +02:00
{
2017-10-18 20:00:06 +02:00
const auto border = subWindow->boxBorderMetricsHint( QskSubWindow::Panel );
2017-07-21 18:21:34 +02:00
QRectF r = contentsRect.marginsRemoved( border.widths() );
r.setHeight( titleBarHeight( subWindow ) );
2017-07-21 18:21:34 +02:00
return r;
2017-07-21 18:21:34 +02:00
}
qreal QskSubWindowSkinlet::titleBarHeight( const QskSubWindow* subWindow ) const
{
using namespace QskAspect;
if ( !subWindow->isDecorated() )
return 0;
const QMarginsF margins = subWindow->marginsHint( QskSubWindow::TitleBar | Padding );
2018-10-29 20:11:48 +01:00
const QFontMetricsF fm( subWindow->effectiveFont( QskSubWindow::TitleBarText ) );
2017-07-21 18:21:34 +02:00
const qreal height = fm.height() + margins.top() + margins.bottom();
const qreal minHeight = subWindow->metric( QskSubWindow::TitleBar | MinimumHeight );
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
return qMax( height, minHeight );
2017-07-21 18:21:34 +02:00
}
QRectF QskSubWindowSkinlet::symbolRect(
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
2018-10-29 20:11:48 +01:00
{
auto rect = subControlRect( subWindow, contentsRect, QskSubWindow::TitleBar );
2018-10-29 20:11:48 +01:00
rect = subWindow->innerBox( QskSubWindow::TitleBar, rect );
int w = 0;
if ( !rect.isEmpty() )
{
const auto symbol = subWindow->windowIcon();
if ( !symbol.isNull() )
w = symbol.widthForHeight( rect.height() );
rect.setWidth( w );
}
return rect;
}
QRectF QskSubWindowSkinlet::titleRect(
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
2018-10-29 20:11:48 +01:00
{
auto rect = subControlRect( subWindow, contentsRect, QskSubWindow::TitleBar );
2018-10-29 20:11:48 +01:00
rect = subWindow->innerBox( QskSubWindow::TitleBar, rect );
if ( !rect.isEmpty() )
{
const auto spacing = subWindow->metric(
QskSubWindow::TitleBar | QskAspect::Spacing );
const auto symbolRect = subControlRect(
subWindow, rect, QskSubWindow::TitleBarSymbol );
2019-01-04 13:42:16 +01:00
rect.setX( rect.x() + symbolRect.right() + spacing );
2018-10-29 20:11:48 +01:00
#if 0
const QFontMetricsF fm( subWindow->effectiveFont( QskSubWindow::TitleBarText ) );
rect.setHeight( fm.height() ); // TitleBarText | Alignment
#endif
}
return rect;
}
2017-07-21 18:21:34 +02:00
#include "moc_QskSubWindowSkinlet.cpp"