2021-10-20 05:50:25 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskArcRenderer.h"
|
|
|
|
#include "QskArcMetrics.h"
|
2022-10-31 13:42:08 +00:00
|
|
|
#include "QskLinearGradient.h"
|
2021-10-20 05:50:25 +00:00
|
|
|
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qrect.h>
|
|
|
|
|
|
|
|
void QskArcRenderer::renderArc(const QRectF& rect,
|
2022-10-31 13:42:08 +00:00
|
|
|
const QskArcMetrics& metrics, const QskGradient& gradient, QPainter* painter )
|
2021-10-20 05:50:25 +00:00
|
|
|
{
|
2022-10-31 13:42:08 +00:00
|
|
|
bool isRadial = false;
|
2021-10-20 05:50:25 +00:00
|
|
|
|
2022-10-31 13:42:08 +00:00
|
|
|
if ( gradient.type() == QskGradient::Linear )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Horizontal is interpreted as conic ( in direction of the arc ),
|
|
|
|
while Vertical means radial ( inner to outer border )
|
|
|
|
*/
|
|
|
|
isRadial = gradient.asLinearGradient().isVertical();
|
|
|
|
}
|
2021-10-20 05:50:25 +00:00
|
|
|
|
|
|
|
QBrush brush;
|
|
|
|
|
2022-10-24 14:40:47 +00:00
|
|
|
const auto qStops = qskToQGradientStops( gradient.stops() );
|
|
|
|
|
2022-10-31 13:42:08 +00:00
|
|
|
if( isRadial )
|
2021-10-20 05:50:25 +00:00
|
|
|
{
|
2022-10-20 07:22:11 +00:00
|
|
|
QRadialGradient radial( rect.center(), qMin( rect.width(), rect.height() ) );
|
2022-10-24 14:40:47 +00:00
|
|
|
radial.setStops( qStops );
|
2021-10-20 05:50:25 +00:00
|
|
|
|
2022-10-20 07:22:11 +00:00
|
|
|
brush = radial;
|
2021-10-20 05:50:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-20 07:22:11 +00:00
|
|
|
QConicalGradient conical( rect.center(), metrics.startAngle() );
|
2022-10-24 14:40:47 +00:00
|
|
|
conical.setStops( qStops );
|
2021-10-20 05:50:25 +00:00
|
|
|
|
2022-10-20 07:22:11 +00:00
|
|
|
brush = conical;
|
2021-10-20 05:50:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 13:42:08 +00:00
|
|
|
painter->setRenderHint( QPainter::Antialiasing, true );
|
2021-10-20 05:50:25 +00:00
|
|
|
painter->setPen( QPen( brush, metrics.width(), Qt::SolidLine, Qt::FlatCap ) );
|
2021-12-02 16:15:41 +00:00
|
|
|
|
|
|
|
const int startAngle = qRound( metrics.startAngle() * 16 );
|
|
|
|
const int spanAngle = qRound( metrics.spanAngle() * 16 );
|
|
|
|
|
|
|
|
painter->drawArc( rect, startAngle, spanAngle );
|
2021-10-20 05:50:25 +00:00
|
|
|
}
|