Updated Configuration model + Added Font selection

This commit is contained in:
xarkes 2017-10-14 11:35:49 +02:00
parent 9860e1d6bf
commit e54b0ee106
16 changed files with 189 additions and 103 deletions

View File

@ -2,7 +2,6 @@
#include "cutter.h"
#include "AnalThread.h"
#include "MainWindow.h"
#include "Settings.h"
#include "dialogs/OptionsDialog.h"
AnalThread::AnalThread(OptionsDialog *parent) :

View File

@ -58,7 +58,6 @@
#include "widgets/SdbDock.h"
#include "widgets/Omnibar.h"
#include "widgets/ConsoleWidget.h"
#include "Settings.h"
#include "dialogs/OptionsDialog.h"
#include "widgets/EntrypointWidget.h"
#include "widgets/DisassemblerGraphView.h"
@ -113,6 +112,7 @@ MainWindow::MainWindow(QWidget *parent) :
webserver(core)
{
doLock = false;
configuration = new Configuration();
}
MainWindow::~MainWindow()

View File

@ -9,6 +9,7 @@
#include "widgets/SidebarWidget.h"
#include "widgets/HexdumpWidget.h"
#include "cutter.h" // only needed for ut64
#include "utils/Configuration.h"
class CutterCore;
class DockWidget;
@ -180,6 +181,7 @@ private:
SideBar *sideBar;
PreviewWidget *previewDock;
Notepad *notepadDock;
Configuration *configuration;
bool doLock;
void refreshMem();

View File

@ -1,56 +0,0 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QSettings>
class Settings
{
private:
QSettings settings;
public:
bool getAsmESIL() const { return settings.value("asm.esil", false).toBool(); }
void setAsmESIL(bool v) { settings.setValue("asm.esil", v); }
bool getAsmPseudo() const { return settings.value("asm.pseudo", false).toBool(); }
void setAsmPseudo(bool v) { settings.setValue("asm.pseudo", v); }
bool getAsmOffset() const { return settings.value("asm.offset", true).toBool(); }
void setAsmOffset(bool v) { settings.setValue("asm.offset", v); }
bool getAsmDescribe() const { return settings.value("asm.describe", false).toBool(); }
void setAsmDescribe(bool v) { settings.setValue("asm.describe", v); }
bool getAsmStackPointer() const { return settings.value("asm.stackptr", false).toBool(); }
void setAsmStackPointer(bool v) { settings.setValue("asm.stackptr", v); }
bool getAsmBytes() const { return settings.value("asm.bytes", false).toBool(); }
void setAsmBytes(bool v) { settings.setValue("asm.bytes", v); }
bool getAsmBytespace() const { return settings.value("asm.bytespace", false).toBool(); }
void setAsmBytespace(bool v) { settings.setValue("asm.bytespace", v); }
bool getAsmLBytes() const { return settings.value("asm.lbytes", true).toBool(); }
void setAsmLBytes(bool v) { settings.setValue("asm.lbytes", v); }
QString getAsmSyntax() const { return settings.value("asm.syntax", "intel").toString(); }
void setAsmSyntax(const QString &v) { settings.setValue("asm.syntax", v); }
bool getAsmUppercase() const { return settings.value("asm.ucase", false).toBool(); }
void setAsmUppercase(bool v) { settings.setValue("asm.ucase", v); }
bool getAsmBBLine() const { return settings.value("asm.bbline", false).toBool(); }
void setAsmBBLine(bool v) { settings.setValue("asm.bbline", v); }
bool getAsmCapitalize() const { return settings.value("asm.capitalize", false).toBool(); }
void setAsmCapitalize(bool v) { settings.setValue("asm.capitalize", v); }
bool getAsmVarsub() const { return settings.value("asm.varsub", true).toBool(); }
void setAsmVarsub(bool v) { settings.setValue("asm.varsub", v); }
bool getAsmVarsubOnly() const { return settings.value("asm.varsub_only", true).toBool(); }
void setAsmVarsubOnly(bool v) { settings.setValue("asm.varsub_only", v); }
};
#endif // SETTINGS_H

View File

