Revert "More work on theming"

This reverts commit cc775770bf.
This commit is contained in:
Nayla Hanegan 2024-05-23 17:34:15 -04:00
parent cc775770bf
commit b4cc0fc9ca
6 changed files with 6 additions and 174 deletions

View file

@ -420,7 +420,9 @@ u32 CEXIIPL::GetEmulatedTime(Core::System& system, u32 epoch)
} }
else else
{ {
ltime = Common::Timer::GetLocalTimeSinceJan1970() - system.GetSystemTimers().GetLocalTimeRTCOffset(); ASSERT(!Core::WantsDeterminism());
ltime = Common::Timer::GetLocalTimeSinceJan1970() -
system.GetSystemTimers().GetLocalTimeRTCOffset();
} }
return static_cast<u32>(ltime) - epoch; return static_cast<u32>(ltime) - epoch;

View file

@ -5,7 +5,7 @@
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <vector> #include <vector>
#include <qoperatingsystemversion.h>
#include <Windows.h> #include <Windows.h>
#endif #endif
@ -257,14 +257,6 @@ int main(int argc, char* argv[])
Settings::Instance().InitDefaultPalette(); Settings::Instance().InitDefaultPalette();
Settings::Instance().UpdateSystemDark(); Settings::Instance().UpdateSystemDark();
#ifdef _WIN32
auto current = QOperatingSystemVersion::current();
if (current >= QOperatingSystemVersion::Windows11)
{
Settings::Instance().ApplyStyleWin10();
}
#endif
MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))}; MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))};
win.Show(); win.Show();

View file

@ -32,8 +32,6 @@
#ifndef _WIN32 #ifndef _WIN32
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include <windows.h>
#include <iostream>
#endif #endif
#include "Common/ScopeGuard.h" #include "Common/ScopeGuard.h"
@ -148,7 +146,6 @@
#endif #endif
#include <qprocess.h> #include <qprocess.h>
#include <qoperatingsystemversion.h>
#if defined(__unix__) || defined(__unix) || defined(__APPLE__) #if defined(__unix__) || defined(__unix) || defined(__APPLE__)
void MainWindow::OnSignal() void MainWindow::OnSignal()
@ -244,15 +241,6 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
ConnectMenuBar(); ConnectMenuBar();
ConnectHotkeys(); ConnectHotkeys();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
auto current = QOperatingSystemVersion::current();
if (current >= QOperatingSystemVersion::Windows11)
{
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[](Qt::ColorScheme colorScheme) { Settings::Instance().ApplyStyleWin10(); });
}
#endif
connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this, connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this,
&MainWindow::ShowGeneralWindow); &MainWindow::ShowGeneralWindow);
@ -1870,37 +1858,9 @@ QSize MainWindow::sizeHint() const
} }
#ifdef _WIN32 #ifdef _WIN32
bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
{ {
MSG* msg = reinterpret_cast<MSG*>(message); return false;
auto current = QOperatingSystemVersion::current();
if (msg && msg->message == WM_SETTINGCHANGE &&
(current >= QOperatingSystemVersion::Windows11) &&
msg->lParam != NULL &&
std::wstring_view(L"ImmersiveColorSet")
.compare(reinterpret_cast<const wchar_t*>(msg->lParam)) == 0)
{
// Windows light/dark theme has changed. Update our flag and refresh the theme.
auto& settings = Settings::Instance();
const bool was_dark_before = settings.IsSystemDark();
settings.UpdateSystemDark();
if (settings.IsSystemDark() != was_dark_before)
{
auto current = QOperatingSystemVersion::current();
if (current >= QOperatingSystemVersion::Windows11)
{
settings.ApplyStyleWin10();
// force the colors in the Skylander window to update
if (m_skylander_window)
m_skylander_window->RefreshList();
}
}
return true; // Event was handled
}
return false; // Event was not handled
} }
#endif #endif

View file

@ -78,10 +78,6 @@ public:
const std::string& movie_path); const std::string& movie_path);
~MainWindow(); ~MainWindow();
#ifdef _WIN32
bool IsWindows10OrLower();
#endif
void Show(); void Show();
WindowSystemInfo GetWindowSystemInfo() const; WindowSystemInfo GetWindowSystemInfo() const;

View file

