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 27, 2025
1 parent e3f4c8d commit 6aa4480
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 163 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-family: 'Lucida Console'"));
#elif defined(__APPLE__)
setStyleSheet(QStringLiteral("font-family: 'Monaco'"));
#else
setStyleSheet(QStringLiteral("font-family: '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
91 changes: 77 additions & 14 deletions pcsx2-qt/Debugger/DebuggerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DebuggerWindow::DebuggerWindow(QWidget* parent)
g_debugger_window = this;

setupDefaultToolBarState();
setupFonts();

m_dock_manager->loadLayouts();

Expand Down Expand Up @@ -133,11 +134,87 @@ DockManager& DebuggerWindow::dockManager()
return *m_dock_manager;
}

void DebuggerWindow::setupDefaultToolBarState()
{
// Hiding all the toolbars lets us save the default state of the window with
// all the toolbars hidden. The DockManager will show the appropriate ones
// later anyway.
for (QToolBar* toolbar : findChildren<QToolBar*>())
toolbar->hide();

m_default_toolbar_state = saveState();

for (QToolBar* toolbar : findChildren<QToolBar*>())
connect(toolbar, &QToolBar::topLevelChanged, m_dock_manager, &DockManager::updateToolBarLockState);
}

void DebuggerWindow::clearToolBarState()
{
restoreState(m_default_toolbar_state);
}

void DebuggerWindow::setupFonts()
{
m_font_size = Host::GetBaseIntSettingValue("Debugger/UserInterface", "FontSize", DEFAULT_FONT_SIZE);
if (m_font_size < MINIMUM_FONT_SIZE || m_font_size > MAXIMUM_FONT_SIZE)
m_font_size = DEFAULT_FONT_SIZE;

m_ui.actionIncreaseFontSize->setShortcuts(QKeySequence::ZoomIn);
connect(m_ui.actionIncreaseFontSize, &QAction::triggered, this, [this]() {
if (m_font_size >= MAXIMUM_FONT_SIZE)
return;

m_font_size++;

updateFontActions();
updateStyleSheets();
saveFontSize();
});

m_ui.actionDecreaseFontSize->setShortcut(QKeySequence::ZoomOut);
connect(m_ui.actionDecreaseFontSize, &QAction::triggered, this, [this]() {
if (m_font_size <= MINIMUM_FONT_SIZE)
return;

m_font_size--;

updateFontActions();
updateStyleSheets();
saveFontSize();
});

connect(m_ui.actionResetFontSize, &QAction::triggered, this, [this]() {
m_font_size = DEFAULT_FONT_SIZE;

updateFontActions();
updateStyleSheets();
saveFontSize();
});

updateFontActions();
updateStyleSheets();
}

void DebuggerWindow::updateFontActions()
{
m_ui.actionIncreaseFontSize->setEnabled(m_font_size < MAXIMUM_FONT_SIZE);
m_ui.actionDecreaseFontSize->setEnabled(m_font_size > MINIMUM_FONT_SIZE);
}

void DebuggerWindow::saveFontSize()
{
Host::SetBaseIntSettingValue("Debugger/UserInterface", "FontSize", m_font_size);
Host::CommitBaseSettingChanges();
g_emu_thread->applySettings();
}

void DebuggerWindow::updateStyleSheets()
{
setStyleSheet(QString("* { font-size: %1pt; } QTabBar { font-size: %2pt; }").arg(m_font_size).arg(m_font_size + 1));

dockManager().updateStyleSheets();
}

void DebuggerWindow::onVMStateChanged()
{
if (!QtHost::IsVMPaused())
Expand Down Expand Up @@ -344,17 +421,3 @@ DebugInterface* DebuggerWindow::currentCPU()

return &DebugInterface::get(*maybe_cpu);
}

void DebuggerWindow::setupDefaultToolBarState()
{
// Hiding all the toolbars lets us save the default state of the window with
// all the toolbars hidden. The DockManager will show the appropriate ones
// later anyway.
for (QToolBar* toolbar : findChildren<QToolBar*>())
toolbar->hide();

m_default_toolbar_state = saveState();

for (QToolBar* toolbar : findChildren<QToolBar*>())
connect(toolbar, &QToolBar::topLevelChanged, m_dock_manager, &DockManager::updateToolBarLockState);
}
12 changes: 10 additions & 2 deletions pcsx2-qt/Debugger/DebuggerWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class DebuggerWindow : public KDDockWidgets::QtWidgets::MainWindow

DockManager& dockManager();

void setupDefaultToolBarState();
void clearToolBarState();
void setupFonts();
void updateFontActions();
void saveFontSize();
void updateStyleSheets();

public slots:
void onVMStateChanged();
Expand All @@ -41,13 +46,16 @@ public slots:
private:
DebugInterface* currentCPU();

void setupDefaultToolBarState();

Ui::DebuggerWindow m_ui;

DockManager* m_dock_manager;

QByteArray m_default_toolbar_state;

int m_font_size;
static const constexpr int DEFAULT_FONT_SIZE = 10;
static const constexpr int MINIMUM_FONT_SIZE = 5;
static const constexpr int MAXIMUM_FONT_SIZE = 30;
};

extern DebuggerWindow* g_debugger_window;
45 changes: 44 additions & 1 deletion pcsx2-qt/Debugger/DebuggerWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<string>View</string>
</property>
<addaction name="actionOnTop"/>
<addaction name="separator"/>
<addaction name="actionIncreaseFontSize"/>
<addaction name="actionDecreaseFontSize"/>
<addaction name="actionResetFontSize"/>
</widget>
<widget class="QMenu" name="menuLayouts">
<property name="title">
Expand Down Expand Up @@ -105,6 +109,9 @@
<bool>false</bool>
</attribute>
<addaction name="actionOnTop"/>
<addaction name="actionIncreaseFontSize"/>
<addaction name="actionDecreaseFontSize"/>
<addaction name="actionResetFontSize"/>
</widget>
<widget class="QToolBar" name="toolBarSystem">
<property name="windowTitle">
Expand Down Expand Up @@ -224,7 +231,7 @@
</action>
<action name="actionClose">
<property name="icon">
<iconset theme="door-open-line"/>
<iconset theme="close-line"/>
</property>
<property name="text">
<string>Close</string>
Expand All @@ -233,6 +240,42 @@
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionIncreaseFontSize">
<property name="icon">
<iconset theme="zoom-in-line"/>
</property>
<property name="text">
<string>Increase Font Size</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionDecreaseFontSize">
<property name="icon">
<iconset theme="zoom-out-line"/>
</property>
<property name="text">
<string>Decrease Font Size</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="actionResetFontSize">
<property name="icon">
<iconset theme="refresh-line"/>
</property>
<property name="text">
<string>Reset Font Size</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
</property>
</action>
</widget>
<resources/>
<connections/>
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
Loading

0 comments on commit 6aa4480

Please sign in to comment.