style: format

This commit is contained in:
2026-01-15 00:30:51 +01:00
parent ed469b74f9
commit e98c0f42cc
7 changed files with 96 additions and 35 deletions
+61
View File
@@ -0,0 +1,61 @@
BasedOnStyle: Google
AccessModifierOffset: -2
AlignConsecutiveAssignments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Regroup
SortIncludes: true
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
InsertNewlineAtEOF: true
MaxEmptyLinesToKeep: 1
TabWidth: 4
UseTab: Never
SeparateDefinitionBlocks: Always
QualifierAlignment: Left
+29 -29
View File
@@ -17,11 +17,11 @@
#include "logger.h" #include "logger.h"
using namespace GeneralLogger; using namespace GeneralLogger;
static QString expandPath(const QString &path); static QString expandPath(const QString& path);
const QString Config::s_DefaultConfigFileName = "config.json"; const QString Config::s_DefaultConfigFileName = "config.json";
Config::Config(const QString &configDir, const QStringList &searchDirs, QObject *parent) Config::Config(const QString& configDir, const QStringList& searchDirs, QObject* parent)
: QObject(parent), m_configDir(configDir) { : QObject(parent), m_configDir(configDir) {
info(QString("Loading configuration from: %1").arg(configDir)); info(QString("Loading configuration from: %1").arg(configDir));
_loadConfig(configDir + QDir::separator() + s_DefaultConfigFileName); _loadConfig(configDir + QDir::separator() + s_DefaultConfigFileName);
@@ -36,7 +36,7 @@ Config::Config(const QString &configDir, const QStringList &searchDirs, QObject
Config::~Config() { Config::~Config() {
} }
void Config::_loadConfig(const QString &configPath) { void Config::_loadConfig(const QString& configPath) {
QFile configFile(configPath); QFile configFile(configPath);
if (!configFile.open(QIODevice::ReadOnly)) { if (!configFile.open(QIODevice::ReadOnly)) {
error(QString("Failed to open config file: %1").arg(configPath)); error(QString("Failed to open config file: %1").arg(configPath));
@@ -56,12 +56,12 @@ void Config::_loadConfig(const QString &configPath) {
struct ConfigMapping { struct ConfigMapping {
QString path; QString path;
QString key; QString key;
std::function<void(const QJsonValue &)> parser; std::function<void(const QJsonValue&)> parser;
}; };
static const auto parseJsonArray = [](const QJsonValue &val, QStringList &list) { static const auto parseJsonArray = [](const QJsonValue& val, QStringList& list) {
if (val.isArray()) { if (val.isArray()) {
for (const auto &item : val.toArray()) { for (const auto& item : val.toArray()) {
if (item.isString()) { if (item.isString()) {
list.append(::expandPath(item.toString())); list.append(::expandPath(item.toString()));
} }
@@ -71,58 +71,58 @@ void Config::_loadConfig(const QString &configPath) {
std::vector<ConfigMapping> std::vector<ConfigMapping>
mappings = { mappings = {
{"wallpaper.paths", "paths", [this](const QJsonValue &val) { {"wallpaper.paths", "paths", [this](const QJsonValue& val) {
parseJsonArray(val, m_wallpaperConfig.paths); parseJsonArray(val, m_wallpaperConfig.paths);
}}, }},
{"wallpaper.dirs", "dirs", [this](const QJsonValue &val) { {"wallpaper.dirs", "dirs", [this](const QJsonValue& val) {
parseJsonArray(val, m_wallpaperConfig.dirs); parseJsonArray(val, m_wallpaperConfig.dirs);
}}, }},
{"wallpaper.excludes", "excludes", [this](const QJsonValue &val) { {"wallpaper.excludes", "excludes", [this](const QJsonValue& val) {
parseJsonArray(val, m_wallpaperConfig.excludes); parseJsonArray(val, m_wallpaperConfig.excludes);
}}, }},
{"action.confirm", "confirm", [this](const QJsonValue &val) { {"action.confirm", "confirm", [this](const QJsonValue& val) {
if (val.isString()) { if (val.isString()) {
m_actionConfig.confirm = ::expandPath(val.toString()); m_actionConfig.confirm = ::expandPath(val.toString());
info(QString("Action confirm: %1").arg(m_actionConfig.confirm), GeneralLogger::STEP); info(QString("Action confirm: %1").arg(m_actionConfig.confirm), GeneralLogger::STEP);
} }
}}, }},
{"style.aspect_ratio", "aspect_ratio", [this](const QJsonValue &val) { {"style.aspect_ratio", "aspect_ratio", [this](const QJsonValue& val) {
if (val.isDouble() && val.toDouble() > 0) { if (val.isDouble() && val.toDouble() > 0) {
m_styleConfig.aspectRatio = val.toDouble(); m_styleConfig.aspectRatio = val.toDouble();
info(QString("Aspect ratio: %1").arg(m_styleConfig.aspectRatio), GeneralLogger::STEP); info(QString("Aspect ratio: %1").arg(m_styleConfig.aspectRatio), GeneralLogger::STEP);
} }
}}, }},
{"style.image_width", "image_width", [this](const QJsonValue &val) { {"style.image_width", "image_width", [this](const QJsonValue& val) {
if (val.isDouble() && val.toDouble() > 0) { if (val.isDouble() && val.toDouble() > 0) {
m_styleConfig.imageWidth = val.toInt(); m_styleConfig.imageWidth = val.toInt();
info(QString("Image width: %1").arg(m_styleConfig.imageWidth), GeneralLogger::STEP); info(QString("Image width: %1").arg(m_styleConfig.imageWidth), GeneralLogger::STEP);
} }
}}, }},
{"style.image_focus_width", "image_focus_width", [this](const QJsonValue &val) { {"style.image_focus_width", "image_focus_width", [this](const QJsonValue& val) {
if (val.isDouble() && val.toDouble() > 0) { if (val.isDouble() && val.toDouble() > 0) {
m_styleConfig.imageFocusWidth = val.toInt(); m_styleConfig.imageFocusWidth = val.toInt();
info(QString("Image focus width: %1").arg(m_styleConfig.imageFocusWidth), GeneralLogger::STEP); info(QString("Image focus width: %1").arg(m_styleConfig.imageFocusWidth), GeneralLogger::STEP);
} }
}}, }},
{"style.window_width", "window_width", [this](const QJsonValue &val) { {"style.window_width", "window_width", [this](const QJsonValue& val) {
if (val.isDouble() && val.toDouble() > 0) { if (val.isDouble() && val.toDouble() > 0) {
m_styleConfig.windowWidth = val.toInt(); m_styleConfig.windowWidth = val.toInt();
info(QString("Window width: %1").arg(m_styleConfig.windowWidth), GeneralLogger::STEP); info(QString("Window width: %1").arg(m_styleConfig.windowWidth), GeneralLogger::STEP);
} }
}}, }},
{"style.window_height", "window_height", [this](const QJsonValue &val) { {"style.window_height", "window_height", [this](const QJsonValue& val) {
if (val.isDouble() && val.toDouble() > 0) { if (val.isDouble() && val.toDouble() > 0) {
m_styleConfig.windowHeight = val.toInt(); m_styleConfig.windowHeight = val.toInt();
info(QString("Window height: %1").arg(m_styleConfig.windowHeight), GeneralLogger::STEP); info(QString("Window height: %1").arg(m_styleConfig.windowHeight), GeneralLogger::STEP);
} }
}}, }},
{"style.no_loading_screen", "no_loading_screen", [this](const QJsonValue &val) { {"style.no_loading_screen", "no_loading_screen", [this](const QJsonValue& val) {
if (val.isBool()) { if (val.isBool()) {
m_styleConfig.noLoadingScreen = val.toBool(); m_styleConfig.noLoadingScreen = val.toBool();
info(QString("No loading screen: %1").arg(m_styleConfig.noLoadingScreen), GeneralLogger::STEP); info(QString("No loading screen: %1").arg(m_styleConfig.noLoadingScreen), GeneralLogger::STEP);
} }
}}, }},
{"sort.type", "type", [this](const QJsonValue &val) { {"sort.type", "type", [this](const QJsonValue& val) {
if (val.isString()) { if (val.isString()) {
QString type = val.toString().toLower(); QString type = val.toString().toLower();
if (type == "none") { if (type == "none") {
@@ -139,7 +139,7 @@ void Config::_loadConfig(const QString &configPath) {
} }
info(QString("Sort type: %1").arg(static_cast<int>(m_sortConfig.type)), GeneralLogger::STEP); info(QString("Sort type: %1").arg(static_cast<int>(m_sortConfig.type)), GeneralLogger::STEP);
}}, }},
{"sort.reverse", "reverse", [this](const QJsonValue &val) { {"sort.reverse", "reverse", [this](const QJsonValue& val) {
if (val.isBool()) { if (val.isBool()) {
m_sortConfig.reverse = val.toBool(); m_sortConfig.reverse = val.toBool();
info(QString("Sort reverse: %1").arg(m_sortConfig.reverse), GeneralLogger::STEP); info(QString("Sort reverse: %1").arg(m_sortConfig.reverse), GeneralLogger::STEP);
@@ -148,7 +148,7 @@ void Config::_loadConfig(const QString &configPath) {
}; };
// 统一解析 // 统一解析
for (const auto &mapping : mappings) { for (const auto& mapping : mappings) {
([&mapping, &jsonObj]() { ([&mapping, &jsonObj]() {
auto pathParts = mapping.path.split('.'); auto pathParts = mapping.path.split('.');
@@ -165,7 +165,7 @@ void Config::_loadConfig(const QString &configPath) {
} }
// 获取目标值 // 获取目标值
const QString &finalKey = pathParts.last(); const QString& finalKey = pathParts.last();
if (currentObj.contains(finalKey)) { if (currentObj.contains(finalKey)) {
mapping.parser(currentObj[finalKey]); mapping.parser(currentObj[finalKey]);
} else { } else {
@@ -181,16 +181,16 @@ void Config::_loadWallpapers() {
QSet<QString> paths; QSet<QString> paths;
info(QString("Loading wallpapers from %1 specified paths").arg(m_wallpaperConfig.paths.size()), LogIndent::STEP); info(QString("Loading wallpapers from %1 specified paths").arg(m_wallpaperConfig.paths.size()), LogIndent::STEP);
for (const QString &path : m_wallpaperConfig.paths) { for (const QString& path : m_wallpaperConfig.paths) {
paths.insert(path); paths.insert(path);
} }
info(QString("Loading wallpapers from %1 specified directories").arg(m_wallpaperConfig.dirs.size()), LogIndent::STEP); info(QString("Loading wallpapers from %1 specified directories").arg(m_wallpaperConfig.dirs.size()), LogIndent::STEP);
for (const QString &dirPath : m_wallpaperConfig.dirs) { for (const QString& dirPath : m_wallpaperConfig.dirs) {
QDir dir(dirPath); QDir dir(dirPath);
if (dir.exists()) { if (dir.exists()) {
QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
for (const QString &file : files) { for (const QString& file : files) {
QString filePath = dir.filePath(file); QString filePath = dir.filePath(file);
paths.insert(filePath); paths.insert(filePath);
} }
@@ -200,12 +200,12 @@ void Config::_loadWallpapers() {
} }
info(QString("Excluding %1 specified paths").arg(m_wallpaperConfig.excludes.size()), LogIndent::STEP); info(QString("Excluding %1 specified paths").arg(m_wallpaperConfig.excludes.size()), LogIndent::STEP);
for (const QString &exclude : m_wallpaperConfig.excludes) { for (const QString& exclude : m_wallpaperConfig.excludes) {
paths.remove(exclude); paths.remove(exclude);
} }
m_wallpapers.reserve(paths.size()); m_wallpapers.reserve(paths.size());
for (const QString &path : paths) { for (const QString& path : paths) {
if (isValidImageFile(path)) { if (isValidImageFile(path)) {
m_wallpapers.append(path); m_wallpapers.append(path);
} }
@@ -214,7 +214,7 @@ void Config::_loadWallpapers() {
info(QString("Found %1 wallpapers").arg(paths.size())); info(QString("Found %1 wallpapers").arg(paths.size()));
} }
bool Config::isValidImageFile(const QString &filePath) { bool Config::isValidImageFile(const QString& filePath) {
static const QStringList validExtensions = { static const QStringList validExtensions = {
".jpg", ".jpg",
".jpeg", ".jpeg",
@@ -240,7 +240,7 @@ bool Config::isValidImageFile(const QString &filePath) {
return false; return false;
} }
// check if valid extension // check if valid extension
for (const QString &ext : validExtensions) { for (const QString& ext : validExtensions) {
if (filePath.endsWith(ext, Qt::CaseInsensitive)) { if (filePath.endsWith(ext, Qt::CaseInsensitive)) {
return true; return true;
} }
@@ -249,7 +249,7 @@ bool Config::isValidImageFile(const QString &filePath) {
return false; return false;
} }
static QString expandPath(const QString &path) { static QString expandPath(const QString& path) {
QString expandedPath = path; QString expandedPath = path;
if (expandedPath.startsWith("~/")) { if (expandedPath.startsWith("~/")) {
@@ -272,4 +272,4 @@ static QString expandPath(const QString &path) {
} }
return QDir::cleanPath(expandedPath); return QDir::cleanPath(expandedPath);
} }
+1 -1
View File
@@ -6,7 +6,7 @@
*/ */
#include "loading_indicator.h" #include "loading_indicator.h"
LoadingIndicator::LoadingIndicator(QWidget *parent) : QWidget(parent), LoadingIndicator::LoadingIndicator(QWidget* parent) : QWidget(parent),
ui(new Ui::LoadingIndicator) { ui(new Ui::LoadingIndicator) {
ui->setupUi(this); ui->setupUi(this);
} }
+2 -2
View File
@@ -19,7 +19,7 @@ class LoadingIndicator : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit LoadingIndicator(QWidget *parent = nullptr); explicit LoadingIndicator(QWidget* parent = nullptr);
~LoadingIndicator(); ~LoadingIndicator();
void setMaximum(int max) { ui->progressBar->setMaximum(max); } void setMaximum(int max) { ui->progressBar->setMaximum(max); }
@@ -27,7 +27,7 @@ class LoadingIndicator : public QWidget {
void setValue(int value) { ui->progressBar->setValue(value); } void setValue(int value) { ui->progressBar->setValue(value); }
private: private:
Ui::LoadingIndicator *ui; Ui::LoadingIndicator* ui;
}; };
#endif // LOADING_INDICATOR_H #endif // LOADING_INDICATOR_H
+1 -1
View File
@@ -109,4 +109,4 @@ void GeneralLogger::warn(const QString& msg, const GeneralLogger::LogIndent inde
void GeneralLogger::error(const QString& msg, const GeneralLogger::LogIndent indent) { void GeneralLogger::error(const QString& msg, const GeneralLogger::LogIndent indent) {
QString indentedMsg = QString(" ").repeated(indent) + msg; QString indentedMsg = QString(" ").repeated(indent) + msg;
qCCritical(logMain).noquote() << indentedMsg; qCCritical(logMain).noquote() << indentedMsg;
} }
+1 -1
View File
@@ -40,4 +40,4 @@ class Logger {
static GeneralLogger::LogIndent maxIndent(); static GeneralLogger::LogIndent maxIndent();
}; };
#endif // GENERAL_LOGGER_H #endif // GENERAL_LOGGER_H
+1 -1
View File
@@ -26,4 +26,4 @@ class Defer {
} }
}; };
#endif // UTILS_H #endif // UTILS_H