[libcalamaresui] Private static methods can be hidden

This commit is contained in:
Adriaan de Groot 2022-04-16 12:48:12 +02:00
parent 56c27c4255
commit 58306de28a
2 changed files with 37 additions and 45 deletions

View File

@ -45,6 +45,43 @@ isAlignCenter( Qt::AlignmentFlag a )
return a == Qt::AlignmentFlag::AlignVCenter; 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::WaitingSpinnerWidget( QWidget* parent, bool centerOnParent, bool disableParentWhenSpinning )
: WaitingSpinnerWidget( Qt::WindowModality::NonModal, parent, centerOnParent, 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 ); 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;
}

View File

@ -121,10 +121,6 @@ protected:
void paintEvent( QPaintEvent* paintEvent ) override; void paintEvent( QPaintEvent* paintEvent ) override;
private: 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 updateSize();
void updateTimer(); void updateTimer();
void updatePosition(); void updatePosition();