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->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()
{

View file

@ -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;

View file

@ -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 )