[libcalamares] Implement reload-stylesheet

- From the debug-window, clicking *reload stylesheet* does just
   that, and applies the new stylesheet to the Calamares window.
 - Remove stylesheet caching from the Branding class; we only
   need the sheet once (on Calamares startup) or when updating
   the stylesheet, which is seldom-enough that we don't need
   to keep an extra copy around.
 - To use, start Calamares, open the debug window, open stylesheet.qss
   in an editor. Make changes, save, then click *reload stylesheet*.

SEE #1149
This commit is contained in:
Adriaan de Groot 2019-05-21 13:21:47 +02:00
parent 877cb0e999
commit ac941e6756
2 changed files with 25 additions and 16 deletions

View File

@ -239,16 +239,6 @@ Branding::Branding( const QString& brandingFilePath,
m_translationsPathPrefix.append( QString( "%1calamares-%2" ) m_translationsPathPrefix.append( QString( "%1calamares-%2" )
.arg( QDir::separator() ) .arg( QDir::separator() )
.arg( m_componentName ) ); .arg( m_componentName ) );
QFileInfo importQSSPath( componentDir.filePath( "stylesheet.qss" ) );
if ( importQSSPath.exists() && importQSSPath.isReadable() )
{
QFile stylesheetFile( importQSSPath.filePath() );
stylesheetFile.open( QFile::ReadOnly );
m_stylesheet = stylesheetFile.readAll();
}
else
cWarning() << "the branding component" << componentDir.absolutePath() << "does not ship stylesheet.qss.";
} }
else else
{ {
@ -310,6 +300,21 @@ Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const
return pixmap; return pixmap;
} }
QString
Branding::stylesheet() const
{
QFileInfo fi( m_descriptorPath );
QFileInfo importQSSPath( fi.absoluteDir().filePath( "stylesheet.qss" ) );
if ( importQSSPath.exists() && importQSSPath.isReadable() )
{
QFile stylesheetFile( importQSSPath.filePath() );
stylesheetFile.open( QFile::ReadOnly );
return stylesheetFile.readAll();
}
else
cWarning() << "The branding component" << fi.absoluteDir().absolutePath() << "does not ship stylesheet.qss.";
return QString();
}
void void
Branding::setGlobals( GlobalStorage* globalStorage ) const Branding::setGlobals( GlobalStorage* globalStorage ) const

View File

@ -123,8 +123,13 @@ public:
QString styleString( Branding::StyleEntry styleEntry ) const; QString styleString( Branding::StyleEntry styleEntry ) const;
QString imagePath( Branding::ImageEntry imageEntry ) const; QString imagePath( Branding::ImageEntry imageEntry ) const;
QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const;
/** @brief Stylesheet to apply for this branding. May be empty. */ /** @brief Stylesheet to apply for this branding. May be empty.
QString stylesheet() const { return m_stylesheet; } *
* The file is loaded every time this function is called, so
* it may be quite expensive -- although normally it will be
* called only once, on startup. (Or from the debug window)
*/
QString stylesheet() const;
bool welcomeStyleCalamares() const { return m_welcomeStyleCalamares; } bool welcomeStyleCalamares() const { return m_welcomeStyleCalamares; }
bool welcomeExpandingLogo() const { return m_welcomeExpandingLogo; } bool welcomeExpandingLogo() const { return m_welcomeExpandingLogo; }
@ -151,14 +156,13 @@ private:
[[noreturn]] void bail( const QString& message ); [[noreturn]] void bail( const QString& message );
QString m_descriptorPath; QString m_descriptorPath; // Path to descriptor (e.g. "/etc/calamares/default/branding.desc")
QString m_componentName; QString m_componentName; // Matches last part of full path to containing directory
QMap< QString, QString > m_strings; QMap< QString, QString > m_strings;
QMap< QString, QString > m_images; QMap< QString, QString > m_images;
QMap< QString, QString > m_style; QMap< QString, QString > m_style;
QString m_slideshowPath; QString m_slideshowPath;
QString m_translationsPathPrefix; QString m_translationsPathPrefix;
QString m_stylesheet; // Text from file
/** @brief Initialize the simple settings below */ /** @brief Initialize the simple settings below */
void initSimpleSettings( const YAML::Node& doc ); void initSimpleSettings( const YAML::Node& doc );