Skip to content

Commit

Permalink
Debugger: Make various improvements to the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Feb 26, 2025
1 parent 56a41b3 commit 0a461fe
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 90 deletions.
33 changes: 18 additions & 15 deletions pcsx2-qt/Debugger/DebuggerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "DebugTools/DebugInterface.h"

#include "common/Assertions.h"
#include "common/Console.h"

DebuggerWidget::DebuggerWidget(const DebuggerWidgetParameters& parameters, u32 flags)
: QWidget(parameters.parent)
Expand All @@ -20,6 +19,7 @@ DebuggerWidget::DebuggerWidget(const DebuggerWidgetParameters& parameters, u32 f
, m_cpu_override(parameters.cpu_override)
, m_flags(flags)
{
updateStyleSheet();
}

DebugInterface& DebuggerWidget::cpu() const
Expand Down Expand Up @@ -126,7 +126,7 @@ void DebuggerWidget::toJson(JsonValueWrapper& json)
json.value().AddMember("isPrimary", m_is_primary, json.allocator());
}

bool DebuggerWidget::fromJson(JsonValueWrapper& json)
bool DebuggerWidget::fromJson(const JsonValueWrapper& json)
{
auto custom_display_name = json.value().FindMember("customDisplayName");
if (custom_display_name != json.value().MemberEnd() && custom_display_name->value.IsString())
Expand All @@ -139,19 +139,6 @@ bool DebuggerWidget::fromJson(JsonValueWrapper& json)
return true;
}

void DebuggerWidget::applyMonospaceFont()
{
// Easiest way to handle cross platform monospace fonts
// There are issues related to TabWidget -> Children font inheritance otherwise
#if defined(WIN32)
setStyleSheet(QStringLiteral("font: 10pt 'Lucida Console'"));
#elif defined(__APPLE__)
setStyleSheet(QStringLiteral("font: 10pt 'Monaco'"));
#else
setStyleSheet(QStringLiteral("font: 10pt 'Monospace'"));
#endif
}

void DebuggerWidget::switchToThisTab()
{
g_debugger_window->dockManager().switchToDebuggerWidget(this);
Expand Down Expand Up @@ -188,6 +175,22 @@ void DebuggerWidget::setDisplayNameSuffixNumber(std::optional<int> suffix_number
m_display_name_suffix_number = suffix_number;
}

void DebuggerWidget::updateStyleSheet()
{
if (m_flags & MONOSPACE_FONT)
{
// Easiest way to handle cross platform monospace fonts
// There are issues related to TabWidget -> Children font inheritance otherwise
#if defined(WIN32)
setStyleSheet(QStringLiteral("font: 10pt 'Lucida Console'"));
#elif defined(__APPLE__)
setStyleSheet(QStringLiteral("font: 10pt 'Monaco'"));
#else
setStyleSheet(QStringLiteral("font: 10pt 'Monospace'"));
#endif
}
}

void DebuggerWidget::goToInDisassembler(u32 address, bool switch_to_tab)
{
DebuggerEvents::GoToAddress event;
Expand Down
10 changes: 6 additions & 4 deletions pcsx2-qt/Debugger/DebuggerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ class DebuggerWidget : public QWidget
}

virtual void toJson(JsonValueWrapper& json);
virtual bool fromJson(JsonValueWrapper& json);

void applyMonospaceFont();
virtual bool fromJson(const JsonValueWrapper& json);

void switchToThisTab();

Expand All @@ -150,6 +148,8 @@ class DebuggerWidget : public QWidget
std::optional<int> displayNameSuffixNumber() const;
void setDisplayNameSuffixNumber(std::optional<int> suffix_number);

void updateStyleSheet();

static void goToInDisassembler(u32 address, bool switch_to_tab);
static void goToInMemoryView(u32 address, bool switch_to_tab);

Expand All @@ -158,7 +158,9 @@ class DebuggerWidget : public QWidget
{
NO_DEBUGGER_FLAGS = 0,
// Prevent the user from opening multiple dock widgets of this type.
DISALLOW_MULTIPLE_INSTANCES = 1 << 0
DISALLOW_MULTIPLE_INSTANCES = 1 << 0,
// Apply a stylesheet that gives all the text a monospace font.
MONOSPACE_FONT = 1 << 1
};

DebuggerWidget(const DebuggerWidgetParameters& parameters, u32 flags);
Expand Down
28 changes: 25 additions & 3 deletions pcsx2-qt/Debugger/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "DisassemblyWidget.h"

#include "Debugger/JsonValueWrapper.h"

#include "DebugTools/DebugInterface.h"
#include "DebugTools/DisassemblyManager.h"
#include "DebugTools/Breakpoints.h"
Expand All @@ -20,7 +22,7 @@
using namespace QtUtils;

DisassemblyWidget::DisassemblyWidget(const DebuggerWidgetParameters& parameters)
: DebuggerWidget(parameters, NO_DEBUGGER_FLAGS)
: DebuggerWidget(parameters, MONOSPACE_FONT)
{
m_ui.setupUi(this);

Expand All @@ -31,8 +33,6 @@ DisassemblyWidget::DisassemblyWidget(const DebuggerWidgetParameters& parameters)
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &DisassemblyWidget::customContextMenuRequested, this, &DisassemblyWidget::openContextMenu);

applyMonospaceFont();

connect(g_emu_thread, &EmuThread::onVMPaused, this, &DisassemblyWidget::gotoProgramCounterOnPause);

receiveEvent<DebuggerEvents::Refresh>([this](const DebuggerEvents::Refresh& event) -> bool {
Expand All @@ -56,6 +56,28 @@ DisassemblyWidget::DisassemblyWidget(const DebuggerWidgetParameters& parameters)

DisassemblyWidget::~DisassemblyWidget() = default;

void DisassemblyWidget::toJson(JsonValueWrapper& json)
{
DebuggerWidget::toJson(json);

json.value().AddMember("startAddress", m_visibleStart, json.allocator());
}

bool DisassemblyWidget::fromJson(const JsonValueWrapper& json)
{
if (!DebuggerWidget::fromJson(json))
return false;

auto start_address = json.value().FindMember("startAddress");
if (start_address != json.value().MemberEnd() && start_address->value.IsUint())
{
m_visibleStart = start_address->value.GetUint() & ~3;
repaint();
}

return true;
}

void DisassemblyWidget::contextCopyAddress()
{
QGuiApplication::clipboard()->setText(FetchSelectionInfo(SelectionInfo::ADDRESS));
Expand Down
16 changes: 9 additions & 7 deletions pcsx2-qt/Debugger/DisassemblyWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "DebuggerWidget.h"

#include "pcsx2/DebugTools/DebugInterface.h"
#include "pcsx2/DebugTools/DisassemblyManager.h"

#include <QtWidgets/QMenu>
Expand All @@ -21,15 +20,18 @@ class DisassemblyWidget final : public DebuggerWidget
DisassemblyWidget(const DebuggerWidgetParameters& parameters);
~DisassemblyWidget();

void toJson(JsonValueWrapper& json) override;
bool fromJson(const JsonValueWrapper& json) override;

// Required for the breakpoint list (ugh wtf)
QString GetLineDisasm(u32 address);

protected:
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void keyPressEvent(QKeyEvent* event);
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;

public slots:
void openContextMenu(QPoint pos);
Expand Down Expand Up @@ -63,7 +65,7 @@ public slots:
private:
Ui::DisassemblyWidget m_ui;

u32 m_visibleStart = 0x00336318; // The address of the first opcode shown(row 0)
u32 m_visibleStart = 0x100000; // The address of the first opcode shown(row 0)
u32 m_visibleRows;
u32 m_selectedAddressStart = 0;
u32 m_selectedAddressEnd = 0;
Expand Down
41 changes: 31 additions & 10 deletions pcsx2-qt/Debugger/Docking/DockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <QtCore/QTimer>
#include <QtCore/QtTranslation>
#include <QtWidgets/QPushButton>

#include "fmt/format.h"

Expand Down Expand Up @@ -454,19 +453,19 @@ QWidget* DockManager::createLayoutSwitcher(QWidget* menu_bar)
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
layout->addWidget(spacer);

bool layout_locked = Host::GetBaseBoolSettingValue("Debugger/UserInterface", "LayoutLocked", true);

QPushButton* lock_layout_toggle = new QPushButton;
connect(lock_layout_toggle, &QPushButton::toggled, this, [this, lock_layout_toggle](bool checked) {
setLayoutLocked(checked);
if (m_layout_locked)
lock_layout_toggle->setText(tr("Layout Locked"));
else
lock_layout_toggle->setText(tr("Layout Unlocked"));
});
lock_layout_toggle->setCheckable(true);
lock_layout_toggle->setChecked(m_layout_locked);
lock_layout_toggle->setChecked(layout_locked);
lock_layout_toggle->setFlat(true);
connect(lock_layout_toggle, &QPushButton::toggled, this, [this, lock_layout_toggle](bool checked) {
setLayoutLocked(checked, lock_layout_toggle, true);
});
layout->addWidget(lock_layout_toggle);

setLayoutLocked(layout_locked, lock_layout_toggle, false);

return container;
}

Expand Down Expand Up @@ -713,16 +712,30 @@ void DockManager::switchToDebuggerWidget(DebuggerWidget* widget)
}
}

void DockManager::updateStyleSheets()
{
if (m_current_layout == DockLayout::INVALID_INDEX)
return;

for (const auto& [unique_name, widget] : m_layouts.at(m_current_layout).debuggerWidgets())
widget->updateStyleSheet();
}

bool DockManager::isLayoutLocked()
{
return m_layout_locked;
}

void DockManager::setLayoutLocked(bool locked)
void DockManager::setLayoutLocked(bool locked, QPushButton* lock_layout_toggle, bool write_back)
{
m_layout_locked = locked;

if (lock_layout_toggle)
if (m_layout_locked)
lock_layout_toggle->setText(tr("Layout Locked"));
else
lock_layout_toggle->setText(tr("Layout Unlocked"));

updateToolBarLockState();

for (KDDockWidgets::Core::Group* group : KDDockWidgets::DockRegistry::self()->groups())
Expand All @@ -734,6 +747,14 @@ void DockManager::setLayoutLocked(bool locked)
if (stack->tabBar()->count() > 0)
stack->tabBar()->setTabText(0, stack->tabBar()->tabText(0));
}

if (write_back)
{
Host::SetBaseBoolSettingValue("Debugger/UserInterface", "LayoutLocked", m_layout_locked);

Host::CommitBaseSettingChanges();
g_emu_thread->applySettings();
}
}

