From 780fe125f7c1f9b5c6c46bc24e1cadc179acb3c6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 18 Jun 2019 16:18:18 +0200 Subject: [PATCH 1/3] [libcalamaresui] Give the buttons icons - Next, Back, Cancel/Quit have somewhat-appropriate icons. --- src/libcalamaresui/ViewManager.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 3a5d24feb..05cefb390 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -54,6 +54,28 @@ ViewManager::instance( QObject* parent ) return s_instance; } +/** @brief Creates a button with a given icon-name + * + * Creates a new button as child of @p parent. + * Sets the named icon, if it exists, onto the button. + * Returns the new button. + * + * There is a QPushButton constructor that takes an icon, + * but it also needs a text and we've got translations + * to worry about as well as state. + */ +static inline QPushButton* +makeButton( QWidget* parent, const QString& name ) +{ + QPushButton* button = new QPushButton( parent ); + auto icon = Calamares::Branding::instance()->image( name, QSize( 22, 22 ) ); + if ( button && !icon.isNull() ) + { + button->setIcon( icon ); + } + return button; +} + ViewManager::ViewManager( QObject* parent ) : QObject( parent ) , m_currentStep( 0 ) @@ -68,9 +90,10 @@ ViewManager::ViewManager( QObject* parent ) m_stack->setContentsMargins( 0, 0, 0, 0 ); mainLayout->addWidget( m_stack ); - m_back = new QPushButton( m_widget ); - m_next = new QPushButton( m_widget ); - m_quit = new QPushButton( m_widget ); + // Create buttons and sets an initial icon; the icons may change + m_back = makeButton( m_widget, "go-previous" ); + m_next = makeButton( m_widget, "go-next" ); + m_quit = makeButton( m_widget, "dialog-cancel" ); CALAMARES_RETRANSLATE( m_back->setText( tr( "&Back" ) ); From b3d9af4cae3356bc3c34cf8cf3a3d6491d882f74 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 18 Jun 2019 22:45:49 +0200 Subject: [PATCH 2/3] [libcalamaresui] Apply correct button labels - updateButtonLabels() knows all the special cases for buttons, so use it when the language changes instead of setting up some possibly-wrong values. - One edge case that this fixes is: have **just** the welcome page before the first exec section in sequence. Then the *next* button label was *next* instead of *install*. --- src/libcalamaresui/ViewManager.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 05cefb390..ad8892802 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -96,13 +96,7 @@ ViewManager::ViewManager( QObject* parent ) m_quit = makeButton( m_widget, "dialog-cancel" ); CALAMARES_RETRANSLATE( - m_back->setText( tr( "&Back" ) ); - m_next->setText( tr( "&Next" ) ); - m_quit->setText( tr( "&Cancel" ) ); - QString tooltip = Calamares::Settings::instance()->isSetupMode() - ? tr( "Cancel setup without changing the system." ) - : tr( "Cancel installation without changing the system." ); - m_quit->setToolTip( tooltip ); + updateButtonLabels(); ) QBoxLayout* bottomLayout = new QHBoxLayout; @@ -344,26 +338,30 @@ ViewManager::updateButtonLabels() { const auto* const settings = Calamares::Settings::instance(); - QString next = settings->isSetupMode() + QString nextIsInstallationStep = settings->isSetupMode() ? tr( "&Set up" ) : tr( "&Install" ); - QString complete = settings->isSetupMode() + QString quitOnCompleteTooltip = settings->isSetupMode() ? tr( "Setup is complete. Close the setup program." ) : tr( "The installation is complete. Close the installer." ); - QString quit = settings->isSetupMode() + QString cancelBeforeInstallationTooltip = settings->isSetupMode() ? tr( "Cancel setup without changing the system." ) : tr( "Cancel installation without changing the system." ); // If we're going into the execution step / install phase, other message if ( stepIsExecute( m_steps, m_currentStep+1 ) ) - m_next->setText( next ); + m_next->setText( nextIsInstallationStep ); else m_next->setText( tr( "&Next" ) ); + // Going back is always simple + m_back->setText( tr( "&Back" ) ); + + // Cancel button changes label at the end if ( isAtVeryEnd() ) { m_quit->setText( tr( "&Done" ) ); - m_quit->setToolTip( complete ); + m_quit->setToolTip( quitOnCompleteTooltip ); m_quit->setVisible( true ); // At end, always visible and enabled. updateCancelEnabled( true ); } @@ -374,7 +372,7 @@ ViewManager::updateButtonLabels() updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) ); m_quit->setText( tr( "&Cancel" ) ); - m_quit->setToolTip( quit ); + m_quit->setToolTip( cancelBeforeInstallationTooltip ); } } From 79dc9e34632e1055fd9c55262f472b48813d8e81 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 18 Jun 2019 22:54:41 +0200 Subject: [PATCH 3/3] [libcalamares] Update button icons as we go along - Adapt the button icons (previous, next, do-install, all-done) to the state of the buttons and the corresponding text. --- src/libcalamaresui/ViewManager.cpp | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index ad8892802..16c38b1bc 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -54,6 +54,23 @@ ViewManager::instance( QObject* parent ) return s_instance; } +/** @brief Get a button-sized icon. */ +static inline QPixmap +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 ); + } +} + /** @brief Creates a button with a given icon-name * * Creates a new button as child of @p parent. @@ -68,11 +85,7 @@ static inline QPushButton* makeButton( QWidget* parent, const QString& name ) { QPushButton* button = new QPushButton( parent ); - auto icon = Calamares::Branding::instance()->image( name, QSize( 22, 22 ) ); - if ( button && !icon.isNull() ) - { - button->setIcon( icon ); - } + setButtonIcon( button, name ); return button; } @@ -350,9 +363,15 @@ 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" ); + } else + { m_next->setText( tr( "&Next" ) ); + setButtonIcon( m_next, "go-next" ); + } // Going back is always simple m_back->setText( tr( "&Back" ) ); @@ -363,6 +382,7 @@ ViewManager::updateButtonLabels() m_quit->setText( tr( "&Done" ) ); m_quit->setToolTip( quitOnCompleteTooltip ); m_quit->setVisible( true ); // At end, always visible and enabled. + setButtonIcon( m_quit, "dialog-ok-apply" ); updateCancelEnabled( true ); } else @@ -373,6 +393,7 @@ ViewManager::updateButtonLabels() m_quit->setText( tr( "&Cancel" ) ); m_quit->setToolTip( cancelBeforeInstallationTooltip ); + setButtonIcon( m_quit, "dialog-cancel" ); } }