!61 add modify WidgetStyle and its history
Merge pull request !61 from likehomedream/WidgetStyle
This commit is contained in:
commit
69fca002cd
|
@ -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)
|
||||
|
|
|
@ -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 修改透明度配置
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue