2014-07-08 17:28:35 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2015-04-09 18:02:29 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2017-09-05 14:18:23 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2014-07-08 17:28:35 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SummaryPage.h"
|
|
|
|
|
2015-09-09 19:06:44 +02:00
|
|
|
#include "SummaryViewStep.h"
|
|
|
|
|
|
|
|
#include "ExecutionViewStep.h"
|
2015-04-09 17:49:00 +02:00
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2017-09-05 14:18:23 +02:00
|
|
|
#include "utils/Logger.h"
|
2015-09-09 19:06:44 +02:00
|
|
|
#include "ViewManager.h"
|
2014-07-08 18:24:39 +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
|
|
|
{
|
2017-09-20 09:24:33 +02:00
|
|
|
Q_UNUSED( parent );
|
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 );
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
headerLabel->setText( tr( "This is an overview of what will happen once you start "
|
|
|
|
"the install procedure." ) );
|
|
|
|
)
|
|
|
|
layout->addWidget( headerLabel );
|
2015-04-09 18:02:29 +02:00
|
|
|
layout->addWidget( m_scrollArea );
|
|
|
|
m_scrollArea->setWidgetResizable( true );
|
|
|
|
m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
|
|
|
m_scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
|
|
|
|
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;
|
2016-09-01 14:21:05 +02:00
|
|
|
const Calamares::ViewStepList steps =
|
2015-09-09 19:06:44 +02:00
|
|
|
stepsForSummary( Calamares::ViewManager::instance()->viewSteps() );
|
|
|
|
|
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 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( first )
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
m_layout->addSpacing( SECTION_SPACING );
|
|
|
|
|
|
|
|
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() )
|
2015-04-09 17:49:00 +02:00
|
|
|
itemBodyCoreLayout->addWidget( createBodyLabel( text ) );
|
2014-07-30 14:15:29 +02:00
|
|
|
if ( widget )
|
2015-04-09 17:49:00 +02:00
|
|
|
itemBodyCoreLayout->addWidget( widget );
|
|
|
|
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;
|
|
|
|
|
|
|
|
emit m_thisViewStep->enlarge( QSize( 0, enlarge ) ); // Only expand height
|
|
|
|
}
|
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 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
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() );
|
|
|
|
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
|
|
|
|
label->setAutoFillBackground( true );
|
|
|
|
label->setPalette( pal );
|
|
|
|
label->setText( text );
|
|
|
|
return label;
|
2014-07-08 17:28:35 +02:00
|
|
|
}
|