add history function info part

This commit is contained in:
likehomedream 2023-10-10 16:41:51 +08:00
parent 69d86b4d3d
commit a944fd39c4
14 changed files with 252 additions and 72 deletions

View File

@ -97,10 +97,10 @@ void Bridge::startCopy()
m_configfilemanager->copyCovertoCacheDir(m_coverpath,m_builderConfig); m_configfilemanager->copyCovertoCacheDir(m_coverpath,m_builderConfig);
} }
void Bridge::createFileManager(QString time) void Bridge::createFileManager(bool ishistory,QString time)
{ {
m_time = time; m_time = time;
m_configfilemanager = new ConfigFileManager(time); m_configfilemanager = new ConfigFileManager(ishistory,time);
createDir(); createDir();
} }

View File

@ -13,7 +13,7 @@ class Bridge : public QObject
Q_OBJECT Q_OBJECT
public: public:
static Bridge* getInstance(QObject *parent = nullptr); static Bridge* getInstance(QObject *parent = nullptr);
void createFileManager(QString time); void createFileManager(bool ishistory,QString time);
void createDir(); void createDir();
void wallpaperPathChanged(QString path); void wallpaperPathChanged(QString path);
void coverPathChanged(QString path); void coverPathChanged(QString path);

View File

@ -1,15 +1,22 @@
#include "configfilemanager.h" #include "configfilemanager.h"
ConfigFileManager::ConfigFileManager(const QString& time,QObject *parent) : QObject(parent) ConfigFileManager::ConfigFileManager(bool ishistory, const QString& time, QObject *parent) : QObject(parent)
{ {
//创建json、conf文件到指定目录在这个类里进行修改。 //创建json、conf文件到指定目录在这个类里进行修改。
m_time = time; if(!ishistory){
createConf(); m_time = time;
createJson(); createConf();
createJson();
}else{
m_time = time;
jsonFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/"+ "default.json";
confFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/"+ "theme.conf";
qDebug()<<"have";
}
} }
bool ConfigFileManager::createJson() bool ConfigFileManager::createJson()
{ {
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/"; QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/";
@ -55,44 +62,43 @@ bool ConfigFileManager::createConf()
bool ConfigFileManager::modifyRadiusJson(int radius) bool ConfigFileManager::modifyRadiusJson(int radius)
{ {
QString confFilePath = jsonFilePath; // 替换为实际的文件路径 QString confFilePath = jsonFilePath; // 替换为实际的文件路径
// 读取配置文件
QFile configFile(confFilePath);
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug() << "Failed to open config file";
return false;
}
// 读取配置文件 QByteArray data = configFile.readAll();
QFile configFile(confFilePath); configFile.close();
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug() << "Failed to open config file";
return false;
}
QByteArray data = configFile.readAll(); // 解析JSON
configFile.close(); QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError)
{
qDebug() << "Failed to parse JSON:" << error.errorString();
return false;
}
// 解析JSON // 修改"value"字段的值为18
QJsonParseError error; QJsonObject jsonObj = jsonDoc.object();
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); QJsonObject radiusObj = jsonObj["Radius"].toObject();
if (error.error != QJsonParseError::NoError) for (auto it = radiusObj.begin(); it != radiusObj.end(); ++it)
{ {
qDebug() << "Failed to parse JSON:" << error.errorString(); QJsonObject valueObj = it.value().toObject();
return false; valueObj["value"] = QString::number(radius);
} radiusObj[it.key()] = valueObj;
}
jsonObj["Radius"] = radiusObj;
// 修改"value"字段的值为18 // 保存修改后的配置文件
QJsonObject jsonObj = jsonDoc.object(); configFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
QJsonObject radiusObj = jsonObj["Radius"].toObject(); configFile.write(QJsonDocument(jsonObj).toJson());
for (auto it = radiusObj.begin(); it != radiusObj.end(); ++it) configFile.close();
{
QJsonObject valueObj = it.value().toObject();
valueObj["value"] = QString::number(radius);
radiusObj[it.key()] = valueObj;
}
jsonObj["Radius"] = radiusObj;
// 保存修改后的配置文件 qDebug() << "Config file updated successfully";
configFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
configFile.write(QJsonDocument(jsonObj).toJson());
configFile.close();
qDebug() << "Config file updated successfully";
} }

View File

@ -15,7 +15,7 @@ class ConfigFileManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigFileManager(const QString& time,QObject *parent = nullptr); explicit ConfigFileManager(bool ishistory,const QString& time,QObject *parent = nullptr);
bool createJson(); bool createJson();
bool createConf(); bool createConf();

View File

@ -2,15 +2,22 @@
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent) HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
{ {
m_historytime = date; m_historyInfo.historytime = date;
m_filepath = QDir::homePath() + "/.cache/theme-build/" + m_historytime; m_historyInfo.filepath = QDir::homePath() + "/.cache/theme-build/" + m_historyInfo.historytime;
getWallpaper();
getAccentColor();
getRadius();
} }
QString HistoryInfoLoad::getCover() QString HistoryInfoLoad::getCover()
{ {
QString filePath = m_filepath + "/config/preview"; QString filePath = m_historyInfo.filepath + "/config/preview";
QString previewFilePath; QString previewFilePath;
QFileInfo pngFileInfo(filePath + ".png"); QFileInfo pngFileInfo(filePath + ".png");
@ -24,13 +31,13 @@ QString HistoryInfoLoad::getCover()
previewFilePath = nullptr; previewFilePath = nullptr;
} }
} }
m_coverpath = previewFilePath; m_historyInfo.coverpath = previewFilePath;
return m_coverpath; return m_historyInfo.coverpath;
} }
QString HistoryInfoLoad::getThemeName() QString HistoryInfoLoad::getThemeName()
{ {
QString filePath = m_filepath + "/debian/control"; QString filePath = m_historyInfo.filepath + "/debian/control";
QFile file(filePath); QFile file(filePath);
if (file.exists() && file.open(QIODevice::ReadOnly)) { if (file.exists() && file.open(QIODevice::ReadOnly)) {
@ -45,29 +52,122 @@ QString HistoryInfoLoad::getThemeName()
QString fieldValue = content.mid(startIndex).trimmed().split("\n").at(0); QString fieldValue = content.mid(startIndex).trimmed().split("\n").at(0);
qDebug() << "Source field value: " << fieldValue; qDebug() << "Source field value: " << fieldValue;
m_themename = fieldValue; m_historyInfo.themename = fieldValue;
} else { } else {
qDebug() << "No Source field found."; qDebug() << "No Source field found.";
} }
} else { } else {
qDebug() << "File not found or cannot open file."; qDebug() << "File not found or cannot open file.";
} }
return m_themename; return m_historyInfo.themename;
} }
QString HistoryInfoLoad::getThemeType() QString HistoryInfoLoad::getThemeType()
{ {
QString filePath = m_filepath; QString filePath = m_historyInfo.filepath;
QDir themeDir(filePath); QDir themeDir(filePath);
if (themeDir.exists("globalTheme")) { if (themeDir.exists("globalTheme")) {
m_themetype = "globalTheme"; m_historyInfo.themetype = "globalTheme";
} else { } else {
if (themeDir.exists("cursorTheme")) { if (themeDir.exists("cursorTheme")) {
m_themetype = "cursorTheme"; m_historyInfo.themetype = "cursorTheme";
} else if (themeDir.exists("iconTheme")) { } else if (themeDir.exists("iconTheme")) {
m_themetype = "iconTheme"; m_historyInfo.themetype = "iconTheme";
} }
} }
return m_themetype; return m_historyInfo.themetype;
} }
void HistoryInfoLoad::getRadius()
{
QString filePath = m_historyInfo.filepath + "/config/default.json";
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qDebug()<<"error"; // 返回一个空字符串表示获取失败
}
QByteArray jsonData = file.readAll();
file.close();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug()<<"jsonDoc is null";
}
QJsonObject rootObj = jsonDoc.object();
QJsonObject radiusObj = rootObj["Radius"].toObject();
int normalRadiusValue = radiusObj["Normal_Radius"].toObject()["value"].toInt();
m_historyInfo.radius = normalRadiusValue;
}
void HistoryInfoLoad::getWallpaper()
{
QString filePath = m_historyInfo.filepath + "/config/theme.conf";
// 读取文件内容
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qDebug() << "无法打开文件:" << filePath;
return;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
// 查找 wallPaperPath= 所在行的位置
int startIndex = content.indexOf("wallPaperPath=");
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("wallPaperPath=");
m_historyInfo.wallpaperpath = lineContent;
}
}
void HistoryInfoLoad::getAccentColor()
{
QString filePath = m_historyInfo.filepath + "/config/theme.conf";
// 读取文件内容
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qDebug() << "无法打开文件:" << filePath;
return;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
// 查找 wallPaperPath= 所在行的位置
int startIndex = content.indexOf("accent=");
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("accent=");
m_historyInfo.accentcolor = lineContent;
}
}
HistoryInfo HistoryInfoLoad::getInfoData()
{
qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath;
return m_historyInfo;
}

View File

@ -2,22 +2,40 @@
#define HISTORYINFOLOAD_H #define HISTORYINFOLOAD_H
#include <QObject> #include <QObject>
#include <QMetaType>
struct HistoryInfo {
bool isEdit = false;
QString filepath = "";
QString historytime = "";
QString coverpath = "";
QString themename = "";
QString themetype = "";
QString wallpaperpath = "";
QString accentcolor = "";
int radius = 6;
};
Q_DECLARE_METATYPE(HistoryInfo)
class HistoryInfoLoad : public QObject { class HistoryInfoLoad : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit HistoryInfoLoad(const QString& date, QObject* parent = nullptr); explicit HistoryInfoLoad(const QString& date, QObject* parent = nullptr);
QString getCover(); QString getCover();
QString getThemeName(); QString getThemeName();
QString getThemeType(); QString getThemeType();
void getRadius();
void getWallpaper();
void getAccentColor();
HistoryInfo getInfoData();
signals: signals:
private: private:
QString m_filepath = nullptr; HistoryInfo m_historyInfo;
QString m_historytime = nullptr;
QString m_coverpath = nullptr;
QString m_themename = nullptr;
QString m_themetype = nullptr;
}; };
#endif // HISTORYINFOLOAD_H #endif // HISTORYINFOLOAD_H

View File

@ -41,6 +41,8 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent)
connect(m_cursorthemewidget, &CursorThemeWidget::newTimeCursorMap, this, [&]( QMap<QString, QString> *timecursormaps) { connect(m_cursorthemewidget, &CursorThemeWidget::newTimeCursorMap, this, [&]( QMap<QString, QString> *timecursormaps) {
emit timeCursorMapChanged(timecursormaps); emit timeCursorMapChanged(timecursormaps);
}); });
} }
void MainInterface::init() void MainInterface::init()
@ -138,3 +140,18 @@ void MainInterface::setCursorTheme()
m_themestackedwidget->setCurrentIndex(2); m_themestackedwidget->setCurrentIndex(2);
m_cursorbtn->setChecked(true); m_cursorbtn->setChecked(true);
} }
void MainInterface::getThemeInfo(const HistoryInfo &InfoData)
{
if (InfoData.themetype == "globalTheme"){
setGlobalTheme();
//发送信号将info传入widget并且显示在widget
m_globalthemewidget->eidtInitWidget(InfoData);
}else if(InfoData.themetype == "cursorTheme"){
setCursorTheme();
}else if(InfoData.themetype == "iconTheme"){
setIconTheme();
}
}

View File

@ -8,6 +8,7 @@
#include "./module/infocreatewidget.h" #include "./module/infocreatewidget.h"
#include "titlebar.h" #include "titlebar.h"
#include "./module/cacheconfirmedwidget.h" #include "./module/cacheconfirmedwidget.h"
#include "./module/historywidget.h"
#include <QWidget> #include <QWidget>
#include <QPushButton> #include <QPushButton>
@ -31,6 +32,8 @@ public:
void setIconTheme(); void setIconTheme();
void setGlobalTheme(); void setGlobalTheme();
void setCursorTheme(); void setCursorTheme();
void getThemeInfo(const HistoryInfo &InfoData);
signals: signals:
void wallpaperupdate(const QString& filePath); void wallpaperupdate(const QString& filePath);
void wallpaperPathChanged(QString path); void wallpaperPathChanged(QString path);

View File

@ -124,6 +124,16 @@ void MainWindow::initUI()
buttonGroup->addButton(m_globalbtn); buttonGroup->addButton(m_globalbtn);
buttonGroup->addButton(m_iconbtn); buttonGroup->addButton(m_iconbtn);
buttonGroup->addButton(m_cursorbtn); buttonGroup->addButton(m_cursorbtn);
connect(m_historywidget,&HistoryWidget::startSecondEdit,[=](HistoryInfo InfoData){
m_stackedWidget->setCurrentWidget(m_maininterface);
m_bridge->createFileManager(true,InfoData.historytime);
m_maininterface->getThemeInfo(InfoData);
});
connect(buttonGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), [=](QAbstractButton* button) { connect(buttonGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), [=](QAbstractButton* button) {
m_stackedWidget->setCurrentWidget(m_maininterface); m_stackedWidget->setCurrentWidget(m_maininterface);
@ -131,17 +141,17 @@ void MainWindow::initUI()
m_maininterface->setGlobalTheme(); m_maininterface->setGlobalTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("globalTheme"), "recognise"); InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("globalTheme"), "recognise");
m_infoCreateWidget->show(); m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date); m_bridge->createFileManager(false,FileProcess::g_date);
} else if (button == m_iconbtn) { } else if (button == m_iconbtn) {
m_maininterface->setIconTheme(); m_maininterface->setIconTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("iconTheme"), "recognise"); InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("iconTheme"), "recognise");
m_infoCreateWidget->show(); m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date); m_bridge->createFileManager(false,FileProcess::g_date);
} else if (button == m_cursorbtn) { } else if (button == m_cursorbtn) {
m_maininterface->setCursorTheme(); m_maininterface->setCursorTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("cursorTheme"), "recognise"); InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("cursorTheme"), "recognise");
m_infoCreateWidget->show(); m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date); m_bridge->createFileManager(false,FileProcess::g_date);
} }
if (m_historywidget == nullptr) { if (m_historywidget == nullptr) {
m_historywidget = new HistoryWidget(); m_historywidget = new HistoryWidget();

View File

@ -51,6 +51,8 @@ public:
public slots: public slots:
void onGoHomeClicked(); void onGoHomeClicked();
signals:
void startSecondEdit(const HistoryInfo &InfoData);
private: private:
HistoryWidget *m_historywidget; HistoryWidget *m_historywidget;
@ -77,7 +79,7 @@ private:
TitleBar*m_titlebar; TitleBar*m_titlebar;
QPoint m_dragStartPosition; QPoint m_dragStartPosition;
QPoint m_dragPosition; QPoint m_dragPosition;
HistoryInfo *m_infodata;
QWidget *m_guideWidget; QWidget *m_guideWidget;
bool m_isHistoryDirUpdated = false; bool m_isHistoryDirUpdated = false;
}; };

View File

