add check and listview
This commit is contained in:
parent
19a883a214
commit
77d0744d71
|
@ -7,6 +7,8 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QStringListModel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#define HOMEPATH "/home/"
|
#define HOMEPATH "/home/"
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ IconThemeWidget::IconThemeWidget(QWidget *parent) : WidgetBase(parent)
|
||||||
connect(m_importButton , &QPushButton::clicked, this, [=](){
|
connect(m_importButton , &QPushButton::clicked, this, [=](){
|
||||||
this->importIcons();
|
this->importIcons();
|
||||||
});
|
});
|
||||||
connect(this,&IconThemeWidget::onConfirmButtonClicked,this, &IconThemeWidget::check);
|
// connect(this,&IconThemeWidget::onConfirmButtonClicked,this, &IconThemeWidget::check);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconThemeWidget::init()
|
void IconThemeWidget::init()
|
||||||
|
@ -29,23 +31,32 @@ void IconThemeWidget::init()
|
||||||
// m_allLayout->insertWidget(new QLabel(tr("WidgetA")));
|
// m_allLayout->insertWidget(new QLabel(tr("WidgetA")));
|
||||||
// 创建新的 widget
|
// 创建新的 widget
|
||||||
QWidget* newWidget = new QWidget(this);
|
QWidget* newWidget = new QWidget(this);
|
||||||
|
|
||||||
newWidget->setFixedHeight(291);
|
newWidget->setFixedHeight(291);
|
||||||
QLineEdit* lll= new QLineEdit(tr("WidgetA"),newWidget);
|
newWidget->setFixedWidth(480);
|
||||||
|
// QLineEdit* lll= new QLineEdit(tr("WidgetA"),newWidget);
|
||||||
m_allLayout->takeAt(1);
|
m_allLayout->takeAt(1);
|
||||||
// m_allLayout->insertWidget(1,spacer);
|
// m_allLayout->insertWidget(1,spacer);
|
||||||
|
|
||||||
|
// 创建一个QListView
|
||||||
|
m_listview = new QListView(newWidget);
|
||||||
|
m_listview->setViewMode(QListView::IconMode);
|
||||||
|
m_listview->setFixedSize(newWidget->size());
|
||||||
|
m_listview->setFlow(QListView::LeftToRight);
|
||||||
|
|
||||||
|
m_model= new QStandardItemModel(newWidget);
|
||||||
|
|
||||||
|
|
||||||
|
// 将QFileSystemModel设置为QListView的模型
|
||||||
|
m_listview->setModel(m_model);
|
||||||
|
|
||||||
// 将新的 widget 插入到 m_allLayout 中
|
// 将新的 widget 插入到 m_allLayout 中
|
||||||
int index = m_allLayout->indexOf(m_buttonWidget);
|
int index = m_allLayout->indexOf(m_buttonWidget);
|
||||||
qDebug()<< index;
|
qDebug()<< index;
|
||||||
m_allLayout->insertWidget(index, newWidget);
|
m_allLayout->insertWidget(index, newWidget);
|
||||||
|
|
||||||
// m_allLayout->addWidget(m_headWidget);
|
|
||||||
// m_allLayout->addWidget(m_buttonWidget);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#include <QMessageBox>
|
|
||||||
void IconThemeWidget::importIcons()
|
void IconThemeWidget::importIcons()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -61,9 +72,28 @@ void IconThemeWidget::importIcons()
|
||||||
m_fd->setViewMode(QFileDialog::List);
|
m_fd->setViewMode(QFileDialog::List);
|
||||||
// m_fd->setNameFilter(filters);
|
// m_fd->setNameFilter(filters);
|
||||||
// m_fd->setFileMode(QFileDialog::ExistingFile);
|
// m_fd->setFileMode(QFileDialog::ExistingFile);
|
||||||
m_fd->setWindowTitle(tr("Select Open Action"));
|
m_fd->setWindowTitle(tr("Select Import Dir"));
|
||||||
m_fd->setLabelText(QFileDialog::Accept, tr("Select"));
|
m_fd->setLabelText(QFileDialog::Accept, tr("Select"));
|
||||||
m_fd->setLabelText(QFileDialog::Reject, tr("Cancel"));
|
m_fd->setLabelText(QFileDialog::Reject, tr("Cancel"));
|
||||||
|
connect(m_fd, &QFileDialog::urlSelected, this, [=](const QUrl &url){
|
||||||
|
|
||||||
|
qDebug() << "demo urlSelected:" << url;
|
||||||
|
|
||||||
|
// 清空模型
|
||||||
|
// model->clear();
|
||||||
|
QStringList str_list = url.toString().split("/");
|
||||||
|
|
||||||
|
QStandardItem *item = new QStandardItem(QIcon::fromTheme("folder"), str_list.last());
|
||||||
|
m_model->appendRow(item);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
openFileDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IconThemeWidget::openFileDialog()
|
||||||
|
{
|
||||||
|
|
||||||
if (m_fd->exec() != QDialog::Accepted)
|
if (m_fd->exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -71,39 +101,65 @@ void IconThemeWidget::importIcons()
|
||||||
QString selectedDirectory;
|
QString selectedDirectory;
|
||||||
selectedDirectory = m_fd->selectedFiles().first();
|
selectedDirectory = m_fd->selectedFiles().first();
|
||||||
|
|
||||||
QStringList str_list = selectedDirectory.split("/");
|
// bool isLegal = ThemesCheck::checkIconsDir(selectedDirectory);
|
||||||
|
// if(isLegal){
|
||||||
|
QStringList str_list = selectedDirectory.split("/");
|
||||||
|
|
||||||
|
QString path = m_iconpath+str_list.last();
|
||||||
|
|
||||||
|
QDir dir(path);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileCopy::copyDirectoryFiles(selectedDirectory,path,true);
|
||||||
|
|
||||||
|
|
||||||
QString path = m_iconpath+str_list.last();
|
//选中的图标文件加显示在界面中
|
||||||
|
// QFileSystemModel* model = qobject_cast<QFileSystemModel*>(this);
|
||||||
QDir dir(path);
|
// QModelIndex rootIndex = model->index(0, 0);
|
||||||
if (!dir.exists()) {
|
// model->setRootPath(path);
|
||||||
dir.mkpath(path);
|
// m_listview->setRootIndex(rootIndex);
|
||||||
}
|
|
||||||
|
|
||||||
FileCopy::copyDirectoryFiles(selectedDirectory,path,true);
|
|
||||||
|
|
||||||
|
|
||||||
|
// QStringList fpath = QFileDialog::getOpenFileNames(this, "Please Select PS File", ".", "PS File(*.ps);;All Files(*.*)");
|
||||||
|
// QFileDialog::getExistingDirectory();
|
||||||
|
// QStringList pathlist = m_slFilePath; // QStringList类的成员变量
|
||||||
|
|
||||||
|
// QStringListModel *modelitem;
|
||||||
|
|
||||||
|
// for(int i=0; i<fpath.length(); i++)
|
||||||
|
// {
|
||||||
|
// bool flag = true;
|
||||||
|
// for(int j=0; j<pathlist.length(); j++)
|
||||||
|
// {
|
||||||
|
// if(pathlist.at(j) == fpath.at(i))
|
||||||
|
// {
|
||||||
|
// flag = false;
|
||||||
|
// QMessageBox::warning(this, "Error", "The file you selected is duplicated");
|
||||||
|
// return ;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if(flag)
|
||||||
|
// m_slFilePath.append(fpath.at(i));
|
||||||
|
// }
|
||||||
|
//// modelitem = new QStringListModel(m_slFilePath);
|
||||||
|
// QStringList test = {
|
||||||
|
// "/home/like/workspace/svg","/home/like/workspace/ktb"
|
||||||
|
// };
|
||||||
|
// modelitem = new QStringListModel(test);
|
||||||
|
// m_listview->setModel(modelitem);//m_plistView是QListView类的成员变量,这个函数就是把list添加到listView中。
|
||||||
|
|
||||||
|
|
||||||
|
// }else{
|
||||||
|
|
||||||
|
// QMessageBox::critical(this, tr("Error"), tr("Invalid file selected. Please try again."));
|
||||||
|
// // 在消息框关闭后再次打开文件选择对话框
|
||||||
|
// QMetaObject::invokeMethod(this, "openFileDialog", Qt::QueuedConnection);
|
||||||
|
// }
|
||||||
|
|
||||||
//选中的图标文件加显示在界面中
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconThemeWidget::check()
|
|
||||||
{
|
|
||||||
//检查
|
|
||||||
bool islegal = ThemesCheck::checkIconsDir(m_iconpath);
|
|
||||||
if(!islegal){
|
|
||||||
//给出提示
|
|
||||||
QMessageBox *messageBox = new QMessageBox(this);
|
|
||||||
messageBox->show();
|
|
||||||
}else{
|
|
||||||
//输入主题包名,返回
|
|
||||||
QMessageBox *messageBox = new QMessageBox(this);
|
|
||||||
messageBox->show();
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
Q_EMIT readyToBuild();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QListView>
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
class IconThemeWidget : public WidgetBase
|
class IconThemeWidget : public WidgetBase
|
||||||
{
|
{
|
||||||
|
@ -17,15 +21,17 @@ public:
|
||||||
void init();
|
void init();
|
||||||
void importIcons();
|
void importIcons();
|
||||||
|
|
||||||
|
// bool check(QString path);
|
||||||
|
void openFileDialog();
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void readyToBuild();
|
void readyToBuild();
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void check();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFileDialog *m_fd;
|
QFileDialog *m_fd;
|
||||||
QString m_iconpath;
|
QString m_iconpath;
|
||||||
|
QListView *m_listview;
|
||||||
|
QStandardItemModel *m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ICONTHEMEWIDGET_H
|
#endif // ICONTHEMEWIDGET_H
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "themescheck.h"
|
#include "themescheck.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QImageReader>
|
||||||
|
|
||||||
ThemesCheck::ThemesCheck(QObject *parent) : QObject(parent)
|
ThemesCheck::ThemesCheck(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +15,17 @@ bool ThemesCheck::checkIconsDir(QString folderPath)
|
||||||
|
|
||||||
QDir dir(folderPath);
|
QDir dir(folderPath);
|
||||||
|
|
||||||
|
//判断文件夹的名字
|
||||||
|
QStringList validFolderNames = {"16", "24", "32", "48", "64", "96"};
|
||||||
|
|
||||||
|
QStringList str_list = folderPath.split("/");
|
||||||
|
|
||||||
|
if (!validFolderNames.contains(str_list.last())) {
|
||||||
|
|
||||||
|
qDebug() << "Invalid folder name: " << str_list.last();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// 获取当前目录下所有文件及文件夹
|
// 获取当前目录下所有文件及文件夹
|
||||||
QFileInfoList fileList = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
QFileInfoList fileList = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
|
@ -24,6 +36,7 @@ bool ThemesCheck::checkIconsDir(QString folderPath)
|
||||||
|
|
||||||
// 判断是否为文件夹
|
// 判断是否为文件夹
|
||||||
if (fileInfo.isDir()) {
|
if (fileInfo.isDir()) {
|
||||||
|
|
||||||
// 递归判断文件夹内所有文件
|
// 递归判断文件夹内所有文件
|
||||||
if (!checkIconsDir(path)) {
|
if (!checkIconsDir(path)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -31,13 +44,32 @@ bool ThemesCheck::checkIconsDir(QString folderPath)
|
||||||
}
|
}
|
||||||
// 判断文件名是否含有空格
|
// 判断文件名是否含有空格
|
||||||
else if (name.contains(" ")) {
|
else if (name.contains(" ")) {
|
||||||
|
qDebug() << "File name contains space: " << name;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 判断文件格式是否为png或svg
|
// 判断文件格式是否为png或svg
|
||||||
else if (fileInfo.suffix() != "png" && !(fileInfo.suffix() == "svg" && fileInfo.dir().dirName() == "scalable")) {
|
else if (fileInfo.suffix() != "png" /*&& !(fileInfo.suffix() == "svg" && fileInfo.dir().dirName() == "scalable")*/) {
|
||||||
|
qDebug() << "Invalid file format: " << name;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 解析文件路径
|
||||||
|
QStringList pathParts = path.split("/");
|
||||||
|
if (pathParts.size() < 3) {
|
||||||
|
qDebug() << "Invalid file path: " << path;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString folderName = pathParts[pathParts.size() - 2];
|
||||||
|
int expectedSize = folderName.toInt();
|
||||||
|
|
||||||
|
// 判断图标文件宽度和高度是否与最开始的数字相匹配
|
||||||
|
QImageReader r(path);
|
||||||
|
if (r.size().width() != expectedSize || r.size().height() != expectedSize) {
|
||||||
|
qDebug() << "Icon size does not match folder name: " << name;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug()<<"yes!!!!!!!!!!";
|
qDebug()<<"yes!!!!!!!!!!";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue