From 0970dd8054daa3aee4db5ad3a95961a0da9ecb77 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 30 Mar 2025 14:48:37 +0200 Subject: [PATCH] Issue #257: Force light mode (or dark mode) --- Pdf4QtEditor/main.cpp | 27 +++- Pdf4QtLibGui/pdfviewersettings.cpp | 37 ++++- Pdf4QtLibGui/pdfviewersettings.h | 20 ++- Pdf4QtLibGui/pdfviewersettingsdialog.cpp | 14 +- Pdf4QtLibGui/pdfviewersettingsdialog.h | 2 +- Pdf4QtLibGui/pdfviewersettingsdialog.ui | 176 ++++++++++++----------- Pdf4QtViewer/main.cpp | 26 +++- RELEASES.txt | 1 + 8 files changed, 211 insertions(+), 92 deletions(-) diff --git a/Pdf4QtEditor/main.cpp b/Pdf4QtEditor/main.cpp index de64cba..c829257 100644 --- a/Pdf4QtEditor/main.cpp +++ b/Pdf4QtEditor/main.cpp @@ -19,7 +19,9 @@ #include "pdfconstants.h" #include "pdfsecurityhandler.h" #include "pdfwidgetutils.h" +#include "pdfviewersettings.h" +#include #include #include @@ -58,7 +60,30 @@ int main(int argc, char *argv[]) pdf::PDFSecurityHandler::setNoDRMMode(); } - pdf::PDFWidgetUtils::setDarkTheme(parser.isSet(lightGui), parser.isSet(darkGui)); + bool isLightGui = false; + bool isDarkGui = false; + const pdfviewer::PDFViewerSettings::ColorScheme colorScheme = pdfviewer::PDFViewerSettings::getColorSchemeStatic(); + switch (colorScheme) + { + case pdfviewer::PDFViewerSettings::AutoScheme: + isLightGui = parser.isSet(lightGui); + isDarkGui = parser.isSet(darkGui); + break; + + case pdfviewer::PDFViewerSettings::LightScheme: + isLightGui = true; + break; + + case pdfviewer::PDFViewerSettings::DarkScheme: + isDarkGui = true; + break; + + default: + Q_ASSERT(false); + break; + } + + pdf::PDFWidgetUtils::setDarkTheme(isLightGui, isDarkGui); QIcon appIcon(":/app-icon.svg"); QApplication::setWindowIcon(appIcon); diff --git a/Pdf4QtLibGui/pdfviewersettings.cpp b/Pdf4QtLibGui/pdfviewersettings.cpp index a4ad72f..cea2be8 100644 --- a/Pdf4QtLibGui/pdfviewersettings.cpp +++ b/Pdf4QtLibGui/pdfviewersettings.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2022 Jakub Melka +// Copyright (C) 2019-2025 Jakub Melka // // This file is part of PDF4QT. // @@ -108,6 +108,10 @@ void PDFViewerSettings::readSettings(QSettings& settings, const pdf::PDFCMSSetti m_settings.m_autoGenerateBookmarks = settings.value("autoGenerateBookmarks", defaultSettings.m_autoGenerateBookmarks).toBool(); settings.endGroup(); + settings.beginGroup("ColorScheme"); + m_settings.m_colorScheme = static_cast(settings.value("colorScheme", int(defaultSettings.m_colorScheme)).toInt()); + settings.endGroup(); + Q_EMIT settingsChanged(); } @@ -180,6 +184,10 @@ void PDFViewerSettings::writeSettings(QSettings& settings) settings.beginGroup("Bookmarks"); settings.setValue("autoGenerateBookmarks", m_settings.m_autoGenerateBookmarks); settings.endGroup(); + + settings.beginGroup("ColorScheme"); + settings.setValue("colorScheme", int(m_settings.m_colorScheme)); + settings.endGroup(); } QString PDFViewerSettings::getDirectory() const @@ -251,6 +259,30 @@ void PDFViewerSettings::setColorTolerance(pdf::PDFReal colorTolerance) } } +void PDFViewerSettings::setColorScheme(ColorScheme colorScheme) +{ + if (m_settings.m_colorScheme != colorScheme) + { + m_settings.m_colorScheme = colorScheme; + Q_EMIT settingsChanged(); + } +} + +PDFViewerSettings::ColorScheme PDFViewerSettings::getColorSchemeStatic() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); + settings.beginGroup("ColorScheme"); + const ColorScheme colorScheme = static_cast(settings.value("colorScheme", int(AutoScheme)).toInt()); + settings.endGroup(); + + return colorScheme; +} + +PDFViewerSettings::ColorScheme PDFViewerSettings::getColorScheme() const +{ + return m_settings.m_colorScheme; +} + PDFViewerSettings::Settings::Settings() : m_features(pdf::PDFRenderer::getDefaultFeatures()), m_rendererEngine(pdf::RendererEngine::Blend2D_MultiThread), @@ -278,7 +310,8 @@ PDFViewerSettings::Settings::Settings() : m_signatureTreatWarningsAsErrors(false), m_signatureIgnoreCertificateValidityTime(false), m_signatureUseSystemStore(true), - m_autoGenerateBookmarks(true) + m_autoGenerateBookmarks(true), + m_colorScheme(AutoScheme) { } diff --git a/Pdf4QtLibGui/pdfviewersettings.h b/Pdf4QtLibGui/pdfviewersettings.h index 443b03e..a2cea34 100644 --- a/Pdf4QtLibGui/pdfviewersettings.h +++ b/Pdf4QtLibGui/pdfviewersettings.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Jakub Melka +// Copyright (C) 2019-2025 Jakub Melka // // This file is part of PDF4QT. // @@ -18,6 +18,7 @@ #ifndef PDFVIEWERSETTINGS_H #define PDFVIEWERSETTINGS_H +#include "pdfviewerglobal.h" #include "pdfglobal.h" #include "pdfrenderer.h" #include "pdfcms.h" @@ -31,7 +32,7 @@ class QSettings; namespace pdfviewer { -class PDFViewerSettings : public QObject +class PDF4QTLIBGUILIBSHARED_EXPORT PDFViewerSettings : public QObject { Q_OBJECT @@ -42,6 +43,13 @@ public: } + enum ColorScheme + { + AutoScheme, + LightScheme, + DarkScheme + }; + struct Settings { Settings(); @@ -94,6 +102,9 @@ public: // Bookmarks settings bool m_autoGenerateBookmarks; + + // UI Dark/Light mode settings + ColorScheme m_colorScheme; }; const Settings& getSettings() const { return m_settings; } @@ -132,6 +143,11 @@ public: pdf::PDFExecutionPolicy::Strategy getMultithreadingStrategy() const { return m_settings.m_multithreadingStrategy; } + ColorScheme getColorScheme() const; + void setColorScheme(ColorScheme colorScheme); + + static ColorScheme getColorSchemeStatic(); + signals: void settingsChanged(); diff --git a/Pdf4QtLibGui/pdfviewersettingsdialog.cpp b/Pdf4QtLibGui/pdfviewersettingsdialog.cpp index cc9eb4a..c21ee29 100644 --- a/Pdf4QtLibGui/pdfviewersettingsdialog.cpp +++ b/Pdf4QtLibGui/pdfviewersettingsdialog.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2022 Jakub Melka +// Copyright (C) 2019-2025 Jakub Melka // // This file is part of PDF4QT. // @@ -133,6 +133,11 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin ui->cmsColorAdaptationXYZComboBox->addItem(tr("CAT02 matrix"), int (pdf::PDFCMSSettings::ColorAdaptationXYZ::CAT02)); ui->cmsColorAdaptationXYZComboBox->addItem(tr("Bradford method"), int (pdf::PDFCMSSettings::ColorAdaptationXYZ::Bradford)); + // UI Color Schemes + ui->colorSchemeCombo->addItem(tr("Automatic (or via command line)"), static_cast(PDFViewerSettings::AutoScheme)); + ui->colorSchemeCombo->addItem(tr("Light scheme"), static_cast(PDFViewerSettings::LightScheme)); + ui->colorSchemeCombo->addItem(tr("Dark scheme"), static_cast(PDFViewerSettings::DarkScheme)); + auto fillColorProfileList = [](QComboBox* comboBox, const pdf::PDFColorProfileIdentifiers& identifiers) { for (const pdf::PDFColorProfileIdentifier& identifier : identifiers) @@ -305,6 +310,7 @@ void PDFViewerSettingsDialog::loadData() ui->maximumRedoStepsEdit->setValue(m_settings.m_maximumRedoSteps); ui->developerModeCheckBox->setChecked(m_settings.m_allowDeveloperMode); ui->logicalPixelZoomCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::LogicalSizeZooming)); + ui->colorSchemeCombo->setCurrentIndex(ui->colorSchemeCombo->findData(static_cast(m_settings.m_colorScheme))); // CMS ui->cmsTypeComboBox->setCurrentIndex(ui->cmsTypeComboBox->findData(int(m_cmsSettings.system))); @@ -396,7 +402,11 @@ void PDFViewerSettingsDialog::saveData() QObject* sender = this->sender(); - if (sender == ui->renderingEngineComboBox) + if (sender == ui->colorSchemeCombo) + { + m_settings.m_colorScheme = static_cast(ui->colorSchemeCombo->currentData().toInt()); + } + else if (sender == ui->renderingEngineComboBox) { m_settings.m_rendererEngine = static_cast(ui->renderingEngineComboBox->currentData().toInt()); } diff --git a/Pdf4QtLibGui/pdfviewersettingsdialog.h b/Pdf4QtLibGui/pdfviewersettingsdialog.h index 5a6eab1..11d25f2 100644 --- a/Pdf4QtLibGui/pdfviewersettingsdialog.h +++ b/Pdf4QtLibGui/pdfviewersettingsdialog.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Jakub Melka +// Copyright (C) 2019-2025 Jakub Melka // // This file is part of PDF4QT. // diff --git a/Pdf4QtLibGui/pdfviewersettingsdialog.ui b/Pdf4QtLibGui/pdfviewersettingsdialog.ui index 2dcf812..9393031 100644 --- a/Pdf4QtLibGui/pdfviewersettingsdialog.ui +++ b/Pdf4QtLibGui/pdfviewersettingsdialog.ui @@ -25,10 +25,10 @@ - QAbstractItemView::SelectRows + QAbstractItemView::SelectionBehavior::SelectRows - QListView::ListMode + QListView::ViewMode::ListMode @@ -308,7 +308,7 @@ li.checked::marker { content: "\2612"; } - QAbstractSpinBox::CorrectToNearestValue + QAbstractSpinBox::CorrectionMode::CorrectToNearestValue 3 @@ -327,7 +327,7 @@ li.checked::marker { content: "\2612"; } - QAbstractSpinBox::CorrectToNearestValue + QAbstractSpinBox::CorrectionMode::CorrectToNearestValue 3 @@ -346,7 +346,7 @@ li.checked::marker { content: "\2612"; } - QAbstractSpinBox::CorrectToNearestValue + QAbstractSpinBox::CorrectionMode::CorrectToNearestValue 3 @@ -425,7 +425,7 @@ li.checked::marker { content: "\2612"; } - QAbstractSpinBox::PlusMinus + QAbstractSpinBox::ButtonSymbols::PlusMinus 4 @@ -438,7 +438,7 @@ li.checked::marker { content: "\2612"; } - QAbstractSpinBox::PlusMinus + QAbstractSpinBox::ButtonSymbols::PlusMinus kB @@ -540,7 +540,7 @@ li.checked::marker { content: "\2612"; } - QAbstractItemView::AllEditTriggers + QAbstractItemView::EditTrigger::AllEditTriggers @@ -928,76 +928,45 @@ li.checked::marker { content: "\2612"; } - - - - Maximum count of recent files - - - - - - - Magnifier size - - - - + - - - - 20 - - - - - - - Maximum undo steps - - - - - - - 20 - - - - - - - 1.000000000000000 - - - 10.000000000000000 - - - - - - - Maximum redo steps - - - - + Enable - - + + - Developer mode + Maximum redo steps - + + + + Magnifier size + + + + + + + Use logical pixels when zooming + + + + + + + Enable + + + + px @@ -1010,7 +979,31 @@ li.checked::marker { content: "\2612"; } - + + + + 1.000000000000000 + + + 10.000000000000000 + + + + + + + 20 + + + + + + + Maximum undo steps + + + + Magnifier zoom @@ -1018,16 +1011,33 @@ li.checked::marker { content: "\2612"; } - - - Enable + + + 20 - - + + - Use logical pixels when zooming + Maximum count of recent files + + + + + + + Developer mode + + + + + + + + + + Color Scheme (GUI) @@ -1329,7 +1339,7 @@ li.checked::marker { content: "\2612"; } - Qt::Horizontal + Qt::Orientation::Horizontal @@ -1343,7 +1353,7 @@ li.checked::marker { content: "\2612"; } - QAbstractItemView::SelectRows + QAbstractItemView::SelectionBehavior::SelectRows @@ -1352,7 +1362,7 @@ li.checked::marker { content: "\2612"; } - Qt::Horizontal + Qt::Orientation::Horizontal @@ -1374,7 +1384,7 @@ li.checked::marker { content: "\2612"; } - Qt::Horizontal + Qt::Orientation::Horizontal @@ -1416,24 +1426,24 @@ li.checked::marker { content: "\2612"; } - QAbstractItemView::SingleSelection + QAbstractItemView::SelectionMode::SingleSelection - QAbstractItemView::SelectRows + QAbstractItemView::SelectionBehavior::SelectRows - Qt::Horizontal + Qt::Orientation::Horizontal - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop true @@ -1452,10 +1462,10 @@ li.checked::marker { content: "\2612"; } - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok diff --git a/Pdf4QtViewer/main.cpp b/Pdf4QtViewer/main.cpp index e76d87b..3381058 100644 --- a/Pdf4QtViewer/main.cpp +++ b/Pdf4QtViewer/main.cpp @@ -19,6 +19,7 @@ #include "pdfconstants.h" #include "pdfsecurityhandler.h" #include "pdfwidgetutils.h" +#include "pdfviewersettings.h" #include #include @@ -52,7 +53,30 @@ int main(int argc, char *argv[]) pdf::PDFSecurityHandler::setNoDRMMode(); } - pdf::PDFWidgetUtils::setDarkTheme(parser.isSet(lightGui), parser.isSet(darkGui)); + bool isLightGui = false; + bool isDarkGui = false; + const pdfviewer::PDFViewerSettings::ColorScheme colorScheme = pdfviewer::PDFViewerSettings::getColorSchemeStatic(); + switch (colorScheme) + { + case pdfviewer::PDFViewerSettings::AutoScheme: + isLightGui = parser.isSet(lightGui); + isDarkGui = parser.isSet(darkGui); + break; + + case pdfviewer::PDFViewerSettings::LightScheme: + isLightGui = true; + break; + + case pdfviewer::PDFViewerSettings::DarkScheme: + isDarkGui = true; + break; + + default: + Q_ASSERT(false); + break; + } + + pdf::PDFWidgetUtils::setDarkTheme(isLightGui, isDarkGui); QIcon appIcon(":/app-icon.svg"); QApplication::setWindowIcon(appIcon); diff --git a/RELEASES.txt b/RELEASES.txt index ed7cb1e..b89e210 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,4 +1,5 @@ CURRENT: + - Issue #257: Force light mode (or dark mode) - Issue #255: PDF4QT Page Master invert selection does not work - Issue #254: Unit Settings default window size too small - Issue #248: update version and year in Help > About page