Commit 69179e25 authored by Pino Toscano's avatar Pino Toscano

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
parent a4da9a27
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="23"> <kpartgui name="okular_part" version="24">
<MenuBar> <MenuBar>
<Menu name="file"><text>&amp;File</text> <Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/> <Action name="get_new_stuff" group="file_open"/>
...@@ -67,6 +67,9 @@ ...@@ -67,6 +67,9 @@
<Action name="mouse_textselect"/> <Action name="mouse_textselect"/>
<Separator/> <Separator/>
<Action name="mouse_toggle_annotate"/> <Action name="mouse_toggle_annotate"/>
<Separator/>
<Action name="speak_document"/>
<Action name="speak_current_page"/>
</Menu> </Menu>
<Menu name="settings"><text>&amp;Settings</text> <Menu name="settings"><text>&amp;Settings</text>
<Action name="show_leftpanel" group="show_merge"/> <Action name="show_leftpanel" group="show_merge"/>
......
...@@ -494,6 +494,18 @@ void PageView::setupActions( KActionCollection * ac ) ...@@ -494,6 +494,18 @@ void PageView::setupActions( KActionCollection * ac )
ta->addAction( d->aMouseSelect ); ta->addAction( d->aMouseSelect );
ta->addAction( d->aMouseTextSelect ); 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 // Other actions
KAction * su = new KAction(i18n("Scroll Up"), this); KAction * su = new KAction(i18n("Scroll Up"), this);
ac->addAction("view_scroll_up", su ); ac->addAction("view_scroll_up", su );
...@@ -1917,6 +1929,9 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) ...@@ -1917,6 +1929,9 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
{ {
KMenu menu( this ); KMenu menu( this );
QAction *textToClipboard = menu.addAction( KIcon( "edit-copy" ), i18n( "Copy Text" ) ); 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 ) ) if ( !d->document->isAllowed( Okular::AllowCopy ) )
{ {
textToClipboard->setEnabled( false ); textToClipboard->setEnabled( false );
...@@ -1928,6 +1943,11 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) ...@@ -1928,6 +1943,11 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
{ {
if ( choice == textToClipboard ) if ( choice == textToClipboard )
copyTextSelection(); copyTextSelection();
else if ( choice == speakText )
{
const QString text = d->selectedText();
d->tts()->say( text );
}
} }
} }
break; break;
...@@ -3117,6 +3137,33 @@ void PageView::slotToggleForms() ...@@ -3117,6 +3137,33 @@ void PageView::slotToggleForms()
void PageView::slotFormWidgetChanged( FormWidgetIface *w ) 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 //END private SLOTS
#include "pageview.moc" #include "pageview.moc"
...@@ -196,6 +196,8 @@ Q_OBJECT ...@@ -196,6 +196,8 @@ Q_OBJECT
void slotPageSizes( int ); void slotPageSizes( int );
void slotToggleForms(); void slotToggleForms();
void slotFormWidgetChanged( FormWidgetIface *w ); void slotFormWidgetChanged( FormWidgetIface *w );
void slotSpeakDocument();
void slotSpeakCurrentPage();
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment