Commit 48633374 authored by Jeremy Whiting's avatar Jeremy Whiting Committed by Oliver Sander

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
parent a90bf7fe
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="okular_part" version="41">
<kpartgui name="okular_part" version="42">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/>
......@@ -84,6 +84,7 @@
<Action name="speak_document"/>
<Action name="speak_current_page"/>
<Action name="speak_stop_all"/>
<Action name="speak_pause_resume"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="show_leftpanel" group="show_merge"/>
......
......@@ -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 )
......
......@@ -274,6 +274,7 @@ Q_OBJECT
void slotSpeakDocument();
void slotSpeakCurrentPage();
void slotStopSpeaks();
void slotPauseResumeSpeech();
#endif
void slotAction( Okular::Action *action );
void externalKeyPressEvent( QKeyEvent *e );
......
......@@ -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)
......
......@@ -22,6 +22,7 @@ class OkularTTS : public QObject
void say( const QString &text );
void stopAllSpeechs();
void pauseResumeSpeech();
public slots:
void slotSpeechStateChanged(QTextToSpeech::State state);
......
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