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
This commit is contained in:
Adriaan de Groot 2017-09-05 08:18:23 -04:00
parent 1859808227
commit 73a75e837b
6 changed files with 59 additions and 21 deletions

View File

@ -131,10 +131,8 @@ 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 );
}

View File

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

View File

@ -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,
@ -150,11 +148,10 @@ 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 )
{
@ -187,9 +184,7 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
QString text = "<p>" + message + "</p>";
if ( !details.isEmpty() )
{
text += "<p>" + details + "</p>";
}
msgBox->setInformativeText( text );
connect( msgBox, &QMessageBox::buttonClicked, qApp, &QApplication::quit );
@ -263,9 +258,7 @@ 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() );
@ -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() );

View File

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

View File

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

View File

@ -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*