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
main
Adriaan de Groot 7 years ago
parent 1859808227
commit 73a75e837b

@ -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 );
}

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* 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;
};

@ -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( "<strong>" + tr( "Installation Failed" ) + "</strong>" );
msgBox->setStandardButtons( QMessageBox::Close );
msgBox->button( QMessageBox::Close )->setText( tr( "&Close" ) );
QString text = "<p>" + message + "</p>";
if ( !details.isEmpty() )
{
text += "<p>" + details + "</p>";
}
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() );

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* 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 );

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* 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;
};

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* 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 <QBoxLayout>
@ -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*

Loading…
Cancel
Save