From 73a75e837b69b0525076dcbdc63a4115b909ca47 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 5 Sep 2017 08:18:23 -0400 Subject: [PATCH] Auto-resize the main window. If the summary widget is large, it gets a scrollbar. This looks really weird, so prefer to grow the installer window instead. Discussed with @sitter and settled on this solution. ViewSteps can signal the ViewManager that they need more space (in pixels), which may or may not be honored. FIXES #778 --- src/calamares/CalamaresWindow.cpp | 17 ++++++++++++++--- src/calamares/CalamaresWindow.h | 9 +++++++++ src/libcalamaresui/ViewManager.cpp | 23 +++++++---------------- src/libcalamaresui/ViewManager.h | 2 ++ src/libcalamaresui/viewpages/ViewStep.h | 12 +++++++++++- src/modules/summary/SummaryPage.cpp | 17 ++++++++++++++++- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 260d56139..eb3289083 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -55,7 +55,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) cDebug() << "Available size" << availableSize; - if ( (availableSize.width() < windowPreferredWidth) || (availableSize.height() < windowPreferredHeight) ) + if ( ( availableSize.width() < windowPreferredWidth ) || ( availableSize.height() < windowPreferredHeight ) ) cDebug() << " Small screen detected."; QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ), qBound( windowMinimumHeight, availableSize.height(), windowPreferredHeight ) ); @@ -131,9 +131,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) else { if ( m_debugWindow ) - { m_debugWindow->deleteLater(); - } } } ); } @@ -142,6 +140,19 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) CalamaresUtils::unmarginLayout( mainLayout ); Calamares::ViewManager* vm = Calamares::ViewManager::instance( this ); + connect( vm, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); mainLayout->addWidget( vm->centralWidget() ); } + +void +CalamaresWindow::enlarge( QSize enlarge ) +{ + auto mainGeometry = this->geometry(); + QSize availableSize = qApp->desktop()->availableGeometry( this ).size(); + + auto h = qBound( 0, mainGeometry.height() + enlarge.height(), availableSize.height() ); + auto w = this->size().width(); + + resize( w, h ); +} diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index 7b2cfa6fa..00f790f5a 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,14 @@ public: CalamaresWindow( QWidget* parent = nullptr ); virtual ~CalamaresWindow() {} +public slots: + /** + * This asks the main window to grow by @p enlarge pixels, to accomodate + * larger-than-expected window contents. The enlargement may be silently + * ignored. + */ + void enlarge( QSize enlarge ); + private: QPointer< Calamares::DebugWindow > m_debugWindow; }; diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 4a8b7acf5..7b5df155b 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -109,9 +109,7 @@ ViewManager::ViewManager( QObject* parent ) qApp->quit(); } else // Means we're at the end, no need to confirm. - { qApp->quit(); - } } ); connect( JobQueue::instance(), &JobQueue::failed, @@ -145,16 +143,15 @@ ViewManager::addViewStep( ViewStep* step ) void -ViewManager::insertViewStep( int before, ViewStep* step) +ViewManager::insertViewStep( int before, ViewStep* step ) { m_steps.insert( before, step ); QLayout* layout = step->widget()->layout(); if ( layout ) - { layout->setContentsMargins( 0, 0, 0, 0 ); - } m_stack->insertWidget( before, step->widget() ); + connect( step, &ViewStep::enlarge, this, &ViewManager::enlarge ); connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) { @@ -180,19 +177,17 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail QMessageBox* msgBox = new QMessageBox(); msgBox->setIcon( QMessageBox::Critical ); - msgBox->setWindowTitle( tr("Error") ); + msgBox->setWindowTitle( tr( "Error" ) ); msgBox->setText( "" + tr( "Installation Failed" ) + "" ); msgBox->setStandardButtons( QMessageBox::Close ); msgBox->button( QMessageBox::Close )->setText( tr( "&Close" ) ); QString text = "

" + message + "

"; if ( !details.isEmpty() ) - { text += "

" + details + "

"; - } msgBox->setInformativeText( text ); - connect(msgBox, &QMessageBox::buttonClicked, qApp, &QApplication::quit); + connect( msgBox, &QMessageBox::buttonClicked, qApp, &QApplication::quit ); cLog() << "Calamares will quit when the dialog closes."; msgBox->show(); } @@ -230,8 +225,8 @@ ViewManager::next() // and right before switching to an execution phase. // Depending on Calamares::Settings, we show an "are you sure" prompt or not. if ( Calamares::Settings::instance()->showPromptBeforeExecution() && - m_currentStep + 1 < m_steps.count() && - qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep + 1 ) ) ) + m_currentStep + 1 < m_steps.count() && + qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep + 1 ) ) ) { int reply = QMessageBox::question( m_widget, @@ -263,15 +258,13 @@ ViewManager::next() } } else - { step->next(); - } m_next->setEnabled( !executing && m_steps.at( m_currentStep )->isNextEnabled() ); m_back->setEnabled( !executing && m_steps.at( m_currentStep )->isBackEnabled() ); if ( m_currentStep == m_steps.count() -1 && - m_steps.last()->isAtEnd() ) + m_steps.last()->isAtEnd() ) { m_quit->setText( tr( "&Done" ) ); m_quit->setToolTip( tr( "The installation is complete. Close the installer." ) ); @@ -292,9 +285,7 @@ ViewManager::back() emit currentStepChanged(); } else if ( !step->isAtBeginning() ) - { step->back(); - } else return; m_next->setEnabled( m_steps.at( m_currentStep )->isNextEnabled() ); diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index f2f0ca57a..38ddda70a 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -111,6 +112,7 @@ public slots: signals: void currentStepChanged(); + void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() private: explicit ViewManager( QObject* parent = nullptr ); diff --git a/src/libcalamaresui/viewpages/ViewStep.h b/src/libcalamaresui/viewpages/ViewStep.h index 27bab23c8..2c07dace5 100644 --- a/src/libcalamaresui/viewpages/ViewStep.h +++ b/src/libcalamaresui/viewpages/ViewStep.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -93,7 +94,10 @@ public: virtual QList< job_ptr > jobs() const = 0; void setModuleInstanceKey( const QString& instanceKey ); - QString moduleInstanceKey() const { return m_instanceKey; } + QString moduleInstanceKey() const + { + return m_instanceKey; + } virtual void setConfigurationMap( const QVariantMap& configurationMap ); @@ -101,6 +105,12 @@ signals: void nextStatusChanged( bool status ); void done(); + /* Emitted when the viewstep thinks it needs more space than is currently + * available for display. @p enlarge is the requested additional space, + * e.g. 24px vertical. This request may be silently ignored. + */ + void enlarge( QSize enlarge ) const; + protected: QString m_instanceKey; }; diff --git a/src/modules/summary/SummaryPage.cpp b/src/modules/summary/SummaryPage.cpp index 6d53ba8b6..c13ec1ccd 100644 --- a/src/modules/summary/SummaryPage.cpp +++ b/src/modules/summary/SummaryPage.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,7 @@ #include "ExecutionViewStep.h" #include "utils/Retranslator.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" #include "ViewManager.h" #include @@ -96,6 +98,20 @@ SummaryPage::onActivate() 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 m_thisViewStep->enlarge( QSize( 0, enlarge ) ); // Only expand height + } } Calamares::ViewStepList @@ -133,7 +149,6 @@ SummaryPage::createContentWidget() m_contentWidget = new QWidget; m_layout = new QVBoxLayout( m_contentWidget ); CalamaresUtils::unmarginLayout( m_layout ); - m_scrollArea->setWidget( m_contentWidget ); } QLabel*