Skip to content

Commit

Permalink
Dark theme choice for Windows like Sigil
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed Jul 28, 2024
1 parent 487176d commit 8535217
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 41 deletions.
19 changes: 18 additions & 1 deletion AppearanceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ AppearanceWidget::AppearanceWidget()

ui.setupUi(this);

// Hide the Windows only preference from all other OSes
#ifndef Q_OS_WIN32
ui.grpCustomDarkStyle->setVisible(false);
#endif

// setup the HighDPI combo box here
ui.comboHighDPI->addItems({tr("Detect"), tr("On"), tr("Off")});
QString highdpi_tooltip = "<p><dt><b>" + tr("Detect") + "</b><dd>" + tr("Detect whether any high dpi scaling should take place.");
Expand All @@ -67,6 +72,8 @@ PreferencesWidget::ResultActions AppearanceWidget::saveSettings()
SettingsStore settings;
settings.setAppearancePrefsTabIndex(ui.tabAppearance->currentIndex());
settings.setPreviewDark(ui.PreviewDarkInDM->isChecked() ? 1 : 0);
// This setting has no effect on other OSes, but it won't hurt to set it.
settings.setUiUseCustomDarkTheme(ui.chkDarkStyle->isChecked() ? 1 : 0);
// Don't try to get the index of a disabled combobox
if (m_isHighDPIComboEnabled) {
settings.setHighDPI(ui.comboHighDPI->currentIndex());
Expand Down Expand Up @@ -111,6 +118,13 @@ PreferencesWidget::ResultActions AppearanceWidget::saveSettings()
if ((m_currentUIFont != m_initUIFont) || m_uiFontResetFlag) {
results = results | PreferencesWidget::ResultAction_RestartPageEdit;
}
// if dark style changed on Windows, set need for restart.
// This setting has no effect on other OSes so no need to prompt for a restart.
#ifdef Q_OS_WIN32
if (m_UseCustomDarkTheme != (ui.chkDarkStyle->isChecked() ? 1 : 0)) {
results = results | PreferencesWidget::ResultAction_RestartPageEdit;
}
#endif
m_uiFontResetFlag = false;
results = results & PreferencesWidget::ResultAction_Mask;
return results;
Expand All @@ -121,6 +135,10 @@ void AppearanceWidget::readSettings()
{
SettingsStore settings;
ui.tabAppearance->setCurrentIndex(settings.appearancePrefsTabIndex());
// This setting has no effect on other OSes, but it won't hurt to read it.
m_UseCustomDarkTheme = settings.uiUseCustomDarkTheme();
ui.chkDarkStyle->setChecked(settings.uiUseCustomDarkTheme());

SettingsStore::WebViewAppearance WVAppearance = settings.webViewAppearance();
SettingsStore::SpecialCharacterAppearance specialCharacterAppearance = settings.specialCharacterAppearance();
loadComboValueOrDefault(ui.cbWebViewFontStandard, WVAppearance.font_family_standard, "Arial");
Expand Down Expand Up @@ -154,7 +172,6 @@ void AppearanceWidget::readSettings()
}
}
ui.cboPrintDPI->setCurrentIndex(index);

}

void AppearanceWidget::updateUIFontDisplay()
Expand Down
2 changes: 2 additions & 0 deletions AppearanceWidget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/************************************************************************
**
** Copyright (C) 2019-2020 Kevin B. Hendricks, Stratford, Ontario Canada
** Copyright (C) 2016-2024 Doug Massay
** Copyright (C) 2012 John Schember <[email protected]>
** Copyright (C) 2012 Grant Drake
**
Expand Down Expand Up @@ -59,6 +60,7 @@ private slots:
QString m_currentUIFont;
bool m_isHighDPIComboEnabled;
bool m_uiFontResetFlag;
bool m_UseCustomDarkTheme;
};

#endif // APPEARANCEWIDGET_H
48 changes: 8 additions & 40 deletions MainApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <QDebug>

#include "MainApplication.h"
#include "SettingsStore.h"
#include "PEDarkStyle.h"

#define DBG if(0)

Expand Down Expand Up @@ -166,59 +168,25 @@ void MainApplication::systemColorChanged()

void MainApplication::windowsDarkThemeChange()
{
#if 0 // FIXME: Is any of this needed on PageEdit?
SettingsStore settings;
if (settings.uiUseCustomSigilDarkTheme()) {
if (settings.uiUseCustomDarkTheme()) {
QStyle* astyle = QStyleFactory::create("Fusion");
setStyle(astyle);
//Handle the new CaretStyle (double width cursor)
bool isbstyle = false;
QStyle* bstyle;
if (settings.uiDoubleWidthTextCursor()) {
bstyle = new CaretStyle(astyle);
setStyle(bstyle);
isbstyle = true;
}
//setStyle(astyle);
// modify windows sigil palette to our dark
QStyle* cstyle;
if (isbstyle) {
cstyle = new SigilDarkStyle(bstyle);
} else {
cstyle = new SigilDarkStyle(astyle);
}
setStyle(cstyle);
QStyle* bstyle;
bstyle = new PEDarkStyle(astyle);
setStyle(bstyle);
setPalette(style()->standardPalette());

// Add back stylesheet changes added after MainApplication started
if (!m_accumulatedQss.isEmpty()) {
setStyleSheet(styleSheet().append(m_accumulatedQss));
DBG qDebug() << styleSheet();
}
}
#endif
}

void MainApplication::windowsLightThemeChange()
{
#if 0 // FIXME: Is any of this needed on PageEdit?
SettingsStore settings;
if (settings.uiUseCustomSigilDarkTheme()) {
if (settings.uiUseCustomDarkTheme()) {
// Windows Fusion light mode
QStyle* astyle = QStyleFactory::create("Fusion");
setStyle(astyle);
// Handle the new CaretStyle (double width cursor)
if (settings.uiDoubleWidthTextCursor()) {
QStyle* bstyle = new CaretStyle(astyle);
setStyle(bstyle);
}
setPalette(style()->standardPalette());
// Add back stylesheet changes added after MainApplication started
if (!m_accumulatedQss.isEmpty()) {
setStyleSheet(m_accumulatedQss);
DBG qDebug() << styleSheet();
} else {
setStyleSheet("");
}
}
#endif
}
39 changes: 39 additions & 0 deletions PAppearanceWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,45 @@ if a sans-serif font-family specified in your CSS</string>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpCustomDarkStyle">
<property name="title">
<string>Dark Theme Style (Windows Only):</string>
</property>
<layout class="QHBoxLayout" name="darkStyleHLayout">
<item>
<widget class="QCheckBox" name="chkDarkStyle">
<property name="toolTip">
<string>When using a Windows dark style, use the classic dark style instead of the built in Qt one</string>
</property>
<property name="text">
<string>Use Classic Dark Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDarkStyleWarn">
<property name="text">
<string>(Needs PageEdit Restart)</string>
</property>
</widget>
</item>
<item>
<spacer name="darkStyleSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>105</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpHighDPI">
<property name="title">
Expand Down
1 change: 1 addition & 0 deletions SettingsStore.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/************************************************************************
**
** Copyright (C) 2016-2024 Kevin B. Hendricks, Stratford, ON
** Copyright (C) 2016-2024 Doug Massay
** Copyright (C) 2011-2013 John Schember <[email protected]>
** Copyright (C) 2012-2013 Dave Heiland
**
Expand Down

0 comments on commit 8535217

Please sign in to comment.