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"
|
|
|
|
#include "QskSubWindow.h"
|
|
|
|
#include "QskAspect.h"
|
2017-10-17 17:34:00 +02:00
|
|
|
#include "QskBoxBorderMetrics.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
|
|
|
|
|
|
|
QskSubWindowSkinlet::QskSubWindowSkinlet( QskSkin* skin ):
|
|
|
|
Inherited( skin )
|
|
|
|
{
|
|
|
|
appendNodeRoles( { PanelRole, TitleBarRole } );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindowSkinlet::~QskSubWindowSkinlet() = default;
|
|
|
|
|
|
|
|
QRectF QskSubWindowSkinlet::subControlRect(
|
|
|
|
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl ) const
|
|
|
|
{
|
|
|
|
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
|
|
|
|
|
|
|
|
if ( subControl == QskSubWindow::TitleBar )
|
|
|
|
{
|
|
|
|
return titleBarRect( subWindow );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( subControl == QskSubWindow::Panel )
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return subWindow->contentsRect();
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::subControlRect( skinnable, subControl );
|
|
|
|
}
|
|
|
|
|
|
|
|
QSGNode* QskSubWindowSkinlet::updateSubNode( const QskSkinnable* skinnable,
|
|
|
|
quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
|
|
|
|
|
|
|
|
switch( nodeRole )
|
|
|
|
{
|
|
|
|
case PanelRole:
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( subWindow, node, QskSubWindow::Panel );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
case TitleBarRole:
|
2017-10-19 16:24:43 +02:00
|
|
|
return updateBoxNode( subWindow, node, QskSubWindow::TitleBar );
|
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
|
|
|
|
{
|
2017-10-18 20:00:06 +02:00
|
|
|
const auto border = subWindow->boxBorderMetricsHint( QskSubWindow::Panel );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QRectF rect = subWindow->contentsRect().marginsRemoved( border.widths() );
|
2017-07-21 18:21:34 +02:00
|
|
|
rect.setHeight( titleBarHeight( subWindow ) );
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal QskSubWindowSkinlet::titleBarHeight( const QskSubWindow* subWindow ) const
|
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
|
|
|
if ( !subWindow->isDecorated() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const QFontMetricsF fm( subWindow->effectiveFont( QskSubWindow::TitleBar ) );
|
2017-08-23 14:53:29 +02:00
|
|
|
const QMarginsF margins = subWindow->marginsHint( QskSubWindow::TitleBar | Padding );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-08-23 14:53:29 +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
|
|
|
|
|
|
|
return qMax( height, minHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskSubWindowSkinlet.cpp"
|