-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dark_mode' into 'master'
Support dark mode on Windows Closes #7985 See merge request OpenMW/openmw!4101
- Loading branch information
Showing
41 changed files
with
969 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "application.hpp" | ||
|
||
#include <QFile> | ||
#include <QStyle> | ||
#include <QStyleHints> | ||
|
||
#include <components/debug/debuglog.hpp> | ||
#include <components/misc/scalableicon.hpp> | ||
|
||
namespace Platform | ||
{ | ||
Application::Application(int& argc, char* argv[]) | ||
: QApplication(argc, argv) | ||
{ | ||
#if defined(WIN32) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) | ||
init(); | ||
} | ||
|
||
void Application::init() | ||
{ | ||
connect(this, &Application::darkModeChanged, this, &Application::updateStyle); | ||
|
||
const auto* hints = QGuiApplication::styleHints(); | ||
const auto currentStyle = QApplication::style()->objectName(); | ||
mInitialStyle = currentStyle.toStdString(); | ||
mCurrentStyle = currentStyle.toStdString(); | ||
if (hints->colorScheme() == Qt::ColorScheme::Dark) | ||
{ | ||
mDarkMode = true; | ||
if (currentStyle == "windowsvista") | ||
{ | ||
mCurrentStyle = "windows"; | ||
setStyle("windows"); | ||
|
||
QFile file(":/dark/dark.qss"); | ||
file.open(QIODevice::ReadOnly); | ||
setStyleSheet(file.readAll()); | ||
} | ||
} | ||
} | ||
|
||
void Application::updateStyle(bool isDark) | ||
{ | ||
if (mInitialStyle != "windowsvista") | ||
return; | ||
|
||
if (isDark) | ||
{ | ||
mCurrentStyle = "windows"; | ||
setStyle("windows"); | ||
|
||
QFile file(":/dark/dark.qss"); | ||
file.open(QIODevice::ReadOnly); | ||
setStyleSheet(file.readAll()); | ||
} | ||
else | ||
{ | ||
mCurrentStyle = mInitialStyle; | ||
setStyleSheet(""); | ||
setStyle(mInitialStyle.c_str()); | ||
} | ||
#endif | ||
} | ||
|
||
bool Application::notify(QObject* receiver, QEvent* event) | ||
{ | ||
try | ||
{ | ||
if (event->type() == QEvent::ThemeChange || event->type() == QEvent::PaletteChange) | ||
{ | ||
#if defined(WIN32) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) | ||
const auto* hints = QGuiApplication::styleHints(); | ||
const auto currentStyle = QApplication::style()->objectName(); | ||
bool isDark = hints->colorScheme() == Qt::ColorScheme::Dark; | ||
if (isDark != mDarkMode) | ||
{ | ||
mDarkMode = isDark; | ||
|
||
bool result = QApplication::notify(receiver, event); | ||
|
||
emit darkModeChanged(isDark); | ||
|
||
return result; | ||
} | ||
#endif | ||
Misc::ScalableIcon::updateAllIcons(); | ||
} | ||
|
||
return QApplication::notify(receiver, event); | ||
} | ||
catch (const std::exception& exception) | ||
{ | ||
Log(Debug::Error) << "An exception has been caught: " << exception.what(); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <QApplication> | ||
#include <QEvent> | ||
|
||
namespace Platform | ||
{ | ||
class Application : public QApplication | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
Application(int& argc, char* argv[]); | ||
|
||
#if defined(WIN32) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) | ||
void init(); | ||
|
||
private slots: | ||
void updateStyle(bool isDark); | ||
#endif | ||
|
||
signals: | ||
void darkModeChanged(bool); | ||
|
||
private: | ||
bool notify(QObject* receiver, QEvent* event) override; | ||
|
||
std::string mCurrentStyle{}; | ||
std::string mInitialStyle{}; | ||
bool mDarkMode{ false }; | ||
}; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
files/windows/QWindowsVistaDark/checkbox-checked-disabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.