Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt/Debugger: Memory View font based sizing, row coloring #7698

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Expand Up @@ -32,6 +32,7 @@ MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QTableWidget(parent)
verticalHeader()->hide();
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setShowGrid(false);
setAlternatingRowColors(true);

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

Expand All @@ -40,7 +41,7 @@ MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QTableWidget(parent)
connect(this, &MemoryViewWidget::customContextMenuRequested, this,
&MemoryViewWidget::OnContextMenu);
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &MemoryViewWidget::Update);

connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &MemoryViewWidget::Update);
setContextMenuPolicy(Qt::CustomContextMenu);

Update();
Expand Down Expand Up @@ -72,7 +73,10 @@ void MemoryViewWidget::Update()
if (rowCount() == 0)
setRowCount(1);

setRowHeight(0, 24);
const QFontMetrics fm(Settings::Instance().GetDebugFont());
const int fonth = fm.height();
verticalHeader()->setDefaultSectionSize(fonth + 3);
horizontalHeader()->setMinimumSectionSize(fonth + 3);

// Calculate (roughly) how many rows will fit in our table
int rows = std::round((height() / static_cast<float>(rowHeight(0))) - 0.25);
Expand All @@ -81,8 +85,6 @@ void MemoryViewWidget::Update()

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

u32 addr = m_address - ((rowCount() / 2) * 16) + i * 16;

auto* bp_item = new QTableWidgetItem;
Expand Down Expand Up @@ -185,19 +187,24 @@ void MemoryViewWidget::Update()

if (row_breakpoint)
{
bp_item->setData(Qt::DecorationRole,
Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(24, 24)));
bp_item->setData(
Qt::DecorationRole,
Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(fonth - 2, fonth - 2)));
}
}

setColumnWidth(0, 24 + 5);
setColumnWidth(0, fonth + 3);

for (int i = 1; i < columnCount(); i++)
{
resizeColumnToContents(i);
// Add some extra spacing because the default width is too small in most cases
setColumnWidth(i, columnWidth(i) * 1.1);
}

// Clearly denote which row the address box points to. Could look better than this.
item(rows / 2, 0)->setBackground(Qt::lightGray);

viewport()->update();
update();
}
Expand Down