void DockManager::updateToolBarLockState()
Expand Down
5 changes: 4 additions & 1 deletion pcsx2-qt/Debugger/Docking/DockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <kddockwidgets/core/Draggable_p.h>

#include <QtCore/QPointer>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTabBar>

class DockManager : public QObject
Expand Down Expand Up @@ -80,8 +81,10 @@ class DockManager : public QObject
void setPrimaryDebuggerWidget(DebuggerWidget* widget, bool is_primary);
void switchToDebuggerWidget(DebuggerWidget* widget);

void updateStyleSheets();

bool isLayoutLocked();
void setLayoutLocked(bool locked);
void setLayoutLocked(bool locked, QPushButton* lock_layout_toggle, bool write_back);
void updateToolBarLockState();

std::optional<BreakPointCpu> cpu();
Expand Down
5 changes: 5 additions & 0 deletions pcsx2-qt/Debugger/JsonValueWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class JsonValueWrapper
return m_value;
}

const rapidjson::Value& value() const
{
return m_value;
}

rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>& allocator()
{
return m_allocator;
Expand Down
28 changes: 23 additions & 5 deletions pcsx2-qt/Debugger/Memory/MemoryViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: GPL-3.0+

#include "MemoryViewWidget.h"
#include "common/Console.h"

#include "Debugger/JsonValueWrapper.h"

#include "QtHost.h"
#include "QtUtils.h"
Expand Down Expand Up @@ -452,7 +453,7 @@ bool MemoryViewTable::KeyPress(int key, QChar keychar, DebugInterface& cpu)
MemoryViewWidget
*/
MemoryViewWidget::MemoryViewWidget(const DebuggerWidgetParameters& parameters)
: DebuggerWidget(parameters, NO_DEBUGGER_FLAGS)
: DebuggerWidget(parameters, MONOSPACE_FONT)
, m_table(this)
{
ui.setupUi(this);
Expand All @@ -462,9 +463,7 @@ MemoryViewWidget::MemoryViewWidget(const DebuggerWidgetParameters& parameters)
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &MemoryViewWidget::customContextMenuRequested, this, &MemoryViewWidget::openContextMenu);

m_table.UpdateStartAddress(0x480000);

applyMonospaceFont();
m_table.UpdateStartAddress(0x100000);

receiveEvent<DebuggerEvents::Refresh>([this](const DebuggerEvents::Refresh& event) -> bool {
update();
Expand All @@ -487,6 +486,25 @@ MemoryViewWidget::MemoryViewWidget(const DebuggerWidgetParameters& parameters)

MemoryViewWidget::~MemoryViewWidget() = default;

void MemoryViewWidget::toJson(JsonValueWrapper& json)
{
DebuggerWidget::toJson(json);

json.value().AddMember("startAddress", m_table.startAddress, json.allocator());
}

bool MemoryViewWidget::fromJson(const JsonValueWrapper& json)
{
if (!DebuggerWidget::fromJson(json))
return false;

auto start_address = json.value().FindMember("startAddress");
if (start_address != json.value().MemberEnd() && start_address->value.IsUint())
m_table.UpdateStartAddress(start_address->value.GetUint());

return true;
}

void MemoryViewWidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
Expand Down
13 changes: 8 additions & 5 deletions pcsx2-qt/Debugger/Memory/MemoryViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ class MemoryViewWidget final : public DebuggerWidget
MemoryViewWidget(const DebuggerWidgetParameters& parameters);
~MemoryViewWidget();

void toJson(JsonValueWrapper& json) override;
bool fromJson(const JsonValueWrapper& json) override;

protected:
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void keyPressEvent(QKeyEvent* event);
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;

public slots:
void openContextMenu(QPoint pos);
Expand Down
Loading

0 comments on commit 0a461fe

Please sign in to comment.