Qt Utilities 6.18.1
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
qtsettings.cpp
Go to the documentation of this file.
1#include "./qtsettings.h"
2
5
6#if defined(QT_UTILITIES_GUI_QTWIDGETS)
7#include "./optioncategory.h"
10#include "./optionpage.h"
11
14#endif
15
16#include "resources/config.h"
17
18#if defined(QT_UTILITIES_GUI_QTWIDGETS)
19#include "ui_qtappearanceoptionpage.h"
20#include "ui_qtenvoptionpage.h"
21#include "ui_qtlanguageoptionpage.h"
22#endif
23
24#include <c++utilities/application/commandlineutils.h>
25
26#include <QDir>
27#include <QFont>
28#include <QGuiApplication>
29#include <QIcon>
30#include <QLocale>
31#include <QOperatingSystemVersion>
32#include <QPalette>
33#include <QSettings>
34#include <QStringBuilder>
35#include <QVersionNumber>
36
37#if defined(QT_UTILITIES_GUI_QTWIDGETS)
38#include <QFileDialog>
39#include <QFontDialog>
40#include <QStyleFactory>
41#endif
42
43#if defined(Q_OS_WINDOWS) && (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 7, 0))
44#include <QOperatingSystemVersion>
45#define QT_UTILITIES_USE_FUSION_ON_WINDOWS_11
46#endif
47
48#include <iostream>
49#include <memory>
50#include <optional>
51
52namespace QtUtilities {
53
56
57 QFont font;
58 std::optional<QFont> initialFont;
59 QPalette palette; // the currently applied palette (only in use if customPalette is true, though)
60 QPalette selectedPalette; // the intermediately selected palette (chosen in palette editor but not yet applied)
61#if defined(QT_UTILITIES_GUI_QTWIDGETS)
62 QString widgetStyle;
63 QString initialWidgetStyle;
64 QString styleSheetPath;
65#endif
66 QString iconTheme;
70 QString localeName;
77#if defined(QT_UTILITIES_GUI_QTWIDGETS)
78 bool customWidgetStyle;
79 bool customStyleSheet;
80#endif
84#if defined(QT_UTILITIES_GUI_QTWIDGETS)
85 bool showNotices;
86 bool retranslatable;
87#endif
88};
89
91 : iconTheme(QIcon::themeName())
94 , customFont(false)
95 , customPalette(false)
96#if defined(QT_UTILITIES_GUI_QTWIDGETS)
97 , customWidgetStyle(false)
98 , customStyleSheet(false)
99#endif
100 , customIconTheme(false)
101 , customLocale(false)
102 , isPaletteDark(false)
103#if defined(QT_UTILITIES_GUI_QTWIDGETS)
104 , showNotices(true)
105 , retranslatable(false)
106#endif
107{
108}
109
118 : m_d(std::make_unique<QtSettingsData>())
119{
120}
121
130
131#if defined(QT_UTILITIES_GUI_QTWIDGETS)
143void QtSettings::disableNotices()
144{
145 m_d->showNotices = false;
146}
147
156void QtSettings::setRetranslatable(bool retranslatable)
157{
158 m_d->retranslatable = retranslatable;
159}
160#endif
161
166{
167 return m_d->customFont;
168}
169
176void QtSettings::restore(QSettings &settings)
177{
178 settings.beginGroup(QStringLiteral("qt"));
179 m_d->font.fromString(settings.value(QStringLiteral("font")).toString());
180 m_d->customFont = settings.value(QStringLiteral("customfont"), false).toBool();
181 m_d->palette = settings.value(QStringLiteral("palette")).value<QPalette>();
182 m_d->customPalette = settings.value(QStringLiteral("custompalette"), false).toBool();
183#if defined(QT_UTILITIES_GUI_QTWIDGETS)
184 m_d->widgetStyle = settings.value(QStringLiteral("widgetstyle"), m_d->widgetStyle).toString();
185 m_d->customWidgetStyle = settings.value(QStringLiteral("customwidgetstyle"), false).toBool();
186 m_d->styleSheetPath = settings.value(QStringLiteral("stylesheetpath"), m_d->styleSheetPath).toString();
187 m_d->customStyleSheet = settings.value(QStringLiteral("customstylesheet"), false).toBool();
188#endif
189 m_d->iconTheme = settings.value(QStringLiteral("icontheme"), m_d->iconTheme).toString();
190 m_d->customIconTheme = settings.value(QStringLiteral("customicontheme"), false).toBool();
191 m_d->localeName = settings.value(QStringLiteral("locale"), m_d->localeName).toString();
192 m_d->customLocale = settings.value(QStringLiteral("customlocale"), false).toBool();
193 m_d->additionalPluginDirectory = settings.value(QStringLiteral("plugindir")).toString();
194 m_d->additionalIconThemeSearchPath = settings.value(QStringLiteral("iconthemepath")).toString();
195 TranslationFiles::additionalTranslationFilePath() = settings.value(QStringLiteral("trpath")).toString();
196 settings.endGroup();
197 if (qEnvironmentVariableIntValue("QT_DEBUG_SETTINGS")) {
198 std::cerr << "Restored Qt settings values\n";
199 }
200}
201
205void QtSettings::save(QSettings &settings) const
206{
207 settings.beginGroup(QStringLiteral("qt"));
208 settings.setValue(QStringLiteral("font"), QVariant(m_d->font.toString()));
209 settings.setValue(QStringLiteral("customfont"), m_d->customFont);
210 settings.setValue(QStringLiteral("palette"), QVariant(m_d->palette));
211 settings.setValue(QStringLiteral("custompalette"), m_d->customPalette);
212#if defined(QT_UTILITIES_GUI_QTWIDGETS)
213 settings.setValue(QStringLiteral("widgetstyle"), m_d->widgetStyle);
214 settings.setValue(QStringLiteral("customwidgetstyle"), m_d->customWidgetStyle);
215 settings.setValue(QStringLiteral("stylesheetpath"), m_d->styleSheetPath);
216 settings.setValue(QStringLiteral("customstylesheet"), m_d->customStyleSheet);
217#endif
218 settings.setValue(QStringLiteral("icontheme"), m_d->iconTheme);
219 settings.setValue(QStringLiteral("customicontheme"), m_d->customIconTheme);
220 settings.setValue(QStringLiteral("locale"), m_d->localeName);
221 settings.setValue(QStringLiteral("customlocale"), m_d->customLocale);
222 settings.setValue(QStringLiteral("plugindir"), m_d->additionalPluginDirectory);
223 settings.setValue(QStringLiteral("iconthemepath"), m_d->additionalIconThemeSearchPath);
224 settings.setValue(QStringLiteral("trpath"), QVariant(TranslationFiles::additionalTranslationFilePath()));
225 settings.endGroup();
226 if (qEnvironmentVariableIntValue("QT_DEBUG_SETTINGS")) {
227 std::cerr << "Set Qt settings values\n";
228 }
229}
230
236static QMap<QString, QString> scanIconThemes(const QStringList &searchPaths)
237{
238 auto res = QMap<QString, QString>();
239 for (const auto &searchPath : searchPaths) {
240 const auto dir = QDir(searchPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
241 for (const auto &iconTheme : dir) {
242 auto indexFile = QFile(searchPath % QChar('/') % iconTheme % QStringLiteral("/index.theme"));
243 auto index = QByteArray();
244 if (indexFile.open(QFile::ReadOnly) && !(index = indexFile.readAll()).isEmpty()) {
245 const auto iconThemeSection = index.indexOf("[Icon Theme]");
246 const auto nameStart = index.indexOf("Name=", iconThemeSection != -1 ? iconThemeSection : 0);
247 if (nameStart != -1) {
248 auto nameLength = index.indexOf("\n", nameStart) - nameStart - 5;
249 if (nameLength > 0) {
250 auto displayName = QString::fromUtf8(index.mid(nameStart + 5, nameLength));
251 if (displayName != iconTheme) {
252 displayName += QChar(' ') % QChar('(') % iconTheme % QChar(')');
253 }
254 res[displayName] = iconTheme;
255 continue;
256 }
257 }
258 }
259 res[iconTheme] = iconTheme;
260 }
261 }
262 return res;
263}
264
277{
278 // apply environment
279 if (m_d->additionalPluginDirectory != m_d->previousPluginDirectory) {
280 if (!m_d->previousPluginDirectory.isEmpty()) {
281 QCoreApplication::removeLibraryPath(m_d->previousPluginDirectory);
282 }
283 if (!m_d->additionalPluginDirectory.isEmpty()) {
284 QCoreApplication::addLibraryPath(m_d->additionalPluginDirectory);
285 }
286 m_d->previousPluginDirectory = m_d->additionalPluginDirectory;
287 }
288 if (m_d->additionalIconThemeSearchPath != m_d->previousIconThemeSearchPath) {
289 auto paths = QIcon::themeSearchPaths();
290 if (!m_d->previousIconThemeSearchPath.isEmpty()) {
291 paths.removeAll(m_d->previousIconThemeSearchPath);
292 }
293 if (!m_d->additionalIconThemeSearchPath.isEmpty()) {
294 paths.append(m_d->additionalIconThemeSearchPath);
295 }
296 m_d->previousIconThemeSearchPath = m_d->additionalIconThemeSearchPath;
297 QIcon::setThemeSearchPaths(paths);
298 }
299
300#if defined(QT_UTILITIES_GUI_QTWIDGETS)
301 // read style sheet
302 auto styleSheet = QString();
303 if (m_d->customStyleSheet && !m_d->styleSheetPath.isEmpty()) {
304 auto file = QFile(m_d->styleSheetPath);
305 if (!file.open(QFile::ReadOnly)) {
306 std::cerr << "Unable to open the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data() << "\"." << std::endl;
307 }
308 styleSheet.append(file.readAll());
309 if (file.error() != QFile::NoError) {
310 std::cerr << "Unable to read the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data() << "\"." << std::endl;
311 }
312 }
313#endif
314
315 // apply appearance
316 if (m_d->customFont) {
317 if (!m_d->initialFont.has_value()) {
318 m_d->initialFont = QGuiApplication::font();
319 }
320 QGuiApplication::setFont(m_d->font);
321 } else if (m_d->initialFont.has_value()) {
322 QGuiApplication::setFont(m_d->initialFont.value());
323 }
324#if defined(QT_UTILITIES_GUI_QTWIDGETS)
325#ifdef QT_UTILITIES_USE_FUSION_ON_WINDOWS_11
326 if (m_d->initialWidgetStyle.isEmpty()) {
327 // use Fusion on Windows 11 as the native style doesn't look good
328 // see https://bugreports.qt.io/browse/QTBUG-97668
329 if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11) {
330 m_d->initialWidgetStyle = QStringLiteral("Fusion");
331 }
332 }
333#endif
334 if (m_d->customWidgetStyle) {
335#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
336 const auto *const currentStyle = QApplication::style();
337 if (m_d->initialWidgetStyle.isEmpty() && currentStyle) {
338 m_d->initialWidgetStyle = currentStyle->name();
339 }
340#endif
341 QApplication::setStyle(m_d->widgetStyle);
342 } else if (!m_d->initialWidgetStyle.isEmpty()) {
343 QApplication::setStyle(m_d->initialWidgetStyle);
344 }
345 if (auto *const qapp = qobject_cast<QApplication *>(QApplication::instance())) {
346 qapp->setStyleSheet(styleSheet);
347 } else {
348 std::cerr << "Unable to apply the specified stylesheet \"" << m_d->styleSheetPath.toLocal8Bit().data()
349 << "\" because no QApplication has been instantiated." << std::endl;
350 }
351#endif
352 if (m_d->customPalette) {
353 QGuiApplication::setPalette(m_d->palette);
354 } else {
355 QGuiApplication::setPalette(QPalette());
356 }
357 m_d->isPaletteDark = QtUtilities::isPaletteDark();
358 if (m_d->customIconTheme) {
359 QIcon::setThemeName(m_d->iconTheme);
360 } else if (!m_d->initialIconTheme.isEmpty()) {
361 if (m_d->iconTheme != m_d->initialIconTheme) {
362 // set the icon theme back to what it was before changing anything (not sure how to read the current system icon theme again)
363 QIcon::setThemeName(m_d->initialIconTheme);
364 }
365 } else {
366 // use bundled default icon theme matching the current palette
367 // notes: - It is ok that search paths specified via CLI arguments are not set here yet. When doing so one should also
368 // specify the desired icon theme explicitly.
369 // - The icon themes "default" and "default-dark" come from QtConfig.cmake which makes the first non-dark bundled
370 // icon theme available as "default" and the first dark icon theme available as "default-dark". An icon theme
371 // is considered dark if it ends with "-dark".
372 const auto bundledIconThemes = scanIconThemes(QStringList(QStringLiteral(":/icons")));
373 if (m_d->isPaletteDark && bundledIconThemes.contains(QStringLiteral("default-dark"))) {
374 QIcon::setThemeName(QStringLiteral("default-dark"));
375 } else if (bundledIconThemes.contains(QStringLiteral("default"))) {
376 QIcon::setThemeName(QStringLiteral("default"));
377 }
378 }
379
380 // apply locale
381 m_d->previousLocale = QLocale();
382 QLocale::setDefault(m_d->customLocale ? QLocale(m_d->localeName) : m_d->defaultLocale);
383
384 // log some debug information on the first call if env variable set
385 static auto debugInfoLogged = false;
386 if (debugInfoLogged) {
387 return;
388 }
389 const auto debugLoggingEnabled = CppUtilities::isEnvVariableSet(PROJECT_VARNAME_UPPER "_LOG_QT_CONFIG");
390 if (debugLoggingEnabled.has_value() && debugLoggingEnabled.value()) {
391 if (const auto os = QOperatingSystemVersion::current(); os.type() != static_cast<decltype(os.type())>(QOperatingSystemVersion::Unknown)) {
392 const auto version = QVersionNumber(os.majorVersion(), os.minorVersion(), os.microVersion());
393 std::cerr << "OS name and version: " << os.name().toStdString() << ' ' << version.toString().toStdString() << '\n';
394 }
395 std::cerr << "Qt version: " << qVersion() << '\n';
396 std::cerr << "Qt platform (set QT_QPA_PLATFORM to override): " << QGuiApplication::platformName().toStdString() << '\n';
397 std::cerr << "Qt locale: " << QLocale().name().toStdString() << '\n';
398 std::cerr << "Qt library paths: " << QCoreApplication::libraryPaths().join(':').toStdString() << '\n';
399 std::cerr << "Qt theme search paths: " << QIcon::themeSearchPaths().join(':').toStdString() << '\n';
400 std::cerr << "Darkmode enabled: " << (QtUtilities::isDarkModeEnabled() ? "yes" : "no") << '\n';
401 std::cerr << "Is Qt palette dark: " << (m_d->isPaletteDark ? "yes" : "no") << '\n';
402 debugInfoLogged = true;
403 }
404}
405
423{
424 if (isPaletteDark == m_d->isPaletteDark) {
425 return; // no need to do anything if there's no change
426 }
427 m_d->isPaletteDark = isPaletteDark;
428 if (auto iconTheme = QIcon::themeName(); iconTheme == QStringLiteral("default") || iconTheme == QStringLiteral("default-dark")) {
429 QIcon::setThemeName(m_d->isPaletteDark ? QStringLiteral("default-dark") : QStringLiteral("default"));
430 }
431}
432
447
455{
456 return m_d->isPaletteDark;
457}
458
463{
464 return m_d->previousLocale != QLocale();
465}
466
467#if defined(QT_UTILITIES_GUI_QTWIDGETS)
477{
478 auto *category = new OptionCategory;
479 category->setDisplayName(QCoreApplication::translate("QtGui::QtOptionCategory", "Qt"));
480 category->setIcon(QIcon::fromTheme(QStringLiteral("qtcreator"), QIcon(QStringLiteral(":/qtutilities/icons/hicolor/48x48/apps/qtcreator.svg"))));
481 category->assignPages({ new QtAppearanceOptionPage(*m_d), new QtLanguageOptionPage(*m_d), new QtEnvOptionPage(*m_d) });
482 return category;
483}
484
485QtAppearanceOptionPage::QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget)
486 : QtAppearanceOptionPageBase(parentWidget)
487 , m_settings(settings)
488 , m_fontDialog(nullptr)
489{
490}
491
492QtAppearanceOptionPage::~QtAppearanceOptionPage()
493{
494}
495
496bool QtAppearanceOptionPage::apply()
497{
498 m_settings.font = ui()->fontComboBox->currentFont();
499 m_settings.customFont = !ui()->fontCheckBox->isChecked();
500 m_settings.widgetStyle = ui()->widgetStyleComboBox->currentText();
501 m_settings.customWidgetStyle = !ui()->widgetStyleCheckBox->isChecked();
502 m_settings.styleSheetPath = ui()->styleSheetPathSelection->lineEdit()->text();
503 m_settings.customStyleSheet = !ui()->styleSheetCheckBox->isChecked();
504 m_settings.palette = m_settings.selectedPalette;
505 m_settings.customPalette = !ui()->paletteCheckBox->isChecked();
506 m_settings.iconTheme
507 = ui()->iconThemeComboBox->currentIndex() != -1 ? ui()->iconThemeComboBox->currentData().toString() : ui()->iconThemeComboBox->currentText();
508 m_settings.customIconTheme = !ui()->iconThemeCheckBox->isChecked();
509 return true;
510}
511
512void QtAppearanceOptionPage::reset()
513{
514 ui()->fontComboBox->setCurrentFont(m_settings.font);
515 ui()->fontCheckBox->setChecked(!m_settings.customFont);
516 ui()->widgetStyleComboBox->setCurrentText(
517 m_settings.widgetStyle.isEmpty() ? (QApplication::style() ? QApplication::style()->objectName() : QString()) : m_settings.widgetStyle);
518 ui()->widgetStyleCheckBox->setChecked(!m_settings.customWidgetStyle);
519 ui()->styleSheetPathSelection->lineEdit()->setText(m_settings.styleSheetPath);
520 ui()->styleSheetCheckBox->setChecked(!m_settings.customStyleSheet);
521 m_settings.selectedPalette = m_settings.palette;
522 ui()->paletteCheckBox->setChecked(!m_settings.customPalette);
523 int iconThemeIndex = ui()->iconThemeComboBox->findData(m_settings.iconTheme);
524 if (iconThemeIndex != -1) {
525 ui()->iconThemeComboBox->setCurrentIndex(iconThemeIndex);
526 } else {
527 ui()->iconThemeComboBox->setCurrentText(m_settings.iconTheme);
528 }
529 ui()->iconThemeCheckBox->setChecked(!m_settings.customIconTheme);
530}
531
532QWidget *QtAppearanceOptionPage::setupWidget()
533{
534 // call base implementation first, so ui() is available
535 auto *widget = QtAppearanceOptionPageBase::setupWidget();
536 if (!m_settings.showNotices) {
537 ui()->label->hide();
538 }
539
540 // setup widget style selection
541 ui()->widgetStyleComboBox->addItems(QStyleFactory::keys());
542
543 // setup style sheet selection
544 ui()->styleSheetPathSelection->provideCustomFileMode(QFileDialog::ExistingFile);
545
546 // setup font selection
547 QObject::connect(ui()->fontPushButton, &QPushButton::clicked, widget, [this] {
548 if (!m_fontDialog) {
549 m_fontDialog = new QFontDialog(this->widget());
550 m_fontDialog->setCurrentFont(ui()->fontComboBox->font());
551 QObject::connect(m_fontDialog, &QFontDialog::fontSelected, ui()->fontComboBox, &QFontComboBox::setCurrentFont);
552 QObject::connect(ui()->fontComboBox, &QFontComboBox::currentFontChanged, m_fontDialog, &QFontDialog::setCurrentFont);
553 }
554 m_fontDialog->show();
555 });
556
557 // setup palette selection
558 QObject::connect(ui()->paletteToolButton, &QToolButton::clicked, ui()->paletteToolButton,
559 [this] { m_settings.selectedPalette = PaletteEditor::getPalette(this->widget(), m_settings.selectedPalette); });
560
561 // setup icon theme selection
562 const auto iconThemes = scanIconThemes(QIcon::themeSearchPaths() << QStringLiteral("/usr/share/icons/"));
563 auto *iconThemeComboBox = ui()->iconThemeComboBox;
564 for (auto i = iconThemes.begin(), end = iconThemes.end(); i != end; ++i) {
565 const auto &displayName = i.key();
566 const auto &id = i.value();
567 if (const auto existingItemIndex = iconThemeComboBox->findData(id); existingItemIndex != -1) {
568 iconThemeComboBox->setItemText(existingItemIndex, displayName);
569 } else {
570 iconThemeComboBox->addItem(displayName, id);
571 }
572 }
573
574 return widget;
575}
576
577QtLanguageOptionPage::QtLanguageOptionPage(QtSettingsData &settings, QWidget *parentWidget)
578 : QtLanguageOptionPageBase(parentWidget)
579 , m_settings(settings)
580{
581}
582
583QtLanguageOptionPage::~QtLanguageOptionPage()
584{
585}
586
587bool QtLanguageOptionPage::apply()
588{
589 m_settings.localeName = ui()->localeComboBox->currentText();
590 m_settings.customLocale = !ui()->localeCheckBox->isChecked();
591 return true;
592}
593
594void QtLanguageOptionPage::reset()
595{
596 ui()->localeComboBox->setCurrentText(m_settings.localeName);
597 ui()->localeCheckBox->setChecked(!m_settings.customLocale);
598}
599
600QWidget *QtLanguageOptionPage::setupWidget()
601{
602 // call base implementation first, so ui() is available
603 auto *widget = QtLanguageOptionPageBase::setupWidget();
604 if (m_settings.retranslatable) {
605 ui()->label->hide();
606 }
607
608 // add all available locales to combo box
609 auto *localeComboBox = ui()->localeComboBox;
610 const auto locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
611 for (const QLocale &locale : locales) {
612 localeComboBox->addItem(locale.name());
613 }
614
615 auto *languageLabel = ui()->languageLabel;
616 QObject::connect(ui()->localeComboBox, &QComboBox::currentTextChanged, languageLabel, [languageLabel, localeComboBox] {
617 const auto selectedLocale = QLocale(localeComboBox->currentText());
618 const auto currentLocale = QLocale();
619 const auto territory =
620#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
621 currentLocale.territoryToString(selectedLocale.territory());
622#else
623 currentLocale.countryToString(selectedLocale.country());
624#endif
625 languageLabel->setText(QCoreApplication::translate("QtGui::QtLanguageOptionPage", "recognized by Qt as") % QStringLiteral(" <i>")
626 % currentLocale.languageToString(selectedLocale.language()) % QChar(',') % QChar(' ') % territory % QStringLiteral("</i>"));
627 });
628 return widget;
629}
630
631QtEnvOptionPage::QtEnvOptionPage(QtSettingsData &settings, QWidget *parentWidget)
632 : QtEnvOptionPageBase(parentWidget)
633 , m_settings(settings)
634{
635}
636
637QtEnvOptionPage::~QtEnvOptionPage()
638{
639}
640
641bool QtEnvOptionPage::apply()
642{
643 m_settings.additionalPluginDirectory = ui()->pluginPathSelection->lineEdit()->text();
644 m_settings.additionalIconThemeSearchPath = ui()->iconThemeSearchPathSelection->lineEdit()->text();
645 TranslationFiles::additionalTranslationFilePath() = ui()->translationPathSelection->lineEdit()->text();
646 return true;
647}
648
649void QtEnvOptionPage::reset()
650{
651 ui()->pluginPathSelection->lineEdit()->setText(m_settings.additionalPluginDirectory);
652 ui()->iconThemeSearchPathSelection->lineEdit()->setText(m_settings.additionalIconThemeSearchPath);
653 ui()->translationPathSelection->lineEdit()->setText(TranslationFiles::additionalTranslationFilePath());
654}
655
656QWidget *QtEnvOptionPage::setupWidget()
657{
658 // call base implementation first, so ui() is available
659 return QtEnvOptionPageBase::setupWidget();
660}
661#endif
662
669QtSettings::operator QtSettingsData &() const
670{
671 return *m_d.get();
672}
673
674} // namespace QtUtilities
675
676#if defined(QT_UTILITIES_GUI_QTWIDGETS)
677INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(QtAppearanceOptionPage)
678INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(QtLanguageOptionPage)
680#endif
The OptionCategory class wraps associated option pages.
void setDisplayName(const QString &displayName)
Sets the display name of the category.
void assignPages(const QList< OptionPage * > &pages)
Assigns the specified pages to the category.
void setIcon(const QIcon &icon)
Sets the icon of the category.
static QPalette getPalette(QWidget *parent, const QPalette &init=QPalette(), const QPalette &parentPal=QPalette(), int *result=nullptr)
void save(QSettings &settings) const
Saves the settings to the specified QSettings object.
OptionCategory * category()
QtSettings()
Creates a new settings object.
void reapplyDefaultIconTheme(bool isPaletteDark)
Re-applies default icon theme assuming the palette is dark or not depending on isPaletteDark.
~QtSettings()
Destroys the settings object.
void restore(QSettings &settings)
Restores the settings from the specified QSettings object.
bool hasLocaleChanged() const
Returns whether the last apply() call has changed the default locale.
bool isPaletteDark()
Returns whether the palette is dark.
bool hasCustomFont() const
Returns whether a custom font is set.
void apply()
Applies the current configuration.
void reevaluatePaletteAndDefaultIconTheme()
Re-evaluates whether the palette is dark and re-applies default icon theme.
QT_UTILITIES_EXPORT QString & additionalTranslationFilePath()
Allows to set an additional search path for translation files.
Definition resources.cpp:84
QT_UTILITIES_EXPORT std::optional< bool > isDarkModeEnabled()
Returns whether dark mode is enabled.
QT_UTILITIES_EXPORT bool isPaletteDark(const QPalette &palette=QPalette())
Returns whether palette is dark.
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(SomeClass)
Instantiates a class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE in a convenient way.
Definition optionpage.h:250
std::optional< QFont > initialFont