[libcalamaresui] Remove *next* button from ViewManager

- add properties for the next button (enabled, label, icon...)
- update those properties as normal
- connect to the properties in the UI implementation
This commit is contained in:
Adriaan de Groot 2020-04-02 12:04:24 +02:00
parent c638343c18
commit 8920be6bca
3 changed files with 56 additions and 14 deletions

View file

@ -150,6 +150,16 @@ getButtonIcon( const QString& name )
return Calamares::Branding::instance()->image( name, QSize( 22, 22 ) );
}
static inline void
setButtonIcon( QPushButton* button, const QString& name )
{
auto icon = getButtonIcon( name );
if ( button && !icon.isNull() )
{
button->setIcon( icon );
}
}
QWidget*
CalamaresWindow::getWidgetNavigation()
{
@ -162,6 +172,10 @@ CalamaresWindow::getWidgetNavigation()
auto* next = new QPushButton( getButtonIcon( QStringLiteral( "go-next" ) ), tr( "&Next" ), navigation );
next->setObjectName( "view-button-next" );
connect( next, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::next );
connect( m_viewManager, &Calamares::ViewManager::nextEnabledChanged, next, &QPushButton::setEnabled );
connect( m_viewManager, &Calamares::ViewManager::nextLabelChanged, next, &QPushButton::setText );
connect(
m_viewManager, &Calamares::ViewManager::nextIconChanged, this, [=]( QString n ) { setButtonIcon( next, n ); } );
auto* quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), navigation );
quit->setObjectName( "view-button-cancel" );
connect( quit, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::quit );

View file

@ -91,8 +91,6 @@ ViewManager::ViewManager( QObject* parent )
// Create buttons and sets an initial icon; the icons may change
m_back = new QPushButton( getButtonIcon( QStringLiteral( "go-previous" ) ), tr( "&Back" ), m_widget );
m_back->setObjectName( "view-button-back" );
m_next = new QPushButton( getButtonIcon( QStringLiteral( "go-next" ) ), tr( "&Next" ), m_widget );
m_next->setObjectName( "view-button-next" );
m_quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), m_widget );
m_quit->setObjectName( "view-button-cancel" );
@ -102,11 +100,9 @@ ViewManager::ViewManager( QObject* parent )
mainLayout->addLayout( bottomLayout );
bottomLayout->addStretch();
bottomLayout->addWidget( m_back );
bottomLayout->addWidget( m_next );
bottomLayout->addSpacing( 12 );
bottomLayout->addWidget( m_quit );
connect( m_next, &QPushButton::clicked, this, &ViewManager::next );
connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
connect( m_quit, &QPushButton::clicked, this, &ViewManager::quit );
m_back->setEnabled( false );
@ -142,7 +138,8 @@ ViewManager::addViewStep( ViewStep* step )
// If this is the first inserted view step, update status of "Next" button
if ( m_steps.count() == 1 )
{
m_next->setEnabled( step->isNextEnabled() );
m_nextEnabled = step->isNextEnabled();
emit nextEnabledChanged( m_nextEnabled );
}
}
@ -153,13 +150,15 @@ ViewManager::insertViewStep( int before, ViewStep* step )
emit beginInsertRows( QModelIndex(), before, before );
m_steps.insert( before, step );
connect( step, &ViewStep::enlarge, this, &ViewManager::enlarge );
// TODO: this can be a regular slot
connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) {
ViewStep* vs = qobject_cast< ViewStep* >( sender() );
if ( vs )
{
if ( vs == m_steps.at( m_currentStep ) )
{
m_next->setEnabled( status );
m_nextEnabled = status;
emit nextEnabledChanged( m_nextEnabled );
}
}
} );
@ -364,7 +363,8 @@ ViewManager::next()
{
// Reached the end in a weird state (e.g. no finished step after an exec)
executing = false;
m_next->setEnabled( false );
m_nextEnabled = false;
emit nextEnabledChanged( m_nextEnabled );
m_back->setEnabled( false );
}
updateCancelEnabled( !settings->disableCancel() && !( executing && settings->disableCancelDuringExec() ) );
@ -376,7 +376,8 @@ ViewManager::next()
if ( m_currentStep < m_steps.count() )
{
m_next->setEnabled( !executing && m_steps.at( m_currentStep )->isNextEnabled() );
m_nextEnabled = !executing && m_steps.at( m_currentStep )->isNextEnabled();
emit nextEnabledChanged( m_nextEnabled );
m_back->setEnabled( !executing && m_steps.at( m_currentStep )->isBackEnabled() );
}
@ -399,13 +400,17 @@ ViewManager::updateButtonLabels()
// If we're going into the execution step / install phase, other message
if ( stepIsExecute( m_steps, m_currentStep + 1 ) )
{
m_next->setText( nextIsInstallationStep );
setButtonIcon( m_next, "run-install" );
m_nextLabel = nextIsInstallationStep;
m_nextIcon = "run-install";
emit nextLabelChanged( m_nextLabel );
emit nextIconChanged( m_nextIcon );
}
else
{
m_next->setText( tr( "&Next" ) );
setButtonIcon( m_next, "go-next" );
m_nextLabel = tr( "&Next" );
m_nextIcon = "go-next";
emit nextLabelChanged( m_nextLabel );
emit nextIconChanged( m_nextIcon );
}
// Going back is always simple
@ -460,7 +465,8 @@ ViewManager::back()
return;
}
m_next->setEnabled( m_steps.at( m_currentStep )->isNextEnabled() );
m_nextEnabled = m_steps.at( m_currentStep )->isNextEnabled();
emit nextEnabledChanged( m_nextEnabled );
m_back->setEnabled( m_steps.at( m_currentStep )->isBackEnabled() );
if ( m_currentStep == 0 && m_steps.first()->isAtBeginning() )

View file

@ -38,6 +38,9 @@ class UIDLLEXPORT ViewManager : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY( int currentStepIndex READ currentStepIndex NOTIFY currentStepChanged FINAL )
Q_PROPERTY( bool nextEnabled READ nextEnabled NOTIFY nextEnabledChanged FINAL )
Q_PROPERTY( QString nextLabel READ nextLabel NOTIFY nextLabelChanged FINAL )
Q_PROPERTY( QString nextIcon READ nextIcon NOTIFY nextIconChanged FINAL )
public:
/**
@ -99,6 +102,18 @@ public Q_SLOTS:
* have any more pages.
*/
void next();
bool nextEnabled() const
{
return m_nextEnabled; ///< Is the next-button to be enabled
}
QString nextLabel() const
{
return m_nextLabel; ///< What should be displayed on the next-button
}
QString nextIcon() const
{
return m_nextIcon; ///< Name of the icon to show
}
/**
* @brief back moves backward to the previous page of the current ViewStep (if any),
@ -133,6 +148,10 @@ signals:
void enlarge( QSize enlarge ) const; // See ViewStep::enlarge()
void cancelEnabled( bool enabled ) const;
void nextEnabledChanged( bool ) const;
void nextLabelChanged( QString ) const;
void nextIconChanged( QString ) const;
private:
explicit ViewManager( QObject* parent = nullptr );
virtual ~ViewManager() override;
@ -149,9 +168,12 @@ private:
QWidget* m_widget;
QStackedWidget* m_stack;
QPushButton* m_back;
QPushButton* m_next;
QPushButton* m_quit;
bool m_nextEnabled = false;
QString m_nextLabel;
QString m_nextIcon; ///< Name of icon to show on button
public:
/** @section Model
*