From 6edfd15962cc788992f1f8109d591f14af857e59 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Fri, 1 Nov 2024 14:25:41 +0800 Subject: [PATCH 01/15] opt: add option about open website in seperate tab --- src/config.cc | 8 ++++++++ src/config.hh | 1 + src/ui/preferences.cc | 2 ++ src/ui/preferences.ui | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/src/config.cc b/src/config.cc index 96b3d842..98c5ebfa 100644 --- a/src/config.cc +++ b/src/config.cc @@ -1082,6 +1082,10 @@ Class load() ( preferences.namedItem( "removeInvalidIndexOnExit" ).toElement().text() == "1" ); } + if ( !preferences.namedItem( "openWebsiteInNewTab" ).isNull() ) { + c.preferences.openWebsiteInNewTab = ( preferences.namedItem( "openWebsiteInNewTab" ).toElement().text() == "1" ); + } + if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() ) { c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt(); } @@ -2111,6 +2115,10 @@ void save( Class const & c ) opt.appendChild( dd.createTextNode( c.preferences.removeInvalidIndexOnExit ? "1" : "0" ) ); preferences.appendChild( opt ); + opt = dd.createElement( "openWebsiteInNewTab" ); + opt.appendChild( dd.createTextNode( c.preferences.openWebsiteInNewTab ? "1" : "0" ) ); + preferences.appendChild( opt ); + opt = dd.createElement( "maxStringsInHistory" ); opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) ); preferences.appendChild( opt ); diff --git a/src/config.hh b/src/config.hh index 1a5feaac..32d4c32e 100644 --- a/src/config.hh +++ b/src/config.hh @@ -382,6 +382,7 @@ struct Preferences int maxNetworkCacheSize; bool clearNetworkCacheOnExit; bool removeInvalidIndexOnExit = false; + bool openWebsiteInNewTab = false; qreal zoomFactor; qreal helpZoomFactor; diff --git a/src/ui/preferences.cc b/src/ui/preferences.cc index 9b97c9ef..5a4537cf 100644 --- a/src/ui/preferences.cc +++ b/src/ui/preferences.cc @@ -336,6 +336,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): //Misc ui.removeInvalidIndexOnExit->setChecked( p.removeInvalidIndexOnExit ); + ui.openWebsiteInNewTab->setChecked( p.openWebsiteInNewTab ); // Add-on styles ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 ); @@ -494,6 +495,7 @@ Config::Preferences Preferences::getPreferences() p.clearNetworkCacheOnExit = ui.clearNetworkCacheOnExit->isChecked(); p.removeInvalidIndexOnExit = ui.removeInvalidIndexOnExit->isChecked(); + p.openWebsiteInNewTab = ui.openWebsiteInNewTab->isChecked(); p.addonStyle = ui.addonStyles->getCurrentStyle(); diff --git a/src/ui/preferences.ui b/src/ui/preferences.ui index d616e44c..1ad3018a 100644 --- a/src/ui/preferences.ui +++ b/src/ui/preferences.ui @@ -1916,6 +1916,13 @@ from Stardict, Babylon and GLS dictionaries + + + + Open website dictionary in seperate tab + + + From 9e99389cc3d90c147b39df87ec21bcf1b1491e5a Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sat, 2 Nov 2024 11:37:22 +0800 Subject: [PATCH 02/15] opt: website dictionary render html --- src/dict/website.cc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/dict/website.cc b/src/dict/website.cc index ca03d6b4..974d2dc4 100644 --- a/src/dict/website.cc +++ b/src/dict/website.cc @@ -24,7 +24,6 @@ class WebSiteDictionary: public Dictionary::Class { string name; QByteArray urlTemplate; - bool experimentalIframe; QString iconFilename; bool inside_iframe; QNetworkAccessManager & netMgr; @@ -41,12 +40,8 @@ public: name( name_ ), iconFilename( iconFilename_ ), inside_iframe( inside_iframe_ ), - netMgr( netMgr_ ), - experimentalIframe( false ) + netMgr( netMgr_ ) { - if ( urlTemplate_.startsWith( "http://" ) || urlTemplate_.startsWith( "https://" ) ) { - experimentalIframe = true; - } //else file:/// local dictionary file path urlTemplate = QUrl( urlTemplate_ ).toEncoded(); @@ -335,15 +330,13 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, QUrl url( urlString ); GlobalBroadcaster::instance()->addWhitelist( url.host() ); - QString encodeUrl; - if ( experimentalIframe ) { - encodeUrl = "ifr://localhost?url=" + QUrl::toPercentEncoding( urlString ); - } - else { - encodeUrl = urlString; - } + QString encodeUrl=encodeUrl = urlString; - fmt::format_to( std::back_inserter( result ), + if ( GlobalBroadcaster::instance()->getPreference()->openWebSiteInNewTab ){ + result += string("
this website dictionary is opened in the new tab
"); + } + else{ + fmt::format_to( std::back_inserter( result ), R"()", getId(), encodeUrl.toStdString(), getId() ); - + } auto dr = std::make_shared< DataRequestInstant >( true ); dr->appendString( result ); return dr; From 0d89c4ab5605e8ed9ae0908930de49b03c6708c6 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sat, 2 Nov 2024 11:50:29 +0800 Subject: [PATCH 03/15] 1 --- src/article_maker.cc | 9 +++++++++ src/common/globalbroadcaster.hh | 2 ++ src/ui/mainwindow.cc | 15 +++++++++++++++ src/ui/mainwindow.hh | 1 + 4 files changed, 27 insertions(+) diff --git a/src/article_maker.cc b/src/article_maker.cc index eab66e6c..50bfd0ed 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -513,6 +513,15 @@ void ArticleRequest::altSearchFinished() for ( const auto & activeDict : activeDicts ) { try { + // if the dictionary is website dictionary and openinNewTab is enabled, emit a signal. + if ( GlobalBroadcaster::instance()->getPreference()->openWebsiteInNewTab ) { + if ( activeDict->getFeature() == Dictionary::WebSite ) { + //todo ,replace the word with actual url + emit GlobalBroadcaster::instance() -> websiteDictionary( word,url ); + continue; + } + } + sptr< Dictionary::DataRequest > r = activeDict->getArticle( wordStd, altsVector, diff --git a/src/common/globalbroadcaster.hh b/src/common/globalbroadcaster.hh index 744c03ee..ff8ef705 100644 --- a/src/common/globalbroadcaster.hh +++ b/src/common/globalbroadcaster.hh @@ -46,6 +46,8 @@ signals: void dictionaryClear( ActiveDictIds ad ); void indexingDictionary( QString ); + + void websiteDictionary( QString ); }; #endif // GLOBAL_GLOBALBROADCASTER_H diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 4c60632a..08234a60 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -713,6 +713,10 @@ MainWindow::MainWindow( Config::Class & cfg_ ): &GlobalBroadcaster::indexingDictionary, this, &MainWindow::showFTSIndexingName ); + connect( GlobalBroadcaster::instance(), + &GlobalBroadcaster::websiteDictionary, + this, + &MainWindow::openWebsiteInNewTab ); connect( &GlobalBroadcaster::instance()->pronounce_engine, &PronounceEngine::emitAudio, @@ -4361,6 +4365,17 @@ void MainWindow::showFTSIndexingName( QString const & name ) } } +void MainWindow::openWebsiteInNewTab( QString const & name,QString const & url ) +{ + QString escaped = Utils::escapeAmps( name ); + + auto view = new QWebEngineView(this); + view->load(QUrl(url)); + + ui.tabWidget->insertTab( index, view, escaped ); + mruList.append( dynamic_cast< QWidget * >( view ) ); +} + QString MainWindow::unescapeTabHeader( QString const & header ) { // Reset table header to original headword diff --git a/src/ui/mainwindow.hh b/src/ui/mainwindow.hh index 007f8cfb..5295f5b4 100644 --- a/src/ui/mainwindow.hh +++ b/src/ui/mainwindow.hh @@ -293,6 +293,7 @@ private slots: void openDictionaryFolder( QString const & id ); void showFTSIndexingName( QString const & name ); + void openWebsiteInNewTab( QString const & name,QString const & url ); void handleAddToFavoritesButton(); From 469896bbf12a62ac49ebdeaee8072074042c4655 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sat, 2 Nov 2024 11:55:09 +0800 Subject: [PATCH 04/15] 1 --- src/dict/website.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dict/website.cc b/src/dict/website.cc index 974d2dc4..08f7f6e9 100644 --- a/src/dict/website.cc +++ b/src/dict/website.cc @@ -42,8 +42,6 @@ public: inside_iframe( inside_iframe_ ), netMgr( netMgr_ ) { - //else file:/// local dictionary file path - urlTemplate = QUrl( urlTemplate_ ).toEncoded(); dictionaryDescription = urlTemplate_; } @@ -55,7 +53,9 @@ public: map< Property, string > getProperties() noexcept override { - return map< Property, string >(); + map< Property, string > properties; + properties.insert({ Property::Url, urlTemplate_ } ) ; + return properties; } unsigned long getArticleCount() noexcept override From c00239a1b17f29e933cf7c0381b2256259f2285e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:05:05 +0000 Subject: [PATCH 05/15] [autofix.ci] apply automated fixes --- src/article_maker.cc | 2 +- src/dict/website.cc | 10 +++++----- src/ui/mainwindow.cc | 6 +++--- src/ui/mainwindow.hh | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/article_maker.cc b/src/article_maker.cc index 50bfd0ed..debd7c8e 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -517,7 +517,7 @@ void ArticleRequest::altSearchFinished() if ( GlobalBroadcaster::instance()->getPreference()->openWebsiteInNewTab ) { if ( activeDict->getFeature() == Dictionary::WebSite ) { //todo ,replace the word with actual url - emit GlobalBroadcaster::instance() -> websiteDictionary( word,url ); + emit GlobalBroadcaster::instance() -> websiteDictionary( word, url ); continue; } } diff --git a/src/dict/website.cc b/src/dict/website.cc index 08f7f6e9..ddb3433b 100644 --- a/src/dict/website.cc +++ b/src/dict/website.cc @@ -54,7 +54,7 @@ public: map< Property, string > getProperties() noexcept override { map< Property, string > properties; - properties.insert({ Property::Url, urlTemplate_ } ) ; + properties.insert( { Property::Url, urlTemplate_ } ); return properties; } @@ -330,12 +330,12 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, QUrl url( urlString ); GlobalBroadcaster::instance()->addWhitelist( url.host() ); - QString encodeUrl=encodeUrl = urlString; + QString encodeUrl = encodeUrl = urlString; - if ( GlobalBroadcaster::instance()->getPreference()->openWebSiteInNewTab ){ - result += string("
this website dictionary is opened in the new tab
"); + if ( GlobalBroadcaster::instance()->getPreference()->openWebSiteInNewTab ) { + result += string( "
this website dictionary is opened in the new tab
" ); } - else{ + else { fmt::format_to( std::back_inserter( result ), R"()", - getId(), - encodeUrl.toStdString(), - getId() ); + getId(), + encodeUrl.toStdString(), + getId() ); } auto dr = std::make_shared< DataRequestInstant >( true ); dr->appendString( result ); From c6387df39232bde23809de1a1e59fb69477661e2 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sun, 3 Nov 2024 17:11:02 +0800 Subject: [PATCH 09/15] 1 --- src/ui/articleview.cc | 270 +++++++++++++++++++++++------------------- src/ui/articleview.hh | 8 +- src/ui/mainwindow.cc | 8 +- src/ui/mainwindow.hh | 2 +- 4 files changed, 157 insertions(+), 131 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 722fde5a..fb9b3a8a 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -85,7 +85,144 @@ 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 ); + this->ftsSearchPanel = new FtsSearchPanel( this ); + this->searchPanel = new SearchPanel( this ); + this->searchPanel->hide(); + this->ftsSearchPanel->hide(); + // Layout + auto * mainLayout = new QVBoxLayout( this ); + mainLayout->addWidget( this->webview ); + mainLayout->addWidget( this->ftsSearchPanel ); + mainLayout->addWidget( this->searchPanel ); + this->webview->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + this->ftsSearchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); + this->searchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); + + mainLayout->setContentsMargins( 0, 0, 0, 0 ); + + // 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 ); + connect( this->searchPanel->close, &QPushButton::clicked, this, &ArticleView::on_searchCloseButton_clicked ); + connect( this->searchPanel->caseSensitive, &QCheckBox::toggled, this, &ArticleView::on_searchCaseSensitive_clicked ); + connect( this->searchPanel->lineEdit, &QLineEdit::textEdited, this, &ArticleView::on_searchText_textEdited ); + connect( this->searchPanel->lineEdit, &QLineEdit::returnPressed, this, &ArticleView::on_searchText_returnPressed ); + connect( this->ftsSearchPanel->next, &QPushButton::clicked, this, &ArticleView::on_ftsSearchNext_clicked ); + connect( this->ftsSearchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_ftsSearchPrevious_clicked ); + + // + + this->webview->setUp( const_cast< Config::Class * >( &this->cfg ) ); + + this->syncBackgroundColorWithCfgDarkReader(); + + this->goBackAction.setShortcut( QKeySequence( "Alt+Left" ) ); + this->webview->addAction( &this->goBackAction ); + connect( &this->goBackAction, &QAction::triggered, this, &ArticleView::back ); + + this->goForwardAction.setShortcut( QKeySequence( "Alt+Right" ) ); + this->webview->addAction( &this->goForwardAction ); + connect( &this->goForwardAction, &QAction::triggered, this, &ArticleView::forward ); + + this->webview->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy ); + this->webview->addAction( this->webview->pageAction( QWebEnginePage::Copy ) ); + + QAction * selectAll = this->webview->pageAction( QWebEnginePage::SelectAll ); + selectAll->setShortcut( QKeySequence::SelectAll ); + selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut ); + this->webview->addAction( selectAll ); + + this->webview->setContextMenuPolicy( Qt::CustomContextMenu ); + + connect( this->webview, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished ); + + connect( this->webview, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked ); + + connect( this->webview->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged ); + + connect( this->webview, &QWidget::customContextMenuRequested, this, &ArticleView::contextMenuRequested ); + + connect( this->webview->page(), &QWebEnginePage::linkHovered, this, &ArticleView::linkHovered ); + + connect( this->webview, &ArticleWebView::doubleClicked, this, &ArticleView::doubleClicked ); + + this->pasteAction.setShortcut( QKeySequence::Paste ); + this->webview->addAction( &this->pasteAction ); + connect( &this->pasteAction, &QAction::triggered, this, &ArticleView::pasteTriggered ); + + this->articleUpAction.setShortcut( QKeySequence( "Alt+Up" ) ); + this->webview->addAction( &this->articleUpAction ); + connect( &this->articleUpAction, &QAction::triggered, this, &ArticleView::moveOneArticleUp ); + + this->articleDownAction.setShortcut( QKeySequence( "Alt+Down" ) ); + this->webview->addAction( &this->articleDownAction ); + connect( &this->articleDownAction, &QAction::triggered, this, &ArticleView::moveOneArticleDown ); + + this->selectCurrentArticleAction.setShortcut( QKeySequence( "Ctrl+Shift+A" ) ); + this->selectCurrentArticleAction.setText( tr( "Select Current Article" ) ); + this->webview->addAction( &this->selectCurrentArticleAction ); + connect( &this->selectCurrentArticleAction, &QAction::triggered, this, &ArticleView::selectCurrentArticle ); + + this->copyAsTextAction.setShortcut( QKeySequence( "Ctrl+Shift+C" ) ); + this->copyAsTextAction.setText( tr( "Copy as text" ) ); + this->webview->addAction( &this->copyAsTextAction ); + connect( &this->copyAsTextAction, &QAction::triggered, this, &ArticleView::copyAsText ); + + this->inspectAction.setShortcut( QKeySequence( Qt::Key_F12 ) ); + this->inspectAction.setText( tr( "Inspect" ) ); + this->webview->addAction( &this->inspectAction ); + + + connect( &this->inspectAction, &QAction::triggered, this, &ArticleView::inspectElement ); + + this->webview->installEventFilter( this ); + this->searchPanel->installEventFilter( this ); + this->ftsSearchPanel->installEventFilter( this ); + + QWebEngineSettings * settings = this->webview->settings(); + settings->setUnknownUrlSchemePolicy( QWebEngineSettings::UnknownUrlSchemePolicy::DisallowUnknownUrlSchemes ); +#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) + settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::ErrorPageEnabled, false ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::LinksIncludedInFocusChain, false ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); +#else + settings->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true ); + settings->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true ); + settings->setAttribute( QWebEngineSettings::ErrorPageEnabled, false ); + settings->setAttribute( QWebEngineSettings::LinksIncludedInFocusChain, false ); + settings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false ); + settings->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true ); + settings->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); +#endif + + + this->expandOptionalParts = this->cfg.preferences.alwaysExpandOptionalParts; +#ifndef Q_OS_MACOS + this->webview->grabGesture( Gestures::GDPinchGestureType ); + this->webview->grabGesture( Gestures::GDSwipeGestureType ); +#endif +} ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, AudioPlayerPtr const & audioPlayer_, @@ -115,133 +252,11 @@ ArticleView::ArticleView( QWidget * parent, translateLine( translateLine_ ) { // setup GUI - webview = new ArticleWebView( this ); - ftsSearchPanel = new FtsSearchPanel( this ); - searchPanel = new SearchPanel( this ); - searchPanel->hide(); - ftsSearchPanel->hide(); - // Layout - auto * mainLayout = new QVBoxLayout( this ); - mainLayout->addWidget( webview ); - mainLayout->addWidget( ftsSearchPanel ); - mainLayout->addWidget( searchPanel ); + setupWebview(); - webview->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); - ftsSearchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); - searchPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); - - mainLayout->setContentsMargins( 0, 0, 0, 0 ); - - // end UI setup - - connect( searchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_searchPrevious_clicked ); - connect( searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked ); - connect( searchPanel->close, &QPushButton::clicked, this, &ArticleView::on_searchCloseButton_clicked ); - connect( searchPanel->caseSensitive, &QCheckBox::toggled, this, &ArticleView::on_searchCaseSensitive_clicked ); - connect( searchPanel->lineEdit, &QLineEdit::textEdited, this, &ArticleView::on_searchText_textEdited ); - connect( searchPanel->lineEdit, &QLineEdit::returnPressed, this, &ArticleView::on_searchText_returnPressed ); - connect( ftsSearchPanel->next, &QPushButton::clicked, this, &ArticleView::on_ftsSearchNext_clicked ); - connect( ftsSearchPanel->previous, &QPushButton::clicked, this, &ArticleView::on_ftsSearchPrevious_clicked ); - - // - - webview->setUp( const_cast< Config::Class * >( &cfg ) ); - - syncBackgroundColorWithCfgDarkReader(); - - goBackAction.setShortcut( QKeySequence( "Alt+Left" ) ); - webview->addAction( &goBackAction ); - connect( &goBackAction, &QAction::triggered, this, &ArticleView::back ); - - goForwardAction.setShortcut( QKeySequence( "Alt+Right" ) ); - webview->addAction( &goForwardAction ); - connect( &goForwardAction, &QAction::triggered, this, &ArticleView::forward ); - - webview->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy ); - webview->addAction( webview->pageAction( QWebEnginePage::Copy ) ); - - QAction * selectAll = webview->pageAction( QWebEnginePage::SelectAll ); - selectAll->setShortcut( QKeySequence::SelectAll ); - selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut ); - webview->addAction( selectAll ); - - webview->setContextMenuPolicy( Qt::CustomContextMenu ); - - connect( webview, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished ); - - connect( webview, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked ); - - connect( webview->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged ); - - connect( webview, &QWidget::customContextMenuRequested, this, &ArticleView::contextMenuRequested ); - - connect( webview->page(), &QWebEnginePage::linkHovered, this, &ArticleView::linkHovered ); - - connect( webview, &ArticleWebView::doubleClicked, this, &ArticleView::doubleClicked ); - - pasteAction.setShortcut( QKeySequence::Paste ); - webview->addAction( &pasteAction ); - connect( &pasteAction, &QAction::triggered, this, &ArticleView::pasteTriggered ); - - articleUpAction.setShortcut( QKeySequence( "Alt+Up" ) ); - webview->addAction( &articleUpAction ); - connect( &articleUpAction, &QAction::triggered, this, &ArticleView::moveOneArticleUp ); - - articleDownAction.setShortcut( QKeySequence( "Alt+Down" ) ); - webview->addAction( &articleDownAction ); - connect( &articleDownAction, &QAction::triggered, this, &ArticleView::moveOneArticleDown ); - - selectCurrentArticleAction.setShortcut( QKeySequence( "Ctrl+Shift+A" ) ); - selectCurrentArticleAction.setText( tr( "Select Current Article" ) ); - webview->addAction( &selectCurrentArticleAction ); - connect( &selectCurrentArticleAction, &QAction::triggered, this, &ArticleView::selectCurrentArticle ); - - copyAsTextAction.setShortcut( QKeySequence( "Ctrl+Shift+C" ) ); - copyAsTextAction.setText( tr( "Copy as text" ) ); - webview->addAction( ©AsTextAction ); - connect( ©AsTextAction, &QAction::triggered, this, &ArticleView::copyAsText ); - - inspectAction.setShortcut( QKeySequence( Qt::Key_F12 ) ); - inspectAction.setText( tr( "Inspect" ) ); - webview->addAction( &inspectAction ); - - - connect( &inspectAction, &QAction::triggered, this, &ArticleView::inspectElement ); - - webview->installEventFilter( this ); - searchPanel->installEventFilter( this ); - ftsSearchPanel->installEventFilter( this ); - - QWebEngineSettings * settings = webview->settings(); - settings->setUnknownUrlSchemePolicy( QWebEngineSettings::UnknownUrlSchemePolicy::DisallowUnknownUrlSchemes ); -#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) - settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::ErrorPageEnabled, false ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::LinksIncludedInFocusChain, false ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true ); - settings->defaultSettings()->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); -#else - settings->setAttribute( QWebEngineSettings::LocalContentCanAccessRemoteUrls, true ); - settings->setAttribute( QWebEngineSettings::LocalContentCanAccessFileUrls, true ); - settings->setAttribute( QWebEngineSettings::ErrorPageEnabled, false ); - settings->setAttribute( QWebEngineSettings::LinksIncludedInFocusChain, false ); - settings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false ); - settings->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true ); - settings->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); -#endif - - auto html = articleNetMgr.getHtml( ResourceType::UNTITLE ); - - webview->setHtml( QString::fromStdString( html ) ); - - expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts; -#ifndef Q_OS_MACOS - webview->grabGesture( Gestures::GDPinchGestureType ); - webview->grabGesture( Gestures::GDSwipeGestureType ); -#endif + auto html = this->articleNetMgr.getHtml( ResourceType::UNTITLE ); + this->webview->setHtml( QString::fromStdString( html ) ); connect( GlobalBroadcaster::instance(), &GlobalBroadcaster::dictionaryChanges, this, &ArticleView::setActiveDictIds ); connect( GlobalBroadcaster::instance(), &GlobalBroadcaster::dictionaryClear, this, &ArticleView::dictionaryClear ); @@ -2165,6 +2180,11 @@ void ArticleView::clearContent() webview->setHtml( QString::fromStdString( html ) ); } +void ArticleView::load( QString url ) +{ + webview->load( QUrl( url ) ); +} + ResourceToSaveHandler::ResourceToSaveHandler( ArticleView * view, QString fileName ): QObject( view ), diff --git a/src/ui/articleview.hh b/src/ui/articleview.hh index 58d5b5fa..fc9d7c70 100644 --- a/src/ui/articleview.hh +++ b/src/ui/articleview.hh @@ -96,7 +96,10 @@ public: QLineEdit const * translateLine, QAction * dictionaryBarToggled = nullptr, unsigned currentGroupId = 0 ); - + explicit ArticleView( QWidget * parent, + ArticleNetworkAccessManager & nm, + AudioPlayerPtr const & audioPlayer_, + Config::Class const & cfg_ ); void setCurrentGroupId( unsigned currengGrgId ); unsigned getCurrentGroupId(); @@ -109,7 +112,7 @@ public: ~ArticleView(); - + void load( QString url ); /// Returns "gdfrom-" + dictionaryId. static QString scrollToFromDictionaryId( QString const & dictionaryId ); @@ -412,6 +415,7 @@ private: QString getMutedForGroup( unsigned group ); QStringList getMutedDictionaries( unsigned group ); + void setupWebview(); }; class ResourceToSaveHandler: public QObject diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 28db0f3a..f8248309 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -4370,12 +4370,14 @@ void MainWindow::showFTSIndexingName( QString const & name ) } } -void MainWindow::openWebsiteInNewTab( QString const & name, QString const & url ) +void MainWindow::openWebsiteInNewTab( QString name, QString url ) { QString escaped = Utils::escapeAmps( name ); - auto view = new QWebEngineView( this ); - view->load( QUrl( url ) ); + auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg ); + + connect( view, &ArticleView::inspectSignal, this, &MainWindow::inspectElement ); + view->load( url ); int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count(); ui.tabWidget->insertTab( index, view, escaped ); diff --git a/src/ui/mainwindow.hh b/src/ui/mainwindow.hh index 3172413d..4a153b26 100644 --- a/src/ui/mainwindow.hh +++ b/src/ui/mainwindow.hh @@ -293,7 +293,7 @@ private slots: void openDictionaryFolder( QString const & id ); void showFTSIndexingName( QString const & name ); - void openWebsiteInNewTab( QString const & name, QString const & url ); + void openWebsiteInNewTab( QString name, QString url ); void handleAddToFavoritesButton(); From 2c91b78e136675a90262af83257322a17507cda7 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sun, 3 Nov 2024 17:42:20 +0800 Subject: [PATCH 10/15] 1 --- src/ui/articleview.hh | 11 +++++++++++ src/ui/mainwindow.cc | 12 +++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ui/articleview.hh b/src/ui/articleview.hh index fc9d7c70..92c484ff 100644 --- a/src/ui/articleview.hh +++ b/src/ui/articleview.hh @@ -42,6 +42,8 @@ class ArticleView: public QWidget QWebChannel * channel; ArticleViewAgent * agent; + ArticleView * parentView; + AnkiConnector * ankiConnector; QAction pasteAction, articleUpAction, articleDownAction, goBackAction, goForwardAction, selectCurrentArticleAction, @@ -101,6 +103,15 @@ public: AudioPlayerPtr const & audioPlayer_, Config::Class const & cfg_ ); + void setParentView( ArticleView * parentView_ ) + { + parentView = parentView_; + } + + ArticleView * getParentView() + { + return parentView; + } void setCurrentGroupId( unsigned currengGrgId ); unsigned getCurrentGroupId(); diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index f8248309..e4aadfdb 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -2173,7 +2173,7 @@ void MainWindow::updateBackForwardButtons() { ArticleView * view = getCurrentArticleView(); - if ( view ) { + if ( view != nullptr ) { navBack->setEnabled( view->canGoBack() ); navForward->setEnabled( view->canGoForward() ); } @@ -3714,7 +3714,13 @@ void MainWindow::messageFromAnotherInstanceReceived( QString const & message ) ArticleView * MainWindow::getCurrentArticleView() { if ( QWidget * cw = ui.tabWidget->currentWidget() ) { - return dynamic_cast< ArticleView * >( cw ); + auto * pView = dynamic_cast< ArticleView * >( cw ); + if ( pView != nullptr ) { + if ( pView->getParentView() != nullptr ) { + return pView->getParentView(); + } + } + return pView; } return nullptr; } @@ -4375,7 +4381,7 @@ 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(); From f9a370594284157fbcf36df8584f926c1de70899 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 11:27:46 +0800 Subject: [PATCH 11/15] 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 ) From 701a4effb3ca2a7e4bbf838b8ed1ec0249af6be8 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:29:03 +0000 Subject: [PATCH 12/15] [autofix.ci] apply automated fixes --- src/ui/articleview.cc | 9 +++++---- src/ui/mainwindow.cc | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 665b278e..2dc1f9cd 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -125,7 +125,7 @@ void ArticleView::setupWebview() this->tabWidget->addTab( mainLayout, "Dictionaries" ); this->tabWidget->setTabBarAutoHide( true ); - // end UI setup + // 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 ); @@ -1262,12 +1262,13 @@ void ArticleView::syncBackgroundColorWithCfgDarkReader() const #endif } -void ArticleView::openWebsiteInNewTab( QString name, QString url ) { +void ArticleView::openWebsiteInNewTab( QString name, QString url ) +{ QString escaped = Utils::escapeAmps( name ); -//found existed QWebEngineView. + //found existed QWebEngineView. auto * view = new QWebEngineView( this ); - view->load( QUrl(url) ); + view->load( QUrl( url ) ); tabWidget->addTab( view, escaped ); } diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 402ebf6a..5d48a0ad 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -4376,7 +4376,8 @@ 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 ); // auto * view = new ArticleView( this, articleNetMgr, audioPlayerFactory.player(), cfg ); From c0697ecdda788e1de260610e1f507df9baabae39 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 4 Nov 2024 11:41:50 +0800 Subject: [PATCH 13/15] 1 --- src/ui/articleview.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 2dc1f9cd..900096b6 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -110,8 +110,9 @@ void ArticleView::setupWebview() this->tabWidget = new QTabWidget( this ); baseLayout->addWidget( this->tabWidget ); + QWidget * tab1 = new QWidget( tabWidget ); // Layout - auto * mainLayout = new QVBoxLayout( tabWidget ); + auto * mainLayout = new QVBoxLayout( tab1 ); mainLayout->addWidget( this->webview ); mainLayout->addWidget( this->ftsSearchPanel ); mainLayout->addWidget( this->searchPanel ); @@ -122,7 +123,7 @@ void ArticleView::setupWebview() mainLayout->setContentsMargins( 0, 0, 0, 0 ); - this->tabWidget->addTab( mainLayout, "Dictionaries" ); + this->tabWidget->addTab( tab1, "Dictionaries" ); this->tabWidget->setTabBarAutoHide( true ); // end UI setup From a9478cdc349f096ba36e151b5925d5d16a331efd Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sat, 9 Nov 2024 20:17:29 +0800 Subject: [PATCH 14/15] 1 --- src/ui/articleview.cc | 35 ++++++++++++++++++++++------------- src/ui/articleview.hh | 9 ++++----- src/ui/mainwindow.cc | 8 ++------ 3 files changed, 28 insertions(+), 24 deletions(-) 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 ) From 6c63ba45b69a52efccf7857a9860114457683d4c Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sat, 9 Nov 2024 20:40:55 +0800 Subject: [PATCH 15/15] 1 --- src/article_maker.cc | 6 +++++- src/common/globalbroadcaster.hh | 2 +- src/ui/articleview.cc | 3 ++- src/ui/mainwindow.cc | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/article_maker.cc b/src/article_maker.cc index 70d13b2e..d576792a 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -524,7 +524,11 @@ void ArticleRequest::altSearchFinished() QString requestUrl = Utils::WebSite::urlReplaceWord( QString::fromStdString( url ), word ); 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; } } diff --git a/src/common/globalbroadcaster.hh b/src/common/globalbroadcaster.hh index 36c262b6..1f9112d2 100644 --- a/src/common/globalbroadcaster.hh +++ b/src/common/globalbroadcaster.hh @@ -47,7 +47,7 @@ signals: void indexingDictionary( QString ); - void websiteDictionary( QString, QString ); + void websiteDictionarySignal( QString, QString ); }; #endif // GLOBAL_GLOBALBROADCASTER_H diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 3b347567..4984642b 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -96,9 +96,10 @@ void ArticleView::setupWebview() auto * baseLayout = new QVBoxLayout( this ); this->tabWidget = new QTabWidget( this ); + baseLayout->setContentsMargins( 0, 0, 0, 0 ); baseLayout->addWidget( this->tabWidget ); - QWidget * tab1 = new QWidget( tabWidget ); + auto * tab1 = new QWidget( tabWidget ); // Layout auto * mainLayout = new QVBoxLayout( tab1 ); mainLayout->addWidget( this->webview ); diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 7cd7615b..9569320b 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -715,7 +715,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): this, &MainWindow::showFTSIndexingName ); connect( GlobalBroadcaster::instance(), - &GlobalBroadcaster::websiteDictionary, + &GlobalBroadcaster::websiteDictionarySignal, this, &MainWindow::openWebsiteInNewTab ); @@ -2149,7 +2149,7 @@ void MainWindow::updateFoundInDictsList() if ( dictionaries[ x ]->getId() == i->toUtf8().data() ) { QString dictName = QString::fromUtf8( dictionaries[ x ]->getName().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 ); item->setData( Qt::UserRole, QVariant( dictId ) ); item->setToolTip( dictName ); @@ -2163,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() ) { ui.dictsList->setCurrentRow( 0 ); }