[libcalamaresui] Implement non-QML Slideshow

This commit is contained in:
Adriaan de Groot 2020-05-13 16:35:09 +02:00
parent e7f4479df1
commit df74604755
2 changed files with 129 additions and 3 deletions

View File

@ -26,11 +26,15 @@
#include "utils/Qml.h"
#include "utils/Retranslator.h"
#include <QLabel>
#include <QMutexLocker>
#include <QQmlComponent>
#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickWidget>
#include <QTimer>
#include <chrono>
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

View File

@ -22,8 +22,11 @@
#define LIBCALAMARESUI_SLIDESHOW_H
#include <QMutex>
#include <QStringList>
#include <QWidget>
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