@ -124,20 +124,6 @@ void Settings::SetThemeName(const QString& theme_name)
emit ThemeChanged(); emit ThemeChanged();
} }
QString Settings::GetUserStyleName() const
{
if (GetQSettings().contains(QStringLiteral("userstyle/name")))
return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
// Migration code for the old way of storing this setting
return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
}
void Settings::SetUserStyleName(const QString& stylesheet_name)
{
GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
}
void Settings::InitDefaultPalette() void Settings::InitDefaultPalette()
{ {
s_default_palette = std::make_unique<QPalette>(qApp->palette()); s_default_palette = std::make_unique<QPalette>(qApp->palette());
@ -172,111 +158,7 @@ bool Settings::IsSystemDark()
bool Settings::IsThemeDark() bool Settings::IsThemeDark()
{ {
return qApp->palette().color(QPalette::Base).valueF() < 0.5; return qApp->palette().color(QPalette::Base).valueF() < 0.5;
}
// Calling this before the main window has been created breaks the style of some widgets.
void Settings::ApplyStyleWin10()
{
const StyleType style_type = GetStyleType();
const QString stylesheet_name = GetUserStyleName();
QString stylesheet_contents;
// If we haven't found one, we continue with an empty (default) style
if (!stylesheet_name.isEmpty() && style_type == StyleType::User)
{
// Load custom user stylesheet
QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX)));
QFile stylesheet(directory.filePath(stylesheet_name));
if (stylesheet.open(QFile::ReadOnly))
stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
}
#ifdef _WIN32
if (stylesheet_contents.isEmpty())
{
// No theme selected or found. Usually we would just fallthrough and set an empty stylesheet
// which would select Qt's default theme, but unlike other OSes we don't automatically get a
// default dark theme on Windows when the user has selected dark mode in the Windows settings.
// So manually check if the user wants dark mode and, if yes, load our embedded dark theme.
if (style_type == StyleType::Dark || (style_type != StyleType::Light && IsSystemDark()))
{
QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss"));
if (file.open(QFile::ReadOnly))
stylesheet_contents = QString::fromUtf8(file.readAll().data());
QPalette palette = qApp->style()->standardPalette();
palette.setColor(QPalette::Window, QColor(32, 32, 32));
palette.setColor(QPalette::WindowText, QColor(220, 220, 220));
palette.setColor(QPalette::Base, QColor(32, 32, 32));
palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48));
palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126));
palette.setColor(QPalette::Text, QColor(220, 220, 220));
palette.setColor(QPalette::Button, QColor(48, 48, 48));
palette.setColor(QPalette::ButtonText, QColor(220, 220, 220));
palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::Highlight, QColor(0, 120, 215));
palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
palette.setColor(QPalette::Link, QColor(100, 160, 220));
palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220));
qApp->setPalette(palette);
}
else
{
// reset any palette changes that may exist from a previously set dark mode
if (s_default_palette)
qApp->setPalette(*s_default_palette);
}
}
#endif
// Define tooltips style if not already defined
if (!stylesheet_contents.contains(QStringLiteral("QToolTip"), Qt::CaseSensitive))
{
const QPalette& palette = qApp->palette();
QColor window_color;
QColor text_color;
QColor unused_text_emphasis_color;
QColor border_color;
GetToolTipStyle(window_color, text_color, unused_text_emphasis_color, border_color, palette,
palette);
const auto tooltip_stylesheet =
QStringLiteral("QToolTip { background-color: #%1; color: #%2; padding: 8px; "
"border: 1px; border-style: solid; border-color: #%3; }")
.arg(window_color.rgba(), 0, 16)
.arg(text_color.rgba(), 0, 16)
.arg(border_color.rgba(), 0, 16);
stylesheet_contents.append(QStringLiteral("%1").arg(tooltip_stylesheet));
}
qApp->setStyleSheet(stylesheet_contents);
}
Settings::StyleType Settings::GetStyleType() const
{
if (GetQSettings().contains(QStringLiteral("userstyle/styletype")))
{
bool ok = false;
const int type_int = GetQSettings().value(QStringLiteral("userstyle/styletype")).toInt(&ok);
if (ok && type_int >= static_cast<int>(StyleType::MinValue) &&
type_int <= static_cast<int>(StyleType::MaxValue))
{
return static_cast<StyleType>(type_int);
}
}
// if the style type is unset or invalid, try the old enabled flag instead
const bool enabled = GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool();
return enabled ? StyleType::User : StyleType::System;
}
void Settings::SetStyleType(StyleType type)
{
GetQSettings().setValue(QStringLiteral("userstyle/styletype"), static_cast<int>(type));
// also set the old setting so that the config is correctly intepreted by older Dolphin builds
GetQSettings().setValue(QStringLiteral("userstyle/enabled"), type == StyleType::User);
} }
void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color, void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color,

View file

@ -76,7 +76,7 @@ public:
StyleType GetStyleType() const; StyleType GetStyleType() const;
// this evaluates the current stylesheet settings and refreshes the GUI with them // this evaluates the current stylesheet settings and refreshes the GUI with them
void ApplyStyleWin10(); void ApplyStyle();
void GetToolTipStyle(QColor& window_color, QColor& text_color, QColor& emphasis_text_color, void GetToolTipStyle(QColor& window_color, QColor& text_color, QColor& emphasis_text_color,
QColor& border_color, const QPalette& palette, QColor& border_color, const QPalette& palette,