!59 Add Icon snd Cursor delete function

Merge pull request !59 from likehomedream/add-delete
This commit is contained in:
KevinDuan 2023-11-27 08:26:52 +00:00 committed by Gitee
commit 0a45396344
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 281 additions and 17 deletions

View File

@ -385,23 +385,27 @@ bool ConfigFileManager::copyFileContent(const QString &sourceFilePath, const QSt
*/
bool ConfigFileManager::copyIcontoCacheDir(QMap<QString, QString> *map, QDir cachedir)
{
bool success = true;
// Delete files not in the map
QStringList fileList = cachedir.entryList(QDir::Files);
for (const QString &file : fileList) {
if (!map->values().contains(cachedir.filePath(file))) {
QFile::remove(cachedir.filePath(file));
}
}
// Copy files from map to cache directory
for (auto it = map->begin(); it != map->end(); ++it)
{
QString key = it.key();
QString value = it.value();
// if (value.startsWith(":/resource")){
// continue;
// }
QFile inputFile(value);
QFileInfo fileInfo(inputFile.fileName());
QString destinationPath = cachedir.filePath(key + "." + fileInfo.completeSuffix());
if(fileInfo.baseName() != key){
QFile outFile(destinationPath);
outFile.remove();
}
if (!inputFile.exists()){
success = false;
continue;

View File

@ -64,6 +64,7 @@ signals:
void timeCursorMapChanged(QMap<QString, QString> *systemiconsmap);
void plymouthPathChanged(QString path);
void grubPathChanged(QString path);
void deleteIcon(QString widgetName);
void startCopy();
void gohomesignals();

View File

@ -360,6 +360,8 @@ CursorEditWidget::CursorEditWidget(QWidget *parent)
m_iconwidgetlayout->addWidget(m_tiplabel);
this->setLayout(m_iconwidgetlayout);
connect(m_icondecustomlabel,&CursorCustomLabel::deleteCustomIcon,this,&CursorEditWidget::deleteCustomIcon);
}
void CursorEditWidget::setdefaulticon(QString iconname)
@ -372,9 +374,21 @@ void CursorEditWidget::setcustomicon(QString iconFilePath)
QPixmap pixmap(iconFilePath);
m_icondecustomlabel->setPixmap(pixmap.scaled(48, 48));
}
CursorCustomLabel::CursorCustomLabel(QWidget *parent): QLabel(parent), pixmap()
{
this->setFixedSize(48,48);
initializeCloseIconRect();
}
/**
* @brief
*
*
*/
void CursorCustomLabel::initializeCloseIconRect()
{
closeIconRect = QRect(width() - 15, 5, 10, 10);
}
/**
@ -406,10 +420,105 @@ void CursorCustomLabel::paintEvent(QPaintEvent *event)
if (!pixmap.isNull()) {
painter.drawPixmap(rect(), pixmap);
}
drawCloseIcon(painter); // 调用绘制关闭图标的函数
}
/**
* @brief
*
* 使
*
* @param painter
*/
void CursorCustomLabel::drawCloseIcon(QPainter &painter)
{
if (!closeIconPixmap.isNull()) {
painter.drawPixmap(closeIconRect, closeIconPixmap);
}
}
/**
* @brief QPixmap
*
* CustomLabel QPixmap
*
* @param pixmap QPixmap
*/
void CursorCustomLabel::setPixmap(const QPixmap &pixmap)
{
this->pixmap = pixmap; // 使用赋值操作来更新 pixmap
this->pixmap = pixmap;
update();
}
/**
* @brief
*
* CustomLabel
*
* @param event
*/
void CursorCustomLabel::enterEvent(QEvent *event)
{
QWidget::enterEvent(event);
if(!this->pixmap.isNull()){
showCloseIcon(); // 在这个函数中显示“x”图标
}else{
qDebug()<<"pixmap is null";
}
}
/**
* @brief
*
* QWidget::leaveEvent() x
*
* @param event
*/
void CursorCustomLabel::leaveEvent(QEvent *event)
{
QWidget::leaveEvent(event);
hideCloseIcon(); // 在这个函数中隐藏“x”图标
}
/**
* @brief
*
*
*
*
* @param event
*/
void CursorCustomLabel::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
if (closeIconRect.contains(event->pos())) {
setPixmap(QPixmap()); // 点击“x”时将 Icon 显示为空
hideCloseIcon(); // 在这个函数中隐藏“x”图标
emit deleteCustomIcon();
} else {
// 处理其他点击事件
}
}
/**
* @brief
*
* Pixmap从主题中加载
*/
void CursorCustomLabel::showCloseIcon()
{
closeIconPixmap = QIcon::fromTheme("window-close-symbolic").pixmap(10, 10);
this->update();
}
/**
* @brief
*
* pixmap置空
*/
void CursorCustomLabel::hideCloseIcon()
{
closeIconPixmap = QPixmap(); // 将关闭图标的pixmap置空
update(); // 重新绘制以清除关闭图标
}

View File

@ -29,16 +29,28 @@
class CursorCustomLabel : public QLabel
{
Q_OBJECT
public:
explicit CursorCustomLabel(QWidget* parent = nullptr);
void setPixmap(const QPixmap& pixmap);
void initializeCloseIconRect();
void hideCloseIcon();
void showCloseIcon();
void drawCloseIcon(QPainter &painter);
signals:
void deleteCustomIcon();
protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent *event);
void leaveEvent(QEvent *event);
void enterEvent(QEvent *event);
private:
QRect closeIconRect;
QPixmap pixmap;
QPixmap closeIconPixmap;
};
@ -51,7 +63,8 @@ public:
void setcustomicon(QString iconFilePath);
QPushButton *m_addiconbutton;
signals:
void deleteCustomIcon();
private:
QHBoxLayout *m_iconwidgetlayout;
QLabel *m_icondefaultlabel;
@ -79,7 +92,6 @@ public:
void updateImage(const QString& imagePath);
void updateIconMap(const QMap<QString, QString>* newIconMap);
void setIconMap(QMap<QString,QString>*);
private:
const QMap<QString,QString>* m_iconMap;
CursorGraphicsView* graphicsView;

