From 39534325e68e8ccb5e0e5963eb751baf6e122a2c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jan 2020 13:39:27 +0100 Subject: [PATCH] [welcome] Re-use widget creation code - for the list, the code can be the same as for the dialog, only the predicate is different. - while here, implement retranslate() since there's no text on the list widgets otherwise. --- .../welcome/checker/ResultsListWidget.cpp | 41 ++++++++++--------- .../welcome/checker/ResultsListWidget.h | 3 ++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/modules/welcome/checker/ResultsListWidget.cpp b/src/modules/welcome/checker/ResultsListWidget.cpp index d7fdf5437..db28d079b 100644 --- a/src/modules/welcome/checker/ResultsListWidget.cpp +++ b/src/modules/welcome/checker/ResultsListWidget.cpp @@ -110,9 +110,9 @@ ResultsListDialog::ResultsListDialog( QWidget* parent, const Calamares::Requirem setLayout( mainLayout ); - CALAMARES_RETRANSLATE_SLOT( &ResultsListDialog::retranslate ) - connect( buttonBox, &QDialogButtonBox::clicked, this, &QDialog::close ); + + CALAMARES_RETRANSLATE_SLOT( &ResultsListDialog::retranslate ) retranslate(); // Do it now to fill in the texts } @@ -171,24 +171,7 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem const bool requirementsSatisfied = std::none_of( checkEntries.begin(), checkEntries.end(), isUnSatisfied ); const bool mandatorySatisfied = std::none_of( checkEntries.begin(), checkEntries.end(), isMandatoryAndUnSatisfied ); - for ( const auto& entry : checkEntries ) - { - if ( !entry.satisfied ) - { - ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory ); - CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); ) - entriesLayout->addWidget( ciw ); - ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); - ciw->setAutoFillBackground( true ); - QPalette pal( ciw->palette() ); - QColor bgColor = pal.window().color(); - int bgHue = ( entry.satisfied ) ? bgColor.hue() : ( entry.mandatory ) ? 0 : 60; - bgColor.setHsv( bgHue, 64, bgColor.value() ); - pal.setColor( QPalette::Window, bgColor ); - ciw->setPalette( pal ); - } - } - + createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, isUnSatisfied ); if ( !requirementsSatisfied ) { @@ -258,6 +241,9 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem { mainLayout->addStretch(); } + + CALAMARES_RETRANSLATE_SLOT( &ResultsListWidget::retranslate ) + retranslate(); } @@ -271,3 +257,18 @@ ResultsListWidget::linkClicked( const QString& link ) dialog->deleteLater(); } } + +void +ResultsListWidget::retranslate() +{ + int i = 0; + for ( const auto& entry : m_entries ) + { + if ( entry.satisfied ) + { + continue; + } + m_resultWidgets[ i ]->setText( entry.negatedText() ); + i++; + } +} diff --git a/src/modules/welcome/checker/ResultsListWidget.h b/src/modules/welcome/checker/ResultsListWidget.h index 62f2d1a17..357ad88c2 100644 --- a/src/modules/welcome/checker/ResultsListWidget.h +++ b/src/modules/welcome/checker/ResultsListWidget.h @@ -20,6 +20,8 @@ #ifndef CHECKER_RESULTSLISTWIDGET_H #define CHECKER_RESULTSLISTWIDGET_H +#include "ResultWidget.h" + #include "modulesystem/Requirement.h" #include @@ -39,6 +41,7 @@ private: QLabel* m_explanation = nullptr; ///< Explanatory text above the list, with link const Calamares::RequirementsList& m_entries; + QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry }; #endif // CHECKER_RESULTSLISTWIDGET_H