add grub delete function and fix some UI bugs

This commit is contained in:
likehomedream 2023-12-06 15:42:35 +08:00
parent a3a92b037d
commit ea6e0d0e7d
8 changed files with 120 additions and 12 deletions

View File

@ -221,5 +221,6 @@
<file>resource/plymouth/1.png</file> <file>resource/plymouth/1.png</file>
<file>resource/background/custom-preview.png</file> <file>resource/background/custom-preview.png</file>
<file>resource/background/1-openkylin.jpg</file> <file>resource/background/1-openkylin.jpg</file>
<file>resource/background/grub-background.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 MiB

View File

@ -52,7 +52,7 @@ private:
QString m_coverpath = ":/resource/background/custom-preview.png"; QString m_coverpath = ":/resource/background/custom-preview.png";
QString m_plymouthpath = ":/resource/background/openKylin.svg"; QString m_plymouthpath = ":/resource/background/openKylin.svg";
QString m_plymouthdir = ":/resource/plymouth/"; 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_builderConfig;
// QDir m_buildericons; // QDir m_buildericons;
// QDir m_builderappicon; // QDir m_builderappicon;

View File

@ -150,3 +150,71 @@ void GrubImageWidget::updateBackground(const QString &imagePath)
graphicsView->resetTransform(); graphicsView->resetTransform();
graphicsView->scale(initialScale, initialScale); 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);
}
}

View File

@ -11,6 +11,7 @@
#include <QWheelEvent> #include <QWheelEvent>
#include <QPainter> #include <QPainter>
#include <QtMath> #include <QtMath>
#include <QPushButton>
class GrubGraphicsView : public QGraphicsView { class GrubGraphicsView : public QGraphicsView {
public: 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 { class GrubImageWidget : public QWidget {
public: public:
GrubImageWidget(QWidget *parent = nullptr); GrubImageWidget(QWidget *parent = nullptr);

View File

@ -90,15 +90,17 @@ void GrubThemeWidget::initEditWidget()
QWidget *grubWidget = new QWidget(); QWidget *grubWidget = new QWidget();
QHBoxLayout *widgetLayout = new QHBoxLayout(); QHBoxLayout *widgetLayout = new QHBoxLayout();
m_showBtn = new QPushButton(); m_showBtn = new GrubEditButton();
m_showBtn->setFixedSize(160,100); m_showBtn->setFixedSize(160,100);
QPixmap pixmap(resourceGrubPath);
m_showBtn->setIcon(QIcon(pixmap));
m_showBtn->setIconSize(QSize(130,80));
QLabel *tipLabel1 = new QLabel(); QLabel *tipLabel1 = new QLabel();
tipLabel1->setText("<html>尺寸3840*2160<br>大小:不超过 10 MB<br>格式PNG</html>"); tipLabel1->setText("<html>尺寸3840*2160<br>大小:不超过 10 MB<br>格式PNG</html>");
connect(m_showBtn, &QPushButton::clicked, this, [=]() { 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()) { if (!newFilePath.isEmpty()) {
@ -110,7 +112,7 @@ void GrubThemeWidget::initEditWidget()
QPixmap pixmap(newFilePath); QPixmap pixmap(newFilePath);
// 设置按钮的图标为加载的图片文件对应的图标,并设置图标大小为按钮的大小 // 设置按钮的图标为加载的图片文件对应的图标,并设置图标大小为按钮的大小
m_showBtn->setIcon(QIcon(pixmap)); m_showBtn->setIcon(QIcon(pixmap));
m_showBtn->setIconSize(m_showBtn->size()); m_showBtn->setIconSize(QSize(130,80));
// 发出新的Grub文件路径信号 // 发出新的Grub文件路径信号
emit newGrubFilePath(newFilePath); emit newGrubFilePath(newFilePath);
g_themeChange = true; g_themeChange = true;
@ -119,6 +121,13 @@ void GrubThemeWidget::initEditWidget()
qDebug() << "Selected file path:" << newFilePath; 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(m_showBtn);
widgetLayout->addWidget(tipLabel1); widgetLayout->addWidget(tipLabel1);
@ -131,17 +140,20 @@ void GrubThemeWidget::initEditWidget()
void GrubThemeWidget::eidtInitWidget(const HistoryInfo &InfoData) 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); m_preview->updateBackground(imagedirpath);
QPixmap pixmap(imagedirpath); QPixmap pixmap(imagedirpath);
m_showBtn->setIcon(QIcon(pixmap)); m_showBtn->setIcon(QIcon(pixmap));
m_showBtn->setIconSize(m_showBtn->size()); m_showBtn->setIconSize(QSize(130,80));
} }
void GrubThemeWidget::refresh() void GrubThemeWidget::refresh()
{ {
m_preview->updateBackground(":/resource/background/1-warty-final-ubuntukylin.jpg"); m_preview->updateBackground(resourceGrubPath);
m_showBtn->setIcon(QPixmap()); QPixmap pixmap(resourceGrubPath);
m_showBtn->setIcon(QIcon(pixmap));
m_showBtn->setIconSize(QSize(130,80));
} }
void GrubThemeWidget::addspaceritem() void GrubThemeWidget::addspaceritem()

View File

@ -26,12 +26,13 @@ public:
signals: signals:
void newGrubFilePath(const QString& path); void newGrubFilePath(const QString& path);
private: private:
const QString resourceGrubPath = ":/resource/background/grub-background.png";
QWidget *m_previewwidget; QWidget *m_previewwidget;
GrubImageWidget *m_preview; GrubImageWidget *m_preview;
QWidget *m_rightwidget; QWidget *m_rightwidget;
QWidget *m_grubwidget; QWidget *m_grubwidget;
QVBoxLayout *m_previewlayout; QVBoxLayout *m_previewlayout;
QPushButton *m_showBtn; GrubEditButton *m_showBtn;
}; };
#endif // GRUBTHEMEWIDGET_H #endif // GRUBTHEMEWIDGET_H

View File

@ -194,12 +194,13 @@ void HistoryButton::initUI()
QVBoxLayout* layout = new QVBoxLayout(this); QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* imageLabel = new QLabel; QLabel* imageLabel = new QLabel;
imageLabel->setFixedSize(QSize(208, 137)); imageLabel->setAlignment(Qt::AlignCenter);
layout->addWidget(imageLabel); layout->addWidget(imageLabel);
QString imagePath = nullptr; QString imagePath = nullptr;
if(nullptr == m_coverpath){ if(nullptr == m_coverpath){
imagePath = ":/resource/background/background-light.png"; imagePath = ":/resource/background/custom-preview.png";
}else{ }else{
imagePath = m_coverpath; imagePath = m_coverpath;
}; };