View File

@ -259,6 +259,12 @@ void CursorThemeWidget::initRightWidget()
}
}
});
connect(widget,&CursorEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/cursor/"+widgetName+".png";
m_preview->updateIcon(widgetName, iconPath);
m_customiconpathmap->insert(widgetName, iconPath);
emit newCursorMap(m_customiconpathmap);
});
}
for (const auto& pair : sortedList2) {
@ -300,6 +306,12 @@ void CursorThemeWidget::initRightWidget()
}
}
});
connect(widget,&CursorEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/time-cursor/"+widgetName+".png";
m_preview2->updateIcon(widgetName, iconPath);
m_timecustomiconpathmap->insert(widgetName, iconPath);
emit newTimeCursorMap(m_timecustomiconpathmap);
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout();

View File

@ -121,6 +121,12 @@ void IconThemeWidget::initEditWidget()
}
}
});
connect(widget,&IconEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/appicons/"+widgetName+".png";
m_preview->updateIcon(widgetName, iconPath);
m_customiconpathmap->insert(widgetName, iconPath);
emit newAppIconsMap(m_customiconpathmap);
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_editwidget);
@ -271,6 +277,12 @@ void IconThemeWidget::initSystemEditWidget()
}
}
});
connect(widget,&IconEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/systemicons/"+widgetName+".png";
m_systempreview->updateIcon(widgetName, iconPath);
m_systemcustomiconpathmap->insert(widgetName, iconPath);
emit newSystemIconsMap(m_systemcustomiconpathmap);
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_systemeditwidget);

View File

@ -45,7 +45,6 @@ signals:
void wallpaperupdate(const QString& filePath);
void newAppIconsMap(QMap<QString, QString> *appiconsmap);
void newSystemIconsMap(QMap<QString, QString> *systemiconsmap);
private:
QStringList getWidgetNamesFromFilesInDirectory(const QString& directoryPath);

View File

@ -1,4 +1,4 @@
#include "iconwidgetfeature.h"
#include "iconwidgetfeature.h"
MainInterFaceFeature::MainInterFaceFeature(QWidget *parent) : QWidget(parent)
{
@ -476,7 +476,7 @@ IconEditWidget::IconEditWidget(QWidget *parent)
frame->setLayout(innerLayout);
widgetLayout->addWidget(frame);
connect(m_icondecustomlabel,&CustomLabel::deleteCustomIcon,this,&IconEditWidget::deleteCustomIcon);
}
/**
@ -523,9 +523,21 @@ void IconEditWidget::setcustomicon(QString iconFilePath)
*
* @param parent
*/
CustomLabel::CustomLabel(QWidget *parent): QLabel(parent), pixmap()
CustomLabel::CustomLabel(QWidget *parent) : QLabel(parent), pixmap(), closeIconRect(0, 0, 0, 0)
{
this->setMouseTracking(true);
this->setFixedSize(48,48);
initializeCloseIconRect();
}
/**
* @brief
*
*
*/
void CustomLabel::initializeCloseIconRect()
{
closeIconRect = QRect(width() - 15, 5, 10, 10);
}
/**
@ -546,7 +558,6 @@ void CustomLabel::paintEvent(QPaintEvent *event)
QBrush brush(QColor("#F5F5F5"));
painter.setBrush(brush);
QRect roundedRect = rect().adjusted(1, 1, -1, -1);
QPainterPath path;
int radius = 6;
@ -556,6 +567,21 @@ void CustomLabel::paintEvent(QPaintEvent *event)
if (!pixmap.isNull()) {
painter.drawPixmap(rect(), pixmap);
}
drawCloseIcon(painter); // 调用绘制关闭图标的函数
}
/**
* @brief
*
* 使
*
* @param painter
*/
void CustomLabel::drawCloseIcon(QPainter &painter)
{
if (!closeIconPixmap.isNull()) {
painter.drawPixmap(closeIconRect, closeIconPixmap);
}
}
/**
@ -571,3 +597,78 @@ void CustomLabel::setPixmap(const QPixmap &pixmap)
update();
}
/**
* @brief
*
* CustomLabel
*
* @param event
*/
void CustomLabel::enterEvent(QEvent *event)
{
QWidget::enterEvent(event);
if(!this->pixmap.isNull()){
showCloseIcon(); // 在这个函数中显示“x”图标
}else{
qDebug()<<"pixmap is null";
}
}
/**
* @brief
*
* QWidget::leaveEvent() x
*
* @param event
*/
void CustomLabel::leaveEvent(QEvent *event)
{
QWidget::leaveEvent(event);
hideCloseIcon(); // 在这个函数中隐藏“x”图标
}
/**
* @brief
*
*
*
*
* @param event
*/
void CustomLabel::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
if (closeIconRect.contains(event->pos())) {
setPixmap(QPixmap()); // 点击“x”时将 Icon 显示为空
hideCloseIcon(); // 在这个函数中隐藏“x”图标
emit deleteCustomIcon();
} else {
// 处理其他点击事件
}
}
/**
* @brief
*
* Pixmap从主题中加载
*/
void CustomLabel::showCloseIcon()
{
closeIconPixmap = QIcon::fromTheme("window-close-symbolic").pixmap(10, 10);
this->update();
}
/**
* @brief
*
* pixmap置空
*/
void CustomLabel::hideCloseIcon()
{
closeIconPixmap = QPixmap(); // 将关闭图标的pixmap置空
update(); // 重新绘制以清除关闭图标
}

View File

@ -48,7 +48,9 @@ public:
protected:
void wheelEvent(QWheelEvent* event) override;
};
class ImageWidget : public QWidget {
Q_OBJECT
public:
ImageWidget(QWidget *parent = nullptr, const QMap<QString,QString>* iconMap = nullptr);
void updateIcon(const QString& widgetName, const QString& newFilePath);
@ -62,16 +64,27 @@ private:
};
class CustomLabel : public QLabel {
Q_OBJECT
public:
explicit CustomLabel(QWidget* parent = nullptr);
void setPixmap(const QPixmap& pixmap);
void showCloseIcon();
void hideCloseIcon();
void initializeCloseIconRect();
void drawCloseIcon(QPainter &painter);
protected:
void paintEvent(QPaintEvent* event) override;
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mousePressEvent(QMouseEvent *event);
signals:
void deleteCustomIcon();
private:
QRect closeIconRect;
QPixmap pixmap;
QPixmap closeIconPixmap;
};
class IconEditWidget : public QWidget
@ -84,7 +97,8 @@ public:
void setcustomicon(QString iconFilePath);
QLabel *m_label;
QPushButton *m_addiconbutton;
signals:
void deleteCustomIcon();
private:
QLabel *m_icondefaultlabel;