Skip to content

Commit

Permalink
src/gui/widgets/overlay/playermenu: fix unreadable text in dark mode
Browse files Browse the repository at this point in the history
On Windows if the user enabled dark mode, the text would be unreadable.
This is due to a Qt bug as far as I can tell. This makes it so the Alt
proxy style isn't used on Windows when dark mode is set. macOS and Linux
remain unaffected by this change.
  • Loading branch information
ripose-jp committed Jun 23, 2024
1 parent 40973ce commit 05d1ef5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
53 changes: 50 additions & 3 deletions src/gui/widgets/overlay/playermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class MenuStyle : public QProxyStyle
{
public:
using QProxyStyle::QProxyStyle;

int styleHint(
StyleHint hint,
const QStyleOption *opt,
Expand All @@ -68,7 +70,7 @@ PlayerMenu::PlayerMenu(QWidget *parent)
{
m_ui->setupUi(this);

setStyle(new MenuStyle());
initStyle();

updateSubtitlePauseAction();

Expand Down Expand Up @@ -277,6 +279,11 @@ PlayerMenu::PlayerMenu(QWidget *parent)
);
}

connect(
mediator, &GlobalMediator::interfaceSettingsChanged,
this, &PlayerMenu::initStyle
);

#ifdef OCR_SUPPORT
connect(
mediator, &GlobalMediator::ocrSettingsChanged,
Expand All @@ -287,14 +294,54 @@ PlayerMenu::PlayerMenu(QWidget *parent)

PlayerMenu::~PlayerMenu()
{
setStyle(nullptr);
clearTracks();
delete m_ui;
}

/* End Constructor/Destructor */
#ifdef OCR_SUPPORT
/* Begin Initializers */

void PlayerMenu::initStyle()
{
#ifdef Q_OS_WIN
QSettings settings;
settings.beginGroup(Constants::Settings::Interface::GROUP);
Constants::Theme theme = static_cast<Constants::Theme>(
settings.value(
Constants::Settings::Interface::THEME,
static_cast<int>(Constants::Settings::Interface::THEME_DEFAULT)
).toInt()
);
settings.endGroup();

switch (theme)
{
case Constants::Theme::Dark:
/* Not using MenuStyle in dark mode is due to a bug in Qt that
* messes up colors on Windows when using a proxy style. This only
* makes text unreadable in dark mode. */
setStyle(nullptr);
break;

case Constants::Theme::Light:
case Constants::Theme::System:
default:
std::unique_ptr<MenuStyle> menuStyle =
std::make_unique<MenuStyle>(QApplication::style());
setStyle(menuStyle.get());
m_menuStyle = std::move(menuStyle);
break;
}
#else
std::unique_ptr<MenuStyle> menuStyle =
std::make_unique<MenuStyle>(QApplication::style());
setStyle(menuStyle.get());
m_menuStyle = std::move(menuStyle);
#endif // Q_OS_WIN
}

#ifdef OCR_SUPPORT
void PlayerMenu::initOCRSettings()
{
QSettings settings;
Expand All @@ -307,9 +354,9 @@ void PlayerMenu::initOCRSettings()

settings.endGroup();
}
#endif // OCR_SUPPORT

/* End Initializers */
#endif // OCR_SUPPORT
/* Begin Status Methods */

bool PlayerMenu::menuOpen() const
Expand Down
9 changes: 9 additions & 0 deletions src/gui/widgets/overlay/playermenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class QActionGroup;
class QAction;
class QMenu;
class MenuStyle;

namespace Ui
{
Expand Down Expand Up @@ -76,6 +77,11 @@ public Q_SLOTS:
void aboutToHide() const;

private Q_SLOTS:
/**
* Initializes the style for the widget.
*/
void initStyle();

#ifdef OCR_SUPPORT
/**
* Initializes menus with regards to OCR Settings.
Expand Down Expand Up @@ -231,6 +237,9 @@ private Q_SLOTS:

/* A saved pointer to the player */
PlayerAdapter *m_player;

/* The menu style object. QWidget does not take ownership. */
std::unique_ptr<MenuStyle> m_menuStyle;
};

#endif // PLAYERMENU_H

0 comments on commit 05d1ef5

Please sign in to comment.