Colors modifications

This commit is contained in:
xarkes 2017-11-20 12:23:37 +01:00
parent 3a4e87ca41
commit 84168cb340
9 changed files with 152 additions and 49 deletions

View File

@ -391,11 +391,11 @@ void MainWindow::toggleTheme()
{
if (QSettings().value("dark").toBool())
{
def_theme();
setDefaultTheme();
}
else
{
dark();
setDarkTheme();
}
}
@ -456,28 +456,19 @@ void MainWindow::readSettings()
restoreState(state);
if (settings.value("dark").toBool())
{
this->dark();
this->setDarkTheme();
}
this->responsive = settings.value("responsive").toBool();
}
void MainWindow::dark()
void MainWindow::setDarkTheme()
{
qApp->setStyleSheet("QPlainTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} QTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} ");
// Call Config() rather than QSettings
QSettings settings;
settings.setValue("dark", true);
// TODO: emit a signal for theme
Config()->setDarkTheme(true);
}
void MainWindow::def_theme()
void MainWindow::setDefaultTheme()
{
qApp->setStyleSheet("");
QSettings settings;
settings.setValue("dark", false);
// TODO: emit a signal for theme
Config()->setDarkTheme(false);
}
@ -834,12 +825,12 @@ void MainWindow::on_actionRun_Script_triggered()
void MainWindow::on_actionDark_Theme_triggered()
{
this->dark();
this->setDarkTheme();
}
void MainWindow::on_actionWhite_Theme_triggered()
{
this->def_theme();
this->setDefaultTheme();
}
void MainWindow::on_actionSDBBrowser_triggered()

View File

@ -86,9 +86,8 @@ public slots:
void refreshAll();
void dark();
void def_theme();
void setDarkTheme();
void setDefaultTheme();
void on_actionEntry_points_triggered();
void on_actionFunctions_triggered();

View File

@ -849,8 +849,8 @@ void CutterCore::setSettings()
//setConfig("bin.rawstr", "true");
// Colors
setConfig("scr.color", false);
setConfig("scr.truecolor", true);
setConfig("scr.color", true);
setConfig("scr.truecolor", false);
}
QList<RVA> CutterCore::getSeekHistory()

View File

