!76 fix QSlider error
Merge pull request !76 from likehomedream/plymouthshow
This commit is contained in:
commit
89bc702f4c
|
@ -54,7 +54,6 @@
|
|||
<file>resource/background/homepage-global.png</file>
|
||||
<file>resource/background/homepage-icons.png</file>
|
||||
<file>resource/systemicons/kylin-settings-commoninfo.png</file>
|
||||
<file>resource/config/defualt.json</file>
|
||||
<file>resource/config/theme.conf</file>
|
||||
<file>resource/debian/rules</file>
|
||||
<file>resource/debian/copyright</file>
|
||||
|
@ -227,5 +226,6 @@
|
|||
<file>resource/background/custom-preview.png</file>
|
||||
<file>resource/background/1-openkylin.jpg</file>
|
||||
<file>resource/background/grub-background.png</file>
|
||||
<file>resource/config/json.txt</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -35,7 +35,7 @@ void Bridge::coverPathChanged(QString path)
|
|||
void Bridge::radiusChanged(int radius)
|
||||
{
|
||||
m_configfilemanager->modifyRadiusJson(radius,QDir::homePath() + "/.cache/theme-build/"
|
||||
+m_time + "/src/globalTheme/default.json");
|
||||
+m_time + "/src/globalTheme/json.txt");
|
||||
}
|
||||
|
||||
void Bridge::accentColorChanged(QColor accentcolor)
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QtMath>
|
||||
#include <QRegularExpression>
|
||||
#include <QBuffer>
|
||||
#include <QFileInfoList>
|
||||
|
||||
ConfigFileManager::ConfigFileManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
@ -25,14 +28,14 @@ ConfigFileManager::ConfigFileManager(QObject *parent) : QObject(parent)
|
|||
bool ConfigFileManager::createJson(QDir cachedir)
|
||||
{
|
||||
QString m_themePath = cachedir.absolutePath();
|
||||
QString filePath = m_themePath + "/default.json";
|
||||
QString filePath = m_themePath + "/json.txt";
|
||||
|
||||
QDir dir;
|
||||
if (!dir.exists(m_themePath)) {
|
||||
dir.mkpath(m_themePath);
|
||||
}
|
||||
|
||||
if (copyFileContent(":/resource/config/defualt.json", filePath)) {
|
||||
if (copyFileContent(":/resource/config/json.txt", filePath)) {
|
||||
// 成功将文件内容写入目标文件中
|
||||
return true;
|
||||
} else {
|
||||
|
@ -81,43 +84,39 @@ bool ConfigFileManager::createConf(QDir cachedir)
|
|||
*/
|
||||
bool ConfigFileManager::modifyRadiusJson(int radius,QString jsonFilePath)
|
||||
{
|
||||
QString confFilePath = jsonFilePath;
|
||||
|
||||
// 读取配置文件
|
||||
QFile configFile(confFilePath);
|
||||
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text))
|
||||
{
|
||||
qDebug() << "Failed to open config file"<<configFile.AbortError<<confFilePath;
|
||||
// 读取文件内容
|
||||
QFile file(jsonFilePath);
|
||||
if (!file.open(QIODevice::ReadWrite| QIODevice::Text)) {
|
||||
qDebug() << "Failed to open file for reading";
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray data = configFile.readAll();
|
||||
configFile.close();
|
||||
QTextStream in(&file);
|
||||
QString content = in.readAll();
|
||||
file.close();
|
||||
|
||||
// 解析JSON
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
qDebug() << "Failed to parse JSON:" << error.errorString();
|
||||
// 使用正则表达式进行替换
|
||||
QRegularExpression regexMax(R"("Max_Radius"\s*:\s*{"value"\s*:\s*"\d+"\s*,\s*"type"\s*:\s*"int"\s*})");
|
||||
content.replace(regexMax, "\"Max_Radius\" : {\"value\": \"" + QString::number(radius) + "\", \"type\": \"int\"}");
|
||||
|
||||
QRegularExpression regexNormal(R"("Normal_Radius"\s*:\s*{"value"\s*:\s*"\d+"\s*,\s*"type"\s*:\s*"int"\s*})");
|
||||
content.replace(regexNormal, "\"Normal_Radius\" : {\"value\": \"" + QString::number(radius) + "\", \"type\": \"int\"}");
|
||||
|
||||
QRegularExpression regexMin(R"("Min_Radius"\s*:\s*{"value"\s*:\s*"\d+"\s*,\s*"type"\s*:\s*"int"\s*})");
|
||||
content.replace(regexMin, "\"Min_Radius\" : {\"value\": \"" + QString::number(radius) + "\", \"type\": \"int\"}");
|
||||
|
||||
qDebug()<<QString::number(radius);
|
||||
// 写回文件
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
qDebug() << "Failed to open file for writing";
|
||||
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;
|
||||
QTextStream out(&file);
|
||||
out << content;
|
||||
file.close();
|
||||
|
||||
// 保存修改后的配置文件
|
||||
configFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
configFile.write(QJsonDocument(jsonObj).toJson());
|
||||
configFile.close();
|
||||
return true;
|
||||
|
||||
qDebug() << "Config file updated successfully";
|
||||
emit updateInfo();
|
||||
|
@ -574,7 +573,12 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD
|
|||
//ffmpeg -i "111.mp4" -vframes 104 "/home/.cache/theme-build/m_time/src/plymouthTheme/%d.png"
|
||||
//FIX ME :限制条件
|
||||
QString cache = cachedir.absolutePath()+"/%d.png";
|
||||
list<<"-i"<<destinationFilePath<<"-vframes"<<"104"<<cache;
|
||||
list<<"-i"<<destinationFilePath
|
||||
<<"-vf"
|
||||
<<"scale='min(100,iw)':min'(100,ih)':force_original_aspect_ratio=decrease"
|
||||
<<"-vframes"
|
||||
<<"104"
|
||||
<<cache;
|
||||
|
||||
QProcess p;
|
||||
p.start("ffmpeg",list);
|
||||
|
@ -586,42 +590,10 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD
|
|||
qWarning()<<"wait video image too long time.";
|
||||
}
|
||||
QString err=p.readAllStandardError();
|
||||
QString read=p.readAll();
|
||||
if (err.contains("not contain any stream")) {
|
||||
qWarning()<<"get video image failed.";
|
||||
}
|
||||
|
||||
// // 处理所有PNG文件大小
|
||||
// QDirIterator it(cachedir.absolutePath(), QStringList() << "*.png", QDir::Files, QDirIterator::Subdirectories);
|
||||
// while (it.hasNext()) {
|
||||
// QString filePath = it.next();
|
||||
|
||||
// QFile file(filePath);
|
||||
// if (file.open(QIODevice::ReadOnly))
|
||||
// {
|
||||
// QByteArray imageData = file.readAll();
|
||||
// file.close();
|
||||
|
||||
// int maxSize = 17500; // 最大文件大小为17.5KB
|
||||
|
||||
// if (imageData.size() > maxSize)
|
||||
// {
|
||||
// QImage image;
|
||||
// image.loadFromData(imageData);
|
||||
|
||||
// // 按比例缩小图片尺寸
|
||||
// qreal scale = qSqrt(static_cast<qreal>(maxSize) / imageData.size());
|
||||
// QSize newSize = image.size() * scale;
|
||||
// image = image.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
// // 保存为PNG文件
|
||||
// QPixmap pixmap = QPixmap::fromImage(image);
|
||||
// pixmap.save(filePath, "PNG");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
QString thunbnail = cachedir.absolutePath()+"/40.png";
|
||||
emit updateThumbnail(thunbnail);
|
||||
}
|
||||
|
|
|
@ -51,3 +51,41 @@ bool FileCheck::isLegalWallPaperFile(const QString& filePath, const QString& typ
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileCheck::isLegalMP4File(const QString &filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
if (!fileInfo.exists() || !fileInfo.isFile() || fileInfo.suffix().toLower() != "mp4") {
|
||||
return false;
|
||||
}
|
||||
|
||||
qint64 fileSize = fileInfo.size(); // 文件大小,单位为 Bytes
|
||||
qint64 maxSize = 1024 * 1024 *10;
|
||||
|
||||
if (fileSize > maxSize) {
|
||||
QMessageBox::information(nullptr, tr("error"), tr("The file size cannot exceed 1MB"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileCheck::isLegalPlymouthPicFile(const QString &filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
if (!fileInfo.exists() || !fileInfo.isFile() || fileInfo.suffix().toLower() != "png") {
|
||||
return false;
|
||||
}
|
||||
|
||||
qint64 fileSize = fileInfo.size(); // 文件大小,单位为 Bytes
|
||||
qint64 maxSize = 1024 * 20;
|
||||
|
||||
if (fileSize > maxSize) {
|
||||
QMessageBox::information(nullptr, tr("error"), tr("The file size cannot exceed 20KB"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ public:
|
|||
explicit FileCheck(QObject *parent = nullptr);
|
||||
static bool isLegalIconFile(const QString& filePath);
|
||||
static bool isLegalWallPaperFile(const QString& filePath, const QString& type);
|
||||
static bool isLegalMP4File(const QString& filePath, const QString& type);
|
||||
static bool isLegalMP4File(const QString& filePath);
|
||||
static bool isLegalPlymouthPicFile(const QString& filePath);
|
||||
|
||||
signals:
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ QString HistoryInfoLoad::getThemeType()
|
|||
*/
|
||||
void HistoryInfoLoad::getRadius()
|
||||
{
|
||||
QString filePath = m_historyInfo.filepath + "/src/globalTheme/default.json";
|
||||
QString filePath = m_historyInfo.filepath + "/src/globalTheme/json.txt";
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
|
|
|
@ -27,9 +27,10 @@ PlymouthImageWidget::PlymouthImageWidget(QWidget *parent)
|
|||
for (int i = 1; i <= 104; ++i) {
|
||||
pixmaps.append(QPixmap(QString(":/resource/plymouth/%1.png").arg(i)));
|
||||
}
|
||||
QPixmap pixmap(":/resource/plymouth/%1.png");
|
||||
QPixmap pixmap(":/resource/plymouth/1.png");
|
||||
pixmapItem = new QGraphicsPixmapItem(pixmaps.first());
|
||||
qreal x = (scene->width() - pixmap.width()) / 2;
|
||||
qDebug()<<"x= "<<x<<"scene->width()"<<scene->width()<<" pixmap.width()" << pixmap.width();
|
||||
qreal y = (scene->height() - pixmap.height()) / 2;
|
||||
sceneWidth = scene->width();
|
||||
sceneHeight = scene->height();
|
||||
|
|
|
@ -108,23 +108,31 @@ void PlymouthThemeWidget::initEditWidget()
|
|||
if(pic->isChecked()){
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select Png file"), "", tr("Png file (*.png)"));
|
||||
if (!newFilePath.isEmpty()) {
|
||||
QPixmap pixmap(newFilePath);
|
||||
pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio);
|
||||
m_customLabel->setPixmap(pixmap);
|
||||
emit newPlymouthFilePath(newFilePath);
|
||||
if(FileCheck::isLegalPlymouthPicFile(newFilePath)){
|
||||
QPixmap pixmap(newFilePath);
|
||||
pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio);
|
||||
m_customLabel->setPixmap(pixmap);
|
||||
emit newPlymouthFilePath(newFilePath);
|
||||
|
||||
g_themeChange = true;
|
||||
g_themeChange = true;
|
||||
} else{
|
||||
qDebug()<<"plumouth icon is error";
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select MP4 file"), "", tr("MP4 file (*.mp4)"));
|
||||
if (!newFilePath.isEmpty()) {
|
||||
QPixmap pixmap(newFilePath);
|
||||
pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio);
|
||||
m_customLabel->setPixmap(pixmap);
|
||||
emit newPlymouthFilePath(newFilePath);
|
||||
if(FileCheck::isLegalMP4File(newFilePath)){
|
||||
QPixmap pixmap(newFilePath);
|
||||
pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio);
|
||||
m_customLabel->setPixmap(pixmap);
|
||||
emit newPlymouthFilePath(newFilePath);
|
||||
|
||||
g_themeChange = true;
|
||||
g_themeChange = true;
|
||||
} else{
|
||||
qDebug()<<"plumouth icon is error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "iconwidgetfeature.h"
|
||||
#include "historywidget.h"
|
||||
#include "basewidget.h"
|
||||
#include "../fileProcess/filecheck.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
|
|
@ -29,21 +29,25 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent)
|
|||
m_gohomebtn = new QPushButton();
|
||||
m_gohomebtn->setFixedSize(30,30);
|
||||
m_gohomebtn->setIcon(QIcon::fromTheme("go-home-symbolic"));
|
||||
m_gohomebtn->setToolTip(tr("Return"));
|
||||
m_gohomebtn->setFlat(true);
|
||||
|
||||
m_minimumbtn = new QPushButton();
|
||||
m_minimumbtn->setFixedSize(30,30);
|
||||
m_minimumbtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
|
||||
m_minimumbtn->setToolTip(tr("Minimize"));
|
||||
m_minimumbtn->setFlat(true);
|
||||
|
||||
m_maximumbtn = new QPushButton();
|
||||
m_maximumbtn->setFixedSize(30,30);
|
||||
m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
|
||||
m_maximumbtn->setToolTip(tr("Maximize"));
|
||||
m_maximumbtn->setFlat(true);
|
||||
|
||||
m_closebtn = new QPushButton();
|
||||
m_closebtn->setFixedSize(30, 30);
|
||||
m_closebtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
|
||||
m_closebtn->setToolTip(tr("Close"));
|
||||
m_closebtn->setFlat(true);
|
||||
|
||||
connect(m_gohomebtn, &QPushButton::clicked, this,[=](){
|
||||
|
|
Loading…
Reference in New Issue