diff --git a/src/Backend.cpp b/src/Backend.cpp index a751b27..13f1d8d 100644 --- a/src/Backend.cpp +++ b/src/Backend.cpp @@ -35,15 +35,15 @@ Backend::Backend() : todoView(&mirai) if (loadFile.open(QIODevice::ReadOnly)) { QByteArray loadData = loadFile.readAll(); - QJsonDocument json = QJsonDocument::fromJson(loadData); + configJson = QJsonDocument::fromJson(loadData); loadFile.close(); - if (!json.isObject()) { + if (!configJson.isObject()) { qWarning() << "config.json is not a valid config file"; exit(1); } - QJsonObject jsonRootObject = json.object(); + QJsonObject jsonRootObject = configJson.object(); - auto jsonFilesPath = json["files"]; + auto jsonFilesPath = configJson["files"]; if (!jsonFilesPath.isArray()) { qWarning() << "config.json should contains a 'files' string array"; exit(1); @@ -60,7 +60,7 @@ Backend::Backend() : todoView(&mirai) ); } - auto jsonTagsConfig = json["tags"]; + auto jsonTagsConfig = configJson["tags"]; if (jsonTagsConfig.isObject()) { for (auto &jsonTagConfigKey : jsonTagsConfig.toObject().keys()) { tagsConfig[jsonTagConfigKey] = @@ -341,6 +341,8 @@ void Backend::saveConfig() } rootJson["tags"] = tagsJson; + rootJson["theme"] = configJson["theme"]; + QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); QFile configFile(getConfigFilePath()); if (!configFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { @@ -357,3 +359,23 @@ QString Backend::getConfigFilePath() const QString configFolder = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); return configFolder + "/config.json"; } + +QString Backend::getThemeColor(QString themeElementName) +{ + if (configJson["theme"].isNull()) { + std::cerr << "Warning: theme in config is null" << std::endl; + return ""; + } + + if (!configJson["theme"].isObject()) { + std::cerr << "Warning: theme in config is not an object" << std::endl; + return ""; + } + + if (!configJson["theme"].toObject()[themeElementName].isString()) { + std::cerr << "Warning: element " << themeElementName.toStdString() + << " in theme in config is not valid" << std::endl; + return ""; + } + return configJson["theme"].toObject()[themeElementName].toString(); +} diff --git a/src/Backend.h b/src/Backend.h index 3753725..393790a 100644 --- a/src/Backend.h +++ b/src/Backend.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "TaskItem.h" @@ -56,6 +57,7 @@ class Backend : public QObject Q_INVOKABLE QString getTagColor(QString tag); Q_INVOKABLE void saveTagsColor(QVariant tags); Q_INVOKABLE void saveFilesPath(QVariant filesPath); + Q_INVOKABLE QString getThemeColor(QString themeElementName); private: void rebuildQMLTasksList(); @@ -73,6 +75,7 @@ class Backend : public QObject // Both Todo and Calendar view use the todoView for now. mirai::TasksView todoView; + QJsonDocument configJson; QList QMLTasks; QList QMLResources; QList QMLTags; diff --git a/src/core/BaseResource.h b/src/core/BaseResource.h index cff2c15..c20baac 100644 --- a/src/core/BaseResource.h +++ b/src/core/BaseResource.h @@ -18,7 +18,7 @@ namespace mirai class BaseResource { public: - BaseResource(std::string name) : name(name){}; + BaseResource(std::string name) : name(name) {}; BaseResource(BaseResource &) = delete; BaseResource(BaseResource &&) = delete; @@ -48,5 +48,6 @@ class BaseResource std::vector> tasks; bool isDirty_ = false; }; + } // namespace mirai #endif diff --git a/src/qml/Main.qml b/src/qml/Main.qml index a8fc928..41b28dd 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -28,9 +28,12 @@ Window { id: colorPalette property QtObject selected: OneDark - function selectStyle(styleName) { - // TODO - selected = OneDark; + function applyCustomThemeFromConfig() { + //console.log(backend.getThemeColor("text")) + } + + Component.onCompleted: { + applyCustomThemeFromConfig() } } diff --git a/src/qml/TaskItem.qml b/src/qml/TaskItem.qml index 799935c..1ca6dbf 100644 --- a/src/qml/TaskItem.qml +++ b/src/qml/TaskItem.qml @@ -15,7 +15,7 @@ RowLayout { function getFormatedText() { if (task?.time && task.time != "") { - return `${task.time} \> ${task.text}` + return `${task.time} \> ${task.text}` } return task.text }