From 3bd610a8388deb4157d849685daf922c1c30c5ed Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 16 Apr 2022 11:53:03 +0200 Subject: [PATCH] [libcalamaresui] Port Countdown to spinner widget alone --- src/libcalamaresui/widgets/WaitingWidget.cpp | 26 ++++++++------------ src/libcalamaresui/widgets/WaitingWidget.h | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/libcalamaresui/widgets/WaitingWidget.cpp b/src/libcalamaresui/widgets/WaitingWidget.cpp index 13ae9fd03..118d219e4 100644 --- a/src/libcalamaresui/widgets/WaitingWidget.cpp +++ b/src/libcalamaresui/widgets/WaitingWidget.cpp @@ -37,35 +37,29 @@ struct CountdownWaitingWidget::Private // int because we count down, need to be able to show a 0, // and then wrap around to duration a second later. int count = 0; - WaitingSpinnerWidget* spinner = nullptr; QTimer* timer = nullptr; Private( std::chrono::seconds seconds, QWidget* parent ) : duration( seconds ) - , spinner( new WaitingSpinnerWidget( parent ) ) , timer( new QTimer( parent ) ) { } }; CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, QWidget* parent ) - : QWidget( parent ) + : WaitingSpinnerWidget( parent, false, false ) , d( std::make_unique< Private >( duration, this ) ) { // Set up the label first for sizing const int labelHeight = qBound( 16, CalamaresUtils::defaultFontHeight() * 3 / 2, 64 ); // Set up the spinner - d->spinner->setFixedSize( labelHeight, labelHeight ); - d->spinner->setRevolutionsPerSecond( 1.0 / double( duration.count() ) ); - d->spinner->setInnerRadius( labelHeight / 2 ); - d->spinner->setLineLength( labelHeight / 2 ); - d->spinner->setLineWidth( labelHeight / 8 ); - - // Overall UI layout - QBoxLayout* box = new QHBoxLayout; - box->addWidget( d->spinner ); - setLayout( box ); + setFixedSize( labelHeight, labelHeight ); + setRevolutionsPerSecond( 1.0 / double( duration.count() ) ); + setInnerRadius( labelHeight / 2 ); + setLineLength( labelHeight / 2 ); + setLineWidth( labelHeight / 8 ); + setAlignment( Qt::AlignmentFlag::AlignVCenter ); // Last because it updates the text setInterval( duration ); @@ -97,14 +91,14 @@ CountdownWaitingWidget::start() tick(); } d->timer->start(); - d->spinner->start(); + WaitingSpinnerWidget::start(); } void CountdownWaitingWidget::stop() { d->timer->stop(); - d->spinner->stop(); + WaitingSpinnerWidget::stop(); } void @@ -117,7 +111,7 @@ CountdownWaitingWidget::tick() { d->count = int( d->duration.count() ); } - d->spinner->setText( QString::number( d->count ) ); + setText( QString::number( d->count ) ); if ( d->count == 0 ) { timeout(); diff --git a/src/libcalamaresui/widgets/WaitingWidget.h b/src/libcalamaresui/widgets/WaitingWidget.h index cb0e15545..009f17f49 100644 --- a/src/libcalamaresui/widgets/WaitingWidget.h +++ b/src/libcalamaresui/widgets/WaitingWidget.h @@ -39,7 +39,7 @@ public: * every second. The signal timeout() is sent every time * the countdown reaches 0. */ -class CountdownWaitingWidget : public QWidget +class CountdownWaitingWidget : public WaitingSpinnerWidget { Q_OBJECT public: