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