fix(frontend): Close webview when mainwindow focused out.

Description: 主界面失焦消失时关闭网页搜索详情页

Log: 主界面失焦消失时关闭网页搜索详情页
This commit is contained in:
zhangjiaping 2021-02-23 10:16:41 +08:00
parent 5cf3423052
commit 812daf056d
5 changed files with 22 additions and 6 deletions

View File

@ -719,3 +719,11 @@ void ContentWidget::setQuicklyOpenList(const QStringList & list)
{ {
m_quicklyOpenList = list; m_quicklyOpenList = list;
} }
/**
* @brief ContentWidget::closeWebView webview未关闭
*/
void ContentWidget::closeWebView()
{
m_detailView->closeWebWidget();
}

View File

@ -45,6 +45,7 @@ public:
void setContentList(const QStringList&); void setContentList(const QStringList&);
void setKeyword(QString); void setKeyword(QString);
void setQuicklyOpenList(const QStringList &); void setQuicklyOpenList(const QStringList &);
void closeWebView();
private: private:
void initUI(); void initUI();
void initListView(); void initListView();

View File

@ -77,10 +77,7 @@ void SearchDetailView::clearLayout() {
m_hLine_2->hide(); m_hLine_2->hide();
m_optionView->hide(); m_optionView->hide();
m_isEmpty = true; m_isEmpty = true;
if (m_webView) { closeWebWidget();
m_webView->close();
m_webView = NULL;
}
// m_reload = false; // m_reload = false;
} }
@ -138,8 +135,7 @@ void SearchDetailView::setWebWidget(const QString& keyword)
}); });
connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) { connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) {
if (m_reload) { if (m_reload) {
m_webView->close(); closeWebWidget();
m_webView = NULL;
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
}); });
@ -164,6 +160,14 @@ void SearchDetailView::setWebWidget(const QString& keyword)
m_webView->show(); m_webView->show();
} }
void SearchDetailView::closeWebWidget()
{
if (m_webView) {
m_webView->close();
m_webView = NULL;
}
}
QString SearchDetailView::getHtmlText(const QString & text, const QString & keyword) { QString SearchDetailView::getHtmlText(const QString & text, const QString & keyword) {
QString htmlString; QString htmlString;
bool boldOpenned = false; bool boldOpenned = false;

View File

@ -44,6 +44,7 @@ public:
int getType(); int getType();
bool isContent = false; bool isContent = false;
void setWebWidget(const QString&); void setWebWidget(const QString&);
void closeWebWidget();
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);

View File

@ -382,6 +382,7 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
switch (event->response_type & ~0x80) { switch (event->response_type & ~0x80) {
case XCB_FOCUS_OUT: case XCB_FOCUS_OUT:
this->hide(); this->hide();
m_contentFrame->closeWebView();
m_search_result_thread->requestInterruption(); m_search_result_thread->requestInterruption();
m_search_result_thread->quit(); m_search_result_thread->quit();
break; break;
@ -394,6 +395,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
{ {
if (event->key() == Qt::Key_Escape) { if (event->key() == Qt::Key_Escape) {
this->hide(); this->hide();
m_contentFrame->closeWebView();
m_search_result_thread->requestInterruption(); m_search_result_thread->requestInterruption();
m_search_result_thread->quit(); m_search_result_thread->quit();
} }