[libcalamaresui] activate -> change state
- since we also need to *disable* the shortcuts, and should tell a V1 slideshow that it no longer is running, - use existing function to set the property to true / false depending. - instead of changeState( true ) or changeStage( false ), use meaningful enum names so that the code at the call site becomes readable; make the boolean part internal to the state-changing method.
This commit is contained in:
parent
1e3e53d30a
commit
be5388abcd
@ -179,28 +179,53 @@ ExecutionViewStep::loadQmlV2()
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activateSlideShow( QQuickItem* slideshow, QQuickWidget* widget)
|
||||
/// @brief State-change of the slideshow, for changeSlideShowState()
|
||||
enum class Slideshow
|
||||
{
|
||||
Start,
|
||||
Stop
|
||||
};
|
||||
|
||||
/** @brief Tells the slideshow we activated or left the show.
|
||||
*
|
||||
* If @p state is @c Slideshow::Start, calls suitable activation procedures.
|
||||
* If @p state is @c Slideshow::Stop, calls deactivation procedures.
|
||||
*
|
||||
* Applies V1 and V2 QML activation / deactivation:
|
||||
* - V1 loads the QML in @p widget on activation. Sets root object property
|
||||
* *activatedInCalamares* as appropriate.
|
||||
* - V2 calls onActivate() or onLeave() in the QML as appropriate. Also
|
||||
* sets the *activatedInCalamares* property.
|
||||
*/
|
||||
static void
|
||||
changeSlideShowState( Slideshow state, QQuickItem* slideshow, QQuickWidget* widget )
|
||||
{
|
||||
bool activate = state == Slideshow::Start;
|
||||
|
||||
if ( Branding::instance()->slideshowAPI() == 2 )
|
||||
{
|
||||
// The QML was already loaded in the constructor, need to start it
|
||||
callQMLFunction( slideshow, "onActivate" );
|
||||
callQMLFunction( slideshow, activate ? "onActivate" : "onLeave" );
|
||||
}
|
||||
else if ( !Calamares::Branding::instance()->slideshowPath().isEmpty() )
|
||||
{
|
||||
// API version 1 assumes onCompleted is the trigger
|
||||
widget->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) );
|
||||
if ( activate )
|
||||
{
|
||||
widget->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) );
|
||||
}
|
||||
// needs the root object for property setting, below
|
||||
slideshow = widget->rootObject();
|
||||
}
|
||||
|
||||
|
||||
// V1 API has picked up the root object for use, V2 passed it in.
|
||||
if ( slideshow )
|
||||
{
|
||||
static const char propertyName[] = "activatedInCalamares";
|
||||
auto active = slideshow->property( propertyName );
|
||||
if ( active.isValid() && ( active.type() == QVariant::Bool ) && !active.toBool() )
|
||||
auto property = slideshow->property( propertyName );
|
||||
if ( property.isValid() && ( property.type() == QVariant::Bool ) && ( property.toBool() != activate ) )
|
||||
{
|
||||
slideshow->setProperty( propertyName, true );
|
||||
slideshow->setProperty( propertyName, activate );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,7 +248,7 @@ ExecutionViewStep::loadQmlV2Complete()
|
||||
else
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "Loading" << Calamares::Branding::instance()->slideshowPath();
|
||||
|
||||
|
||||
// setContent() is public API, but not documented publicly.
|
||||
// It is marked \internal in the Qt sources, but does exactly
|
||||
// what is needed: sets up visual parent by replacing the root
|
||||
@ -234,7 +259,7 @@ ExecutionViewStep::loadQmlV2Complete()
|
||||
{
|
||||
// We're alreay visible! Must have been slow QML loading, and we
|
||||
// passed onActivate already.
|
||||
activateSlideShow( m_qmlObject, m_qmlShow );
|
||||
changeSlideShowState( Slideshow::Start, m_qmlObject, m_qmlShow );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,7 +268,7 @@ ExecutionViewStep::loadQmlV2Complete()
|
||||
void
|
||||
ExecutionViewStep::onActivate()
|
||||
{
|
||||
activateSlideShow( m_qmlObject, m_qmlShow );
|
||||
changeSlideShowState( Slideshow::Start, m_qmlObject, m_qmlShow );
|
||||
|
||||
JobQueue* queue = JobQueue::instance();
|
||||
foreach ( const QString& instanceKey, m_jobInstanceKeys )
|
||||
@ -291,10 +316,10 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
|
||||
void
|
||||
ExecutionViewStep::onLeave()
|
||||
{
|
||||
changeSlideShowState( Slideshow::Stop, m_qmlObject, m_qmlShow );
|
||||
// API version 2 is explicitly stopped; version 1 keeps running
|
||||
if ( Branding::instance()->slideshowAPI() == 2 )
|
||||
{
|
||||
callQMLFunction( m_qmlObject, "onLeave" );
|
||||
delete m_qmlObject;
|
||||
m_qmlObject = nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user