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

@ -565,7 +565,7 @@ QString CutterCore::getConfig(const QString &k)
void CutterCore::setConfig(const QString &k, const QVariant &v)
{
switch(v.type()) {
switch (v.type()) {
case QVariant::Type::Bool:
setConfig(k, v.toBool());
break;
@ -778,10 +778,10 @@ void CutterCore::startDebug()
emit registersChanged();
if (!currentlyDebugging) {
setConfig("asm.flags", false);
currentlyDebugging = true;
emit changeDebugView();
emit flagsChanged();
emit refreshCodeViews();
currentlyDebugging = true;
}
}
@ -798,11 +798,11 @@ void CutterCore::startEmulation()
setConfig("asm.flags", false);
// allows to view self-modifying code changes or other binary changes
setConfig("io.cache", true);
currentlyDebugging = true;
currentlyEmulating = true;
emit changeDebugView();
emit flagsChanged();
emit refreshCodeViews();
currentlyDebugging = true;
currentlyEmulating = true;
}
}
@ -819,9 +819,9 @@ void CutterCore::attachDebug(int pid)
if (!currentlyDebugging || !currentlyEmulating) {
// prevent register flags from appearing during debug/emul
setConfig("asm.flags", false);
currentlyDebugging = true;
emit changeDebugView();
emit flagsChanged();
currentlyDebugging = true;
}
}
@ -2034,12 +2034,28 @@ QList<QString> CutterCore::getColorThemes()
return r;
}
void CutterCore::setCutterPlugins(QList<CutterPlugin*> plugins)
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)
{
this->plugins = plugins;
}
QList<CutterPlugin*> CutterCore::getCutterPlugins()
QList<CutterPlugin *> CutterCore::getCutterPlugins()
{
return plugins;
}

View File

@ -267,10 +267,11 @@ void MainWindow::initUI()
connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView);
updateTasksIndicator();
connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this, &MainWindow::updateTasksIndicator);
connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this,
&MainWindow::updateTasksIndicator);
/* Load plugins */
QList<CutterPlugin*> plugins = Core()->getCutterPlugins();
QList<CutterPlugin *> plugins = Core()->getCutterPlugins();
for (auto plugin : plugins) {
CutterDockWidget *pluginDock = plugin->setupInterface(this);
tabifyDockWidget(dashboardDock, pluginDock);
@ -337,7 +338,8 @@ void MainWindow::openNewFileFailed()
mb.setIcon(QMessageBox::Critical);
mb.setStandardButtons(QMessageBox::Ok);
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();
}
@ -557,9 +559,9 @@ void MainWindow::restoreDocks()
tabifyDockWidget(dashboardDock, vTablesDock);
// Add Stack, Registers and Backtrace vertically stacked
addExtraWidget(stackDock);
splitDockWidget(sidebarDock, stackDock, Qt::Horizontal);
splitDockWidget(stackDock, registersDock, Qt::Vertical);
splitDockWidget(stackDock, backtraceDock, Qt::Vertical);
tabifyDockWidget(stackDock, backtraceDock);
// MemoryMap/Breakpoint widget goes in the center tabs
tabifyDockWidget(dashboardDock, memoryMapDock);
tabifyDockWidget(dashboardDock, breakpointDock);
@ -625,7 +627,7 @@ void MainWindow::showZenDocks()
disassemblyDock,
hexdumpDock,
searchDock
};
};
for (auto w : dockWidgets) {
if (zenDocks.contains(w)) {
w->show();
@ -637,16 +639,16 @@ void MainWindow::showZenDocks()
void MainWindow::showDebugDocks()
{
const QList<QDockWidget *> debugDocks = { functionsDock,
stringsDock,
graphDock,
disassemblyDock,
hexdumpDock,
searchDock,
stackDock,
registersDock,
backtraceDock,
memoryMapDock,
breakpointDock
stringsDock,
graphDock,
disassemblyDock,
hexdumpDock,
searchDock,
stackDock,
registersDock,
backtraceDock,
memoryMapDock,
breakpointDock
};
for (auto w : dockWidgets) {
if (debugDocks.contains(w)) {
@ -954,7 +956,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
bool MainWindow::eventFilter(QObject *, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::ForwardButton || mouseEvent->button() == Qt::BackButton) {
mousePressEvent(mouseEvent);
return true;

View File

@ -9,16 +9,17 @@
#include "utils/Helpers.h"
#include "utils/Configuration.h"
GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog */*dialog*/, QWidget *parent)
GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog *dialog, QWidget *parent)
: QDialog(parent),
ui(new Ui::GeneralOptionsWidget)
{
Q_UNUSED(dialog);
ui->setupUi(this);
updateFontFromConfig();
updateThemeFromConfig();
//connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig()));
connect(Config(), &Configuration::fontsUpdated, this, &GeneralOptionsWidget::updateFontFromConfig);
//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(3, new QStandardItem(tr("Func Name")));
modelBacktrace->setHorizontalHeaderItem(4, new QStandardItem(tr("Description")));
viewBacktrace->setStyleSheet("QTableView {font-family: mono}");
viewBacktrace->setFont(Config()->getFont());
viewBacktrace->setModel(modelBacktrace);
ui->verticalLayout->addWidget(viewBacktrace);
connect(Core(), &CutterCore::refreshAll, this, &BacktraceWidget::updateContents);
connect(Core(), &CutterCore::seekChanged, this, &BacktraceWidget::updateContents);
connect(Config(), &Configuration::fontsUpdated, this, &BacktraceWidget::fontsUpdatedSlot);
}
BacktraceWidget::~BacktraceWidget() {}
@ -61,3 +62,8 @@ void BacktraceWidget::setBacktraceGrid()
viewBacktrace->setModel(modelBacktrace);
viewBacktrace->resizeColumnsToContents();;
}
void BacktraceWidget::fontsUpdatedSlot()
{
viewBacktrace->setFont(Config()->getFont());
}

View File

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

View File

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

View File

@ -127,8 +127,8 @@ void GraphView::adjustSize(int new_width, int new_height, QPoint mouse)
int dx = newMaxX - originalRangeX;
int dy = newMaxY - originalRangeY;
horizontalScrollBar()->setValue(topX + dx*((float)mouseLocal.x()/new_width));
verticalScrollBar()->setValue(topY + dy*((float)mouseLocal.y()/new_height));
horizontalScrollBar()->setValue(topX + dx * ((float)mouseLocal.x() / new_width));
verticalScrollBar()->setValue(topY + dy * ((float)mouseLocal.y() / new_height));
}
bool GraphView::event(QEvent *event)
@ -411,9 +411,9 @@ void GraphView::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(viewport());
p.setRenderHint(QPainter::Antialiasing);
int render_offset_x = -horizontalScrollBar()->value() * current_scale;
int render_offset_y = -verticalScrollBar()->value() * current_scale;
int render_width = viewport()->size().width() / current_scale;
@ -864,8 +864,8 @@ void GraphView::mouseMoveEvent(QMouseEvent *event)
int y_delta = scroll_base_y - event->y();
scroll_base_x = event->x();
scroll_base_y = event->y();
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1/current_scale));
verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1/current_scale));
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1 / current_scale));
verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1 / current_scale));
}
}
@ -912,7 +912,7 @@ void GraphView::wheelEvent(QWheelEvent *event)
const QPoint delta = -event->angleDelta();
int x_delta = delta.x();
int y_delta = delta.y();
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1/current_scale));
verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1/current_scale));
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta * (1 / current_scale));
verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta * (1 / current_scale));
event->accept();
}

View File

@ -29,12 +29,12 @@ void RegistersWidget::updateContents()
setRegisterGrid();
}
void RegistersWidget::handleButton()
{
void RegistersWidget::handleButton()
{
int j = 0;
int i = 0;
int col = 0;
for (j = 0; j<registerLen; j++) {
for (j = 0; j < registerLen; j++) {
QWidget *regName = registerLayout->itemAtPosition(i, col)->widget();
QWidget *regValue = registerLayout->itemAtPosition(i, col + 1)->widget();
QLabel *regLabel = qobject_cast<QLabel *>(regName);
@ -43,13 +43,13 @@ void RegistersWidget::updateContents()
QString regValueString = regLine->text();
Core()->setRegister(regNameString, regValueString);
i++;
if (i >= registerLen/numCols + 1) {
if (i >= registerLen / numCols + 1) {
i = 0;
col += 2;
}
}
setRegisterGrid();
}
}
void RegistersWidget::setRegisterGrid()
{
@ -66,16 +66,14 @@ void RegistersWidget::setRegisterGrid()
// check if we already filled this grid space with label/value
if (!registerLayout->itemAtPosition(i, col)) {
registerLabel = new QLabel;
registerLabel->setStyleSheet("font-weight: bold; font-family: mono");
registerLabel->setStyleSheet("font-weight: bold; font-family: mono;");
registerEditValue = new QLineEdit;
QFont font = registerEditValue->font();
font.setWeight(QFont::Monospace);
registerEditValue->setFont(font);
registerEditValue->setFixedWidth(140);
registerEditValue->setFont(Config()->getFont());
// add label and register value to grid
registerLayout->addWidget(registerLabel, i, col);
registerLayout->addWidget(registerEditValue, i, col + 1);
}
else {
} else {
QWidget *regNameWidget = registerLayout->itemAtPosition(i, col)->widget();
QWidget *regValueWidget = registerLayout->itemAtPosition(i, col + 1)->widget();
registerLabel = qobject_cast<QLabel *>(regNameWidget);
@ -84,8 +82,7 @@ void RegistersWidget::setRegisterGrid()
// decide to highlight QLine Box in case of change of register value
if (regValue != registerEditValue->text() && registerEditValue->text() != 0) {
registerEditValue->setStyleSheet("QLineEdit {border: 1px solid green;} QLineEdit:hover { border: 1px solid #3daee9; color: #eff0f1;}");
}
else {
} else {
// reset stylesheet
registerEditValue->setStyleSheet("");
}
@ -95,7 +92,7 @@ void RegistersWidget::setRegisterGrid()
registerEditValue->setText(regValue);
i++;
// decide if we should change column
if (i >= registerLen/numCols + 1) {
if (i >= registerLen / numCols + 1) {
i = 0;
col += 2;
}

View File

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

View File

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

View File

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