完善设置中的亮色暗色设置与UI的集成

This commit is contained in:
RigoLigoRLC 2022-02-17 18:16:41 +08:00
parent 2481adf29c
commit 8f8f479873
6 changed files with 73 additions and 6 deletions

View File

@ -1,6 +1,7 @@
#include "spkutils.h"
#include "page/spkpagesettings.h"
#include "spkmsgbox.h"
namespace SpkUi
{
@ -54,6 +55,7 @@ namespace SpkUi
ui->edtDownloadServers->setPlainText(CFG->ReadField("download/servers", "").toString());
ui->edtQssPath->setText(CFG->ReadField("internal/qss_path", "").toString());
ui->edtRepoListUrl->setText(CFG->ReadField("url/repo", "").toString());
ui->cmbLightDarkTheme->setCurrentIndex(CFG->ReadField("ui/theme", 0).toInt());
}
void SpkPageSettings::SaveConfiguration()
@ -65,9 +67,20 @@ namespace SpkUi
CFG->SetField("url/res", ui->edtResourceUrl->text());
CFG->SetSettings("dirs/cache", ui->edtResourceCachePath->text());
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText());
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
CFG->SetField("url/repo", ui->edtRepoListUrl->text());
if(!CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText()))
SpkMsgBox::StaticExec(tr("Cannot change distribution servers.\n"
"There's probably still downloads going on."),
tr("Cannot set distribution server"),
QMessageBox::Warning);
if(!CFG->SetField("ui/theme", ui->cmbLightDarkTheme->currentIndex()))
SpkMsgBox::StaticExec(tr("Auto mode can only be used when DDE plugin is loaded.\n"
"Option change is not applied."),
tr("Cannot set theme mode"),
QMessageBox::Warning);
}
void SpkPageSettings::Activated()

View File

@ -196,6 +196,9 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmbLightDarkTheme">
<property name="currentIndex">
<number>3</number>
</property>
<property name="frame">
<bool>true</bool>
</property>
@ -204,7 +207,7 @@
</property>
<item>
<property name="text">
<string>Auto</string>
<string>Auto (DDE only)</string>
</property>
</item>
<item>
@ -217,6 +220,11 @@
<string>Always Dark</string>
</property>
</item>
<item>
<property name="text">
<string>Manual</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">

View File

@ -371,6 +371,13 @@ void SpkMainWindow::Initialize()
connect(ui->PageHome->ui->btnReloadCategory, &QPushButton::clicked,
this, &SpkMainWindow::RefreshCategoryData);
connect(&SpkUi::SpkUiMetaObject, &SpkUi::UiMetaObject::SetThemeButtonVisible,
[=](bool visible)
{
ui->BtnDayNight->setVisible(visible);
ReloadThemedUiIcons();
});
// Register themed button icons
// mThemedUiIconReferences.append({ ui->BtnSettings, "settings" });
mThemedUiIconReferences.append({ ui->BtnDayNight, "daynight" });

View File

@ -40,6 +40,32 @@ namespace SpkUi
namespace States
{
bool IsDDE = false, IsUsingDtkPlugin = false;
bool DoRespondAutoTheme = false;
int LightDarkMode = 3; // Default to Manual
bool ThemeConfigCallback()
{
switch(LightDarkMode)
{
case 0:
if(!DtkPlugin) return false;
SpkUiMetaObject.SetDarkLightTheme(DtkPlugin->GetIsDarkTheme());
break;
case 1:
SetGlobalStyle(Light, true);
SpkUiMetaObject.SetThemeButtonVisible(false);
break;
case 2:
SetGlobalStyle(Dark, true);
SpkUiMetaObject.SetThemeButtonVisible(false);
break;
case 3:
SpkUiMetaObject.SetThemeButtonVisible(true);
break;
}
return true;
}
}
namespace Priv
@ -87,11 +113,12 @@ namespace SpkUi
// Misc data initialization
PrimaryScreenSize = QGuiApplication::primaryScreen()->size();
CFG->BindField("ui/theme", &States::LightDarkMode, 3, States::ThemeConfigCallback);
}
void GuessAppropriateTheme()
{
// FIXME: Too difficult, not implementing it
}
bool CheckIsDeepinDesktop()
@ -280,9 +307,12 @@ namespace SpkUi
// =================== UiMetaObject =======================
// UiMetaObject is the signal-slot receiver for DDE plugin, receiving the DDE system level
// notifications of UI theme changes
// Communications with UI widgets are also done here
void UiMetaObject::SetAccentColor(QColor aColor)
{
if(!SpkUi::States::DoRespondAutoTheme)
return;
CurrentColorSet[Qss::AccentColor] = aColor.lighter(90);
CurrentColorSet[Qss::AccentColorHighlighted] = aColor.lighter(105);
CurrentColorSet[Qss::TextOnAccentColor] = ColorTextOnBackground(aColor);
@ -292,6 +322,8 @@ namespace SpkUi
void UiMetaObject::SetDarkLightTheme(bool isDark)
{
if(!SpkUi::States::DoRespondAutoTheme)
return;
if(isDark)
SetGlobalStyle(Dark, true);
else

View File

@ -34,6 +34,8 @@ namespace SpkUi
public slots:
void SetAccentColor(QColor);
void SetDarkLightTheme(bool isDark);
signals:
void SetThemeButtonVisible(bool);
};
extern UiMetaObject SpkUiMetaObject;
@ -52,6 +54,11 @@ namespace SpkUi
namespace States
{
extern bool IsDDE, IsUsingDtkPlugin;
extern bool DoRespondAutoTheme;
extern int LightDarkMode; ///< Tied to settings UI value
bool ThemeConfigCallback();
}
namespace Priv

View File

@ -6,7 +6,7 @@ repo=https://d.store.deepinos.org.cn/store/server.list
[dirs]
cache="*/.cache/spark-store/res/"
download="*/.local/spark-store/downloads/"
download="*/Downloads/spark-store/"
[download]
servers="https://d1.store.deepinos.org.cn/;;https://d2.store.deepinos.org.cn/;;https://d3.store.deepinos.org.cn/;;https://d4.store.deepinos.org.cn/;;https://d5.store.deepinos.org.cn/"
@ -18,8 +18,8 @@ concurrent=5
privacy_warned=0
distro=none
[gui]
theme=light
[ui]
theme=3
[pkgmgr]
apt_repo=""