mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-12 20:51:17 +00:00
Add "find in this document" to selection context menu
BUG: 408355 FIXED-IN: 1.9.0
This commit is contained in:
parent
d57eeb5918
commit
4a4a2a1b52
6
part.cpp
6
part.cpp
|
@ -524,6 +524,12 @@ m_cliPresentation(false), m_cliPrint(false), m_cliPrintAndExit(false), m_embedMo
|
|||
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 );
|
||||
|
|
|
@ -103,6 +103,12 @@ static const int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLi
|
|||
|
||||
static const float kZoomValues[] = { 0.12, 0.25, 0.33, 0.50, 0.66, 0.75, 1.00, 1.25, 1.50, 2.00, 4.00, 8.00, 16.00 };
|
||||
|
||||
// This is the length of the text that will be shown when the user is searching for a specific piece of text.
|
||||
static const int searchTextPreviewLength = 21;
|
||||
|
||||
// When following a link, only a preview of this length will be used to set the text of the action.
|
||||
static const int linkTextPreviewLength = 30;
|
||||
|
||||
static inline double normClamp( double value, double def )
|
||||
{
|
||||
return ( value < 0.0 || value > 1.0 ) ? def : value;
|
||||
|
@ -2833,6 +2839,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
#endif
|
||||
if ( copyAllowed )
|
||||
{
|
||||
addSearchWithinDocumentAction( &menu, selectedText );
|
||||
addWebShortcutsMenu( &menu, selectedText );
|
||||
}
|
||||
}
|
||||
|
@ -3116,6 +3123,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
}
|
||||
else
|
||||
{
|
||||
addSearchWithinDocumentAction(menu, d->selectedText());
|
||||
addWebShortcutsMenu( menu, d->selectedText() );
|
||||
}
|
||||
|
||||
|
@ -3125,7 +3133,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
url = UrlUtils::getUrl( d->selectedText() );
|
||||
if ( !url.isEmpty() )
|
||||
{
|
||||
const QString squeezedText = KStringHandler::rsqueeze( url, 30 );
|
||||
const QString squeezedText = KStringHandler::rsqueeze( url, linkTextPreviewLength );
|
||||
httpLink = menu->addAction( i18n( "Go to '%1'", squeezedText ) );
|
||||
httpLink->setObjectName(QStringLiteral("GoToAction"));
|
||||
}
|
||||
|
@ -4431,7 +4439,7 @@ void PageView::addWebShortcutsMenu( QMenu * menu, const QString & text )
|
|||
QMenu *webShortcutsMenu = new QMenu( menu );
|
||||
webShortcutsMenu->setIcon( QIcon::fromTheme( QStringLiteral("preferences-web-browser-shortcuts") ) );
|
||||
|
||||
const QString squeezedText = KStringHandler::rsqueeze( searchText, 21 );
|
||||
const QString squeezedText = KStringHandler::rsqueeze( searchText, searchTextPreviewLength );
|
||||
webShortcutsMenu->setTitle( i18n( "Search for '%1' with", squeezedText ) );
|
||||
|
||||
QAction *action = nullptr;
|
||||
|
@ -4507,6 +4515,15 @@ QMenu* PageView::createProcessLinkMenu(PageViewItem *item, const QPoint &eventPo
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void PageView::addSearchWithinDocumentAction(QMenu *menu, const QString &searchText)
|
||||
{
|
||||
const QString squeezedText = KStringHandler::rsqueeze( searchText, searchTextPreviewLength );
|
||||
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
|
||||
|
|
|
@ -135,6 +135,7 @@ Q_OBJECT
|
|||
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 @@ Q_OBJECT
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue