From 103decab68cd0a54e3b1d26069fb1b8e23982ecc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 2 Jun 2019 13:40:53 +0200 Subject: [PATCH] [libcalamaresui] Create the slideshow on activation - Load QML on startup, compile async - Create QML component when the page is reached. - On leave, stop the slideshow (otherwise, e.g. timers will keep running) This should move some of the delay from loading a large slideshow forward as the engine is already initialized when we reach the install / slideshow page. --- src/libcalamaresui/ExecutionViewStep.cpp | 30 +++++++++++++++++------- src/libcalamaresui/ExecutionViewStep.h | 6 ++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/ExecutionViewStep.cpp index a1f7bcd27..f41068237 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/ExecutionViewStep.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,8 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent ) , m_progressBar( new QProgressBar ) , m_label( new QLabel ) , m_qmlShow( new QQuickWidget ) - , m_qmlShowLoaded( false ) + , m_qmlComponent( nullptr ) + , m_qmlObject( nullptr ) { QVBoxLayout* layout = new QVBoxLayout( m_widget ); QVBoxLayout* innerLayout = new QVBoxLayout; @@ -72,11 +74,6 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent ) loadQml(); connect( JobQueue::instance(), &JobQueue::progress, this, &ExecutionViewStep::updateFromJobQueue ); - - CALAMARES_RETRANSLATE_WIDGET( m_widget, - if ( m_qmlShowLoaded ) - m_qmlShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) ); - ) } @@ -138,10 +135,12 @@ ExecutionViewStep::isAtEnd() const void ExecutionViewStep::loadQml() { - if ( !m_qmlShowLoaded && !Calamares::Branding::instance()->slideshowPath().isEmpty() ) + if ( !m_qmlComponent && !Calamares::Branding::instance()->slideshowPath().isEmpty() ) { - m_qmlShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) ); - m_qmlShowLoaded = true; + m_qmlComponent = new QQmlComponent( m_qmlShow->engine(), + QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ), + QQmlComponent::CompilationMode::Asynchronous + ); } } @@ -149,6 +148,12 @@ void ExecutionViewStep::onActivate() { loadQml(); + if ( m_qmlComponent ) + { + m_qmlObject = m_qmlComponent->create(); + cDebug() << "Created QML object" << (void *)m_qmlObject << m_qmlObject->objectName(); + cDebug() << "Show root" << m_qmlShow->rootObject() << "context" << m_qmlShow->rootContext(); + } JobQueue* queue = JobQueue::instance(); foreach ( const QString& instanceKey, m_jobInstanceKeys ) @@ -191,4 +196,11 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message ) m_label->setText( message ); } +void +ExecutionViewStep::onLeave() +{ + delete m_qmlObject; + m_qmlObject = nullptr; +} + } // namespace diff --git a/src/libcalamaresui/ExecutionViewStep.h b/src/libcalamaresui/ExecutionViewStep.h index 12eb6736c..a968f22e4 100644 --- a/src/libcalamaresui/ExecutionViewStep.h +++ b/src/libcalamaresui/ExecutionViewStep.h @@ -25,8 +25,10 @@ #include class QLabel; +class QObject; class QProgressBar; class QQuickWidget; +class QQmlComponent; namespace Calamares { @@ -51,6 +53,7 @@ public: bool isAtEnd() const override; void onActivate() override; + void onLeave() override; JobList jobs() const override; @@ -61,7 +64,8 @@ private: QProgressBar* m_progressBar; QLabel* m_label; QQuickWidget* m_qmlShow; - bool m_qmlShowLoaded; + QQmlComponent* m_qmlComponent; + QObject* m_qmlObject; //< The actual show QStringList m_jobInstanceKeys;