[libcalamaresui] Shuffle code for QML slideshow

- Create widgets earlier
 - Group layouting code
 - Add retranslator only once, not on every activate
 - Load QML only once, preferably at activation
This commit is contained in:
Adriaan de Groot 2019-06-01 23:39:39 +02:00
parent cbe14bbf03
commit 5973dbf74c
2 changed files with 21 additions and 15 deletions

View File

@ -46,31 +46,36 @@ namespace Calamares
ExecutionViewStep::ExecutionViewStep( QObject* parent ) ExecutionViewStep::ExecutionViewStep( QObject* parent )
: ViewStep( parent ) : ViewStep( parent )
, m_widget( new QWidget ) , m_widget( new QWidget )
, m_progressBar( new QProgressBar )
, m_label( new QLabel )
, m_qmlShow( new QQuickWidget )
, m_qmlShowLoaded( false )
{ {
m_progressBar = new QProgressBar;
m_progressBar->setMaximum( 10000 );
m_label = new QLabel;
QVBoxLayout* layout = new QVBoxLayout( m_widget ); QVBoxLayout* layout = new QVBoxLayout( m_widget );
QVBoxLayout* innerLayout = new QVBoxLayout; QVBoxLayout* innerLayout = new QVBoxLayout;
m_qmlShow = new QQuickWidget; m_progressBar->setMaximum( 10000 );
layout->addWidget( m_qmlShow );
CalamaresUtils::unmarginLayout( layout );
layout->addLayout( innerLayout );
m_qmlShow->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); m_qmlShow->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_qmlShow->setResizeMode( QQuickWidget::SizeRootObjectToView ); m_qmlShow->setResizeMode( QQuickWidget::SizeRootObjectToView );
m_qmlShow->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); m_qmlShow->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() );
layout->addWidget( m_qmlShow );
CalamaresUtils::unmarginLayout( layout );
layout->addLayout( innerLayout );
innerLayout->addSpacing( CalamaresUtils::defaultFontHeight() / 2 ); innerLayout->addSpacing( CalamaresUtils::defaultFontHeight() / 2 );
innerLayout->addWidget( m_progressBar ); innerLayout->addWidget( m_progressBar );
innerLayout->addWidget( m_label ); innerLayout->addWidget( m_label );
cDebug() << "QML import paths:" << Logger::DebugList( m_qmlShow->engine()->importPathList() ); cDebug() << "QML import paths:" << Logger::DebugList( m_qmlShow->engine()->importPathList() );
connect( JobQueue::instance(), &JobQueue::progress, connect( JobQueue::instance(), &JobQueue::progress, this, &ExecutionViewStep::updateFromJobQueue );
this, &ExecutionViewStep::updateFromJobQueue );
CALAMARES_RETRANSLATE_WIDGET( m_widget,
if ( m_qmlShowLoaded )
m_qmlShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) );
)
} }
@ -133,11 +138,11 @@ ExecutionViewStep::isAtEnd() const
void void
ExecutionViewStep::onActivate() ExecutionViewStep::onActivate()
{ {
CALAMARES_RETRANSLATE_WIDGET( m_widget, if ( !m_qmlShowLoaded && !Calamares::Branding::instance()->slideshowPath().isEmpty() )
if ( !Calamares::Branding::instance()->slideshowPath().isEmpty() ) {
m_qmlShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance() m_qmlShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) );
->slideshowPath() ) ); m_qmlShowLoaded = true;
) }
JobQueue* queue = JobQueue::instance(); JobQueue* queue = JobQueue::instance();
foreach ( const QString& instanceKey, m_jobInstanceKeys ) foreach ( const QString& instanceKey, m_jobInstanceKeys )

View File

@ -61,6 +61,7 @@ private:
QProgressBar* m_progressBar; QProgressBar* m_progressBar;
QLabel* m_label; QLabel* m_label;
QQuickWidget* m_qmlShow; QQuickWidget* m_qmlShow;
bool m_qmlShowLoaded;
QStringList m_jobInstanceKeys; QStringList m_jobInstanceKeys;