[libcalamaresui] Remove *back* button from ViewManager
- Now the back button should be done by clients as well - Refactor in CalamaresWindow to avoid leaking local button pointers to surrounding code. - Add macro UPDATE_BUTTON_PROPERTY for convenience in ViewManager (ugh, macro) to change a value and emit corresponding update signal.
This commit is contained in:
parent
8920be6bca
commit
38deb66e42
@ -164,28 +164,39 @@ QWidget*
|
|||||||
CalamaresWindow::getWidgetNavigation()
|
CalamaresWindow::getWidgetNavigation()
|
||||||
{
|
{
|
||||||
QWidget* navigation = new QWidget( this );
|
QWidget* navigation = new QWidget( this );
|
||||||
|
|
||||||
// Create buttons and sets an initial icon; the icons may change
|
|
||||||
auto* back = new QPushButton( getButtonIcon( QStringLiteral( "go-previous" ) ), tr( "&Back" ), navigation );
|
|
||||||
back->setObjectName( "view-button-back" );
|
|
||||||
connect( back, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::back );
|
|
||||||
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 );
|
|
||||||
|
|
||||||
QBoxLayout* bottomLayout = new QHBoxLayout;
|
QBoxLayout* bottomLayout = new QHBoxLayout;
|
||||||
bottomLayout->addStretch();
|
bottomLayout->addStretch();
|
||||||
bottomLayout->addWidget( back );
|
|
||||||
bottomLayout->addWidget( next );
|
// Create buttons and sets an initial icon; the icons may change
|
||||||
|
{
|
||||||
|
auto* back = new QPushButton( getButtonIcon( QStringLiteral( "go-previous" ) ), tr( "&Back" ), navigation );
|
||||||
|
back->setObjectName( "view-button-back" );
|
||||||
|
connect( back, &QPushButton::clicked, m_viewManager, &Calamares::ViewManager::back );
|
||||||
|
connect( m_viewManager, &Calamares::ViewManager::backEnabledChanged, back, &QPushButton::setEnabled );
|
||||||
|
connect( m_viewManager, &Calamares::ViewManager::backLabelChanged, back, &QPushButton::setText );
|
||||||
|
connect( m_viewManager, &Calamares::ViewManager::backIconChanged, this, [=]( QString n ) {
|
||||||
|
setButtonIcon( back, n );
|
||||||
|
} );
|
||||||
|
bottomLayout->addWidget( back );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
} );
|
||||||
|
bottomLayout->addWidget( next );
|
||||||
|
}
|
||||||
bottomLayout->addSpacing( 12 );
|
bottomLayout->addSpacing( 12 );
|
||||||
bottomLayout->addWidget( quit );
|
{
|
||||||
|
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 );
|
||||||
|
bottomLayout->addWidget( quit );
|
||||||
|
}
|
||||||
|
|
||||||
navigation->setLayout( bottomLayout );
|
navigation->setLayout( bottomLayout );
|
||||||
return navigation;
|
return navigation;
|
||||||
|
@ -38,6 +38,12 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
|
|
||||||
|
#define UPDATE_BUTTON_PROPERTY( name, value ) \
|
||||||
|
{ \
|
||||||
|
m_##name = value; \
|
||||||
|
emit name##Changed( m_##name ); \
|
||||||
|
}
|
||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -89,8 +95,6 @@ ViewManager::ViewManager( QObject* parent )
|
|||||||
mainLayout->addWidget( m_stack );
|
mainLayout->addWidget( m_stack );
|
||||||
|
|
||||||
// Create buttons and sets an initial icon; the icons may change
|
// 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_quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), m_widget );
|
m_quit = new QPushButton( getButtonIcon( QStringLiteral( "dialog-cancel" ) ), tr( "&Cancel" ), m_widget );
|
||||||
m_quit->setObjectName( "view-button-cancel" );
|
m_quit->setObjectName( "view-button-cancel" );
|
||||||
|
|
||||||
@ -99,13 +103,9 @@ ViewManager::ViewManager( QObject* parent )
|
|||||||
QBoxLayout* bottomLayout = new QHBoxLayout;
|
QBoxLayout* bottomLayout = new QHBoxLayout;
|
||||||
mainLayout->addLayout( bottomLayout );
|
mainLayout->addLayout( bottomLayout );
|
||||||
bottomLayout->addStretch();
|
bottomLayout->addStretch();
|
||||||
bottomLayout->addWidget( m_back );
|
|
||||||
bottomLayout->addSpacing( 12 );
|
|
||||||
bottomLayout->addWidget( m_quit );
|
bottomLayout->addWidget( m_quit );
|
||||||
|
|
||||||
connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
|
|
||||||
connect( m_quit, &QPushButton::clicked, this, &ViewManager::quit );
|
connect( m_quit, &QPushButton::clicked, this, &ViewManager::quit );
|
||||||
m_back->setEnabled( false );
|
|
||||||
|
|
||||||
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 );
|
||||||
@ -363,9 +363,8 @@ ViewManager::next()
|
|||||||
{
|
{
|
||||||
// Reached the end in a weird state (e.g. no finished step after an exec)
|
// Reached the end in a weird state (e.g. no finished step after an exec)
|
||||||
executing = false;
|
executing = false;
|
||||||
m_nextEnabled = false;
|
UPDATE_BUTTON_PROPERTY( nextEnabled, false )
|
||||||
emit nextEnabledChanged( m_nextEnabled );
|
UPDATE_BUTTON_PROPERTY( backEnabled, false )
|
||||||
m_back->setEnabled( false );
|
|
||||||
}
|
}
|
||||||
updateCancelEnabled( !settings->disableCancel() && !( executing && settings->disableCancelDuringExec() ) );
|
updateCancelEnabled( !settings->disableCancel() && !( executing && settings->disableCancelDuringExec() ) );
|
||||||
}
|
}
|
||||||
@ -376,9 +375,8 @@ ViewManager::next()
|
|||||||
|
|
||||||
if ( m_currentStep < m_steps.count() )
|
if ( m_currentStep < m_steps.count() )
|
||||||
{
|
{
|
||||||
m_nextEnabled = !executing && m_steps.at( m_currentStep )->isNextEnabled();
|
UPDATE_BUTTON_PROPERTY( nextEnabled, !executing && m_steps.at( m_currentStep )->isNextEnabled() )
|
||||||
emit nextEnabledChanged( m_nextEnabled );
|
UPDATE_BUTTON_PROPERTY( backEnabled, !executing && m_steps.at( m_currentStep )->isBackEnabled() )
|
||||||
m_back->setEnabled( !executing && m_steps.at( m_currentStep )->isBackEnabled() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateButtonLabels();
|
updateButtonLabels();
|
||||||
@ -400,21 +398,17 @@ ViewManager::updateButtonLabels()
|
|||||||
// If we're going into the execution step / install phase, other message
|
// If we're going into the execution step / install phase, other message
|
||||||
if ( stepIsExecute( m_steps, m_currentStep + 1 ) )
|
if ( stepIsExecute( m_steps, m_currentStep + 1 ) )
|
||||||
{
|
{
|
||||||
m_nextLabel = nextIsInstallationStep;
|
UPDATE_BUTTON_PROPERTY( nextLabel, nextIsInstallationStep )
|
||||||
m_nextIcon = "run-install";
|
UPDATE_BUTTON_PROPERTY( nextIcon, "run-install" )
|
||||||
emit nextLabelChanged( m_nextLabel );
|
|
||||||
emit nextIconChanged( m_nextIcon );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_nextLabel = tr( "&Next" );
|
UPDATE_BUTTON_PROPERTY( nextLabel, tr( "&Next" ) )
|
||||||
m_nextIcon = "go-next";
|
UPDATE_BUTTON_PROPERTY( nextIcon, "go-next" )
|
||||||
emit nextLabelChanged( m_nextLabel );
|
|
||||||
emit nextIconChanged( m_nextIcon );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Going back is always simple
|
// Going back is always simple
|
||||||
m_back->setText( tr( "&Back" ) );
|
UPDATE_BUTTON_PROPERTY( backLabel, tr( "&Back" ) )
|
||||||
|
|
||||||
// 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 ) )
|
||||||
@ -465,14 +459,11 @@ ViewManager::back()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nextEnabled = m_steps.at( m_currentStep )->isNextEnabled();
|
UPDATE_BUTTON_PROPERTY( nextEnabled, m_steps.at( m_currentStep )->isNextEnabled() )
|
||||||
emit nextEnabledChanged( m_nextEnabled );
|
UPDATE_BUTTON_PROPERTY( backEnabled,
|
||||||
m_back->setEnabled( m_steps.at( m_currentStep )->isBackEnabled() );
|
( m_currentStep == 0 && m_steps.first()->isAtBeginning() )
|
||||||
|
? false
|
||||||
if ( m_currentStep == 0 && m_steps.first()->isAtBeginning() )
|
: m_steps.at( m_currentStep )->isBackEnabled() )
|
||||||
{
|
|
||||||
m_back->setEnabled( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
updateButtonLabels();
|
updateButtonLabels();
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,15 @@ class UIDLLEXPORT ViewManager : public QAbstractListModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( int currentStepIndex READ currentStepIndex NOTIFY currentStepChanged FINAL )
|
Q_PROPERTY( int currentStepIndex READ currentStepIndex NOTIFY currentStepChanged FINAL )
|
||||||
|
|
||||||
Q_PROPERTY( bool nextEnabled READ nextEnabled NOTIFY nextEnabledChanged FINAL )
|
Q_PROPERTY( bool nextEnabled READ nextEnabled NOTIFY nextEnabledChanged FINAL )
|
||||||
Q_PROPERTY( QString nextLabel READ nextLabel NOTIFY nextLabelChanged FINAL )
|
Q_PROPERTY( QString nextLabel READ nextLabel NOTIFY nextLabelChanged FINAL )
|
||||||
Q_PROPERTY( QString nextIcon READ nextIcon NOTIFY nextIconChanged FINAL )
|
Q_PROPERTY( QString nextIcon READ nextIcon NOTIFY nextIconChanged FINAL )
|
||||||
|
|
||||||
|
Q_PROPERTY( bool backEnabled READ backEnabled NOTIFY backEnabledChanged FINAL )
|
||||||
|
Q_PROPERTY( QString backLabel READ backLabel NOTIFY backLabelChanged FINAL )
|
||||||
|
Q_PROPERTY( QString backIcon READ backIcon NOTIFY backIconChanged FINAL )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief instance access to the ViewManager singleton.
|
* @brief instance access to the ViewManager singleton.
|
||||||
@ -121,6 +126,18 @@ public Q_SLOTS:
|
|||||||
* have any pages before the current one.
|
* have any pages before the current one.
|
||||||
*/
|
*/
|
||||||
void back();
|
void back();
|
||||||
|
bool backEnabled() const
|
||||||
|
{
|
||||||
|
return m_backEnabled; ///< Is the back-button to be enabled
|
||||||
|
}
|
||||||
|
QString backLabel() const
|
||||||
|
{
|
||||||
|
return m_backLabel; ///< What should be displayed on the back-button
|
||||||
|
}
|
||||||
|
QString backIcon() const
|
||||||
|
{
|
||||||
|
return m_backIcon; ///< Name of the icon to show
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Probably quit
|
* @brief Probably quit
|
||||||
@ -152,6 +169,10 @@ signals:
|
|||||||
void nextLabelChanged( QString ) const;
|
void nextLabelChanged( QString ) const;
|
||||||
void nextIconChanged( QString ) const;
|
void nextIconChanged( QString ) const;
|
||||||
|
|
||||||
|
void backEnabledChanged( bool ) const;
|
||||||
|
void backLabelChanged( QString ) const;
|
||||||
|
void backIconChanged( QString ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ViewManager( QObject* parent = nullptr );
|
explicit ViewManager( QObject* parent = nullptr );
|
||||||
virtual ~ViewManager() override;
|
virtual ~ViewManager() override;
|
||||||
@ -167,13 +188,16 @@ private:
|
|||||||
|
|
||||||
QWidget* m_widget;
|
QWidget* m_widget;
|
||||||
QStackedWidget* m_stack;
|
QStackedWidget* m_stack;
|
||||||
QPushButton* m_back;
|
|
||||||
QPushButton* m_quit;
|
QPushButton* m_quit;
|
||||||
|
|
||||||
bool m_nextEnabled = false;
|
bool m_nextEnabled = false;
|
||||||
QString m_nextLabel;
|
QString m_nextLabel;
|
||||||
QString m_nextIcon; ///< Name of icon to show on button
|
QString m_nextIcon; ///< Name of icon to show on button
|
||||||
|
|
||||||
|
bool m_backEnabled = false;
|
||||||
|
QString m_backLabel;
|
||||||
|
QString m_backIcon;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** @section Model
|
/** @section Model
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user