From 58306de28a78e6cf6c863558db21d0d9403467e9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 16 Apr 2022 12:48:12 +0200 Subject: [PATCH] [libcalamaresui] Private static methods can be hidden --- .../widgets/waitingspinnerwidget.cpp | 78 +++++++++---------- .../widgets/waitingspinnerwidget.h | 4 - 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/libcalamaresui/widgets/waitingspinnerwidget.cpp b/src/libcalamaresui/widgets/waitingspinnerwidget.cpp index 542d01a38..9d3577e78 100644 --- a/src/libcalamaresui/widgets/waitingspinnerwidget.cpp +++ b/src/libcalamaresui/widgets/waitingspinnerwidget.cpp @@ -45,6 +45,43 @@ isAlignCenter( Qt::AlignmentFlag a ) return a == Qt::AlignmentFlag::AlignVCenter; } +static int +lineCountDistanceFromPrimary( int current, int primary, int totalNrOfLines ) +{ + int distance = primary - current; + if ( distance < 0 ) + { + distance += totalNrOfLines; + } + return distance; +} + +static QColor +currentLineColor( int countDistance, int totalNrOfLines, qreal trailFadePerc, qreal minOpacity, QColor color ) +{ + if ( countDistance == 0 ) + { + return color; + } + const qreal minAlphaF = minOpacity / 100.0; + int distanceThreshold = static_cast< int >( ceil( ( totalNrOfLines - 1 ) * trailFadePerc / 100.0 ) ); + if ( countDistance > distanceThreshold ) + { + color.setAlphaF( minAlphaF ); + } + else + { + qreal alphaDiff = color.alphaF() - minAlphaF; + qreal gradient = alphaDiff / static_cast< qreal >( distanceThreshold + 1 ); + qreal resultAlpha = color.alphaF() - gradient * countDistance; + + // If alpha is out of bounds, clip it. + resultAlpha = std::min( 1.0, std::max( 0.0, resultAlpha ) ); + color.setAlphaF( resultAlpha ); + } + return color; +} + WaitingSpinnerWidget::WaitingSpinnerWidget( QWidget* parent, bool centerOnParent, bool disableParentWhenSpinning ) : WaitingSpinnerWidget( Qt::WindowModality::NonModal, parent, centerOnParent, disableParentWhenSpinning ) { @@ -356,44 +393,3 @@ WaitingSpinnerWidget::updatePosition() move( parentWidget()->width() / 2 - width() / 2, parentWidget()->height() / 2 - height() / 2 ); } } - -int -WaitingSpinnerWidget::lineCountDistanceFromPrimary( int current, int primary, int totalNrOfLines ) -{ - int distance = primary - current; - if ( distance < 0 ) - { - distance += totalNrOfLines; - } - return distance; -} - -QColor -WaitingSpinnerWidget::currentLineColor( int countDistance, - int totalNrOfLines, - qreal trailFadePerc, - qreal minOpacity, - QColor color ) -{ - if ( countDistance == 0 ) - { - return color; - } - const qreal minAlphaF = minOpacity / 100.0; - int distanceThreshold = static_cast< int >( ceil( ( totalNrOfLines - 1 ) * trailFadePerc / 100.0 ) ); - if ( countDistance > distanceThreshold ) - { - color.setAlphaF( minAlphaF ); - } - else - { - qreal alphaDiff = color.alphaF() - minAlphaF; - qreal gradient = alphaDiff / static_cast< qreal >( distanceThreshold + 1 ); - qreal resultAlpha = color.alphaF() - gradient * countDistance; - - // If alpha is out of bounds, clip it. - resultAlpha = std::min( 1.0, std::max( 0.0, resultAlpha ) ); - color.setAlphaF( resultAlpha ); - } - return color; -} diff --git a/src/libcalamaresui/widgets/waitingspinnerwidget.h b/src/libcalamaresui/widgets/waitingspinnerwidget.h index 2fe76b5b1..ce4a4cbff 100644 --- a/src/libcalamaresui/widgets/waitingspinnerwidget.h +++ b/src/libcalamaresui/widgets/waitingspinnerwidget.h @@ -121,10 +121,6 @@ protected: void paintEvent( QPaintEvent* paintEvent ) override; private: - static int lineCountDistanceFromPrimary( int current, int primary, int totalNrOfLines ); - static QColor - currentLineColor( int distance, int totalNrOfLines, qreal trailFadePerc, qreal minOpacity, QColor color ); - void updateSize(); void updateTimer(); void updatePosition();