@ -16,6 +16,14 @@ QString GlobalThemeWidget::getWallpaperPath()
return m_wallpaperpath; return m_wallpaperpath;
} }
void GlobalThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
{
m_info = InfoData;
m_info.isEdit = true;
this->setRadiusSetting(m_info.radius);
this->update();
}
void GlobalThemeWidget::initPreviewWidget() void GlobalThemeWidget::initPreviewWidget()
{ {
m_previewwidget = new QWidget(this); m_previewwidget = new QWidget(this);
@ -75,7 +83,12 @@ void GlobalThemeWidget::initCoverWidget()
m_coverwidget = new QWidget(m_viewportwidget); m_coverwidget = new QWidget(m_viewportwidget);
m_coverwidget->setFixedHeight(182); m_coverwidget->setFixedHeight(182);
QLabel *title = new QLabel(m_coverwidget); QLabel *title = new QLabel(m_coverwidget);
title->setText("全局主题效果图"); if(m_info.isEdit){
title->setText("111111111111111111111111");
}else{
title->setText("全局主题效果图");
}
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
QWidget *cover = new QWidget(m_coverwidget); QWidget *cover = new QWidget(m_coverwidget);
@ -304,3 +317,8 @@ void GlobalThemeWidget::addspaceritem()
m_previewlayout->addWidget(m_preview); m_previewlayout->addWidget(m_preview);
m_previewlayout->addItem(spacer2); m_previewlayout->addItem(spacer2);
} }
void GlobalThemeWidget::setRadiusSetting(int radius)
{
}

View File

@ -13,7 +13,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QStackedWidget> #include <QStackedWidget>
#include <QComboBox> #include <QComboBox>
#include "historywidget.h"
class GlobalThemeWidget : public QWidget class GlobalThemeWidget : public QWidget
{ {
@ -21,6 +21,8 @@ class GlobalThemeWidget : public QWidget
public: public:
explicit GlobalThemeWidget(QWidget *parent = nullptr); explicit GlobalThemeWidget(QWidget *parent = nullptr);
QString getWallpaperPath(); QString getWallpaperPath();
void eidtInitWidget(const HistoryInfo &InfoData);
signals: signals:
void wallpaperupdate(const QString& filePath); void wallpaperupdate(const QString& filePath);
void newWallpaperFilePath(const QString& path); void newWallpaperFilePath(const QString& path);
@ -40,6 +42,7 @@ private:
void updateWallpaperFilePath(const QString& coverFilePath); void updateWallpaperFilePath(const QString& coverFilePath);
void addspaceritem(); void addspaceritem();
void setRadiusSetting(int radius);
QWidget *m_globalthemewidget; QWidget *m_globalthemewidget;
QWidget *m_coverwidget; QWidget *m_coverwidget;
QWidget *m_wallpaperwidget; QWidget *m_wallpaperwidget;
@ -54,7 +57,7 @@ private:
QHBoxLayout *m_globalthemelayout; QHBoxLayout *m_globalthemelayout;
QWidget *m_rightwidget; QWidget *m_rightwidget;
HistoryInfo m_info;
QWidget *m_previewwidget; QWidget *m_previewwidget;
GlobalImageWidget *m_preview; GlobalImageWidget *m_preview;

View File

@ -52,6 +52,10 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
button->setThemeName(info->getThemeName()); button->setThemeName(info->getThemeName());
button->setThemeType(info->getThemeType()); button->setThemeType(info->getThemeType());
button->initUI(); button->initUI();
connect(button,&HistoryButton::clicked,this,[=](){
emit startSecondEdit(info->getInfoData());
});
layout->addWidget(button, row, col); layout->addWidget(button, row, col);
col++; col++;
if (col == 4) { if (col == 4) {

View File

@ -11,6 +11,7 @@
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QMouseEvent> #include <QMouseEvent>
#include "../fileProcess/historyinfoload.h"
class HistoryButton : public QPushButton class HistoryButton : public QPushButton
{ {
@ -22,8 +23,6 @@ public:
void setThemeName(const QString &themeName); void setThemeName(const QString &themeName);
void setThemeType(const QString &themeType); void setThemeType(const QString &themeType);
void initUI(); void initUI();
// void showContextMenu();
// void mousePressEvent(QMouseEvent* event);
signals: signals:
void updateHistoryRequested(); void updateHistoryRequested();
private: private:
@ -46,7 +45,7 @@ public slots:
signals: signals:
void startSecondEdit(const HistoryInfo &InfoData);
}; };
#endif // HISTORYWIDGET_H #endif // HISTORYWIDGET_H