Skip to content

Commit

Permalink
Merge pull request #7697 from TryTwo/Debugger_UI_CodeView_Font_Based_…
Browse files Browse the repository at this point in the history
…Sizing

Qt/Debugger: Improve Code View
  • Loading branch information
leoetlino committed May 11, 2019
2 parents a0a0a68 + 86d1e6c commit 3bcee22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
48 changes: 33 additions & 15 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
Expand Up @@ -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();
Expand All @@ -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)
Expand All @@ -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;

Expand All @@ -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})
{
Expand Down Expand Up @@ -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);
Expand All @@ -179,8 +199,6 @@ void CodeViewWidget::Update()
}

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

g_symbolDB.FillInCallers();

repaint();
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.h
Expand Up @@ -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();
Expand Down

0 comments on commit 3bcee22

Please sign in to comment.