diff --git a/src/module/grubthemefeature.cpp b/src/module/grubthemefeature.cpp index 24f191a..4d878cc 100644 --- a/src/module/grubthemefeature.cpp +++ b/src/module/grubthemefeature.cpp @@ -38,45 +38,102 @@ void GrubGraphicsView::wheelEvent(QWheelEvent *event) GrubImageWidget::GrubImageWidget(QWidget *parent) { - QGraphicsScene* scene = new QGraphicsScene(this); - GrubGraphicsView* graphicsView = new GrubGraphicsView(scene); + m_scene = new QGraphicsScene(this); + graphicsView = new GrubGraphicsView(m_scene); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(graphicsView); setLayout(layout); - graphicsView->setScene(scene); + graphicsView->setScene(m_scene); + // 加载并显示背景图片 QPixmap pixmap(":/resource/background/1-warty-final-ubuntukylin.jpg"); - QGraphicsPixmapItem* backgroundItem = new QGraphicsPixmapItem(pixmap); - scene->addItem(backgroundItem); + m_backgroundItem = new QGraphicsPixmapItem(pixmap); + m_backgroundItem->setData(Qt::UserRole, "background"); + m_scene->addItem(m_backgroundItem); // 创建毛玻璃特效并应用于背景图元 QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect; blurEffect->setBlurRadius(10); - backgroundItem->setGraphicsEffect(blurEffect); + m_backgroundItem->setGraphicsEffect(blurEffect); // 设置图元居中显示 QRectF viewRect = graphicsView->viewport()->rect(); QPointF center(viewRect.center()); - backgroundItem->setPos(center.x() - pixmap.width() / 2, center.y() - pixmap.height() / 2); + m_backgroundItem->setPos(center.x() - pixmap.width() / 2, center.y() - pixmap.height() / 2); // 添加新的图元 - QPixmap overlayPixmap(":/resource/background/grub-listview.png"); - QGraphicsPixmapItem* overlayItem = new QGraphicsPixmapItem(overlayPixmap); - scene->addItem(overlayItem); + m_overlayPixmap.load(":/resource/background/grub-listview.png"); + m_overlayItem = new QGraphicsPixmapItem(m_overlayPixmap); + m_scene->addItem(m_overlayItem); // 放大图元 qreal scaleRatio = 2.0; // 放大倍数 - overlayItem->setScale(scaleRatio); + m_overlayItem->setScale(scaleRatio); // 计算新的图元位置 - qreal scaledWidth = overlayPixmap.width() * scaleRatio; // 放大后的宽度 - qreal scaledHeight = overlayPixmap.height() * scaleRatio; // 放大后的高度 - overlayItem->setPos(center.x() - scaledWidth / 2, center.y() - scaledHeight / 2); + qreal scaledWidth = m_overlayPixmap.width() * scaleRatio; // 放大后的宽度 + qreal scaledHeight = m_overlayPixmap.height() * scaleRatio; // 放大后的高度 + m_overlayItem->setPos(center.x() - scaledWidth / 2, center.y() - scaledHeight / 2); - graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); + graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio); graphicsView->show(); // 设置初始缩放倍数为0.9倍 qreal initialScale = 0.4; graphicsView->scale(initialScale, initialScale); } + +void GrubImageWidget::updateBackground(const QString &imagePath) +{ + // 加载新的背景图片 + QPixmap pixmap(imagePath); + + if (pixmap.isNull()) { +// qDebug() << "Failed to load background image.";· + return; + } + + // 移除旧的背景图元 + m_scene->removeItem(m_backgroundItem); + delete m_backgroundItem; + + // 创建并添加新的背景图元 + m_backgroundItem = new QGraphicsPixmapItem(pixmap); + m_backgroundItem->setData(Qt::UserRole, "background"); + m_scene->addItem(m_backgroundItem); + + // 创建毛玻璃特效并应用于新的背景图元 + QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect; + blurEffect->setBlurRadius(10); + m_backgroundItem->setGraphicsEffect(blurEffect); + + // 设置图元居中显示 + QRectF viewRect = graphicsView->viewport()->rect(); + QPointF center(viewRect.center()); + m_backgroundItem->setPos(center.x() - pixmap.width() / 2, center.y() - pixmap.height() / 2); + + // 创建并添加新的overlay图元 + QGraphicsPixmapItem* newOverlayItem = new QGraphicsPixmapItem(m_overlayPixmap); + m_scene->addItem(newOverlayItem); + + // 设置新的overlay图元位置 + qreal scaleRatio = 2.0; // 放大倍数 + qreal scaledWidth = m_overlayPixmap.width() * scaleRatio; // 放大后的宽度 + qreal scaledHeight = m_overlayPixmap.height() * scaleRatio; // 放大后的高度 + newOverlayItem->setPos(center.x() - scaledWidth / 2, center.y() - scaledHeight / 2); + + // 移除旧的overlay图元 + m_scene->removeItem(m_overlayItem); + delete m_overlayItem; + + // 更新overlayItem指针 + m_overlayItem = newOverlayItem; + + graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio); + graphicsView->show(); + + // 设置初始缩放倍数为0.9倍 + qreal initialScale = 0.4; + graphicsView->resetTransform(); + graphicsView->scale(initialScale, initialScale); +} diff --git a/src/module/grubthemefeature.h b/src/module/grubthemefeature.h index f883eb8..c8eb15e 100644 --- a/src/module/grubthemefeature.h +++ b/src/module/grubthemefeature.h @@ -26,13 +26,17 @@ protected: class GrubImageWidget : public QWidget { public: GrubImageWidget(QWidget *parent = nullptr); + void updateBackground(const QString& imagePath); private: GrubGraphicsView* graphicsView; QGraphicsScene* m_scene; QPixmap m_mergedImage; QPixmap m_image; + QGraphicsPixmapItem* m_backgroundItem; + QPixmap m_overlayPixmap; + QGraphicsPixmapItem* m_overlayItem; QGraphicsProxyWidget* m_proxy; }; diff --git a/src/module/grubthemewidget.cpp b/src/module/grubthemewidget.cpp index 6846aa9..359d28c 100644 --- a/src/module/grubthemewidget.cpp +++ b/src/module/grubthemewidget.cpp @@ -1,4 +1,6 @@ #include "grubthemewidget.h" +#include "../fileProcess/filecheck.h" +#include GrubThemeWidget::GrubThemeWidget(QWidget *parent) : QWidget(parent) { @@ -56,6 +58,23 @@ void GrubThemeWidget::initEditWidget() QLabel *tipLabel1 = new QLabel(); tipLabel1->setText("尺寸:3840*2160
大小:不超过 10 MB
格式:PNG"); + connect(showBtn, &QPushButton::clicked, this, [=]() { + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png *.jpg)")); + + if (!newFilePath.isEmpty()/* && FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")*/) { + + m_preview->updateBackground(newFilePath); + QPixmap pixmap(newFilePath); + showBtn->setIcon(QIcon(pixmap)); + showBtn->setIconSize(showBtn->size()); + } else { + qDebug() << "Selected file path:" << newFilePath; + + } + }); + + + widgetLayout->addWidget(showBtn); widgetLayout->addWidget(tipLabel1); grubWidget->setLayout(widgetLayout); diff --git a/src/module/plymouththemefeature.cpp b/src/module/plymouththemefeature.cpp index cb551e0..058b4c3 100644 --- a/src/module/plymouththemefeature.cpp +++ b/src/module/plymouththemefeature.cpp @@ -7,17 +7,17 @@ PlymouthThemeFeature::PlymouthThemeFeature(QWidget *parent) : QWidget(parent) PlymouthImageWidget::PlymouthImageWidget(QWidget *parent) { - QGraphicsScene* scene = new QGraphicsScene(this); - PlymouthGraphicsView* graphicsView = new PlymouthGraphicsView(scene); + scene = new QGraphicsScene(this); + graphicsView = new PlymouthGraphicsView(scene); - QVBoxLayout* layout = new QVBoxLayout(this); + layout = new QVBoxLayout(this); layout->addWidget(graphicsView); setLayout(layout); graphicsView->setScene(scene); // 加载并显示图片 QPixmap pixmap(":/resource/background/openKylin.svg"); - QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(pixmap); + pixmapItem = new QGraphicsPixmapItem(pixmap); scene->addItem(pixmapItem); graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); @@ -28,6 +28,26 @@ PlymouthImageWidget::PlymouthImageWidget(QWidget *parent) graphicsView->scale(initialScale, initialScale); } +void PlymouthImageWidget::updatePlymouth(const QString &imagePath) +{ + // 移除之前的pixmapItem + scene->removeItem(pixmapItem); + delete pixmapItem; + + // 加载新图片 + QPixmap newPixmap(imagePath); + newPixmap = newPixmap.scaled(3000, 3000); + pixmapItem = new QGraphicsPixmapItem(newPixmap); + scene->addItem(pixmapItem); + + // 调整视图 + graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); + //FIX ME :pixmapItem没有放在视图正中间 + // 设置初始缩放倍数为0.9倍 + qreal initialScale = 0.4; + graphicsView->scale(initialScale, initialScale); +} + PlymouthGraphicsView::PlymouthGraphicsView(QGraphicsScene *scene) { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); diff --git a/src/module/plymouththemefeature.h b/src/module/plymouththemefeature.h index 856b8c8..78f5ca5 100644 --- a/src/module/plymouththemefeature.h +++ b/src/module/plymouththemefeature.h @@ -25,14 +25,12 @@ protected: class PlymouthImageWidget : public QWidget { public: PlymouthImageWidget(QWidget *parent = nullptr); + void updatePlymouth(const QString& imagePath); private: PlymouthGraphicsView* graphicsView; - QString m_coverFilePath; - - QGraphicsScene* m_scene; - QPixmap m_mergedImage; - QPixmap m_image; - QGraphicsProxyWidget* m_proxy; + QGraphicsScene* scene; + QGraphicsPixmapItem* pixmapItem; + QVBoxLayout* layout; }; class PlymouthThemeFeature : public QWidget diff --git a/src/module/plymouththemewidget.cpp b/src/module/plymouththemewidget.cpp index 959dfb4..76a4bf2 100644 --- a/src/module/plymouththemewidget.cpp +++ b/src/module/plymouththemewidget.cpp @@ -1,5 +1,5 @@ #include "plymouththemewidget.h" -#include "iconwidgetfeature.h" + PlymouthThemeWidget::PlymouthThemeWidget(QWidget *parent) : QWidget(parent) { @@ -62,19 +62,28 @@ void PlymouthThemeWidget::initEditWidget() QLabel *defaultLabel = new QLabel(); defaultLabel->setFixedSize(64,64); QPixmap pixmap(":/resource/background/openKylin.svg"); - pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); + pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); defaultLabel->setPixmap(pixmap); - CustomLabel *customLabel= new CustomLabel(); - customLabel->setFixedSize(64,64); + m_customLabel= new CustomLabel(); + m_customLabel->setFixedSize(64,64); QPushButton *addButton = new QPushButton(); addButton->setIcon(QIcon::fromTheme("list-add-symbolic")); addButton->setFixedSize(36,36); + connect(addButton, &QPushButton::clicked, this, [=]() { + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), "", tr("SVG file (*.svg *.png)")); + if (!newFilePath.isEmpty()) { + QPixmap pixmap(newFilePath); + pixmap = pixmap.scaled(64,64, Qt::KeepAspectRatio); + m_customLabel->setPixmap(pixmap); + m_preview->updatePlymouth(newFilePath); + } + }); QLabel *tipLabel = new QLabel(); tipLabel->setText("大小不超过10MB
格式:MP4"); showLayout->addWidget(defaultLabel); - showLayout->addWidget(customLabel); + showLayout->addWidget(m_customLabel); showLayout->addWidget(addButton); showLayout->addStretch(1); showLayout->addWidget(tipLabel); diff --git a/src/module/plymouththemewidget.h b/src/module/plymouththemewidget.h index f4a485d..cc4e098 100644 --- a/src/module/plymouththemewidget.h +++ b/src/module/plymouththemewidget.h @@ -1,5 +1,7 @@ #ifndef PLYMOUTHMOUTHTHEMEWIDGET_H #define PLYMOUTHMOUTHTHEMEWIDGET_H +#include "plymouththemefeature.h" +#include "iconwidgetfeature.h" #include #include @@ -8,7 +10,7 @@ #include #include #include -#include "plymouththemefeature.h" + class PlymouthThemeWidget : public QWidget { @@ -26,6 +28,7 @@ private: QWidget *m_rightwidget; QWidget *m_plymouthwidget; QVBoxLayout *m_previewlayout; + CustomLabel *m_customLabel; }; #endif // PLYMOUTHMOUTHTHEMEWIDGET_H