!23 add filecheck function
Merge pull request !23 from likehomedream/my-2.0-devel
This commit is contained in:
commit
2ecf9b648d
|
@ -1,4 +1,4 @@
|
|||
QT += core gui
|
||||
QT += core gui svg
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
@ -21,6 +21,7 @@ SOURCES += \
|
|||
src/configfilemanager.cpp \
|
||||
src/cursorthemefeature.cpp \
|
||||
src/cursorthemewidget.cpp \
|
||||
src/filecheck.cpp \
|
||||
src/fileprocess.cpp \
|
||||
src/globalthemefeature.cpp \
|
||||
src/globalthemewidget.cpp \
|
||||
|
@ -39,6 +40,7 @@ HEADERS += \
|
|||
src/configfilemanager.h \
|
||||
src/cursorthemefeature.h \
|
||||
src/cursorthemewidget.h \
|
||||
src/filecheck.h \
|
||||
src/fileprocess.h \
|
||||
src/globalthemefeature.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 "filecheck.h"
|
||||
|
||||
GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -92,21 +92,18 @@ void GlobalThemeWidget::initCoverWidget()
|
|||
|
||||
|
||||
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择PNG文件"), "", tr("PNG 文件 (*.png)"));
|
||||
if (newFilePath.isEmpty()) {
|
||||
qDebug() << "Selected file path:" << newFilePath;
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
|
||||
bool legalFile = FileCheck::isLegalWallPaperFile(newFilePath,"cover");
|
||||
|
||||
if (newFilePath.isEmpty() || !legalFile) {
|
||||
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);
|
||||
|
@ -130,7 +127,7 @@ void GlobalThemeWidget::initWallPaperWidget()
|
|||
QPushButton *coverbtn = new QPushButton(cover);
|
||||
coverbtn->setFixedSize(160,100);
|
||||
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(tip);
|
||||
|
@ -141,18 +138,19 @@ void GlobalThemeWidget::initWallPaperWidget()
|
|||
coverbtn->setIconSize(coverbtn->size());
|
||||
|
||||
connect(coverbtn, &QPushButton::clicked, this, [=]() {
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择PNG文件"), "", tr("PNG 文件 (*.png)"));
|
||||
if (newFilePath.isEmpty()) {
|
||||
qDebug() << "Selected file path:" << newFilePath;
|
||||
updateWallpaperFilePath(m_wallpaperpath);
|
||||
}else{
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
|
||||
|
||||
if (!newFilePath.isEmpty() && FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")) {
|
||||
updateWallpaperFilePath(newFilePath);
|
||||
emit wallpaperupdate(newFilePath);
|
||||
emit newWallpaperFilePath(newFilePath);
|
||||
|
||||
QPixmap pixmap(newFilePath);
|
||||
coverbtn->setIcon(QIcon(pixmap));
|
||||
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(29, 29, 29));
|
||||
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);
|
||||
m_preview->updateOverlayImage(":/resource/background/panel-light.png");
|
||||
m_preview->updatescale();
|
||||
}else if(index == 1){
|
||||
QColor selectedColor = combobox->itemData(index).value<QColor>();
|
||||
|
||||
m_preview->updateWidgetBackgroundColor(selectedColor);
|
||||
m_preview->updateOverlayImage(":/resource/background/panel-dark.png");
|
||||
m_preview->updatescale();
|
||||
if (index == 0) {
|
||||
overlayImage = ":/resource/background/panel-light.png";
|
||||
} else if (index == 1) {
|
||||
overlayImage = ":/resource/background/panel-dark.png";
|
||||
}
|
||||
emit newExterior(combobox->itemData(index).value<QColor>());
|
||||
|
||||
m_preview->updateWidgetBackgroundColor(selectedColor);
|
||||
m_preview->updateOverlayImage(overlayImage);
|
||||
m_preview->updatescale();
|
||||
|
||||
emit newExterior(selectedColor);
|
||||
});
|
||||
|
||||
layout->addWidget(title);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "iconthemewidget.h"
|
||||
#include "filecheck.h"
|
||||
|
||||
IconThemeWidget::IconThemeWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -132,11 +133,14 @@ void IconThemeWidget::initSystemEditWidget()
|
|||
|
||||
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
|
||||
if (!newFilePath.isEmpty()) {
|
||||
m_systemcustomiconpathmap->insert(widgetName, newFilePath);
|
||||
clickedWidget->setcustomicon(newFilePath);
|
||||
//check
|
||||
if(FileCheck::isLegalIconFile(newFilePath)){
|
||||
m_systemcustomiconpathmap->insert(widgetName, newFilePath);
|
||||
clickedWidget->setcustomicon(newFilePath);
|
||||
|
||||
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
|
||||
m_systempreview->updateIcon(widgetName, newFilePath);
|
||||
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
|
||||
m_systempreview->updateIcon(widgetName, newFilePath);
|
||||
}
|
||||
}
|
||||
emit newSystemIconsMap(m_systemcustomiconpathmap);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue