2017-07-21 16:21:34 +00: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 06:30:23 +00:00
|
|
|
#include "QskSubWindow.h"
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
#include "QskAspect.h"
|
2017-10-17 15:34:00 +00:00
|
|
|
#include "QskBoxBorderMetrics.h"
|
2018-10-29 19:11:48 +00:00
|
|
|
#include "QskGraphic.h"
|
|
|
|
#include "QskTextOptions.h"
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2018-07-19 12:10:48 +00:00
|
|
|
#include <qfontmetrics.h>
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QskSubWindowSkinlet::QskSubWindowSkinlet( QskSkin* skin )
|
|
|
|
: Inherited( skin )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2018-10-29 19:11:48 +00:00
|
|
|
appendNodeRoles( { PanelRole, TitleBarRole, SymbolRole, TitleRole } );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QskSubWindowSkinlet::~QskSubWindowSkinlet() = default;
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
QRectF QskSubWindowSkinlet::subControlRect( const QskSkinnable* skinnable,
|
|
|
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
|
|
|
|
|
2018-10-29 19:11:48 +00:00
|
|
|
if ( subControl == QskSubWindow::Panel )
|
|
|
|
{
|
2019-04-25 12:23:39 +00:00
|
|
|
return contentsRect;
|
2018-10-29 19:11:48 +00:00
|
|
|
}
|
|
|
|
else if ( subControl == QskSubWindow::TitleBar )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-04-25 12:23:39 +00:00
|
|
|
return titleBarRect( subWindow, contentsRect );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
2018-10-29 19:11:48 +00:00
|
|
|
else if ( subControl == QskSubWindow::TitleBarSymbol )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-04-25 12:23:39 +00:00
|
|
|
return symbolRect( subWindow, contentsRect );
|
2018-10-29 19:11:48 +00:00
|
|
|
}
|
|
|
|
else if ( subControl == QskSubWindow::TitleBarText )
|
|
|
|
{
|
2019-04-25 12:23:39 +00:00
|
|
|
return titleRect( subWindow, contentsRect );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QSGNode* QskSubWindowSkinlet::updateSubNode(
|
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
const auto subWindow = static_cast< const QskSubWindow* >( skinnable );
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
switch ( nodeRole )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
case PanelRole:
|
2018-10-29 19:11:48 +00:00
|
|
|
{
|
2017-10-17 15:34:00 +00:00
|
|
|
return updateBoxNode( subWindow, node, QskSubWindow::Panel );
|
2018-10-29 19:11:48 +00:00
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
case TitleBarRole:
|
2018-10-29 19:11:48 +00: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 16:21:34 +00:00
|
|
|
}
|
2017-09-01 09:55:55 +00:00
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
QRectF QskSubWindowSkinlet::titleBarRect(
|
|
|
|
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2017-10-18 18:00:06 +00:00
|
|
|
const auto border = subWindow->boxBorderMetricsHint( QskSubWindow::Panel );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
QRectF r = contentsRect.marginsRemoved( border.widths() );
|
|
|
|
r.setHeight( titleBarHeight( subWindow ) );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
return r;
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal QskSubWindowSkinlet::titleBarHeight( const QskSubWindow* subWindow ) const
|
|
|
|
{
|
2020-12-15 06:21:12 +00:00
|
|
|
using Q = QskSubWindow;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
if ( !subWindow->isDecorated() )
|
|
|
|
return 0;
|
|
|
|
|
2020-12-15 06:21:12 +00:00
|
|
|
const auto margins = subWindow->paddingHint( Q::TitleBar );
|
|
|
|
const QFontMetricsF fm( subWindow->effectiveFont( Q::TitleBarText ) );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2017-08-23 12:53:29 +00:00
|
|
|
const qreal height = fm.height() + margins.top() + margins.bottom();
|
2020-12-16 11:49:24 +00:00
|
|
|
const auto strutSize = subWindow->strutSizeHint( Q::TitleBar );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2020-12-16 11:49:24 +00:00
|
|
|
return qMax( height, strutSize.height() );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
QRectF QskSubWindowSkinlet::symbolRect(
|
|
|
|
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
|
2018-10-29 19:11:48 +00:00
|
|
|
{
|
2020-12-15 06:21:12 +00:00
|
|
|
using Q = QskSubWindow;
|
|
|
|
|
2020-12-29 11:57:03 +00:00
|
|
|
auto rect = subWindow->subControlContentsRect( contentsRect, Q::TitleBar );
|
2018-10-29 19:11:48 +00:00
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
if ( !rect.isEmpty() )
|
|
|
|
{
|
|
|
|
const auto symbol = subWindow->windowIcon();
|
|
|
|
if ( !symbol.isNull() )
|
|
|
|
w = symbol.widthForHeight( rect.height() );
|
|
|
|
|
|
|
|
rect.setWidth( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
QRectF QskSubWindowSkinlet::titleRect(
|
|
|
|
const QskSubWindow* subWindow, const QRectF& contentsRect ) const
|
2018-10-29 19:11:48 +00:00
|
|
|
{
|
2020-12-15 06:21:12 +00:00
|
|
|
using Q = QskSubWindow;
|
|
|
|
|
2020-12-29 11:57:03 +00:00
|
|
|
auto rect = subWindow->subControlContentsRect( contentsRect, Q::TitleBar );
|
2018-10-29 19:11:48 +00:00
|
|
|
|
|
|
|
if ( !rect.isEmpty() )
|
|
|
|
{
|
2020-12-15 06:21:12 +00:00
|
|
|
const auto spacing = subWindow->spacingHint( Q::TitleBar );
|
|
|
|
const auto symbolRect = subControlRect( subWindow, rect, Q::TitleBarSymbol );
|
2019-04-25 12:23:39 +00:00
|
|
|
|
2019-01-04 12:42:16 +00:00
|
|
|
rect.setX( rect.x() + symbolRect.right() + spacing );
|
2018-10-29 19:11:48 +00:00
|
|
|
|
|
|
|
#if 0
|
2020-12-15 06:21:12 +00:00
|
|
|
const QFontMetricsF fm( subWindow->effectiveFont( Q::TitleBarText ) );
|
2018-10-29 19:11:48 +00:00
|
|
|
rect.setHeight( fm.height() ); // TitleBarText | Alignment
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
#include "moc_QskSubWindowSkinlet.cpp"
|