File indexing completed on 2024-04-28 16:00:59

0001 /*
0002    SPDX-FileCopyrightText: 2014-2023 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "texttospeechinterface.h"
0008 #include "texttospeech.h"
0009 
0010 using namespace TextEditTextToSpeech;
0011 
0012 class Q_DECL_HIDDEN TextEditTextToSpeech::TextToSpeechInterfacePrivate
0013 {
0014 public:
0015     TextToSpeechInterfacePrivate(TextToSpeechWidget *textToSpeechWidget)
0016         : mTextToSpeechWidget(textToSpeechWidget)
0017     {
0018     }
0019 
0020     TextToSpeechWidget *const mTextToSpeechWidget;
0021 };
0022 
0023 TextToSpeechInterface::TextToSpeechInterface(TextToSpeechWidget *textToSpeechWidget, QObject *parent)
0024     : QObject(parent)
0025     , d(new TextEditTextToSpeech::TextToSpeechInterfacePrivate(textToSpeechWidget))
0026 {
0027     TextEditTextToSpeech::TextToSpeech::self(); // init
0028     connect(d->mTextToSpeechWidget, &TextEditTextToSpeech::TextToSpeechWidget::stateChanged, this, &TextToSpeechInterface::stateChanged);
0029     connect(TextEditTextToSpeech::TextToSpeech::self(),
0030             &TextEditTextToSpeech::TextToSpeech::stateChanged,
0031             d->mTextToSpeechWidget,
0032             &TextEditTextToSpeech::TextToSpeechWidget::slotStateChanged);
0033 }
0034 
0035 TextToSpeechInterface::~TextToSpeechInterface() = default;
0036 
0037 bool TextToSpeechInterface::isReady() const
0038 {
0039     return TextEditTextToSpeech::TextToSpeech::self()->isReady();
0040 }
0041 
0042 void TextToSpeechInterface::say(const QString &text)
0043 {
0044     d->mTextToSpeechWidget->setState(TextEditTextToSpeech::TextToSpeechWidget::Play);
0045     d->mTextToSpeechWidget->showWidget();
0046     TextEditTextToSpeech::TextToSpeech::self()->say(text);
0047 }
0048 
0049 double TextToSpeechInterface::volume() const
0050 {
0051     return TextEditTextToSpeech::TextToSpeech::self()->volume();
0052 }
0053 
0054 void TextToSpeechInterface::setVolume(double value)
0055 {
0056     TextEditTextToSpeech::TextToSpeech::self()->setVolume(value);
0057 }
0058 
0059 void TextToSpeechInterface::reloadSettings()
0060 {
0061     TextEditTextToSpeech::TextToSpeech::self()->reloadSettings();
0062 }
0063 
0064 void TextToSpeechInterface::stateChanged(TextToSpeechWidget::State state)
0065 {
0066     switch (state) {
0067     case TextToSpeechWidget::Stop:
0068         TextEditTextToSpeech::TextToSpeech::self()->stop();
0069         break;
0070     case TextToSpeechWidget::Play:
0071         TextEditTextToSpeech::TextToSpeech::self()->resume();
0072         break;
0073     case TextToSpeechWidget::Pause:
0074         TextEditTextToSpeech::TextToSpeech::self()->pause();
0075         break;
0076     }
0077 }
0078 
0079 #include "moc_texttospeechinterface.cpp"