diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -523,6 +523,12 @@ QMetaObject::invokeMethod( m_pageView, "setFocus", Qt::QueuedConnection ); //usability setting // m_splitter->setFocusProxy(m_pageView); connect( m_pageView.data(), &PageView::rightClick, this, &Part::slotShowMenu ); + connect( m_pageView, &PageView::triggerSearch, this, + [this] (const QString& searchText){ + m_findBar->startSearch(searchText); + slotShowFindBar(); + } + ); connect( m_document, &Document::error, this, &Part::errorMessage ); connect( m_document, &Document::warning, this, &Part::warningMessage ); connect( m_document, &Document::notice, this, &Part::noticeMessage ); diff --git a/ui/pageview.h b/ui/pageview.h --- a/ui/pageview.h +++ b/ui/pageview.h @@ -135,6 +135,7 @@ void mouseForwardButtonClick(); void escPressed(); void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize ); + void triggerSearch( const QString& text ); protected: bool event( QEvent * event ) override; @@ -196,6 +197,7 @@ void resizeContentArea( const QSize & newSize ); void updatePageStep(); + void addSearchWithinDocumentAction(QMenu * menu, const QString & searchText ); void addWebShortcutsMenu( QMenu * menu, const QString & text ); QMenu* createProcessLinkMenu( PageViewItem *item, const QPoint & eventPos ); // used when selecting stuff, makes the view scroll as necessary to keep the mouse inside the view diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -2794,6 +2794,7 @@ #endif if ( copyAllowed ) { + addSearchWithinDocumentAction( &menu, selectedText ); addWebShortcutsMenu( &menu, selectedText ); } } @@ -3077,6 +3078,7 @@ } else { + addSearchWithinDocumentAction(menu, d->selectedText()); addWebShortcutsMenu( menu, d->selectedText() ); } @@ -4443,6 +4445,15 @@ return nullptr; } +void PageView::addSearchWithinDocumentAction(QMenu *menu, const QString &searchText) +{ + const QString squeezedText = KStringHandler::rsqueeze( searchText, 21 ); + QAction *action = new QAction(i18n("Search for '%1' in open document", squeezedText), menu); + action->setIcon( QIcon::fromTheme( QStringLiteral("document-preview") ) ); + connect(action, &QAction::triggered, [this, searchText]{Q_EMIT triggerSearch(searchText);}); + menu->addAction( action ); +} + //BEGIN private SLOTS void PageView::slotRelayoutPages() // called by: notifySetup, viewportResizeEvent, slotViewMode, slotContinuousToggled, updateZoom