2017-10-14 09:35:49 +00:00
|
|
|
#include "Configuration.h"
|
2017-10-15 07:14:05 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2017-11-20 20:20:31 +00:00
|
|
|
#include <QFontDatabase>
|
2018-01-09 11:03:07 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QApplication>
|
2017-10-14 09:35:49 +00:00
|
|
|
|
|
|
|
Configuration* Configuration::mPtr = nullptr;
|
|
|
|
|
|
|
|
Configuration::Configuration() : QObject()
|
|
|
|
{
|
|
|
|
mPtr = this;
|
2017-12-03 12:10:09 +00:00
|
|
|
loadInitial();
|
2017-10-14 09:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Configuration* Configuration::instance()
|
|
|
|
{
|
2018-02-26 22:25:23 +00:00
|
|
|
if (!mPtr)
|
|
|
|
mPtr = new Configuration();
|
2017-10-14 09:35:49 +00:00
|
|
|
return mPtr;
|
|
|
|
}
|
|
|
|
|
2017-12-03 12:10:09 +00:00
|
|
|
void Configuration::loadInitial()
|
|
|
|
{
|
2017-12-14 15:14:33 +00:00
|
|
|
setDarkTheme(getDarkTheme());
|
2017-12-03 12:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::resetAll()
|
|
|
|
{
|
|
|
|
s.clear();
|
2017-12-03 12:48:51 +00:00
|
|
|
Core()->cmd("e-");
|
|
|
|
Core()->setSettings();
|
|
|
|
Core()->resetDefaultAsmOptions();
|
|
|
|
|
2017-12-03 12:10:09 +00:00
|
|
|
loadInitial();
|
|
|
|
emit fontsUpdated();
|
2017-12-03 12:48:51 +00:00
|
|
|
Core()->triggerAsmOptionsChanged();
|
2017-12-03 12:10:09 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
void Configuration::loadDefaultTheme()
|
2017-10-15 07:14:05 +00:00
|
|
|
{
|
2018-02-26 22:25:23 +00:00
|
|
|
/* Load Qt Theme */
|
|
|
|
qApp->setStyleSheet("");
|
2017-11-20 11:23:37 +00:00
|
|
|
|
2018-02-26 22:25:23 +00:00
|
|
|
/* Images */
|
|
|
|
logoFile = QString(":/img/cutter_plain.svg");
|
2017-11-20 11:23:37 +00:00
|
|
|
|
2018-02-26 22:25:23 +00:00
|
|
|
/* Colors */
|
2017-11-20 11:23:37 +00:00
|
|
|
// GUI
|
2018-02-26 22:25:23 +00:00
|
|
|
setColor("gui.cflow", QColor(0, 0, 0));
|
|
|
|
setColor("gui.dataoffset", QColor(0, 0, 0));
|
|
|
|
setColor("gui.border", QColor(0, 0, 0));
|
|
|
|
setColor("highlight", QColor(210, 210, 255));
|
2017-11-20 11:23:37 +00:00
|
|
|
// Windows background
|
|
|
|
setColor("gui.background", QColor(255, 255, 255));
|
|
|
|
// Disassembly nodes background
|
|
|
|
setColor("gui.alt_background", QColor(245, 250, 255));
|
2017-12-20 15:40:46 +00:00
|
|
|
// Custom
|
2018-02-26 22:25:23 +00:00
|
|
|
setColor("gui.imports", QColor(50, 140, 255));
|
|
|
|
setColor("gui.main", QColor(0, 128, 0));
|
2018-02-01 16:06:30 +00:00
|
|
|
setColor("gui.navbar.err", QColor(255, 0, 0));
|
|
|
|
setColor("gui.navbar.code", QColor(104, 229, 69));
|
|
|
|
setColor("gui.navbar.str", QColor(69, 104, 229));
|
|
|
|
setColor("gui.navbar.sym", QColor(229, 150, 69));
|
|
|
|
setColor("gui.navbar.empty", QColor(100, 100, 100));
|
2017-11-20 11:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::loadDarkTheme()
|
|
|
|
{
|
2018-01-09 11:03:07 +00:00
|
|
|
/* Load Qt Theme */
|
|
|
|
QFile f(":qdarkstyle/style.qss");
|
|
|
|
if (!f.exists())
|
|
|
|
{
|
|
|
|
qWarning() << "Can't find dark theme stylesheet.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.open(QFile::ReadOnly | QFile::Text);
|
|
|
|
QTextStream ts(&f);
|
2018-02-03 20:00:31 +00:00
|
|
|
QString stylesheet = ts.readAll();
|
|
|
|
#ifdef Q_OS_MACX
|
|
|
|
// see https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/22#issuecomment-96179529
|
|
|
|
stylesheet += "QDockWidget::title"
|
|
|
|
"{"
|
|
|
|
" background-color: #31363b;"
|
|
|
|
" text-align: center;"
|
|
|
|
" height: 12px;"
|
|
|
|
"}";
|
|
|
|
#endif
|
|
|
|
qApp->setStyleSheet(stylesheet);
|
2018-01-09 11:03:07 +00:00
|
|
|
}
|
2018-02-12 12:22:53 +00:00
|
|
|
|
|
|
|
/* Images */
|
|
|
|
logoFile = QString(":/img/cutter_white_plain.svg");
|
2018-02-26 22:25:23 +00:00
|
|
|
|
|
|
|
/* Colors */
|
|
|
|
// GUI
|
|
|
|
setColor("gui.cflow", QColor(255, 255, 255));
|
|
|
|
setColor("gui.dataoffset", QColor(255, 255, 255));
|
|
|
|
setColor("gui.border", QColor(255, 255, 255));
|
|
|
|
setColor("highlight", QColor(64, 115, 115));
|
|
|
|
// Windows background
|
|
|
|
setColor("gui.background", QColor(36, 66, 79));
|
|
|
|
// Disassembly nodes background
|
|
|
|
setColor("gui.alt_background", QColor(58, 100, 128));
|
|
|
|
// Custom
|
|
|
|
setColor("gui.imports", QColor(50, 140, 255));
|
|
|
|
setColor("gui.main", QColor(0, 128, 0));
|
|
|
|
setColor("gui.navbar.err", QColor(255, 0, 0));
|
|
|
|
setColor("gui.navbar.code", QColor(104, 229, 69));
|
|
|
|
setColor("gui.navbar.str", QColor(69, 104, 229));
|
|
|
|
setColor("gui.navbar.sym", QColor(229, 150, 69));
|
|
|
|
setColor("gui.navbar.empty", QColor(100, 100, 100));
|
2017-10-15 07:14:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 09:35:49 +00:00
|
|
|
const QFont Configuration::getFont() const
|
|
|
|
{
|
2018-01-31 15:36:09 +00:00
|
|
|
QFont font = s.value("font", QFont("Inconsolata", 12)).value<QFont>();
|
2017-10-14 09:35:49 +00:00
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::setFont(const QFont &font)
|
|
|
|
{
|
|
|
|
s.setValue("font", font);
|
|
|
|
emit fontsUpdated();
|
|
|
|
}
|
2017-10-15 07:14:05 +00:00
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
void Configuration::setDarkTheme(bool set)
|
|
|
|
{
|
|
|
|
s.setValue("dark", set);
|
|
|
|
if (set) {
|
|
|
|
loadDarkTheme();
|
|
|
|
} else {
|
|
|
|
loadDefaultTheme();
|
|
|
|
}
|
|
|
|
emit colorsUpdated();
|
|
|
|
}
|
|
|
|
|
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>();
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 11:23:37 +00:00
|
|
|
|
2018-02-12 12:22:53 +00:00
|
|
|
QString Configuration::getLogoFile()
|
|
|
|
{
|
|
|
|
return logoFile;
|
|
|
|
}
|
|
|
|
|
2017-11-20 11:23:37 +00:00
|
|
|
/**
|
|
|
|
* @brief Configuration::setColor sets the local Cutter configuration color
|
|
|
|
* @param name Color Name
|
|
|
|
* @param color The color you want to set
|
|
|
|
*/
|
|
|
|
void Configuration::setColor(const QString &name, const QColor &color)
|
|
|
|
{
|
|
|
|
s.setValue("colors." + name, color);
|
2018-02-26 22:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::setColorTheme(QString theme)
|
|
|
|
{
|
|
|
|
if (theme == "default")
|
|
|
|
{
|
|
|
|
Core()->cmd("ecd");
|
|
|
|
s.setValue("theme", "default");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Core()->cmd(QString("eco %1").arg(theme));
|
|
|
|
s.setValue("theme", theme);
|
|
|
|
}
|
|
|
|
emit colorsUpdated();
|
2017-11-20 11:23:37 +00:00
|
|
|
}
|