libcalamaresui: support Qt6 QMLViewStep
This commit is contained in:
parent
628c98becb
commit
4a5e7af9a4
@ -24,7 +24,12 @@
|
|||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
#include <QQuickWindow>
|
||||||
|
#else
|
||||||
#include <QQuickWidget>
|
#include <QQuickWidget>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
@ -66,16 +71,22 @@ QmlViewStep::QmlViewStep( QObject* parent )
|
|||||||
: ViewStep( parent )
|
: ViewStep( parent )
|
||||||
, m_widget( new QWidget )
|
, m_widget( new QWidget )
|
||||||
, m_spinner( new WaitingWidget( tr( "Loading ..." ) ) )
|
, m_spinner( new WaitingWidget( tr( "Loading ..." ) ) )
|
||||||
, m_qmlWidget( new QQuickWidget )
|
|
||||||
{
|
{
|
||||||
Calamares::registerQmlModels();
|
Calamares::registerQmlModels();
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
m_qmlEngine = new QQmlEngine( this );
|
||||||
|
#else
|
||||||
|
m_qmlWidget = new QQuickWidget;
|
||||||
|
m_qmlWidget->setResizeMode( QQuickWidget::SizeRootObjectToView );
|
||||||
|
m_qmlWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||||
|
m_qmlEngine = m_qmlWidget->engine();
|
||||||
|
#endif
|
||||||
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
||||||
layout->addWidget( m_spinner );
|
layout->addWidget( m_spinner );
|
||||||
|
|
||||||
m_qmlWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
m_qmlEngine->addImportPath( Calamares::qmlModulesDir().absolutePath() );
|
||||||
m_qmlWidget->setResizeMode( QQuickWidget::SizeRootObjectToView );
|
|
||||||
m_qmlWidget->engine()->addImportPath( Calamares::qmlModulesDir().absolutePath() );
|
|
||||||
|
|
||||||
// QML Loading starts when the configuration for the module is set.
|
// QML Loading starts when the configuration for the module is set.
|
||||||
}
|
}
|
||||||
@ -181,11 +192,20 @@ QmlViewStep::loadComplete()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
auto* quick = new QQuickWindow;
|
||||||
|
auto* root = quick->contentItem();
|
||||||
|
m_qmlObject->setParentItem( root );
|
||||||
|
m_qmlObject->bindableWidth().setBinding( [ = ]() { return root->width(); } );
|
||||||
|
m_qmlObject->bindableHeight().setBinding( [ = ]() { return root->height(); } );
|
||||||
|
m_qmlWidget = QWidget::createWindowContainer( quick, m_widget );
|
||||||
|
#else
|
||||||
// setContent() is public API, but not documented publicly.
|
// setContent() is public API, but not documented publicly.
|
||||||
// It is marked \internal in the Qt sources, but does exactly
|
// It is marked \internal in the Qt sources, but does exactly
|
||||||
// what is needed: sets up visual parent by replacing the root
|
// what is needed: sets up visual parent by replacing the root
|
||||||
// item, and handling resizes.
|
// item, and handling resizes.
|
||||||
m_qmlWidget->setContent( QUrl( m_qmlFileName ), m_qmlComponent, m_qmlObject );
|
m_qmlWidget->setContent( QUrl( m_qmlFileName ), m_qmlComponent, m_qmlObject );
|
||||||
|
#endif
|
||||||
showQml();
|
showQml();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,8 +261,8 @@ QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName;
|
cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName;
|
||||||
m_qmlComponent = new QQmlComponent(
|
m_qmlComponent
|
||||||
m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous );
|
= new QQmlComponent( m_qmlEngine, QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous );
|
||||||
connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete );
|
connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete );
|
||||||
if ( m_qmlComponent->status() == QQmlComponent::Error )
|
if ( m_qmlComponent->status() == QQmlComponent::Error )
|
||||||
{
|
{
|
||||||
@ -275,7 +295,7 @@ QmlViewStep::getConfig()
|
|||||||
void
|
void
|
||||||
QmlViewStep::setContextProperty( const char* name, QObject* property )
|
QmlViewStep::setContextProperty( const char* name, QObject* property )
|
||||||
{
|
{
|
||||||
m_qmlWidget->engine()->rootContext()->setContextProperty( name, property );
|
m_qmlEngine->rootContext()->setContextProperty( name, property );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "viewpages/ViewStep.h"
|
#include "viewpages/ViewStep.h"
|
||||||
|
|
||||||
class QQmlComponent;
|
class QQmlComponent;
|
||||||
|
class QQmlEngine;
|
||||||
class QQuickItem;
|
class QQuickItem;
|
||||||
class QQuickWidget;
|
class QQuickWidget;
|
||||||
class WaitingWidget;
|
class WaitingWidget;
|
||||||
@ -109,7 +110,14 @@ private:
|
|||||||
|
|
||||||
QWidget* m_widget = nullptr;
|
QWidget* m_widget = nullptr;
|
||||||
WaitingWidget* m_spinner = nullptr;
|
WaitingWidget* m_spinner = nullptr;
|
||||||
QQuickWidget* m_qmlWidget = nullptr;
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
|
QWidget* m_qmlWidget = nullptr; // Qt6: container for QQuickWindow
|
||||||
|
#else
|
||||||
|
QQuickWidget * m_qmlWidget = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QQmlEngine* m_qmlEngine = nullptr; // Qt5: points to QuickWidget engine, Qt6: separate engine
|
||||||
QQmlComponent* m_qmlComponent = nullptr;
|
QQmlComponent* m_qmlComponent = nullptr;
|
||||||
QQuickItem* m_qmlObject = nullptr;
|
QQuickItem* m_qmlObject = nullptr;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user