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
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent a4da9a27dc
commit 69179e2505
  1. 5
      part.rc
  2. 47
      ui/pageview.cpp
  3. 2
      ui/pageview.h

@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="23">
<kpartgui name="okular_part" version="24">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/>
@ -67,6 +67,9 @@
<Action name="mouse_textselect"/>
<Separator/>
<Action name="mouse_toggle_annotate"/>
<Separator/>
<Action name="speak_document"/>
<Action name="speak_current_page"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="show_leftpanel" group="show_merge"/>

@ -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"

@ -196,6 +196,8 @@ Q_OBJECT
void slotPageSizes( int );
void slotToggleForms();
void slotFormWidgetChanged( FormWidgetIface *w );
void slotSpeakDocument();
void slotSpeakCurrentPage();
};
#endif

Loading…
Cancel
Save