解决内容搜索插件详情页加载大图片时阻塞ui的问题
This commit is contained in:
parent
b0159fb2cb
commit
243a2874e7
|
@ -296,7 +296,7 @@ bool AppSearchPlugin::launch(const QString &path)
|
|||
if(reply.isValid()) {
|
||||
res = reply;
|
||||
} else {
|
||||
qWarning() << "SoftWareCenter dbus called failed!";
|
||||
qWarning() << "AppManager dbus called failed!";
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -431,10 +431,19 @@ FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(pare
|
|||
SearchPluginIface::Actioninfo CopyPath { 2, tr("Copy Path")};
|
||||
m_actionInfo << open << Openpath << CopyPath;
|
||||
m_pool.setMaxThreadCount(1);
|
||||
m_thumbnailPool.setMaxThreadCount(1);
|
||||
m_pool.setExpiryTimeout(1000);
|
||||
initDetailPage();
|
||||
}
|
||||
|
||||
FileContengSearchPlugin::~FileContengSearchPlugin()
|
||||
{
|
||||
m_pool.clear();
|
||||
m_thumbnailPool.clear();
|
||||
m_thumbnailPool.waitForDone();
|
||||
m_pool.waitForDone();
|
||||
}
|
||||
|
||||
const QString FileContengSearchPlugin::name()
|
||||
{
|
||||
return "File Content Search";
|
||||
|
@ -469,6 +478,8 @@ void FileContengSearchPlugin::stopSearch()
|
|||
SearchManager::m_mutexContent.lock();
|
||||
++SearchManager::uniqueSymbolContent;
|
||||
SearchManager::m_mutexContent.unlock();
|
||||
m_thumbnailPool.clear();
|
||||
m_pool.clear();
|
||||
}
|
||||
|
||||
QList<SearchPluginIface::Actioninfo> FileContengSearchPlugin::getActioninfo(int type)
|
||||
|
@ -497,17 +508,27 @@ void FileContengSearchPlugin::openAction(int actionkey, QString key, int type)
|
|||
|
||||
QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri)
|
||||
{
|
||||
if(ri.actionKey == m_currentActionKey) {
|
||||
return m_detailPage;
|
||||
}
|
||||
if (1 == ri.type) {
|
||||
QPixmap pixmap;
|
||||
if(pixmap.load(ri.actionKey)) {
|
||||
pixmap = pixmap.scaled(OCR_ICONLABLE_WITH, OCR_ICONLABLE_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
auto creator = new ThumbnailCreator(ri.actionKey);
|
||||
connect(creator, &ThumbnailCreator::ready, this, [&](QString uri, const QImage &image){
|
||||
if(uri != m_currentActionKey) {
|
||||
return;
|
||||
}
|
||||
QPixmap pixmap = QPixmap::fromImage(image);
|
||||
if(!pixmap.isNull()) {
|
||||
m_iconLabel->setPixmap(pixmap.scaled(OCR_ICONLABLE_WITH, OCR_ICONLABLE_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
m_detailLyt->setContentsMargins(8, (OCR_ICONLABLE_HEIGHT-pixmap.height())/2 + 8, 16, 0);
|
||||
} else {
|
||||
pixmap = ri.icon.pixmap(120, 120);
|
||||
m_detailLyt->setContentsMargins(8, 50, 16, 0);
|
||||
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
m_thumbnailPool.start(creator);
|
||||
|
||||
m_iconLabel->setPixmap(pixmap);
|
||||
m_iconLabel->setPixmap({});
|
||||
m_detailLyt->setContentsMargins(8, 50, 16, 0);
|
||||
m_pluginLabel->setText(tr("OCR"));
|
||||
m_snippetLabel->hide();
|
||||
} else {
|
||||
|
@ -686,3 +707,14 @@ void FileContengSearchPlugin::initDetailPage()
|
|||
//{
|
||||
// return nullptr;
|
||||
//}
|
||||
|
||||
ThumbnailCreator::ThumbnailCreator(QString url, QObject *parent): QObject(parent)
|
||||
{
|
||||
setAutoDelete(true);
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
void ThumbnailCreator::run()
|
||||
{
|
||||
Q_EMIT ready(m_url, QImage(m_url));
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ class LIBSEARCH_EXPORT FileContengSearchPlugin : public QObject, public SearchPl
|
|||
Q_OBJECT
|
||||
public:
|
||||
FileContengSearchPlugin(QObject *parent = nullptr);
|
||||
~FileContengSearchPlugin();
|
||||
PluginType pluginType() {return PluginType::SearchPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
|
@ -201,6 +202,22 @@ private:
|
|||
bool m_enable = true;
|
||||
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
||||
QThreadPool m_pool;
|
||||
QThreadPool m_thumbnailPool;
|
||||
};
|
||||
class ThumbnailCreator : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThumbnailCreator(QString url, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void ready(QString url, const QImage &image);
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue