mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13: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)) {
|
if (loadFile.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray loadData = loadFile.readAll();
|
QByteArray loadData = loadFile.readAll();
|
||||||
QJsonDocument json = QJsonDocument::fromJson(loadData);
|
configJson = QJsonDocument::fromJson(loadData);
|
||||||
loadFile.close();
|
loadFile.close();
|
||||||
if (!json.isObject()) {
|
if (!configJson.isObject()) {
|
||||||
qWarning() << "config.json is not a valid config file";
|
qWarning() << "config.json is not a valid config file";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
QJsonObject jsonRootObject = json.object();
|
QJsonObject jsonRootObject = configJson.object();
|
||||||
|
|
||||||
auto jsonFilesPath = json["files"];
|
auto jsonFilesPath = configJson["files"];
|
||||||
if (!jsonFilesPath.isArray()) {
|
if (!jsonFilesPath.isArray()) {
|
||||||
qWarning() << "config.json should contains a 'files' string array";
|
qWarning() << "config.json should contains a 'files' string array";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -60,7 +60,7 @@ Backend::Backend() : todoView(&mirai)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto jsonTagsConfig = json["tags"];
|
auto jsonTagsConfig = configJson["tags"];
|
||||||
if (jsonTagsConfig.isObject()) {
|
if (jsonTagsConfig.isObject()) {
|
||||||
for (auto &jsonTagConfigKey : jsonTagsConfig.toObject().keys()) {
|
for (auto &jsonTagConfigKey : jsonTagsConfig.toObject().keys()) {
|
||||||
tagsConfig[jsonTagConfigKey] =
|
tagsConfig[jsonTagConfigKey] =
|
||||||
|
@ -341,6 +341,8 @@ void Backend::saveConfig()
|
||||||
}
|
}
|
||||||
rootJson["tags"] = tagsJson;
|
rootJson["tags"] = tagsJson;
|
||||||
|
|
||||||
|
rootJson["theme"] = configJson["theme"];
|
||||||
|
|
||||||
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
||||||
QFile configFile(getConfigFilePath());
|
QFile configFile(getConfigFilePath());
|
||||||
if (!configFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (!configFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
|
@ -357,3 +359,23 @@ QString Backend::getConfigFilePath() const
|
||||||
QString configFolder = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
QString configFolder = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||||
return configFolder + "/config.json";
|
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 <QtCore/QString>
|
||||||
#include <QtQml/qqmlregistration.h>
|
#include <QtQml/qqmlregistration.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <qjsondocument.h>
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
|
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
|
@ -56,6 +57,7 @@ class Backend : public QObject
|
||||||
Q_INVOKABLE QString getTagColor(QString tag);
|
Q_INVOKABLE QString getTagColor(QString tag);
|
||||||
Q_INVOKABLE void saveTagsColor(QVariant tags);
|
Q_INVOKABLE void saveTagsColor(QVariant tags);
|
||||||
Q_INVOKABLE void saveFilesPath(QVariant filesPath);
|
Q_INVOKABLE void saveFilesPath(QVariant filesPath);
|
||||||
|
Q_INVOKABLE QString getThemeColor(QString themeElementName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rebuildQMLTasksList();
|
void rebuildQMLTasksList();
|
||||||
|
@ -73,6 +75,7 @@ class Backend : public QObject
|
||||||
// Both Todo and Calendar view use the todoView for now.
|
// Both Todo and Calendar view use the todoView for now.
|
||||||
mirai::TasksView todoView;
|
mirai::TasksView todoView;
|
||||||
|
|
||||||
|
QJsonDocument configJson;
|
||||||
QList<QMLTaskItem> QMLTasks;
|
QList<QMLTaskItem> QMLTasks;
|
||||||
QList<QMLTasksFile> QMLResources;
|
QList<QMLTasksFile> QMLResources;
|
||||||
QList<QMLTag> QMLTags;
|
QList<QMLTag> QMLTags;
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace mirai
|
||||||
class BaseResource
|
class BaseResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseResource(std::string name) : name(name){};
|
BaseResource(std::string name) : name(name) {};
|
||||||
BaseResource(BaseResource &) = delete;
|
BaseResource(BaseResource &) = delete;
|
||||||
BaseResource(BaseResource &&) = delete;
|
BaseResource(BaseResource &&) = delete;
|
||||||
|
|
||||||
|
@ -48,5 +48,6 @@ class BaseResource
|
||||||
std::vector<std::unique_ptr<TaskItem>> tasks;
|
std::vector<std::unique_ptr<TaskItem>> tasks;
|
||||||
bool isDirty_ = false;
|
bool isDirty_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,9 +28,12 @@ Window {
|
||||||
id: colorPalette
|
id: colorPalette
|
||||||
property QtObject selected: OneDark
|
property QtObject selected: OneDark
|
||||||
|
|
||||||
function selectStyle(styleName) {
|
function applyCustomThemeFromConfig() {
|
||||||
// TODO
|
//console.log(backend.getThemeColor("text"))
|
||||||
selected = OneDark;
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
applyCustomThemeFromConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ RowLayout {
|
||||||
|
|
||||||
function getFormatedText() {
|
function getFormatedText() {
|
||||||
if (task?.time && task.time != "") {
|
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
|
return task.text
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue