2020-08-25 16:05:56 +02:00
|
|
|
/* === 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
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-07-08 17:28:35 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SummaryPage.h"
|
|
|
|
|
2015-09-09 19:06:44 +02:00
|
|
|
#include "SummaryViewStep.h"
|
|
|
|
|
2019-04-24 19:58:38 +02:00
|
|
|
#include "Branding.h"
|
2019-04-08 13:43:38 +02:00
|
|
|
#include "Settings.h"
|
2015-09-09 19:06:44 +02:00
|
|
|
#include "ViewManager.h"
|
2014-07-08 18:24:39 +02:00
|
|
|
|
2019-04-24 19:58:38 +02:00
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Retranslator.h"
|
2020-01-10 11:56:30 +01:00
|
|
|
#include "viewpages/ExecutionViewStep.h"
|
2019-04-24 19:58:38 +02:00
|
|
|
|
2014-07-08 17:28:35 +02:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QLabel>
|
2015-04-09 18:02:29 +02:00
|
|
|
#include <QScrollArea>
|
2014-07-08 17:28:35 +02:00
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
static const int SECTION_SPACING = 12;
|
2014-07-08 17:28:35 +02:00
|
|
|
|
2015-09-09 19:06:44 +02:00
|
|
|
SummaryPage::SummaryPage( const SummaryViewStep* thisViewStep, QWidget* parent )
|
2014-07-08 17:28:35 +02:00
|
|
|
: QWidget()
|
2015-09-09 19:06:44 +02:00
|
|
|
, m_thisViewStep( thisViewStep )
|
2015-04-09 18:02:29 +02:00
|
|
|
, m_contentWidget( nullptr )
|
2017-09-20 09:24:33 +02:00
|
|
|
, m_scrollArea( new QScrollArea( this ) )
|
2014-07-08 17:28:35 +02:00
|
|
|
{
|
2019-04-17 11:57:46 +02:00
|
|
|
Q_UNUSED( parent )
|
2019-04-23 22:41:22 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
this->setObjectName( "summaryStep" );
|
2019-04-23 22:41:22 +02:00
|
|
|
|
2015-09-09 19:06:44 +02:00
|
|
|
Q_ASSERT( m_thisViewStep );
|
2014-07-30 14:15:29 +02:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout( this );
|
|
|
|
layout->setContentsMargins( 0, 0, 0, 0 );
|
2015-04-09 17:49:00 +02:00
|
|
|
|
|
|
|
QLabel* headerLabel = new QLabel( this );
|
2020-08-22 01:19:58 +02:00
|
|
|
CALAMARES_RETRANSLATE( if ( Calamares::Settings::instance()->isSetupMode() )
|
|
|
|
headerLabel->setText( tr( "This is an overview of what will happen once you start "
|
|
|
|
"the setup procedure." ) );
|
|
|
|
else headerLabel->setText( tr( "This is an overview of what will happen once you start "
|
|
|
|
"the install procedure." ) ); )
|
2015-04-09 17:49:00 +02:00
|
|
|
layout->addWidget( headerLabel );
|
2015-04-09 18:02:29 +02:00
|
|
|
layout->addWidget( m_scrollArea );
|
|
|
|
m_scrollArea->setWidgetResizable( true );
|
|
|
|
m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
2019-04-24 19:58:38 +02:00
|
|
|
// 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 );
|
2015-04-09 18:02:29 +02:00
|
|
|
m_scrollArea->setFrameStyle( QFrame::NoFrame );
|
|
|
|
m_scrollArea->setContentsMargins( 0, 0, 0, 0 );
|
2014-07-08 18:24:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 13:54:38 +02:00
|
|
|
// Adds a widget for those ViewSteps that want a summary;
|
|
|
|
// see SummaryPage documentation and also ViewStep docs.
|
2014-07-08 18:24:39 +02:00
|
|
|
void
|
|
|
|
SummaryPage::onActivate()
|
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
createContentWidget();
|
|
|
|
|
|
|
|
bool first = true;
|
2020-08-22 01:19:58 +02:00
|
|
|
const Calamares::ViewStepList steps = stepsForSummary( Calamares::ViewManager::instance()->viewSteps() );
|
2015-09-09 19:06:44 +02:00
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( Calamares::ViewStep* step : steps )
|
2014-07-08 18:24:39 +02:00
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
QString text = step->prettyStatus();
|
|
|
|
QWidget* widget = step->createSummaryWidget();
|
|
|
|
|
|
|
|
if ( text.isEmpty() && !widget )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
continue;
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
|
|
|
|
if ( first )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
first = false;
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
else
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2014-07-30 14:15:29 +02:00
|
|
|
m_layout->addSpacing( SECTION_SPACING );
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
|
|
|
|
m_layout->addWidget( createTitleLabel( step->prettyName() ) );
|
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 );
|
2014-07-30 14:15:29 +02:00
|
|
|
if ( !text.isEmpty() )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2015-04-09 17:49:00 +02:00
|
|
|
itemBodyCoreLayout->addWidget( createBodyLabel( text ) );
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +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 );
|
2014-07-08 18:24:39 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
m_layout->addStretch();
|
2017-09-05 14:18:23 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-04-17 12:54:31 +02:00
|
|
|
emit m_thisViewStep->ensureSize( widgetSize ); // Only expand height
|
2017-09-05 14:18:23 +02:00
|
|
|
}
|
2014-07-30 14:15:29 +02:00
|
|
|
}
|
2014-07-08 17:28:35 +02:00
|
|
|
|
2015-09-09 19:06:44 +02:00
|
|
|
Calamares::ViewStepList
|
|
|
|
SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
|
|
|
|
{
|
|
|
|
Calamares::ViewStepList steps;
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( Calamares::ViewStep* step : allSteps )
|
2015-09-09 19:06:44 +02:00
|
|
|
{
|
|
|
|
// 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 ( m_thisViewStep == step )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2015-09-09 19:06:44 +02:00
|
|
|
break;
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2015-09-09 19:06:44 +02:00
|
|
|
|
|
|
|
steps.append( step );
|
|
|
|
}
|
|
|
|
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
void
|
|
|
|
SummaryPage::createContentWidget()
|
|
|
|
{
|
|
|
|
delete m_contentWidget;
|
|
|
|
m_contentWidget = new QWidget;
|
|
|
|
m_layout = new QVBoxLayout( m_contentWidget );
|
2015-04-09 17:49:00 +02:00
|
|
|
CalamaresUtils::unmarginLayout( m_layout );
|
2014-07-30 14:15:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QLabel*
|
|
|
|
SummaryPage::createTitleLabel( const QString& text ) const
|
|
|
|
{
|
|
|
|
QLabel* label = new QLabel( text );
|
|
|
|
QFont fnt = font();
|
2015-04-09 17:49:00 +02:00
|
|
|
fnt.setWeight( QFont::Light );
|
|
|
|
fnt.setPointSize( CalamaresUtils::defaultFontSize() * 2 );
|
2014-07-30 14:15:29 +02:00
|
|
|
label->setFont( fnt );
|
2015-04-09 17:49:00 +02:00
|
|
|
label->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel*
|
|
|
|
SummaryPage::createBodyLabel( const QString& text ) const
|
|
|
|
{
|
2015-04-09 17:49:00 +02:00
|
|
|
QLabel* label = new QLabel;
|
|
|
|
label->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
|
|
|
|
QPalette pal( palette() );
|
2019-11-28 23:31:00 +01:00
|
|
|
pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) );
|
2015-04-09 17:49:00 +02:00
|
|
|
label->setAutoFillBackground( true );
|
|
|
|
label->setPalette( pal );
|
|
|
|
label->setText( text );
|
|
|
|
return label;
|
2014-07-08 17:28:35 +02:00
|
|
|
}
|