This commit is contained in:
Golubev Alexander
2024-12-08 15:20:39 +01:00
committed by GitHub
4 changed files with 16 additions and 0 deletions

View File

@ -40,14 +40,18 @@ int main(int argc, char *argv[])
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Editor")); QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Editor"));
QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents."); QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents.");
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI."); QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI.");
QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI."); QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI.");
#endif
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName()); parser.setApplicationDescription(QCoreApplication::applicationName());
parser.addOption(noDrm); parser.addOption(noDrm);
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
parser.addOption(lightGui); parser.addOption(lightGui);
parser.addOption(darkGui); parser.addOption(darkGui);
#endif
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addPositionalArgument("file", "The PDF file to open."); parser.addPositionalArgument("file", "The PDF file to open.");
@ -58,6 +62,7 @@ int main(int argc, char *argv[])
pdf::PDFSecurityHandler::setNoDRMMode(); pdf::PDFSecurityHandler::setNoDRMMode();
} }
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
if (parser.isSet(lightGui)) if (parser.isSet(lightGui))
{ {
pdf::PDFWidgetUtils::setDarkTheme(false); pdf::PDFWidgetUtils::setDarkTheme(false);
@ -67,6 +72,7 @@ int main(int argc, char *argv[])
{ {
pdf::PDFWidgetUtils::setDarkTheme(true); pdf::PDFWidgetUtils::setDarkTheme(true);
} }
#endif
QIcon appIcon(":/app-icon.svg"); QIcon appIcon(":/app-icon.svg");
QApplication::setWindowIcon(appIcon); QApplication::setWindowIcon(appIcon);

View File

@ -174,10 +174,12 @@ void PDFWidgetUtils::style(QWidget* widget)
} }
} }
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
void PDFWidgetUtils::setDarkTheme(bool isDarkTheme) void PDFWidgetUtils::setDarkTheme(bool isDarkTheme)
{ {
QApplication::styleHints()->setColorScheme(isDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light); QApplication::styleHints()->setColorScheme(isDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light);
} }
#endif
bool PDFWidgetUtils::isDarkTheme() bool PDFWidgetUtils::isDarkTheme()
{ {

View File

@ -60,8 +60,10 @@ public:
/// Apply style to the widget /// Apply style to the widget
static void style(QWidget* widget); static void style(QWidget* widget);
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
/// Overrides automatically detected dark theme / light theme settings /// Overrides automatically detected dark theme / light theme settings
static void setDarkTheme(bool isDarkTheme); static void setDarkTheme(bool isDarkTheme);
#endif
/// Returns true if the dark theme is currently set for the application. /// Returns true if the dark theme is currently set for the application.
static bool isDarkTheme(); static bool isDarkTheme();

View File

@ -34,14 +34,18 @@ int main(int argc, char *argv[])
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Viewer")); QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Viewer"));
QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents."); QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents.");
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI."); QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI.");
QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI."); QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI.");
#endif
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName()); parser.setApplicationDescription(QCoreApplication::applicationName());
parser.addOption(noDrm); parser.addOption(noDrm);
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
parser.addOption(lightGui); parser.addOption(lightGui);
parser.addOption(darkGui); parser.addOption(darkGui);
#endif
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addPositionalArgument("file", "The PDF file to open."); parser.addPositionalArgument("file", "The PDF file to open.");
@ -52,6 +56,7 @@ int main(int argc, char *argv[])
pdf::PDFSecurityHandler::setNoDRMMode(); pdf::PDFSecurityHandler::setNoDRMMode();
} }
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
if (parser.isSet(lightGui)) if (parser.isSet(lightGui))
{ {
pdf::PDFWidgetUtils::setDarkTheme(false); pdf::PDFWidgetUtils::setDarkTheme(false);
@ -61,6 +66,7 @@ int main(int argc, char *argv[])
{ {
pdf::PDFWidgetUtils::setDarkTheme(true); pdf::PDFWidgetUtils::setDarkTheme(true);
} }
#endif
QIcon appIcon(":/app-icon.svg"); QIcon appIcon(":/app-icon.svg");
QApplication::setWindowIcon(appIcon); QApplication::setWindowIcon(appIcon);