Skip to content

Commit 6b74d83

Browse files
committed
Use Qt 6.5 styleHint colorScheme to detect dark theme
- keep linux compatibility WE2-826 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent b219e14 commit 6b74d83

6 files changed

+14
-26
lines changed

src/controller/application.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <QPalette>
3434
#include <QProcess>
3535
#include <QSettings>
36+
#include <QStyleHints>
3637
#include <QTranslator>
3738

3839
inline CommandWithArguments::second_type parseArgumentJson(const QString& argumentStr)
@@ -74,19 +75,17 @@ Application::Application(int& argc, char** argv, const QString& name) :
7475
#endif
7576
}
7677

77-
#ifndef Q_OS_MAC
7878
bool Application::isDarkTheme()
7979
{
80-
#ifdef Q_OS_WIN
81-
QSettings settings(
82-
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
83-
QSettings::NativeFormat);
84-
return settings.value("AppsUseLightTheme", 1).toInt() == 0;
85-
#else
86-
// There is currently no straightforward way to detect dark mode in Linux, but this works for supported OS-s.
80+
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
81+
return styleHints()->colorScheme() == Qt::ColorScheme::Dark;
82+
#elif defined(Q_OS_UNIX)
83+
// There is currently no straightforward way to detect dark mode in Linux, but this works for
84+
// supported OS-s.
8785
static const bool isDarkTheme = [] {
8886
QProcess p;
89-
p.start(QStringLiteral("gsettings"), {"get", "org.gnome.desktop.interface", "color-scheme"});
87+
p.start(QStringLiteral("gsettings"),
88+
{"get", "org.gnome.desktop.interface", "color-scheme"});
9089
if (p.waitForFinished()) {
9190
return p.readAllStandardOutput().contains("dark");
9291
}
@@ -97,7 +96,6 @@ bool Application::isDarkTheme()
9796
return isDarkTheme;
9897
#endif
9998
}
100-
#endif
10199

102100
void Application::loadTranslations(const QString& lang)
103101
{

src/controller/application.mm

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
#import <AppKit/AppKit.h>
2828
#import <Cocoa/Cocoa.h>
2929

30-
bool Application::isDarkTheme()
31-
{
32-
auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
33-
@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
34-
return [appearance isEqualToString:NSAppearanceNameDarkAqua];
35-
}
36-
3730
void Application::showAbout()
3831
{
3932
NSLog(@"web-eid-app: starting app");

src/controller/threads/commandhandlerconfirmthread.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class CommandHandlerConfirmThread : public ControllerChildThread
3131
public:
3232
CommandHandlerConfirmThread(QObject* parent, CommandHandler& handler, WebEidUI* w,
3333
const CardCertificateAndPinInfo& cardCertAndPin) :
34-
ControllerChildThread(parent),
35-
commandHandler(handler), cmdType(commandHandler.commandType()), window(w),
36-
cardCertAndPinInfo(cardCertAndPin)
34+
ControllerChildThread(parent), commandHandler(handler),
35+
cmdType(commandHandler.commandType()), window(w), cardCertAndPinInfo(cardCertAndPin)
3736
{
3837
}
3938

src/controller/threads/commandhandlerrunthread.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class CommandHandlerRunThread : public ControllerChildThread
3131
public:
3232
CommandHandlerRunThread(QObject* parent, CommandHandler& handler,
3333
const std::vector<electronic_id::CardInfo::ptr>& cs) :
34-
ControllerChildThread(parent),
35-
commandHandler(handler), cmdType(commandHandler.commandType()), cards(cs)
34+
ControllerChildThread(parent), commandHandler(handler),
35+
cmdType(commandHandler.commandType()), cards(cs)
3636
{
3737
// Connect retry signal to retry signal to pass it up from the command handler.
3838
connect(&commandHandler, &CommandHandler::retry, this, &ControllerChildThread::retry);

src/ui/certificatewidget.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ void CertificateWidget::paintEvent(QPaintEvent* /*event*/)
142142

143143
CertificateButton::CertificateButton(const CardCertificateAndPinInfo& cardCertPinInfo,
144144
QWidget* parent) :
145-
QAbstractButton(parent),
146-
CertificateWidgetInfo(this)
145+
QAbstractButton(parent), CertificateWidgetInfo(this)
147146
{
148147
setCheckable(true);
149148
setAutoExclusive(true);

src/ui/webeiddialog.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,7 @@ void WebEidDialog::setupOK(Func&& func, const std::function<QString()>& text, bo
653653
connect(ui->okButton, &QPushButton::clicked, this, std::forward<Func>(func));
654654
ui->okButton->show();
655655
ui->okButton->setEnabled(enabled);
656-
setTrText(
657-
ui->okButton, text ? text : [] { return tr("Confirm"); });
656+
setTrText(ui->okButton, text ? text : [] { return tr("Confirm"); });
658657
ui->cancelButton->show();
659658
ui->cancelButton->setEnabled(true);
660659
ui->helpButton->hide();

0 commit comments

Comments
 (0)