From 700eca1baac5c944432f2a2d806cd09d6ca803ae Mon Sep 17 00:00:00 2001 From: TryTwo Date: Thu, 20 Oct 2022 17:58:22 -0700 Subject: [PATCH] MemoryViewWidget set target address as selected. Fix focus call. Always color selected item blue. --- .../DolphinQt/Debugger/MemoryViewWidget.cpp | 32 +++++++++++++++---- .../DolphinQt/Debugger/MemoryViewWidget.h | 2 ++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index 81178106af..e83e77eb1b 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -56,8 +56,17 @@ public: 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); @@ -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); @@ -440,6 +446,10 @@ void MemoryViewWidget::UpdateColumns() const Type type = static_cast(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); } } } @@ -743,6 +753,7 @@ void MemoryViewWidget::SetBPType(BPType type) void MemoryViewWidget::SetAddress(u32 address) { + m_address_highlight = address; if (m_address == address) return; @@ -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); } @@ -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(); +} diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h index ddf93d84d2..19cd2dd85b 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h @@ -60,6 +60,7 @@ public: 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); @@ -85,6 +86,7 @@ private: 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;