diff --git a/src/baseUI/baseUI.pro b/src/baseUI/baseUI.pro index 0d8fed7..311a6ff 100644 --- a/src/baseUI/baseUI.pro +++ b/src/baseUI/baseUI.pro @@ -9,7 +9,7 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ cursorthemewidget.cpp \ debmaker/debmaker.cpp \ - filecopy.cpp \ + fileoperate.cpp \ globalthemewidget.cpp \ iconthemewidget.cpp \ main.cpp \ @@ -21,7 +21,7 @@ SOURCES += \ HEADERS += \ cursorthemewidget.h \ debmaker/debmaker.h \ - filecopy.h \ + fileoperate.h \ globalthemewidget.h \ iconthemewidget.h \ mainwindow.h \ diff --git a/src/baseUI/filecopy.cpp b/src/baseUI/fileoperate.cpp similarity index 52% rename from src/baseUI/filecopy.cpp rename to src/baseUI/fileoperate.cpp index 73f7634..e8ff5e6 100644 --- a/src/baseUI/filecopy.cpp +++ b/src/baseUI/fileoperate.cpp @@ -1,14 +1,15 @@ -#include "filecopy.h" +#include "fileoperate.h" #include +#include -FileCopy::FileCopy(QObject *parent) : QObject(parent) +FileOperate::FileOperate(QObject *parent) : QObject(parent) { } -bool FileCopy::copyDirectoryFiles(const QString &fromDir, const QString &toDir, bool coverFileIfExist) +bool FileOperate::copyDirectoryFiles(const QString &fromDir, const QString &toDir, bool coverFileIfExist) { QDir sourceDir(fromDir); @@ -46,3 +47,28 @@ bool FileCopy::copyDirectoryFiles(const QString &fromDir, const QString &toDir, } return true; } + +bool FileOperate::deleteDirectoryFiles(const QString &path) +{ + qDebug()<<"deleteDirectoryFiles====start"; + if (path.isEmpty()){ + qDebug()<<"path.isEmpty()====start"; + return false; + } + QDir dir(path); + qDebug()<<"path====start"< -class FileCopy : public QObject +class FileOperate : public QObject { Q_OBJECT public: - explicit FileCopy(QObject *parent = nullptr); + explicit FileOperate(QObject *parent = nullptr); static bool copyDirectoryFiles(const QString &fromDir, const QString &toDir, bool coverFileIfExist); + static bool deleteDirectoryFiles(const QString &Dir); signals: }; diff --git a/src/baseUI/iconthemewidget.cpp b/src/baseUI/iconthemewidget.cpp index c245e95..fbfc99a 100644 --- a/src/baseUI/iconthemewidget.cpp +++ b/src/baseUI/iconthemewidget.cpp @@ -7,8 +7,10 @@ #include #include #include +#include +#include + -#define HOMEPATH "/home/" IconThemeWidget::IconThemeWidget(QWidget *parent) : WidgetBase(parent) @@ -21,49 +23,98 @@ 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() { + QString name = qgetenv("USER"); + qDebug()<<"QString name = qgetenv;"<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_listwidget = new QListWidget(newWidget); + m_listwidget->setViewMode(QListView::IconMode); + m_listwidget->setFixedSize(newWidget->size()); + m_listwidget->setFlow(QListView::LeftToRight); + m_listwidget->setMovement(QListView::Static); + m_listwidget->setIconSize(QSize(48, 48)); + // 初始化固定路径 + QString fixedPath = m_iconpath; + + // 获取文件列表,并将文件显示在列表视图中 + QStringList fileNames = QDir(fixedPath).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + foreach (QString fileName, fileNames) { + QListWidgetItem *item = new QListWidgetItem(QIcon(QIcon::fromTheme("folder")), fileName); +// DeletableItem *item = new DeletableItem(QIcon(QIcon::fromTheme("folder")), fileName); + m_listwidget->addItem(item); + } + + connect(m_listwidget, &QListWidget::itemDoubleClicked, [&](QListWidgetItem *item) { + + int row = m_listwidget->row(item); + + QString clicked_path = m_iconpath+m_listwidget->currentItem()->data(Qt::DisplayRole).toString(); + + //删除.cache中的文件目录 + FileOperate::deleteDirectoryFiles(clicked_path); + m_listwidget->takeItem(row); + delete item; + }); // 将新的 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() { - QString name = qgetenv("USER"); - qDebug()<<"QString name = qgetenv;"<setFileMode(QFileDialog::Directory); - m_fd->setDirectory(HOMEPATH); + m_fd->setDirectory(HOMEPATH+qgetenv("USER")); m_fd->setAcceptMode(QFileDialog::AcceptOpen); 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; + QStringList str_list = url.toString().split("/"); + + // 创建新的 QListWidgetItem,并设置标志为 Qt::UserRole,用于存储目录路径 + QListWidgetItem *item = new QListWidgetItem(QIcon(QIcon::fromTheme("folder")), str_list.last()); + item->setData(Qt::UserRole, str_list.last()); + + // 添加项到 QListWidget + m_listwidget->addItem(item); + }); + + + + openFileDialog(); +} + +void IconThemeWidget::openFileDialog() +{ + if (m_fd->exec() != QDialog::Accepted) return; @@ -71,39 +122,24 @@ 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(); - QString path = m_iconpath+str_list.last(); + QDir dir(path); + if (!dir.exists()) { + dir.mkpath(path); + } - QDir dir(path); - if (!dir.exists()) { - dir.mkpath(path); - } + FileOperate::copyDirectoryFiles(selectedDirectory,path,true); - FileCopy::copyDirectoryFiles(selectedDirectory,path,true); - - - - //选中的图标文件加显示在界面中 + qDebug()<<"path----------------"<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..82a110e 100644 --- a/src/baseUI/iconthemewidget.h +++ b/src/baseUI/iconthemewidget.h @@ -3,11 +3,68 @@ #include "widgetbase.h" -#include "filecopy.h" +#include "fileoperate.h" #include #include #include +#include +#include +#include +#include +#include +#include + +class DeletableItem : public QListWidgetItem +{ +public: + explicit DeletableItem(const QIcon &icon, const QString &text, QListWidget *parent = nullptr) : QListWidgetItem(text, parent) + { +// // 创建删除按钮 +// QPushButton* deleteButton = new QPushButton("删除"); +// deleteButton->setObjectName("deleteButton"); // 设置对象名称以便样式定制 + +// // 使用水平布局将按钮添加到项中 +// QHBoxLayout* layout = new QHBoxLayout; +// layout->addWidget(deleteButton); +// layout->setAlignment(Qt::AlignRight); + +// // 创建一个小部件来容纳布局 +// QWidget* widget = new QWidget(parent); +// widget->setLayout(layout); +// widget->setProperty("isRoundButton",true); +// // 将小部件设置为项的右上角小部件 +// setSizeHint(widget->sizeHint()); +// parent->setItemWidget(this, widget); +// deleteButton->setFixedSize(20,20); +// deleteButton->setIcon(QIcon::fromTheme("window-close-symbolic")); + // 连接删除按钮的点击信号到槽函数 +// QObject::connect(deleteButton, &QPushButton::clicked, this, &DeletableItem::deleteItem); + QWidget* widget = new QWidget(parent); + QHBoxLayout* layout = new QHBoxLayout(widget); + + QPushButton* deleteButton = new QPushButton(widget); + deleteButton->setIcon(QIcon::fromTheme("window-close-symbolic")); + deleteButton->setFixedSize(80, 80); +// deleteButton->setStyleSheet("QPushButton { border: none; padding: 0; }"); + deleteButton->setCursor(Qt::PointingHandCursor); + layout->addStretch(); + layout->addWidget(deleteButton, 0, Qt::AlignTop | Qt::AlignRight); + + widget->setLayout(layout); + setSizeHint(widget->sizeHint()); + parent->setItemWidget(this, widget); + + } + +//private slots: +// void deleteItem() +// { +// QListWidget* listWidget = qobject_cast(listWidget()); +// listWidget->takeItem(listWidget->row(this)); +// } +}; + class IconThemeWidget : public WidgetBase { @@ -17,15 +74,18 @@ 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; + QListWidget *m_listwidget; }; #endif // ICONTHEMEWIDGET_H diff --git a/src/baseUI/themescheck/themescheck.cpp b/src/baseUI/themescheck/themescheck.cpp index 50b7b95..164e617 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,38 @@ 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; } + +bool ThemesCheck::checkWallpaperDir(QString folderPath) +{ + //检查图片大小。 +// folderPath +} diff --git a/src/baseUI/wallpaperthemewidget.cpp b/src/baseUI/wallpaperthemewidget.cpp index cec8d11..fdb0d6b 100644 --- a/src/baseUI/wallpaperthemewidget.cpp +++ b/src/baseUI/wallpaperthemewidget.cpp @@ -1,7 +1,121 @@ #include "wallpaperthemewidget.h" +#include WallpaperthemeWidget::WallpaperthemeWidget(QWidget *parent) : WidgetBase(parent) { this->initThemeLabel("创建桌面壁纸包"); this->initImportButton("导入图片"); + init(); + connect(m_importButton , &QPushButton::clicked, this, [=](){ + this->importWallpaper(); + }); +} + +void WallpaperthemeWidget::init() +{ + QString name = qgetenv("USER"); + qDebug()<<"QString name = qgetenv;"<setFixedHeight(291); + newWidget->setFixedWidth(480); + m_allLayout->takeAt(1); + + // 创建一个QListView + m_listwidget = new QListWidget(newWidget); + m_listwidget->setViewMode(QListView::IconMode); + m_listwidget->setFixedSize(newWidget->size()); + m_listwidget->setFlow(QListView::LeftToRight); + m_listwidget->setMovement(QListView::Static); + m_listwidget->setIconSize(QSize(100, 56)); + + // 初始化固定路径 + QString fixedPath = m_wallpaperpath; + + // 获取文件列表,并将文件显示在列表视图中 + QStringList fileNames = QDir(fixedPath).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + foreach (QString fileName, fileNames) { + QString imgpath = m_wallpaperpath+fileName; + QListWidgetItem *item = new QListWidgetItem(fileName); + + item->setIcon(QIcon(imgpath)); + m_listwidget->addItem(item); + } + + connect(m_listwidget, &QListWidget::itemDoubleClicked, [&](QListWidgetItem *item) { + + int row = m_listwidget->row(item); + + QString clicked_path = m_wallpaperpath+m_listwidget->currentItem()->data(Qt::DisplayRole).toString(); + + QFile::remove(clicked_path); + m_listwidget->takeItem(row); + delete item; + }); + + // 将新的 widget 插入到 m_allLayout 中 + int index = m_allLayout->indexOf(m_buttonWidget); + qDebug()<< index; + m_allLayout->insertWidget(index, newWidget); +} + +void WallpaperthemeWidget::importWallpaper() +{ + QString filters = tr("Wallpaper files(*.png *.jpg)"); + m_fd= new QFileDialog(this); + m_fd->setFileMode(QFileDialog::Directory); + m_fd->setViewMode(QFileDialog::List); + m_fd->setNameFilter(filters); + m_fd->setFileMode(QFileDialog::ExistingFile); + m_fd->setWindowTitle(tr("Select Import Wallpapers")); + m_fd->setLabelText(QFileDialog::Accept, tr("Select")); + m_fd->setLabelText(QFileDialog::Reject, tr("Cancel")); + + connect(m_fd, &QFileDialog::fileSelected, this, [this](const QString &file){ + + QFileInfo fileInfo(file); + + QListWidgetItem *item = new QListWidgetItem(fileInfo.fileName()); + item->setIcon(QIcon(fileInfo.fileName())); +// item->setSizeHint(QSize(100, 100)); + item->setData(Qt::UserRole, fileInfo.fileName()); + + m_listwidget->addItem(item); + }); + + openFileDialog(); + +} + +void WallpaperthemeWidget::openFileDialog() +{ + if (m_fd->exec() != QDialog::Accepted) + return; + + // if(isLegal){ + + QString path = m_wallpaperpath; + + QDir dir(path); + if (!dir.exists()) { + dir.mkpath(path); + } + QString sourceFilePath = m_fd->selectedFiles().first(); + + if (sourceFilePath.isEmpty()) + return; + + QFileInfo fileInfo(sourceFilePath); + QString destinationFolderPath = m_wallpaperpath; // 替换为目标文件夹的路径 + + QString destinationFilePath = destinationFolderPath + "/" + fileInfo.fileName(); + + QFile::copy(sourceFilePath, destinationFilePath); + + + //选中的图标文件加显示在界面中 + + // } } diff --git a/src/baseUI/wallpaperthemewidget.h b/src/baseUI/wallpaperthemewidget.h index 03bb9bd..a4194e7 100644 --- a/src/baseUI/wallpaperthemewidget.h +++ b/src/baseUI/wallpaperthemewidget.h @@ -4,15 +4,24 @@ #include "widgetbase.h" #include +#include class WallpaperthemeWidget : public WidgetBase { Q_OBJECT public: explicit WallpaperthemeWidget(QWidget *parent = nullptr); + void init(); + void importWallpaper(); + void openFileDialog(); signals: +private: + QFileDialog *m_fd; + QString m_wallpaperpath; + + QListWidget *m_listwidget; }; #endif // WALLPAPERTHEMEWIDGET_H diff --git a/src/baseUI/widgetbase.h b/src/baseUI/widgetbase.h index aade2f1..320ce28 100644 --- a/src/baseUI/widgetbase.h +++ b/src/baseUI/widgetbase.h @@ -9,7 +9,9 @@ #include #include -#include "filecopy.h" +#include "fileoperate.h" + +#define HOMEPATH "/home/" class WidgetBase : public QWidget {