From 48633374a94e980dccbbe77cbe2f846dd07a9166 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Thu, 19 Sep 2019 13:50:58 -0600 Subject: [PATCH] Add Pause/Resume action for pausing and resuming speech synthesis. Summary: TODO: Only enable the action when there's text being spoken or when speech is paused. Subscribers: okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D24102 --- part.rc | 3 ++- ui/pageview.cpp | 18 ++++++++++++++++++ ui/pageview.h | 1 + ui/tts.cpp | 11 +++++++++++ ui/tts.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/part.rc b/part.rc index 8ba1afc4f..353db202b 100644 --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -84,6 +84,7 @@ + &Settings diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 152a5b112..88d790c20 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -241,6 +241,7 @@ public: QAction * aSpeakDoc; QAction * aSpeakPage; QAction * aSpeakStop; + QAction * aSpeakPauseResume; KActionCollection * actionCollection; QActionGroup * mouseModeActionGroup; QAction * aFitWindowToPage; @@ -379,6 +380,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document ) d->aSpeakDoc = nullptr; d->aSpeakPage = nullptr; d->aSpeakStop = nullptr; + d->aSpeakPauseResume = nullptr; d->actionCollection = nullptr; d->aPageSizes=nullptr; d->setting_viewCols = Okular::Settings::viewColumns(); @@ -705,10 +707,16 @@ void PageView::setupActions( KActionCollection * ac ) 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 @@ -1253,6 +1261,7 @@ void PageView::updateActionState( bool haspages, bool documentChanged, bool hasf const bool enablettsactions = haspages ? Okular::Settings::useTTS() : false; d->aSpeakDoc->setEnabled( enablettsactions ); d->aSpeakPage->setEnabled( enablettsactions ); + d->aSpeakPauseResume->setEnabled( enablettsactions ); } #endif if (d->aMouseMagnifier) @@ -5546,6 +5555,15 @@ void PageView::slotStopSpeaks() 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/pageview.h b/ui/pageview.h index c41dda201..823038868 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -274,6 +274,7 @@ Q_OBJECT void slotSpeakDocument(); void slotSpeakCurrentPage(); void slotStopSpeaks(); + void slotPauseResumeSpeech(); #endif void slotAction( Okular::Action *action ); void externalKeyPressEvent( QKeyEvent *e ); diff --git a/ui/tts.cpp b/ui/tts.cpp index da7c75b5f..08ecf6bc5 100644 --- a/ui/tts.cpp +++ b/ui/tts.cpp @@ -60,6 +60,17 @@ void OkularTTS::stopAllSpeechs() 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) diff --git a/ui/tts.h b/ui/tts.h index 767ad4c89..003576834 100644 --- a/ui/tts.h +++ b/ui/tts.h @@ -22,6 +22,7 @@ class OkularTTS : public QObject void say( const QString &text ); void stopAllSpeechs(); + void pauseResumeSpeech(); public slots: void slotSpeechStateChanged(QTextToSpeech::State state);