[libcalamaresui] The waiting spinner now supports text, no need for extra label

This commit is contained in:
Adriaan de Groot 2022-04-16 11:28:10 +02:00
parent 82d721f455
commit 3c5ac535f1
2 changed files with 15 additions and 47 deletions

View File

@ -12,50 +12,24 @@
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "3rdparty/waitingspinnerwidget.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QLabel> #include <QLabel>
#include <QTimer> #include <QTimer>
WaitingWidget::WaitingWidget( const QString& text, QWidget* parent ) WaitingWidget::WaitingWidget( const QString& text, QWidget* parent )
: QWidget( parent ) : WaitingSpinnerWidget( parent )
{ {
QBoxLayout* waitingLayout = new QVBoxLayout; int spnrSize = CalamaresUtils::defaultFontHeight() * 4;
setLayout( waitingLayout ); setFixedSize( spnrSize, spnrSize );
waitingLayout->addStretch(); setInnerRadius( spnrSize / 2 );
QBoxLayout* pbLayout = new QHBoxLayout; setLineLength( spnrSize / 2 );
waitingLayout->addLayout( pbLayout ); setLineWidth( spnrSize / 8 );
pbLayout->addStretch(); setAlignment( Qt::AlignmentFlag::AlignBottom );
setText( text );
WaitingSpinnerWidget* spnr = new WaitingSpinnerWidget(); start();
pbLayout->addWidget( spnr );
pbLayout->addStretch();
m_waitingLabel = new QLabel( text );
int spnrSize = m_waitingLabel->fontMetrics().height() * 4;
spnr->setFixedSize( spnrSize, spnrSize );
spnr->setInnerRadius( spnrSize / 2 );
spnr->setLineLength( spnrSize / 2 );
spnr->setLineWidth( spnrSize / 8 );
spnr->start();
m_waitingLabel->setAlignment( Qt::AlignCenter );
waitingLayout->addSpacing( spnrSize / 2 );
waitingLayout->addWidget( m_waitingLabel );
waitingLayout->addStretch();
CalamaresUtils::unmarginLayout( waitingLayout );
} }
WaitingWidget::~WaitingWidget() {}
void
WaitingWidget::setText( const QString& text )
{
m_waitingLabel->setText( text );
}
struct CountdownWaitingWidget::Private struct CountdownWaitingWidget::Private
{ {
@ -83,7 +57,7 @@ CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, Q
// Set up the spinner // Set up the spinner
d->spinner->setFixedSize( labelHeight, labelHeight ); d->spinner->setFixedSize( labelHeight, labelHeight );
d->spinner->setRevolutionsPerSecond( 1.0 / double(duration.count()) ); d->spinner->setRevolutionsPerSecond( 1.0 / double( duration.count() ) );
d->spinner->setInnerRadius( labelHeight / 2 ); d->spinner->setInnerRadius( labelHeight / 2 );
d->spinner->setLineLength( labelHeight / 2 ); d->spinner->setLineLength( labelHeight / 2 );
d->spinner->setLineWidth( labelHeight / 8 ); d->spinner->setLineWidth( labelHeight / 8 );
@ -143,7 +117,7 @@ CountdownWaitingWidget::tick()
{ {
d->count = int( d->duration.count() ); d->count = int( d->duration.count() );
} }
d->spinner->setText( QString::number(d->count) ); d->spinner->setText( QString::number( d->count ) );
if ( d->count == 0 ) if ( d->count == 0 )
{ {
timeout(); timeout();

View File

@ -10,7 +10,7 @@
#ifndef WAITINGWIDGET_H #ifndef WAITINGWIDGET_H
#define WAITINGWIDGET_H #define WAITINGWIDGET_H
#include <QWidget> #include "3rdparty/waitingspinnerwidget.h"
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -24,18 +24,12 @@ class QTimer;
* and the text is displayed centered below it. Use this * and the text is displayed centered below it. Use this
* to display a long-term waiting situation with a status report. * to display a long-term waiting situation with a status report.
*/ */
class WaitingWidget : public QWidget class WaitingWidget : public WaitingSpinnerWidget
{ {
Q_OBJECT
public: public:
/// Create a WaitingWidget with initial @p text label. /// Create a WaitingWidget with initial @p text label.
explicit WaitingWidget( const QString& text, QWidget* parent = nullptr ); explicit WaitingWidget( const QString& text, QWidget* parent = nullptr );
~WaitingWidget() override;
/// Update the @p text displayed in the label.
void setText( const QString& text );
private:
QLabel* m_waitingLabel;
}; };
/** @brief A spinner and a countdown next to it /** @brief A spinner and a countdown next to it