From a9f669e27ebac3e4a9186cadcd4a89c460896926 Mon Sep 17 00:00:00 2001 From: xarkes Date: Mon, 26 Feb 2018 23:25:23 +0100 Subject: [PATCH] Splitted Qt theme and color theme (now using eco/ecoj) --- radare2 | 2 +- src/MainWindow.cpp | 4 +- src/cutter.cpp | 12 +- src/cutter.h | 2 + .../preferences/GeneralOptionsWidget.cpp | 25 +- .../preferences/GeneralOptionsWidget.h | 1 + .../preferences/GeneralOptionsWidget.ui | 19 +- src/utils/Configuration.cpp | 224 ++++-------------- src/utils/Configuration.h | 5 +- src/widgets/DisassemblerGraphView.cpp | 2 +- src/widgets/DisassemblyWidget.cpp | 2 +- 11 files changed, 108 insertions(+), 190 deletions(-) diff --git a/radare2 b/radare2 index 06c519ea..70bd99da 160000 --- a/radare2 +++ b/radare2 @@ -1 +1 @@ -Subproject commit 06c519ead78a37aea46fab7443cdde41c6d3dd7b +Subproject commit 70bd99da259438fbe552b7debfe68c571cdcd2da diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d1923577..1bd37965 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -87,12 +87,12 @@ static void registerCustomFonts() MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - core(CutterCore::getInstance()), + core(Core()), ui(new Ui::MainWindow) { panelLock = false; tabsOnTop = false; - configuration = new Configuration(); + configuration = Config(); } MainWindow::~MainWindow() diff --git a/src/cutter.cpp b/src/cutter.cpp index f7ad5fbf..d89ecd25 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -824,8 +824,7 @@ void CutterCore::setSettings() setConfig("http.sandbox", false); // Colors - setConfig("scr.color", false); - setConfig("scr.truecolor", false); + setConfig("scr.color", COLOR_MODE_DISABLED); } QList CutterCore::getSeekHistory() @@ -1417,3 +1416,12 @@ QJsonArray CutterCore::getOpenedFiles() QJsonDocument files = cmdj("oj"); return files.array(); } + +QList CutterCore::getColorThemes() +{ + QList r; + QJsonDocument themes = cmdj("ecoj"); + for (auto s : themes.array()) + r << s.toString(); + return r; +} diff --git a/src/cutter.h b/src/cutter.h index 7ac9ba9f..c13b52b7 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -381,6 +381,8 @@ public: QString getVersionInformation(); QJsonArray getOpenedFiles(); + QList getColorThemes(); + RCoreLocked core() const; /* fields */ diff --git a/src/dialogs/preferences/GeneralOptionsWidget.cpp b/src/dialogs/preferences/GeneralOptionsWidget.cpp index 82e93c8e..0d40e91e 100644 --- a/src/dialogs/preferences/GeneralOptionsWidget.cpp +++ b/src/dialogs/preferences/GeneralOptionsWidget.cpp @@ -3,7 +3,7 @@ #include "GeneralOptionsWidget.h" #include "ui_GeneralOptionsWidget.h" - +#include #include "PreferencesDialog.h" #include "utils/Helpers.h" @@ -18,8 +18,8 @@ GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog */*dialog*/, QWidge updateFontFromConfig(); updateThemeFromConfig(); - connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig())); - connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); + //connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig())); + //connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); } GeneralOptionsWidget::~GeneralOptionsWidget() {} @@ -33,6 +33,15 @@ void GeneralOptionsWidget::updateFontFromConfig() void GeneralOptionsWidget::updateThemeFromConfig() { ui->themeComboBox->setCurrentIndex(Config()->getDarkTheme() ? 1 : 0); + + QList themes = Core()->getColorThemes(); + ui->colorComboBox->clear(); + ui->colorComboBox->addItem("default"); + for (QString str : themes) + ui->colorComboBox->addItem(str); + QString curTheme = Config()->getCurrentTheme(); + int index = themes.indexOf(curTheme) + 1; + ui->colorComboBox->setCurrentIndex(index); } void GeneralOptionsWidget::on_fontSelectionButton_clicked() @@ -47,7 +56,13 @@ void GeneralOptionsWidget::on_fontSelectionButton_clicked() void GeneralOptionsWidget::on_themeComboBox_currentIndexChanged(int index) { - disconnect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); + //disconnect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); Config()->setDarkTheme(index == 1); - connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); + //connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); +} + +void GeneralOptionsWidget::on_colorComboBox_currentIndexChanged(int index) +{ + QString theme = ui->colorComboBox->itemText(index); + Config()->setColorTheme(theme); } diff --git a/src/dialogs/preferences/GeneralOptionsWidget.h b/src/dialogs/preferences/GeneralOptionsWidget.h index 8d979256..3cb91a90 100644 --- a/src/dialogs/preferences/GeneralOptionsWidget.h +++ b/src/dialogs/preferences/GeneralOptionsWidget.h @@ -32,6 +32,7 @@ private slots: void on_fontSelectionButton_clicked(); void on_themeComboBox_currentIndexChanged(int index); + void on_colorComboBox_currentIndexChanged(int index); }; diff --git a/src/dialogs/preferences/GeneralOptionsWidget.ui b/src/dialogs/preferences/GeneralOptionsWidget.ui index f75f509e..af65c2e7 100644 --- a/src/dialogs/preferences/GeneralOptionsWidget.ui +++ b/src/dialogs/preferences/GeneralOptionsWidget.ui @@ -59,7 +59,7 @@ - Theme: + Qt Theme: @@ -83,6 +83,23 @@ + + + + Color theme + + + + + + + + 0 + 0 + + + + diff --git a/src/utils/Configuration.cpp b/src/utils/Configuration.cpp index 15d1425d..c7e12b54 100644 --- a/src/utils/Configuration.cpp +++ b/src/utils/Configuration.cpp @@ -15,6 +15,8 @@ Configuration::Configuration() : QObject() Configuration* Configuration::instance() { + if (!mPtr) + mPtr = new Configuration(); return mPtr; } @@ -37,193 +39,34 @@ void Configuration::resetAll() void Configuration::loadDefaultTheme() { - QColor color0 = QColor(0, 0, 0); - QColor color1 = QColor(0, 0, 255); - QColor color2 = QColor(0, 128, 0); - QColor color3 = QColor(255, 0, 0); - QColor color4 = QColor(127, 0, 127); - QColor color5 = QColor(95, 95, 175); - QColor color6 = QColor(255, 235, 95); - QColor color7 = QColor(215, 135, 0); - QColor color8 = QColor(108, 108, 108); - QColor color9 = QColor(96, 48, 0); - QColor colorA = QColor(50, 140, 255); - - QColor highlightColor = QColor(210, 210, 255); - - // Instructions - setColor("comment", color4); - setColor("usrcmt", color2); - setColor("args", color5); - setColor("fname", color1); - setColor("floc", color6); - setColor("fline", color2); - setColor("flag", color1); - setColor("label", color7); - setColor("help", color1); - setColor("flow", color2); - setColor("flow2", color2); - setColor("prompt", color0); - setColor("offset", color0); - setColor("input", color0); - setColor("invalid", color3); - setColor("other", color1); - setColor("b0x00", color8); - setColor("b0x7f", color0); - setColor("b0xff", color3); - setColor("math", color1); - setColor("bin", color1); - setColor("btext", color0); - setColor("push", color0); - setColor("pop", color0); - setColor("crypto", color4); - setColor("jmp", color2); - setColor("cjmp", color2); - setColor("call", color9); - setColor("nop", color1); - setColor("ret", color9); - setColor("trap", color3); - setColor("swi", color2); - setColor("cmp", color0); - setColor("reg", color1); - setColor("creg", color1); - setColor("num", color1); - setColor("mov", color0); - - // AI - setColor("ai.read", color0); - setColor("ai.write", color0); - setColor("ai.exec", color0); - setColor("ai.seq", color0); - setColor("ai.ascii", color0); - - // Graphs - setColor("graph.box", color0); - setColor("graph.box2", color2); - setColor("graph.box3", color3); - setColor("graph.box4", color0); - setColor("graph.true", color2); - setColor("graph.false", color3); - setColor("graph.trufae", color0); - setColor("graph.current", color0); - setColor("graph.traced", color3); - - // GUI - setColor("gui.cflow", color0); - setColor("gui.dataoffset", color0); - setColor("gui.border", color0); - setColor("highlight", highlightColor); - // Windows background - setColor("gui.background", QColor(255, 255, 255)); - // Disassembly nodes background - setColor("gui.alt_background", QColor(245, 250, 255)); - // Custom - setColor("gui.imports", colorA); - setColor("gui.main", color2); - 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)); - /* Load Qt Theme */ qApp->setStyleSheet(""); /* Images */ logoFile = QString(":/img/cutter_plain.svg"); -} - -void Configuration::loadDarkTheme() -{ - QColor color0 = QColor(255, 255, 255); - QColor color1 = QColor(100, 180, 255); - QColor color2 = QColor(0, 255, 0); - QColor color3 = QColor(255, 0, 0); - QColor color4 = QColor(128, 235, 200); - QColor color5 = QColor(95, 95, 175); - QColor color6 = QColor(255, 235, 95); - QColor color7 = QColor(255, 130, 0); - QColor color8 = QColor(108, 108, 108); - QColor color9 = QColor(255, 130, 0); - QColor colorA = QColor(50, 140, 255); - - QColor highlightColor = QColor(64, 115, 115); - - // Instructions - setColor("comment", color4); - setColor("usrcmt", color2); - setColor("args", color5); - setColor("fname", color1); - setColor("floc", color6); - setColor("fline", color2); - setColor("flag", color1); - setColor("label", color7); - setColor("help", color1); - setColor("flow", color2); - setColor("flow2", color2); - setColor("prompt", color0); - setColor("offset", color0); - setColor("input", color0); - setColor("invalid", color3); - setColor("other", color1); - setColor("b0x00", color8); - setColor("b0x7f", color0); - setColor("b0xff", color3); - setColor("math", color1); - setColor("bin", color1); - setColor("btext", color0); - setColor("push", color0); - setColor("pop", color0); - setColor("crypto", color4); - setColor("jmp", color2); - setColor("cjmp", color2); - setColor("call", color9); - setColor("nop", color1); - setColor("ret", color9); - setColor("trap", color3); - setColor("swi", color2); - setColor("cmp", color0); - setColor("reg", color1); - setColor("creg", color1); - setColor("num", color1); - setColor("mov", color0); - - // AI - setColor("ai.read", color0); - setColor("ai.write", color0); - setColor("ai.exec", color0); - setColor("ai.seq", color0); - setColor("ai.ascii", color0); - - // Graphs - setColor("graph.box", color0); - setColor("graph.box2", color2); - setColor("graph.box3", color3); - setColor("graph.box4", color0); - setColor("graph.true", color2); - setColor("graph.false", color3); - setColor("graph.trufae", color0); - setColor("graph.current", color0); - setColor("graph.traced", color3); + /* Colors */ // GUI - setColor("gui.cflow", color0); - setColor("gui.dataoffset", color0); - setColor("gui.border", color0); - setColor("highlight", highlightColor); + 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)); // Windows background - setColor("gui.background", QColor(36, 66, 79)); + setColor("gui.background", QColor(255, 255, 255)); // Disassembly nodes background - setColor("gui.alt_background", QColor(58, 100, 128)); + setColor("gui.alt_background", QColor(245, 250, 255)); // Custom - setColor("gui.imports", colorA); - setColor("gui.main", color2); + 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)); +} +void Configuration::loadDarkTheme() +{ /* Load Qt Theme */ QFile f(":qdarkstyle/style.qss"); if (!f.exists()) @@ -249,6 +92,25 @@ void Configuration::loadDarkTheme() /* Images */ logoFile = QString(":/img/cutter_white_plain.svg"); + + /* 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)); } const QFont Configuration::getFont() const @@ -290,15 +152,25 @@ QString Configuration::getLogoFile() /** * @brief Configuration::setColor sets the local Cutter configuration color - * and the radare2 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); - // R2 does not support truecolor properly - QString col = QString("rgb:%1%2%3").arg(color.red() >> 4, 1, 16).arg(color.green() >> 4, 1, 16).arg(color.blue() >> 4, 1, 16); - // Not clean but this is a private function so name should NEVER be a bad input - Core()->cmd("ec " + name + " " + col); +} + +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(); } diff --git a/src/utils/Configuration.h b/src/utils/Configuration.h index 9c656289..1996aa07 100644 --- a/src/utils/Configuration.h +++ b/src/utils/Configuration.h @@ -13,7 +13,7 @@ class Configuration : public QObject Q_OBJECT private: QSettings s; - static Configuration* mPtr; + static Configuration *mPtr; void loadInitial(); @@ -115,6 +115,9 @@ public: int getAsmTabs() const { return s.value("asm.tabs", 5).toInt(); } void setAsmTabs(int v) { s.setValue("asm.tabs", v); } + QString getCurrentTheme() const { return s.value("theme", "default").toString(); } + void setColorTheme(QString theme); + signals: void fontsUpdated(); void colorsUpdated(); diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index a2b287fa..9470919f 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -121,7 +121,7 @@ void DisassemblerGraphView::loadCurrentGraph() { TempConfig tempConfig; tempConfig.set("scr.html", true) - .set("scr.color", true) + .set("scr.color", COLOR_MODE_16M) .set("asm.bbline", false) .set("asm.lines", false) .set("asm.fcnlines", false); diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index bf8f54da..92a1ef7b 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -189,7 +189,7 @@ void DisassemblyWidget::refreshDisasm(RVA offset) { TempConfig tempConfig; tempConfig.set("scr.html", true) - .set("scr.color", true); + .set("scr.color", COLOR_MODE_16M); disassemblyLines = Core()->disassembleLines(topOffset, maxLines); }