From f788b5a384b5445bd08c775e51e4041ca7045da2 Mon Sep 17 00:00:00 2001 From: Shubham Jangra Date: Mon, 22 Apr 2019 01:06:54 +0200 Subject: [PATCH] Add action in Edit menu to select the text on current page BUG: 358868 Test Plan: Click on "Select All Text on Current Page" entry in Edit menu to select the entire page. The selected text can then be copied via Edit menu item "Copy" Reviewers: aacid, #vdg, ngraham Reviewed By: #vdg, ngraham Subscribers: yurchor, michaelweghorn, kde-doc-english, davidhurka, abetts, loh.tar, alexde, ngraham, okular-devel Tags: #okular, #documentation Differential Revision: https://phabricator.kde.org/D18744 --- doc/index.docbook | 15 +++++++++++++++ part.cpp | 9 +++++++++ part.h | 1 + part.rc | 3 ++- ui/pageview.cpp | 15 +++++++++++++++ ui/pageview.h | 2 ++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/index.docbook b/doc/index.docbook index 8b83b422c..886e59365 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1284,6 +1284,21 @@ Context menu actions like Rename Bookmarks etc.) + + + + + Edit + Select All Text on Current Page + + + + Selects all the text (if the document provides it) of the current page. + + + + + diff --git a/part.cpp b/part.cpp index 869ee8a40..c831f8793 100644 --- a/part.cpp +++ b/part.cpp @@ -720,6 +720,7 @@ void Part::setupViewerActions() m_copy = nullptr; m_selectAll = nullptr; + m_selectCurrentPage = nullptr; // Find and other actions m_find = KStandardAction::find( this, SLOT(slotShowFindBar()), ac ); @@ -843,6 +844,12 @@ void Part::setupActions() m_selectAll = KStandardAction::selectAll( m_pageView, SLOT(selectAll()), ac ); + // Setup select all action for the current page + m_selectCurrentPage = ac->addAction(QStringLiteral("edit_select_all_current_page")); + m_selectCurrentPage->setText(i18n("Select All Text on Current Page")); + connect( m_selectCurrentPage, &QAction::triggered, m_pageView, &PageView::slotSelectPage ); + m_selectCurrentPage->setEnabled( false ); + m_save = KStandardAction::save( this, [this] { saveFile(); }, ac ); m_save->setEnabled( false ); @@ -2146,6 +2153,7 @@ void Part::updateViewActions() m_reload->setEnabled( true ); if (m_copy) m_copy->setEnabled( true ); if (m_selectAll) m_selectAll->setEnabled( true ); + if (m_selectCurrentPage) m_selectCurrentPage->setEnabled( true ); } else { @@ -2159,6 +2167,7 @@ void Part::updateViewActions() m_reload->setEnabled( false ); if (m_copy) m_copy->setEnabled( false ); if (m_selectAll) m_selectAll->setEnabled( false ); + if (m_selectCurrentPage) m_selectCurrentPage->setEnabled( false ); } if ( factory() ) diff --git a/part.h b/part.h index 2954e45d6..3cfc5a31d 100644 --- a/part.h +++ b/part.h @@ -360,6 +360,7 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu QAction *m_nextBookmark; QAction *m_copy; QAction *m_selectAll; + QAction *m_selectCurrentPage; QAction *m_find; QAction *m_findNext; QAction *m_findPrev; diff --git a/part.rc b/part.rc index c8dc309a0..bf15cac50 100644 --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -21,6 +21,7 @@ + diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 6369c87e5..59f9565e5 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -5538,6 +5538,21 @@ void PageView::slotFitWindowToPage() emit fitWindowToPage( viewportSize, pageSize ); } +void PageView::slotSelectPage() +{ + textSelectionClear(); + const int currentPage = d->document->viewport().pageNumber; + PageViewItem *item = d->items.at( currentPage ); + + if ( item ) + { + Okular::RegularAreaRect * area = textSelectionForItem( item ); + const QString text = item->page()->text( area ); + d->pagesWithTextSelection.insert( currentPage ); + d->document->setPageTextSelection( currentPage, area, palette().color( QPalette::Active, QPalette::Highlight ) ); + } +} + void PageView::highlightSignatureFormWidget( const Okular::FormFieldSignature *form ) { QVector< PageViewItem * >::const_iterator dIt = d->items.constBegin(), dEnd = d->items.constEnd(); diff --git a/ui/pageview.h b/ui/pageview.h index 4af4333d9..a892a5bb0 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -130,6 +130,8 @@ Q_OBJECT void slotToggleChangeColors(); void slotSetChangeColors(bool active); + void slotSelectPage(); + Q_SIGNALS: void rightClick( const Okular::Page *, const QPoint & ); void mouseBackButtonClick();