[calamares] Implement productWallpaper setting

- If we have a wallpaper, bung in an extra QWidget between the main
  window and the panels (sidebar, nav and main) where we set a
  stylesheet that displays the chosen image.
This commit is contained in:
Adriaan de Groot 2020-04-30 13:30:59 +02:00
parent 1d44c88e0a
commit 3d6e5c5df7
2 changed files with 46 additions and 24 deletions

View File

@ -61,11 +61,11 @@ windowDimensionToPixels( const Calamares::Branding::WindowDimension& u )
QWidget* QWidget*
CalamaresWindow::getWidgetSidebar( int desiredWidth ) CalamaresWindow::getWidgetSidebar( QWidget* parent, int desiredWidth )
{ {
const Calamares::Branding* const branding = Calamares::Branding::instance(); const Calamares::Branding* const branding = Calamares::Branding::instance();
QWidget* sideBox = new QWidget( this ); QWidget* sideBox = new QWidget( parent );
sideBox->setObjectName( "sidebarApp" ); sideBox->setObjectName( "sidebarApp" );
QBoxLayout* sideLayout = new QVBoxLayout; QBoxLayout* sideLayout = new QVBoxLayout;
@ -132,10 +132,10 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth )
} }
QWidget* QWidget*
CalamaresWindow::getQmlSidebar( int ) CalamaresWindow::getQmlSidebar( QWidget* parent, int )
{ {
CalamaresUtils::registerCalamaresModels(); CalamaresUtils::registerCalamaresModels();
QQuickWidget* w = new QQuickWidget( this ); QQuickWidget* w = new QQuickWidget( parent );
w->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); w->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
w->setResizeMode( QQuickWidget::SizeRootObjectToView ); w->setResizeMode( QQuickWidget::SizeRootObjectToView );
w->setSource( QUrl( w->setSource( QUrl(
@ -161,9 +161,9 @@ setButtonIcon( QPushButton* button, const QString& name )
} }
QWidget* QWidget*
CalamaresWindow::getWidgetNavigation() CalamaresWindow::getWidgetNavigation( QWidget* parent )
{ {
QWidget* navigation = new QWidget( this ); QWidget* navigation = new QWidget( parent );
QBoxLayout* bottomLayout = new QHBoxLayout; QBoxLayout* bottomLayout = new QHBoxLayout;
bottomLayout->addStretch(); bottomLayout->addStretch();
@ -213,10 +213,10 @@ CalamaresWindow::getWidgetNavigation()
} }
QWidget* QWidget*
CalamaresWindow::getQmlNavigation() CalamaresWindow::getQmlNavigation( QWidget* parent )
{ {
CalamaresUtils::registerCalamaresModels(); CalamaresUtils::registerCalamaresModels();
QQuickWidget* w = new QQuickWidget( this ); QQuickWidget* w = new QQuickWidget( parent );
w->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); w->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
w->setResizeMode( QQuickWidget::SizeRootObjectToView ); w->setResizeMode( QQuickWidget::SizeRootObjectToView );
w->setSource( QUrl( w->setSource( QUrl(
@ -234,6 +234,7 @@ template < typename widgetMaker, typename... args >
QWidget* QWidget*
flavoredWidget( Calamares::Branding::PanelFlavor flavor, flavoredWidget( Calamares::Branding::PanelFlavor flavor,
CalamaresWindow* w, CalamaresWindow* w,
QWidget* parent,
widgetMaker widget, widgetMaker widget,
widgetMaker qml, widgetMaker qml,
args... a ) args... a )
@ -242,9 +243,9 @@ flavoredWidget( Calamares::Branding::PanelFlavor flavor,
switch ( flavor ) switch ( flavor )
{ {
case Calamares::Branding::PanelFlavor::Widget: case Calamares::Branding::PanelFlavor::Widget:
return ( w->*widget )( a... ); return ( w->*widget )( parent, a... );
case Calamares::Branding::PanelFlavor::Qml: case Calamares::Branding::PanelFlavor::Qml:
return ( w->*qml )( a... ); return ( w->*qml )( parent, a... );
case Calamares::Branding::PanelFlavor::None: case Calamares::Branding::PanelFlavor::None:
return nullptr; return nullptr;
} }
@ -281,6 +282,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
: tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); ) : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); )
const Calamares::Branding* const branding = Calamares::Branding::instance(); const Calamares::Branding* const branding = Calamares::Branding::instance();
using ImageEntry = Calamares::Branding::ImageEntry;
using CalamaresUtils::windowMinimumHeight; using CalamaresUtils::windowMinimumHeight;
using CalamaresUtils::windowMinimumWidth; using CalamaresUtils::windowMinimumWidth;
@ -307,7 +309,23 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
cDebug() << Logger::SubEntry << "Proposed window size:" << w << h; cDebug() << Logger::SubEntry << "Proposed window size:" << w << h;
resize( w, h ); resize( w, h );
m_viewManager = Calamares::ViewManager::instance( this ); QWidget* baseWidget = this;
if ( !( branding->imagePath( ImageEntry::ProductWallpaper ).isEmpty() ) )
{
QWidget* label = new QWidget( this );
QVBoxLayout* l = new QVBoxLayout;
CalamaresUtils::unmarginLayout( l );
l->addWidget( label );
setLayout( l );
label->setObjectName( "backgroundWidget" );
label->setStyleSheet(
QStringLiteral( "#backgroundWidget { background-image: url(%1); background-repeat: repeat-xy; }" )
.arg( branding->imagePath( ImageEntry::ProductWallpaper ) ) );
baseWidget = label;
}
m_viewManager = Calamares::ViewManager::instance( baseWidget );
if ( branding->windowExpands() ) if ( branding->windowExpands() )
{ {
connect( m_viewManager, &Calamares::ViewManager::ensureSize, this, &CalamaresWindow::ensureSize ); connect( m_viewManager, &Calamares::ViewManager::ensureSize, this, &CalamaresWindow::ensureSize );
@ -328,11 +346,15 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
QWidget* sideBox = flavoredWidget( QWidget* sideBox = flavoredWidget(
branding->sidebarFlavor(), branding->sidebarFlavor(),
this, this,
baseWidget,
&CalamaresWindow::getWidgetSidebar, &CalamaresWindow::getWidgetSidebar,
&CalamaresWindow::getQmlSidebar, &CalamaresWindow::getQmlSidebar,
qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) );
QWidget* navigation = flavoredWidget( QWidget* navigation = flavoredWidget( branding->navigationFlavor(),
branding->navigationFlavor(), this, &CalamaresWindow::getWidgetNavigation, &CalamaresWindow::getQmlNavigation ); this,
baseWidget,
&CalamaresWindow::getWidgetNavigation,
&CalamaresWindow::getQmlNavigation );
// Build up the contentsLayout (a VBox) top-to-bottom // Build up the contentsLayout (a VBox) top-to-bottom
// .. note that the bottom is mirrored wrt. the top // .. note that the bottom is mirrored wrt. the top
@ -351,7 +373,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
CalamaresUtils::unmarginLayout( mainLayout ); CalamaresUtils::unmarginLayout( mainLayout );
CalamaresUtils::unmarginLayout( contentsLayout ); CalamaresUtils::unmarginLayout( contentsLayout );
setLayout( mainLayout ); baseWidget->setLayout( mainLayout );
setStyleSheet( Calamares::Branding::instance()->stylesheet() ); setStyleSheet( Calamares::Branding::instance()->stylesheet() );
} }

View File

@ -52,12 +52,12 @@ protected:
private: private:
// Two variations on sidebar (the progress view) // Two variations on sidebar (the progress view)
QWidget* getWidgetSidebar( int desiredWidth ); QWidget* getWidgetSidebar( QWidget* parent, int desiredWidth );
QWidget* getQmlSidebar( int desiredWidth ); QWidget* getQmlSidebar( QWidget* parent, int desiredWidth );
// Two variations on navigation (buttons at bottom) // Two variations on navigation (buttons at bottom)
QWidget* getWidgetNavigation(); QWidget* getWidgetNavigation( QWidget* parent );
QWidget* getQmlNavigation(); QWidget* getQmlNavigation( QWidget* parent );
QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self
Calamares::ViewManager* m_viewManager; Calamares::ViewManager* m_viewManager;