add filecheck function
This commit is contained in:
parent
f061269a84
commit
1e3215554b
|
@ -1,4 +1,4 @@
|
||||||
QT += core gui
|
QT += core gui svg
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ SOURCES += \
|
||||||
src/configfilemanager.cpp \
|
src/configfilemanager.cpp \
|
||||||
src/cursorthemefeature.cpp \
|
src/cursorthemefeature.cpp \
|
||||||
src/cursorthemewidget.cpp \
|
src/cursorthemewidget.cpp \
|
||||||
|
src/filecheck.cpp \
|
||||||
src/fileprocess.cpp \
|
src/fileprocess.cpp \
|
||||||
src/globalthemefeature.cpp \
|
src/globalthemefeature.cpp \
|
||||||
src/globalthemewidget.cpp \
|
src/globalthemewidget.cpp \
|
||||||
|
@ -39,6 +40,7 @@ HEADERS += \
|
||||||
src/configfilemanager.h \
|
src/configfilemanager.h \
|
||||||
src/cursorthemefeature.h \
|
src/cursorthemefeature.h \
|
||||||
src/cursorthemewidget.h \
|
src/cursorthemewidget.h \
|
||||||
|
src/filecheck.h \
|
||||||
src/fileprocess.h \
|
src/fileprocess.h \
|
||||||
src/globalthemefeature.h \
|
src/globalthemefeature.h \
|
||||||
src/globalthemewidget.h \
|
src/globalthemewidget.h \
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include "filecheck.h"
|
||||||
|
#include <QSvgRenderer>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
FileCheck::FileCheck(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileCheck::isLegalIconFile(const QString &filePath)
|
||||||
|
{
|
||||||
|
QSvgRenderer renderer(filePath);
|
||||||
|
|
||||||
|
if (renderer.isValid()){
|
||||||
|
QSize svgSize = renderer.defaultSize();
|
||||||
|
if (svgSize.width() >= 96 && svgSize.height() >= 96 && svgSize.width() == svgSize.height()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileCheck::isLegalWallPaperFile(const QString& filePath, const QString& type)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(filePath);
|
||||||
|
QImage image(filePath);
|
||||||
|
QSize imageSize = image.size();
|
||||||
|
qint64 fileSize = fileInfo.size();
|
||||||
|
|
||||||
|
if (type == "wallpaper") {
|
||||||
|
if (imageSize.width() != 3840 || imageSize.height() != 2160){
|
||||||
|
QMessageBox::information(nullptr, tr("错误"), tr("壁纸尺寸必须为3840x2160"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qint64 maxSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
if (fileSize > maxSize){
|
||||||
|
QMessageBox::information(nullptr, tr("错误"), tr("文件大小不能超过10MB"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (type == "cover") {
|
||||||
|
if (imageSize.width() != 1640 || imageSize.height() != 1080){
|
||||||
|
QMessageBox::information(nullptr, tr("错误"), tr("封面尺寸必须为1640x1080"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qint64 maxSize = 5 * 1024 * 1024; // 5 MB
|
||||||
|
if (fileSize > maxSize){
|
||||||
|
QMessageBox::information(nullptr, tr("错误"), tr("文件大小不能超过5MB"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef FILECHECK_H
|
||||||
|
#define FILECHECK_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDebug>
|
||||||
|
class FileCheck : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FileCheck(QObject *parent = nullptr);
|
||||||
|
static bool isLegalIconFile(const QString& filePath);
|
||||||
|
static bool isLegalWallPaperFile(const QString& filePath, const QString& type);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILECHECK_H
|
|
@ -1,5 +1,5 @@
|
||||||
#include "globalthemewidget.h"
|
#include "globalthemewidget.h"
|
||||||
|
#include "filecheck.h"
|
||||||
|
|
||||||
GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : QWidget(parent)
|
GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -92,21 +92,18 @@ void GlobalThemeWidget::initCoverWidget()
|
||||||
|
|
||||||
|
|
||||||
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
||||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择PNG文件"), "", tr("PNG 文件 (*.png)"));
|
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
|
||||||
if (newFilePath.isEmpty()) {
|
bool legalFile = FileCheck::isLegalWallPaperFile(newFilePath,"cover");
|
||||||
qDebug() << "Selected file path:" << newFilePath;
|
|
||||||
|
if (newFilePath.isEmpty() || !legalFile) {
|
||||||
newFilePath = m_coverpath;
|
newFilePath = m_coverpath;
|
||||||
QPixmap pixmap(m_coverpath);
|
|
||||||
coverbtn->setIcon(QIcon(pixmap));
|
|
||||||
coverbtn->setIconSize(coverbtn->size());
|
|
||||||
}else{
|
|
||||||
m_coverpath = newFilePath;
|
|
||||||
QPixmap pixmap(m_coverpath);
|
|
||||||
coverbtn->setIcon(QIcon(pixmap));
|
|
||||||
coverbtn->setIconSize(coverbtn->size());
|
|
||||||
emit newCoverFilePath(newFilePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_coverpath = newFilePath;
|
||||||
|
coverbtn->setIcon(QIcon(m_coverpath));
|
||||||
|
coverbtn->setIconSize(coverbtn->size());
|
||||||
|
emit newCoverFilePath(newFilePath);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
layout->addStretch(1);
|
layout->addStretch(1);
|
||||||
|
@ -130,7 +127,7 @@ void GlobalThemeWidget::initWallPaperWidget()
|
||||||
QPushButton *coverbtn = new QPushButton(cover);
|
QPushButton *coverbtn = new QPushButton(cover);
|
||||||
coverbtn->setFixedSize(160,100);
|
coverbtn->setFixedSize(160,100);
|
||||||
QLabel *tip = new QLabel(cover);
|
QLabel *tip = new QLabel(cover);
|
||||||
tip->setText("<html>尺寸:1640*1080<br>大小:不超过 5 MB<br>格式:PNG</html>");
|
tip->setText("<html>尺寸:3840*2160<br>大小:不超过 10 MB<br>格式:PNG</html>");
|
||||||
|
|
||||||
coverlayout->addWidget(coverbtn);
|
coverlayout->addWidget(coverbtn);
|
||||||
coverlayout->addWidget(tip);
|
coverlayout->addWidget(tip);
|
||||||
|
@ -141,18 +138,19 @@ void GlobalThemeWidget::initWallPaperWidget()
|
||||||
coverbtn->setIconSize(coverbtn->size());
|
coverbtn->setIconSize(coverbtn->size());
|
||||||
|
|
||||||
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
||||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择PNG文件"), "", tr("PNG 文件 (*.png)"));
|
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
|
||||||
if (newFilePath.isEmpty()) {
|
|
||||||
qDebug() << "Selected file path:" << newFilePath;
|
if (!newFilePath.isEmpty() && FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")) {
|
||||||
updateWallpaperFilePath(m_wallpaperpath);
|
|
||||||
}else{
|
|
||||||
updateWallpaperFilePath(newFilePath);
|
updateWallpaperFilePath(newFilePath);
|
||||||
emit wallpaperupdate(newFilePath);
|
emit wallpaperupdate(newFilePath);
|
||||||
emit newWallpaperFilePath(newFilePath);
|
emit newWallpaperFilePath(newFilePath);
|
||||||
|
|
||||||
QPixmap pixmap(newFilePath);
|
QPixmap pixmap(newFilePath);
|
||||||
coverbtn->setIcon(QIcon(pixmap));
|
coverbtn->setIcon(QIcon(pixmap));
|
||||||
coverbtn->setIconSize(coverbtn->size());
|
coverbtn->setIconSize(coverbtn->size());
|
||||||
|
} else {
|
||||||
|
qDebug() << "Selected file path:" << newFilePath;
|
||||||
|
updateWallpaperFilePath(m_wallpaperpath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -175,20 +173,20 @@ void GlobalThemeWidget::initExteriorWidget()
|
||||||
combobox->addItem("浅色",QColor(255, 255, 255));
|
combobox->addItem("浅色",QColor(255, 255, 255));
|
||||||
combobox->addItem("深色", QColor(29, 29, 29));
|
combobox->addItem("深色", QColor(29, 29, 29));
|
||||||
connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
|
connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
|
||||||
if(index == 0){
|
QColor selectedColor = combobox->itemData(index).value<QColor>();
|
||||||
QColor selectedColor = combobox->itemData(index).value<QColor>();
|
QString overlayImage;
|
||||||
|
|
||||||
m_preview->updateWidgetBackgroundColor(selectedColor);
|
if (index == 0) {
|
||||||
m_preview->updateOverlayImage(":/resource/background/panel-light.png");
|
overlayImage = ":/resource/background/panel-light.png";
|
||||||
m_preview->updatescale();
|
} else if (index == 1) {
|
||||||
}else if(index == 1){
|
overlayImage = ":/resource/background/panel-dark.png";
|
||||||
QColor selectedColor = combobox->itemData(index).value<QColor>();
|
|
||||||
|
|
||||||
m_preview->updateWidgetBackgroundColor(selectedColor);
|
|
||||||
m_preview->updateOverlayImage(":/resource/background/panel-dark.png");
|
|
||||||
m_preview->updatescale();
|
|
||||||
}
|
}
|
||||||
emit newExterior(combobox->itemData(index).value<QColor>());
|
|
||||||
|
m_preview->updateWidgetBackgroundColor(selectedColor);
|
||||||
|
m_preview->updateOverlayImage(overlayImage);
|
||||||
|
m_preview->updatescale();
|
||||||
|
|
||||||
|
emit newExterior(selectedColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
layout->addWidget(title);
|
layout->addWidget(title);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "iconthemewidget.h"
|
#include "iconthemewidget.h"
|
||||||
|
#include "filecheck.h"
|
||||||
|
|
||||||
IconThemeWidget::IconThemeWidget(QWidget *parent) : QWidget(parent)
|
IconThemeWidget::IconThemeWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -132,11 +133,14 @@ void IconThemeWidget::initSystemEditWidget()
|
||||||
|
|
||||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
|
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
|
||||||
if (!newFilePath.isEmpty()) {
|
if (!newFilePath.isEmpty()) {
|
||||||
m_systemcustomiconpathmap->insert(widgetName, newFilePath);
|
//check
|
||||||
clickedWidget->setcustomicon(newFilePath);
|
if(FileCheck::isLegalIconFile(newFilePath)){
|
||||||
|
m_systemcustomiconpathmap->insert(widgetName, newFilePath);
|
||||||
|
clickedWidget->setcustomicon(newFilePath);
|
||||||
|
|
||||||
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
|
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
|
||||||
m_systempreview->updateIcon(widgetName, newFilePath);
|
m_systempreview->updateIcon(widgetName, newFilePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit newSystemIconsMap(m_systemcustomiconpathmap);
|
emit newSystemIconsMap(m_systemcustomiconpathmap);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue