Monospace fonts (#584)

* Use preferences font in debug widgets and astyle cleanup
* Use pref font in backtrace widget
* Fix opening correct panel in the preferences dialog via the contextmenu
* Fix highlighting in selected instruction and RIP
This commit is contained in:
fcasal 2018-07-18 11:15:10 +01:00 committed by xarkes
parent 43215a06ac
commit 96f832dafb
11 changed files with 95 additions and 63 deletions

View File

@ -778,10 +778,10 @@ void CutterCore::startDebug()
emit registersChanged(); emit registersChanged();
if (!currentlyDebugging) { if (!currentlyDebugging) {
setConfig("asm.flags", false); setConfig("asm.flags", false);
currentlyDebugging = true;
emit changeDebugView(); emit changeDebugView();
emit flagsChanged(); emit flagsChanged();
emit refreshCodeViews(); emit refreshCodeViews();
currentlyDebugging = true;
} }
} }
@ -798,11 +798,11 @@ void CutterCore::startEmulation()
setConfig("asm.flags", false); setConfig("asm.flags", false);
// allows to view self-modifying code changes or other binary changes // allows to view self-modifying code changes or other binary changes
setConfig("io.cache", true); setConfig("io.cache", true);
currentlyDebugging = true;
currentlyEmulating = true;
emit changeDebugView(); emit changeDebugView();
emit flagsChanged(); emit flagsChanged();
emit refreshCodeViews(); emit refreshCodeViews();
currentlyDebugging = true;
currentlyEmulating = true;
} }
} }
@ -819,9 +819,9 @@ void CutterCore::attachDebug(int pid)
if (!currentlyDebugging || !currentlyEmulating) { if (!currentlyDebugging || !currentlyEmulating) {
// prevent register flags from appearing during debug/emul // prevent register flags from appearing during debug/emul
setConfig("asm.flags", false); setConfig("asm.flags", false);
currentlyDebugging = true;
emit changeDebugView(); emit changeDebugView();
emit flagsChanged(); emit flagsChanged();
currentlyDebugging = true;
} }
} }
@ -2034,6 +2034,22 @@ QList<QString> CutterCore::getColorThemes()
return r; return r;
} }
RCoreTask *CutterCore::startTask(const QString &cmd)
{
RCoreTask *task = r_core_task_new (core_, true, cmd.toLocal8Bit().constData(), nullptr, nullptr);
r_core_task_enqueue(core_, task);
return task;
}
void CutterCore::joinTask(RCoreTask *task)
{
r_core_task_join(core_, nullptr, task);
}
void CutterCore::deleteTask(RCoreTask *task)
{
r_core_task_del(core_, task->id);
}
void CutterCore::setCutterPlugins(QList<CutterPlugin *> plugins) void CutterCore::setCutterPlugins(QList<CutterPlugin *> plugins)
{ {
this->plugins = plugins; this->plugins = plugins;

View File

@ -267,7 +267,8 @@ void MainWindow::initUI()
connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView); connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView);
updateTasksIndicator(); updateTasksIndicator();
connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this, &MainWindow::updateTasksIndicator); connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this,
&MainWindow::updateTasksIndicator);
/* Load plugins */ /* Load plugins */
QList<CutterPlugin *> plugins = Core()->getCutterPlugins(); QList<CutterPlugin *> plugins = Core()->getCutterPlugins();
@ -337,7 +338,8 @@ void MainWindow::openNewFileFailed()
mb.setIcon(QMessageBox::Critical); mb.setIcon(QMessageBox::Critical);
mb.setStandardButtons(QMessageBox::Ok); mb.setStandardButtons(QMessageBox::Ok);
mb.setWindowTitle(tr("Cannot open file!")); mb.setWindowTitle(tr("Cannot open file!"));
mb.setText(tr("Could not open the file! Make sure the file exists and that you have the correct permissions.")); mb.setText(
tr("Could not open the file! Make sure the file exists and that you have the correct permissions."));
mb.exec(); mb.exec();
} }
@ -557,9 +559,9 @@ void MainWindow::restoreDocks()
tabifyDockWidget(dashboardDock, vTablesDock); tabifyDockWidget(dashboardDock, vTablesDock);
// Add Stack, Registers and Backtrace vertically stacked // Add Stack, Registers and Backtrace vertically stacked
addExtraWidget(stackDock); splitDockWidget(sidebarDock, stackDock, Qt::Horizontal);
splitDockWidget(stackDock, registersDock, Qt::Vertical); splitDockWidget(stackDock, registersDock, Qt::Vertical);
splitDockWidget(stackDock, backtraceDock, Qt::Vertical); tabifyDockWidget(stackDock, backtraceDock);
// MemoryMap/Breakpoint widget goes in the center tabs // MemoryMap/Breakpoint widget goes in the center tabs
tabifyDockWidget(dashboardDock, memoryMapDock); tabifyDockWidget(dashboardDock, memoryMapDock);
tabifyDockWidget(dashboardDock, breakpointDock); tabifyDockWidget(dashboardDock, breakpointDock);

View File

@ -9,16 +9,17 @@
#include "utils/Helpers.h" #include "utils/Helpers.h"
#include "utils/Configuration.h" #include "utils/Configuration.h"
GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog */*dialog*/, QWidget *parent) GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog *dialog, QWidget *parent)
: QDialog(parent), : QDialog(parent),
ui(new Ui::GeneralOptionsWidget) ui(new Ui::GeneralOptionsWidget)
{ {
Q_UNUSED(dialog);
ui->setupUi(this); ui->setupUi(this);
updateFontFromConfig(); updateFontFromConfig();
updateThemeFromConfig(); updateThemeFromConfig();
//connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig())); connect(Config(), &Configuration::fontsUpdated, this, &GeneralOptionsWidget::updateFontFromConfig);
//connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); //connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig()));
} }

View File

@ -18,12 +18,13 @@ BacktraceWidget::BacktraceWidget(MainWindow *main, QAction *action) :
modelBacktrace->setHorizontalHeaderItem(2, new QStandardItem(tr("Frame Size"))); modelBacktrace->setHorizontalHeaderItem(2, new QStandardItem(tr("Frame Size")));
modelBacktrace->setHorizontalHeaderItem(3, new QStandardItem(tr("Func Name"))); modelBacktrace->setHorizontalHeaderItem(3, new QStandardItem(tr("Func Name")));
modelBacktrace->setHorizontalHeaderItem(4, new QStandardItem(tr("Description"))); modelBacktrace->setHorizontalHeaderItem(4, new QStandardItem(tr("Description")));
viewBacktrace->setStyleSheet("QTableView {font-family: mono}"); viewBacktrace->setFont(Config()->getFont());
viewBacktrace->setModel(modelBacktrace); viewBacktrace->setModel(modelBacktrace);
ui->verticalLayout->addWidget(viewBacktrace); ui->verticalLayout->addWidget(viewBacktrace);
connect(Core(), &CutterCore::refreshAll, this, &BacktraceWidget::updateContents); connect(Core(), &CutterCore::refreshAll, this, &BacktraceWidget::updateContents);
connect(Core(), &CutterCore::seekChanged, this, &BacktraceWidget::updateContents); connect(Core(), &CutterCore::seekChanged, this, &BacktraceWidget::updateContents);
connect(Config(), &Configuration::fontsUpdated, this, &BacktraceWidget::fontsUpdatedSlot);
} }
BacktraceWidget::~BacktraceWidget() {} BacktraceWidget::~BacktraceWidget() {}
@ -61,3 +62,8 @@ void BacktraceWidget::setBacktraceGrid()
viewBacktrace->setModel(modelBacktrace); viewBacktrace->setModel(modelBacktrace);
viewBacktrace->resizeColumnsToContents();; viewBacktrace->resizeColumnsToContents();;
} }
void BacktraceWidget::fontsUpdatedSlot()
{
viewBacktrace->setFont(Config()->getFont());
}

View File

@ -25,6 +25,7 @@ public:
private slots: private slots:
void updateContents(); void updateContents();
void setBacktraceGrid(); void setBacktraceGrid();
void fontsUpdatedSlot();
private: private:
std::unique_ptr<Ui::BacktraceWidget> ui; std::unique_ptr<Ui::BacktraceWidget> ui;

View File

@ -376,21 +376,21 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
block.width, block.height); block.width, block.height);
// Draw different background for selected instruction // Draw different background for selected instruction
bool paintedSelected = false;
if (selected_instruction != RVA_INVALID) { if (selected_instruction != RVA_INVALID) {
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight); int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
for (Instr &instr : db.instrs) { for (Instr &instr : db.instrs) {
if (instr.addr > selected_instruction) {
break;
}
auto selected = instr.addr == selected_instruction; auto selected = instr.addr == selected_instruction;
//auto traceCount = dbgfunctions->GetTraceRecordHitCount(instr.addr); //auto traceCount = dbgfunctions->GetTraceRecordHitCount(instr.addr);
auto traceCount = 0; auto traceCount = 0;
if (selected && traceCount) { if (selected && traceCount) {
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth), p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
int(instr.text.lines.size()) * charHeight), disassemblyTracedSelectionColor); int(instr.text.lines.size()) * charHeight), disassemblyTracedSelectionColor);
paintedSelected = true;
} else if (selected) { } else if (selected) {
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth), p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor); int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
paintedSelected = true;
} else if (traceCount) { } else if (traceCount) {
// Color depending on how often a sequence of code is executed // Color depending on how often a sequence of code is executed
int exponent = 1; int exponent = 1;
@ -407,10 +407,6 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
QColor(disassemblyTracedColor.red(), QColor(disassemblyTracedColor.red(),
disassemblyTracedColor.green(), disassemblyTracedColor.green(),
std::max(0, std::min(256, disassemblyTracedColor.blue() + colorDiff)))); std::max(0, std::min(256, disassemblyTracedColor.blue() + colorDiff))));
paintedSelected = true;
}
if (paintedSelected) {
break;
} }
y += int(instr.text.lines.size()) * charHeight; y += int(instr.text.lines.size()) * charHeight;
} }
@ -420,11 +416,13 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
if (PCInBlock) { if (PCInBlock) {
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight); int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
for (Instr &instr : db.instrs) { for (Instr &instr : db.instrs) {
if (instr.addr > PCAddr) {
break;
}
auto PC = instr.addr == PCAddr; auto PC = instr.addr == PCAddr;
if (PC) { if (PC) {
p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth), p.fillRect(QRect(block.x + charWidth, y, block.width - (10 + 2 * charWidth),
int(instr.text.lines.size()) * charHeight), PCSelectionColor); int(instr.text.lines.size()) * charHeight), PCSelectionColor);
break;
} }
y += int(instr.text.lines.size()) * charHeight; y += int(instr.text.lines.size()) * charHeight;
} }
@ -677,8 +675,7 @@ void DisassemblerGraphView::seekPrev()
{ {
if (seekable->getSyncWithCore()) { if (seekable->getSyncWithCore()) {
Core()->seekPrev(); Core()->seekPrev();
} } else {
else {
seekable->seek(seekable->getPrevIndependentOffset()); seekable->seek(seekable->getPrevIndependentOffset());
} }
} }

View File

@ -66,16 +66,14 @@ void RegistersWidget::setRegisterGrid()
// check if we already filled this grid space with label/value // check if we already filled this grid space with label/value
if (!registerLayout->itemAtPosition(i, col)) { if (!registerLayout->itemAtPosition(i, col)) {
registerLabel = new QLabel; registerLabel = new QLabel;
registerLabel->setStyleSheet("font-weight: bold; font-family: mono"); registerLabel->setStyleSheet("font-weight: bold; font-family: mono;");
registerEditValue = new QLineEdit; registerEditValue = new QLineEdit;
QFont font = registerEditValue->font(); registerEditValue->setFixedWidth(140);
font.setWeight(QFont::Monospace); registerEditValue->setFont(Config()->getFont());
registerEditValue->setFont(font);
// add label and register value to grid // add label and register value to grid
registerLayout->addWidget(registerLabel, i, col); registerLayout->addWidget(registerLabel, i, col);
registerLayout->addWidget(registerEditValue, i, col + 1); registerLayout->addWidget(registerEditValue, i, col + 1);
} } else {
else {
QWidget *regNameWidget = registerLayout->itemAtPosition(i, col)->widget(); QWidget *regNameWidget = registerLayout->itemAtPosition(i, col)->widget();
QWidget *regValueWidget = registerLayout->itemAtPosition(i, col + 1)->widget(); QWidget *regValueWidget = registerLayout->itemAtPosition(i, col + 1)->widget();
registerLabel = qobject_cast<QLabel *>(regNameWidget); registerLabel = qobject_cast<QLabel *>(regNameWidget);
@ -84,8 +82,7 @@ void RegistersWidget::setRegisterGrid()
// decide to highlight QLine Box in case of change of register value // decide to highlight QLine Box in case of change of register value
if (regValue != registerEditValue->text() && registerEditValue->text() != 0) { if (regValue != registerEditValue->text() && registerEditValue->text() != 0) {
registerEditValue->setStyleSheet("QLineEdit {border: 1px solid green;} QLineEdit:hover { border: 1px solid #3daee9; color: #eff0f1;}"); registerEditValue->setStyleSheet("QLineEdit {border: 1px solid green;} QLineEdit:hover { border: 1px solid #3daee9; color: #eff0f1;}");
} } else {
else {
// reset stylesheet // reset stylesheet
registerEditValue->setStyleSheet(""); registerEditValue->setStyleSheet("");
} }

View File

@ -13,23 +13,28 @@
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">Registers</string> <string notr="true">Registers</string>
</property> </property>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing"> <property name="spacing">
<number>10</number> <number>10</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>6</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>6</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>6</number>
</property> </property>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -16,7 +16,7 @@ StackWidget::StackWidget(MainWindow *main, QAction *action) :
modelStack->setHorizontalHeaderItem(0, new QStandardItem(tr("Offset"))); modelStack->setHorizontalHeaderItem(0, new QStandardItem(tr("Offset")));
modelStack->setHorizontalHeaderItem(1, new QStandardItem(tr("Value"))); modelStack->setHorizontalHeaderItem(1, new QStandardItem(tr("Value")));
modelStack->setHorizontalHeaderItem(2, new QStandardItem(tr("Reference"))); modelStack->setHorizontalHeaderItem(2, new QStandardItem(tr("Reference")));
viewStack->setStyleSheet("QTableView {font-family: mono}"); viewStack->setFont(Config()->getFont());
viewStack->setModel(modelStack); viewStack->setModel(modelStack);
viewStack->verticalHeader()->hide(); viewStack->verticalHeader()->hide();
viewStack->setSortingEnabled(true); viewStack->setSortingEnabled(true);
@ -24,6 +24,7 @@ StackWidget::StackWidget(MainWindow *main, QAction *action) :
connect(Core(), &CutterCore::refreshAll, this, &StackWidget::updateContents); connect(Core(), &CutterCore::refreshAll, this, &StackWidget::updateContents);
connect(Core(), &CutterCore::seekChanged, this, &StackWidget::updateContents); connect(Core(), &CutterCore::seekChanged, this, &StackWidget::updateContents);
connect(Config(), &Configuration::fontsUpdated, this, &StackWidget::fontsUpdatedSlot);
} }
StackWidget::~StackWidget() {} StackWidget::~StackWidget() {}
@ -56,3 +57,8 @@ void StackWidget::setStackGrid()
viewStack->setModel(modelStack); viewStack->setModel(modelStack);
viewStack->resizeColumnsToContents();; viewStack->resizeColumnsToContents();;
} }
void StackWidget::fontsUpdatedSlot()
{
viewStack->setFont(Config()->getFont());
}

View File

@ -25,6 +25,7 @@ public:
private slots: private slots:
void updateContents(); void updateContents();
void setStackGrid(); void setStackGrid();
void fontsUpdatedSlot();
private: private:
std::unique_ptr<Ui::StackWidget> ui; std::unique_ptr<Ui::StackWidget> ui;