[fix] Fixed dark theme settings on QV2RAY_USE_BUILTIN_DARKTHEME #130

Signed-off-by: Leroy.H.Y <lhy20010403@hotmail.com>
This commit is contained in:
Leroy.H.Y 2019-11-13 20:29:47 +08:00
parent 9121fc5bb6
commit 12e25c92b1
2 changed files with 24 additions and 7 deletions

View File

@ -244,17 +244,13 @@ int main(int argc, char *argv[])
font.setFamily("微软雅黑"); font.setFamily("微软雅黑");
_qApp.setFont(font); _qApp.setFont(font);
#endif #endif
QStringList themes = QStyleFactory::keys();
if (themes.contains(QSTRING(confObject.UISettings.theme))) {
_qApp.setStyle(QSTRING(confObject.UISettings.theme));
LOG(MODULE_INIT " " MODULE_UI, "Setting Qv2ray UI themes.")
}
#if QV2RAY_USE_BUILTIN_DARKTHEME #if QV2RAY_USE_BUILTIN_DARKTHEME
LOG(MODULE_UI, "Using built-in theme.")
if (confObject.UISettings.useDarkTheme) { if (confObject.UISettings.useDarkTheme) {
LOG(MODULE_UI, " --> Using built-in dark theme.")
// From https://forum.qt.io/topic/101391/windows-10-dark-theme/4 // From https://forum.qt.io/topic/101391/windows-10-dark-theme/4
_qApp.setStyle("Fusion");
QPalette darkPalette; QPalette darkPalette;
QColor darkColor = QColor(45, 45, 45); QColor darkColor = QColor(45, 45, 45);
QColor disabledColor = QColor(127, 127, 127); QColor disabledColor = QColor(127, 127, 127);
@ -280,6 +276,14 @@ int main(int argc, char *argv[])
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }");
} }
#else
QStringList themes = QStyleFactory::keys();
if (themes.contains(QSTRING(confObject.UISettings.theme))) {
_qApp.setStyle(QSTRING(confObject.UISettings.theme));
LOG(MODULE_INIT " " MODULE_UI, "Setting Qv2ray UI themes.")
}
#endif #endif
try { try {

View File

@ -33,6 +33,10 @@ PrefrencesWindow::PrefrencesWindow(QWidget *parent) : QDialog(parent),
// //
themeCombo->setCurrentText(QSTRING(CurrentConfig.UISettings.theme)); themeCombo->setCurrentText(QSTRING(CurrentConfig.UISettings.theme));
darkChartThemeCB->setChecked(CurrentConfig.UISettings.useDarkTheme); darkChartThemeCB->setChecked(CurrentConfig.UISettings.useDarkTheme);
#if QV2RAY_USE_BUILTIN_DARKTHEME
// If we use built in theme, it should always be fusion.
themeCombo->setEnabled(!CurrentConfig.UISettings.useDarkTheme);
#endif
languageComboBox->setCurrentText(QSTRING(CurrentConfig.UISettings.language)); languageComboBox->setCurrentText(QSTRING(CurrentConfig.UISettings.language));
logLevelComboBox->setCurrentIndex(CurrentConfig.logLevel); logLevelComboBox->setCurrentIndex(CurrentConfig.logLevel);
tProxyCheckBox->setChecked(CurrentConfig.tProxySupport); tProxyCheckBox->setChecked(CurrentConfig.tProxySupport);
@ -712,4 +716,13 @@ void PrefrencesWindow::on_darkChartThemeCB_stateChanged(int arg1)
{ {
LOADINGCHECK LOADINGCHECK
CurrentConfig.UISettings.useDarkTheme = arg1 == Qt::Checked; CurrentConfig.UISettings.useDarkTheme = arg1 == Qt::Checked;
#if QV2RAY_USE_BUILTIN_DARKTHEME
themeCombo->setEnabled(arg1 != Qt::Checked);
if (arg1 == Qt::Checked) {
themeCombo->setCurrentIndex(QStyleFactory::keys().indexOf("Fusion"));
CurrentConfig.UISettings.theme = "Fusion";
}
#endif
} }