From 39c2d29ac2de9163fa9c3f56cccb2225da6d8be1 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 26 Feb 2008 20:54:31 +0000 Subject: [PATCH] Do not copy to the selection the text when selecting "Copy text" in the RMB menu, but after releasing the LMB when "visually" selecting text. BUG: 157364 svn path=/trunk/KDE/kdegraphics/okular/; revision=779710 --- ui/pageview.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index bbbbbd20a..f0c9b1f7e 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -82,6 +82,7 @@ public: PageViewPrivate( PageView *qq ); FormWidgetsController* formWidgetsController(); + QString selectedText() const; // the document, pageviewItems and the 'visible cache' PageView *q; @@ -620,39 +621,43 @@ KAction *PageView::toggleFormsAction() const return d->aToggleForms; } -void PageView::copyTextSelection() const +QString PageViewPrivate::selectedText() const { - if ( d->pagesWithTextSelection.isEmpty() ) - return; + if ( pagesWithTextSelection.isEmpty() ) + return QString(); QString text; - QList< int > selpages = d->pagesWithTextSelection.toList(); + QList< int > selpages = pagesWithTextSelection.toList(); qSort( selpages ); const Okular::Page * pg = 0; if ( selpages.count() == 1 ) { - pg = d->document->page( selpages.first() ); + pg = document->page( selpages.first() ); text.append( pg->text( pg->textSelection() ) ); } else { - pg = d->document->page( selpages.first() ); + pg = document->page( selpages.first() ); text.append( pg->text( pg->textSelection() ) ); int end = selpages.count() - 1; for( int i = 1; i < end; ++i ) { - pg = d->document->page( selpages.at( i ) ); + pg = document->page( selpages.at( i ) ); text.append( pg->text() ); } - pg = d->document->page( selpages.last() ); + pg = document->page( selpages.last() ); text.append( pg->text( pg->textSelection() ) ); } + return text; +} + +void PageView::copyTextSelection() const +{ + const QString text = d->selectedText(); if ( !text.isEmpty() ) { QClipboard *cb = QApplication::clipboard(); cb->setText( text, QClipboard::Clipboard ); - if ( cb->supportsSelection() ) - cb->setText( text, QClipboard::Selection ); } } @@ -1913,6 +1918,13 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) { d->mouseTextSelecting = false; // textSelectionClear(); + const QString text = d->selectedText(); + if ( !text.isEmpty() ) + { + QClipboard *cb = QApplication::clipboard(); + if ( cb->supportsSelection() ) + cb->setText( text, QClipboard::Selection ); + } } else if ( !d->mousePressPos.isNull() && rightButton ) {