From ef52350f7db39e9f39a83212ba469bdca6a72cb5 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Thu, 26 Sep 2019 00:08:50 -0600 Subject: [PATCH] When tts engine is changed via okular settings recreate tts object. --- ui/tts.cpp | 20 ++++++++++++++++++++ ui/tts.h | 1 + 2 files changed, 21 insertions(+) diff --git a/ui/tts.cpp b/ui/tts.cpp index d309576da..37675d0bb 100644 --- a/ui/tts.cpp +++ b/ui/tts.cpp @@ -33,12 +33,19 @@ public: OkularTTS *q; QTextToSpeech *speech; + // Which speech engine was used when above object was created. + // When the setting changes, we need to stop speaking and recreate. + QString speechEngine; }; OkularTTS::OkularTTS( QObject *parent ) : QObject( parent ), d( new Private( this ) ) { + // Initialize speechEngine so we can reinitialize if it changes. + d->speechEngine = Okular::Settings::ttsEngine(); connect( d->speech, &QTextToSpeech::stateChanged, this, &OkularTTS::slotSpeechStateChanged); + connect( Okular::Settings::self(), &KConfigSkeleton::configChanged, + this, &OkularTTS::slotConfigChanged); } OkularTTS::~OkularTTS() @@ -90,5 +97,18 @@ void OkularTTS::slotSpeechStateChanged(QTextToSpeech::State state) } } +void OkularTTS::slotConfigChanged() +{ + const QString engine = Okular::Settings::ttsEngine(); + if (engine != d->speechEngine) + { + d->speech->stop(); + delete d->speech; + d->speech = new QTextToSpeech(engine); + connect( d->speech, &QTextToSpeech::stateChanged, this, &OkularTTS::slotSpeechStateChanged); + d->speechEngine = engine; + } +} + #include "moc_tts.cpp" diff --git a/ui/tts.h b/ui/tts.h index 9030a88a1..eaa8557cb 100644 --- a/ui/tts.h +++ b/ui/tts.h @@ -26,6 +26,7 @@ class OkularTTS : public QObject public slots: void slotSpeechStateChanged(QTextToSpeech::State state); + void slotConfigChanged(); signals: void isSpeaking( bool speaking );