!31 add update some history info

Merge pull request !31 from likehomedream/my-2.0-devel
This commit is contained in:
KevinDuan 2023-10-12 06:27:14 +00:00 committed by Gitee
commit d9e2c8cf08
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 105 additions and 54 deletions

View File

@ -102,6 +102,7 @@ void Bridge::createFileManager(bool ishistory,QString time)
m_time = time;
m_configfilemanager = new ConfigFileManager(ishistory,time);
createDir();
connect(m_configfilemanager,&ConfigFileManager::updateInfo,this,&Bridge::updateInfo);
}
void Bridge::createDir()

View File

@ -27,7 +27,7 @@ public:
void startCopy();
signals:
void updateInfo();
private:
Bridge(QObject *parent = nullptr);
QString m_time;

View File

@ -1,4 +1,5 @@
#include "configfilemanager.h"
#include "historyinfoload.h"
ConfigFileManager::ConfigFileManager(bool ishistory, const QString& time, QObject *parent) : QObject(parent)
{
@ -99,7 +100,7 @@ bool ConfigFileManager::modifyRadiusJson(int radius)
configFile.close();
qDebug() << "Config file updated successfully";
emit updateInfo();
}
@ -132,6 +133,7 @@ bool ConfigFileManager::modifyAccentColorConf(QColor accentcolor)
QTextStream out(&file);
out << content;
file.close();
emit updateInfo();
return true;
} else {
qDebug() << "无法写入文件:" << confFilePath;
@ -167,6 +169,7 @@ bool ConfigFileManager::modifyWallPaperConf(QString wallpaperpath)
QTextStream out(&file);
out << content;
file.close();
emit updateInfo();
return true;
} else {
qDebug() << "无法写入文件:" << confFilePath;
@ -243,7 +246,7 @@ void ConfigFileManager::copyCovertoCacheDir(const QString &destinationFilePath,
qDebug() << "Failed to copy file";
return;
}
emit updateInfo();
qDebug() << "File copied successfully";
}

View File

@ -30,6 +30,7 @@ public:
void copyCovertoCacheDir(const QString& destinationFilePath,QDir cachedir);
signals:
void updateInfo();
private:
QString m_time;
QString jsonFilePath;

View File

@ -84,8 +84,9 @@ void HistoryInfoLoad::getRadius()
QString filePath = m_historyInfo.filepath + "/config/default.json";
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
qDebug()<<"error"; // 返回一个空字符串表示获取失败
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Error opening file";
return;
}
QByteArray jsonData = file.readAll();
@ -93,13 +94,18 @@ void HistoryInfoLoad::getRadius()
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug()<<"jsonDoc is null";
qDebug() << "jsonDoc is null";
return;
}
QJsonObject rootObj = jsonDoc.object();
QJsonObject radiusObj = rootObj["Radius"].toObject();
int normalRadiusValue = radiusObj["Normal_Radius"].toObject()["value"].toInt();
m_historyInfo.radius = normalRadiusValue;
qDebug() << "Normal_Radius value:" << radiusObj["Normal_Radius"].toObject()["value"];
qDebug() << "radiusObj:" << radiusObj;
qDebug() << "Normal_Radius value type:" << radiusObj["Normal_Radius"].toObject()["value"].type();
QString normalRadiusValue = radiusObj["Normal_Radius"].toObject()["value"].toString();
m_historyInfo.radius = normalRadiusValue.toInt();
}
void HistoryInfoLoad::getWallpaper()
@ -171,3 +177,13 @@ HistoryInfo HistoryInfoLoad::getInfoData()
return m_historyInfo;
}
void HistoryInfoLoad::updateHistoryInfo()
{
getCover();
getThemeName();
getThemeType();
getRadius();
getWallpaper();
getAccentColor();
}

View File

@ -31,7 +31,7 @@ public:
void getWallpaper();
void getAccentColor();
HistoryInfo getInfoData();
void updateHistoryInfo();
signals:
private:

View File

@ -29,7 +29,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_maininterface, &MainInterface::cursorMapChanged, m_bridge, &Bridge::cursorMapChanged);
connect(m_maininterface, &MainInterface::timeCursorMapChanged, m_bridge, &Bridge::timeCursorMapChanged);
connect(m_maininterface, &MainInterface::startCopy, m_bridge, &Bridge::startCopy);
connect(m_bridge,&Bridge::updateInfo,m_historywidget,&HistoryWidget::updateInfo);
}
MainWindow::~MainWindow()
@ -82,7 +82,6 @@ void MainWindow::initUI()
m_historywidget = new HistoryWidget();
m_historywidget->setMinimumHeight(2000);
QDir builderDir = QDir::homePath()+"/.cache/theme-build/";
if(!builderDir.exists()|| builderDir.isEmpty()){
alllayout->addStretch(1);

View File

@ -21,7 +21,10 @@ void GlobalThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
m_info = InfoData;
m_info.isEdit = true;
this->setRadiusSetting(m_info.radius);
this->update();
this->setAccentColor(m_info.accentcolor);
this->setCover(m_info.coverpath);
this->setWallpaper(m_info.wallpaperpath);
// this->update();
}
void GlobalThemeWidget::initPreviewWidget()
@ -94,21 +97,21 @@ void GlobalThemeWidget::initCoverWidget()
QWidget *cover = new QWidget(m_coverwidget);
cover->setFixedHeight(160);
QHBoxLayout *coverlayout = new QHBoxLayout(cover);
QPushButton *coverbtn = new QPushButton(cover);
coverbtn->setFixedSize(160,100);
m_coverbtn = new QPushButton(cover);
m_coverbtn->setFixedSize(160,100);
QLabel *tip = new QLabel(cover);
QPixmap pixmap(m_coverpath);
coverbtn->setIcon(QIcon(pixmap));
coverbtn->setIconSize(coverbtn->size());
m_coverbtn->setIcon(QIcon(pixmap));
m_coverbtn->setIconSize(m_coverbtn->size());
tip->setText("<html>尺寸1640*1080<br>大小:不超过 5 MB<br>格式PNG</html>");
coverlayout->addWidget(coverbtn);
coverlayout->addWidget(m_coverbtn);
coverlayout->addWidget(tip);
cover->setLayout(coverlayout);
connect(coverbtn, &QPushButton::clicked, this, [=]() {
connect(m_coverbtn, &QPushButton::clicked, this, [=]() {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
bool legalFile = FileCheck::isLegalWallPaperFile(newFilePath,"cover");
@ -117,8 +120,8 @@ void GlobalThemeWidget::initCoverWidget()
}
m_coverpath = newFilePath;
coverbtn->setIcon(QIcon(m_coverpath));
coverbtn->setIconSize(coverbtn->size());
m_coverbtn->setIcon(QIcon(m_coverpath));
m_coverbtn->setIconSize(m_coverbtn->size());
emit newCoverFilePath(newFilePath);
});
@ -141,20 +144,20 @@ void GlobalThemeWidget::initWallPaperWidget()
QWidget *cover = new QWidget(m_wallpaperwidget);
cover->setFixedHeight(160);
QHBoxLayout *coverlayout = new QHBoxLayout(cover);
QPushButton *coverbtn = new QPushButton(cover);
coverbtn->setFixedSize(160,100);
wallpaperbtn = new QPushButton(cover);
wallpaperbtn->setFixedSize(160,100);
QLabel *tip = new QLabel(cover);
tip->setText("<html>尺寸3840*2160<br>大小:不超过 10 MB<br>格式PNG</html>");
coverlayout->addWidget(coverbtn);
coverlayout->addWidget(wallpaperbtn);
coverlayout->addWidget(tip);
cover->setLayout(coverlayout);
QPixmap pixmap(m_wallpaperpath);
coverbtn->setIcon(QIcon(pixmap));
coverbtn->setIconSize(coverbtn->size());
wallpaperbtn->setIcon(QIcon(pixmap));
wallpaperbtn->setIconSize(wallpaperbtn->size());
connect(coverbtn, &QPushButton::clicked, this, [=]() {
connect(wallpaperbtn, &QPushButton::clicked, this, [=]() {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
if (!newFilePath.isEmpty() && FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")) {
@ -163,8 +166,8 @@ void GlobalThemeWidget::initWallPaperWidget()
emit newWallpaperFilePath(newFilePath);
QPixmap pixmap(newFilePath);
coverbtn->setIcon(QIcon(pixmap));
coverbtn->setIconSize(coverbtn->size());
wallpaperbtn->setIcon(QIcon(pixmap));
wallpaperbtn->setIconSize(wallpaperbtn->size());
} else {
qDebug() << "Selected file path:" << newFilePath;
updateWallpaperFilePath(m_wallpaperpath);
@ -220,24 +223,24 @@ void GlobalThemeWidget::initFilletWidget()
title->setFixedWidth(m_filletwidget->width());
title->setText("控件圆角");
QHBoxLayout *layout = new QHBoxLayout();
QSlider *filletslider = new QSlider(m_filletwidget);
m_filletslider = new QSlider(m_filletwidget);
filletslider->setOrientation(Qt::Horizontal);
filletslider->setFixedWidth(210);
filletslider->setRange(0,18);
filletslider->setSingleStep(1);
filletslider->setTickInterval(1);
filletslider->setFixedWidth(120);
filletslider->setValue(6);
m_filletslider->setOrientation(Qt::Horizontal);
m_filletslider->setFixedWidth(210);
m_filletslider->setRange(0,18);
m_filletslider->setSingleStep(1);
m_filletslider->setTickInterval(1);
m_filletslider->setFixedWidth(120);
m_filletslider->setValue(6);
QPushButton *showButton = new QPushButton(m_filletwidget);
showButton->setDisabled(true);
showButton->setFixedSize(60,36);
int value = 0;
value = filletslider->value();
showButton->setText(QString::number(filletslider->value())+"px");
value = m_filletslider->value();
showButton->setText(QString::number(m_filletslider->value())+"px");
QObject::connect(filletslider, &QSlider::valueChanged, [=](int value) {
QObject::connect(m_filletslider, &QSlider::valueChanged, [=](int value) {
showButton->setText(QString::number(value)+"px");
m_preview->updatescale();
m_preview->updateWidgetRadius(value);
@ -246,7 +249,7 @@ void GlobalThemeWidget::initFilletWidget()
layout->addWidget(title);
layout->addStretch(1);
layout->addWidget(filletslider);
layout->addWidget(m_filletslider);
layout->addWidget(showButton);
m_filletwidget->setLayout(layout);
@ -261,18 +264,18 @@ void GlobalThemeWidget::AccentColorWidget()
title->setFixedWidth(m_accentcolorwidget->width());
title->setText("强调色");
QHBoxLayout *layout = new QHBoxLayout();
QComboBox *combobox = new QComboBox(m_accentcolorwidget);
combobox->addItem("daybreakBlue",QColor(55, 144, 250));
combobox->addItem("jamPurple", QColor(120, 115, 245));
combobox->addItem("magenta", QColor(235, 48, 150));
combobox->addItem("sunRed", QColor(243, 34, 45));
combobox->addItem("sunsetOrange", QColor(246, 140, 39));
combobox->addItem("dustGold", QColor(249, 197, 61));
combobox->addItem("polarGreen", QColor(82, 196, 41));
m_combobox = new QComboBox(m_accentcolorwidget);
m_combobox->addItem("daybreakBlue",QColor(55, 144, 250));
m_combobox->addItem("jamPurple", QColor(120, 115, 245));
m_combobox->addItem("magenta", QColor(235, 48, 150));
m_combobox->addItem("sunRed", QColor(243, 34, 45));
m_combobox->addItem("sunsetOrange", QColor(246, 140, 39));
m_combobox->addItem("dustGold", QColor(249, 197, 61));
m_combobox->addItem("polarGreen", QColor(82, 196, 41));
connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
connect(m_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
QColor selectedColor = combobox->itemData(index).value<QColor>();
QColor selectedColor = m_combobox->itemData(index).value<QColor>();
qDebug() << "Selected color:" << selectedColor;
@ -283,7 +286,7 @@ void GlobalThemeWidget::AccentColorWidget()
});
layout->addWidget(title);
layout->addWidget(combobox);
layout->addWidget(m_combobox);
m_accentcolorwidget->setLayout(layout);
}
@ -320,5 +323,26 @@ void GlobalThemeWidget::addspaceritem()
void GlobalThemeWidget::setRadiusSetting(int radius)
{
m_filletslider->setValue(radius);
}
void GlobalThemeWidget::setAccentColor(QString accentcolor)
{
QColor color;
color.setNamedColor(accentcolor);
int index = m_combobox->findData(color);
if (index != -1) {
m_combobox->setCurrentIndex(index);
}
}
void GlobalThemeWidget::setCover(QString coverpath)
{
m_coverbtn->setIcon(QIcon(coverpath));
}
void GlobalThemeWidget::setWallpaper(QString wallpaperpath)
{
wallpaperbtn->setIcon(QIcon(wallpaperpath));
}

View File

@ -43,6 +43,9 @@ private:
void addspaceritem();
void setRadiusSetting(int radius);
void setAccentColor(QString accentcolor);
void setCover(QString coverpath);
void setWallpaper(QString wallpaperpath);
QWidget *m_globalthemewidget;
QWidget *m_coverwidget;
QWidget *m_wallpaperwidget;
@ -54,11 +57,13 @@ private:
QString m_coverpath = ":/resource/background/background-glazing.png";
QWidget *m_viewportwidget;
QScrollArea *m_scrollArea;
QSlider *m_filletslider;
QHBoxLayout *m_globalthemelayout;
QWidget *m_rightwidget;
HistoryInfo m_info;
QComboBox *m_combobox;
QPushButton *m_coverbtn;
QPushButton *wallpaperbtn;
QWidget *m_previewwidget;
GlobalImageWidget *m_preview;
};

View File

@ -62,6 +62,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
col = 0;
row++;
}
connect(this,&HistoryWidget::updateInfo,info,&HistoryInfoLoad::updateHistoryInfo);
}
QWidget *widget = new QWidget(this);

View File

@ -46,6 +46,7 @@ public slots:
signals:
void startSecondEdit(const HistoryInfo &InfoData);
void updateInfo();
};
#endif // HISTORYWIDGET_H