Merge branch '2209-22-0525' into 'yhkylin/v101'

Gbp-Pq: Name 0011-Merge-branch-2209-22-0525-into-yhkylin-v101.patch
This commit is contained in:
cibot 2022-05-30 10:35:03 +00:00 committed by 谢炜
parent de0caa1027
commit d065de5f8c
13 changed files with 589 additions and 229 deletions

View File

@ -0,0 +1,184 @@
#include "customglobaltheme.h"
#include <QGSettings>
#include <QSettings>
#include <QStandardPaths>
#include <QPixmap>
#include <QTextCodec>
#include <QMetaMethod>
#define USER_THEME_DIR QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).arg("globaltheme/")
CustomGlobalTheme::CustomGlobalTheme(QObject *parent) : GlobalTheme(parent)
{
if (QGSettings::isSchemaInstalled("org.ukui.globaltheme.settings")) {
gsettings = new QGSettings("org.ukui.globaltheme.settings", "/org/ukui/globaltheme/settings/", this);
connect(gsettings, &QGSettings::changed, this, &CustomGlobalTheme::onGlobalSettingsChanged);
}
QString path = USER_THEME_DIR + "custom.conf";
qsettings = new QSettings(path, QSettings::NativeFormat, this);
qsettings->setIniCodec(QTextCodec::codecForName("utf-8"));
}
QString CustomGlobalTheme::getThemeName()
{
return "custom";
}
QString CustomGlobalTheme::getLocaleThemeName()
{
return tr("custom");
}
bool CustomGlobalTheme::getSupportLightDarkMode()
{
return qsettings->value("getSupportLightDarkMode", false).toBool();
}
QString CustomGlobalTheme::getDefaultLightDarkMode()
{
return qsettings->value("getDefaultLightDarkMode", "light").toString();
}
QString CustomGlobalTheme::getWidgetStyleName()
{
return qsettings->value("getWidgetStyleName", "fashion").toString();
}
QString CustomGlobalTheme::getQtLightThemeName()
{
return qsettings->value("getQtLightThemeName", "ukui-light").toString();
}
QString CustomGlobalTheme::getQtDarkThemeName()
{
return qsettings->value("getQtDarkThemeName", "ukui-dark").toString();
}
QString CustomGlobalTheme::getGtkThemeName()
{
return qsettings->value("getGtkThemeName", "ukui-white").toString();
}
QString CustomGlobalTheme::getGtkLightThemeName()
{
return qsettings->value("getGtkLightThemeName", "ukui-white").toString();
}
QString CustomGlobalTheme::getGtkDarkThemeName()
{
return qsettings->value("getGtkDarkThemeName", "ukui-black").toString();
}
QString CustomGlobalTheme::getIconThemeName()
{
return qsettings->value("getIconThemeName", "ukui-icon-theme-default").toString();
}
QString CustomGlobalTheme::getCursorThemeName()
{
return qsettings->value("getCursorThemeName", "DMZ-white").toString();
}
QString CustomGlobalTheme::getSoundThemeName()
{
return qsettings->value("getSoundThemeName", "xunguang").toString();
}
QString CustomGlobalTheme::getWallPaperPath()
{
return qsettings->value("getWallPaperPath").toString();
}
bool CustomGlobalTheme::getSupportBlur()
{
return qsettings->value("getSupportBlur").toBool();
}
bool CustomGlobalTheme::getBlurEnabled()
{
return qsettings->value("getBlurEnabled").toBool();
}
bool CustomGlobalTheme::getSupportTransparency()
{
return qsettings->value("getSupportTransparency").toBool();
}
int CustomGlobalTheme::getTransparencyBlur()
{
return qsettings->value("getTransparencyBlur", 90).toInt();
}
int CustomGlobalTheme::getTransparencyNoBlur()
{
return qsettings->value("getTransparencyNoBlur", 100).toInt();
}
bool CustomGlobalTheme::getSupportAnimation()
{
return qsettings->value("getSupportAnimation").toBool();
}
int CustomGlobalTheme::getAnimationDuration()
{
return qsettings->value("getAnimationDuration", 150).toInt();
}
void CustomGlobalTheme::loadThumbnail()
{
}
QPixmap CustomGlobalTheme::getThumbnail()
{
return QPixmap();
}
bool CustomGlobalTheme::isModified()
{
if (!gsettings) {
return false;
}
return gsettings->get("idModified").toBool();
}
void CustomGlobalTheme::loadFromOtherGlobalTheme(GlobalTheme *other)
{
if (other->getThemeName() == "custom")
return;
int methodCount = other->metaObject()->methodCount();
for (int i = 0; i < methodCount; i++) {
auto method = other->metaObject()->method(i);
if (method.parameterCount() > 0)
continue;
QString var;
if (other->metaObject()->invokeMethod(other, method.name().constData(), Q_RETURN_ARG(QString, var))) {
qsettings->setValue(method.name().constData(), var);
} else {
bool var;
if (other->metaObject()->invokeMethod(other, method.name().constData(), Q_RETURN_ARG(bool, var))) {
qsettings->setValue(method.name().constData(), var);
}
}
}
qsettings->sync();
}
void CustomGlobalTheme::updateValue(const QString &functionName, const QVariant &value)
{
qsettings->setValue(functionName, value);
qsettings->sync();
}
void CustomGlobalTheme::onGlobalSettingsChanged(const QString &key)
{
if (key == "isModified") {
} else if (key == "globalThemeName") {
}
}

View File

@ -0,0 +1,60 @@
#ifndef CUSTOMGLOBALTHEME_H
#define CUSTOMGLOBALTHEME_H
#include "globaltheme.h"
class QGSettings;
class QSettings;
class CustomGlobalTheme : public GlobalTheme
{
Q_OBJECT
public:
explicit CustomGlobalTheme(QObject *parent = nullptr);
QString getThemeName() override;
QString getLocaleThemeName() override;
bool getSupportLightDarkMode() override;
QString getDefaultLightDarkMode() override;
QString getWidgetStyleName() override;
QString getQtLightThemeName() override;
QString getQtDarkThemeName() override;
QString getGtkThemeName() override;
QString getGtkLightThemeName() override;
QString getGtkDarkThemeName() override;
QString getIconThemeName() override;
QString getCursorThemeName() override;
QString getSoundThemeName() override;
QString getWallPaperPath() override;
bool getSupportBlur() override;
bool getBlurEnabled() override;
bool getSupportTransparency() override;
int getTransparencyBlur() override;
int getTransparencyNoBlur() override;
bool getSupportAnimation() override;
int getAnimationDuration() override;
void loadThumbnail() override;
QPixmap getThumbnail() override;
bool isModified();
void loadFromOtherGlobalTheme(GlobalTheme *other);
void updateValue(const QString &functionName, const QVariant &value);
public Q_SLOTS:
void onGlobalSettingsChanged(const QString &key);
private:
QGSettings *gsettings = nullptr;
QSettings *qsettings = nullptr;
};
#endif // CUSTOMGLOBALTHEME_H

View File

@ -8,6 +8,8 @@
#include <QFile>
#include <QDir>
#include <QPixmap>
#include <QLocale>
#include <QTextCodec>
#include <QDebug>
@ -39,10 +41,22 @@ GlobalTheme::GlobalTheme(const QString &theme, QObject *parent) : QObject(parent
qWarning()<<"can not find global theme"<<d_ptr->themeName;
d_ptr->settings = new QSettings(userPath, QSettings::NativeFormat, this);
}
d_ptr->settings->setIniCodec(QTextCodec::codecForName("utf-8"));
QVariant var;
// generic
d_ptr->settings->beginGroup("generic");
var = d_ptr->settings->value(QString("Name[%1]").arg(QLocale::system().name()));
if (var.isValid()) {
d_ptr->localeThemeName = var.toString();
} else {
d_ptr->localeThemeName = d_ptr->themeName;
}
d_ptr->settings->endGroup();
// color-schemes
d_ptr->settings->beginGroup("color-schemes");
QVariant var;
var = d_ptr->settings->value("supportLightDarkMode");
if (var.isValid()) {
d_ptr->supportLightDarkMode = var.toBool();
@ -142,12 +156,23 @@ GlobalTheme::GlobalTheme(const QString &theme, QObject *parent) : QObject(parent
d_ptr->settings->endGroup();
}
GlobalTheme::GlobalTheme(QObject *parent)
{
d_ptr = new GlobalThemePrivate;
}
QString GlobalTheme::getThemeName()
{
Q_D(GlobalTheme);
return d_func()->themeName;
}
QString GlobalTheme::getLocaleThemeName()
{
Q_D(GlobalTheme);
return d_func()->localeThemeName;
}
bool GlobalTheme::getSupportLightDarkMode()
{
Q_D(GlobalTheme);

View File

@ -22,49 +22,51 @@ class GlobalTheme : public QObject
Q_OBJECT
public:
explicit GlobalTheme(const QString &theme, QObject *parent = nullptr);
explicit GlobalTheme(QObject *parent = nullptr); //custom globaltheme 使用
QString getThemeName();
Q_INVOKABLE virtual QString getThemeName();
Q_INVOKABLE virtual QString getLocaleThemeName();
bool getSupportLightDarkMode();
QString getDefaultLightDarkMode();
Q_INVOKABLE virtual bool getSupportLightDarkMode();
Q_INVOKABLE virtual QString getDefaultLightDarkMode();
QString getWidgetStyleName();
QString getQtLightThemeName();
QString getQtDarkThemeName();
Q_INVOKABLE virtual QString getWidgetStyleName();
Q_INVOKABLE virtual QString getQtLightThemeName();
Q_INVOKABLE virtual QString getQtDarkThemeName();
QString getGtkThemeName();
QString getGtkLightThemeName();
QString getGtkDarkThemeName();
Q_INVOKABLE virtual QString getGtkThemeName();
Q_INVOKABLE virtual QString getGtkLightThemeName();
Q_INVOKABLE virtual QString getGtkDarkThemeName();
QString getIconThemeName();
QString getCursorThemeName();
QString getSoundThemeName();
QString getWallPaperPath();
Q_INVOKABLE virtual QString getIconThemeName();
Q_INVOKABLE virtual QString getCursorThemeName();
Q_INVOKABLE virtual QString getSoundThemeName();
Q_INVOKABLE virtual QString getWallPaperPath();
bool getSupportBlur();
bool getBlurEnabled();
Q_INVOKABLE virtual bool getSupportBlur();
Q_INVOKABLE virtual bool getBlurEnabled();
bool getSupportTransparency();
int getTransparencyBlur();
int getTransparencyNoBlur();
Q_INVOKABLE virtual bool getSupportTransparency();
Q_INVOKABLE virtual int getTransparencyBlur();
Q_INVOKABLE virtual int getTransparencyNoBlur();
bool getSupportAnimation();
int getAnimationDuration();
Q_INVOKABLE virtual bool getSupportAnimation();
Q_INVOKABLE virtual int getAnimationDuration();
void loadThumbnail();
QPixmap getThumbnail();
virtual void loadThumbnail();
virtual QPixmap getThumbnail();
/*!
* \brief realPath
* \return
*/
QString realPath();
virtual QString realPath();
Q_SIGNALS:
void thumbnailLoaded();
public Q_SLOTS:
void updateThumbnail(const QPixmap &pixmap);
virtual void updateThumbnail(const QPixmap &pixmap);
private:
Q_DECLARE_PRIVATE(GlobalTheme)

View File

@ -13,6 +13,7 @@ public:
GlobalThemePrivate() {}
QString themeName;
QString localeThemeName;
bool supportLightDarkMode = true;
QString defaultLightDarkMode = "light";

View File

@ -1,5 +1,6 @@
#include "globalthemehelper.h"
#include "globaltheme.h"
#include "customglobaltheme.h"
#include <QSettings>
#include <QStandardPaths>
@ -73,6 +74,23 @@ void GlobalThemeHelper::invalidateCurrentGlobalTheme()
}
}
GlobalTheme *GlobalThemeHelper::getCustomTheme()
{
return d_func()->globalThemes.value("custom");
}
void GlobalThemeHelper::syncCustomThemeFromCurrentTheme()
{
auto customTheme = qobject_cast<CustomGlobalTheme *>(d_func()->globalThemes.value("custom"));
customTheme->loadFromOtherGlobalTheme(getCurrentGlobalTheme());
}
void GlobalThemeHelper::updateCustomThemeSetting(const QString &functionName, const QVariant &value)
{
auto customTheme = qobject_cast<CustomGlobalTheme *>(d_func()->globalThemes.value("custom"));
customTheme->updateValue(functionName, value);
}
void GlobalThemeHelper::loadThumbnail(GlobalTheme *theme)
{
auto thread = new QThread;
@ -113,6 +131,9 @@ void GlobalThemeHelperPrivate::initThemes()
auto globalTheme = new GlobalTheme(theme);
globalThemes.insert(theme, globalTheme);
}
auto customTheme = new CustomGlobalTheme;
globalThemes.insert("custom", customTheme);
}
QString GlobalThemeHelperPrivate::getCurrentThemeName()

View File

@ -47,6 +47,27 @@ public:
*/
void invalidateCurrentGlobalTheme();
/*!
* \brief getCustomTheme
* \return
*/
GlobalTheme *getCustomTheme();
/*!
* \brief syncCustomThemeFromCurrentTheme
*
* updateCustomThemeSetting()
*/
void syncCustomThemeFromCurrentTheme();
/*!
* \brief updateCustomThemeSetting
* key值是对应方法的namevalue是需要更新的值
* \param functionName
* \param value
*/
void updateCustomThemeSetting(const QString &functionName, const QVariant &value);
/*!
* \brief loadThumbnail
* \param theme

View File

@ -81,4 +81,9 @@ bool PictureUnit::getClickedFlag()
void PictureUnit::changeClickedFlag(bool flag)
{
clickedFlag = flag;
if (flag) {
setStyleSheet(this->clickedStyleSheet);
} else {
setStyleSheet("border-width: 0px;");
}
}

View File

@ -45,6 +45,11 @@
#define PEONY_TRAN_KEY "peony-side-bar-transparency"
#define ICON_QT_KEY "icon-theme-name"
#define WIDGET_QT_KEY "widget-theme-name"
#define COLOR_QT_KEY "theme-color"
#define GLOBAL_SCHEMA "org.ukui.globaltheme.settings"
#define GLOBAL_NAME_KEY "global-theme-name"
#define ISMODIFY_KEY "is-modified"
#define ICONTHEMEPATH "/usr/share/icons/"
#define SYSTHEMEPATH "/usr/share/themes/"
@ -224,11 +229,6 @@ void Theme::setupComponent() {
ui->darkFrame->setVisible(!Utils::isCommunity());
//隐藏现阶段不支持功能
ui->controlLabel->hide();
ui->controlWidget->hide();
ui->verticalSpacer_2->changeSize(0,0);
ui->defaultButton->setProperty("value", "ukui-default");
ui->defaultButton->setStyleSheet("QPushButton{color: palette(base);border-radius: 4px;}");
ui->lightButton->setProperty("value", "ukui-light");
@ -244,9 +244,7 @@ void Theme::setupComponent() {
ui->tranSlider->setValue(static_cast<int>(personliseGsettings->get(PERSONALSIE_TRAN_KEY).toDouble() * 100.0));
connect(ui->tranSlider, &QSlider::valueChanged, this, [=]() {
personliseGsettings->set(PERSONALSIE_TRAN_KEY,(static_cast<int>(ui->tranSlider->value()) / 100.0));
qtSettings->set(THEME_TRAN_KEY, ui->tranSlider->value());
qtSettings->set(PEONY_TRAN_KEY, ui->tranSlider->value());
changeTranpancySlot(ui->tranSlider->value());
});
//构建并填充特效开关按钮
@ -256,6 +254,9 @@ void Theme::setupComponent() {
ui->kwinFrame->setVisible(false);
ui->transFrame->setVisible(true);
ui->line->setVisible(true);
initGlobalTheme();
initControlTheme();
}
void Theme::buildThemeModeBtn(QPushButton *button, QString name, QString icon){
@ -413,7 +414,7 @@ void Theme::initThemeMode() {
});
connect(personliseGsettings, &QGSettings::changed,this,[=] (const QString &key) {
if(key == "effect") {
if (key == "effect") {
bool effectEnabled = personliseGsettings->get("effect").toBool();
effectSwitchBtn->setChecked(effectEnabled);
}
@ -436,6 +437,7 @@ void Theme::initIconTheme() {
// 设置图标主题
qtSettings->set(ICON_QT_KEY, value);
gtkSettings->set(ICON_GTK_KEY, value);
revokeGlobalThemeSlot();
});
//构建图标主题QDir
@ -462,53 +464,70 @@ void Theme::initIconTheme() {
}
}
void Theme::setupControlTheme(){
QStringList colorStringList;
colorStringList << QString("#3D6BE5");
colorStringList << QString("#FA6C63");
colorStringList << QString("#6cd472");
colorStringList << QString("#f9a959");
colorStringList << QString("#BA7Bd8");
colorStringList << QString("#F8D15D");
colorStringList << QString("#E7BBB0");
colorStringList << QString("#176F57");
QButtonGroup * colorBtnGroup = new QButtonGroup();
for (QString color : colorStringList){
QPushButton * button = new QPushButton(ui->controlWidget);
button->setFixedSize(QSize(48, 48));
button->setCheckable(true);
colorBtnGroup->addButton(button, colorStringList.indexOf(color));
QVBoxLayout * colorVerLayout = new QVBoxLayout();
colorVerLayout->setSpacing(0);
colorVerLayout->setMargin(0);
QHBoxLayout * colorHorLayout = new QHBoxLayout();
colorHorLayout->setSpacing(0);
colorHorLayout->setMargin(0);
QLabel * selectedColorLabel = new QLabel(button);
QSizePolicy scSizePolicy = selectedColorLabel->sizePolicy();
scSizePolicy.setHorizontalPolicy(QSizePolicy::Fixed);
scSizePolicy.setVerticalPolicy(QSizePolicy::Fixed);
selectedColorLabel->setSizePolicy(scSizePolicy);
selectedColorLabel->setScaledContents(true);
selectedColorLabel->setPixmap(QPixmap("://img/plugins/theme/selected.png"));
// 初始化选中图标状态
selectedColorLabel->setVisible(button->isChecked());
colorHorLayout->addStretch();
colorHorLayout->addWidget(selectedColorLabel);
colorVerLayout->addLayout(colorHorLayout);
colorVerLayout->addStretch();
button->setLayout(colorVerLayout);
ui->controlHorLayout->addWidget(button);
void Theme::initControlTheme()
{
if (!qtSettings->keys().contains("themeColor")) {
return;
}
QString colorName = qtSettings->get(COLOR_QT_KEY).toString();
mControlMap.insert("daybreakBlue", QColor(55, 144, 250));
mControlMap.insert("jamPurple", QColor(114, 46, 209));
mControlMap.insert("magenta", QColor(235, 48, 150));
mControlMap.insert("sunRed", QColor(243, 34, 45));
mControlMap.insert("sunsetOrange", QColor(246, 140, 39));
mControlMap.insert("dustGold", QColor(255, 217, 102));
mControlMap.insert("polarGreen", QColor(82, 196, 41));
mControlLabel = new TitleLabel();
mControlLabel->setMaximumWidth(100);
mControlLabel->setText(tr("Corlor"));
mControlHLyt = new QHBoxLayout();
mControlHLyt->addWidget(mControlLabel);
mControlHLyt->addSpacing(32);
mControlFrame = new QFrame(pluginWidget);
mControlFrame->setMinimumHeight(60);
mControlFrame->setFrameShape(QFrame::Shape::Box);
QMap<QString, QColor>::const_iterator it = mControlMap.constBegin();
while (it != mControlMap.constEnd()) {
QRadioButton *radioBtn = new QRadioButton();
QPen pen = QPen(it.value());
QBrush brush = QBrush(it.value());
radioBtn->setProperty("setDefaultPen", pen);
radioBtn->setProperty("setDefaultBrush", brush);
radioBtn->setProperty("setOnDefaultPen", pen);
radioBtn->setProperty("setOnDefaultBrush", brush);
radioBtn->setProperty("setHoverPen", pen);
radioBtn->setProperty("setHoverBrush", brush);
radioBtn->setProperty("setClickPen", pen);
radioBtn->setProperty("setClickBrush", brush);
radioBtn->setProperty("setOnHoverPen", pen);
radioBtn->setProperty("setOnHoverBrush", brush);
radioBtn->setProperty("setOnClickPen", pen);
radioBtn->setProperty("setOnClickBrush", brush);
radioBtn->setProperty("key", it.key());
if (!colorName.compare(radioBtn->property("key").toString())) {
radioBtn->setChecked(true);
}
mControlHLyt->addWidget(radioBtn);
connect(radioBtn, &QRadioButton::clicked, this, [=]{
qtSettings->set(COLOR_QT_KEY, radioBtn->property("key"));
});
it++;
}
mControlHLyt->addStretch();
mControlFrame->setLayout(mControlHLyt);
ui->controlLyt->addWidget(mControlFrame);
}
void Theme::initCursorTheme(){
@ -526,6 +545,7 @@ void Theme::initCursorTheme(){
// 设置光标主题
curSettings->set(CURSOR_THEME_KEY, value);
kwinCursorSlot(value);
revokeGlobalThemeSlot();
});
int count = 0;
@ -543,17 +563,19 @@ void Theme::initCursorTheme(){
}
}
void Theme::initSwitchTheme()
void Theme::initGlobalTheme()
{
QGSettings globalSet(QByteArray("org.ukui.globaltheme.settings"), QByteArray());
QString globalName = globalSet.get("global-theme-name").toString();
if (!mGlobalSettings->keys().contains("globalThemeName")) {
return;
}
QString globalName = mGlobalSettings->get("global-theme-name").toString();
mHLyt = new QHBoxLayout();
mSwitchFrame = new QFrame(pluginWidget);
mSwitchFrame->setMinimumHeight(156);
mSwitchFrame->setFrameShape(QFrame::Shape::Box);
mSwitchFrame->setLayout(mHLyt);
mBtnGroup = new QButtonGroup(this);
mSwitchLabel = new TitleLabel();
mSwitchLabel->setText(tr("Theme"));
@ -564,12 +586,17 @@ void Theme::initSwitchTheme()
mGlobalthemehelper->loadThumbnail(theme);
QString themeName = theme->getThemeName();
QString i18nName = theme->getLocaleThemeName();
QVBoxLayout *vLyt = new QVBoxLayout();
QLabel *labelName = new QLabel(dullTranslation(themeName));
QLabel *labelName = new QLabel(i18nName);
PictureUnit *iconLabel = new PictureUnit(pluginWidget);
if (!themeName.compare("custom")) {
mCustomPicUnit = iconLabel;
}
vLyt->addWidget(iconLabel);
vLyt->addWidget(labelName);
labelName->setAlignment(Qt::AlignCenter);
@ -579,7 +606,6 @@ void Theme::initSwitchTheme()
if (!globalName.compare(themeName)) {
mPrePicUnit = iconLabel;
iconLabel->changeClickedFlag(true);
iconLabel->setStyleSheet(iconLabel->clickedStyleSheet);
}
connect(theme, &GlobalTheme::thumbnailLoaded, this, [=]{
@ -590,13 +616,11 @@ void Theme::initSwitchTheme()
if (mPrePicUnit != nullptr) {
mPrePicUnit->changeClickedFlag(false);
mPrePicUnit->setStyleSheet("border-width: 0px;");
}
iconLabel->changeClickedFlag(true);
mPrePicUnit = iconLabel;
iconLabel->setFrameShape(QFrame::Box);
iconLabel->setStyleSheet(iconLabel->clickedStyleSheet);
changeGlobalThemeSlot(theme);
});
}
@ -609,23 +633,7 @@ void Theme::initConnection() {
connect(ui->resetBtn, &QPushButton::clicked, this, &Theme::resetBtnClickSlot);
connect(effectSwitchBtn, &KSwitchButton::stateChanged, [this](bool checked) {
if (!checked) {
save_trans = static_cast<int>(personliseGsettings->get(PERSONALSIE_TRAN_KEY).toDouble() * 100.0);
personliseGsettings->set(PERSONALSIE_SAVE_TRAN_KEY, save_trans);
personliseGsettings->set(PERSONALSIE_TRAN_KEY, 1.0);
qtSettings->set(THEME_TRAN_KEY, 100);
qtSettings->set(PEONY_TRAN_KEY, 100);
ui->tranSlider->setValue(100);
} else {
save_trans = personliseGsettings->get(PERSONALSIE_SAVE_TRAN_KEY).toInt();
ui->tranSlider->setValue(save_trans);
}
// 提供给外部监听特效接口
personliseGsettings->set(PERSONALSIE_EFFECT_KEY, checked);
QString currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
ui->transFrame->setVisible(checked && !Utils::isTablet());
ui->line->setVisible(checked && !Utils::isTablet());
writeKwinSettings(checked, currentThemeMode, true);
changeEffectSlot(checked);
});
}
@ -776,10 +784,15 @@ void Theme::setupGSettings() {
const QByteArray idd(THEME_QT_SCHEMA);
const QByteArray iid(CURSOR_THEME_SCHEMA);
const QByteArray iiid(PERSONALSIE_SCHEMA);
const QByteArray globalID(GLOBAL_SCHEMA);
gtkSettings = new QGSettings(id, QByteArray(), this);
qtSettings = new QGSettings(idd, QByteArray(), this);
curSettings = new QGSettings(iid, QByteArray(), this);
personliseGsettings = new QGSettings(iiid, QByteArray(), this);
if (QGSettings::isSchemaInstalled(globalID)) {
mGlobalSettings = new QGSettings(globalID, QByteArray(), this);
}
}
void Theme::kwinCursorSlot(QString value) {
@ -953,40 +966,96 @@ void Theme::themeBtnClickSlot(QAbstractButton *button) {
tmpMode = "ukui-white";
}
gtkSettings->set(MODE_GTK_KEY, tmpMode);
qtSettings->set(MODE_QT_KEY, themeMode);
}
revokeGlobalThemeSlot();
}
void Theme::changeGlobalThemeSlot(GlobalTheme *theme)
{
bool supportBlur = theme->getSupportBlur();
bool blurEnable = theme->getBlurEnabled();
bool supportTranspancy = theme->getSupportTransparency();
int transparency = theme->getTransparencyBlur();
QString globalName = theme->getThemeName();
QString wallpaper = theme->getWallPaperPath();
QString iconName = theme->getIconThemeName();
QString cursorName = theme->getCursorThemeName();
QString widgetName = theme->getWidgetStyleName();
QString colorTheme = theme->getDefaultLightDarkMode();
QString gtkColorTheme;
if (!colorTheme.compare("light")) {
colorTheme = theme->getQtLightThemeName();
gtkColorTheme = theme->getGtkLightThemeName();
} else if (!colorTheme.compare("dark")) {
colorTheme = theme->getQtDarkThemeName();
gtkColorTheme = theme->getGtkDarkThemeName();
}
QGSettings globalSet(QByteArray("org.ukui.globaltheme.settings"), QByteArray());
globalSet.set("global-theme-name", globalName);
QGSettings wallPaperSet(QByteArray("org.mate.background"), QByteArray());
wallPaperSet.set("picture-filename", wallpaper);
mGlobalSettings->set(GLOBAL_NAME_KEY, globalName);
mGlobalSettings->set(ISMODIFY_KEY, false);
qtSettings->set(ICON_QT_KEY, iconName);
qtSettings->set(WIDGET_QT_KEY, widgetName);
qtSettings->set(MODE_QT_KEY, colorTheme);
gtkSettings->set(ICON_GTK_KEY, iconName);
gtkSettings->set(MODE_GTK_KEY, iconName);
gtkSettings->set(MODE_GTK_KEY, gtkColorTheme);
curSettings->set(CURSOR_THEME_KEY, cursorName);
if (supportBlur) {
changeEffectSlot(blurEnable);
}
if (supportTranspancy) {
changeTranpancySlot(transparency);
}
}
void Theme::revokeGlobalThemeSlot()
{
mPrePicUnit->changeClickedFlag(false);
mCustomPicUnit->changeClickedFlag(true);
if (mGlobalSettings) {
mGlobalSettings->set(ISMODIFY_KEY, true);
mGlobalSettings->set(GLOBAL_NAME_KEY, "custom");
}
}
void Theme::changeEffectSlot(bool checked)
{
if (!checked) {
save_trans = static_cast<int>(personliseGsettings->get(PERSONALSIE_TRAN_KEY).toDouble() * 100.0);
personliseGsettings->set(PERSONALSIE_SAVE_TRAN_KEY, save_trans);
personliseGsettings->set(PERSONALSIE_TRAN_KEY, 1.0);
qtSettings->set(THEME_TRAN_KEY, 100);
qtSettings->set(PEONY_TRAN_KEY, 100);
ui->tranSlider->setValue(100);
} else {
save_trans = personliseGsettings->get(PERSONALSIE_SAVE_TRAN_KEY).toInt();
ui->tranSlider->setValue(save_trans);
}
// 提供给外部监听特效接口
personliseGsettings->set(PERSONALSIE_EFFECT_KEY, checked);
QString currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
ui->transFrame->setVisible(checked && !Utils::isTablet());
ui->line->setVisible(checked && !Utils::isTablet());
writeKwinSettings(checked, currentThemeMode, true);
}
void Theme::changeTranpancySlot(int value)
{
personliseGsettings->set(PERSONALSIE_TRAN_KEY,(static_cast<int>(value) / 100.0));
qtSettings->set(THEME_TRAN_KEY, value);
qtSettings->set(PEONY_TRAN_KEY, value);
}
void Theme::setCheckStatus(QLayout *mlayout, QString checkName, ThemeType type) {

View File

@ -25,7 +25,7 @@
#include <QLayout>
#include <QMap>
#include <QDir>
#include <QDir>
#include <QColor>
#include <QSettings>
#include <QtDBus/QDBusMessage>
#include <QGSettings>
@ -68,13 +68,12 @@ private:
int pluginType;
QWidget *pluginWidget;
QGSettings *gtkSettings;
QGSettings *qtSettings;
QGSettings *curSettings;
QSettings *kwinSettings;
QSettings *themeSettings;
QGSettings *kwinGsettings = nullptr;
QGSettings *gtkSettings = nullptr;
QGSettings *qtSettings = nullptr;
QGSettings *curSettings = nullptr;
QGSettings *personliseGsettings = nullptr;
QGSettings *mGlobalSettings = nullptr;
QSettings *kwinSettings;
KSwitchButton *effectSwitchBtn;
@ -84,12 +83,18 @@ private:
WidgetGroup *iconThemeWidgetGroup;
TitleLabel *mSwitchLabel;
TitleLabel *mControlLabel;
PictureUnit *mPrePicUnit = nullptr;
PictureUnit *mCustomPicUnit = nullptr;
GlobalThemeHelper *mGlobalthemehelper;
QHBoxLayout *mHLyt;
QButtonGroup *mBtnGroup;
QHBoxLayout *mControlHLyt;
QFrame *mSwitchFrame;
QFrame *mControlFrame;
QMap<QString, QColor> mControlMap;
public:
Theme();
@ -108,9 +113,9 @@ public:
void setupComponent();
void initThemeMode();
void initIconTheme();
void setupControlTheme();
void initControlTheme();
void initCursorTheme();
void initSwitchTheme();
void initGlobalTheme();
void initConnection();
void initIconThemeWidget(QString themedir, int count);
void initCursorThemeWidget(QString themedir, int count);
@ -134,7 +139,7 @@ private:
QString dullCursorTranslation(QString str);
QString getCursorName();
void hideIntelComponent(); // 隐藏非intel功能
void hideIntelComponent();
bool isBlurEffect();
@ -143,6 +148,9 @@ private slots:
void writeKwinSettings(bool change, QString theme, bool effect = false);
void themeBtnClickSlot(QAbstractButton *button);
void changeGlobalThemeSlot(GlobalTheme *theme);
void revokeGlobalThemeSlot();
void changeEffectSlot(bool checked);
void changeTranpancySlot(int value);
};
#endif // THEME_H

View File

@ -29,6 +29,7 @@ PKGCONFIG += gsettings-qt \
SOURCES += \
cursor/cursortheme.cpp \
cursor/xcursortheme.cpp \
globaltheme/customglobaltheme.cpp \
globaltheme/globaltheme.cpp \
pictureunit.cpp \
globaltheme/globalthemehelper.cpp \
@ -43,6 +44,7 @@ HEADERS += \
cursor/config-X11.h \
cursor/cursortheme.h \
cursor/xcursortheme.h \
globaltheme/customglobaltheme.h \
globaltheme/globaltheme.h \
globaltheme/globaltheme_p.h \
globaltheme/globalthemehelper.h \

View File

@ -70,6 +70,19 @@
<item>
<layout class="QVBoxLayout" name="switchLyt"/>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="TitleLabel" name="titleLabel">
<property name="sizePolicy">
@ -339,6 +352,22 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>4</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="controlLyt"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@ -415,81 +444,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>32</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="TitleLabel" name="controlLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Control theme</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="controlWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>66</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>66</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="controlHorLayout">
<property name="spacing">
<number>16</number>
</property>
<property name="leftMargin">
<number>24</number>
</property>
<property name="rightMargin">
<number>24</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">

View File

@ -3130,6 +3130,14 @@ change system settings</source>
<translation></translation>
</message>
</context>
<context>
<name>CustomGlobalTheme</name>
<message>
<location filename="../../../plugins/personalized/theme/globaltheme/customglobaltheme.cpp" line="32"/>
<source>custom</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CustomLineEdit</name>
<message>
@ -10734,64 +10742,64 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="109"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="533"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="110"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="579"/>
<source>Theme</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="243"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="239"/>
<source>Default</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="244"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="240"/>
<source>Light</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="245"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="241"/>
<source>Dark</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="483"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="485"/>
<source>Corlor</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="787"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="819"/>
<source>Blue-Crystal</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="789"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="832"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="821"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="864"/>
<source>Light-Seeking</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="791"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="823"/>
<source>DMZ-Black</source>
<translation>DMZ-</translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="793"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="825"/>
<source>DMZ-White</source>
<translation>DMZ-</translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="795"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="827"/>
<source>Dark-Sense</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="828"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="860"/>
<source>basic</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="830"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="862"/>
<source>Classic</source>
<translation></translation>
</message>
@ -10804,22 +10812,22 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="836"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="868"/>
<source>hp</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="838"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="870"/>
<source>ukui</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="834"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="866"/>
<source>HeYin</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="840"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="872"/>
<source>default</source>
<translation></translation>
</message>
@ -10828,15 +10836,15 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="82"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="166"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="95"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="167"/>
<source>Window Theme</source>
<translation></translation>
<extra-contents_path>/Theme/Window Theme</extra-contents_path>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="370"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="168"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="396"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="169"/>
<source>Icon theme</source>
<translation></translation>
<extra-contents_path>/Theme/Icon theme</extra-contents_path>
@ -10846,20 +10854,20 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="446"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="170"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="472"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="171"/>
<source>Cursor theme</source>
<translation></translation>
<extra-contents_path>/Theme/Cursor theme</extra-contents_path>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="522"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="548"/>
<source>Effect setting</source>
<translation></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="724"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="174"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="750"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="175"/>
<source>Transparency</source>
<translation></translation>
<extra-contents_path>/Theme/Transparency</extra-contents_path>
@ -10869,8 +10877,8 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="621"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="172"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="647"/>
<location filename="../../../plugins/personalized/theme/theme.cpp" line="173"/>
<source>Performance mode</source>
<translation></translation>
<extra-contents_path>/Theme/Performance mode</extra-contents_path>
@ -10888,7 +10896,7 @@ E-mail: support@kylinos.cn</source>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../../plugins/personalized/theme/theme.ui" line="842"/>
<location filename="../../../plugins/personalized/theme/theme.ui" line="868"/>
<source>Reset to default</source>
<translation></translation>
</message>