[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 "WaitingWidget.h"
|
||||||
|
|
||||||
#include "utils/Gui.h"
|
#include "utils/Gui.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QTimer>
|
#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 )
|
WaitingWidget::WaitingWidget( const QString& text, QWidget* parent )
|
||||||
: WaitingSpinnerWidget( parent, false, false )
|
: WaitingSpinnerWidget( parent, false, false )
|
||||||
{
|
{
|
||||||
int spnrSize = Calamares::defaultFontHeight() * 4;
|
int spnrSize = Calamares::defaultFontHeight() * 4;
|
||||||
setFixedSize( spnrSize, spnrSize );
|
styleSpinner( this, spnrSize );
|
||||||
setInnerRadius( spnrSize / 2 );
|
|
||||||
setLineLength( spnrSize / 2 );
|
|
||||||
setLineWidth( spnrSize / 8 );
|
|
||||||
setAlignment( Qt::AlignmentFlag::AlignBottom );
|
setAlignment( Qt::AlignmentFlag::AlignBottom );
|
||||||
setText( text );
|
setText( text );
|
||||||
start();
|
start();
|
||||||
@ -31,6 +49,16 @@ WaitingWidget::WaitingWidget( const QString& text, QWidget* parent )
|
|||||||
|
|
||||||
WaitingWidget::~WaitingWidget() {}
|
WaitingWidget::~WaitingWidget() {}
|
||||||
|
|
||||||
|
void
|
||||||
|
WaitingWidget::changeEvent( QEvent* event )
|
||||||
|
{
|
||||||
|
if ( event->type() == QEvent::PaletteChange )
|
||||||
|
{
|
||||||
|
colorSpinner( this );
|
||||||
|
}
|
||||||
|
WaitingSpinnerWidget::changeEvent( event );
|
||||||
|
}
|
||||||
|
|
||||||
struct CountdownWaitingWidget::Private
|
struct CountdownWaitingWidget::Private
|
||||||
{
|
{
|
||||||
std::chrono::seconds duration;
|
std::chrono::seconds duration;
|
||||||
@ -52,13 +80,8 @@ CountdownWaitingWidget::CountdownWaitingWidget( std::chrono::seconds duration, Q
|
|||||||
{
|
{
|
||||||
// Set up the label first for sizing
|
// Set up the label first for sizing
|
||||||
const int labelHeight = qBound( 16, Calamares::defaultFontHeight() * 3 / 2, 64 );
|
const int labelHeight = qBound( 16, Calamares::defaultFontHeight() * 3 / 2, 64 );
|
||||||
|
styleSpinner( this, labelHeight );
|
||||||
// Set up the spinner
|
|
||||||
setFixedSize( labelHeight, labelHeight );
|
|
||||||
setRevolutionsPerSecond( 1.0 / double( duration.count() ) );
|
setRevolutionsPerSecond( 1.0 / double( duration.count() ) );
|
||||||
setInnerRadius( labelHeight / 2 );
|
|
||||||
setLineLength( labelHeight / 2 );
|
|
||||||
setLineWidth( labelHeight / 8 );
|
|
||||||
setAlignment( Qt::AlignmentFlag::AlignVCenter );
|
setAlignment( Qt::AlignmentFlag::AlignVCenter );
|
||||||
|
|
||||||
// Last because it updates the text
|
// Last because it updates the text
|
||||||
@ -117,3 +140,13 @@ CountdownWaitingWidget::tick()
|
|||||||
timeout();
|
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.
|
/// 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;
|
~WaitingWidget() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent( QEvent* event ) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief A spinner and a countdown inside it
|
/** @brief A spinner and a countdown inside it
|
||||||
@ -64,6 +67,9 @@ Q_SIGNALS:
|
|||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent( QEvent* event ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Private;
|
struct Private;
|
||||||
std::unique_ptr< Private > d;
|
std::unique_ptr< Private > d;
|
||||||
|
Loading…
Reference in New Issue
Block a user