@ -7,8 +7,7 @@ Configuration* Configuration::mPtr = nullptr;
Configuration::Configuration() : QObject()
{
mPtr = this;
loadDefaultColors();
loadDefaultTheme();
}
Configuration* Configuration::instance()
@ -16,17 +15,92 @@ Configuration* Configuration::instance()
return mPtr;
}
void Configuration::loadDefaultColors()
void Configuration::loadDefaultTheme()
{
Core()->cmd("eco cutter");
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);
}
s.setValue("colors.gui.background", QColor(255, 255, 245));
s.setValue("colors.gui.alt_background", QColor(245, 250, 255));
QColor color0 = QColor(0, 0, 0);
QColor color1 = QColor(0, 0, 255);
QColor color2 = QColor(0, 255, 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(255, 128, 0);
// 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", color0);
// Windows background
setColor("gui.background", QColor(255, 255, 255));
// Disassembly nodes background
setColor("gui.alt_background", QColor(245, 250, 255));
}
void Configuration::loadDarkTheme()
{
setColor("gui.background", QColor(36, 66, 79));
setColor("gui.alt_background", QColor(58, 155, 196));
}
const QFont Configuration::getFont() const
@ -41,6 +115,17 @@ void Configuration::setFont(const QFont &font)
emit fontsUpdated();
}
void Configuration::setDarkTheme(bool set)
{
s.setValue("dark", set);
if (set) {
loadDarkTheme();
} else {
loadDefaultTheme();
}
emit colorsUpdated();
}
const QColor Configuration::getColor(const QString &name) const
{
if (s.contains("colors." + name)) {
@ -49,3 +134,18 @@ const QColor Configuration::getColor(const QString &name) const
return s.value("colors.other").value<QColor>();
}
}
/**
* @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);
}

View File

@ -15,7 +15,10 @@ private:
QSettings s;
static Configuration* mPtr;
void loadDefaultColors();
// Colors
void loadDefaultTheme();
void loadDarkTheme();
void setColor(const QString &name, const QColor &color);
public:
// Functions
@ -28,6 +31,7 @@ public:
// Colors
const QColor getColor(const QString &name) const;
void setDarkTheme(bool set);
// TODO Imho it's wrong doing it this way. Should find something else.
bool getAsmESIL() const { return s.value("asm.esil", false).toBool(); }
@ -74,6 +78,7 @@ public:
signals:
void fontsUpdated();
void colorsUpdated();
};
#endif // CONFIGURATION_H

View File

@ -85,7 +85,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
//connect(Bridge::getBridge(), SIGNAL(focusGraph()), this, SLOT(setFocus()));
//Connect to config
//connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
//connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(shortcutsUpdatedSlot()));
//connect(Config(), SIGNAL(tokenizerConfigUpdated()), this, SLOT(tokenizerConfigUpdatedSlot()));
@ -1777,10 +1777,10 @@ void DisassemblerGraphView::followDisassemblerSlot()
void DisassemblerGraphView::colorsUpdatedSlot()
{
disassemblyBackgroundColor = ConfigColor("gui.background");
disassemblyBackgroundColor = ConfigColor("gui.alt_background");
mDisabledBreakpointColor = disassemblyBackgroundColor;
graphNodeColor = ConfigColor("gui.border");
backgroundColor = ConfigColor("gui.alt_background");
backgroundColor = ConfigColor("gui.background");
disassemblySelectionColor = ConfigColor("gui.highlight");
jmpColor = ConfigColor("graph.trufae");

View File

@ -30,6 +30,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
setAllowedAreas(Qt::AllDockWidgetAreas);
setObjectName("DisassemblyWidget");
colorsUpdatedSlot();
mDisasTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mDisasTextEdit->setFont(Config()->getFont());
@ -42,7 +43,6 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
QTextDocument *asm_docu = mDisasTextEdit->document();
asm_docu->setDocumentMargin(10);
// Event filter to intercept double clicks in the textbox
mDisasTextEdit->viewport()->installEventFilter(this);
@ -81,6 +81,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
if (visibility)
@ -214,13 +215,12 @@ void DisassemblyWidget::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
// Highlight the current line in yellow
// Highlight the current line
if (mDisasTextEdit->isReadOnly())
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(190, 144, 212);
QColor lineColor = ConfigColor("gui.highlight");
lineColor.setAlpha(128);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = mDisasTextEdit->textCursor();
@ -234,8 +234,9 @@ void DisassemblyWidget::highlightCurrentLine()
QTextEdit::ExtraSelection currentWord;
QColor blueColor = QColor(Qt::blue).lighter(160);
currentWord.format.setBackground(blueColor);
QColor highlightColor = ConfigColor("comment");
highlightColor.setAlpha(128);
currentWord.format.setBackground(highlightColor);
currentWord.cursor = cursor;
extraSelections.append(currentWord);
@ -248,7 +249,7 @@ void DisassemblyWidget::highlightCurrentLine()
//QTextCursor highlightCursor(document);
QTextEdit::ExtraSelection highlightSelection;
highlightSelection.cursor = cursor;
highlightSelection.format.setBackground(blueColor);
highlightSelection.format.setBackground(highlightColor);
QTextCursor cursor2(document);
cursor2.beginEditBlock();
@ -450,6 +451,12 @@ void DisassemblyWidget::fontsUpdatedSlot()
}
}
void DisassemblyWidget::colorsUpdatedSlot()
{
mDisasTextEdit->setStyleSheet(QString("QPlainTextEdit { background-color: %1; }").arg(ConfigColor("gui.background").name()));
refreshDisasm();
}
DisassemblyScrollArea::DisassemblyScrollArea(QWidget *parent) : QAbstractScrollArea(parent)
{
}

View File

@ -25,6 +25,7 @@ public slots:
void showDisasContextMenu(const QPoint &pt);
void refreshDisasm(RVA offset = RVA_INVALID);
void fontsUpdatedSlot();
void colorsUpdatedSlot();
private slots:
void on_seekChanged(RVA offset);

View File

@ -77,12 +77,12 @@ void SideBar::on_themesButton_clicked()
if (ui->themesButton->isChecked())
{
// Dark theme
this->main->dark();
this->main->setDarkTheme();
}
else
{
// Clear theme
this->main->def_theme();
this->main->setDefaultTheme();
}
}