qskinny/src/nodes/QskArcRenderer.cpp

55 lines
1.6 KiB
C++
Raw Normal View History

/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "QskArcRenderer.h"
#include "QskArcMetrics.h"
#include "QskGradient.h"
#include "QskGradientDirection.h"
#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 )
{
2022-10-31 13:42:08 +00:00
bool isRadial = false;
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.linearDirection().isVertical();
2022-10-31 13:42:08 +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 )
{
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 );
2022-10-20 07:22:11 +00:00
brush = radial;
}
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 );
2022-10-20 07:22:11 +00:00
brush = conical;
}
2022-10-31 13:42:08 +00:00
painter->setRenderHint( QPainter::Antialiasing, true );
painter->setPen( QPen( brush, metrics.width(), Qt::SolidLine, Qt::FlatCap ) );
const int startAngle = qRound( metrics.startAngle() * 16 );
const int spanAngle = qRound( metrics.spanAngle() * 16 );
painter->drawArc( rect, startAngle, spanAngle );
}