Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11794 from shuffle2/color-scheme-changed
DolphinQt: reset stylesheets on colorSchemeChanged
  • Loading branch information
lioncash committed Apr 26, 2023
2 parents e483b56 + bb227ad commit adbee91
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
17 changes: 14 additions & 3 deletions Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp
Expand Up @@ -7,10 +7,12 @@
#include <string>
#include <vector>

#include <QGuiApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QStyleHints>
#include <QTableWidget>
#include <QVBoxLayout>

Expand All @@ -30,6 +32,10 @@
#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/Settings.h"

static const QString RECORD_BUTTON_STYLESHEET =
QStringLiteral("QPushButton:checked { background-color: rgb(150, 0, 0); border-style: solid; "
"border-width: 3px; border-color: rgb(150,0,0); color: rgb(255, 255, 255);}");

CodeDiffDialog::CodeDiffDialog(CodeWidget* parent) : QDialog(parent), m_code_widget(parent)
{
setWindowTitle(tr("Code Diff Tool"));
Expand All @@ -54,9 +60,7 @@ void CodeDiffDialog::CreateWidgets()
m_include_btn = new QPushButton(tr("Code has been executed"));
m_record_btn = new QPushButton(tr("Start Recording"));
m_record_btn->setCheckable(true);
m_record_btn->setStyleSheet(
QStringLiteral("QPushButton:checked { background-color: rgb(150, 0, 0); border-style: solid; "
"border-width: 3px; border-color: rgb(150,0,0); color: rgb(255, 255, 255);}"));
m_record_btn->setStyleSheet(RECORD_BUTTON_STYLESHEET);

m_exclude_btn->setEnabled(false);
m_include_btn->setEnabled(false);
Expand Down Expand Up @@ -105,6 +109,13 @@ void CodeDiffDialog::CreateWidgets()

void CodeDiffDialog::ConnectWidgets()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) {
m_record_btn->setStyleSheet(RECORD_BUTTON_STYLESHEET);
});
#endif

connect(m_record_btn, &QPushButton::toggled, this, &CodeDiffDialog::OnRecord);
connect(m_include_btn, &QPushButton::pressed, [this]() { Update(true); });
connect(m_exclude_btn, &QPushButton::pressed, [this]() { Update(false); });
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QPainter>
#include <QResizeEvent>
#include <QScrollBar>
#include <QStyleHints>
#include <QStyledItemDelegate>
#include <QTableWidgetItem>
#include <QWheelEvent>
Expand Down Expand Up @@ -161,6 +162,11 @@ CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance())

FontBasedSizing();

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) { OnSelectionChanged(); });
#endif

connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu);
connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged);
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont);
Expand Down
17 changes: 14 additions & 3 deletions Source/Core/DolphinQt/Debugger/CodeWidget.cpp
Expand Up @@ -9,11 +9,13 @@

#include <QGridLayout>
#include <QGroupBox>
#include <QGuiApplication>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QSplitter>
#include <QStyleHints>
#include <QTableWidget>
#include <QWidget>

Expand All @@ -28,6 +30,10 @@
#include "DolphinQt/Host.h"
#include "DolphinQt/Settings.h"

static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral(
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
"margin-right: 10px; }");

CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance())
{
setWindowTitle(tr("Code"));
Expand Down Expand Up @@ -104,9 +110,7 @@ void CodeWidget::CreateWidgets()
m_search_address->setPlaceholderText(tr("Search Address"));

m_box_splitter = new QSplitter(Qt::Vertical);
m_box_splitter->setStyleSheet(QStringLiteral(
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
"margin-right: 10px; }"));
m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);

auto add_search_line_edit = [this](const QString& name, QListWidget* list_widget) {
auto* widget = new QWidget;
Expand Down Expand Up @@ -154,6 +158,13 @@ void CodeWidget::CreateWidgets()

void CodeWidget::ConnectWidgets()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) {
m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);
});
#endif

connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress);
connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress);
connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols);
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -14,6 +14,7 @@
#include <QIcon>
#include <QMimeData>
#include <QStackedWidget>
#include <QStyleHints>
#include <QVBoxLayout>
#include <QWindow>

Expand Down Expand Up @@ -238,6 +239,13 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
ConnectMenuBar();
ConnectHotkeys();

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[](Qt::ColorScheme colorScheme) {
Settings::Instance().SetCurrentUserStyle(Settings::Instance().GetCurrentUserStyle());
});
#endif

connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this,
&MainWindow::ShowGeneralWindow);

Expand Down

0 comments on commit adbee91

Please sign in to comment.