From f5e2a20160c6a6a1dd5f7824e7443fa61526154d Mon Sep 17 00:00:00 2001 From: liuzhangjian Date: Fri, 21 Jul 2023 17:49:00 +0800 Subject: [PATCH] fix: [thumbnail] The file thumbnail is not displayed in the file detail view If the file has a thumbnail, replace the default icon with the thumbnail Log: fix bug Bug: https://pms.uniontech.com/bug-view-211009.html --- src/dfm-base/file/local/asyncfileinfo.cpp | 1 + .../views/detailview.cpp | 20 +++++++++++++++---- .../common/dfmplugin-dirshare/CMakeLists.txt | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/dfm-base/file/local/asyncfileinfo.cpp b/src/dfm-base/file/local/asyncfileinfo.cpp index 7ec1e66285..9e776946e0 100644 --- a/src/dfm-base/file/local/asyncfileinfo.cpp +++ b/src/dfm-base/file/local/asyncfileinfo.cpp @@ -84,6 +84,7 @@ void AsyncFileInfo::refresh() d->extraProperties.clear(); d->attributesExtend.clear(); d->extendIDs.clear(); + d->fileIcon = QIcon(); extendOtherCache.clear(); } } diff --git a/src/plugins/filemanager/core/dfmplugin-detailspace/views/detailview.cpp b/src/plugins/filemanager/core/dfmplugin-detailspace/views/detailview.cpp index 1444872dce..0c82a7d2eb 100644 --- a/src/plugins/filemanager/core/dfmplugin-detailspace/views/detailview.cpp +++ b/src/plugins/filemanager/core/dfmplugin-detailspace/views/detailview.cpp @@ -5,6 +5,7 @@ #include "detailview.h" #include +#include #include @@ -149,11 +150,22 @@ void DetailView::createHeadUI(const QUrl &url, int widgetFilter) }; // get icon from plugin + QIcon icon; const QString &iconName = findPluginIcon(info->urlOf(UrlInfoType::kUrl)); - if (!iconName.isEmpty()) - iconLabel->setPixmap(QIcon::fromTheme(iconName).pixmap(targetSize)); - else - iconLabel->setPixmap(info->fileIcon().pixmap(targetSize)); + if (!iconName.isEmpty()) { + icon = QIcon::fromTheme(iconName); + } else if (ThumbnailHelper::instance()->checkThumbEnable(url)) { + icon = info->extendAttributes(ExtInfoType::kFileThumbnail).value(); + if (icon.isNull()) { + const auto &img = ThumbnailHelper::instance()->thumbnailImage(url, Global::kLarge); + icon = QPixmap::fromImage(img); + } + } + + if (icon.isNull()) + icon = info->fileIcon(); + + iconLabel->setPixmap(icon.pixmap(targetSize)); iconLabel->setAlignment(Qt::AlignCenter); iconLabel->setContentsMargins(0, 0, 0, 15); vLayout->insertWidget(0, iconLabel, 0, Qt::AlignHCenter); diff --git a/tests/plugins/common/dfmplugin-dirshare/CMakeLists.txt b/tests/plugins/common/dfmplugin-dirshare/CMakeLists.txt index b7392a4f98..b0b32a76cc 100644 --- a/tests/plugins/common/dfmplugin-dirshare/CMakeLists.txt +++ b/tests/plugins/common/dfmplugin-dirshare/CMakeLists.txt @@ -15,6 +15,7 @@ file(GLOB_RECURSE SRC_FILES find_package(Dtk COMPONENTS Widget REQUIRED) find_package(Qt5 COMPONENTS DBus REQUIRED) find_package(Qt5 COMPONENTS Svg REQUIRED) +find_package(Qt5 COMPONENTS Network REQUIRED) add_executable(${PROJECT_NAME} ${SRC_FILES} @@ -34,6 +35,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE DFM::base DFM::extension Qt5::Svg + Qt5::Network ${DtkWidget_LIBRARIES} )