!61 add modify WidgetStyle and its history

Merge pull request !61 from likehomedream/WidgetStyle
This commit is contained in:
KevinDuan 2023-11-27 08:29:26 +00:00 committed by Gitee
commit 69fca002cd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 89 additions and 3 deletions

View File

@ -61,7 +61,15 @@ void Bridge::accentColorChanged(QColor accentcolor)
void Bridge::exteriorChanged(QColor accentcolor)
{
QString color = accentcolor.name(QColor::HexRgb);
QString widgetStyle;
if(color=="#1d1d1d"){
widgetStyle = "dark";
}else if(color=="#ffffff"){
widgetStyle = "light";
}
m_configfilemanager->modifyWidgetStyleConf(widgetStyle,QDir::homePath() + "/.cache/theme-build/"
+m_time + "/src/globalTheme/theme.conf");
}
void Bridge::transparencyChanged(int transparency)

View File

@ -182,7 +182,6 @@ bool ConfigFileManager::modifyAccentColorConf(QColor accentcolor,QString confFil
*/
bool ConfigFileManager::modifyQtAccentColorConf(QString accentcolor, QString confFilePath)
{
// 将颜色转换为字符串
QString colorString = accentcolor;
while (colorString.length() < 6) {
@ -263,6 +262,50 @@ bool ConfigFileManager::modifyWallPaperConf(QString wallpaperpath,QString confFi
}
}
/**
* @brief
*
*
*
* @param WidgetStyle
* @param confFilePath
*
* @return true false
*/
bool ConfigFileManager::modifyWidgetStyleConf(QString WidgetStyle, QString confFilePath)
{
QString colorString = WidgetStyle;
// 读取文件内容
QFile file(confFilePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "无法打开文件:" << confFilePath;
return false;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
// 修改内容
int startIndex = content.indexOf("defaultLightDarkMode=") + QString("defaultLightDarkMode=").size();
int endIndex = content.indexOf("\n", startIndex);
content.remove(startIndex, endIndex - startIndex);
content.insert(startIndex, colorString);
// 写入文件
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << content;
file.close();
emit updateInfo();
return true;
} else {
qDebug() << "无法写入文件:" << confFilePath;
return false;
}
}
/**
* @brief
*

View File

@ -26,6 +26,7 @@ public:
bool modifyAccentColorConf(QColor accentcolor,QString confFilePath);
bool modifyQtAccentColorConf(QString accentcolor,QString confFilePath);
bool modifyWallPaperConf(QString wallpaperpath,QString confFilePath);
bool modifyWidgetStyleConf(QString WidgetStyle,QString confFilePath);
bool modifyTransparencyConf(int transparency,QString confFilePath);
bool modifywindowRadiusConf(int windowradius,QString confFilePath);
bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath);

View File

@ -23,6 +23,7 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
getRadius();
getTransparency();
getWindowRadius();
getWidgetStyle();
}
/**
@ -261,6 +262,36 @@ void HistoryInfoLoad::getTransparency()
}
}
void HistoryInfoLoad::getWidgetStyle()
{
QString filePath = m_historyInfo.filepath + "/src/globalTheme/theme.conf";
// 读取文件内容
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qDebug() << "无法打开文件:" << filePath;
return;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
int startIndex = content.indexOf("defaultLightDarkMode=");
if (startIndex != -1) {
int lineStartIndex = content.lastIndexOf('\n', startIndex) + 1;
int lineEndIndex = content.indexOf('\n', startIndex);
if (lineEndIndex == -1) {
lineEndIndex = content.size();
}
QString lineContent = content.mid(lineStartIndex, lineEndIndex - lineStartIndex).trimmed();
lineContent.remove("defaultLightDarkMode=");
m_historyInfo.widgetstyle = lineContent;
}
}
/**
* @brief
*
@ -311,7 +342,7 @@ void HistoryInfoLoad::getWindowRadius()
*/
HistoryInfo HistoryInfoLoad::getInfoData()
{
qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath<<m_historyInfo.windowradius;
qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath<<m_historyInfo.windowradius<<m_historyInfo.widgetstyle;
return m_historyInfo;
}
@ -330,5 +361,6 @@ void HistoryInfoLoad::updateHistoryInfo()
getAccentColor();
getTransparency();
getWindowRadius();
getWidgetStyle();
}

View File

@ -14,6 +14,7 @@ struct HistoryInfo {
QString themetype = "";
QString wallpaperpath = "";
QString accentcolor = "";
QString widgetstyle = "";
int radius = 6;
int transparency = 65;
int windowradius = 6;
@ -33,6 +34,7 @@ public:
void getWallpaper();
void getAccentColor();
void getTransparency();
void getWidgetStyle();
void getWindowRadius();
HistoryInfo getInfoData();
void updateHistoryInfo();