[welcome] Don't duplicate result widgets
This commit is contained in:
parent
ee925492d4
commit
fc653adcc0
@ -110,10 +110,11 @@ ResultsListDialog::ResultsListDialog( const Calamares::RequirementsModel& model,
|
|||||||
m_title = new QLabel( this );
|
m_title = new QLabel( this );
|
||||||
m_title->setObjectName( "resultDialogTitle" );
|
m_title->setObjectName( "resultDialogTitle" );
|
||||||
|
|
||||||
createResultWidgets(
|
createResultWidgets( entriesLayout,
|
||||||
entriesLayout, m_resultWidgets, model, []( const Calamares::RequirementsModel& m, QModelIndex i ) {
|
m_resultWidgets,
|
||||||
return m.data( i, Calamares::RequirementsModel::HasDetails ).toBool();
|
model,
|
||||||
} );
|
[]( const Calamares::RequirementsModel& m, QModelIndex i )
|
||||||
|
{ return m.data( i, Calamares::RequirementsModel::HasDetails ).toBool(); } );
|
||||||
|
|
||||||
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );
|
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );
|
||||||
buttonBox->setObjectName( "resultDialogButtons" );
|
buttonBox->setObjectName( "resultDialogButtons" );
|
||||||
@ -154,75 +155,35 @@ ResultsListWidget::ResultsListWidget( Config* config, QWidget* parent )
|
|||||||
{
|
{
|
||||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||||
|
|
||||||
QBoxLayout* mainLayout = new QVBoxLayout;
|
m_mainLayout = new QVBoxLayout;
|
||||||
QBoxLayout* entriesLayout = new QVBoxLayout;
|
m_entriesLayout = new QVBoxLayout;
|
||||||
|
|
||||||
setLayout( mainLayout );
|
setLayout( m_mainLayout );
|
||||||
|
|
||||||
int paddingSize = qBound( 32, CalamaresUtils::defaultFontHeight() * 4, 128 );
|
int paddingSize = qBound( 32, CalamaresUtils::defaultFontHeight() * 4, 128 );
|
||||||
|
|
||||||
QHBoxLayout* spacerLayout = new QHBoxLayout;
|
QHBoxLayout* spacerLayout = new QHBoxLayout;
|
||||||
mainLayout->addLayout( spacerLayout );
|
m_mainLayout->addLayout( spacerLayout );
|
||||||
spacerLayout->addSpacing( paddingSize );
|
spacerLayout->addSpacing( paddingSize );
|
||||||
spacerLayout->addLayout( entriesLayout );
|
spacerLayout->addLayout( m_entriesLayout );
|
||||||
spacerLayout->addSpacing( paddingSize );
|
spacerLayout->addSpacing( paddingSize );
|
||||||
CalamaresUtils::unmarginLayout( spacerLayout );
|
CalamaresUtils::unmarginLayout( spacerLayout );
|
||||||
|
|
||||||
auto* explanation = new QLabel( m_config->warningMessage() );
|
m_explanation = new QLabel( m_config->warningMessage() );
|
||||||
explanation->setWordWrap( true );
|
m_explanation->setWordWrap( true );
|
||||||
explanation->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
m_explanation->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
||||||
explanation->setOpenExternalLinks( false );
|
m_explanation->setOpenExternalLinks( false );
|
||||||
explanation->setObjectName( "resultsExplanation" );
|
m_explanation->setObjectName( "resultsExplanation" );
|
||||||
entriesLayout->addWidget( explanation );
|
m_entriesLayout->addWidget( m_explanation );
|
||||||
|
|
||||||
connect( config, &Config::warningMessageChanged, explanation, &QLabel::setText );
|
requirementsChanged();
|
||||||
connect( explanation, &QLabel::linkActivated, this, &ResultsListWidget::linkClicked );
|
|
||||||
|
|
||||||
// Check that all are satisfied (gives warnings if not) and
|
connect( config, &Config::warningMessageChanged, m_explanation, &QLabel::setText );
|
||||||
// all *mandatory* entries are satisfied (gives errors if not).
|
connect( m_explanation, &QLabel::linkActivated, this, &ResultsListWidget::linkClicked );
|
||||||
|
connect( config->requirementsModel(),
|
||||||
const bool requirementsSatisfied = config->requirementsModel()->satisfiedRequirements();
|
&Calamares::RequirementsModel::modelReset,
|
||||||
auto isUnSatisfied = []( const Calamares::RequirementsModel& m, QModelIndex i ) {
|
this,
|
||||||
return !m.data( i, Calamares::RequirementsModel::Satisfied ).toBool();
|
&ResultsListWidget::requirementsChanged );
|
||||||
};
|
|
||||||
|
|
||||||
createResultWidgets( entriesLayout, m_resultWidgets, *( config->requirementsModel() ), isUnSatisfied );
|
|
||||||
|
|
||||||
if ( !requirementsSatisfied )
|
|
||||||
{
|
|
||||||
entriesLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() / 2 );
|
|
||||||
mainLayout->addStretch();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( !Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
|
|
||||||
{
|
|
||||||
QPixmap theImage
|
|
||||||
= QPixmap( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ) );
|
|
||||||
if ( !theImage.isNull() )
|
|
||||||
{
|
|
||||||
QLabel* imageLabel;
|
|
||||||
if ( Calamares::Branding::instance()->welcomeExpandingLogo() )
|
|
||||||
{
|
|
||||||
FixedAspectRatioLabel* p = new FixedAspectRatioLabel;
|
|
||||||
p->setPixmap( theImage );
|
|
||||||
imageLabel = p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
imageLabel = new QLabel;
|
|
||||||
imageLabel->setPixmap( theImage );
|
|
||||||
}
|
|
||||||
|
|
||||||
imageLabel->setContentsMargins( 4, CalamaresUtils::defaultFontHeight() * 3 / 4, 4, 4 );
|
|
||||||
imageLabel->setAlignment( Qt::AlignCenter );
|
|
||||||
imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
|
||||||
imageLabel->setObjectName( "welcomeLogo" );
|
|
||||||
mainLayout->addWidget( imageLabel );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
explanation->setAlignment( Qt::AlignCenter );
|
|
||||||
}
|
|
||||||
|
|
||||||
CALAMARES_RETRANSLATE_SLOT( &ResultsListWidget::retranslate );
|
CALAMARES_RETRANSLATE_SLOT( &ResultsListWidget::retranslate );
|
||||||
}
|
}
|
||||||
@ -253,6 +214,73 @@ ResultsListWidget::retranslate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ResultsListWidget::requirementsChanged()
|
||||||
|
{
|
||||||
|
if ( m_config->requirementsModel()->count() < m_requirementsSeen )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_requirementsSeen = m_config->requirementsModel()->count();
|
||||||
|
|
||||||
|
// Check that all are satisfied (gives warnings if not) and
|
||||||
|
// all *mandatory* entries are satisfied (gives errors if not).
|
||||||
|
|
||||||
|
const bool requirementsSatisfied = m_config->requirementsModel()->satisfiedRequirements();
|
||||||
|
auto isUnSatisfied = []( const Calamares::RequirementsModel& m, QModelIndex i )
|
||||||
|
{ return !m.data( i, Calamares::RequirementsModel::Satisfied ).toBool(); };
|
||||||
|
|
||||||
|
|
||||||
|
std::for_each( m_resultWidgets.begin(),
|
||||||
|
m_resultWidgets.end(),
|
||||||
|
[]( QWidget* w )
|
||||||
|
{
|
||||||
|
if ( w )
|
||||||
|
{
|
||||||
|
w->deleteLater();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
createResultWidgets( m_entriesLayout, m_resultWidgets, *( m_config->requirementsModel() ), isUnSatisfied );
|
||||||
|
|
||||||
|
if ( !requirementsSatisfied )
|
||||||
|
{
|
||||||
|
m_entriesLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() / 2 );
|
||||||
|
m_mainLayout->addStretch();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
|
||||||
|
{
|
||||||
|
QPixmap theImage
|
||||||
|
= QPixmap( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ) );
|
||||||
|
if ( !theImage.isNull() )
|
||||||
|
{
|
||||||
|
QLabel* imageLabel;
|
||||||
|
if ( Calamares::Branding::instance()->welcomeExpandingLogo() )
|
||||||
|
{
|
||||||
|
FixedAspectRatioLabel* p = new FixedAspectRatioLabel;
|
||||||
|
p->setPixmap( theImage );
|
||||||
|
imageLabel = p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imageLabel = new QLabel;
|
||||||
|
imageLabel->setPixmap( theImage );
|
||||||
|
}
|
||||||
|
|
||||||
|
imageLabel->setContentsMargins( 4, CalamaresUtils::defaultFontHeight() * 3 / 4, 4, 4 );
|
||||||
|
imageLabel->setAlignment( Qt::AlignCenter );
|
||||||
|
imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||||
|
imageLabel->setObjectName( "welcomeLogo" );
|
||||||
|
m_mainLayout->addWidget( imageLabel );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_explanation->setAlignment( Qt::AlignCenter );
|
||||||
|
}
|
||||||
|
|
||||||
|
retranslate();
|
||||||
|
}
|
||||||
|
|
||||||
#include "utils/moc-warnings.h"
|
#include "utils/moc-warnings.h"
|
||||||
|
|
||||||
#include "ResultsListWidget.moc"
|
#include "ResultsListWidget.moc"
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QBoxLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class ResultsListWidget : public QWidget
|
class ResultsListWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -27,10 +28,23 @@ public:
|
|||||||
private:
|
private:
|
||||||
/// @brief A link in the explanatory text has been clicked
|
/// @brief A link in the explanatory text has been clicked
|
||||||
void linkClicked( const QString& link );
|
void linkClicked( const QString& link );
|
||||||
|
/// @brief The model of requirements changed
|
||||||
|
void requirementsChanged();
|
||||||
|
|
||||||
void retranslate();
|
void retranslate();
|
||||||
|
|
||||||
QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
|
QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
|
||||||
Config* m_config = nullptr;
|
Config* m_config = nullptr;
|
||||||
|
|
||||||
|
// UI parts, which need updating when the model changes
|
||||||
|
QLabel* m_explanation = nullptr;
|
||||||
|
QBoxLayout* m_mainLayout = nullptr;
|
||||||
|
QBoxLayout* m_entriesLayout = nullptr;
|
||||||
|
// We count how many requirements we have seen; since the model
|
||||||
|
// does not shrink, we can avoid reacting to model-is-cleared
|
||||||
|
// events because the size of the model is then (briefly) smaller
|
||||||
|
// than what we expect.
|
||||||
|
int m_requirementsSeen = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHECKER_RESULTSLISTWIDGET_H
|
#endif // CHECKER_RESULTSLISTWIDGET_H
|
||||||
|
Loading…
Reference in New Issue
Block a user