qt5-ukui-platformtheme/ukui-styles/readconfig.h

220 lines
7.0 KiB
C++

/*
* Qt5-UKUI's Library
*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* 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: Jing Tan <tanjing@kylinos.cn>
*
*/
#ifndef READCONFIG_H
#define READCONFIG_H
#include <QObject>
#include <QSettings>
#include <QColor>
#include <QJsonDocument>
#include <QJsonObject>
#include <QPalette>
#include "themeinformation.h"
//#define UKUIStyle_Debug
//#define UKUIStyle_Warning
class Debug
{
public:
template<typename T>
Debug & operator <<(const T&){return *this;}
};
inline Debug debug(){return Debug();}
#ifdef UKUIStyle_Debug
# define cDebug qDebug() << "UKUIStyle input:"
#else
# define cDebug Debug()
#endif
class Warning
{
public:
template<typename T>
Warning & operator <<(const T&){return *this;}
};
inline Warning warning(){return Warning();}
#ifdef UKUIStyle_Warning
# define cWarning qWarning() << "UKUIStyle input:"
#else
# define cWarning Warning()
#endif
class ReadConfig : public QObject
{
Q_OBJECT
public:
ReadConfig(const QString &cfg);
~ReadConfig();
bool load(const QString &cfg);
QVariant getValue(const QString key_1, const QString key_2 = "", const QString key_3 = "", const QString key_4 = "", const QString key_5 = "") const;
QVariant getValue(const QString key, QJsonObject obj) const;
QJsonObject getJsonObjectValue(const QString key, QJsonObject obj) const;
bool getColorValue(QColor &color, const QString key_1, const QString key_2 = "", const QString key_3 = "", const QString key_4 = "", const QString key_5 = "") const;
bool getColorValue(QBrush &brush, const QString key_1, const QString key_2 = "", const QString key_3 = "", const QString key_4 = "", const QString key_5 = "") const;
bool getGradientValue(QList<QColor> &cl, const QString key_1, const QString key_2 = "", const QString key_3 = "", const QString key_4 = "", const QString key_5 = "") const;
QString getType(const QString key_1, const QString key_2 = "", const QString key_3 = "", const QString key_4 = "", const QString key_5 = "") const;
QColor stringToColor(QString s) const;
QColor stringToPaletteColor(QString s) const;
void stringToGradient(QList<QColor> &cl, QString s) const;
bool setValue(QString key, QVariant value);
void widgetPalette(const QPalette platte);
private:
QJsonObject m_cfgJsonObj;
QString m_cfgPath;
QPalette m_platte;
};
class ReadThemeConfig : public QObject
{
Q_OBJECT
public:
ReadThemeConfig(QString colorCfgPath, bool isDark = true);
~ReadThemeConfig();
UKUIColorTheme::PaletteColorCfg paletteColorCfg();
UKUIColorTheme::ButtonColorCfg buttonColorCfg(const QPalette palette, QString property = C_Button_DefaultPushButton);
UKUIColorTheme::ToolButtonColorCfg toolButtonColorCfg(const QPalette palette, QString property = C_Button_DefaultToolButton);
UKUIColorTheme::CheckBoxColorCfg checkBoxColorCfg(const QPalette palette, QString property = C_CheckBox_Default);
UKUIColorTheme::RadioButtonColorCfg radioButtonColorCfg(const QPalette palette, QString property = C_RadioButton_Default);
UKUIColorTheme::LineEditColorCfg lineEditColorCfg(const QPalette palette, QString property = C_LineEdit_Default);
UKUIColorTheme::ComboBoxColorCfg comboBoxColorCfg(const QPalette palette, QString property = C_ComboBox_Default);
UKUIColorTheme::SpinBoxColorCfg spinBoxColorCfg(const QPalette palette, QString property = C_SpinBox_Default, QString layout = C_SpinBox_DefaultLayout);
UKUIColorTheme::TableColorCfg tableColorCfg(const QPalette palette, QString property = C_Table_Default);
UKUIColorTheme::ListViewColorCfg listViewColorCfg(const QPalette palette, QString property = C_ListView_Default);
UKUIColorTheme::TreeViewColorCfg treeViewColorCfg(const QPalette palette, QString property = C_TreeView_Default);
UKUIColorTheme::SliderBarColorCfg sliderBarColorCfg(const QPalette palette, QString property = C_SliderBar_Default);
UKUIColorTheme::ProgressBarColorCfg progressBarColorCfg(const QPalette palette, QString property = C_ProgressBar_Default);
UKUIColorTheme::ToolTipColorCfg toolTipColorCfg(const QPalette palette, QString property = C_ToolTip_Default);
UKUIColorTheme::ScrollBarColorCfg scrollBarColorCfg(const QPalette palette, QString property = C_ScrollBar_Default);
UKUIColorTheme::TabWidgetColorCfg tabWidgetColorCfg(const QPalette palette, QString property = C_TabWidget_Default);
UKUIColorTheme::MenuColorCfg menuColorCfg(const QPalette palette, QString property = C_Menu_Default);
bool setRadius(QString key, int r);
void getRadius(QString key, int &r);
UKUIRadiusInformation::UKUIRadiusStruct getRadiusStruct(QString key);
QString getColorValueAdjustRules();
private:
QString m_colorCfgPath;
bool m_themeIsDark = false;
UKUIColorTheme::PaletteColorCfg m_paletteColorCfg ;
UKUIColorTheme::ButtonColorCfg m_buttonColorCfg ;
UKUIColorTheme::ToolButtonColorCfg m_toolButtonColorCfg ;
UKUIColorTheme::CheckBoxColorCfg m_checkBoxColorCfg ;
UKUIColorTheme::RadioButtonColorCfg m_radioButtonColorCfg ;
UKUIColorTheme::LineEditColorCfg m_lineEditColorCfg ;
UKUIColorTheme::ComboBoxColorCfg m_comboBoxColorCfg ;
UKUIColorTheme::SpinBoxColorCfg m_spinBoxColorCfg ;
UKUIColorTheme::TableColorCfg m_tableColorCfg ;
UKUIColorTheme::ListViewColorCfg m_listViewColorCfg ;
UKUIColorTheme::TreeViewColorCfg m_treeViewColorCfg ;
UKUIColorTheme::SliderBarColorCfg m_sliderBarColorCfg ;
UKUIColorTheme::ProgressBarColorCfg m_progressBarColorCfg ;
UKUIColorTheme::ToolTipColorCfg m_toolTipColorCfg ;
UKUIColorTheme::ScrollBarColorCfg m_scrollBarColorCfg ;
UKUIColorTheme::TabWidgetColorCfg m_tabWidgetColorCfg ;
UKUIColorTheme::MenuColorCfg m_menuColorCfg ;
UKUIRadiusInformation::UKUIRadiusStruct m_radiusStruct;
ReadConfig *m_readConfig = nullptr;
QString m_theme = "";
bool m_loadConfig = false;
};
/*
class RadiusConfig : public QObject{
Q_OBJECT
public:
RadiusConfig(QString cfgPath);
~RadiusConfig();
bool setRadius(QString key, int r);
void getRadius(QString key, int &r);
private:
QString m_cfgPath = "";
ReadConfig *m_readConfig = nullptr;
bool m_loadConfig = false;
};
*/
#endif // READCONFIG_H