Skip to content

Commit

Permalink
customizable stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Feb 23, 2022
1 parent aa12c1f commit 34ade7d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/local/localmodpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ QString LocalModPath::modsJsonFilePath() const
void LocalModPath::loadMods(bool autoLoaderType)
{
if(isLoading_) return;
qDebug() << "load" << info_.displayName();
loaded_ = true;
isLoading_ = true;
modsLinker_.reset();
Expand Down
29 changes: 27 additions & 2 deletions src/qss/stylesheets.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include "stylesheets.h"

#include <QObject>
#include <QStandardPaths>
#include <QDir>
#include <QDebug>

const QMap<QString, QString> &styleSheets()
const QString &styleSheetsPath()
{
static auto path = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation))
.absoluteFilePath("stylesheets");
return path;
}

const QMap<QString, QString> &builtinStyleSheets()
{
static const QMap<QString, QString> stylesheets{
{ "basic", QObject::tr("Basic") },
Expand All @@ -12,9 +22,24 @@ const QMap<QString, QString> &styleSheets()
return stylesheets;
}

QMap<QString, QString> styleSheets()
{
auto styleSheets = builtinStyleSheets();
for(auto &&fileInfo : QDir(styleSheetsPath()).entryInfoList())
if(fileInfo.suffix() == "qss"){
auto name = fileInfo.baseName();
if(!styleSheets.contains(name))
styleSheets.insert(name, name);
}
return styleSheets;
}

QString styleSheetPath(const QString &name)
{
if(!styleSheets().contains(name))
return QString("file:///:/stylesheet/%1.qss").arg("basic");
return QString("file:///:/stylesheet/%1.qss").arg(name);
auto fileName = QDir(styleSheetsPath()).absoluteFilePath(name + ".qss");
if(!QFileInfo(fileName).exists() && builtinStyleSheets().contains(name))
return QString("file:///:/stylesheet/%1.qss").arg(name);
return fileName;
}
5 changes: 4 additions & 1 deletion src/qss/stylesheets.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#define STYLESHEETS_H
#include <QMap>

const QMap<QString, QString> &styleSheets();
const QString &styleSheetsPath();

const QMap<QString, QString> &builtinStyleSheets();
QMap<QString, QString> styleSheets();

QString styleSheetPath(const QString &name);
#endif // STYLESHEETS_H
3 changes: 2 additions & 1 deletion src/ui/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Preferences::Preferences(QWidget *parent) :
#if !defined (Q_OS_WIN)
ui->useFramelessWindow->setVisible(false);
#endif
for(auto it = styleSheets().cbegin(); it != styleSheets().cend(); it++){
auto s = styleSheets();
for(auto it = s.cbegin(); it != s.cend(); it++){
ui->customStyle->addItem(it.value());
ui->customStyle->setItemData(ui->customStyle->count() - 1, it.key());
}
Expand Down

0 comments on commit 34ade7d

Please sign in to comment.