diff --git a/src/content-widget.cpp b/src/content-widget.cpp index f21628a..72e7566 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -719,3 +719,11 @@ void ContentWidget::setQuicklyOpenList(const QStringList & list) { m_quicklyOpenList = list; } + +/** + * @brief ContentWidget::closeWebView 在主界面失焦消失的时候调用,(若webview未关闭)关闭网页搜索界面 + */ +void ContentWidget::closeWebView() +{ + m_detailView->closeWebWidget(); +} diff --git a/src/content-widget.h b/src/content-widget.h index 05aa168..83390df 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -45,6 +45,7 @@ public: void setContentList(const QStringList&); void setKeyword(QString); void setQuicklyOpenList(const QStringList &); + void closeWebView(); private: void initUI(); void initListView(); diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 18b1e4c..a56be27 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -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; diff --git a/src/control/search-detail-view.h b/src/control/search-detail-view.h index 1f159c9..480e7a4 100644 --- a/src/control/search-detail-view.h +++ b/src/control/search-detail-view.h @@ -44,6 +44,7 @@ public: int getType(); bool isContent = false; void setWebWidget(const QString&); + void closeWebWidget(); protected: void paintEvent(QPaintEvent *); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b20e349..474ea3f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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(); }