!59 Add Icon snd Cursor delete function
Merge pull request !59 from likehomedream/add-delete
This commit is contained in:
commit
0a45396344
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(); // 重新绘制以清除关闭图标
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(); // 重新绘制以清除关闭图标
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue