2020-07-31 16:57:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
#include "QskProgressBarSkinlet.h"
|
|
|
|
#include "QskProgressBar.h"
|
2020-07-31 16:57:22 +02:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QskProgressBarSkinlet::QskProgressBarSkinlet( QskSkin* skin )
|
2020-07-31 16:57:22 +02:00
|
|
|
: QskSkinlet( skin )
|
|
|
|
{
|
|
|
|
setNodeRoles( { GrooveRole, ValueFillRole } );
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QskProgressBarSkinlet::~QskProgressBarSkinlet()
|
2020-07-31 16:57:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QRectF QskProgressBarSkinlet::subControlRect(
|
2020-07-31 16:57:22 +02:00
|
|
|
const QskSkinnable* skinnable, const QRectF& contentsRect,
|
|
|
|
QskAspect::Subcontrol subControl ) const
|
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
const auto bar = static_cast< const QskProgressBar* >( skinnable );
|
2020-07-31 16:57:22 +02:00
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
if( ( subControl == QskProgressBar::Groove ) )
|
2020-07-31 16:57:22 +02:00
|
|
|
{
|
|
|
|
const auto dim = bar->thickness();
|
|
|
|
|
|
|
|
auto rect = contentsRect;
|
|
|
|
if ( bar->orientation() == Qt::Horizontal )
|
|
|
|
{
|
|
|
|
rect.setY( rect.y() + 0.5 * ( rect.height() - dim ) );
|
|
|
|
rect.setHeight( dim );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect.setX( rect.x() + 0.5 * ( rect.width() - dim ) );
|
|
|
|
rect.setWidth( dim );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
if( subControl == QskProgressBar::ValueFill )
|
2020-07-31 16:57:22 +02:00
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
const auto bar = static_cast< const QskProgressBar* >( skinnable );
|
2020-07-31 16:57:22 +02:00
|
|
|
return fillRect( bar );
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QSGNode* QskProgressBarSkinlet::updateSubNode(
|
2020-07-31 16:57:22 +02:00
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
switch( nodeRole )
|
|
|
|
{
|
|
|
|
case GrooveRole:
|
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
return updateBoxNode( skinnable, node, QskProgressBar::Groove );
|
2020-07-31 16:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case ValueFillRole:
|
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
const auto bar = static_cast< const QskProgressBar* >( skinnable );
|
2020-07-31 16:57:22 +02:00
|
|
|
return updateFillNode( bar, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QSGNode* QskProgressBarSkinlet::updateFillNode(
|
|
|
|
const QskProgressBar* bar, QSGNode* node ) const
|
2020-07-31 16:57:22 +02:00
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
const auto subControl = QskProgressBar::ValueFill;
|
2020-07-31 16:57:22 +02:00
|
|
|
|
|
|
|
const auto rect = bar->subControlRect( subControl );
|
|
|
|
if ( rect.isEmpty() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto gradient = bar->gradientHint( subControl );
|
|
|
|
if ( !gradient.isVisible() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
gradient.setOrientation( bar->orientation() );
|
|
|
|
|
|
|
|
if ( !gradient.isMonochrome() )
|
|
|
|
{
|
|
|
|
qreal pos1 = bar->valueAsRatio( bar->origin() );
|
|
|
|
qreal pos2 = bar->valueAsRatio( bar->value() );
|
|
|
|
|
|
|
|
if ( pos2 < pos1 )
|
|
|
|
std::swap( pos1, pos2 );
|
|
|
|
|
|
|
|
gradient = gradient.extracted( pos1, pos2 );
|
|
|
|
|
|
|
|
if ( bar->orientation() == Qt::Vertical )
|
|
|
|
gradient.reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return updateBoxNode( bar, node, rect, gradient, subControl );
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
QRectF QskProgressBarSkinlet::fillRect( const QskProgressBar* bar ) const
|
2020-07-31 16:57:22 +02:00
|
|
|
{
|
2020-08-01 17:51:45 +02:00
|
|
|
auto rect = bar->subControlRect( QskProgressBar::Groove );
|
|
|
|
rect = bar->innerBox( QskProgressBar::Groove, rect );
|
2020-07-31 16:57:22 +02:00
|
|
|
|
|
|
|
auto pos1 = bar->valueAsRatio( bar->origin() );
|
|
|
|
auto pos2 = bar->valueAsRatio( bar->value() );
|
|
|
|
|
|
|
|
if ( pos1 > pos2 )
|
|
|
|
std::swap( pos1, pos2 );
|
|
|
|
|
|
|
|
if( bar->orientation() == Qt::Horizontal )
|
|
|
|
{
|
|
|
|
const auto w = rect.width();
|
|
|
|
|
|
|
|
rect.setRight( rect.left() + pos2 * w );
|
|
|
|
rect.setLeft( rect.left() + pos1 * w );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto h = rect.height();
|
|
|
|
|
|
|
|
rect.setTop( rect.bottom() - h * pos2 );
|
|
|
|
rect.setBottom( rect.bottom() - h * pos1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:51:45 +02:00
|
|
|
#include "moc_QskProgressBarSkinlet.cpp"
|