2023-04-06 09:23:37 +02:00
|
|
|
/******************************************************************************
|
2021-10-20 07:50:25 +02:00
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2021-10-20 07:50:25 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskArcNode.h"
|
|
|
|
#include "QskArcRenderer.h"
|
2023-04-12 12:19:26 +02:00
|
|
|
#include "QskArcMetrics.h"
|
2022-06-01 16:57:57 +02:00
|
|
|
#include "QskGradient.h"
|
2023-04-12 12:19:26 +02:00
|
|
|
#include "QskGradientDirection.h"
|
|
|
|
|
|
|
|
#include <qpainterpath.h>
|
2022-06-01 16:57:57 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
#define LINEAR_GRADIENT_HACK 1
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
#if LINEAR_GRADIENT_HACK
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
static inline QskGradient buildGradient( QskGradient::Type type,
|
|
|
|
const QRectF& rect, const QskArcMetrics& metrics,
|
|
|
|
const QskGradientStops& stops )
|
|
|
|
{
|
|
|
|
const auto center = rect.center();
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
QskGradient gradient;
|
|
|
|
gradient.setStretchMode( QskGradient::NoStretch );
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
if ( type == QskGradient::Conic )
|
|
|
|
{
|
|
|
|
gradient.setConicDirection(
|
|
|
|
center.x(), center.y(), metrics.startAngle() );
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
gradient.setStops( stops );
|
|
|
|
}
|
|
|
|
else
|
2022-06-01 16:57:57 +02:00
|
|
|
{
|
2023-04-14 09:47:10 +02:00
|
|
|
gradient.setRadialDirection( center.x(), center.y(),
|
2023-04-12 12:19:26 +02:00
|
|
|
rect.width(), rect.height() );
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Trying to do what QGradient::LogicalMode does in
|
|
|
|
the previous QPainter based implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
const auto radius = 0.5 * qMin( rect.width(), rect.height() );
|
|
|
|
const auto t = metrics.thickness() / radius;
|
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
QskGradientStops scaledStops;
|
|
|
|
scaledStops.reserve( stops.size() );
|
2023-04-12 12:19:26 +02:00
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
for ( const auto& stop : stops )
|
2023-04-12 12:19:26 +02:00
|
|
|
{
|
|
|
|
const auto pos = 0.5 - t * ( 0.75 - stop.position() );
|
2023-04-14 09:47:10 +02:00
|
|
|
scaledStops += QskGradientStop( pos, stop.color() );
|
2023-04-12 12:19:26 +02:00
|
|
|
}
|
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
gradient.setStops( scaledStops );
|
2023-04-12 12:19:26 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-14 09:47:10 +02:00
|
|
|
|
|
|
|
return gradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline QskGradient effectiveGradient( const QRectF& rect,
|
|
|
|
const QskArcMetrics& metrics, const QskGradient& gradient )
|
|
|
|
{
|
|
|
|
if ( !gradient.isMonochrome() )
|
2023-04-12 12:19:26 +02:00
|
|
|
{
|
2023-04-14 09:47:10 +02:00
|
|
|
if ( gradient.type() == QskGradient::Stops )
|
|
|
|
{
|
|
|
|
const QskConicDirection dir(
|
|
|
|
rect.center(), metrics.startAngle() );
|
|
|
|
#if 0
|
|
|
|
dir.setSpanAngle( metrics.spanAngle() ); // what is "expected" ??
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QskGradient g( gradient.stops() );
|
|
|
|
g.setStretchMode( QskGradient::NoStretch );
|
|
|
|
g.setConicDirection( dir );
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if LINEAR_GRADIENT_HACK
|
|
|
|
if ( gradient.type() == QskGradient::Linear )
|
|
|
|
{
|
|
|
|
// to keep the iotdashboard working: to be removed
|
|
|
|
|
|
|
|
const auto type = gradient.linearDirection().isHorizontal()
|
|
|
|
? QskGradient::Conic : QskGradient::Radial;
|
|
|
|
|
|
|
|
return buildGradient( type, rect, metrics, gradient.stops() );
|
|
|
|
}
|
|
|
|
#endif
|
2023-04-12 12:19:26 +02:00
|
|
|
}
|
|
|
|
|
2023-04-14 09:47:10 +02:00
|
|
|
return gradient;
|
2022-06-01 16:57:57 +02:00
|
|
|
}
|
2021-10-20 07:50:25 +02:00
|
|
|
|
|
|
|
QskArcNode::QskArcNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskArcNode::~QskArcNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-04-12 12:19:26 +02:00
|
|
|
void QskArcNode::setArcData( const QRectF& rect,
|
|
|
|
const QskArcMetrics& metrics, const QskGradient& gradient )
|
2021-10-20 07:50:25 +02:00
|
|
|
{
|
2023-04-12 12:19:26 +02:00
|
|
|
const auto path = QskArcRenderer::arcPath( rect, metrics );
|
2023-04-14 09:47:10 +02:00
|
|
|
|
|
|
|
updateNode( path, QTransform(), rect,
|
|
|
|
effectiveGradient( rect, metrics, gradient ) );
|
2021-10-20 07:50:25 +02:00
|
|
|
}
|