[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.
This commit is contained in:
Adriaan de Groot 2020-01-28 13:39:27 +01:00
parent 38d58e5b16
commit 39534325e6
2 changed files with 24 additions and 20 deletions

View File

@ -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++;
}
}

View File

@ -20,6 +20,8 @@
#ifndef CHECKER_RESULTSLISTWIDGET_H
#define CHECKER_RESULTSLISTWIDGET_H
#include "ResultWidget.h"
#include "modulesystem/Requirement.h"
#include <QWidget>
@ -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