From df746047553e635d3cd8dd68b961d9909ee44033 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 13 May 2020 16:35:09 +0200 Subject: [PATCH] [libcalamaresui] Implement non-QML Slideshow --- src/libcalamaresui/viewpages/Slideshow.cpp | 91 +++++++++++++++++++++- src/libcalamaresui/viewpages/Slideshow.h | 41 +++++++++- 2 files changed, 129 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/viewpages/Slideshow.cpp b/src/libcalamaresui/viewpages/Slideshow.cpp index 5b264a5dd..a6c4c952c 100644 --- a/src/libcalamaresui/viewpages/Slideshow.cpp +++ b/src/libcalamaresui/viewpages/Slideshow.cpp @@ -26,11 +26,15 @@ #include "utils/Qml.h" #include "utils/Retranslator.h" +#include #include #include #include #include #include +#include + +#include namespace Calamares { @@ -61,9 +65,13 @@ SlideshowQML::SlideshowQML( QWidget* parent ) SlideshowQML::~SlideshowQML() { + delete m_qmlObject; + delete m_qmlComponent; + delete m_qmlShow; } -QWidget * SlideshowQML::widget() +QWidget* +SlideshowQML::widget() { return m_qmlShow; } @@ -166,4 +174,83 @@ SlideshowQML::changeSlideShowState( Action state ) m_state = state; } -} // namespace +SlideshowPictures::SlideshowPictures( QWidget* parent ) + : Slideshow( parent ) + , m_label( new QLabel( parent ) ) + , m_timer( new QTimer( this ) ) + , m_imageIndex( 0 ) + , m_images { QStringLiteral( ":/data/images/yes.svgz" ), QStringLiteral( ":/data/images/no.svgz" ) } +{ + m_timer->setInterval( std::chrono::milliseconds( 2000 ) ); + connect( m_timer, &QTimer::timeout, this, &SlideshowPictures::next ); +} + +SlideshowPictures::~SlideshowPictures() +{ + delete m_timer; + delete m_label; +} + +QWidget* +SlideshowPictures::widget() +{ + return m_label; +} + +void +SlideshowPictures::changeSlideShowState( Calamares::Slideshow::Action a ) +{ + QMutexLocker l( &m_mutex ); + m_state = a; + if ( a == Slideshow::Start ) + { + m_imageIndex = -1; + if ( m_images.count() < 1 ) + { + m_label->setPixmap( QPixmap( ":/data/images/squid.svg" ) ); + } + else + { + + m_timer->start(); + QTimer::singleShot( 0, this, &SlideshowPictures::next ); + } + } + else + { + m_timer->stop(); + } +} + +void +SlideshowPictures::next() +{ + QMutexLocker l( &m_mutex ); + + if ( m_imageIndex < 0 ) + { + // Initialization, don't do the advance-by-one + m_imageIndex = 0; + } + else + { + m_imageIndex++; + if ( m_imageIndex >= m_images.count() ) + { + m_imageIndex = 0; + } + } + + if ( m_imageIndex >= m_images.count() ) + { + // Unusual case: timer is running, but we have 0 images to display. + // .. this would have been caught in changeSlideShowState(), which + // .. special-cases 0 images. + return; + } + + m_label->setPixmap( QPixmap( m_images.at( m_imageIndex ) ) ); +} + + +} // namespace Calamares diff --git a/src/libcalamaresui/viewpages/Slideshow.h b/src/libcalamaresui/viewpages/Slideshow.h index 428422db5..2296c6d23 100644 --- a/src/libcalamaresui/viewpages/Slideshow.h +++ b/src/libcalamaresui/viewpages/Slideshow.h @@ -22,8 +22,11 @@ #define LIBCALAMARESUI_SLIDESHOW_H #include +#include #include +class QLabel; +class QTimer; class QQmlComponent; class QQuickItem; class QQuickWidget; @@ -31,6 +34,14 @@ class QQuickWidget; namespace Calamares { +/** @brief API for Slideshow objects + * + * A Slideshow (subclass) object is created by the ExecutionViewStep + * and needs to manage its own configuration (e.g. from Branding). + * The slideshow is started and stopped when it becomes visible + * and when installation is over, by calling changeSlideShowState() + * as appropriate. + */ class Slideshow : public QObject { Q_OBJECT @@ -48,7 +59,7 @@ public: } virtual ~Slideshow(); - ///@brief Is the slideshow being shown **right now**? + /// @brief Is the slideshow being shown **right now**? bool isActive() const { return m_state == Start; } /** @brief The actual widget to show the user. @@ -70,6 +81,15 @@ protected: Action m_state = Stop; }; +/** @brief Slideshow using a QML file + * + * This is the "classic" slideshow in Calamares, which runs some QML + * while the installation is in progress. It is configured through + * Branding settings *slideshow* and *slideshowAPI*, showing the QML + * file from *slideshow*. The API version influences when and how the + * QML is loaded; version 1 does so only when the slideshow is activated, + * while version 2 does so asynchronously. + */ class SlideshowQML : public Slideshow { Q_OBJECT @@ -90,13 +110,32 @@ private: QQuickItem* m_qmlObject; ///< The actual show }; +/** @brief Slideshow using images + * + * This is an "oldschool" slideshow, but new in Calamares, which + * displays static image files one-by-one. It is for systems that + * do not use QML at all. It is configured through the Branding + * setting *slideshow*. When using this widget, the setting must + * be a list of filenames; the API is set to -1. + */ class SlideshowPictures : public Slideshow { + Q_OBJECT public: SlideshowPictures( QWidget* parent ); virtual ~SlideshowPictures() override; QWidget* widget() override; + virtual void changeSlideShowState( Action a ) override; + +public slots: + void next(); + +private: + QLabel* m_label; + QTimer* m_timer; + int m_imageIndex; + QStringList m_images; }; } // namespace Calamares