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
|
|
|
|
|
|
|
#include <QSGSimpleRectNode>
|
|
|
|
#include <QFontMetricsF>
|
|
|
|
|
|
|
|
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-09-01 11:55:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( subWindow, node, QskSubWindow::Panel );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
case TitleBarRole:
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2017-07-21 18:21:34 +02:00
|
|
|
return updateTitleBarNode( subWindow, node );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
QSGNode* QskSubWindowSkinlet::updateTitleBarNode(
|
|
|
|
const QskSubWindow* subWindow, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const QRectF rect = subControlRect( subWindow, QskSubWindow::TitleBar );
|
|
|
|
if ( rect.isEmpty() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto barNode = static_cast< QSGSimpleRectNode* >( node );
|
|
|
|
if ( barNode == nullptr )
|
|
|
|
barNode = new QSGSimpleRectNode();
|
|
|
|
|
|
|
|
QskAspect::Aspect aspect = QskSubWindow::TitleBar;
|
|
|
|
if ( subWindow->isActive() )
|
|
|
|
aspect = aspect | QskControl::Focused;
|
|
|
|
|
|
|
|
barNode->setColor( subWindow->color( aspect ) );
|
|
|
|
barNode->setRect( rect );
|
|
|
|
|
|
|
|
return barNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF QskSubWindowSkinlet::titleBarRect( const QskSubWindow* subWindow ) const
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
const auto border = subWindow->boxBorderHint( QskSubWindow::Panel | QskAspect::Border );
|
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"
|