diff --git a/src/baseUI/iconthemewidget.cpp b/src/baseUI/iconthemewidget.cpp index c245e95..518bbe8 100644 --- a/src/baseUI/iconthemewidget.cpp +++ b/src/baseUI/iconthemewidget.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #define HOMEPATH "/home/" @@ -21,7 +23,7 @@ IconThemeWidget::IconThemeWidget(QWidget *parent) : WidgetBase(parent) connect(m_importButton , &QPushButton::clicked, this, [=](){ this->importIcons(); }); - connect(this,&IconThemeWidget::onConfirmButtonClicked,this, &IconThemeWidget::check); +// connect(this,&IconThemeWidget::onConfirmButtonClicked,this, &IconThemeWidget::check); } void IconThemeWidget::init() @@ -29,23 +31,32 @@ void IconThemeWidget::init() // m_allLayout->insertWidget(new QLabel(tr("WidgetA"))); // 创建新的 widget QWidget* newWidget = new QWidget(this); + 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->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 中 int index = m_allLayout->indexOf(m_buttonWidget); qDebug()<< index; m_allLayout->insertWidget(index, newWidget); -// m_allLayout->addWidget(m_headWidget); -// m_allLayout->addWidget(m_buttonWidget); - } -#include + void IconThemeWidget::importIcons() { @@ -61,9 +72,28 @@ void IconThemeWidget::importIcons() m_fd->setViewMode(QFileDialog::List); // m_fd->setNameFilter(filters); // 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::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) return; @@ -71,39 +101,65 @@ void IconThemeWidget::importIcons() QString selectedDirectory; 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(); - - QDir dir(path); - if (!dir.exists()) { - dir.mkpath(path); - } - - FileCopy::copyDirectoryFiles(selectedDirectory,path,true); + //选中的图标文件加显示在界面中 +// QFileSystemModel* model = qobject_cast(this); +// QModelIndex rootIndex = model->index(0, 0); +// model->setRootPath(path); +// m_listview->setRootIndex(rootIndex); +// 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; isetModel(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(); - } -} diff --git a/src/baseUI/iconthemewidget.h b/src/baseUI/iconthemewidget.h index 3bfbe43..438a70b 100644 --- a/src/baseUI/iconthemewidget.h +++ b/src/baseUI/iconthemewidget.h @@ -8,6 +8,10 @@ #include #include #include +#include +#include +#include +#include class IconThemeWidget : public WidgetBase { @@ -17,15 +21,17 @@ public: void init(); void importIcons(); +// bool check(QString path); + void openFileDialog(); Q_SIGNALS: void readyToBuild(); -public Q_SLOTS: - void check(); private: QFileDialog *m_fd; QString m_iconpath; + QListView *m_listview; + QStandardItemModel *m_model; }; #endif // ICONTHEMEWIDGET_H diff --git a/src/baseUI/themescheck/themescheck.cpp b/src/baseUI/themescheck/themescheck.cpp index 50b7b95..df1067b 100644 --- a/src/baseUI/themescheck/themescheck.cpp +++ b/src/baseUI/themescheck/themescheck.cpp @@ -1,5 +1,6 @@ #include "themescheck.h" #include +#include ThemesCheck::ThemesCheck(QObject *parent) : QObject(parent) { @@ -14,6 +15,17 @@ bool ThemesCheck::checkIconsDir(QString 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); @@ -24,6 +36,7 @@ bool ThemesCheck::checkIconsDir(QString folderPath) // 判断是否为文件夹 if (fileInfo.isDir()) { + // 递归判断文件夹内所有文件 if (!checkIconsDir(path)) { return false; @@ -31,13 +44,32 @@ bool ThemesCheck::checkIconsDir(QString folderPath) } // 判断文件名是否含有空格 else if (name.contains(" ")) { + qDebug() << "File name contains space: " << name; return false; } // 判断文件格式是否为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; } } + qDebug()<<"yes!!!!!!!!!!"; return true; }