Skip to content
Permalink
Browse files

Qt/Debugger: Improve Code View

* Use font based sizing for row height. Fits more rows on screen.
* Adds whitespace for better formatting and minimum column width.
  Helps prevent frequent resizing while scrolling.
  • Loading branch information...
TryTwo authored and leoetlino committed Jan 12, 2019
1 parent a0a0a68 commit 86d1e6cd7eb0866cbeef63c3a5c339c9f51ce011
Showing with 35 additions and 15 deletions.
  1. +33 −15 Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
  2. +2 −0 Source/Core/DolphinQt/Debugger/CodeViewWidget.h
@@ -45,23 +45,21 @@ CodeViewWidget::CodeViewWidget()
setSelectionBehavior(QAbstractItemView::SelectRows);

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

for (int i = 0; i < columnCount(); i++)
{
horizontalHeader()->setSectionResizeMode(i, QHeaderView::Fixed);
}
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);

verticalHeader()->hide();
horizontalHeader()->hide();
horizontalHeader()->setStretchLastSection(true);

setFont(Settings::Instance().GetDebugFont());

Update();
FontBasedSizing();

connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu);
connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged);
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont);
connect(&Settings::Instance(), &Settings::DebugFontChanged, this,
&CodeViewWidget::FontBasedSizing);

connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] {
m_address = PC;
Update();
@@ -82,6 +80,16 @@ static u32 GetBranchFromAddress(u32 addr)
return std::stoul(hex, nullptr, 16);
}

void CodeViewWidget::FontBasedSizing()
{
const QFontMetrics fm(Settings::Instance().GetDebugFont());
const int rowh = fm.height() + 1;
verticalHeader()->setMaximumSectionSize(rowh);
horizontalHeader()->setMinimumSectionSize(rowh + 5);
setColumnWidth(0, rowh + 5);
Update();
}

void CodeViewWidget::Update()
{
if (m_updating)
@@ -98,8 +106,11 @@ void CodeViewWidget::Update()

setRowCount(rows);

const QFontMetrics fm(Settings::Instance().GetDebugFont());
const int rowh = fm.height() + 1;

for (int i = 0; i < rows; i++)
setRowHeight(i, 24);
setRowHeight(i, rowh);

u32 pc = PowerPC::ppcState.pc;

@@ -122,9 +133,17 @@ void CodeViewWidget::Update()
std::string param = (split == std::string::npos ? "" : disas.substr(split + 1));
std::string desc = PowerPC::debug_interface.GetDescription(addr);

auto* ins_item = new QTableWidgetItem(QString::fromStdString(ins));
auto* param_item = new QTableWidgetItem(QString::fromStdString(param));
auto* description_item = new QTableWidgetItem(QString::fromStdString(desc));
// Adds whitespace and a minimum size to ins and param. Helps to prevent frequent resizing while
// scrolling.
const QString ins_formatted =
QStringLiteral("%1").arg(QString::fromStdString(ins), -7, QLatin1Char(' '));
const QString param_formatted =
QStringLiteral("%1").arg(QString::fromStdString(param), -19, QLatin1Char(' '));
const QString desc_formatted = QStringLiteral("%1 ").arg(QString::fromStdString(desc));

auto* ins_item = new QTableWidgetItem(ins_formatted);
auto* param_item = new QTableWidgetItem(param_formatted);
auto* description_item = new QTableWidgetItem(desc_formatted);

for (auto* item : {bp_item, addr_item, ins_item, param_item, description_item})
{
@@ -162,8 +181,9 @@ void CodeViewWidget::Update()

if (PowerPC::debug_interface.IsBreakpoint(addr))
{
bp_item->setData(Qt::DecorationRole,
Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(24, 24)));
bp_item->setData(
Qt::DecorationRole,
Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(rowh - 2, rowh - 2)));
}

setItem(i, 0, bp_item);
@@ -179,8 +199,6 @@ void CodeViewWidget::Update()
}

resizeColumnsToContents();
setColumnWidth(0, 24 + 5);

g_symbolDB.FillInCallers();

repaint();
@@ -30,6 +30,8 @@ class CodeViewWidget : public QTableWidget
u32 GetContextAddress() const;
void SetAddress(u32 address, SetAddressUpdate update);

// Set tighter row height. Set BP column sizing. This needs to run when font type changes.
void FontBasedSizing();
void Update();

void ToggleBreakpoint();

0 comments on commit 86d1e6c

Please sign in to comment.
You can’t perform that action at this time.