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 "QskStatusIndicatorSkinlet.h"
|
2018-08-03 08:30:23 +02:00
|
|
|
#include "QskStatusIndicator.h"
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "QskAspect.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskColorFilter.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "QskFunctions.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskGraphic.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskStatusIndicatorSkinlet::QskStatusIndicatorSkinlet( QskSkin* skin )
|
|
|
|
: Inherited( skin )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setNodeRoles( { GraphicRole } );
|
|
|
|
}
|
|
|
|
|
|
|
|
QskStatusIndicatorSkinlet::~QskStatusIndicatorSkinlet() = default;
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskStatusIndicatorSkinlet::subControlRect( const QskSkinnable* skinnable,
|
|
|
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
const auto label = static_cast< const QskStatusIndicator* >( skinnable );
|
|
|
|
|
|
|
|
if ( subControl == QskStatusIndicator::Graphic )
|
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return graphicRect( label, contentsRect );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2017-09-01 11:55:55 +02:00
|
|
|
QSGNode* QskStatusIndicatorSkinlet::updateSubNode(
|
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const auto indicator = static_cast< const QskStatusIndicator* >( skinnable );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
switch ( nodeRole )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
|
|
|
case GraphicRole:
|
|
|
|
{
|
|
|
|
return updateGraphicNode( indicator, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QRect QskStatusIndicatorSkinlet::graphicRect(
|
2019-04-25 14:23:39 +02:00
|
|
|
const QskStatusIndicator* indicator, const QRectF& contentsRect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
// maybe we should have a common base class for
|
|
|
|
// QskStatusIndicator and QskGraphicLabel
|
|
|
|
|
|
|
|
// PreserveAspectFit/PreserveAspectCrop
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
const QRect graphicRect = contentsRect.toAlignedRect();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QSizeF sz = indicator->graphic( indicator->status() ).defaultSize();
|
|
|
|
sz.scale( graphicRect.size(), Qt::KeepAspectRatio );
|
|
|
|
|
|
|
|
return qskAlignedRect( graphicRect,
|
2018-08-03 08:15:28 +02:00
|
|
|
( int ) sz.width(), ( int ) sz.height(), Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSGNode* QskStatusIndicatorSkinlet::updateGraphicNode(
|
|
|
|
const QskStatusIndicator* indicator, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const auto subControl = QskStatusIndicator::Graphic;
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
const auto rect = subControlRect( indicator, indicator->contentsRect(), subControl );
|
|
|
|
const auto alignment = indicator->alignmentHint( subControl, Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
const int status = indicator->status();
|
|
|
|
|
|
|
|
node = QskSkinlet::updateGraphicNode( indicator, node,
|
|
|
|
indicator->graphic( status ), indicator->graphicFilter( status ),
|
|
|
|
rect, alignment );
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskStatusIndicatorSkinlet.cpp"
|