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;
}
/**
* @brief ContentWidget::closeWebView webview未关闭
*/
void ContentWidget::closeWebView()
{
m_detailView->closeWebWidget();
}

View File

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

View File

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

View File

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

View File

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