Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11232 from TryTwo/PR_MemoryView_highlighting
Debugger MemoryViewWidget: always highlight target address
  • Loading branch information
AdmiralCurtiss committed Dec 4, 2022
2 parents 51dfab6 + 700eca1 commit 2bd47d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Expand Up @@ -56,8 +56,17 @@ class MemoryViewTable final : public QTableWidget
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setShowGrid(false);
setContextMenuPolicy(Qt::CustomContextMenu);
setSelectionMode(SingleSelection);
// Selection will be set programmatically. User will still get an outline on clicked items.
setSelectionMode(NoSelection);
setTextElideMode(Qt::TextElideMode::ElideNone);

// Prevent colors from changing based on focus.
QPalette palette(m_view->palette());
palette.setBrush(QPalette::Inactive, QPalette::Highlight, palette.brush(QPalette::Highlight));
palette.setBrush(QPalette::Inactive, QPalette::HighlightedText,
palette.brush(QPalette::HighlightedText));
setPalette(palette);

setRowCount(30);
setColumnCount(8);

Expand Down Expand Up @@ -398,9 +407,6 @@ void MemoryViewWidget::Update()
row_item->setText(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
row_item->setData(USER_ROLE_CELL_ADDRESS, row_address);

if (row_address == address)
row_item->setSelected(true);

for (int c = 0; c < m_data_columns; c++)
{
auto* item = m_table->item(i, c + MISC_COLUMNS);
Expand Down Expand Up @@ -440,6 +446,10 @@ void MemoryViewWidget::UpdateColumns()
const Type type = static_cast<Type>(cell_item->data(USER_ROLE_VALUE_TYPE).toInt());

cell_item->setText(ValueToString(cell_address, type));

// Set search address to selected / colored
if (cell_address == m_address_highlight)
cell_item->setSelected(true);
}
}
}
Expand Down Expand Up @@ -743,6 +753,7 @@ void MemoryViewWidget::SetBPType(BPType type)

void MemoryViewWidget::SetAddress(u32 address)
{
m_address_highlight = address;
if (m_address == address)
return;

Expand Down Expand Up @@ -868,21 +879,23 @@ void MemoryViewWidget::ScrollbarActionTriggered(int action)
{
// User is currently dragging the scrollbar.
// Adjust the memory view by the exact drag difference.
SetAddress(m_address + difference * m_bytes_per_row);
m_address += difference * m_bytes_per_row;
Update();
}
else
{
if (std::abs(difference) == 1)
{
// User clicked the arrows at the top or bottom, go up/down one row.
SetAddress(m_address + difference * m_bytes_per_row);
m_address += difference * m_bytes_per_row;
}
else
{
// User clicked the free part of the scrollbar, go up/down one page.
SetAddress(m_address + (difference < 0 ? -1 : 1) * m_bytes_per_row * m_table->rowCount());
m_address += (difference < 0 ? -1 : 1) * m_bytes_per_row * m_table->rowCount();
}

Update();
// Manually reset the draggable part of the bar back to the center.
m_scrollbar->setSliderPosition(SCROLLBAR_CENTER);
}
Expand All @@ -893,3 +906,8 @@ void MemoryViewWidget::ScrollbarSliderReleased()
// Reset the draggable part of the bar back to the center.
m_scrollbar->setValue(SCROLLBAR_CENTER);
}

void MemoryViewWidget::SetFocus() const
{
m_table->setFocus();
}
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.h
Expand Up @@ -60,6 +60,7 @@ class MemoryViewWidget final : public QWidget
void SetDisplay(Type type, int bytes_per_row, int alignment, bool dual_view);
void SetBPType(BPType type);
void SetAddress(u32 address);
void SetFocus() const;

void SetBPLoggingEnabled(bool enabled);

Expand All @@ -85,6 +86,7 @@ class MemoryViewWidget final : public QWidget
BPType m_bp_type = BPType::ReadWrite;
bool m_do_log = true;
u32 m_address = 0x80000000;
u32 m_address_highlight = 0;
int m_font_width = 0;
int m_font_vspace = 0;
int m_bytes_per_row = 16;
Expand Down

0 comments on commit 2bd47d1

Please sign in to comment.