!26 修复内容搜索详情页加载图片失败导致的崩溃问题。

Merge pull request !26 from iaom/bug-fix
This commit is contained in:
纪笑旭 2022-11-18 01:57:21 +00:00 committed by Gitee
commit e46c607beb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 7 additions and 6 deletions

View File

@ -6,7 +6,7 @@
#include <QMessageBox> #include <QMessageBox>
#define OCR_ICONLABLE_WITH 352 #define OCR_ICONLABLE_WITH 352
#define OCR_ICONLABLE_HEIGHT 256 #define OCR_ICONLABLE_HEIGHT 247
using namespace UkuiSearch; using namespace UkuiSearch;
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent) FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
@ -476,15 +476,16 @@ QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri)
{ {
if (1 == ri.type) { if (1 == ri.type) {
QPixmap pixmap; QPixmap pixmap;
pixmap.load(ri.actionKey); if(pixmap.load(ri.actionKey)) {
if (pixmap.width()/OCR_ICONLABLE_WITH > pixmap.height()/OCR_ICONLABLE_HEIGHT) { pixmap = pixmap.scaled(OCR_ICONLABLE_WITH, OCR_ICONLABLE_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmap = pixmap.scaled(OCR_ICONLABLE_WITH, (pixmap.height()*OCR_ICONLABLE_WITH)/pixmap.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); m_detailLyt->setContentsMargins(8, (OCR_ICONLABLE_HEIGHT-pixmap.height())/2 + 8, 16, 0);
} else { } else {
pixmap = pixmap.scaled((pixmap.width()*OCR_ICONLABLE_HEIGHT)/pixmap.height(), OCR_ICONLABLE_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixmap = ri.icon.pixmap(120, 120);
m_detailLyt->setContentsMargins(8, 50, 16, 0);
} }
m_iconLabel->setPixmap(pixmap); m_iconLabel->setPixmap(pixmap);
m_pluginLabel->setText(tr("OCR")); m_pluginLabel->setText(tr("OCR"));
m_detailLyt->setContentsMargins(8, (OCR_ICONLABLE_HEIGHT-pixmap.height())/2+8, 16, 0);
m_snippetLabel->hide(); m_snippetLabel->hide();
} else { } else {
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));