diff --git a/.clang-format b/.clang-format index 57e959c2..cc210a4c 100644 --- a/.clang-format +++ b/.clang-format @@ -48,6 +48,7 @@ ExperimentalAutoDetectBinPacking: true FixNamespaceComments: false IncludeBlocks: Regroup IndentCaseLabels: true +IndentAccessModifiers: false IndentPPDirectives: BeforeHash MaxEmptyLinesToKeep: 2 NamespaceIndentation: Inner diff --git a/.clang-tidy b/.clang-tidy index 02b85527..4cb47c91 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,6 +16,7 @@ Checks: > -bugprone-easily-swappable-parameters, -bugprone-reserved-identifier, -cppcoreguidelines-owning-memory, + -cppcoreguidelines-prefer-member-initializer, -google-default-arguments, -misc-non-private-member-variables-in-classes, -misc-const-correctness, diff --git a/CMakeLists.txt b/CMakeLists.txt index cb547812..6812c101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +133,6 @@ set(QRC_RESOURCES set(UI_SRC about.ui - articleview.ui authentication.ui chineseconversion.ui dictgroupwidget.ui diff --git a/articleview.cc b/articleview.cc index 1ad89c9d..64ae5138 100644 --- a/articleview.cc +++ b/articleview.cc @@ -13,7 +13,6 @@ #include "weburlrequestinterceptor.h" #include "wildcard.hh" #include "wstring_qt.hh" -#include #include #include #include @@ -226,7 +225,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au QAction * dictionaryBarToggled_, GroupComboBox const * groupComboBox_ ): - QFrame( parent ), + QWidget( parent ), articleNetMgr( nm ), audioPlayer( audioPlayer_ ), allDictionaries( allDictionaries_ ), @@ -250,84 +249,171 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au ftsSearchMatchCase( false ), ftsPosition( 0 ) { - ui.setupUi( this ); + // setup GUI + webview = new ArticleWebView( this ); - ui.definition->setUp( const_cast< Config::Class * >( &cfg ) ); + // fts Search Panel + ftsSearchPanel = new QWidget( this ); + + auto * ftsLayout = new QHBoxLayout( ftsSearchPanel ); + ftsSearchPrevious = new QPushButton( ftsSearchPanel ); + ftsSearchNext = new QPushButton( ftsSearchPanel ); + ftsSearchStatusLabel = new QLabel( ftsSearchPanel ); + + ftsLayout->addWidget( ftsSearchPrevious ); + ftsLayout->addWidget( ftsSearchNext ); + ftsLayout->addWidget( ftsSearchStatusLabel ); + + ftsSearchPrevious->setIcon( QIcon( ":/icons/previous.svg" ) ); + ftsSearchNext->setIcon( QIcon( ":/icons/next.svg" ) ); + + ftsSearchPrevious->setText( tr( "&Previous" ) ); + ftsSearchNext->setText( tr( "&Next" ) ); + + ftsLayout->addStretch(); + + // Search Panel + searchPanel = new QWidget( this ); + + auto * searchLabel = new QLabel( tr( "Find:" ) ); + + searchText = new QLineEdit( searchPanel ); + + searchCloseButton = new QPushButton( searchPanel ); + searchCloseButton->setIcon( QIcon( ":/icons/closetab.svg" ) ); + + searchPrevious = new QPushButton( searchPanel ); + searchPrevious->setIcon( QIcon( ":/icons/previous.svg" ) ); + searchPrevious->setText( tr( "&Previous" ) ); + + searchNext = new QPushButton( searchPanel ); + searchNext->setIcon( QIcon( ":/icons/next.svg" ) ); + searchNext->setText( tr( "&Next" ) ); + + highlightAllButton = new QCheckBox( searchPanel ); + highlightAllButton->setIcon( QIcon( ":/icons/highlighter.png" ) ); + highlightAllButton->setText( tr( "Highlight &all" ) ); + highlightAllButton->setChecked( true ); + + searchCaseSensitive = new QCheckBox( searchPanel ); + searchCaseSensitive->setText( tr( "&Case Sensitive" ) ); + + auto * searchEditRow = new QHBoxLayout; + searchEditRow->addWidget( searchLabel ); + searchEditRow->addWidget( searchText ); + searchEditRow->addWidget( searchCloseButton ); + + auto * searchButtonsRow = new QHBoxLayout; + searchButtonsRow->addWidget( searchPrevious ); + searchButtonsRow->addWidget( searchNext ); + searchButtonsRow->addWidget( highlightAllButton ); + searchButtonsRow->addWidget( searchCaseSensitive ); + searchButtonsRow->addStretch(); + + auto * searchPanelLayout = new QVBoxLayout( searchPanel ); + searchPanelLayout->addLayout( searchEditRow ); + searchPanelLayout->addLayout( searchButtonsRow ); + + // Combine Layouts + auto * mainLayout = new QVBoxLayout( this ); + mainLayout->addWidget( webview ); + mainLayout->addWidget( ftsSearchPanel ); + mainLayout->addWidget( searchPanel ); + + 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( searchPrevious, &QPushButton::clicked, this, &ArticleView::on_searchPrevious_clicked ); + connect( searchNext, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked ); + connect( searchCloseButton, &QPushButton::clicked, this, &ArticleView::on_searchCloseButton_clicked ); + connect( searchCaseSensitive, &QPushButton::clicked, this, &ArticleView::on_searchCaseSensitive_clicked ); + connect( highlightAllButton, &QPushButton::clicked, this, &ArticleView::on_highlightAllButton_clicked ); + connect( searchText, &QLineEdit::textEdited, this, &ArticleView::on_searchText_textEdited ); + connect( searchText, &QLineEdit::returnPressed, this, &ArticleView::on_searchText_returnPressed ); + connect( ftsSearchNext, &QPushButton::clicked, this, &ArticleView::on_ftsSearchNext_clicked ); + connect( ftsSearchPrevious, &QPushButton::clicked, this, &ArticleView::on_ftsSearchPrevious_clicked ); + + // + + webview->setUp( const_cast< Config::Class * >( &cfg ) ); goBackAction.setShortcut( QKeySequence( "Alt+Left" ) ); - ui.definition->addAction( &goBackAction ); + webview->addAction( &goBackAction ); connect( &goBackAction, &QAction::triggered, this, &ArticleView::back ); goForwardAction.setShortcut( QKeySequence( "Alt+Right" ) ); - ui.definition->addAction( &goForwardAction ); + webview->addAction( &goForwardAction ); connect( &goForwardAction, &QAction::triggered, this, &ArticleView::forward ); - ui.definition->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy ); - ui.definition->addAction( ui.definition->pageAction( QWebEnginePage::Copy ) ); + webview->pageAction( QWebEnginePage::Copy )->setShortcut( QKeySequence::Copy ); + webview->addAction( webview->pageAction( QWebEnginePage::Copy ) ); - QAction * selectAll = ui.definition->pageAction( QWebEnginePage::SelectAll ); + QAction * selectAll = webview->pageAction( QWebEnginePage::SelectAll ); selectAll->setShortcut( QKeySequence::SelectAll ); selectAll->setShortcutContext( Qt::WidgetWithChildrenShortcut ); - ui.definition->addAction( selectAll ); + webview->addAction( selectAll ); - ui.definition->setContextMenuPolicy( Qt::CustomContextMenu ); + webview->setContextMenuPolicy( Qt::CustomContextMenu ); - connect( ui.definition, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished ); + connect( webview, &QWebEngineView::loadFinished, this, &ArticleView::loadFinished ); - connect( ui.definition, &QWebEngineView::loadProgress, this, &ArticleView::loadProgress ); - connect( ui.definition, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked ); + connect( webview, &QWebEngineView::loadProgress, this, &ArticleView::loadProgress ); + connect( webview, &ArticleWebView::linkClicked, this, &ArticleView::linkClicked ); - connect( ui.definition->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged ); + connect( webview->page(), &QWebEnginePage::titleChanged, this, &ArticleView::handleTitleChanged ); - connect( ui.definition->page(), &QWebEnginePage::urlChanged, this, &ArticleView::handleUrlChanged ); + connect( webview->page(), &QWebEnginePage::urlChanged, this, &ArticleView::handleUrlChanged ); - connect( ui.definition, &QWidget::customContextMenuRequested, this, &ArticleView::contextMenuRequested ); + connect( webview, &QWidget::customContextMenuRequested, this, &ArticleView::contextMenuRequested ); - connect( ui.definition->page(), - SIGNAL( linkHovered( const QString & ) ), - this, - SLOT( linkHovered( const QString & ) ) ); + connect( webview->page(), SIGNAL( linkHovered( const QString & ) ), this, SLOT( linkHovered( const QString & ) ) ); - connect( ui.definition, &ArticleWebView::doubleClicked, this, &ArticleView::doubleClicked ); + connect( webview, &ArticleWebView::doubleClicked, this, &ArticleView::doubleClicked ); - pasteAction.setShortcut( QKeySequence::Paste ); - ui.definition->addAction( &pasteAction ); + pasteAction.setShortcut( QKeySequence::Paste ); + webview->addAction( &pasteAction ); connect( &pasteAction, &QAction::triggered, this, &ArticleView::pasteTriggered ); articleUpAction.setShortcut( QKeySequence( "Alt+Up" ) ); - ui.definition->addAction( &articleUpAction ); + webview->addAction( &articleUpAction ); connect( &articleUpAction, &QAction::triggered, this, &ArticleView::moveOneArticleUp ); articleDownAction.setShortcut( QKeySequence( "Alt+Down" ) ); - ui.definition->addAction( &articleDownAction ); + webview->addAction( &articleDownAction ); connect( &articleDownAction, &QAction::triggered, this, &ArticleView::moveOneArticleDown ); - ui.definition->addAction( &openSearchAction ); + webview->addAction( &openSearchAction ); connect( &openSearchAction, &QAction::triggered, this, &ArticleView::openSearch ); - selectCurrentArticleAction.setShortcut( QKeySequence( "Ctrl+Shift+A" )); + selectCurrentArticleAction.setShortcut( QKeySequence( "Ctrl+Shift+A" ) ); selectCurrentArticleAction.setText( tr( "Select Current Article" ) ); - ui.definition->addAction( &selectCurrentArticleAction ); + webview->addAction( &selectCurrentArticleAction ); connect( &selectCurrentArticleAction, &QAction::triggered, this, &ArticleView::selectCurrentArticle ); copyAsTextAction.setShortcut( QKeySequence( "Ctrl+Shift+C" ) ); copyAsTextAction.setText( tr( "Copy as text" ) ); - ui.definition->addAction( ©AsTextAction ); + webview->addAction( ©AsTextAction ); connect( ©AsTextAction, &QAction::triggered, this, &ArticleView::copyAsText ); inspectAction.setShortcut( QKeySequence( Qt::Key_F12 ) ); inspectAction.setText( tr( "Inspect" ) ); - ui.definition->addAction( &inspectAction ); + webview->addAction( &inspectAction ); - connect(&inspectAction, &QAction::triggered, this, &ArticleView::inspectElement); + connect( &inspectAction, &QAction::triggered, this, &ArticleView::inspectElement ); - ui.definition->installEventFilter( this ); - ui.searchFrame->installEventFilter( this ); - ui.ftsSearchFrame->installEventFilter( this ); + webview->installEventFilter( this ); + searchPanel->installEventFilter( this ); + ftsSearchPanel->installEventFilter( this ); - QWebEngineSettings * settings = ui.definition->settings(); - settings->setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy::DisallowUnknownUrlSchemes); + 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 ); @@ -346,12 +432,12 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au settings->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); #endif - ui.definition->load( QUrl("gdlookup://localhost?word=(untitled)&blank=1") ); + webview->load( QUrl( "gdlookup://localhost?word=(untitled)&blank=1" ) ); expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts; - ui.definition->grabGesture( Gestures::GDPinchGestureType ); - ui.definition->grabGesture( Gestures::GDSwipeGestureType ); + webview->grabGesture( Gestures::GDPinchGestureType ); + webview->grabGesture( Gestures::GDSwipeGestureType ); // Variable name for store current selection range rangeVarName = QString( "sr_%1" ).arg( QString::number( (quint64)this, 16 ) ); @@ -360,7 +446,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au connect( GlobalBroadcaster::instance(), &GlobalBroadcaster::dictionaryClear, this, &ArticleView::dictionaryClear ); - channel = new QWebChannel(ui.definition->page()); + channel = new QWebChannel( webview->page() ); agent = new ArticleViewAgent(this); attachWebChannelToHtml(); ankiConnector = new AnkiConnector( this, cfg ); @@ -372,10 +458,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au // explicitly report the minimum size, to avoid // sidebar widgets' improper resize during restore -QSize ArticleView::minimumSizeHint() const -{ - return ui.searchFrame->minimumSizeHint(); -} +QSize ArticleView::minimumSizeHint() const { return searchPanel->minimumSizeHint(); } void ArticleView::setGroupComboBox( GroupComboBox const * g ) { @@ -387,8 +470,8 @@ ArticleView::~ArticleView() cleanupTemp(); audioPlayer->stop(); //channel->deregisterObject(this); - ui.definition->ungrabGesture( Gestures::GDPinchGestureType ); - ui.definition->ungrabGesture( Gestures::GDSwipeGestureType ); + webview->ungrabGesture( Gestures::GDPinchGestureType ); + webview->ungrabGesture( Gestures::GDSwipeGestureType ); } void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned group, @@ -457,15 +540,12 @@ void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned g // Any search opened is probably irrelevant now closeSearch(); - // Clear highlight all button selection - ui.highlightAllButton->setChecked(false); - emit setExpandMode( expandOptionalParts ); load( req ); //QApplication::setOverrideCursor( Qt::WaitCursor ); - ui.definition->setCursor( Qt::WaitCursor ); + webview->setCursor( Qt::WaitCursor ); } void ArticleView::showDefinition( QString const & word, unsigned group, @@ -510,13 +590,13 @@ void ArticleView::showDefinition( QString const & word, QStringList const & dict closeSearch(); // Clear highlight all button selection - ui.highlightAllButton->setChecked(false); + highlightAllButton->setChecked( false ); emit setExpandMode( expandOptionalParts ); load( req ); - ui.definition->setCursor( Qt::WaitCursor ); + webview->setCursor( Qt::WaitCursor ); } void ArticleView::sendToAnki(QString const & word, QString const & text, QString const & sentence ){ @@ -525,20 +605,17 @@ void ArticleView::sendToAnki(QString const & word, QString const & text, QString void ArticleView::showAnticipation() { - ui.definition->setHtml( "" ); - ui.definition->setCursor( Qt::WaitCursor ); + webview->setHtml( "" ); + webview->setCursor( Qt::WaitCursor ); } -void ArticleView::inspectElement() -{ - emit inspectSignal( ui.definition->page() ); -} +void ArticleView::inspectElement() { emit inspectSignal( webview->page() ); } void ArticleView::loadFinished( bool result ) { - ui.definition->setFocus(); + webview->setFocus(); setZoomFactor( cfg.preferences.zoomFactor ); - QUrl url = ui.definition->url(); + QUrl url = webview->url(); qDebug() << "article view loaded url:" << url.url().left( 200 ) << result; if( url.url() == "about:blank" ) @@ -561,10 +638,10 @@ void ArticleView::loadFinished( bool result ) } } - ui.definition->unsetCursor(); + webview->unsetCursor(); // Expand collapsed article if only one loaded - ui.definition->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) ); + webview->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) ); if( !Utils::Url::queryItemValue( url, "gdanchor" ).isEmpty() ) { @@ -587,16 +664,16 @@ void ArticleView::loadFinished( bool result ) QString hash=originalAnchor.left(end); url.clear(); url.setFragment(hash); - ui.definition->page()->runJavaScript( - QString("window.location.hash = \"%1\"").arg(QString::fromUtf8(url.toEncoded()))); + webview->page()->runJavaScript( + QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); } else { url.clear(); url.setFragment( anchor ); - ui.definition->page()->runJavaScript( - QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); + webview->page()->runJavaScript( + QString( "window.location.hash = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); } } @@ -605,7 +682,7 @@ void ArticleView::loadFinished( bool result ) if(result){ emit pageLoaded( this ); } - if( Utils::Url::hasQueryItem( ui.definition->url(), "regexp" ) ) + if( Utils::Url::hasQueryItem( webview->url(), "regexp" ) ) highlightFTSResults(); } @@ -684,7 +761,7 @@ bool ArticleView::setCurrentArticle( QString const & id, bool moveToIt ) if ( !isScrollTo( id ) ) return false; // Incorrect id - if ( !ui.definition->isVisible() ) + if( !webview->isVisible() ) return false; // No action on background page, scrollIntoView there don't work if(moveToIt){ @@ -695,7 +772,7 @@ bool ArticleView::setCurrentArticle( QString const & id, bool moveToIt ) "if(elem!=undefined){elem.scrollIntoView(true);} gdMakeArticleActive('%2',true);" ) .arg( id, dictId ); onJsActiveArticleChanged( id ); - ui.definition->page()->runJavaScript( script ); + webview->page()->runJavaScript( script ); setActiveArticleId( dictId ); } return true; @@ -703,8 +780,10 @@ bool ArticleView::setCurrentArticle( QString const & id, bool moveToIt ) void ArticleView::selectCurrentArticle() { - ui.definition->page()->runJavaScript( - QString( "gdSelectArticle( '%1' );var elem=document.getElementById('%2'); if(elem!=undefined){elem.scrollIntoView(true);}" ).arg( getActiveArticleId() ,getCurrentArticle()) ); + webview->page()->runJavaScript( + QString( + "gdSelectArticle( '%1' );var elem=document.getElementById('%2'); if(elem!=undefined){elem.scrollIntoView(true);}" ) + .arg( getActiveArticleId(), getCurrentArticle() ) ); } void ArticleView::isFramedArticle( QString const & ca, const std::function< void( bool ) > & callback ) @@ -712,8 +791,10 @@ void ArticleView::isFramedArticle( QString const & ca, const std::function< void if( ca.isEmpty() ) callback( false ); - ui.definition->page()->runJavaScript( QString( "!!document.getElementById('gdexpandframe-%1');" ).arg( ca.mid( 7 ) ), - [ callback ]( const QVariant & res ) { callback( res.toBool() ); } ); + webview->page()->runJavaScript( QString( "!!document.getElementById('gdexpandframe-%1');" ).arg( ca.mid( 7 ) ), + [ callback ]( const QVariant & res ) { + callback( res.toBool() ); + } ); } bool ArticleView::isExternalLink( QUrl const & url ) @@ -734,10 +815,7 @@ void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts ) } } -void ArticleView::load( QUrl const & url ) -{ - ui.definition->load( url ); -} +void ArticleView::load( QUrl const & url ) { webview->load( url ); } void ArticleView::cleanupTemp() { @@ -874,9 +952,8 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev ) return true; } - if ( obj == ui.definition ) - { - if ( ev->type() == QEvent::MouseButtonPress ) { + if( obj == webview ) { + if( ev->type() == QEvent::MouseButtonPress ) { QMouseEvent * event = static_cast< QMouseEvent * >( ev ); if ( event->button() == Qt::XButton1 ) { back(); @@ -926,7 +1003,7 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev ) } } else - return QFrame::eventFilter( obj, ev ); + return QWidget::eventFilter( obj, ev ); return false; } @@ -1078,7 +1155,7 @@ void ArticleView::linkHovered ( const QString & link ) void ArticleView::attachWebChannelToHtml() { // set the web channel to be used by the page // see http://doc.qt.io/qt-5/qwebenginepage.html#setWebChannel - ui.definition->page()->setWebChannel(channel, QWebEngineScript::MainWorld); + webview->page()->setWebChannel(channel, QWebEngineScript::MainWorld); // register QObjects to be exposed to JavaScript channel->registerObject(QStringLiteral("articleview"), agent); @@ -1097,29 +1174,24 @@ void ArticleView::linkClicked( QUrl const & url_ ) tryMangleWebsiteClickedUrl( url, contexts ); - if ( !popupView && - ( ui.definition->isMidButtonPressed() || - ( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) ) && !isAudioLink(url) ) - { + if( !popupView && ( webview->isMidButtonPressed() || ( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) ) + && !isAudioLink( url ) ) { // Mid button or Control/Shift is currently pressed - open the link in new tab - ui.definition->resetMidButtonPressed(); - emit openLinkInNewTab( url, ui.definition->url(), getCurrentArticle(), contexts ); + webview->resetMidButtonPressed(); + emit openLinkInNewTab( url, webview->url(), getCurrentArticle(), contexts ); } else - openLink( url, ui.definition->url(), getCurrentArticle(), contexts ); + openLink( url, webview->url(), getCurrentArticle(), contexts ); } void ArticleView::linkClickedInHtml( QUrl const & url_ ) { - emit ui.definition->linkClickedInHtml(url_); - if(!url_.isEmpty()) - { + emit webview->linkClickedInHtml( url_ ); + if( !url_.isEmpty() ) { linkClicked( url_ ); } } -void ArticleView::openLink( QUrl const & url, QUrl const & ref, - QString const & scrollTo, - Contexts const & contexts_ ) +void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const & scrollTo, Contexts const & contexts_ ) { audioPlayer->stop(); qDebug() << "open link url:" << url; @@ -1154,7 +1226,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, { if ( url.hasFragment() ) { - ui.definition->page()->runJavaScript( + webview->page()->runJavaScript( QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) ); } else @@ -1429,7 +1501,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QString & fileName ) { - return saveResource( url, ui.definition->url(), fileName ); + return saveResource( url, webview->url(), fileName ); } ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QUrl & ref, const QString & fileName ) @@ -1556,7 +1628,7 @@ ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QUrl void ArticleView::updateMutedContents() { - QUrl currentUrl = ui.definition->url(); + QUrl currentUrl = webview->url(); if ( currentUrl.scheme() != "gdlookup" ) return; // Weird url -- do nothing @@ -1580,7 +1652,7 @@ void ArticleView::updateMutedContents() load( currentUrl ); //QApplication::setOverrideCursor( Qt::WaitCursor ); - ui.definition->setCursor( Qt::WaitCursor ); + webview->setCursor( Qt::WaitCursor ); } } @@ -1588,18 +1660,12 @@ bool ArticleView::canGoBack() { // First entry in a history is always an empty page, // so we skip it. - return ui.definition->history()->currentItemIndex() > 1; + return webview->history()->currentItemIndex() > 1; } -bool ArticleView::canGoForward() -{ - return ui.definition->history()->canGoForward(); -} +bool ArticleView::canGoForward() { return webview->history()->canGoForward(); } -void ArticleView::setSelectionBySingleClick( bool set ) -{ - ui.definition->setSelectionBySingleClick( set ); -} +void ArticleView::setSelectionBySingleClick( bool set ) { webview->setSelectionBySingleClick( set ); } void ArticleView::setDelayedHighlightText(QString const & text) { @@ -1614,7 +1680,7 @@ void ArticleView::back() { currentActiveDictIds.clear(); historyMode = true; - ui.definition->back(); + webview->back(); } } @@ -1622,24 +1688,20 @@ void ArticleView::forward() { currentActiveDictIds.clear(); historyMode = true; - ui.definition->forward(); + webview->forward(); } -void ArticleView::reload() -{ - ui.definition->reload(); -} +void ArticleView::reload() { webview->reload(); } void ArticleView::hasSound( const std::function< void( bool ) > & callback ) { - ui.definition->page()->runJavaScript( "if(typeof(gdAudioLinks)!=\"undefined\") gdAudioLinks.first", - [ callback ]( const QVariant & v ) - { - bool has = false; - if( v.type() == QVariant::String ) - has = !v.toString().isEmpty(); - callback( has ); - } ); + webview->page()->runJavaScript( "if(typeof(gdAudioLinks)!=\"undefined\") gdAudioLinks.first", + [ callback ]( const QVariant & v ) { + bool has = false; + if( v.type() == QVariant::String ) + has = !v.toString().isEmpty(); + callback( has ); + } ); } //use webengine javascript to playsound @@ -1651,41 +1713,38 @@ void ArticleView::playSound() " } " " return link;})(); "; - ui.definition->page()->runJavaScript(variable,[this](const QVariant & result){ - if (result.type() == QVariant::String) { - QString soundScript = result.toString(); - if (!soundScript.isEmpty()) - openLink(QUrl::fromEncoded(soundScript.toUtf8()), ui.definition->url()); - } - }); + webview->page()->runJavaScript( variable, [ this ]( const QVariant & result ) { + if( result.type() == QVariant::String ) { + QString soundScript = result.toString(); + if( !soundScript.isEmpty() ) + openLink( QUrl::fromEncoded( soundScript.toUtf8() ), webview->url() ); + } + } ); } void ArticleView::toHtml( const std::function< void( QString & ) > & callback ) { - ui.definition->page()->toHtml( - [ = ]( const QString & content ) - { - QString html = content; - callback( html ); - } ); + webview->page()->toHtml( [ = ]( const QString & content ) { + QString html = content; + callback( html ); + } ); } -void ArticleView::setHtml(const QString& content,const QUrl& baseUrl){ - ui.definition->page()->setHtml(content,baseUrl); -} - -void ArticleView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl ){ - ui.definition->page()->setContent(data,mimeType,baseUrl); -} - -QString ArticleView::getTitle() +void ArticleView::setHtml( const QString & content, const QUrl & baseUrl ) { - return ui.definition->page()->title(); + webview->page()->setHtml( content, baseUrl ); } +void ArticleView::setContent( const QByteArray & data, const QString & mimeType, const QUrl & baseUrl ) +{ + webview->page()->setContent( data, mimeType, baseUrl ); +} + +QString ArticleView::getTitle() { return webview->page()->title(); } + Config::InputPhrase ArticleView::getPhrase() const { - const QUrl url = ui.definition->url(); + const QUrl url = webview->url(); return Config::InputPhrase( Utils::Url::queryItemValue( url, "word" ), Utils::Url::queryItemValue( url, "punctuation_suffix" ) ); } @@ -1700,10 +1759,10 @@ void ArticleView::print( QPrinter * printer ) const loop.quit(); }; #if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) - ui.definition->page()->print( printer, std::move( printPreview ) ); + webview->page()->print( printer, std::move( printPreview ) ); #else - connect( ui.definition, &QWebEngineView::printFinished, &loop, std::move( printPreview ) ); - ui.definition->print( printer ); + connect( webview, &QWebEngineView::printFinished, &loop, std::move( printPreview ) ); + webview->print( printer ); #endif loop.exec(); if( !result ) @@ -1715,7 +1774,7 @@ void ArticleView::print( QPrinter * printer ) const void ArticleView::contextMenuRequested( QPoint const & pos ) { // Is that a link? Is there a selection? - QWebEnginePage* r=ui.definition->page(); + QWebEnginePage * r = webview->page(); QMenu menu( this ); QAction * followLink = 0; @@ -1737,7 +1796,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) #if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) const QWebEngineContextMenuData * menuData = &(r->contextMenuData()); #else - QWebEngineContextMenuRequest * menuData = ui.definition->lastContextMenuRequest(); + QWebEngineContextMenuRequest * menuData = webview->lastContextMenuRequest(); #endif QUrl targetUrl(menuData->linkUrl()); Contexts contexts; @@ -1763,7 +1822,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) { followLinkExternal = new QAction( tr( "Open Link in &External Browser" ), &menu ); menu.addAction( followLinkExternal ); - menu.addAction( ui.definition->pageAction( QWebEnginePage::CopyLinkToClipboard ) ); + menu.addAction( webview->pageAction( QWebEnginePage::CopyLinkToClipboard ) ); } } @@ -1774,13 +1833,12 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) if( !popupView && menuData->mediaType ()==QWebEngineContextMenuRequest::MediaType::MediaTypeImage) #endif { - imageUrl = menuData->mediaUrl (); - if( !imageUrl.isEmpty() ) - { - menu.addAction( ui.definition->pageAction( QWebEnginePage::CopyImageToClipboard ) ); - saveImageAction = new QAction( tr( "Save &image..." ), &menu ); - menu.addAction( saveImageAction ); - } + imageUrl = menuData->mediaUrl(); + if( !imageUrl.isEmpty() ) { + menu.addAction( webview->pageAction( QWebEnginePage::CopyImageToClipboard ) ); + saveImageAction = new QAction( tr( "Save &image..." ), &menu ); + menu.addAction( saveImageAction ); + } } if( !popupView && isAudioLink( targetUrl ) ) @@ -1789,7 +1847,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) menu.addAction( saveSoundAction ); } - QString selectedText = ui.definition->selectedText(); + QString selectedText = webview->selectedText(); QString text = Utils::trimNonChar( selectedText ); if ( text.size() && text.size() < 60 ) @@ -1828,8 +1886,9 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) menu.addAction( addWordToHistoryAction ); Instances::Group const * altGroup = - ( groupComboBox && groupComboBox->getCurrentGroup() != getGroup( ui.definition->url() ) ) ? - groups.findGroup( groupComboBox->getCurrentGroup() ) : 0; + ( groupComboBox && groupComboBox->getCurrentGroup() != getGroup( webview->url() ) ) ? + groups.findGroup( groupComboBox->getCurrentGroup() ) : + 0; if ( altGroup ) { @@ -1862,14 +1921,14 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) // add anki menu if( !text.isEmpty() && cfg.preferences.ankiConnectServer.enabled ) { - QString txt = ui.definition->title(); + QString txt = webview->title(); sendToAnkiAction = new QAction( tr( "&Send \"%1\" to anki with selected text." ).arg( txt ), &menu ); menu.addAction( sendToAnkiAction ); } if( text.isEmpty() && !cfg.preferences.storeHistory) { - QString txt = ui.definition->title(); + QString txt = webview->title(); if( txt.size() > 60 ) txt = txt.left( 60 ) + "..."; @@ -1881,13 +1940,13 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) if ( selectedText.size() ) { - menu.addAction( ui.definition->pageAction( QWebEnginePage::Copy ) ); + menu.addAction( webview->pageAction( QWebEnginePage::Copy ) ); menu.addAction( ©AsTextAction ); } else { menu.addAction( &selectCurrentArticleAction ); - menu.addAction( ui.definition->pageAction( QWebEnginePage::SelectAll ) ); + menu.addAction( webview->pageAction( QWebEnginePage::SelectAll ) ); } map< QAction *, QString > tableOfContents; @@ -1947,26 +2006,22 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) if ( !menu.isEmpty() ) { connect( this, &ArticleView::closePopupMenu, &menu, &QWidget::close ); - QAction * result = menu.exec( ui.definition->mapToGlobal( pos ) ); + QAction * result = menu.exec( webview->mapToGlobal( pos ) ); if ( !result ) return; - if ( result == followLink ) - openLink( targetUrl, ui.definition->url(), getCurrentArticle(), contexts ); - else - if ( result == followLinkExternal ) + if( result == followLink ) + openLink( targetUrl, webview->url(), getCurrentArticle(), contexts ); + else if( result == followLinkExternal ) QDesktopServices::openUrl( targetUrl ); - else - if ( result == lookupSelection ) - showDefinition( text, getGroup( ui.definition->url() ), getCurrentArticle() ); - else if( result == saveBookmark ) - { + else if( result == lookupSelection ) + showDefinition( text, getGroup( webview->url() ), getCurrentArticle() ); + else if( result == saveBookmark ) { emit saveBookmarkSignal( text.left( 60 ) ); } - else if( result == sendToAnkiAction ) - { - sendToAnki( ui.definition->title(), ui.definition->selectedText(), translateLine->text() ); + else if( result == sendToAnkiAction ) { + sendToAnki( webview->title(), webview->selectedText(), translateLine->text() ); } else if ( result == lookupSelectionGr && groupComboBox ) @@ -1974,25 +2029,17 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) else if ( result == addWordToHistoryAction ) emit forceAddWordToHistory( selectedText ); - if ( result == addHeaderToHistoryAction ) - emit forceAddWordToHistory( ui.definition->title() ); - else - if( result == sendWordToInputLineAction ) + if( result == addHeaderToHistoryAction ) + emit forceAddWordToHistory( webview->title() ); + else if( result == sendWordToInputLineAction ) emit sendWordToInputLine( selectedText ); - else - if ( !popupView && result == followLinkNewTab ) - emit openLinkInNewTab( targetUrl, ui.definition->url(), getCurrentArticle(), contexts ); - else - if ( !popupView && result == lookupSelectionNewTab ) - emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ), - getCurrentArticle(), Contexts() ); - else - if ( !popupView && result == lookupSelectionNewTabGr && groupComboBox ) - emit showDefinitionInNewTab( selectedText, groupComboBox->getCurrentGroup(), - QString(), Contexts() ); - else - if( result == saveImageAction || result == saveSoundAction ) - { + else if( !popupView && result == followLinkNewTab ) + emit openLinkInNewTab( targetUrl, webview->url(), getCurrentArticle(), contexts ); + else if( !popupView && result == lookupSelectionNewTab ) + emit showDefinitionInNewTab( selectedText, getGroup( webview->url() ), getCurrentArticle(), Contexts() ); + else if( !popupView && result == lookupSelectionNewTabGr && groupComboBox ) + emit showDefinitionInNewTab( selectedText, groupComboBox->getCurrentGroup(), QString(), Contexts() ); + else if( result == saveImageAction || result == saveSoundAction ) { QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl; QString savePath; QString fileName; @@ -2039,7 +2086,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) { QFileInfo fileInfo( fileName ); emit storeResourceSavePath( QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ) ); - saveResource( url, ui.definition->url(), fileName ); + saveResource( url, webview->url(), fileName ); } } else @@ -2151,11 +2198,9 @@ void ArticleView::pasteTriggered() { Config::InputPhrase phrase = cfg.preferences.sanitizeInputPhrase( QApplication::clipboard()->text() ); - if ( phrase.isValid() ) - { - unsigned groupId = getGroup( ui.definition->url() ); - if ( groupId == 0 ) - { + if( phrase.isValid() ) { + unsigned groupId = getGroup( webview->url() ); + if( groupId == 0 ) { // We couldn't figure out the group out of the URL, // so let's try the currently selected group. groupId = groupComboBox->getCurrentGroup(); @@ -2217,24 +2262,21 @@ void ArticleView::openSearch() if ( !searchIsOpened ) { - ui.searchFrame->show(); - ui.searchText->setText( getTitle() ); + searchPanel->show(); + searchText->setText( getTitle() ); searchIsOpened = true; } - ui.searchText->setFocus(); - ui.searchText->selectAll(); + searchText->setFocus(); + searchText->selectAll(); // Clear any current selection - if ( ui.definition->selectedText().size() ) - { - ui.definition->page()-> - runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); + if( webview->selectedText().size() ) { + webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); } - if ( ui.searchText->property( "noResults" ).toBool() ) - { - ui.searchText->setProperty( "noResults", false ); + if( searchText->property( "noResults" ).toBool() ) { + searchText->setProperty( "noResults", false ); // Reload stylesheet reloadStyleSheet(); @@ -2243,13 +2285,13 @@ void ArticleView::openSearch() void ArticleView::on_searchPrevious_clicked() { - if ( searchIsOpened ) + if( searchIsOpened ) performFindOperation( false, true ); } void ArticleView::on_searchNext_clicked() { - if ( searchIsOpened ) + if( searchIsOpened ) performFindOperation( false, false ); } @@ -2293,9 +2335,8 @@ void ArticleView::doubleClicked( QPoint pos ) { // We might want to initiate translation of the selected word audioPlayer->stop(); - if ( cfg.preferences.doubleClickTranslates ) - { - QString selectedText = ui.definition->selectedText(); + if( cfg.preferences.doubleClickTranslates ) { + QString selectedText = webview->selectedText(); // ignore empty word; if( selectedText.isEmpty() ) @@ -2308,14 +2349,11 @@ void ArticleView::doubleClicked( QPoint pos ) { // Initiate translation Qt::KeyboardModifiers kmod = QApplication::keyboardModifiers(); - if (kmod & (Qt::ControlModifier | Qt::ShiftModifier)) - { // open in new tab - emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ), - getCurrentArticle(), Contexts() ); + if( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) { // open in new tab + emit showDefinitionInNewTab( selectedText, getGroup( webview->url() ), getCurrentArticle(), Contexts() ); } - else - { - QUrl const & ref = ui.definition->url(); + else { + QUrl const & ref = webview->url(); if( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) { @@ -2333,29 +2371,27 @@ void ArticleView::doubleClicked( QPoint pos ) void ArticleView::performFindOperation( bool restart, bool backwards, bool checkHighlight ) { - QString text = ui.searchText->text(); + QString text = searchText->text(); if ( restart || checkHighlight ) { if( restart ) { // Anyone knows how we reset the search position? // For now we resort to this hack: - if ( ui.definition->selectedText().size() ) - { - ui.definition->page()-> - runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); + if( webview->selectedText().size() ) { + webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); } } QWebEnginePage::FindFlags f( 0 ); - if ( ui.searchCaseSensitive->isChecked() ) + if( searchCaseSensitive->isChecked() ) f |= QWebEnginePage::FindCaseSensitively; - ui.definition->findText( "", f ); + webview->findText( "", f ); - if( ui.highlightAllButton->isChecked() ) - ui.definition->findText( text, f ); + if( highlightAllButton->isChecked() ) + webview->findText( text, f ); if( checkHighlight ) return; @@ -2363,10 +2399,10 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check QWebEnginePage::FindFlags f( 0 ); - if ( ui.searchCaseSensitive->isChecked() ) + if( searchCaseSensitive->isChecked() ) f |= QWebEnginePage::FindCaseSensitively; - if ( backwards ) + if( backwards ) f |= QWebEnginePage::FindBackward; findText( text, @@ -2375,9 +2411,8 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check { bool setMark = !text.isEmpty() && !match; - if( ui.searchText->property( "noResults" ).toBool() != setMark ) - { - ui.searchText->setProperty( "noResults", setMark ); + if( searchText->property( "noResults" ).toBool() != setMark ) { + searchText->setProperty( "noResults", setMark ); // Reload stylesheet reloadStyleSheet(); @@ -2390,22 +2425,16 @@ void ArticleView::findText( QString & text, const std::function< void( bool match ) > & callback ) { #if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) - ui.definition->findText( text, - f, - [ callback ]( const QWebEngineFindTextResult & result ) - { - auto r = result.numberOfMatches() > 0; - if( callback ) - callback( r ); - } ); + webview->findText( text, f, [ callback ]( const QWebEngineFindTextResult & result ) { + auto r = result.numberOfMatches() > 0; + if( callback ) + callback( r ); + } ); #else - ui.definition->findText( text, - f, - [ callback ]( bool result ) - { - if( callback ) - callback( result ); - } ); + webview->findText( text, f, [ callback ]( bool result ) { + if( callback ) + callback( result ); + } ); #endif } @@ -2424,10 +2453,9 @@ void ArticleView::reloadStyleSheet() bool ArticleView::closeSearch() { - if ( searchIsOpened ) - { - ui.searchFrame->hide(); - ui.definition->setFocus(); + if( searchIsOpened ) { + searchPanel->hide(); + webview->setFocus(); searchIsOpened = false; return true; @@ -2440,12 +2468,12 @@ bool ArticleView::closeSearch() ftsPosition = 0; ftsSearchIsOpened = false; - ui.ftsSearchFrame->hide(); - ui.definition->setFocus(); + ftsSearchPanel->hide(); + webview->setFocus(); QWebEnginePage::FindFlags flags ( 0 ); - ui.definition->findText( "", flags ); + webview->findText( "", flags ); return true; } @@ -2453,20 +2481,17 @@ bool ArticleView::closeSearch() return false; } -bool ArticleView::isSearchOpened() -{ - return searchIsOpened; -} +bool ArticleView::isSearchOpened() { return searchIsOpened; } void ArticleView::showEvent( QShowEvent * ev ) { - QFrame::showEvent( ev ); + QWidget::showEvent( ev ); - if ( !searchIsOpened ) - ui.searchFrame->hide(); + if( !searchIsOpened ) + searchPanel->hide(); if( !ftsSearchIsOpened ) - ui.ftsSearchFrame->hide(); + ftsSearchPanel->hide(); } void ArticleView::receiveExpandOptionalParts( bool expand ) @@ -2484,7 +2509,7 @@ void ArticleView::switchExpandOptionalParts() void ArticleView::copyAsText() { - QString text = ui.definition->selectedText(); + QString text = webview->selectedText(); if( !text.isEmpty() ) QApplication::clipboard()->setText( text ); } @@ -2494,23 +2519,21 @@ void ArticleView::highlightFTSResults() closeSearch(); // Clear any current selection - if( ui.definition->selectedText().size() ) - { - ui.definition->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); + if( webview->selectedText().size() ) { + webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" ); } - ui.definition->page()->toPlainText( - [ & ]( const QString pageText ) - { - const QUrl & url = ui.definition->url(); + webview->page()->toPlainText( + [ & ]( const QString pageText ) { + const QUrl & url = webview->url(); QString regString = Utils::Url::queryItemValue( url, "regexp" ); if( regString.isEmpty() ) return; bool ignoreDiacritics = Utils::Url::hasQueryItem( url, "ignore_diacritics" ); - - if( ignoreDiacritics ) + + if( ignoreDiacritics ) regString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( regString ) ) ); else regString = regString.remove( AccentMarkHandler::accentMark() ); @@ -2571,25 +2594,24 @@ void ArticleView::highlightFTSResults() if( ftsSearchMatchCase ) flags |= QWebEnginePage::FindCaseSensitively; - if( allMatches.isEmpty() ) - ui.ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); - else - { -// highlightAllFtsOccurences( flags ); - ui.definition->findText( allMatches.at( 0 ), flags ); - // if( ui.definition->findText( allMatches.at( 0 ), flags ) ) + if( allMatches.isEmpty() ) + ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); + else { + // highlightAllFtsOccurences( flags ); + webview->findText( allMatches.at( 0 ), flags ); + // if( webview->findText( allMatches.at( 0 ), flags ) ) // { - // ui.definition->page()->runJavaScript( + // webview->page()->runJavaScript( // QString( "%1=window.getSelection().getRangeAt(0);_=0;" ).arg( rangeVarName ) ); // } Q_ASSERT( ftsPosition == 0 ); - ui.ftsSearchStatusLabel->setText( searchStatusMessage( 1, allMatches.size() ) ); + ftsSearchStatusLabel->setText( searchStatusMessage( 1, allMatches.size() ) ); } - ui.ftsSearchFrame->show(); - ui.ftsSearchPrevious->setEnabled( false ); - ui.ftsSearchNext->setEnabled( allMatches.size() > 1 ); + ftsSearchPanel->show(); + ftsSearchPrevious->setEnabled( false ); + ftsSearchNext->setEnabled( allMatches.size() > 1 ); ftsSearchIsOpened = true; } ); @@ -2611,7 +2633,7 @@ void ArticleView::highlightAllFtsOccurences( QWebEnginePage::FindFlags flags ) } for( QSet< QString >::const_iterator it = uniqueMatches.constBegin(); it != uniqueMatches.constEnd(); ++it ) - ui.definition->findText( *it, flags ); + webview->findText( *it, flags ); } void ArticleView::setActiveDictIds(ActiveDictIds ad) { @@ -2640,11 +2662,10 @@ void ArticleView::performFtsFindOperation( bool backwards ) if( !ftsSearchIsOpened ) return; - if( allMatches.isEmpty() ) - { - ui.ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); - ui.ftsSearchNext->setEnabled( false ); - ui.ftsSearchPrevious->setEnabled( false ); + if( allMatches.isEmpty() ) { + ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); + ftsSearchNext->setEnabled( false ); + ftsSearchPrevious->setEnabled( false ); return; } @@ -2655,59 +2676,56 @@ void ArticleView::performFtsFindOperation( bool backwards ) // Restore saved highlighted selection - ui.definition->page()-> - runJavaScript( QString( "var sel=window.getSelection();sel.removeAllRanges();sel.addRange(%1);_=0;" ) - .arg( rangeVarName ) ); + webview->page()->runJavaScript( + QString( "var sel=window.getSelection();sel.removeAllRanges();sel.addRange(%1);_=0;" ).arg( rangeVarName ) ); - if (backwards) { - if (ftsPosition > 0) { - ftsPosition -= 1; - } + if( backwards ) { + if( ftsPosition > 0 ) { + ftsPosition -= 1; + } #if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) - ui.definition->findText( allMatches.at( ftsPosition ), - flags | QWebEnginePage::FindBackward, - [ this ]( const QWebEngineFindTextResult & result ) - { - if( result.numberOfMatches ()== 0 ) - return; - ui.ftsSearchPrevious->setEnabled(true); - if (!ui.ftsSearchNext->isEnabled()) - ui.ftsSearchNext->setEnabled(true); - }); + webview->findText( allMatches.at( ftsPosition ), + flags | QWebEnginePage::FindBackward, + [ this ]( const QWebEngineFindTextResult & result ) { + if( result.numberOfMatches() == 0 ) + return; + ftsSearchPrevious->setEnabled( true ); + if( !ftsSearchNext->isEnabled() ) + ftsSearchNext->setEnabled( true ); + } ); #else - ui.definition->findText(allMatches.at(ftsPosition), - flags | QWebEnginePage::FindBackward, - [this](bool res) { - ui.ftsSearchPrevious->setEnabled(res); - if (!ui.ftsSearchNext->isEnabled()) - ui.ftsSearchNext->setEnabled(res); - }); + webview->findText( allMatches.at( ftsPosition ), flags | QWebEnginePage::FindBackward, [ this ]( bool res ) { + ftsSearchPrevious->setEnabled( res ); + if( !ftsSearchNext->isEnabled() ) + ftsSearchNext->setEnabled( res ); + } ); #endif - } else { - if (ftsPosition < allMatches.size() - 1) { - ftsPosition += 1; - } + } + else { + if( ftsPosition < allMatches.size() - 1 ) { + ftsPosition += 1; + } #if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) - ui.definition->findText(allMatches.at(ftsPosition), flags, [this](const QWebEngineFindTextResult & result ) { - if( result.numberOfMatches() == 0 ) - return; - ui.ftsSearchNext->setEnabled(true); - if (!ui.ftsSearchPrevious->isEnabled()) - ui.ftsSearchPrevious->setEnabled(true); - }); + webview->findText( allMatches.at( ftsPosition ), flags, [ this ]( const QWebEngineFindTextResult & result ) { + if( result.numberOfMatches() == 0 ) + return; + ftsSearchNext->setEnabled( true ); + if( !ftsSearchPrevious->isEnabled() ) + ftsSearchPrevious->setEnabled( true ); + } ); } #else - ui.definition->findText(allMatches.at(ftsPosition), flags, [this](bool res) { - ui.ftsSearchNext->setEnabled(res); - if (!ui.ftsSearchPrevious->isEnabled()) - ui.ftsSearchPrevious->setEnabled(res); - }); + webview->findText( allMatches.at( ftsPosition ), flags, [ this ]( bool res ) { + ftsSearchNext->setEnabled( res ); + if( !ftsSearchPrevious->isEnabled() ) + ftsSearchPrevious->setEnabled( res ); + } ); } #endif - ui.ftsSearchStatusLabel->setText( searchStatusMessage( ftsPosition + 1, allMatches.size() ) ); + ftsSearchStatusLabel->setText( searchStatusMessage( ftsPosition + 1, allMatches.size() ) ); } void ArticleView::on_ftsSearchPrevious_clicked() diff --git a/articleview.hh b/articleview.hh index 055073cd..d73f5c69 100644 --- a/articleview.hh +++ b/articleview.hh @@ -1,34 +1,39 @@ /* This file is (c) 2008-2012 Konstantin Isakov * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ -#ifndef __ARTICLEVIEW_HH_INCLUDED__ -#define __ARTICLEVIEW_HH_INCLUDED__ +#ifndef GOLDENDICT_ARTICLEVIEW_HH +#define GOLDENDICT_ARTICLEVIEW_HH -#include +#include +#include +#include #include -#include +#include #include +#include +#include #include #include "article_netmgr.hh" #include "audioplayerinterface.hh" #include "instances.hh" #include "groupcombobox.hh" -#include "ui_articleview.h" #include "globalbroadcaster.h" #include "article_inspect.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -#include +#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) + #include + #endif #include "ankiconnector.h" #include "webmultimediadownload.hh" #include "base_type.h" +#include "articlewebview.hh" class ResourceToSaveHandler; class ArticleViewAgent ; /// A widget with the web view tailored to view and handle articles -- it /// uses the appropriate netmgr, handles link clicks, rmb clicks etc -class ArticleView: public QFrame +class ArticleView: public QWidget { Q_OBJECT @@ -38,9 +43,8 @@ class ArticleView: public QFrame Instances::Groups const & groups; bool popupView; Config::Class const & cfg; - QWebChannel *channel; + QWebChannel * channel; ArticleViewAgent * agent; - Ui::ArticleView ui; AnkiConnector * ankiConnector; @@ -167,7 +171,25 @@ public: void setDelayedHighlightText(QString const & text); -public slots: + private: + // widgets + ArticleWebView * webview; + + QWidget * searchPanel; + QLineEdit * searchText; + QPushButton * searchCloseButton; + QPushButton * searchPrevious; + QPushButton * searchNext; + QCheckBox * highlightAllButton; + QCheckBox * searchCaseSensitive; + + QWidget * ftsSearchPanel; + QLabel * ftsSearchStatusLabel; + QPushButton * ftsSearchPrevious; + QPushButton * ftsSearchNext; + + + public slots: /// Goes back in history void back(); @@ -176,8 +198,7 @@ public slots: void forward(); /// Takes the focus to the view - void focus() - { ui.definition->setFocus( Qt::ShortcutFocusReason ); } + void focus() { webview->setFocus( Qt::ShortcutFocusReason ); } public: @@ -192,11 +213,11 @@ public: void setZoomFactor( qreal factor ) { - qreal existedFactor = ui.definition->zoomFactor(); - if(!qFuzzyCompare(existedFactor,factor)){ - qDebug()<<"zoom factor ,existed:"<setZoomFactor( factor ); - //ui.definition->page()->setZoomFactor(factor); + qreal existedFactor = webview->zoomFactor(); + if( !qFuzzyCompare( existedFactor, factor ) ) { + qDebug() << "zoom factor ,existed:" << existedFactor << "set:" << factor; + webview->setZoomFactor( factor ); + //webview->page()->setZoomFactor(factor); } } @@ -275,7 +296,7 @@ signals: /// typically in response to user actions /// (clicking on the article or using shortcuts). /// id - the dictionary id of the active article. - void activeArticleChanged ( ArticleView const *, QString const & id ); + void activeArticleChanged( ArticleView const *, QString const & id ); /// Signal to add word to history even if history is disabled void forceAddWordToHistory( const QString & word); @@ -418,7 +439,6 @@ private: QStringList getMutedDictionaries(unsigned group); - protected: // We need this to hide the search bar when we're showed void showEvent( QShowEvent * ); diff --git a/articleview.ui b/articleview.ui deleted file mode 100644 index 08479bd3..00000000 --- a/articleview.ui +++ /dev/null @@ -1,258 +0,0 @@ - - - ArticleView - - - - 0 - 0 - 833 - 634 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - about:blank - - - - - - - - - - - QFrame::Raised - - - - - - &Previous - - - - :/icons/previous.svg:/icons/previous.svg - - - Qt::ToolButtonTextBesideIcon - - - - - - - &Next - - - - :/icons/next.svg:/icons/next.svg - - - Qt::ToolButtonTextBesideIcon - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - - - - Find: - - - - - - - - - - x - - - - :/icons/closetab.svg:/icons/closetab.svg - - - true - - - - - - - - - - - &Previous - - - - :/icons/previous.svg:/icons/previous.svg - - - Qt::ToolButtonTextBesideIcon - - - true - - - - - - - &Next - - - - :/icons/next.svg:/icons/next.svg - - - Ctrl+G - - - Qt::ToolButtonTextBesideIcon - - - true - - - - - - - Highlight &all - - - - :/icons/highlighter.png:/icons/highlighter.png - - - true - - - false - - - Qt::ToolButtonTextBesideIcon - - - true - - - - - - - &Case Sensitive - - - - - - - Qt::Horizontal - - - - 782 - 20 - - - - - - - - - - - - - - ArticleWebView - QWidget -
articlewebview.hh
-
-
- - - - -
diff --git a/goldendict.pro b/goldendict.pro index d0533c7e..3d3853bf 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -412,7 +412,6 @@ FORMS += groups.ui \ sources.ui \ initializing.ui \ scanpopup.ui \ - articleview.ui \ preferences.ui \ about.ui \ editdictionaries.ui \