add plymouth check and fix plymouth show error
This commit is contained in:
parent
6379182bcf
commit
f9b9876b84
|
@ -8,6 +8,8 @@
|
|||
#include <QDebug>
|
||||
#include <QtMath>
|
||||
#include <QRegularExpression>
|
||||
#include <QBuffer>
|
||||
#include <QFileInfoList>
|
||||
|
||||
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<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");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// 调整图像大小为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()<<outputFileName;
|
||||
if (!resizedImage.save(outputFileName, "PNG", 100)) {
|
||||
qDebug() << "Failed to save image:" << outputFileName;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue