diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 900096b6..3b347567 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -85,18 +85,6 @@ QString ArticleView::scrollToFromDictionaryId( QString const & dictionaryId ) Q_ASSERT( !isScrollTo( dictionaryId ) ); return scrollToPrefix + dictionaryId; } -ArticleView::ArticleView( QWidget * parent, - ArticleNetworkAccessManager & nm, - AudioPlayerPtr const & audioPlayer_, - Config::Class const & cfg_ ): - QWidget( parent ), - articleNetMgr( nm ), - audioPlayer( audioPlayer_ ), - cfg( cfg_ ) -{ - // setup GUI - setupWebview(); -} void ArticleView::setupWebview() { // setup GUI this->webview = new ArticleWebView( this ); @@ -233,6 +221,26 @@ void ArticleView::setupWebview() this->webview->grabGesture( Gestures::GDSwipeGestureType ); #endif } + +void ArticleView::addWebsiteTab( QString name, QString url ) +{ + auto * view = new QWebEngineView( this ); + view->load( url ); + view->setZoomFactor( this->cfg.preferences.zoomFactor ); + int index = tabWidget->count(); + QString escaped = Utils::escapeAmps( name ); + tabWidget->insertTab( index, view, escaped ); +} + +void ArticleView::clearWebsiteTabs() +{ + int index = tabWidget->count(); + // keep the first tab + while ( index-- > 1 ) { + tabWidget->removeTab( index ); + } +} + ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, AudioPlayerPtr const & audioPlayer_, @@ -329,6 +337,7 @@ void ArticleView::showDefinition( QString const & word, Contexts const & contexts_ ) { GlobalBroadcaster::instance()->pronounce_engine.reset(); + clearWebsiteTabs(); currentWord = word.trimmed(); if ( currentWord.isEmpty() ) { return; @@ -376,7 +385,7 @@ void ArticleView::showDefinition( QString const & word, QString mutedDicts = getMutedForGroup( group ); - if ( mutedDicts.size() ) { + if ( !mutedDicts.isEmpty() ) { Utils::Url::addQueryItem( req, "muted", mutedDicts ); } diff --git a/src/ui/articleview.hh b/src/ui/articleview.hh index bdcb0433..67b50710 100644 --- a/src/ui/articleview.hh +++ b/src/ui/articleview.hh @@ -96,11 +96,8 @@ public: QLineEdit const * translateLine, QAction * dictionaryBarToggled = nullptr, unsigned currentGroupId = 0 ); - explicit ArticleView( QWidget * parent, - ArticleNetworkAccessManager & nm, - AudioPlayerPtr const & audioPlayer_, - Config::Class const & cfg_ ); + void openWebsiteInNewTab( QString name, QString url ); void setCurrentGroupId( unsigned currengGrgId ); unsigned getCurrentGroupId(); @@ -171,7 +168,9 @@ public: /// \brief Set background as black if darkreader mode is enabled. void syncBackgroundColorWithCfgDarkReader() const; - void openWebsiteInNewTab( QString name, QString url ); + void addWebsiteTab( QString name, QString url ); + + void clearWebsiteTabs(); private: // widgets diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 5d48a0ad..7cd7615b 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -63,6 +63,7 @@ #include #include +#include #ifdef HAVE_X11 #if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) @@ -3715,11 +3716,6 @@ ArticleView * MainWindow::getCurrentArticleView() { if ( QWidget * cw = ui.tabWidget->currentWidget() ) { auto * pView = dynamic_cast< ArticleView * >( cw ); - if ( pView != nullptr ) { - if ( pView->getParentView() != nullptr ) { - return pView->getParentView(); - } - } return pView; } return nullptr; @@ -4386,7 +4382,7 @@ void MainWindow::openWebsiteInNewTab( QString name, QString url ) // ui.tabWidget->insertTab( index, view, escaped ); // mruList.append( dynamic_cast< QWidget * >( view ) ); - getCurrentArticleView()->addWebsiteTab( name, url ); + getCurrentArticleView()->addWebsiteTab( std::move( name ), url ); } QString MainWindow::unescapeTabHeader( QString const & header )