From 69179e25054c5a6452188590f57b631576458899 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 5 Mar 2008 11:06:55 +0000 Subject: [PATCH] More interaction between Okular and the KDE Text To Speech system: a) "Speak While Document" action to speak the content of the whole document b) "Speak Current Page" to just speak the content of the currently shown page c) "Speak Text" action in the right click menu of the editor-like text selection (a) also implements KPDF's bug #118872. svn path=/trunk/KDE/kdegraphics/okular/; revision=782497 --- part.rc | 5 ++++- ui/pageview.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ ui/pageview.h | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/part.rc b/part.rc index 5e6bbed57..88c07537d 100644 --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -67,6 +67,9 @@ + + + &Settings diff --git a/ui/pageview.cpp b/ui/pageview.cpp index bbf68e7c3..f9aa2701f 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -494,6 +494,18 @@ void PageView::setupActions( KActionCollection * ac ) ta->addAction( d->aMouseSelect ); ta->addAction( d->aMouseTextSelect ); + // speak actions + const bool hasTTS = Okular::Settings::useKTTSD(); + KAction *speakDoc = new KAction( KIcon( "text-speak" ), i18n( "Speak Whole Document" ), this ); + ac->addAction( "speak_document", speakDoc ); + speakDoc->setEnabled( hasTTS ); + connect( speakDoc, SIGNAL( triggered() ), SLOT( slotSpeakDocument() ) ); + + KAction *speakPage = new KAction( KIcon( "text-speak" ), i18n( "Speak Current Page" ), this ); + ac->addAction( "speak_current_page", speakPage ); + speakPage->setEnabled( hasTTS ); + connect( speakPage, SIGNAL( triggered() ), SLOT( slotSpeakCurrentPage() ) ); + // Other actions KAction * su = new KAction(i18n("Scroll Up"), this); ac->addAction("view_scroll_up", su ); @@ -1917,6 +1929,9 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) { KMenu menu( this ); QAction *textToClipboard = menu.addAction( KIcon( "edit-copy" ), i18n( "Copy Text" ) ); + QAction *speakText = 0; + if ( Okular::Settings::useKTTSD() ) + speakText = menu.addAction( KIcon( "text-speak" ), i18n( "Speak Text" ) ); if ( !d->document->isAllowed( Okular::AllowCopy ) ) { textToClipboard->setEnabled( false ); @@ -1928,6 +1943,11 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) { if ( choice == textToClipboard ) copyTextSelection(); + else if ( choice == speakText ) + { + const QString text = d->selectedText(); + d->tts()->say( text ); + } } } break; @@ -3117,6 +3137,33 @@ void PageView::slotToggleForms() void PageView::slotFormWidgetChanged( FormWidgetIface *w ) { } + +void PageView::slotSpeakDocument() +{ + QString text; + QVector< PageViewItem * >::const_iterator it = d->items.begin(), itEnd = d->items.end(); + for ( ; it < itEnd; ++it ) + { + Okular::RegularAreaRect * area = textSelectionForItem( *it ); + text.append( (*it)->page()->text( area ) ); + text.append( '\n' ); + delete area; + } + + d->tts()->say( text ); +} + +void PageView::slotSpeakCurrentPage() +{ + const int currentPage = d->document->viewport().pageNumber; + + PageViewItem *item = d->items.at( currentPage ); + Okular::RegularAreaRect * area = textSelectionForItem( item ); + const QString text = item->page()->text( area ); + delete area; + + d->tts()->say( text ); +} //END private SLOTS #include "pageview.moc" diff --git a/ui/pageview.h b/ui/pageview.h index 2a4b0348d..30467a7e9 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -196,6 +196,8 @@ Q_OBJECT void slotPageSizes( int ); void slotToggleForms(); void slotFormWidgetChanged( FormWidgetIface *w ); + void slotSpeakDocument(); + void slotSpeakCurrentPage(); }; #endif