diff --git a/part.rc b/part.rc --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -84,6 +84,7 @@ + &Settings diff --git a/ui/pageview.h b/ui/pageview.h --- a/ui/pageview.h +++ b/ui/pageview.h @@ -270,6 +270,7 @@ void slotSpeakDocument(); void slotSpeakCurrentPage(); void slotStopSpeaks(); + void slotPauseResumeSpeech(); #endif void slotAction( Okular::Action *action ); void externalKeyPressEvent( QKeyEvent *e ); diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -234,6 +234,7 @@ QAction * aSpeakDoc; QAction * aSpeakPage; QAction * aSpeakStop; + QAction * aSpeakPauseResume; KActionCollection * actionCollection; QActionGroup * mouseModeActionGroup; QAction * aFitWindowToPage; @@ -372,6 +373,7 @@ d->aSpeakDoc = nullptr; d->aSpeakPage = nullptr; d->aSpeakStop = nullptr; + d->aSpeakPauseResume = nullptr; d->actionCollection = nullptr; d->aPageSizes=nullptr; d->setting_viewCols = Okular::Settings::viewColumns(); @@ -698,10 +700,16 @@ ac->addAction( QStringLiteral("speak_stop_all"), d->aSpeakStop ); d->aSpeakStop->setEnabled( false ); connect( d->aSpeakStop, &QAction::triggered, this, &PageView::slotStopSpeaks ); + + d->aSpeakPauseResume = new QAction( QIcon::fromTheme( QStringLiteral("media-playback-pause") ), i18n( "Pause/Resume Speaking" ), this ); + ac->addAction( QStringLiteral("speak_pause_resume"), d->aSpeakPauseResume ); + d->aSpeakPauseResume->setEnabled( false ); + connect( d->aSpeakPauseResume, &QAction::triggered, this, &PageView::slotPauseResumeSpeech ); #else d->aSpeakDoc = 0; d->aSpeakPage = 0; d->aSpeakStop = 0; + d->aSpeakPauseResume = 0; #endif // Other actions @@ -1246,6 +1254,7 @@ const bool enablettsactions = haspages ? Okular::Settings::useTTS() : false; d->aSpeakDoc->setEnabled( enablettsactions ); d->aSpeakPage->setEnabled( enablettsactions ); + d->aSpeakPauseResume->setEnabled( enablettsactions ); } #endif if (d->aMouseMagnifier) @@ -2603,7 +2612,7 @@ { // handle click over a image } -/* Enrico and me have decided this is not worth the trouble it generates +/* Enrico and me have decided this is not worth the trouble it generates else { // if not on a rect, the click selects the page @@ -2812,6 +2821,7 @@ QAction *textToClipboard = nullptr; #ifdef HAVE_SPEECH QAction *speakText = nullptr; + QAction *pauseResumeSpeech = nullptr; #endif QAction *imageToClipboard = nullptr; QAction *imageToFile = nullptr; @@ -2828,7 +2838,10 @@ } #ifdef HAVE_SPEECH if ( Okular::Settings::useTTS() ) + { speakText = menu.addAction( QIcon::fromTheme(QStringLiteral("text-speak")), i18n( "Speak Text" ) ); + pauseResumeSpeech = menu.addAction( QIcon::fromTheme(QStringLiteral("text-speak")), i18n( "Pause/Resume Speech" ) ); + } #endif if ( copyAllowed ) { @@ -2898,6 +2911,11 @@ // [2] speech selection using TTS d->tts()->say( selectedText ); } + else if ( choice == pauseResumeSpeech ) + { + // [3] pause or resume speech synthesis + d->tts()->pauseResumeSpeech(); + } #endif } } @@ -3812,7 +3830,7 @@ void PageView::scrollPosIntoView( const QPoint & pos ) { // this number slows the speed of the page by its value, chosen not to be too fast or too slow, the actual speed is determined from the mouse position, not critical - const int damping=6; + const int damping=6; if (pos.x() < horizontalScrollBar()->value()) d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value())/damping); else if (horizontalScrollBar()->value() + viewport()->width() < pos.x()) d->dragScrollVector.setX((pos.x() - horizontalScrollBar()->value() - viewport()->width())/damping); @@ -5474,6 +5492,15 @@ d->m_tts->stopAllSpeechs(); } + +void PageView::slotPauseResumeSpeech() +{ + if ( !d->m_tts ) + return; + + d->m_tts->pauseResumeSpeech(); +} + #endif void PageView::slotAction( Okular::Action *action ) diff --git a/ui/tts.h b/ui/tts.h --- a/ui/tts.h +++ b/ui/tts.h @@ -22,6 +22,7 @@ void say( const QString &text ); void stopAllSpeechs(); + void pauseResumeSpeech(); public slots: void slotSpeechStateChanged(QTextToSpeech::State state); diff --git a/ui/tts.cpp b/ui/tts.cpp --- a/ui/tts.cpp +++ b/ui/tts.cpp @@ -60,6 +60,17 @@ d->speech->stop(); } +void OkularTTS::pauseResumeSpeech() +{ + if ( !d->speech ) + return; + + if ( d->speech->state() == QTextToSpeech::Speaking ) + d->speech->pause(); + else + d->speech->resume(); +} + void OkularTTS::slotSpeechStateChanged(QTextToSpeech::State state) { if (state == QTextToSpeech::Speaking)