source: calamares/trunk/fuentes/src/calamares/CalamaresWindow.cpp @ 7538

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

sync with github

File size: 6.3 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-2018, 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 "CalamaresWindow.h"
21
22#include "ViewManager.h"
23#include "progresstree/ProgressTreeView.h"
24#include "utils/CalamaresUtilsGui.h"
25#include "utils/Logger.h"
26#include "utils/DebugWindow.h"
27#include "utils/Retranslator.h"
28#include "Settings.h"
29#include "Branding.h"
30
31#include <QApplication>
32#include <QBoxLayout>
33#include <QCloseEvent>
34#include <QDesktopWidget>
35#include <QLabel>
36#include <QTreeView>
37#include <QFile>
38
39CalamaresWindow::CalamaresWindow( QWidget* parent )
40    : QWidget( parent )
41    , m_debugWindow( nullptr )
42    , m_viewManager( nullptr )
43{
44    CALAMARES_RETRANSLATE(
45        setWindowTitle( tr( "%1 Installer" )
46                        .arg( *Calamares::Branding::ProductName ) );
47    )
48
49    using CalamaresUtils::windowMinimumHeight;
50    using CalamaresUtils::windowMinimumWidth;
51    using CalamaresUtils::windowPreferredHeight;
52    using CalamaresUtils::windowPreferredWidth;
53
54    QSize availableSize = qApp->desktop()->availableGeometry( this ).size();
55    this->setObjectName("mainApp");
56   
57    cDebug() << "Available size" << availableSize;
58
59    if ( ( availableSize.width() < windowPreferredWidth ) || ( availableSize.height() < windowPreferredHeight ) )
60        cDebug() << "  Small screen detected.";
61    QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ),
62                       qBound( windowMinimumHeight, availableSize.height(), windowPreferredHeight ) );
63    setMinimumSize( minimumSize );
64
65
66    int w = qBound( minimumSize.width(), CalamaresUtils::defaultFontHeight() * 60, availableSize.width() );
67    int h = qBound( minimumSize.height(),  CalamaresUtils::defaultFontHeight() * 36, availableSize.height() );
68
69    cDebug() << "  Proposed window size:" << w << h;
70    resize( w, h );
71
72    QBoxLayout* mainLayout = new QHBoxLayout;
73    setLayout( mainLayout );
74
75    QWidget* sideBox = new QWidget( this );
76    sideBox->setObjectName("sidebarApp");
77    mainLayout->addWidget( sideBox );
78
79    QBoxLayout* sideLayout = new QVBoxLayout;
80    sideBox->setLayout( sideLayout );
81    // Set this attribute into qss file
82    sideBox->setFixedWidth( qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) );
83    sideBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
84
85    QHBoxLayout* logoLayout = new QHBoxLayout;
86    sideLayout->addLayout( logoLayout );
87    logoLayout->addStretch();
88    QLabel* logoLabel = new QLabel( sideBox );
89    logoLabel->setObjectName("logoApp");
90    //Define all values into qss file
91    {
92        QPalette plt = sideBox->palette();
93        sideBox->setAutoFillBackground( true );
94        plt.setColor( sideBox->backgroundRole(), Calamares::Branding::instance()->
95                      styleString( Calamares::Branding::SidebarBackground ) );
96        plt.setColor( sideBox->foregroundRole(), Calamares::Branding::instance()->
97                      styleString( Calamares::Branding::SidebarText ) );
98        sideBox->setPalette( plt );
99        logoLabel->setPalette( plt );
100    }
101    logoLabel->setAlignment( Qt::AlignCenter );
102    logoLabel->setFixedSize( 80, 80 );
103    logoLabel->setPixmap( Calamares::Branding::instance()->
104                          image( Calamares::Branding::ProductLogo,
105                                 logoLabel->size() ) );
106    logoLayout->addWidget( logoLabel );
107    logoLayout->addStretch();
108
109    ProgressTreeView* tv = new ProgressTreeView( sideBox );
110    sideLayout->addWidget( tv );
111    tv->setFocusPolicy( Qt::NoFocus );
112
113    if ( Calamares::Settings::instance()->debugMode() )
114    {
115        QPushButton* debugWindowBtn = new QPushButton;
116        CALAMARES_RETRANSLATE(
117            debugWindowBtn->setText( tr( "Show debug information" ) );
118        )
119        sideLayout->addWidget( debugWindowBtn );
120        debugWindowBtn->setFlat( true );
121        debugWindowBtn->setCheckable( true );
122        connect( debugWindowBtn, &QPushButton::clicked,
123                 this, [ = ]( bool checked )
124        {
125            if ( checked )
126            {
127                m_debugWindow = new Calamares::DebugWindow();
128                m_debugWindow->show();
129                connect( m_debugWindow.data(), &Calamares::DebugWindow::closed,
130                         this, [ = ]()
131                {
132                    m_debugWindow->deleteLater();
133                    debugWindowBtn->setChecked( false );
134                } );
135            }
136            else
137            {
138                if ( m_debugWindow )
139                    m_debugWindow->deleteLater();
140            }
141        } );
142    }
143
144    CalamaresUtils::unmarginLayout( sideLayout );
145    CalamaresUtils::unmarginLayout( mainLayout );
146
147    m_viewManager = Calamares::ViewManager::instance( this );
148    connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
149
150    mainLayout->addWidget( m_viewManager->centralWidget() );
151    QFile File("/etc/calamares/stylesheet.qss");
152    File.open(QFile::ReadOnly);
153    QString StyleSheet = QLatin1String(File.readAll());
154    this->setStyleSheet(StyleSheet);
155
156}
157
158void
159CalamaresWindow::enlarge( QSize enlarge )
160{
161    auto mainGeometry = this->geometry();
162    QSize availableSize = qApp->desktop()->availableGeometry( this ).size();
163
164    auto h = qBound( 0, mainGeometry.height() + enlarge.height(), availableSize.height() );
165    auto w = this->size().width();
166
167    resize( w, h );
168}
169
170void
171CalamaresWindow::closeEvent( QCloseEvent* event )
172{
173    if ( ( !m_viewManager ) || m_viewManager->confirmCancelInstallation() )
174    {
175        event->accept();
176        qApp->quit();
177    }
178    else
179        event->ignore();
180}
Note: See TracBrowser for help on using the repository browser.