From 6161997f3fe1864d8355f105a8eea49b11cceced Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Tue, 24 Dec 2024 23:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=83=8C=E6=99=AF=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dde-file-manager-lib/dde-file-manager-lib.pro | 2 + .../views/dfilemanagerwindow.cpp | 1 + .../views/dfilemanagerwindowbackground.cpp | 21 +++++-- .../views/dfilemanagerwindowbackground.h | 12 ++++ .../views/dfmbackgroundsettingdialog.cpp | 60 +++++++++++++++++++ .../views/dfmbackgroundsettingdialog.h | 30 ++++++++++ 6 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 dde-file-manager-lib/views/dfmbackgroundsettingdialog.cpp create mode 100644 dde-file-manager-lib/views/dfmbackgroundsettingdialog.h diff --git a/dde-file-manager-lib/dde-file-manager-lib.pro b/dde-file-manager-lib/dde-file-manager-lib.pro index eb3f3d4..996d04d 100644 --- a/dde-file-manager-lib/dde-file-manager-lib.pro +++ b/dde-file-manager-lib/dde-file-manager-lib.pro @@ -81,6 +81,7 @@ RESOURCES += \ HEADERS += \ controllers/appcontroller.h \ views/dfilemanagerwindowbackground.h \ + views/dfmbackgroundsettingdialog.h \ views/dfmsidebaropticaldevitem.h \ views/dtoolbar.h \ views/dfileview.h \ @@ -271,6 +272,7 @@ HEADERS += \ SOURCES += \ controllers/appcontroller.cpp \ views/dfilemanagerwindowbackground.cpp \ + views/dfmbackgroundsettingdialog.cpp \ views/dfmsidebaropticaldevitem.cpp \ views/dtoolbar.cpp \ views/dfileview.cpp \ diff --git a/dde-file-manager-lib/views/dfilemanagerwindow.cpp b/dde-file-manager-lib/views/dfilemanagerwindow.cpp index 288d085..4fad1a7 100644 --- a/dde-file-manager-lib/views/dfilemanagerwindow.cpp +++ b/dde-file-manager-lib/views/dfilemanagerwindow.cpp @@ -842,6 +842,7 @@ void DFileManagerWindow::resizeEvent(QResizeEvent *event) { Q_D(DFileManagerWindow); DMainWindow::resizeEvent(event); + m_backgroundManager->resizeImage(); d->titleFrame->setFixedSize(event->size().width() - titlebar()->buttonAreaWidth(), TITLE_FIXED_HEIGHT); } diff --git a/dde-file-manager-lib/views/dfilemanagerwindowbackground.cpp b/dde-file-manager-lib/views/dfilemanagerwindowbackground.cpp index 7a398d5..6a0caa4 100644 --- a/dde-file-manager-lib/views/dfilemanagerwindowbackground.cpp +++ b/dde-file-manager-lib/views/dfilemanagerwindowbackground.cpp @@ -3,11 +3,17 @@ #include #include #include +#include "ddialog.h" DWIDGET_USE_NAMESPACE DFileManagerWindowBackground::DFileManagerWindowBackground(DMainWindow *window) { + /*m_imageTranslateList = {QObject::tr("TopLeft"), QObject::tr("TopCenter"), QObject::tr("TopRight"), + QObject::tr("CenterLeft"), QObject::tr("Center"), QObject::tr("CenterRight"), + QObject::tr("BottomLeft"), QObject::tr("BottomCenter"), QObject::tr("BottomRight"), + // 特殊的一类 + QObject::tr("FullWindow")};*/ setMainWindow(window); refresh(); } @@ -70,11 +76,17 @@ void DFileManagerWindowBackground::setMainWindow(DMainWindow *window) m_dmainWindow = window; } +void DFileManagerWindowBackground::resizeImage() +{ + m_backgroundResized = m_imageVar[BackgroundPlace::FullWindow].scaled(m_dmainWindow->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); +} + QImage DFileManagerWindowBackground::getImage(BackgroundPlace place) { if (place == BackgroundPlace::FullWindow) { // 拉伸图片 - return m_imageVar[place].scaled(m_dmainWindow->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + return m_backgroundResized; + //return m_imageVar[place].scaled(m_dmainWindow->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); } return m_imageVar[place]; } @@ -135,11 +147,7 @@ void DFileManagerWindowBackground::refresh() { QString theme = DThemeManager::instance()->theme(m_dmainWindow); - QStringList imageName = {"TopLeft", "TopCenter", "TopRight", - "CenterLeft", "Center", "CenterRight", - "BottomLeft", "BottomCenter", "BottomRight", - // 特殊的一类 - "FullWindow"}; + QStringList imageName = m_imageList; QStringList imagePath = {}; // 清空列表 m_imageVar.clear(); @@ -160,6 +168,7 @@ void DFileManagerWindowBackground::refresh() } m_imageVar.append(image); } + resizeImage(); // 读取默认 logo //m_fmLogo = QImage(":/images/images/fm-logo.png"); diff --git a/dde-file-manager-lib/views/dfilemanagerwindowbackground.h b/dde-file-manager-lib/views/dfilemanagerwindowbackground.h index 32115a3..81cd63b 100644 --- a/dde-file-manager-lib/views/dfilemanagerwindowbackground.h +++ b/dde-file-manager-lib/views/dfilemanagerwindowbackground.h @@ -24,9 +24,20 @@ class DFileManagerWindowBackground // 特殊的一类 FullWindow = 9 }; + QStringList m_imageList = {"TopLeft", "TopCenter", "TopRight", + "CenterLeft", "Center", "CenterRight", + "BottomLeft", "BottomCenter", "BottomRight", + // 特殊的一类 + "FullWindow"}; + QStringList m_imageTranslateList = {"TopLeft", "TopCenter", "TopRight", + "CenterLeft", "Center", "CenterRight", + "BottomLeft", "BottomCenter", "BottomRight", + // 特殊的一类 + "FullWindow"}; DFileManagerWindowBackground(DMainWindow *window); void refresh(); + void resizeImage(); void setMainWindow(DMainWindow *window); QImage getImage(BackgroundPlace place); @@ -40,6 +51,7 @@ class DFileManagerWindowBackground DMainWindow *m_dmainWindow; bool m_showFMLogo = true; QImage m_fmLogo; + QImage m_backgroundResized; /*QImage m_topLeft_image; QImage m_topCenter_image; QImage m_topRight_image; diff --git a/dde-file-manager-lib/views/dfmbackgroundsettingdialog.cpp b/dde-file-manager-lib/views/dfmbackgroundsettingdialog.cpp new file mode 100644 index 0000000..03478e6 --- /dev/null +++ b/dde-file-manager-lib/views/dfmbackgroundsettingdialog.cpp @@ -0,0 +1,60 @@ +/*#include "dfmbackgroundsettingdialog.h" +#include +#include + +DFMBackgroundSettingDialog::DFMBackgroundSettingDialog(QWidget *parent) : DDialog(parent) +{ + for (QString i: m_backgroundManager.m_imageTranslateList) { + QPushButton *button = new QPushButton(this); + button->setText(i); + button->setToolTip(tr("Set background: ") + i); + m_settingButtonList.append(button); + connect(button, &QPushButton::clicked, this, &DFMBackgroundSettingDialog::setBackgroundButtonClick); + } + for (int i = 0; i < 9; ++i) { + m_mainLayout.addWidget(m_settingButtonList[i], i / 3, i % 3); + } + m_mainWidget.setLayout(&m_mainLayout); + + // 添加 QWidget 至 DDialog + addContent(&m_mainWidget, Qt::AlignmentFlag::AlignCenter); +} + +void DFMBackgroundSettingDialog::setBackgroundButtonClick() +{ + QPushButton *clickedButton = static_cast(sender()); + int buttonIndex = -1; + // 寻找点击按钮对应的编号 + for (int i = 0; i < m_settingButtonList.count(); ++i) { + if (m_settingButtonList[i] == clickedButton) { + buttonIndex = i; + break; + } + } + if (buttonIndex == -1) { + return; + } + // 获取位置 + QString place = m_backgroundManager.m_imageList.at(buttonIndex); + QString filePath = QFileDialog::getOpenFileName(this, "", QDir::homePath(), "图像文件 (*.jpg);;所有文件 (*.*)"); + if (filePath == NULL || filePath == "") { + return; + } + setBackground(filePath, "light", place); + setBackground(filePath, "dark", place); + +} + +void DFMBackgroundSettingDialog::setBackground(QString filePath, QString theme, QString place) +{ + +} + +// 释放内存 +DFMBackgroundSettingDialog::~DFMBackgroundSettingDialog() +{ + for (QPushButton *i: m_settingButtonList) { + delete i; + } +}*/ + diff --git a/dde-file-manager-lib/views/dfmbackgroundsettingdialog.h b/dde-file-manager-lib/views/dfmbackgroundsettingdialog.h new file mode 100644 index 0000000..893e669 --- /dev/null +++ b/dde-file-manager-lib/views/dfmbackgroundsettingdialog.h @@ -0,0 +1,30 @@ +#ifndef DFMBACKGROUNDSETTINGDIALOG_H +#define DFMBACKGROUNDSETTINGDIALOG_H + +/*#include +#include +#include + +#include "dfilemanagerwindowbackground.h" + +DWIDGET_USE_NAMESPACE + +class DFMBackgroundSettingDialog: public DDialog +{ +public: + DFMBackgroundSettingDialog(QWidget *parent); + ~DFMBackgroundSettingDialog(); + +private: + void setBackgroundButtonClick(); + void setBackground(QString filePath, QString theme, QString place); + + QWidget m_mainWidget; + QGridLayout m_mainLayout; + QList m_settingButtonList; + DFileManagerWindowBackground m_backgroundManager; + +};*/ + + +#endif // DFMBACKGROUNDSETTINGDIALOG_H