[libcalamaresui] Rename enlarge()

- rename enlarge to ensureSize() and change the meaning from
  "make this much bigger" to "make sure this is displayed",
  which is easier on the caller to calculate.
This commit is contained in:
Adriaan de Groot 2020-04-17 12:54:31 +02:00
parent 2a4c74c099
commit e804ad2488
7 changed files with 22 additions and 11 deletions

View file

@ -310,7 +310,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
m_viewManager = Calamares::ViewManager::instance( this );
if ( branding->windowExpands() )
{
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
connect( m_viewManager, &Calamares::ViewManager::ensureSize, this, &CalamaresWindow::ensureSize );
}
// NOTE: Although the ViewManager has a signal cancelEnabled() that
// signals when the state of the cancel button changes (in
@ -356,12 +356,19 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
}
void
CalamaresWindow::enlarge( QSize enlarge )
CalamaresWindow::ensureSize( QSize size )
{
auto mainGeometry = this->geometry();
QSize availableSize = qApp->desktop()->availableGeometry( this ).size();
auto h = qBound( 0, mainGeometry.height() + enlarge.height(), availableSize.height() );
// We only care about vertical sizes that are big enough
int embiggenment = qMax( 0, size.height() - m_viewManager->centralWidget()->size().height() );
if ( embiggenment < 6 )
{
return;
}
auto h = qBound( 0, mainGeometry.height() + embiggenment, availableSize.height() );
auto w = this->size().width();
resize( w, h );

View file

@ -41,11 +41,11 @@ public:
public slots:
/**
* This asks the main window to grow by @p enlarge pixels, to accomodate
* This asks the main window to grow to accomodate @p size pixels, to accomodate
* larger-than-expected window contents. The enlargement may be silently
* ignored.
*/
void enlarge( QSize enlarge );
void ensureSize( QSize size );
protected:
virtual void closeEvent( QCloseEvent* e ) override;

View file

@ -118,7 +118,7 @@ ViewManager::insertViewStep( int before, ViewStep* step )
{
emit beginInsertRows( QModelIndex(), before, before );
m_steps.insert( before, step );
connect( step, &ViewStep::enlarge, this, &ViewManager::enlarge );
connect( step, &ViewStep::ensureSize, this, &ViewManager::ensureSize );
connect( step, &ViewStep::nextStatusChanged, this, &ViewManager::updateNextStatus );
if ( !step->widget() )

View file

@ -195,7 +195,7 @@ public Q_SLOTS:
signals:
void currentStepChanged();
void enlarge( QSize enlarge ) const; // See ViewStep::enlarge()
void ensureSize( QSize size ) const; // See ViewStep::ensureSize()
void cancelEnabled( bool enabled ) const;
void nextEnabledChanged( bool ) const;

View file

@ -149,10 +149,12 @@ signals:
void nextStatusChanged( bool status );
/* 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.
* available for display. @p size is the requested space, that is needed
* to display the entire page.
*
* This request may be silently ignored.
*/
void enlarge( QSize enlarge ) const;
void ensureSize( QSize enlarge ) const;
protected:
Calamares::ModuleSystem::InstanceKey m_instanceKey;

View file

@ -73,6 +73,8 @@ LocaleViewStep::setUpPage()
m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath );
m_widget->layout()->addWidget( m_actualWidget );
ensureSize( m_actualWidget->sizeHint() );
m_nextEnabled = true;
emit nextStatusChanged( m_nextEnabled );
}

View file

@ -124,7 +124,7 @@ SummaryPage::onActivate()
cDebug() << "Summary widget is larger than viewport, enlarge by" << enlarge << "to" << widgetSize;
emit m_thisViewStep->enlarge( QSize( 0, enlarge ) ); // Only expand height
emit m_thisViewStep->ensureSize( widgetSize ); // Only expand height
}
}