This commit is contained in:
xiaoyifang 2024-11-04 11:27:46 +08:00
parent 2c91b78e13
commit f9a3705942
3 changed files with 32 additions and 23 deletions

View file

@ -104,8 +104,14 @@ void ArticleView::setupWebview()
this->searchPanel = new SearchPanel( this ); this->searchPanel = new SearchPanel( this );
this->searchPanel->hide(); this->searchPanel->hide();
this->ftsSearchPanel->hide(); this->ftsSearchPanel->hide();
auto * baseLayout = new QVBoxLayout( this );
this->tabWidget = new QTabWidget( this );
baseLayout->addWidget( this->tabWidget );
// Layout // Layout
auto * mainLayout = new QVBoxLayout( this ); auto * mainLayout = new QVBoxLayout( tabWidget );
mainLayout->addWidget( this->webview ); mainLayout->addWidget( this->webview );
mainLayout->addWidget( this->ftsSearchPanel ); mainLayout->addWidget( this->ftsSearchPanel );
mainLayout->addWidget( this->searchPanel ); mainLayout->addWidget( this->searchPanel );
@ -116,7 +122,10 @@ void ArticleView::setupWebview()
mainLayout->setContentsMargins( 0, 0, 0, 0 ); 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->previous, &QPushButton::clicked, this, &ArticleView::on_searchPrevious_clicked );
connect( this->searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked ); connect( this->searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked );
@ -1253,6 +1262,16 @@ void ArticleView::syncBackgroundColorWithCfgDarkReader() const
#endif #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() void ArticleView::back()
{ {

View file

@ -42,8 +42,6 @@ class ArticleView: public QWidget
QWebChannel * channel; QWebChannel * channel;
ArticleViewAgent * agent; ArticleViewAgent * agent;
ArticleView * parentView;
AnkiConnector * ankiConnector; AnkiConnector * ankiConnector;
QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction, QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction,
@ -103,15 +101,6 @@ public:
AudioPlayerPtr const & audioPlayer_, AudioPlayerPtr const & audioPlayer_,
Config::Class const & cfg_ ); Config::Class const & cfg_ );
void setParentView( ArticleView * parentView_ )
{
parentView = parentView_;
}
ArticleView * getParentView()
{
return parentView;
}
void setCurrentGroupId( unsigned currengGrgId ); void setCurrentGroupId( unsigned currengGrgId );
unsigned getCurrentGroupId(); unsigned getCurrentGroupId();
@ -182,9 +171,12 @@ public:
/// \brief Set background as black if darkreader mode is enabled. /// \brief Set background as black if darkreader mode is enabled.
void syncBackgroundColorWithCfgDarkReader() const; void syncBackgroundColorWithCfgDarkReader() const;
void openWebsiteInNewTab( QString name, QString url );
private: private:
// widgets // widgets
ArticleWebView * webview; ArticleWebView * webview;
QTabWidget * tabWidget;
SearchPanel * searchPanel; SearchPanel * searchPanel;
FtsSearchPanel * ftsSearchPanel; FtsSearchPanel * ftsSearchPanel;

View file

@ -4376,18 +4376,16 @@ void MainWindow::showFTSIndexingName( QString const & name )
} }
} }
void MainWindow::openWebsiteInNewTab( QString name, QString url ) void MainWindow::openWebsiteInNewTab( QString name, QString url ){
{ // QString escaped = Utils::escapeAmps( name );
QString escaped = Utils::escapeAmps( name );
auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg ); // auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg );
view->setParentView( getCurrentArticleView() ); // view->load( url );
connect( view, &ArticleView::inspectSignal, this, &MainWindow::inspectElement ); // int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
view->load( url );
int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
ui.tabWidget->insertTab( index, view, escaped ); // ui.tabWidget->insertTab( index, view, escaped );
mruList.append( dynamic_cast< QWidget * >( view ) ); // mruList.append( dynamic_cast< QWidget * >( view ) );
getCurrentArticleView()->addWebsiteTab( name, url );
} }
QString MainWindow::unescapeTabHeader( QString const & header ) QString MainWindow::unescapeTabHeader( QString const & header )