From 2c91b78e136675a90262af83257322a17507cda7 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sun, 3 Nov 2024 17:42:20 +0800 Subject: [PATCH] 1 --- src/ui/articleview.hh | 11 +++++++++++ src/ui/mainwindow.cc | 12 +++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ui/articleview.hh b/src/ui/articleview.hh index fc9d7c70..92c484ff 100644 --- a/src/ui/articleview.hh +++ b/src/ui/articleview.hh @@ -42,6 +42,8 @@ class ArticleView: public QWidget QWebChannel * channel; ArticleViewAgent * agent; + ArticleView * parentView; + AnkiConnector * ankiConnector; QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction, @@ -101,6 +103,15 @@ public: AudioPlayerPtr const & audioPlayer_, Config::Class const & cfg_ ); + void setParentView( ArticleView * parentView_ ) + { + parentView = parentView_; + } + + ArticleView * getParentView() + { + return parentView; + } void setCurrentGroupId( unsigned currengGrgId ); unsigned getCurrentGroupId(); diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index f8248309..e4aadfdb 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -2173,7 +2173,7 @@ void MainWindow::updateBackForwardButtons() { ArticleView * view = getCurrentArticleView(); - if ( view ) { + if ( view != nullptr ) { navBack->setEnabled( view->canGoBack() ); navForward->setEnabled( view->canGoForward() ); } @@ -3714,7 +3714,13 @@ void MainWindow::messageFromAnotherInstanceReceived( QString const & message ) ArticleView * MainWindow::getCurrentArticleView() { if ( QWidget * cw = ui.tabWidget->currentWidget() ) { - return dynamic_cast< ArticleView * >( cw ); + auto * pView = dynamic_cast< ArticleView * >( cw ); + if ( pView != nullptr ) { + if ( pView->getParentView() != nullptr ) { + return pView->getParentView(); + } + } + return pView; } return nullptr; } @@ -4375,7 +4381,7 @@ void MainWindow::openWebsiteInNewTab( QString name, QString url ) QString escaped = Utils::escapeAmps( name ); auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg ); - + view->setParentView( getCurrentArticleView() ); connect( view, &ArticleView::inspectSignal, this, &MainWindow::inspectElement ); view->load( url ); int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();