Compare commits

...

2 commits

Author SHA1 Message Date
YiFang Xiao 6c63ba45b6 1 2024-11-09 20:40:55 +08:00
YiFang Xiao a9478cdc34 1 2024-11-09 20:17:29 +08:00
5 changed files with 39 additions and 30 deletions

View file

@ -524,7 +524,11 @@ void ArticleRequest::altSearchFinished()
QString requestUrl = Utils::WebSite::urlReplaceWord( QString::fromStdString( url ), word ); QString requestUrl = Utils::WebSite::urlReplaceWord( QString::fromStdString( url ), word );
emit GlobalBroadcaster::instance() emit GlobalBroadcaster::instance()
-> websiteDictionary( QString::fromStdString( activeDict->getName() ), requestUrl ); -> websiteDictionarySignal( QString::fromStdString( activeDict->getName() ), requestUrl );
QStringList dictIds;
dictIds << QString::fromStdString( activeDict->getId() );
ActiveDictIds hittedWord{ group.id, word, dictIds };
emit GlobalBroadcaster::instance() -> dictionaryChanges( hittedWord );
continue; continue;
} }
} }

View file

@ -47,7 +47,7 @@ signals:
void indexingDictionary( QString ); void indexingDictionary( QString );
void websiteDictionary( QString, QString ); void websiteDictionarySignal( QString, QString );
}; };
#endif // GLOBAL_GLOBALBROADCASTER_H #endif // GLOBAL_GLOBALBROADCASTER_H

View file

