[libcalamaresui] Remove *quit* button from ViewManager

- Mostly like the other buttons
- Also show/hide the button and set tooltip
This commit is contained in:
Adriaan de Groot 2020-04-02 13:44:49 +02:00
parent 0c71c7c23f
commit 91d0ba1007
3 changed files with 56 additions and 25 deletions

View File

@ -197,6 +197,13 @@ CalamaresWindow::getWidgetNavigation()
auto* quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), navigation ); auto* quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), navigation );
quit->setObjectName( "view-button-cancel" ); quit->setObjectName( "view-button-cancel" );
connect( quit, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::quit ); connect( quit, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::quit );
connect( m_viewManager, &Calamares::ViewManager::quitEnabledChanged, quit, &QPushButton::setEnabled );
connect( m_viewManager, &Calamares::ViewManager::quitLabelChanged, quit, &QPushButton::setText );
connect( m_viewManager, &Calamares::ViewManager::quitIconChanged, this, [=]( QString n ) {
setButtonIcon( quit, n );
} );
connect( m_viewManager, &Calamares::ViewManager::quitTooltipChanged, quit, &QPushButton::setToolTip );
connect( m_viewManager, &Calamares::ViewManager::quitVisibleChanged, quit, &QPushButton::setVisible );
bottomLayout->addWidget( quit ); bottomLayout->addWidget( quit );
} }

View File

@ -94,26 +94,12 @@ ViewManager::ViewManager( QObject* parent )
m_stack->setContentsMargins( 0, 0, 0, 0 ); m_stack->setContentsMargins( 0, 0, 0, 0 );
mainLayout->addWidget( m_stack ); mainLayout->addWidget( m_stack );
// Create buttons and sets an initial icon; the icons may change
m_quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), m_widget );
m_quit->setObjectName( "view-button-cancel" );
CALAMARES_RETRANSLATE_SLOT( &ViewManager::updateButtonLabels ) CALAMARES_RETRANSLATE_SLOT( &ViewManager::updateButtonLabels )
QBoxLayout* bottomLayout = new QHBoxLayout;
mainLayout->addLayout( bottomLayout );
bottomLayout->addStretch();
bottomLayout->addWidget( m_quit );
connect( m_quit, &QPushButton::clicked, this, &ViewManager::quit );
connect( JobQueue::instance(), &JobQueue::failed, this, &ViewManager::onInstallationFailed ); connect( JobQueue::instance(), &JobQueue::failed, this, &ViewManager::onInstallationFailed );
connect( JobQueue::instance(), &JobQueue::finished, this, &ViewManager::next ); connect( JobQueue::instance(), &JobQueue::finished, this, &ViewManager::next );
if ( Calamares::Settings::instance()->disableCancel() ) UPDATE_BUTTON_PROPERTY( quitVisible, !Calamares::Settings::instance()->disableCancel() )
{
m_quit->setVisible( false );
}
} }
@ -413,28 +399,31 @@ ViewManager::updateButtonLabels()
// Cancel button changes label at the end // Cancel button changes label at the end
if ( isAtVeryEnd( m_steps, m_currentStep ) ) if ( isAtVeryEnd( m_steps, m_currentStep ) )
{ {
m_quit->setText( tr( "&Done" ) ); UPDATE_BUTTON_PROPERTY( quitLabel, tr( "&Done" ) )
m_quit->setToolTip( quitOnCompleteTooltip ); UPDATE_BUTTON_PROPERTY( quitTooltip, quitOnCompleteTooltip )
m_quit->setVisible( true ); // At end, always visible and enabled. UPDATE_BUTTON_PROPERTY( quitVisible, true )
setButtonIcon( m_quit, "dialog-ok-apply" ); UPDATE_BUTTON_PROPERTY( quitIcon, "dialog-ok-apply" )
updateCancelEnabled( true ); updateCancelEnabled( true );
// FIXME
#if 0
if ( settings->quitAtEnd() ) if ( settings->quitAtEnd() )
{ {
m_quit->click(); m_quit->click();
} }
#endif
} }
else else
{ {
if ( settings->disableCancel() ) if ( settings->disableCancel() )
{ {
m_quit->setVisible( false ); // In case we went back from final UPDATE_BUTTON_PROPERTY( quitVisible, false )
} }
updateCancelEnabled( !settings->disableCancel() updateCancelEnabled( !settings->disableCancel()
&& !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) ); && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) );
m_quit->setText( tr( "&Cancel" ) ); UPDATE_BUTTON_PROPERTY( quitLabel, tr( "&Cancel" ) )
m_quit->setToolTip( cancelBeforeInstallationTooltip ); UPDATE_BUTTON_PROPERTY( quitTooltip, cancelBeforeInstallationTooltip )
setButtonIcon( m_quit, "dialog-cancel" ); UPDATE_BUTTON_PROPERTY( quitIcon, "dialog-cancel" )
} }
} }
@ -516,7 +505,7 @@ ViewManager::confirmCancelInstallation()
void void
ViewManager::updateCancelEnabled( bool enabled ) ViewManager::updateCancelEnabled( bool enabled )
{ {
m_quit->setEnabled( enabled ); UPDATE_BUTTON_PROPERTY( quitEnabled, enabled )
emit cancelEnabled( enabled ); emit cancelEnabled( enabled );
} }

View File

@ -47,6 +47,13 @@ class UIDLLEXPORT ViewManager : public QAbstractListModel
Q_PROPERTY( QString backLabel READ backLabel NOTIFY backLabelChanged FINAL ) Q_PROPERTY( QString backLabel READ backLabel NOTIFY backLabelChanged FINAL )
Q_PROPERTY( QString backIcon READ backIcon NOTIFY backIconChanged FINAL ) Q_PROPERTY( QString backIcon READ backIcon NOTIFY backIconChanged FINAL )
Q_PROPERTY( bool quitEnabled READ quitEnabled NOTIFY quitEnabledChanged FINAL )
Q_PROPERTY( QString quitLabel READ quitLabel NOTIFY quitLabelChanged FINAL )
Q_PROPERTY( QString quitIcon READ quitIcon NOTIFY quitIconChanged FINAL )
Q_PROPERTY( QString quitTooltip READ quitTooltip NOTIFY quitTooltipChanged FINAL )
Q_PROPERTY( bool quitVisible READ quitVisible NOTIFY quitVisibleChanged FINAL )
public: public:
/** /**
* @brief instance access to the ViewManager singleton. * @brief instance access to the ViewManager singleton.
@ -145,6 +152,23 @@ public Q_SLOTS:
* Asks for confirmation if necessary. Terminates the application. * Asks for confirmation if necessary. Terminates the application.
*/ */
void quit(); void quit();
bool quitEnabled() const
{
return m_quitEnabled; ///< Is the quit-button to be enabled
}
QString quitLabel() const
{
return m_quitLabel; ///< What should be displayed on the quit-button
}
QString quitIcon() const
{
return m_quitIcon; ///< Name of the icon to show
}
bool quitVisible() const
{
return m_quitVisible; ///< Should the quit-button be visible
}
QString quitTooltip() const { return m_quitTooltip; }
/** /**
* @brief onInstallationFailed displays an error message when a fatal failure * @brief onInstallationFailed displays an error message when a fatal failure
@ -173,6 +197,12 @@ signals:
void backLabelChanged( QString ) const; void backLabelChanged( QString ) const;
void backIconChanged( QString ) const; void backIconChanged( QString ) const;
void quitEnabledChanged( bool ) const;
void quitLabelChanged( QString ) const;
void quitIconChanged( QString ) const;
void quitVisibleChanged( bool ) const;
void quitTooltipChanged( QString ) const;
private: private:
explicit ViewManager( QObject* parent = nullptr ); explicit ViewManager( QObject* parent = nullptr );
virtual ~ViewManager() override; virtual ~ViewManager() override;
@ -188,7 +218,6 @@ private:
QWidget* m_widget; QWidget* m_widget;
QStackedWidget* m_stack; QStackedWidget* m_stack;
QPushButton* m_quit;
bool m_nextEnabled = false; bool m_nextEnabled = false;
QString m_nextLabel; QString m_nextLabel;
@ -198,6 +227,12 @@ private:
QString m_backLabel; QString m_backLabel;
QString m_backIcon; QString m_backIcon;
bool m_quitEnabled = false;
QString m_quitLabel;
QString m_quitIcon;
QString m_quitTooltip;
bool m_quitVisible = true;
public: public:
/** @section Model /** @section Model
* *