2021-08-24 06:46:26 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2021 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "CircularProgressBarSkinlet.h"
|
|
|
|
#include "CircularProgressBar.h"
|
|
|
|
|
2021-10-11 12:44:40 +00:00
|
|
|
#include <QskArcNode.h>
|
2021-08-24 06:46:26 +00:00
|
|
|
#include <QskPaintedNode.h>
|
|
|
|
|
|
|
|
#include <QEasingCurve>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
CircularProgressBarSkinlet::CircularProgressBarSkinlet( QskSkin* skin )
|
|
|
|
: QskSkinlet( skin )
|
|
|
|
{
|
|
|
|
setNodeRoles( { GrooveRole, BarRole } );
|
|
|
|
}
|
|
|
|
|
|
|
|
CircularProgressBarSkinlet::~CircularProgressBarSkinlet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF CircularProgressBarSkinlet::subControlRect(
|
2021-08-24 12:38:03 +00:00
|
|
|
const QskSkinnable*, const QRectF& contentsRect, QskAspect::Subcontrol ) const
|
2021-08-24 06:46:26 +00:00
|
|
|
{
|
|
|
|
return contentsRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSGNode* CircularProgressBarSkinlet::updateSubNode(
|
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const auto bar = static_cast< const CircularProgressBar* >( skinnable );
|
|
|
|
|
|
|
|
switch( nodeRole )
|
|
|
|
{
|
|
|
|
case GrooveRole: // fall through
|
|
|
|
case BarRole:
|
|
|
|
{
|
|
|
|
return updateBarNode( bar, nodeRole, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
|
|
|
}
|
|
|
|
|
2021-08-24 12:38:03 +00:00
|
|
|
QSGNode* CircularProgressBarSkinlet::updateBarNode(
|
|
|
|
const CircularProgressBar* bar, quint8 nodeRole, QSGNode* node ) const
|
2021-08-24 06:46:26 +00:00
|
|
|
{
|
2021-10-11 12:44:40 +00:00
|
|
|
auto arcNode = static_cast< QskArcNode* >( node );
|
2021-08-24 06:46:26 +00:00
|
|
|
|
|
|
|
if( arcNode == nullptr )
|
|
|
|
{
|
2021-10-11 12:44:40 +00:00
|
|
|
arcNode = new QskArcNode();
|
2021-08-24 06:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto subControl = ( nodeRole == GrooveRole ) ? CircularProgressBar::Groove
|
|
|
|
: CircularProgressBar::Bar;
|
|
|
|
|
|
|
|
const QskGradient gradient = bar->gradientHint( subControl );
|
|
|
|
|
|
|
|
const QGradient::Type type = ( nodeRole == GrooveRole ) ?
|
|
|
|
QGradient::RadialGradient : QGradient::ConicalGradient;
|
|
|
|
|
|
|
|
const double width = bar->metric( subControl | QskAspect::Size );
|
|
|
|
const double value = ( nodeRole == GrooveRole ) ? bar->maximum() : bar->value();
|
2021-10-11 12:44:40 +00:00
|
|
|
const double position = bar->metric( CircularProgressBar::Bar | QskAspect::Position );
|
2021-08-24 06:46:26 +00:00
|
|
|
|
2021-10-11 12:44:40 +00:00
|
|
|
arcNode->setArcData( gradient, type, width, value, bar->origin(), bar->maximum(),
|
|
|
|
bar->isIndeterminate(), position );
|
2021-08-24 06:46:26 +00:00
|
|
|
|
|
|
|
QQuickWindow* window = bar->window();
|
|
|
|
const QRect rect = bar->contentsRect().toRect();
|
|
|
|
arcNode->update( window, QskTextureRenderer::AutoDetect, rect );
|
|
|
|
|
|
|
|
return arcNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_CircularProgressBarSkinlet.cpp"
|