2023-08-25 11:24:16 +08:00
|
|
|
/*
|
|
|
|
* Qt5-UKUI's Library
|
|
|
|
*
|
2023-10-08 15:46:08 +08:00
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
2023-08-25 11:24:16 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Yue Lan <lanyue@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ukui-style-plugin.h"
|
2023-12-11 15:20:27 +08:00
|
|
|
#include "qt5-config-style-ukui/ukui-config-style.h"
|
2023-08-25 11:24:16 +08:00
|
|
|
|
2023-12-11 15:20:27 +08:00
|
|
|
#include "settings/black-list.h"
|
|
|
|
#include "settings/ukui-style-settings.h"
|
|
|
|
#include "effects/highlight-effect.h"
|
|
|
|
#include "settings/application-style-settings.h"
|
2023-08-25 11:24:16 +08:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QStyleFactory>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
|
|
|
UKUIStylePlugin::UKUIStylePlugin(QObject *parent) :
|
|
|
|
QStylePlugin(parent)
|
|
|
|
{
|
|
|
|
qDebug() << "UKUIStylePlugin.........";
|
|
|
|
if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) {
|
|
|
|
auto settings = UKUIStyleSettings::globalInstance();
|
|
|
|
connect(settings, &UKUIStyleSettings::changed, this, [=](const QString &key) {
|
|
|
|
if (key == "styleName" || key == "widgetThemeName" || key == "themeColor" ||
|
|
|
|
key == "style-name" || key == "widget-theme-name" || key == "theme-color") {
|
|
|
|
if (blackList().contains(qAppName()) || qAppName() == "kylin-software-center.py")
|
|
|
|
return;
|
|
|
|
|
|
|
|
//We should not swich a application theme which use internal style.
|
|
|
|
if (QApplication::style()->inherits("InternalStyle"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto appStyleSettings = ApplicationStyleSettings::getInstance();
|
|
|
|
if (appStyleSettings->currentStyleStretagy() != ApplicationStyleSettings::Default)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto styleName = settings->get("styleName").toString();
|
|
|
|
auto widgetThemeName = settings->get("widgetThemeName").toString();
|
|
|
|
|
|
|
|
if (widgetThemeName != "") {
|
|
|
|
if(qAppName() != blackStyleChangeApp) {
|
|
|
|
if (widgetThemeName == "classical") {
|
2023-10-16 10:30:11 +08:00
|
|
|
styleName ="ukui-config";
|
2023-08-25 11:24:16 +08:00
|
|
|
} else {
|
|
|
|
styleName = "ukui-config";
|
2023-10-18 09:37:33 +08:00
|
|
|
}
|
|
|
|
qApp->setStyle(new UKUIConfigStyle(styleName));
|
|
|
|
|
2023-10-18 10:00:45 +08:00
|
|
|
// if(key == "widgetThemeName" || key == "widget-theme-name"){
|
|
|
|
// qDebug() << "qApp style....." << qApp->style();
|
|
|
|
// auto configStyle = qobject_cast<UKUIConfigStyle *>(qApp->style());
|
|
|
|
// if(configStyle){
|
|
|
|
// int max, normal, min;
|
|
|
|
// max = configStyle->property("windowRadius").isValid() ? configStyle->property("windowRadius").toInt() : settings->get("windowRadius").toInt();
|
|
|
|
// normal = configStyle->property("normalRadius").isValid() ? configStyle->property("normalRadius").toInt() : settings->get("normalRadius").toInt();
|
|
|
|
// min = configStyle->property("minRadius").isValid() ? configStyle->property("minRadius").toInt() : settings->get("minRadius").toInt();
|
|
|
|
// settings->trySet("max-radius", max);
|
|
|
|
// settings->trySet("normal-radius", normal);
|
|
|
|
// settings->trySet("min-radius", min);
|
|
|
|
// }
|
|
|
|
// }
|
2023-08-25 11:24:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//other style
|
|
|
|
for (auto keys : QStyleFactory::keys()) {
|
|
|
|
if (styleName.toLower() == keys.toLower()) {
|
|
|
|
qApp->setStyle(new QProxyStyle(styleName));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//default style fusion
|
|
|
|
qApp->setStyle(new QProxyStyle(styleName));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == "systemPalette") {
|
|
|
|
onSystemPaletteChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == "useSystemPalette") {
|
|
|
|
onSystemPaletteChanged();
|
|
|
|
}
|
2023-10-18 09:37:33 +08:00
|
|
|
|
2023-10-18 10:00:45 +08:00
|
|
|
/*
|
|
|
|
if(key == "window-radius" || key == "windowRadius"){
|
2023-10-18 09:37:33 +08:00
|
|
|
auto radius = settings->get("windowRadius").toInt();
|
|
|
|
foreach (QWidget *widget, qApp->allWidgets()) {
|
|
|
|
widget->setProperty("windowRadius", radius);
|
|
|
|
widget->repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(key == "normal-radius" || key == "normalRadius"){
|
|
|
|
auto radius = settings->get("normalRadius").toInt();
|
|
|
|
//qDebug() << "normalRadius.........." << radius;
|
|
|
|
foreach (QWidget *widget, qApp->allWidgets()) {
|
|
|
|
widget->setProperty("normalRadius", radius);
|
|
|
|
widget->repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(key == "min-radius" || key == "minRadius"){
|
|
|
|
auto radius = settings->get("minRadius").toInt();
|
|
|
|
foreach (QWidget *widget, qApp->allWidgets()) {
|
|
|
|
widget->setProperty("minRadius", radius);
|
|
|
|
widget->repaint();
|
|
|
|
}
|
|
|
|
}
|
2023-10-18 10:00:45 +08:00
|
|
|
*/
|
2023-08-25 11:24:16 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QDBusInterface *interFace = new QDBusInterface("com.kylin.statusmanager.interface",
|
|
|
|
"/",
|
|
|
|
"com.kylin.statusmanager.interface",
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if(interFace->isValid()){
|
|
|
|
connect(interFace, SIGNAL(mode_change_signal(bool)), this, SLOT(tableModeChanged(bool)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QStyle *UKUIStylePlugin::create(const QString &key)
|
|
|
|
{
|
|
|
|
if (blackList().contains(qAppName()))
|
|
|
|
return new Style;
|
|
|
|
|
|
|
|
auto settings = UKUIStyleSettings::globalInstance();
|
|
|
|
auto widgetThemeName = settings->get("widgetThemeName").toString();
|
|
|
|
auto styleName = settings->get("styleName").toString();
|
|
|
|
|
|
|
|
qDebug() << "widgetThemeName........." << widgetThemeName;
|
|
|
|
if (widgetThemeName != "") {
|
|
|
|
if(qAppName() != blackStyleChangeApp) {
|
|
|
|
if (widgetThemeName == "classical") {
|
|
|
|
return new UKUIConfigStyle(styleName);
|
|
|
|
} else {
|
|
|
|
return new UKUIConfigStyle(styleName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new UKUIConfigStyle(widgetThemeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList UKUIStylePlugin::blackList()
|
|
|
|
{
|
|
|
|
return blackAppList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UKUIStylePlugin::onSystemPaletteChanged()
|
|
|
|
{
|
|
|
|
bool useSystemPalette = UKUIStyleSettings::globalInstance()->get("useSystemPalette").toBool();
|
|
|
|
if (useSystemPalette) {
|
|
|
|
auto data = UKUIStyleSettings::globalInstance()->get("systemPalette");
|
|
|
|
if (data.isNull())
|
|
|
|
return;
|
|
|
|
auto palette = qvariant_cast<QPalette>(data);
|
|
|
|
QApplication::setPalette(palette);
|
|
|
|
} else {
|
|
|
|
auto palette = QApplication::style()->standardPalette();
|
|
|
|
QApplication::setPalette(palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UKUIStylePlugin::tableModeChanged(bool isTableMode)
|
|
|
|
{
|
|
|
|
if (blackList().contains(qAppName()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//We should not swich a application theme which use internal style.
|
|
|
|
if (QApplication::style()->inherits("InternalStyle"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto appStyleSettings = ApplicationStyleSettings::getInstance();
|
|
|
|
if (appStyleSettings->currentStyleStretagy() != ApplicationStyleSettings::Default)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto settings = UKUIStyleSettings::globalInstance();
|
|
|
|
auto styleName = settings->get("styleName").toString();
|
|
|
|
|
|
|
|
if (styleName == "ukui-default" || styleName == "ukui-dark" || styleName == "ukui-white"
|
|
|
|
|| styleName == "ukui-black" || styleName == "ukui-light" || styleName == "ukui" || styleName == "ukui-config")
|
|
|
|
|
|
|
|
{
|
|
|
|
if (qApp->property("customStyleName").isValid()) {
|
|
|
|
if (qApp->property("customStyleName").toString() == "ukui-light") {
|
|
|
|
styleName = "ukui-light";
|
|
|
|
} else if (qApp->property("customStyleName").toString() == "ukui-dark") {
|
|
|
|
styleName = "ukui-dark";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QWidget *widget, qApp->allWidgets()) {
|
|
|
|
widget->updateGeometry();
|
|
|
|
}
|
|
|
|
qApp->setProperty("isInitial", false);
|
|
|
|
if(qAppName() != blackStyleChangeApp){
|
|
|
|
auto settings = UKUIStyleSettings::globalInstance();
|
|
|
|
auto widgetThemeName = settings->get("widgetThemeName").toString();
|
|
|
|
auto styleName = settings->get("styleName").toString();
|
|
|
|
|
|
|
|
qDebug() << "widgetThemeName123........." << widgetThemeName;
|
|
|
|
if (widgetThemeName != "") {
|
|
|
|
if(qAppName() != blackStyleChangeApp) {
|
|
|
|
if (widgetThemeName == "classical") {
|
|
|
|
qApp->setStyle(new UKUIConfigStyle(styleName));
|
|
|
|
} else {
|
|
|
|
qApp->setStyle(new UKUIConfigStyle(styleName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-16 10:30:11 +08:00
|
|
|
else
|
|
|
|
qApp->setStyle(new UKUIConfigStyle(styleName));
|
2023-08-25 11:24:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
foreach (QObject *obj, qApp->children()) {
|
|
|
|
if(qobject_cast<const QVBoxLayout*>(obj))//obj->inherits("QVBoxLayout"))
|
|
|
|
{
|
|
|
|
auto *vlayout = qobject_cast<QVBoxLayout *>(obj);
|
|
|
|
qDebug() << "vlayout..." << vlayout->spacing();
|
|
|
|
|
|
|
|
//layout->update();
|
|
|
|
}
|
|
|
|
else if(qobject_cast<QHBoxLayout *>(obj))
|
|
|
|
{
|
|
|
|
auto *hlayout = qobject_cast<QHBoxLayout *>(obj);
|
|
|
|
qDebug() << "hlayout..." << hlayout->spacing();
|
|
|
|
|
|
|
|
//layout->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (QWidget *widget, qApp->topLevelWidgets()) {
|
|
|
|
qDebug() << "widget size...." << widget->size() << widget->minimumSizeHint() << widget->minimumSize();
|
|
|
|
widget->adjustSize();
|
|
|
|
if(widget->layout() != nullptr)
|
|
|
|
{
|
|
|
|
qDebug() << "layoutSpace...." << widget->layout()->spacing();
|
|
|
|
}
|
|
|
|
// if(widget->size() != widget->minimumSizeHint())
|
|
|
|
// widget->setGeometry(widget->x(), widget->y(), widget->minimumSizeHint().width(), widget->minimumSizeHint().height());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
Q_EXPORT_PLUGIN2(ukui-config-style, UKUIStylePlugin)
|
|
|
|
#endif // QT_VERSION < 0x050000
|