Skip to content

Commit

Permalink
Merge PR #3595: Refactor themes.cpp and themes.h
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebeatrici committed Feb 9, 2019
2 parents 1fb1e9c + bdfda03 commit ba08786
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/mumble/Themes.cpp
Expand Up @@ -51,19 +51,9 @@ void Themes::applyFallback() {


QStringList skinPaths; QStringList skinPaths;
skinPaths << QLatin1String(":/themes/Mumble"); skinPaths << QLatin1String(":/themes/Mumble");
QDir::setSearchPaths(QLatin1String("skin"), skinPaths); QString defaultTheme = getDefaultStylesheet();

setTheme(defaultTheme, skinPaths);
QString userStylesheetFn = userStylesheetPath();
QString userStylesheetContent;
if (readStylesheet(userStylesheetFn, userStylesheetContent)) {
qWarning("Themes: allowing user stylesheet at '%s' to override fallback stylesheet", qPrintable(userStylesheetFn));
}


qApp->setStyleSheet(
getDefaultStylesheet() +
QLatin1String("\n") +
userStylesheetContent
);
} }


bool Themes::applyConfigured() { bool Themes::applyConfigured() {
Expand All @@ -87,14 +77,19 @@ bool Themes::applyConfigured() {
QStringList skinPaths; QStringList skinPaths;
skinPaths << qssFile.path(); skinPaths << qssFile.path();
skinPaths << QLatin1String(":/themes/Mumble"); // Some skins might want to fall-back on our built-in resources skinPaths << QLatin1String(":/themes/Mumble"); // Some skins might want to fall-back on our built-in resources
QDir::setSearchPaths(QLatin1String("skin"), skinPaths);


QString themeQss = QString::fromUtf8(file.readAll()); QString themeQss = QString::fromUtf8(file.readAll());
setTheme(themeQss, skinPaths);
return true;
}


void Themes::setTheme(QString &themeQss, QStringList &skinPaths) {
QDir::setSearchPaths(QLatin1String("skin"), skinPaths);

QString userStylesheetFn = userStylesheetPath(); QString userStylesheetFn = userStylesheetPath();
QString userStylesheetContent; QString userStylesheetContent;
if (readStylesheet(userStylesheetFn, userStylesheetContent)) { if (readStylesheet(userStylesheetFn, userStylesheetContent)) {
qWarning("Themes: allowing user stylesheet at '%s' to override the chosen theme", qPrintable(userStylesheetFn)); qWarning("Themes: allowing user stylesheet at '%s' to override the stylesheet", qPrintable(userStylesheetFn));
} }


qApp->setStyleSheet( qApp->setStyleSheet(
Expand All @@ -103,7 +98,6 @@ bool Themes::applyConfigured() {
userStylesheetContent userStylesheetContent
); );


return true;
} }


bool Themes::apply() { bool Themes::apply() {
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/Themes.h
Expand Up @@ -45,6 +45,9 @@ class Themes {
/// @return True on success. False on failure. /// @return True on success. False on failure.
static bool applyConfigured(); static bool applyConfigured();


// Sets the theme to a QSS theme
static void setTheme(QString &themeQss, QStringList &skinPaths);

/// Returns list of theme search directories ordered ascending by priorty (lowest first) /// Returns list of theme search directories ordered ascending by priorty (lowest first)
static QVector<QDir> getSearchDirectories(); static QVector<QDir> getSearchDirectories();


Expand Down

0 comments on commit ba08786

Please sign in to comment.