Skip to content

Commit

Permalink
优化背景加载性能问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gfdgd-xi committed Dec 24, 2024
1 parent 6ee9c4b commit 6161997
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dde-file-manager-lib/dde-file-manager-lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ RESOURCES += \
HEADERS += \
controllers/appcontroller.h \
views/dfilemanagerwindowbackground.h \
views/dfmbackgroundsettingdialog.h \
views/dfmsidebaropticaldevitem.h \
views/dtoolbar.h \
views/dfileview.h \
Expand Down Expand Up @@ -271,6 +272,7 @@ HEADERS += \
SOURCES += \
controllers/appcontroller.cpp \
views/dfilemanagerwindowbackground.cpp \
views/dfmbackgroundsettingdialog.cpp \
views/dfmsidebaropticaldevitem.cpp \
views/dtoolbar.cpp \
views/dfileview.cpp \
Expand Down
1 change: 1 addition & 0 deletions dde-file-manager-lib/views/dfilemanagerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
21 changes: 15 additions & 6 deletions dde-file-manager-lib/views/dfilemanagerwindowbackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#include <DThemeManager>
#include <QDebug>
#include <QDir>
#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();
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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();
Expand All @@ -160,6 +168,7 @@ void DFileManagerWindowBackground::refresh()
}
m_imageVar.append(image);
}
resizeImage();
// 读取默认 logo
//m_fmLogo = QImage(":/images/images/fm-logo.png");

Expand Down
12 changes: 12 additions & 0 deletions dde-file-manager-lib/views/dfilemanagerwindowbackground.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions dde-file-manager-lib/views/dfmbackgroundsettingdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*#include "dfmbackgroundsettingdialog.h"
#include <QGridLayout>
#include <QFileDialog>
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<QPushButton *>(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;
}
}*/

30 changes: 30 additions & 0 deletions dde-file-manager-lib/views/dfmbackgroundsettingdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef DFMBACKGROUNDSETTINGDIALOG_H
#define DFMBACKGROUNDSETTINGDIALOG_H

/*#include <ddialog.h>
#include <QGridLayout>
#include <QPushButton>
#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<QPushButton *> m_settingButtonList;
DFileManagerWindowBackground m_backgroundManager;
};*/


#endif // DFMBACKGROUNDSETTINGDIALOG_H

0 comments on commit 6161997

Please sign in to comment.