[libcalamaresui] Port Countdown to spinner widget alone

This commit is contained in:
Adriaan de Groot 2022-04-16 11:53:03 +02:00
parent 5060a66d4e
commit 3bd610a838
2 changed files with 11 additions and 17 deletions

View File

@ -37,35 +37,29 @@ struct CountdownWaitingWidget::Private
// int because we count down, need to be able to show a 0, // int because we count down, need to be able to show a 0,
// and then wrap around to duration a second later. // and then wrap around to duration a second later.
int count = 0; int count = 0;
WaitingSpinnerWidget* spinner = nullptr;
QTimer* timer = nullptr; QTimer* timer = nullptr;
Private( std::chrono::seconds seconds, QWidget* parent ) Private( std::chrono::seconds seconds, QWidget* parent )
: duration( seconds ) : duration( seconds )
, spinner( new WaitingSpinnerWidget( parent ) )
, timer( new QTimer( parent ) ) , timer( new QTimer( parent ) )
{ {
} }
}; };
CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, QWidget* parent ) CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, QWidget* parent )
: QWidget( parent ) : WaitingSpinnerWidget( parent, false, false )
, d( std::make_unique< Private >( duration, this ) ) , d( std::make_unique< Private >( duration, this ) )
{ {
// Set up the label first for sizing // Set up the label first for sizing
const int labelHeight = qBound( 16, CalamaresUtils::defaultFontHeight() * 3 / 2, 64 ); const int labelHeight = qBound( 16, CalamaresUtils::defaultFontHeight() * 3 / 2, 64 );
// Set up the spinner // Set up the spinner
d->spinner->setFixedSize( labelHeight, labelHeight ); setFixedSize( labelHeight, labelHeight );
d->spinner->setRevolutionsPerSecond( 1.0 / double( duration.count() ) ); setRevolutionsPerSecond( 1.0 / double( duration.count() ) );
d->spinner->setInnerRadius( labelHeight / 2 ); setInnerRadius( labelHeight / 2 );
d->spinner->setLineLength( labelHeight / 2 ); setLineLength( labelHeight / 2 );
d->spinner->setLineWidth( labelHeight / 8 ); setLineWidth( labelHeight / 8 );
setAlignment( Qt::AlignmentFlag::AlignVCenter );
// Overall UI layout
QBoxLayout* box = new QHBoxLayout;
box->addWidget( d->spinner );
setLayout( box );
// Last because it updates the text // Last because it updates the text
setInterval( duration ); setInterval( duration );
@ -97,14 +91,14 @@ CountdownWaitingWidget::start()
tick(); tick();
} }
d->timer->start(); d->timer->start();
d->spinner->start(); WaitingSpinnerWidget::start();
} }
void void
CountdownWaitingWidget::stop() CountdownWaitingWidget::stop()
{ {
d->timer->stop(); d->timer->stop();
d->spinner->stop(); WaitingSpinnerWidget::stop();
} }
void void
@ -117,7 +111,7 @@ CountdownWaitingWidget::tick()
{ {
d->count = int( d->duration.count() ); d->count = int( d->duration.count() );
} }
d->spinner->setText( QString::number( d->count ) ); setText( QString::number( d->count ) );
if ( d->count == 0 ) if ( d->count == 0 )
{ {
timeout(); timeout();

View File

@ -39,7 +39,7 @@ public:
* every second. The signal timeout() is sent every time * every second. The signal timeout() is sent every time
* the countdown reaches 0. * the countdown reaches 0.
*/ */
class CountdownWaitingWidget : public QWidget class CountdownWaitingWidget : public WaitingSpinnerWidget
{ {
Q_OBJECT Q_OBJECT
public: public: