mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Prepare support for custom theme
This commit is contained in:
parent
b1ed3c26c0
commit
677e1f2f81
5 changed files with 39 additions and 10 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QtCore/QString>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
#include <memory>
|
||||
#include <qjsondocument.h>
|
||||
#include <qmap.h>
|
||||
|
||||
#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<QMLTaskItem> QMLTasks;
|
||||
QList<QMLTasksFile> QMLResources;
|
||||
QList<QMLTag> QMLTags;
|
||||
|
|
|
@ -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<std::unique_ptr<TaskItem>> tasks;
|
||||
bool isDirty_ = false;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
#endif
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ RowLayout {
|
|||
|
||||
function getFormatedText() {
|
||||
if (task?.time && task.time != "") {
|
||||
return `<font color=\"${"blue"}\">${task.time} \></font> ${task.text}`
|
||||
return `<font color=\"${colorPalette.selected.textPlaceholder}\">${task.time} \></font> ${task.text}`
|
||||
}
|
||||
return task.text
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue