Qt/Debugger: Highlight selection on dump address

This commit is contained in:
Stenzek 2024-09-09 20:37:04 +10:00
parent eeca12467c
commit f1f0e7de14
No known key found for this signature in database
3 changed files with 16 additions and 5 deletions

View File

@ -672,7 +672,7 @@ bool DebuggerWindow::scrollToMemoryAddress(VirtualMemoryAddress address)
setMemoryViewRegion(region.value());
const PhysicalMemoryAddress offset = phys_address - Bus::GetMemoryRegionStart(region.value());
m_ui.memoryView->scrolltoOffset(offset);
m_ui.memoryView->scrollToOffset(offset);
return true;
}

View File

@ -75,11 +75,13 @@ void MemoryViewWidget::clearHighlightRange()
viewport()->update();
}
void MemoryViewWidget::scrolltoOffset(size_t offset)
void MemoryViewWidget::scrollToOffset(size_t offset, bool select /* = true */)
{
const unsigned row = static_cast<unsigned>(offset / m_bytes_per_line);
verticalScrollBar()->setSliderPosition(static_cast<int>(row));
horizontalScrollBar()->setSliderPosition(0);
if (select)
setSelection(offset, false);
}
void MemoryViewWidget::scrollToAddress(size_t address)
@ -205,6 +207,7 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
if (!m_data)
return;
const QColor alt_fill_color(40, 40, 40);
const QColor highlight_color(100, 100, 0);
const QColor selected_color = viewport()->palette().color(QPalette::Highlight);
const QColor text_color = viewport()->palette().color(QPalette::WindowText);
@ -224,7 +227,9 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
const size_t data_offset = m_start_offset + (row * m_bytes_per_line);
const unsigned row_address = static_cast<unsigned>(m_address_offset + data_offset);
const int draw_x = m_char_width / 2 - offsetX;
if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_highlight_start, m_highlight_end))
if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_selected_address, m_selected_address + 1))
painter.fillRect(0, y - m_char_height + 3, addressWidth(), m_char_height, selected_color);
else if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_highlight_start, m_highlight_end))
painter.fillRect(0, y - m_char_height + 3, addressWidth(), m_char_height, highlight_color);
const QString address_text(QString::asprintf("%08X", row_address));
@ -244,7 +249,7 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
for (unsigned col = 0; col < m_bytes_per_line; col++)
{
if ((col % 2) != 0)
painter.fillRect(x, 0, HEX_CHAR_WIDTH, height(), viewport()->palette().color(QPalette::AlternateBase));
painter.fillRect(x, 0, HEX_CHAR_WIDTH, height(), alt_fill_color);
x += HEX_CHAR_WIDTH;
}
@ -393,6 +398,11 @@ void MemoryViewWidget::updateSelectedByte(const QPoint& pos)
}
}
setSelection(new_selection, new_ascii);
}
void MemoryViewWidget::setSelection(size_t new_selection, bool new_ascii)
{
if (new_selection != m_selected_address || new_ascii != m_selection_was_ascii)
{
m_selected_address = new_selection;

View File

@ -23,7 +23,7 @@ public:
void setData(size_t address_offset, void* data_ptr, size_t data_size, bool data_editable, EditCallback edit_callback);
void setHighlightRange(size_t start, size_t end);
void clearHighlightRange();
void scrolltoOffset(size_t offset);
void scrollToOffset(size_t offset, bool select = true);
void scrollToAddress(size_t address);
void setFont(const QFont& font);
@ -49,6 +49,7 @@ private:
int asciiWidth() const;
void updateMetrics();
void updateSelectedByte(const QPoint& pos);
void setSelection(size_t new_selection, bool new_ascii);
void expandCurrentDataToInclude(size_t offset);
void* m_data;