Skip to content
Permalink
Browse files

Merge PR #2499: Themes: add support for user styles.

  • Loading branch information...
mkrautz committed Nov 17, 2016
2 parents 5e005a7 + c21518f commit 09a0f841e8e1877c5a137ec40852f5cd97dcfb38
Showing with 50 additions and 3 deletions.
  1. +40 −3 src/mumble/Themes.cpp
  2. +10 −0 src/mumble/Themes.h
@@ -53,7 +53,17 @@ void Themes::applyFallback() {
skinPaths << QLatin1String(":/");
QDir::setSearchPaths(QLatin1String("skin"), skinPaths);

qApp->setStyleSheet(getDefaultStylesheet());
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() {
@@ -78,9 +88,21 @@ bool Themes::applyConfigured() {
skinPaths << qssFile.path();
skinPaths << QLatin1String(":/"); // Some skins might want to fall-back on our built-in resources
QDir::setSearchPaths(QLatin1String("skin"), skinPaths);

QString themeQss = QString::fromUtf8(file.readAll());

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

qApp->setStyleSheet(QString::fromUtf8(file.readAll()));

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

return true;
}

@@ -117,6 +139,21 @@ QVector<QDir> Themes::getSearchDirectories() {
return themeSearchDirectories;
}

QString Themes::userStylesheetPath() {
return g.qdBasePath.absolutePath() + QLatin1String("/user.qss");
}

bool Themes::readStylesheet(const QString &stylesheetFn, QString &stylesheetContent) {
QFile file(stylesheetFn);
if (!file.open(QFile::ReadOnly)) {
stylesheetContent = QString();
return false;
}

stylesheetContent = QString::fromUtf8(file.readAll());
return true;
}

QString Themes::getDefaultStylesheet() {
return QLatin1String(".log-channel{text-decoration:none;}.log-user{text-decoration:none;}p{margin:0;}#qwMacWarning{background-color:#FFFEDC;border-radius:5px;border:1px solid #B5B59E;}");
}
@@ -50,6 +50,16 @@ class Themes {

/// Returns default style-sheet used for fall-backs
static QString getDefaultStylesheet();

/// userStylesheetPath returns the absolute path to the
/// user.qss file.
static QString userStylesheetPath();

/// readStylesheet fills stylesheetContent with the content
/// of the file at stylesheetFn, if available.
/// If a the file is is available, the function returns true.
/// If no file is available, it returns false.
static bool readStylesheet(const QString &stylesheetFn, QString &stylesheetContent);
};

#endif // MUMBLE_MUMBLE_THEMES_H_

0 comments on commit 09a0f84

Please sign in to comment.
You can’t perform that action at this time.