[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:
parent
877cb0e999
commit
ac941e6756
@ -153,7 +153,7 @@ Branding::Branding( const QString& brandingFilePath,
|
||||
|
||||
#ifdef WITH_KOSRelease
|
||||
KOSRelease relInfo;
|
||||
|
||||
|
||||
QHash< QString, QString > relMap{
|
||||
std::initializer_list< std::pair< QString, QString > > {
|
||||
{ QStringLiteral( "NAME" ), relInfo.name() },
|
||||
@ -239,16 +239,6 @@ Branding::Branding( const QString& brandingFilePath,
|
||||
m_translationsPathPrefix.append( QString( "%1calamares-%2" )
|
||||
.arg( QDir::separator() )
|
||||
.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
|
||||
{
|
||||
@ -310,6 +300,21 @@ Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const
|
||||
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
|
||||
Branding::setGlobals( GlobalStorage* globalStorage ) const
|
||||
|
@ -123,8 +123,13 @@ public:
|
||||
QString styleString( Branding::StyleEntry styleEntry ) const;
|
||||
QString imagePath( Branding::ImageEntry imageEntry ) const;
|
||||
QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const;
|
||||
/** @brief Stylesheet to apply for this branding. May be empty. */
|
||||
QString stylesheet() const { return m_stylesheet; }
|
||||
/** @brief Stylesheet to apply for this branding. May be empty.
|
||||
*
|
||||
* 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 welcomeExpandingLogo() const { return m_welcomeExpandingLogo; }
|
||||
@ -151,14 +156,13 @@ private:
|
||||
|
||||
[[noreturn]] void bail( const QString& message );
|
||||
|
||||
QString m_descriptorPath;
|
||||
QString m_componentName;
|
||||
QString m_descriptorPath; // Path to descriptor (e.g. "/etc/calamares/default/branding.desc")
|
||||
QString m_componentName; // Matches last part of full path to containing directory
|
||||
QMap< QString, QString > m_strings;
|
||||
QMap< QString, QString > m_images;
|
||||
QMap< QString, QString > m_style;
|
||||
QString m_slideshowPath;
|
||||
QString m_translationsPathPrefix;
|
||||
QString m_stylesheet; // Text from file
|
||||
|
||||
/** @brief Initialize the simple settings below */
|
||||
void initSimpleSettings( const YAML::Node& doc );
|
||||
|
Loading…
Reference in New Issue
Block a user