[libcalamaresui] Adjust waiting widget to style
This follows Dark / Light mode, but also adjusts the spinner when the style is changed while Calamares is running.
This commit is contained in:
parent
b0fc0a0a4d
commit
032fca834e
@ -11,19 +11,37 @@
|
||||
#include "WaitingWidget.h"
|
||||
|
||||
#include "utils/Gui.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
|
||||
static void
|
||||
colorSpinner( WaitingSpinnerWidget* spinner )
|
||||
{
|
||||
const auto color = spinner->palette().text().color();
|
||||
spinner->setTextColor( color );
|
||||
spinner->setColor( color );
|
||||
}
|
||||
|
||||
static void
|
||||
styleSpinner( WaitingSpinnerWidget* spinner, int size )
|
||||
{
|
||||
spinner->setFixedSize( size, size );
|
||||
spinner->setInnerRadius( size / 2 );
|
||||
spinner->setLineLength( size / 2 );
|
||||
spinner->setLineWidth( size / 8 );
|
||||
colorSpinner( spinner );
|
||||
}
|
||||
|
||||
|
||||
WaitingWidget::WaitingWidget( const QString& text, QWidget* parent )
|
||||
: WaitingSpinnerWidget( parent, false, false )
|
||||
{
|
||||
int spnrSize = Calamares::defaultFontHeight() * 4;
|
||||
setFixedSize( spnrSize, spnrSize );
|
||||
setInnerRadius( spnrSize / 2 );
|
||||
setLineLength( spnrSize / 2 );
|
||||
setLineWidth( spnrSize / 8 );
|
||||
styleSpinner( this, spnrSize );
|
||||
setAlignment( Qt::AlignmentFlag::AlignBottom );
|
||||
setText( text );
|
||||
start();
|
||||
@ -31,6 +49,16 @@ WaitingWidget::WaitingWidget( const QString& text, QWidget* parent )
|
||||
|
||||
WaitingWidget::~WaitingWidget() {}
|
||||
|
||||
void
|
||||
WaitingWidget::changeEvent( QEvent* event )
|
||||
{
|
||||
if ( event->type() == QEvent::PaletteChange )
|
||||
{
|
||||
colorSpinner( this );
|
||||
}
|
||||
WaitingSpinnerWidget::changeEvent( event );
|
||||
}
|
||||
|
||||
struct CountdownWaitingWidget::Private
|
||||
{
|
||||
std::chrono::seconds duration;
|
||||
@ -52,13 +80,8 @@ CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, Q
|
||||
{
|
||||
// Set up the label first for sizing
|
||||
const int labelHeight = qBound( 16, Calamares::defaultFontHeight() * 3 / 2, 64 );
|
||||
|
||||
// Set up the spinner
|
||||
setFixedSize( labelHeight, labelHeight );
|
||||
styleSpinner( this, 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
|
||||
@ -117,3 +140,13 @@ CountdownWaitingWidget::tick()
|
||||
timeout();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CountdownWaitingWidget::changeEvent( QEvent* event )
|
||||
{
|
||||
if ( event->type() == QEvent::PaletteChange )
|
||||
{
|
||||
colorSpinner( this );
|
||||
}
|
||||
WaitingSpinnerWidget::changeEvent( event );
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ public:
|
||||
/// Create a WaitingWidget with initial @p text label.
|
||||
explicit WaitingWidget( const QString& text, QWidget* parent = nullptr );
|
||||
~WaitingWidget() override;
|
||||
|
||||
protected:
|
||||
void changeEvent( QEvent* event ) override;
|
||||
};
|
||||
|
||||
/** @brief A spinner and a countdown inside it
|
||||
@ -64,6 +67,9 @@ Q_SIGNALS:
|
||||
protected Q_SLOTS:
|
||||
void tick();
|
||||
|
||||
protected:
|
||||
void changeEvent( QEvent* event ) override;
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
std::unique_ptr< Private > d;
|
||||
|
Loading…
Reference in New Issue
Block a user