diff --git a/resource.qrc b/resource.qrc
index 7c8e427..d3d7d6e 100644
--- a/resource.qrc
+++ b/resource.qrc
@@ -221,5 +221,6 @@
resource/plymouth/1.png
resource/background/custom-preview.png
resource/background/1-openkylin.jpg
+ resource/background/grub-background.png
diff --git a/resource/background/grub-background.png b/resource/background/grub-background.png
new file mode 100644
index 0000000..c3f8cee
Binary files /dev/null and b/resource/background/grub-background.png differ
diff --git a/src/fileProcess/bridge.h b/src/fileProcess/bridge.h
index 0b07416..8fa892f 100644
--- a/src/fileProcess/bridge.h
+++ b/src/fileProcess/bridge.h
@@ -52,7 +52,7 @@ private:
QString m_coverpath = ":/resource/background/custom-preview.png";
QString m_plymouthpath = ":/resource/background/openKylin.svg";
QString m_plymouthdir = ":/resource/plymouth/";
- QString m_grubpath = ":/resource/background/1-warty-final-ubuntukylin.jpg";
+ QString m_grubpath = ":/resource/background/grub-background.png";
// QDir m_builderConfig;
// QDir m_buildericons;
// QDir m_builderappicon;
diff --git a/src/module/grubthemefeature.cpp b/src/module/grubthemefeature.cpp
index 234ccc9..f202f70 100644
--- a/src/module/grubthemefeature.cpp
+++ b/src/module/grubthemefeature.cpp
@@ -150,3 +150,71 @@ void GrubImageWidget::updateBackground(const QString &imagePath)
graphicsView->resetTransform();
graphicsView->scale(initialScale, initialScale);
}
+
+GrubEditButton::GrubEditButton(QWidget *parent) : closeIconRect(0, 0, 0, 0)
+{
+ this->setMouseTracking(true);
+ this->setFixedSize(160,100);
+ initializeCloseIconRect();
+}
+
+void GrubEditButton::showCloseIcon()
+{
+ closeIconPixmap = QIcon::fromTheme("window-close-symbolic").pixmap(10, 10);
+ this->update();
+}
+
+void GrubEditButton::hideCloseIcon()
+{
+ closeIconPixmap = QPixmap(); // 将关闭图标的pixmap置空
+ update(); // 重新绘制以清除关闭图标
+}
+
+void GrubEditButton::initializeCloseIconRect()
+{
+ closeIconRect = QRect(width() - 15, 5, 10, 10);
+}
+
+void GrubEditButton::drawCloseIcon(QPainter &painter)
+{
+ if(!closeIconPixmap.isNull()){
+ painter.drawPixmap(closeIconRect, closeIconPixmap);
+ }
+}
+
+void GrubEditButton::paintEvent(QPaintEvent *event)
+{
+ QPushButton::paintEvent(event);
+ QPainter painter(this);
+ if (!pixmap.isNull()) {
+ painter.drawPixmap(rect(), pixmap);
+ }
+ drawCloseIcon(painter); // 调用绘制关闭图标的函数
+}
+
+void GrubEditButton::enterEvent(QEvent *event)
+{
+ QPushButton::enterEvent(event);
+ showCloseIcon(); // 在这个函数中显示“x”图标
+
+}
+
+void GrubEditButton::leaveEvent(QEvent *event)
+{
+ QPushButton::leaveEvent(event);
+ hideCloseIcon(); // 在这个函数中隐藏“x”图标
+}
+
+void GrubEditButton::mousePressEvent(QMouseEvent *event)
+{
+
+ if (closeIconRect.contains(event->pos())) {
+ emit deleteCustomPic();
+ hideCloseIcon(); // 在这个函数中隐藏“x”图标
+ } else {
+ // 处理其他点击事件
+ QPushButton::mousePressEvent(event);
+ }
+
+}
+
diff --git a/src/module/grubthemefeature.h b/src/module/grubthemefeature.h
index c8eb15e..7d6bed3 100644
--- a/src/module/grubthemefeature.h
+++ b/src/module/grubthemefeature.h
@@ -11,6 +11,7 @@
#include
#include
#include
+#include
class GrubGraphicsView : public QGraphicsView {
public:
@@ -23,6 +24,30 @@ protected:
};
+class GrubEditButton : public QPushButton {
+ Q_OBJECT
+public:
+ GrubEditButton(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 deleteCustomPic();
+private:
+ QRect closeIconRect;
+ QPixmap pixmap;
+ QPixmap closeIconPixmap;
+};
+
class GrubImageWidget : public QWidget {
public:
GrubImageWidget(QWidget *parent = nullptr);
diff --git a/src/module/grubthemewidget.cpp b/src/module/grubthemewidget.cpp
index 07544dc..1eda8ec 100644
--- a/src/module/grubthemewidget.cpp
+++ b/src/module/grubthemewidget.cpp
@@ -90,15 +90,17 @@ void GrubThemeWidget::initEditWidget()
QWidget *grubWidget = new QWidget();
QHBoxLayout *widgetLayout = new QHBoxLayout();
- m_showBtn = new QPushButton();
+ m_showBtn = new GrubEditButton();
m_showBtn->setFixedSize(160,100);
-
+ QPixmap pixmap(resourceGrubPath);
+ m_showBtn->setIcon(QIcon(pixmap));
+ m_showBtn->setIconSize(QSize(130,80));
QLabel *tipLabel1 = new QLabel();
tipLabel1->setText("尺寸:3840*2160
大小:不超过 10 MB
格式:PNG");
connect(m_showBtn, &QPushButton::clicked, this, [=]() {
// 弹出文件选择对话框,选择图片文件
- QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png *.jpg)"));
+ QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png)"));
// 如果选择的文件路径不为空
if (!newFilePath.isEmpty()) {
@@ -110,7 +112,7 @@ void GrubThemeWidget::initEditWidget()
QPixmap pixmap(newFilePath);
// 设置按钮的图标为加载的图片文件对应的图标,并设置图标大小为按钮的大小
m_showBtn->setIcon(QIcon(pixmap));
- m_showBtn->setIconSize(m_showBtn->size());
+ m_showBtn->setIconSize(QSize(130,80));
// 发出新的Grub文件路径信号
emit newGrubFilePath(newFilePath);
g_themeChange = true;
@@ -119,6 +121,13 @@ void GrubThemeWidget::initEditWidget()
qDebug() << "Selected file path:" << newFilePath;
}
});
+ connect(m_showBtn,&GrubEditButton::deleteCustomPic,this,[=](){
+ m_preview->updateBackground(resourceGrubPath);
+ QPixmap pixmap(resourceGrubPath);
+ m_showBtn->setIcon(QIcon(pixmap));
+ m_showBtn->setIconSize(QSize(130,80));
+ emit newGrubFilePath(resourceGrubPath);
+ });
widgetLayout->addWidget(m_showBtn);
widgetLayout->addWidget(tipLabel1);
@@ -131,17 +140,20 @@ void GrubThemeWidget::initEditWidget()
void GrubThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
{
- QString imagedirpath = InfoData.filepath+"/src/grubTheme/background.jpg";
+ QString imagedirpath = InfoData.filepath+"/src/grubTheme/background.png";
+
m_preview->updateBackground(imagedirpath);
QPixmap pixmap(imagedirpath);
m_showBtn->setIcon(QIcon(pixmap));
- m_showBtn->setIconSize(m_showBtn->size());
+ m_showBtn->setIconSize(QSize(130,80));
}
void GrubThemeWidget::refresh()
{
- m_preview->updateBackground(":/resource/background/1-warty-final-ubuntukylin.jpg");
- m_showBtn->setIcon(QPixmap());
+ m_preview->updateBackground(resourceGrubPath);
+ QPixmap pixmap(resourceGrubPath);
+ m_showBtn->setIcon(QIcon(pixmap));
+ m_showBtn->setIconSize(QSize(130,80));
}
void GrubThemeWidget::addspaceritem()
diff --git a/src/module/grubthemewidget.h b/src/module/grubthemewidget.h
index 6773cdc..b56f7de 100644
--- a/src/module/grubthemewidget.h
+++ b/src/module/grubthemewidget.h
@@ -26,12 +26,13 @@ public:
signals:
void newGrubFilePath(const QString& path);
private:
+ const QString resourceGrubPath = ":/resource/background/grub-background.png";
QWidget *m_previewwidget;
GrubImageWidget *m_preview;
QWidget *m_rightwidget;
QWidget *m_grubwidget;
QVBoxLayout *m_previewlayout;
- QPushButton *m_showBtn;
+ GrubEditButton *m_showBtn;
};
#endif // GRUBTHEMEWIDGET_H
diff --git a/src/module/historywidget.cpp b/src/module/historywidget.cpp
index 980aec3..1aeef3d 100644
--- a/src/module/historywidget.cpp
+++ b/src/module/historywidget.cpp
@@ -194,12 +194,13 @@ void HistoryButton::initUI()
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* imageLabel = new QLabel;
- imageLabel->setFixedSize(QSize(208, 137));
+ imageLabel->setAlignment(Qt::AlignCenter);
+
layout->addWidget(imageLabel);
QString imagePath = nullptr;
if(nullptr == m_coverpath){
- imagePath = ":/resource/background/background-light.png";
+ imagePath = ":/resource/background/custom-preview.png";
}else{
imagePath = m_coverpath;
};