From 5aae736ced6383a8651b2818bcd5a173b9799a3f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jan 2020 12:53:19 +0100 Subject: [PATCH] [welcome] Create ResultWidget in separate method --- .../welcome/checker/ResultsListWidget.cpp | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/modules/welcome/checker/ResultsListWidget.cpp b/src/modules/welcome/checker/ResultsListWidget.cpp index 0c3079579..e06f4e7a7 100644 --- a/src/modules/welcome/checker/ResultsListWidget.cpp +++ b/src/modules/welcome/checker/ResultsListWidget.cpp @@ -34,6 +34,35 @@ #include #include +static void +createResultWidgets( QLayout* layout, + QList< ResultWidget* >& resultWidgets, + const Calamares::RequirementsList& checkEntries, + std::function< bool( const Calamares::RequirementEntry& ) > predicate ) +{ + for ( const auto& entry : checkEntries ) + { + if ( !predicate( entry ) ) + { + continue; + } + + ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory ); + layout->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 ); + + resultWidgets.append( ciw ); + } +} + /** @brief A "details" dialog for the results-list * * This displays the same RequirementsList as ResultsListWidget, @@ -69,27 +98,9 @@ ResultsListDialog::ResultsListDialog( QWidget* parent, const Calamares::Requirem m_title = new QLabel( this ); - for ( const auto& entry : checkEntries ) - { - if ( !entry.hasDetails() ) - { - continue; - } - - ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory ); - 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 ); - - m_resultWidgets.append( ciw ); - } + createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, []( const Calamares::RequirementEntry& e ) { + return e.hasDetails(); + } ); QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );