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);
}
void Bridge::createFileManager(QString time)
void Bridge::createFileManager(bool ishistory,QString time)
{
m_time = time;
m_configfilemanager = new ConfigFileManager(time);
m_configfilemanager = new ConfigFileManager(ishistory,time);
createDir();
}

View File

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

View File

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

View File

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

View File

@ -2,15 +2,22 @@
#include <QDebug>
#include <QFileInfo>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
{
m_historytime = date;
m_filepath = QDir::homePath() + "/.cache/theme-build/" + m_historytime;
m_historyInfo.historytime = date;
m_historyInfo.filepath = QDir::homePath() + "/.cache/theme-build/" + m_historyInfo.historytime;
getWallpaper();
getAccentColor();
getRadius();
}
QString HistoryInfoLoad::getCover()
{
QString filePath = m_filepath + "/config/preview";
QString filePath = m_historyInfo.filepath + "/config/preview";
QString previewFilePath;
QFileInfo pngFileInfo(filePath + ".png");
@ -24,13 +31,13 @@ QString HistoryInfoLoad::getCover()
previewFilePath = nullptr;
}
}
m_coverpath = previewFilePath;
return m_coverpath;
m_historyInfo.coverpath = previewFilePath;
return m_historyInfo.coverpath;
}
QString HistoryInfoLoad::getThemeName()
{
QString filePath = m_filepath + "/debian/control";
QString filePath = m_historyInfo.filepath + "/debian/control";
QFile file(filePath);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
@ -45,29 +52,122 @@ QString HistoryInfoLoad::getThemeName()
QString fieldValue = content.mid(startIndex).trimmed().split("\n").at(0);
qDebug() << "Source field value: " << fieldValue;
m_themename = fieldValue;
m_historyInfo.themename = fieldValue;
} else {
qDebug() << "No Source field found.";
}
} else {
qDebug() << "File not found or cannot open file.";
}
return m_themename;
return m_historyInfo.themename;
}
QString HistoryInfoLoad::getThemeType()
{
QString filePath = m_filepath;
QString filePath = m_historyInfo.filepath;
QDir themeDir(filePath);
if (themeDir.exists("globalTheme")) {
m_themetype = "globalTheme";
m_historyInfo.themetype = "globalTheme";
} else {
if (themeDir.exists("cursorTheme")) {
m_themetype = "cursorTheme";
m_historyInfo.themetype = "cursorTheme";
} 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
#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 {
Q_OBJECT
public:
explicit HistoryInfoLoad(const QString& date, QObject* parent = nullptr);
QString getCover();
QString getThemeName();
QString getThemeType();
void getRadius();
void getWallpaper();
void getAccentColor();
HistoryInfo getInfoData();
signals:
private:
QString m_filepath = nullptr;
QString m_historytime = nullptr;
QString m_coverpath = nullptr;
QString m_themename = nullptr;
QString m_themetype = nullptr;
HistoryInfo m_historyInfo;
};
#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) {
emit timeCursorMapChanged(timecursormaps);
});
}
void MainInterface::init()
@ -138,3 +140,18 @@ void MainInterface::setCursorTheme()
m_themestackedwidget->setCurrentIndex(2);
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 "titlebar.h"
#include "./module/cacheconfirmedwidget.h"
#include "./module/historywidget.h"
#include <QWidget>
#include <QPushButton>
@ -31,6 +32,8 @@ public:
void setIconTheme();
void setGlobalTheme();
void setCursorTheme();
void getThemeInfo(const HistoryInfo &InfoData);
signals:
void wallpaperupdate(const QString& filePath);
void wallpaperPathChanged(QString path);

View File

@ -124,6 +124,16 @@ void MainWindow::initUI()
buttonGroup->addButton(m_globalbtn);
buttonGroup->addButton(m_iconbtn);
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) {
m_stackedWidget->setCurrentWidget(m_maininterface);
@ -131,17 +141,17 @@ void MainWindow::initUI()
m_maininterface->setGlobalTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("globalTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->createFileManager(false,FileProcess::g_date);
} else if (button == m_iconbtn) {
m_maininterface->setIconTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("iconTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->createFileManager(false,FileProcess::g_date);
} else if (button == m_cursorbtn) {
m_maininterface->setCursorTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("cursorTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->createFileManager(false,FileProcess::g_date);
}
if (m_historywidget == nullptr) {
m_historywidget = new HistoryWidget();

View File

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

View File

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

View File

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

View File

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

View File

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