From f9a370594284157fbcf36df8584f926c1de70899 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 11:27:46 +0800 Subject: [PATCH] 1 --- src/ui/articleview.cc | 23 +++++++++++++++++++++-- src/ui/articleview.hh | 14 +++----------- src/ui/mainwindow.cc | 18 ++++++++---------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index fb9b3a8a..665b278e 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -104,8 +104,14 @@ void ArticleView::setupWebview() this->searchPanel = new SearchPanel( this ); this->searchPanel->hide(); this->ftsSearchPanel->hide(); + + auto * baseLayout = new QVBoxLayout( this ); + + this->tabWidget = new QTabWidget( this ); + baseLayout->addWidget( this->tabWidget ); + // Layout - auto * mainLayout = new QVBoxLayout( this ); + auto * mainLayout = new QVBoxLayout( tabWidget ); mainLayout->addWidget( this->webview ); mainLayout->addWidget( this->ftsSearchPanel ); mainLayout->addWidget( this->searchPanel ); @@ -116,7 +122,10 @@ void ArticleView::setupWebview() mainLayout->setContentsMargins( 0, 0, 0, 0 ); - // end UI setup + this->tabWidget->addTab( mainLayout, "Dictionaries" ); + this->tabWidget->setTabBarAutoHide( true ); + + // end UI setup connect( this->searchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_searchPrevious_clicked ); connect( this->searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked ); @@ -1253,6 +1262,16 @@ void ArticleView::syncBackgroundColorWithCfgDarkReader() const #endif } +void ArticleView::openWebsiteInNewTab( QString name, QString url ) { + QString escaped = Utils::escapeAmps( name ); + +//found existed QWebEngineView. + auto * view = new QWebEngineView( this ); + view->load( QUrl(url) ); + + tabWidget->addTab( view, escaped ); +} + void ArticleView::back() { diff --git a/src/ui/articleview.hh b/src/ui/articleview.hh index 92c484ff..bdcb0433 100644 --- a/src/ui/articleview.hh +++ b/src/ui/articleview.hh @@ -42,8 +42,6 @@ class ArticleView: public QWidget QWebChannel * channel; ArticleViewAgent * agent; - ArticleView * parentView; - AnkiConnector * ankiConnector; QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction, @@ -103,15 +101,6 @@ public: AudioPlayerPtr const & audioPlayer_, Config::Class const & cfg_ ); - void setParentView( ArticleView * parentView_ ) - { - parentView = parentView_; - } - - ArticleView * getParentView() - { - return parentView; - } void setCurrentGroupId( unsigned currengGrgId ); unsigned getCurrentGroupId(); @@ -182,9 +171,12 @@ public: /// \brief Set background as black if darkreader mode is enabled. void syncBackgroundColorWithCfgDarkReader() const; + void openWebsiteInNewTab( QString name, QString url ); + private: // widgets ArticleWebView * webview; + QTabWidget * tabWidget; SearchPanel * searchPanel; FtsSearchPanel * ftsSearchPanel; diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index e4aadfdb..402ebf6a 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -4376,18 +4376,16 @@ void MainWindow::showFTSIndexingName( QString const & name ) } } -void MainWindow::openWebsiteInNewTab( QString name, QString url ) -{ - QString escaped = Utils::escapeAmps( name ); +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(); + // auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg ); + // view->load( url ); + // int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count(); - ui.tabWidget->insertTab( index, view, escaped ); - mruList.append( dynamic_cast< QWidget * >( view ) ); + // ui.tabWidget->insertTab( index, view, escaped ); + // mruList.append( dynamic_cast< QWidget * >( view ) ); + getCurrentArticleView()->addWebsiteTab( name, url ); } QString MainWindow::unescapeTabHeader( QString const & header )