Skip to content

Commit

Permalink
fix: [thumbnail] The file thumbnail is not displayed in the file deta…
Browse files Browse the repository at this point in the history
…il 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
  • Loading branch information
Kakueeen committed Jul 21, 2023
1 parent fdc0304 commit cc2c962
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/dfm-base/file/local/asyncfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void AsyncFileInfo::refresh()
d->extraProperties.clear();
d->attributesExtend.clear();
d->extendIDs.clear();
d->fileIcon = QIcon();
extendOtherCache.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "detailview.h"

#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/thumbnail/thumbnailhelper.h>

#include <dfm-framework/dpf.h>

Expand Down Expand Up @@ -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<QIcon>();
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);
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins/common/dfmplugin-dirshare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -34,6 +35,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
DFM::base
DFM::extension
Qt5::Svg
Qt5::Network
${DtkWidget_LIBRARIES}
)

Expand Down

0 comments on commit cc2c962

Please sign in to comment.