diff --git a/src/fileProcess/configfilemanager.cpp b/src/fileProcess/configfilemanager.cpp index ec8276b..678f630 100644 --- a/src/fileProcess/configfilemanager.cpp +++ b/src/fileProcess/configfilemanager.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include ConfigFileManager::ConfigFileManager(QObject *parent) : QObject(parent) { @@ -579,6 +581,7 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD qWarning()<<"start get video image failed."; } + if (!p.waitForFinished(40000)) { qWarning()<<"wait video image too long time."; } @@ -588,36 +591,38 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD qWarning()<<"get video image failed."; } -// // 处理所有PNG文件大小 -// QDirIterator it(cachedir.absolutePath(), QStringList() << "*.png", QDir::Files, QDirIterator::Subdirectories); -// while (it.hasNext()) { -// QString filePath = it.next(); + QDir dir(cachedir); + dir.setFilter(QDir::Files | QDir::NoSymLinks); + dir.setNameFilters(QStringList() << "*.png"); -// QFile file(filePath); -// if (file.open(QIODevice::ReadOnly)) -// { -// QByteArray imageData = file.readAll(); -// file.close(); + QFileInfoList fileList1 = dir.entryInfoList(); + foreach (const QFileInfo& fileInfo, fileList1) { + QString fileName = fileInfo.absoluteFilePath(); -// int maxSize = 17500; // 最大文件大小为17.5KB + QImage image(fileName); + if (image.isNull()) { + qDebug() << "Failed to load image:" << fileName; + continue; + } -// if (imageData.size() > maxSize) -// { -// QImage image; -// image.loadFromData(imageData); - -// // 按比例缩小图片尺寸 -// qreal scale = qSqrt(static_cast(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"); -// } -// } -// } + // 调整图像大小为20x20像素 + QSize newSize(100, 100); + QImage resizedImage = image.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + QByteArray byteArray; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + if (!resizedImage.save(&buffer, "PNG", 100)) { + qDebug() << "Failed to resize image:" << fileName; + continue; + } + QString outputFileName = fileInfo.path() + "/" + fileInfo.baseName() + ".png"; + qDebug()< 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; +} + diff --git a/src/fileProcess/filecheck.h b/src/fileProcess/filecheck.h index 79bea4f..bae7ad1 100644 --- a/src/fileProcess/filecheck.h +++ b/src/fileProcess/filecheck.h @@ -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: diff --git a/src/module/plymouththemefeature.cpp b/src/module/plymouththemefeature.cpp index ffa7a98..2bceca5 100644 --- a/src/module/plymouththemefeature.cpp +++ b/src/module/plymouththemefeature.cpp @@ -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= "<width()"<width()<<" pixmap.width()" << pixmap.width(); qreal y = (scene->height() - pixmap.height()) / 2; sceneWidth = scene->width(); sceneHeight = scene->height(); diff --git a/src/module/plymouththemewidget.cpp b/src/module/plymouththemewidget.cpp index 9df782d..0d5839e 100644 --- a/src/module/plymouththemewidget.cpp +++ b/src/module/plymouththemewidget.cpp @@ -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"; + } } } diff --git a/src/module/plymouththemewidget.h b/src/module/plymouththemewidget.h index ebba483..3c9dc6f 100644 --- a/src/module/plymouththemewidget.h +++ b/src/module/plymouththemewidget.h @@ -4,6 +4,7 @@ #include "iconwidgetfeature.h" #include "historywidget.h" #include "basewidget.h" +#include "../fileProcess/filecheck.h" #include #include