[welcome] Refactor lambdas to full slots

- This helps give meaningful names to code chunks
 - Gives clang-format something to work with
 - Reduces indentation depth

I think this is a bit of a code-style opinion issue: big complicated
lambdas doing UI things just don't seem like a good idea.
This commit is contained in:
Adriaan de Groot 2019-08-29 11:06:55 +02:00
parent fc5aa54cb2
commit 535bf01475
2 changed files with 65 additions and 50 deletions

View File

@ -73,61 +73,13 @@ WelcomePage::WelcomePage( QWidget* parent )
cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares()
<< *Calamares::Branding::VersionedName; << *Calamares::Branding::VersionedName;
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( retranslate(); )
QString message;
if ( Calamares::Settings::instance()->isSetupMode() )
{
message = Calamares::Branding::instance()->welcomeStyleCalamares()
? tr( "<h1>Welcome to the Calamares setup program for %1.</h1>" )
: tr( "<h1>Welcome to %1 setup.</h1>" );
}
else
{
message = Calamares::Branding::instance()->welcomeStyleCalamares()
? tr( "<h1>Welcome to the Calamares installer for %1.</h1>" )
: tr( "<h1>Welcome to the %1 installer.</h1>" );
}
ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) );
ui->retranslateUi( this );
ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) ); )
ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap(
CalamaresUtils::Information, CalamaresUtils::Information,
CalamaresUtils::Original, CalamaresUtils::Original,
2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) );
connect( ui->aboutButton, &QPushButton::clicked, this, [this] { connect( ui->aboutButton, &QPushButton::clicked, this, &WelcomePage::showAboutBox );
QString title
= Calamares::Settings::instance()->isSetupMode() ? tr( "About %1 setup" ) : tr( "About %1 installer" );
QMessageBox mb( QMessageBox::Information,
title.arg( CALAMARES_APPLICATION_NAME ),
tr( "<h1>%1</h1><br/>"
"<strong>%2<br/>"
"for %3</strong><br/><br/>"
"Copyright 2014-2017 Teo Mrnjavac &lt;teo@kde.org&gt;<br/>"
"Copyright 2017-2019 Adriaan de Groot &lt;groot@kde.org&gt;<br/>"
"Thanks to <a href=\"https://calamares.io/team/\">the Calamares team</a> "
"and the <a href=\"https://www.transifex.com/calamares/calamares/\">Calamares "
"translators team</a>.<br/><br/>"
"<a href=\"https://calamares.io/\">Calamares</a> "
"development is sponsored by <br/>"
"<a href=\"http://www.blue-systems.com/\">Blue Systems</a> - "
"Liberating Software." )
.arg( CALAMARES_APPLICATION_NAME )
.arg( CALAMARES_VERSION )
.arg( *Calamares::Branding::VersionedName ),
QMessageBox::Ok,
this );
mb.setIconPixmap( CalamaresUtils::defaultPixmap(
CalamaresUtils::Squid,
CalamaresUtils::Original,
QSize( CalamaresUtils::defaultFontHeight() * 6, CalamaresUtils::defaultFontHeight() * 6 ) ) );
QGridLayout* layout = reinterpret_cast< QGridLayout* >( mb.layout() );
if ( layout )
layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 );
mb.exec();
} );
int welcome_text_idx = ui->verticalLayout->indexOf( ui->mainText ); int welcome_text_idx = ui->verticalLayout->indexOf( ui->mainText );
ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget ); ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget );
@ -284,6 +236,65 @@ WelcomePage::setLanguageIcon( QPixmap i )
ui->languageIcon->setPixmap( i ); ui->languageIcon->setPixmap( i );
} }
void
WelcomePage::retranslate()
{
QString message;
if ( Calamares::Settings::instance()->isSetupMode() )
{
message = Calamares::Branding::instance()->welcomeStyleCalamares()
? tr( "<h1>Welcome to the Calamares setup program for %1.</h1>" )
: tr( "<h1>Welcome to %1 setup.</h1>" );
}
else
{
message = Calamares::Branding::instance()->welcomeStyleCalamares()
? tr( "<h1>Welcome to the Calamares installer for %1.</h1>" )
: tr( "<h1>Welcome to the %1 installer.</h1>" );
}
ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) );
ui->retranslateUi( this );
ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) );
}
void
WelcomePage::showAboutBox()
{
QString title
= Calamares::Settings::instance()->isSetupMode() ? tr( "About %1 setup" ) : tr( "About %1 installer" );
QMessageBox mb( QMessageBox::Information,
title.arg( CALAMARES_APPLICATION_NAME ),
tr( "<h1>%1</h1><br/>"
"<strong>%2<br/>"
"for %3</strong><br/><br/>"
"Copyright 2014-2017 Teo Mrnjavac &lt;teo@kde.org&gt;<br/>"
"Copyright 2017-2019 Adriaan de Groot &lt;groot@kde.org&gt;<br/>"
"Thanks to <a href=\"https://calamares.io/team/\">the Calamares team</a> "
"and the <a href=\"https://www.transifex.com/calamares/calamares/\">Calamares "
"translators team</a>.<br/><br/>"
"<a href=\"https://calamares.io/\">Calamares</a> "
"development is sponsored by <br/>"
"<a href=\"http://www.blue-systems.com/\">Blue Systems</a> - "
"Liberating Software." )
.arg( CALAMARES_APPLICATION_NAME )
.arg( CALAMARES_VERSION )
.arg( *Calamares::Branding::VersionedName ),
QMessageBox::Ok,
this );
mb.setIconPixmap( CalamaresUtils::defaultPixmap(
CalamaresUtils::Squid,
CalamaresUtils::Original,
QSize( CalamaresUtils::defaultFontHeight() * 6, CalamaresUtils::defaultFontHeight() * 6 ) ) );
QGridLayout* layout = reinterpret_cast< QGridLayout* >( mb.layout() );
if ( layout )
{
layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 );
}
mb.exec();
}
void void
LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const

View File

@ -58,6 +58,10 @@ public:
/// @brief Change the language from an external source. /// @brief Change the language from an external source.
void externallySelectedLanguage( int row ); void externallySelectedLanguage( int row );
public slots:
void retranslate();
void showAboutBox();
protected: protected:
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus