source: calamares/trunk/fuentes/src/modules/summary/SummaryPage.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.9 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "SummaryPage.h"
21
22#include "SummaryViewStep.h"
23
24#include "ExecutionViewStep.h"
25#include "utils/Retranslator.h"
26#include "utils/CalamaresUtilsGui.h"
27#include "utils/Logger.h"
28#include "ViewManager.h"
29
30#include <QBoxLayout>
31#include <QLabel>
32#include <QScrollArea>
33
34static const int SECTION_SPACING = 12;
35
36SummaryPage::SummaryPage( const SummaryViewStep* thisViewStep, QWidget* parent )
37    : QWidget()
38    , m_thisViewStep( thisViewStep )
39    , m_contentWidget( nullptr )
40    , m_scrollArea( new QScrollArea( this ) )
41{
42    this->setObjectName("summaryStep");
43    Q_UNUSED( parent );
44    Q_ASSERT( m_thisViewStep );
45    QVBoxLayout* layout = new QVBoxLayout( this );
46    layout->setContentsMargins( 0, 0, 0, 0 );
47
48    QLabel* headerLabel = new QLabel( this );
49    CALAMARES_RETRANSLATE(
50        headerLabel->setText( tr( "This is an overview of what will happen once you start "
51                                  "the install procedure." ) );
52    )
53    layout->addWidget( headerLabel );
54    layout->addWidget( m_scrollArea );
55    m_scrollArea->setWidgetResizable( true );
56    m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
57    m_scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
58    m_scrollArea->setFrameStyle( QFrame::NoFrame );
59    m_scrollArea->setContentsMargins( 0, 0, 0, 0 );
60}
61
62
63// Adds a widget for those ViewSteps that want a summary;
64// see SummaryPage documentation and also ViewStep docs.
65void
66SummaryPage::onActivate()
67{
68    createContentWidget();
69
70    bool first = true;
71    const Calamares::ViewStepList steps =
72        stepsForSummary( Calamares::ViewManager::instance()->viewSteps() );
73
74    for ( Calamares::ViewStep* step : steps )
75    {
76        QString text = step->prettyStatus();
77        QWidget* widget = step->createSummaryWidget();
78
79        if ( text.isEmpty() && !widget )
80            continue;
81
82        if ( first )
83            first = false;
84        else
85            m_layout->addSpacing( SECTION_SPACING );
86
87        m_layout->addWidget( createTitleLabel( step->prettyName() ) );
88        QHBoxLayout* itemBodyLayout = new QHBoxLayout;
89        m_layout->addSpacing( CalamaresUtils::defaultFontHeight() / 2 );
90        m_layout->addLayout( itemBodyLayout );
91        itemBodyLayout->addSpacing( CalamaresUtils::defaultFontHeight() * 2 );
92        QVBoxLayout* itemBodyCoreLayout = new QVBoxLayout;
93        itemBodyLayout->addLayout( itemBodyCoreLayout );
94        CalamaresUtils::unmarginLayout( itemBodyLayout );
95        if ( !text.isEmpty() )
96            itemBodyCoreLayout->addWidget( createBodyLabel( text ) );
97        if ( widget )
98            itemBodyCoreLayout->addWidget( widget );
99        itemBodyLayout->addSpacing( CalamaresUtils::defaultFontHeight() * 2 );
100    }
101    m_layout->addStretch();
102
103    m_scrollArea->setWidget( m_contentWidget );
104
105    auto summarySize = m_contentWidget->sizeHint();
106    if ( summarySize.height() > m_scrollArea->size().height() )
107    {
108        auto enlarge = 2 + summarySize.height() - m_scrollArea->size().height();
109        auto widgetSize = this->size();
110        widgetSize.setHeight( widgetSize.height() + enlarge );
111
112        cDebug() << "Summary widget is larger than viewport, enlarge by" << enlarge << "to" << widgetSize;
113
114        emit m_thisViewStep->enlarge( QSize( 0, enlarge ) );  // Only expand height
115    }
116}
117
118Calamares::ViewStepList
119SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
120{
121    Calamares::ViewStepList steps;
122    for ( Calamares::ViewStep* step : allSteps )
123    {
124        // We start from the beginning of the complete steps list. If we encounter any
125        // ExecutionViewStep, it means there was an execution phase in the past, and any
126        // jobs from before that phase were already executed, so we can safely clear the
127        // list of steps to summarize and start collecting from scratch.
128        if ( qobject_cast< Calamares::ExecutionViewStep* >( step ) )
129        {
130            steps.clear();
131            continue;
132        }
133
134        // If we reach the parent step of this page, we're done collecting the list of
135        // steps to summarize.
136        if ( m_thisViewStep == step )
137            break;
138
139        steps.append( step );
140    }
141
142    return steps;
143}
144
145
146void
147SummaryPage::createContentWidget()
148{
149    delete m_contentWidget;
150    m_contentWidget = new QWidget;
151    m_layout = new QVBoxLayout( m_contentWidget );
152    CalamaresUtils::unmarginLayout( m_layout );
153}
154
155QLabel*
156SummaryPage::createTitleLabel( const QString& text ) const
157{
158    QLabel* label = new QLabel( text );
159    QFont fnt = font();
160    fnt.setWeight( QFont::Light );
161    fnt.setPointSize( CalamaresUtils::defaultFontSize() * 2 );
162    label->setFont( fnt );
163    label->setContentsMargins( 0, 0, 0, 0 );
164
165    return label;
166}
167
168QLabel*
169SummaryPage::createBodyLabel( const QString& text ) const
170{
171    QLabel* label = new QLabel;
172    label->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
173    QPalette pal( palette() );
174    pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
175    label->setAutoFillBackground( true );
176    label->setPalette( pal );
177    label->setText( text );
178    return label;
179}
Note: See TracBrowser for help on using the repository browser.