mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 22:23:49 +08:00
完善设置中的亮色暗色设置与UI的集成
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "spkutils.h"
|
#include "spkutils.h"
|
||||||
#include "page/spkpagesettings.h"
|
#include "page/spkpagesettings.h"
|
||||||
|
#include "spkmsgbox.h"
|
||||||
|
|
||||||
namespace SpkUi
|
namespace SpkUi
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,7 @@ namespace SpkUi
|
|||||||
ui->edtDownloadServers->setPlainText(CFG->ReadField("download/servers", "").toString());
|
ui->edtDownloadServers->setPlainText(CFG->ReadField("download/servers", "").toString());
|
||||||
ui->edtQssPath->setText(CFG->ReadField("internal/qss_path", "").toString());
|
ui->edtQssPath->setText(CFG->ReadField("internal/qss_path", "").toString());
|
||||||
ui->edtRepoListUrl->setText(CFG->ReadField("url/repo", "").toString());
|
ui->edtRepoListUrl->setText(CFG->ReadField("url/repo", "").toString());
|
||||||
|
ui->cmbLightDarkTheme->setCurrentIndex(CFG->ReadField("ui/theme", 0).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpkPageSettings::SaveConfiguration()
|
void SpkPageSettings::SaveConfiguration()
|
||||||
@@ -65,9 +67,20 @@ namespace SpkUi
|
|||||||
CFG->SetField("url/res", ui->edtResourceUrl->text());
|
CFG->SetField("url/res", ui->edtResourceUrl->text());
|
||||||
CFG->SetSettings("dirs/cache", ui->edtResourceCachePath->text());
|
CFG->SetSettings("dirs/cache", ui->edtResourceCachePath->text());
|
||||||
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
|
CFG->SetField("dirs/download", ui->edtDownloadPath->text());
|
||||||
CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText());
|
|
||||||
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
||||||
CFG->SetField("url/repo", ui->edtRepoListUrl->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()
|
void SpkPageSettings::Activated()
|
||||||
|
|||||||
@@ -196,6 +196,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="cmbLightDarkTheme">
|
<widget class="QComboBox" name="cmbLightDarkTheme">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
<property name="frame">
|
<property name="frame">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@@ -204,7 +207,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Auto</string>
|
<string>Auto (DDE only)</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -217,6 +220,11 @@
|
|||||||
<string>Always Dark</string>
|
<string>Always Dark</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Manual</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
|||||||
@@ -371,6 +371,13 @@ void SpkMainWindow::Initialize()
|
|||||||
connect(ui->PageHome->ui->btnReloadCategory, &QPushButton::clicked,
|
connect(ui->PageHome->ui->btnReloadCategory, &QPushButton::clicked,
|
||||||
this, &SpkMainWindow::RefreshCategoryData);
|
this, &SpkMainWindow::RefreshCategoryData);
|
||||||
|
|
||||||
|
connect(&SpkUi::SpkUiMetaObject, &SpkUi::UiMetaObject::SetThemeButtonVisible,
|
||||||
|
[=](bool visible)
|
||||||
|
{
|
||||||
|
ui->BtnDayNight->setVisible(visible);
|
||||||
|
ReloadThemedUiIcons();
|
||||||
|
});
|
||||||
|
|
||||||
// Register themed button icons
|
// Register themed button icons
|
||||||
// mThemedUiIconReferences.append({ ui->BtnSettings, "settings" });
|
// mThemedUiIconReferences.append({ ui->BtnSettings, "settings" });
|
||||||
mThemedUiIconReferences.append({ ui->BtnDayNight, "daynight" });
|
mThemedUiIconReferences.append({ ui->BtnDayNight, "daynight" });
|
||||||
|
|||||||
+33
-1
@@ -40,6 +40,32 @@ namespace SpkUi
|
|||||||
namespace States
|
namespace States
|
||||||
{
|
{
|
||||||
bool IsDDE = false, IsUsingDtkPlugin = false;
|
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
|
namespace Priv
|
||||||
@@ -87,11 +113,12 @@ namespace SpkUi
|
|||||||
|
|
||||||
// Misc data initialization
|
// Misc data initialization
|
||||||
PrimaryScreenSize = QGuiApplication::primaryScreen()->size();
|
PrimaryScreenSize = QGuiApplication::primaryScreen()->size();
|
||||||
|
CFG->BindField("ui/theme", &States::LightDarkMode, 3, States::ThemeConfigCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuessAppropriateTheme()
|
void GuessAppropriateTheme()
|
||||||
{
|
{
|
||||||
|
// FIXME: Too difficult, not implementing it
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckIsDeepinDesktop()
|
bool CheckIsDeepinDesktop()
|
||||||
@@ -280,9 +307,12 @@ namespace SpkUi
|
|||||||
// =================== UiMetaObject =======================
|
// =================== UiMetaObject =======================
|
||||||
// UiMetaObject is the signal-slot receiver for DDE plugin, receiving the DDE system level
|
// UiMetaObject is the signal-slot receiver for DDE plugin, receiving the DDE system level
|
||||||
// notifications of UI theme changes
|
// notifications of UI theme changes
|
||||||
|
// Communications with UI widgets are also done here
|
||||||
|
|
||||||
void UiMetaObject::SetAccentColor(QColor aColor)
|
void UiMetaObject::SetAccentColor(QColor aColor)
|
||||||
{
|
{
|
||||||
|
if(!SpkUi::States::DoRespondAutoTheme)
|
||||||
|
return;
|
||||||
CurrentColorSet[Qss::AccentColor] = aColor.lighter(90);
|
CurrentColorSet[Qss::AccentColor] = aColor.lighter(90);
|
||||||
CurrentColorSet[Qss::AccentColorHighlighted] = aColor.lighter(105);
|
CurrentColorSet[Qss::AccentColorHighlighted] = aColor.lighter(105);
|
||||||
CurrentColorSet[Qss::TextOnAccentColor] = ColorTextOnBackground(aColor);
|
CurrentColorSet[Qss::TextOnAccentColor] = ColorTextOnBackground(aColor);
|
||||||
@@ -292,6 +322,8 @@ namespace SpkUi
|
|||||||
|
|
||||||
void UiMetaObject::SetDarkLightTheme(bool isDark)
|
void UiMetaObject::SetDarkLightTheme(bool isDark)
|
||||||
{
|
{
|
||||||
|
if(!SpkUi::States::DoRespondAutoTheme)
|
||||||
|
return;
|
||||||
if(isDark)
|
if(isDark)
|
||||||
SetGlobalStyle(Dark, true);
|
SetGlobalStyle(Dark, true);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ namespace SpkUi
|
|||||||
public slots:
|
public slots:
|
||||||
void SetAccentColor(QColor);
|
void SetAccentColor(QColor);
|
||||||
void SetDarkLightTheme(bool isDark);
|
void SetDarkLightTheme(bool isDark);
|
||||||
|
signals:
|
||||||
|
void SetThemeButtonVisible(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern UiMetaObject SpkUiMetaObject;
|
extern UiMetaObject SpkUiMetaObject;
|
||||||
@@ -52,6 +54,11 @@ namespace SpkUi
|
|||||||
namespace States
|
namespace States
|
||||||
{
|
{
|
||||||
extern bool IsDDE, IsUsingDtkPlugin;
|
extern bool IsDDE, IsUsingDtkPlugin;
|
||||||
|
|
||||||
|
extern bool DoRespondAutoTheme;
|
||||||
|
extern int LightDarkMode; ///< Tied to settings UI value
|
||||||
|
|
||||||
|
bool ThemeConfigCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Priv
|
namespace Priv
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ repo=https://d.store.deepinos.org.cn/store/server.list
|
|||||||
|
|
||||||
[dirs]
|
[dirs]
|
||||||
cache="*/.cache/spark-store/res/"
|
cache="*/.cache/spark-store/res/"
|
||||||
download="*/.local/spark-store/downloads/"
|
download="*/Downloads/spark-store/"
|
||||||
|
|
||||||
[download]
|
[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/"
|
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
|
privacy_warned=0
|
||||||
distro=none
|
distro=none
|
||||||
|
|
||||||
[gui]
|
[ui]
|
||||||
theme=light
|
theme=3
|
||||||
|
|
||||||
[pkgmgr]
|
[pkgmgr]
|
||||||
apt_repo=""
|
apt_repo=""
|
||||||
|
|||||||
Reference in New Issue
Block a user