2017-10-14 09:35:49 +00:00
|
|
|
#include "Configuration.h"
|
2017-10-15 07:14:05 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2017-10-14 09:35:49 +00:00
|
|
|
|
|
|
|
Configuration* Configuration::mPtr = nullptr;
|
|
|
|
|
|
|
|
Configuration::Configuration() : QObject()
|
|
|
|
{
|
|
|
|
mPtr = this;
|
2017-10-15 07:14:05 +00:00
|
|
|
|
|
|
|
loadDefaultColors();
|
2017-10-14 09:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Configuration* Configuration::instance()
|
|
|
|
{
|
|
|
|
return mPtr;
|
|
|
|
}
|
|
|
|
|
2017-10-15 07:14:05 +00:00
|
|
|
void Configuration::loadDefaultColors()
|
|
|
|
{
|
2017-10-22 10:21:44 +00:00
|
|
|
Core()->cmd("eco cutter");
|
2017-10-15 07:14:05 +00:00
|
|
|
QJsonObject colors = Core()->cmdj("ecj").object();
|
|
|
|
for (auto color : colors.keys()) {
|
|
|
|
QJsonArray rgb = colors[color].toArray();
|
|
|
|
QColor col = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
|
|
|
s.setValue("colors." + color, col);
|
|
|
|
}
|
2017-10-22 10:21:44 +00:00
|
|
|
s.setValue("colors.gui.background", QColor(255, 255, 245));
|
|
|
|
s.setValue("colors.gui.alt_background", QColor(245, 250, 255));
|
2017-10-15 07:14:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 09:35:49 +00:00
|
|
|
const QFont Configuration::getFont() const
|
|
|
|
{
|
|
|
|
QFont font = s.value("font", QFont("Monospace", 12)).value<QFont>();
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::setFont(const QFont &font)
|
|
|
|
{
|
|
|
|
s.setValue("font", font);
|
|
|
|
emit fontsUpdated();
|
|
|
|
}
|
2017-10-15 07:14:05 +00:00
|
|
|
|
|
|
|
const QColor Configuration::getColor(const QString &name) const
|
|
|
|
{
|
|
|
|
if (s.contains("colors." + name)) {
|
|
|
|
return s.value("colors." + name).value<QColor>();
|
|
|
|
} else {
|
|
|
|
return s.value("colors.other").value<QColor>();
|
|
|
|
}
|
|
|
|
}
|