calamares/src/modules/summary/SummaryPage.cpp

190 lines
6.0 KiB
C++
Raw Normal View History

/* === This file is part of Calamares - <https://calamares.io> ===
2014-07-08 17:28:35 +02:00
*
2020-08-22 01:19:58 +02:00
* SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
* SPDX-FileCopyrightText: 2017 2019, Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2019 Collabora Ltd <arnaud.ferraris@collabora.com>
* SPDX-License-Identifier: GPL-3.0-or-later
2014-07-08 17:28:35 +02:00
*
* Calamares is Free Software: see the License-Identifier above.
2014-07-08 17:28:35 +02:00
*
*/
#include "SummaryPage.h"
#include "SummaryViewStep.h"
#include "Branding.h"
#include "Settings.h"
#include "ViewManager.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/QtCompat.h"
#include "utils/Retranslator.h"
#include "viewpages/ExecutionViewStep.h"
2014-07-08 17:28:35 +02:00
#include <QBoxLayout>
#include <QLabel>
#include <QScrollArea>
2014-07-08 17:28:35 +02:00
SummaryPage::SummaryPage( Config* config, QWidget* parent )
2014-07-08 17:28:35 +02:00
: QWidget()
, m_contentWidget( nullptr )
2017-09-20 09:24:33 +02:00
, m_scrollArea( new QScrollArea( this ) )
2014-07-08 17:28:35 +02:00
{
Q_UNUSED( parent )
2020-08-22 01:19:58 +02:00
this->setObjectName( "summaryStep" );
QVBoxLayout* layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
2015-04-09 17:49:00 +02:00
QLabel* headerLabel = new QLabel( this );
2021-05-10 21:55:21 +02:00
headerLabel->setObjectName( "summaryTitle" );
headerLabel->setText( config->message() );
connect( config, &Config::messageChanged, headerLabel, &QLabel::setText );
2015-04-09 17:49:00 +02:00
layout->addWidget( headerLabel );
layout->addWidget( m_scrollArea );
m_scrollArea->setWidgetResizable( true );
m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
// If Calamares will grow, then only show scrollbar when it's needed
// (e.g. when the screen is full).
m_scrollArea->setVerticalScrollBarPolicy(
Calamares::Branding::instance()->windowExpands() ? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOn );
m_scrollArea->setFrameStyle( QFrame::NoFrame );
m_scrollArea->setContentsMargins( 0, 0, 0, 0 );
}
static QLabel*
createTitleLabel( const QString& text, const QFont& titleFont )
{
QLabel* label = new QLabel( text );
label->setObjectName( "summaryItemTitle" );
label->setFont( titleFont );
label->setContentsMargins( 0, 0, 0, 0 );
return label;
}
static QLabel*
createBodyLabel( const QString& text, const QPalette& bodyPalette )
{
QLabel* label = new QLabel;
label->setObjectName( "summaryItemBody" );
label->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
label->setAutoFillBackground( true );
label->setPalette( bodyPalette );
label->setText( text );
return label;
}
// Adds a widget for those ViewSteps that want a summary;
// see SummaryPage documentation and also ViewStep docs.
void
SummaryPage::buildWidgets( Config* config, SummaryViewStep* viewstep )
{
const int SECTION_SPACING = 12;
delete m_contentWidget; // It might have been created previously
m_contentWidget = new QWidget;
m_layout = new QVBoxLayout( m_contentWidget );
CalamaresUtils::unmarginLayout( m_layout );
QFont titleFont = font();
titleFont.setWeight( QFont::Light );
titleFont.setPointSize( CalamaresUtils::defaultFontSize() * 2 );
QPalette bodyPalette( palette() );
bodyPalette.setColor( WindowBackground, palette().window().color().lighter( 108 ) );
bool first = true;
const Calamares::ViewStepList steps = stepsForSummary( Calamares::ViewManager::instance()->viewSteps(), viewstep );
for ( Calamares::ViewStep* step : steps )
{
QString text = step->prettyStatus();
QWidget* widget = step->createSummaryWidget();
if ( text.isEmpty() && !widget )
2020-08-22 01:19:58 +02:00
{
continue;
2020-08-22 01:19:58 +02:00
}
if ( !first )
2020-08-22 01:19:58 +02:00
{
m_layout->addSpacing( SECTION_SPACING );
2020-08-22 01:19:58 +02:00
}
first = false;
m_layout->addWidget( createTitleLabel( step->prettyName(), titleFont ) );
2015-04-09 17:49:00 +02:00
QHBoxLayout* itemBodyLayout = new QHBoxLayout;
m_layout->addSpacing( CalamaresUtils::defaultFontHeight() / 2 );
m_layout->addLayout( itemBodyLayout );
itemBodyLayout->addSpacing( CalamaresUtils::defaultFontHeight() * 2 );
QVBoxLayout* itemBodyCoreLayout = new QVBoxLayout;
itemBodyLayout->addLayout( itemBodyCoreLayout );
CalamaresUtils::unmarginLayout( itemBodyLayout );
if ( !text.isEmpty() )
2020-08-22 01:19:58 +02:00
{
itemBodyCoreLayout->addWidget( createBodyLabel( text, bodyPalette ) );
2020-08-22 01:19:58 +02:00
}
if ( widget )
2020-08-22 01:19:58 +02:00
{
2015-04-09 17:49:00 +02:00
itemBodyCoreLayout->addWidget( widget );
2020-08-22 01:19:58 +02:00
}
2015-04-09 17:49:00 +02:00
itemBodyLayout->addSpacing( CalamaresUtils::defaultFontHeight() * 2 );
}
m_layout->addStretch();
m_scrollArea->setWidget( m_contentWidget );
auto summarySize = m_contentWidget->sizeHint();
if ( summarySize.height() > m_scrollArea->size().height() )
{
auto enlarge = 2 + summarySize.height() - m_scrollArea->size().height();
auto widgetSize = this->size();
widgetSize.setHeight( widgetSize.height() + enlarge );
cDebug() << "Summary widget is larger than viewport, enlarge by" << enlarge << "to" << widgetSize;
emit viewstep->ensureSize( widgetSize ); // Only expand height
}
}
2014-07-08 17:28:35 +02:00
Calamares::ViewStepList
SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps, SummaryViewStep* viewstep ) const
{
Calamares::ViewStepList steps;
for ( Calamares::ViewStep* step : allSteps )
{
// We start from the beginning of the complete steps list. If we encounter any
// ExecutionViewStep, it means there was an execution phase in the past, and any
// jobs from before that phase were already executed, so we can safely clear the
// list of steps to summarize and start collecting from scratch.
if ( qobject_cast< Calamares::ExecutionViewStep* >( step ) )
{
steps.clear();
continue;
}
// If we reach the parent step of this page, we're done collecting the list of
// steps to summarize.
if ( viewstep == step )
2020-08-22 01:19:58 +02:00
{
break;
2020-08-22 01:19:58 +02:00
}
steps.append( step );
}
return steps;
}
void
SummaryPage::cleanup()
{
delete m_contentWidget;
m_contentWidget = nullptr;
}