@ -85,18 +85,6 @@ QString ArticleView::scrollToFromDictionaryId( QString const & dictionaryId )
Q_ASSERT( !isScrollTo( dictionaryId ) ); Q_ASSERT( !isScrollTo( dictionaryId ) );
return scrollToPrefix + 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() void ArticleView::setupWebview()
{ // setup GUI { // setup GUI
this->webview = new ArticleWebView( this ); this->webview = new ArticleWebView( this );
@ -108,9 +96,10 @@ void ArticleView::setupWebview()
auto * baseLayout = new QVBoxLayout( this ); auto * baseLayout = new QVBoxLayout( this );
this->tabWidget = new QTabWidget( this ); this->tabWidget = new QTabWidget( this );
baseLayout->setContentsMargins( 0, 0, 0, 0 );
baseLayout->addWidget( this->tabWidget ); baseLayout->addWidget( this->tabWidget );
QWidget * tab1 = new QWidget( tabWidget ); auto * tab1 = new QWidget( tabWidget );
// Layout // Layout
auto * mainLayout = new QVBoxLayout( tab1 ); auto * mainLayout = new QVBoxLayout( tab1 );
mainLayout->addWidget( this->webview ); mainLayout->addWidget( this->webview );
@ -233,6 +222,26 @@ void ArticleView::setupWebview()
this->webview->grabGesture( Gestures::GDSwipeGestureType ); this->webview->grabGesture( Gestures::GDSwipeGestureType );
#endif #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, ArticleView::ArticleView( QWidget * parent,
ArticleNetworkAccessManager & nm, ArticleNetworkAccessManager & nm,
AudioPlayerPtr const & audioPlayer_, AudioPlayerPtr const & audioPlayer_,
@ -329,6 +338,7 @@ void ArticleView::showDefinition( QString const & word,
Contexts const & contexts_ ) Contexts const & contexts_ )
{ {
GlobalBroadcaster::instance()->pronounce_engine.reset(); GlobalBroadcaster::instance()->pronounce_engine.reset();
clearWebsiteTabs();
currentWord = word.trimmed(); currentWord = word.trimmed();
if ( currentWord.isEmpty() ) { if ( currentWord.isEmpty() ) {
return; return;
@ -376,7 +386,7 @@ void ArticleView::showDefinition( QString const & word,
QString mutedDicts = getMutedForGroup( group ); QString mutedDicts = getMutedForGroup( group );
if ( mutedDicts.size() ) { if ( !mutedDicts.isEmpty() ) {
Utils::Url::addQueryItem( req, "muted", mutedDicts ); Utils::Url::addQueryItem( req, "muted", mutedDicts );
} }

View file

@ -96,11 +96,8 @@ public:
QLineEdit const * translateLine, QLineEdit const * translateLine,
QAction * dictionaryBarToggled = nullptr, QAction * dictionaryBarToggled = nullptr,
unsigned currentGroupId = 0 ); 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 ); void setCurrentGroupId( unsigned currengGrgId );
unsigned getCurrentGroupId(); unsigned getCurrentGroupId();
@ -171,7 +168,9 @@ 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 ); void addWebsiteTab( QString name, QString url );
void clearWebsiteTabs();
private: private:
// widgets // widgets

View file

@ -63,6 +63,7 @@
#include <QWebEngineSettings> #include <QWebEngineSettings>
#include <QProxyStyle> #include <QProxyStyle>
#include <utility>
#ifdef HAVE_X11 #ifdef HAVE_X11
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) #if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
@ -714,7 +715,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
this, this,
&MainWindow::showFTSIndexingName ); &MainWindow::showFTSIndexingName );
connect( GlobalBroadcaster::instance(), connect( GlobalBroadcaster::instance(),
&GlobalBroadcaster::websiteDictionary, &GlobalBroadcaster::websiteDictionarySignal,
this, this,
&MainWindow::openWebsiteInNewTab ); &MainWindow::openWebsiteInNewTab );
@ -2148,7 +2149,7 @@ void MainWindow::updateFoundInDictsList()
if ( dictionaries[ x ]->getId() == i->toUtf8().data() ) { if ( dictionaries[ x ]->getId() == i->toUtf8().data() ) {
QString dictName = QString::fromUtf8( dictionaries[ x ]->getName().c_str() ); QString dictName = QString::fromUtf8( dictionaries[ x ]->getName().c_str() );
QString dictId = QString::fromUtf8( dictionaries[ x ]->getId().c_str() ); QString dictId = QString::fromUtf8( dictionaries[ x ]->getId().c_str() );
QListWidgetItem * item = auto * item =
new QListWidgetItem( dictionaries[ x ]->getIcon(), dictName, ui.dictsList, QListWidgetItem::Type ); new QListWidgetItem( dictionaries[ x ]->getIcon(), dictName, ui.dictsList, QListWidgetItem::Type );
item->setData( Qt::UserRole, QVariant( dictId ) ); item->setData( Qt::UserRole, QVariant( dictId ) );
item->setToolTip( dictName ); item->setToolTip( dictName );
@ -2162,7 +2163,7 @@ void MainWindow::updateFoundInDictsList()
} }
} }
//if no item in dict List panel has been choose ,select first one. //if no item in dict List panel has been choosen ,select first one.
if ( ui.dictsList->count() > 0 && ui.dictsList->selectedItems().empty() ) { if ( ui.dictsList->count() > 0 && ui.dictsList->selectedItems().empty() ) {
ui.dictsList->setCurrentRow( 0 ); ui.dictsList->setCurrentRow( 0 );
} }
@ -3715,11 +3716,6 @@ ArticleView * MainWindow::getCurrentArticleView()
{ {
if ( QWidget * cw = ui.tabWidget->currentWidget() ) { if ( QWidget * cw = ui.tabWidget->currentWidget() ) {
auto * pView = dynamic_cast< ArticleView * >( cw ); auto * pView = dynamic_cast< ArticleView * >( cw );
if ( pView != nullptr ) {
if ( pView->getParentView() != nullptr ) {
return pView->getParentView();
}
}
return pView; return pView;
} }
return nullptr; return nullptr;
@ -4386,7 +4382,7 @@ void MainWindow::openWebsiteInNewTab( QString name, QString url )
// 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 ); getCurrentArticleView()->addWebsiteTab( std::move( name ), url );
} }
QString MainWindow::unescapeTabHeader( QString const & header ) QString MainWindow::unescapeTabHeader( QString const & header )