@ -1,8 +1,8 @@
#include <QJsonArray>
#include <QJsonObject>
#include "utils/Configuration.h"
#include "cutter.h"
#include "sdb.h"
#include "Settings.h"
Q_GLOBAL_STATIC(ccClass, uniqueInstance)
@ -513,40 +513,38 @@ void CutterCore::triggerAsmOptionsChanged()
void CutterCore::resetDefaultAsmOptions()
{
Settings settings;
setConfig("asm.esil", settings.getAsmESIL());
setConfig("asm.pseudo", settings.getAsmPseudo());
setConfig("asm.offset", settings.getAsmOffset());
setConfig("asm.describe", settings.getAsmDescribe());
setConfig("asm.stackptr", settings.getAsmStackPointer());
setConfig("asm.bytes", settings.getAsmBytes());
setConfig("asm.bytespace", settings.getAsmBytespace());
setConfig("asm.lbytes", settings.getAsmLBytes());
setConfig("asm.syntax", settings.getAsmSyntax());
setConfig("asm.ucase", settings.getAsmUppercase());
setConfig("asm.bbline", settings.getAsmBBLine());
setConfig("asm.capitalize", settings.getAsmCapitalize());
setConfig("asm.varsub", settings.getAsmVarsub());
setConfig("asm.varsub_only", settings.getAsmVarsubOnly());
setConfig("asm.esil", Config()->getAsmESIL());
setConfig("asm.pseudo", Config()->getAsmPseudo());
setConfig("asm.offset", Config()->getAsmOffset());
setConfig("asm.describe", Config()->getAsmDescribe());
setConfig("asm.stackptr", Config()->getAsmStackPointer());
setConfig("asm.bytes", Config()->getAsmBytes());
setConfig("asm.bytespace", Config()->getAsmBytespace());
setConfig("asm.lbytes", Config()->getAsmLBytes());
setConfig("asm.syntax", Config()->getAsmSyntax());
setConfig("asm.ucase", Config()->getAsmUppercase());
setConfig("asm.bbline", Config()->getAsmBBLine());
setConfig("asm.capitalize", Config()->getAsmCapitalize());
setConfig("asm.varsub", Config()->getAsmVarsub());
setConfig("asm.varsub_only", Config()->getAsmVarsubOnly());
}
void CutterCore::saveDefaultAsmOptions()
{
Settings settings;
settings.setAsmESIL(getConfigb("asm.esil"));
settings.setAsmPseudo(getConfigb("asm.pseudo"));
settings.setAsmOffset(getConfigb("asm.offset"));
settings.setAsmDescribe(getConfigb("asm.describe"));
settings.setAsmStackPointer(getConfigb("asm.stackptr"));
settings.setAsmBytes(getConfigb("asm.bytes"));
settings.setAsmBytespace(getConfigb("asm.bytespace"));
settings.setAsmLBytes(getConfigb("asm.lbytes"));
settings.setAsmSyntax(getConfig("asm.syntax"));
settings.setAsmUppercase(getConfigb("asm.ucase"));
settings.setAsmBBLine(getConfigb("asm.bbline"));
settings.setAsmCapitalize(getConfigb("asm.capitalize"));
settings.setAsmVarsub(getConfigb("asm.varsub"));
settings.setAsmVarsubOnly(getConfigb("asm.varsub_only"));
Config()->setAsmESIL(getConfigb("asm.esil"));
Config()->setAsmPseudo(getConfigb("asm.pseudo"));
Config()->setAsmOffset(getConfigb("asm.offset"));
Config()->setAsmDescribe(getConfigb("asm.describe"));
Config()->setAsmStackPointer(getConfigb("asm.stackptr"));
Config()->setAsmBytes(getConfigb("asm.bytes"));
Config()->setAsmBytespace(getConfigb("asm.bytespace"));
Config()->setAsmLBytes(getConfigb("asm.lbytes"));
Config()->setAsmSyntax(getConfig("asm.syntax"));
Config()->setAsmUppercase(getConfigb("asm.ucase"));
Config()->setAsmBBLine(getConfigb("asm.bbline"));
Config()->setAsmCapitalize(getConfigb("asm.capitalize"));
Config()->setAsmVarsub(getConfigb("asm.varsub"));
Config()->setAsmVarsubOnly(getConfigb("asm.varsub_only"));
}
QString CutterCore::getConfig(const QString &k)

View File

@ -32,6 +32,8 @@
#define APPNAME "Cutter"
#define Core() (CutterCore::getInstance())
typedef ut64 RVA;
#define RVA_INVALID UT64_MAX

View File

@ -76,7 +76,8 @@ SOURCES += \
menus/DisassemblyContextMenu.cpp \
widgets/DisassemblyWidget.cpp \
widgets/SidebarWidget.cpp \
widgets/HexdumpWidget.cpp
widgets/HexdumpWidget.cpp \
utils/Configuration.cpp
HEADERS += \
cutter.h \
@ -96,7 +97,6 @@ HEADERS += \
MainWindow.h \
utils/Highlighter.h \
utils/MdHighlighter.h \
Settings.h \
dialogs/OptionsDialog.h \
dialogs/CreateNewDialog.h \
dialogs/NewFileDialog.h \
@ -125,7 +125,8 @@ HEADERS += \
menus/DisassemblyContextMenu.h \
widgets/DisassemblyWidget.h \
widgets/SidebarWidget.h \
widgets/HexdumpWidget.h
widgets/HexdumpWidget.h \
utils/Configuration.h
FORMS += \
widgets/PreviewWidget.ui \

View File

@ -1,9 +1,11 @@
#include <QLabel>
#include <QFontDialog>
#include "Settings.h"
#include "AsmOptionsDialog.h"
#include "ui_AsmOptionsDialog.h"
#include "utils/Helpers.h"
#include "utils/Configuration.h"
AsmOptionsDialog::AsmOptionsDialog(QWidget *parent)
: QDialog(parent),
@ -19,6 +21,9 @@ AsmOptionsDialog::AsmOptionsDialog(QWidget *parent)
ui->syntaxComboBox->addItem(syntax, syntax);
ui->syntaxComboBox->blockSignals(false);
QFont currentFont = Config()->getFont();
ui->fontSelectionLabel->setText(currentFont.toString());
updateFromVars();
}
@ -209,3 +214,14 @@ void AsmOptionsDialog::on_buttonBox_clicked(QAbstractButton *button)
break;
}
}
void AsmOptionsDialog::on_fontSelectionButton_clicked()
{
QFont currentFont = Config()->getFont();
bool ok;
QFont newFont = QFontDialog::getFont(&ok, currentFont, this);
if (ok) {
Config()->setFont(newFont);
ui->fontSelectionLabel->setText(newFont.toString());
}
}

View File

@ -44,6 +44,7 @@ private slots:
void on_varsubCheckBox_toggled(bool checked);
void on_varsubOnlyCheckBox_toggled(bool checked);
void on_buttonBox_clicked(QAbstractButton *button);
void on_fontSelectionButton_clicked();
};

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>445</width>
<width>476</width>
<height>631</height>
</rect>
</property>
@ -17,6 +17,24 @@
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="fontSelectionLayout">
<item>
<widget class="QLabel" name="fontSelectionLabel">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontSelectionButton">
<property name="text">
<string>Select font</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="esilCheckBox">
<property name="text">

View File

@ -7,7 +7,6 @@
// TODO: remove us
#include "widgets/PreviewWidget.h"
#include "widgets/Notepad.h"
#include "Settings.h"
#include <QSettings>
#include <QFileInfo>

View File

@ -0,0 +1,25 @@
#include "Configuration.h"
Configuration* Configuration::mPtr = nullptr;
Configuration::Configuration() : QObject()
{
mPtr = this;
}
Configuration* Configuration::instance()
{
return mPtr;
}
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();
}

72
src/utils/Configuration.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <QSettings>
#include <QFont>
#define Config() (Configuration::instance())
class Configuration : public QObject
{
Q_OBJECT
private:
QSettings s;
static Configuration* mPtr;
public:
// Functions
Configuration();
static Configuration* instance();
// Fonts
const QFont getFont() const;
void setFont(const QFont &font);
// TODO Imho it's wrong doing it this way. Should find something else.
bool getAsmESIL() const { return s.value("asm.esil", false).toBool(); }
void setAsmESIL(bool v) { s.setValue("asm.esil", v); }
bool getAsmPseudo() const { return s.value("asm.pseudo", false).toBool(); }
void setAsmPseudo(bool v) { s.setValue("asm.pseudo", v); }
bool getAsmOffset() const { return s.value("asm.offset", true).toBool(); }
void setAsmOffset(bool v) { s.setValue("asm.offset", v); }
bool getAsmDescribe() const { return s.value("asm.describe", false).toBool(); }
void setAsmDescribe(bool v) { s.setValue("asm.describe", v); }
bool getAsmStackPointer() const { return s.value("asm.stackptr", false).toBool(); }
void setAsmStackPointer(bool v) { s.setValue("asm.stackptr", v); }
bool getAsmBytes() const { return s.value("asm.bytes", false).toBool(); }
void setAsmBytes(bool v) { s.setValue("asm.bytes", v); }
bool getAsmBytespace() const { return s.value("asm.bytespace", false).toBool(); }
void setAsmBytespace(bool v) { s.setValue("asm.bytespace", v); }
bool getAsmLBytes() const { return s.value("asm.lbytes", true).toBool(); }
void setAsmLBytes(bool v) { s.setValue("asm.lbytes", v); }
QString getAsmSyntax() const { return s.value("asm.syntax", "intel").toString(); }
void setAsmSyntax(const QString &v) { s.setValue("asm.syntax", v); }
bool getAsmUppercase() const { return s.value("asm.ucase", false).toBool(); }
void setAsmUppercase(bool v) { s.setValue("asm.ucase", v); }
bool getAsmBBLine() const { return s.value("asm.bbline", false).toBool(); }
void setAsmBBLine(bool v) { s.setValue("asm.bbline", v); }
bool getAsmCapitalize() const { return s.value("asm.capitalize", false).toBool(); }
void setAsmCapitalize(bool v) { s.setValue("asm.capitalize", v); }
bool getAsmVarsub() const { return s.value("asm.varsub", true).toBool(); }
void setAsmVarsub(bool v) { s.setValue("asm.varsub", v); }
bool getAsmVarsubOnly() const { return s.value("asm.varsub_only", true).toBool(); }
void setAsmVarsubOnly(bool v) { s.setValue("asm.varsub_only", v); }
signals:
void fontsUpdated();
};
#endif // CONFIGURATION_H

View File

@ -9,6 +9,7 @@
#include <QMimeData>
#include <QFileDialog>
#include <QMessageBox>
#include "utils/Configuration.h"
#ifdef _WIN32
#undef min
@ -74,7 +75,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
setupContextMenu();
//Connect to bridge
connect(CutterCore::getInstance(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
//connect(Bridge::getBridge(), SIGNAL(loadGraph(BridgeCFGraphList*, duint)), this, SLOT(loadGraphSlot(BridgeCFGraphList*, duint)));
//connect(Bridge::getBridge(), SIGNAL(graphAt(duint)), this, SLOT(graphAtSlot(duint)));
//connect(Bridge::getBridge(), SIGNAL(updateGraph()), this, SLOT(updateGraphSlot()));
@ -84,7 +85,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
//Connect to config
//connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
//connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
//connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(shortcutsUpdatedSlot()));
//connect(Config(), SIGNAL(tokenizerConfigUpdated()), this, SLOT(tokenizerConfigUpdatedSlot()));
@ -98,7 +99,7 @@ DisassemblerGraphView::~DisassemblerGraphView()
void DisassemblerGraphView::initFont()
{
setFont(QFont("Monospace", 10));
setFont(Config()->getFont());
QFontMetricsF metrics(this->font());
this->baseline = int(metrics.ascent());
this->charWidth = metrics.width('X');
@ -734,9 +735,9 @@ void DisassemblerGraphView::mouseDoubleClickEvent(QMouseEvent* event)
{
duint instr = this->getInstrForMouseEvent(event);
//DbgCmdExec(QString("graph dis.branchdest(%1), silent").arg(ToPtrString(instr)).toUtf8().constData());
QList<XrefDescription> refs = CutterCore::getInstance()->getXRefs(instr, false, false);
QList<XrefDescription> refs = Core()->getXRefs(instr, false, false);
if (refs.length()) {
CutterCore::getInstance()->seek(refs.at(0).to);
Core()->seek(refs.at(0).to);
}
if (refs.length() > 1) {
qWarning() << "Too many references here. Weird behaviour expected.";
@ -1547,7 +1548,7 @@ void DisassemblerGraphView::tokenizerConfigUpdatedSlot()
void DisassemblerGraphView::loadCurrentGraph()
{
// Read functions
QJsonDocument functionsDoc = CutterCore::getInstance()->cmdj("agj");
QJsonDocument functionsDoc = Core()->cmdj("agj");
QJsonArray functions = functionsDoc.array();
Analysis anal;

View File

@ -5,6 +5,7 @@
#include "utils/HexHighlighter.h"
#include <QShortcut>
#include <QScrollBar>
#include "utils/Configuration.h"
DisassemblyWidget::DisassemblyWidget(QWidget *parent) :
QDockWidget(parent),
@ -15,8 +16,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) :
setAllowedAreas(Qt::AllDockWidgetAreas);
setObjectName("DisassemblyWidget");
// TODO Use Settings
mDisasTextEdit->setFont(QFont("Monospace", 10));
mDisasTextEdit->setFont(Config()->getFont());
// Increase asm text edit margin
QTextDocument *asm_docu = mDisasTextEdit->document();
@ -66,6 +66,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) :
// Seek signal
connect(CutterCore::getInstance(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
}
DisassemblyWidget::DisassemblyWidget(const QString &title, QWidget *parent) :
@ -407,3 +408,9 @@ void DisassemblyWidget::highlightDisasms()
//Highlighter *preview_highlighter = new Highlighter(mDisasTextEdit->document());
//Highlighter *deco_highlighter = new Highlighter(mDisasTextEdit->document());
}
void DisassemblyWidget::fontsUpdatedSlot()
{
mDisasTextEdit->setFont(Config()->getFont());
refreshDisasm();
}

View File

@ -22,6 +22,7 @@ public slots:
void on_mDisasTextEdit_cursorPositionChanged();
void on_seekChanged(RVA offset);
void refreshDisasm();
void fontsUpdatedSlot();
private:
QTextEdit *mDisasTextEdit;