KTextAddons

texttospeechinterface.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "texttospeechinterface.h"
8#include "texttospeech.h"
9
10using namespace TextEditTextToSpeech;
11
12class Q_DECL_HIDDEN TextEditTextToSpeech::TextToSpeechInterfacePrivate
13{
14public:
15 TextToSpeechInterfacePrivate(TextToSpeechWidget *textToSpeechWidget)
16 : mTextToSpeechWidget(textToSpeechWidget)
17 {
18 }
19
20 TextToSpeechWidget *const mTextToSpeechWidget;
21};
22
23TextToSpeechInterface::TextToSpeechInterface(TextToSpeechWidget *textToSpeechWidget, QObject *parent)
24 : QObject(parent)
25 , d(new TextEditTextToSpeech::TextToSpeechInterfacePrivate(textToSpeechWidget))
26{
27 TextEditTextToSpeech::TextToSpeech::self(); // init
28 connect(d->mTextToSpeechWidget, &TextEditTextToSpeech::TextToSpeechWidget::stateChanged, this, &TextToSpeechInterface::stateChanged);
29 connect(TextEditTextToSpeech::TextToSpeech::self(),
30 &TextEditTextToSpeech::TextToSpeech::stateChanged,
31 d->mTextToSpeechWidget,
32 &TextEditTextToSpeech::TextToSpeechWidget::slotStateChanged);
33}
34
35TextToSpeechInterface::~TextToSpeechInterface() = default;
36
37bool TextToSpeechInterface::isReady() const
38{
39 return TextEditTextToSpeech::TextToSpeech::self()->isReady();
40}
41
42void TextToSpeechInterface::say(const QString &text)
43{
44 d->mTextToSpeechWidget->setState(TextEditTextToSpeech::TextToSpeechWidget::Play);
45 d->mTextToSpeechWidget->showWidget();
46 TextEditTextToSpeech::TextToSpeech::self()->say(text);
47}
48
49double TextToSpeechInterface::volume() const
50{
51 return TextEditTextToSpeech::TextToSpeech::self()->volume();
52}
53
54void TextToSpeechInterface::setVolume(double value)
55{
56 TextEditTextToSpeech::TextToSpeech::self()->setVolume(value);
57}
58
59void TextToSpeechInterface::reloadSettings()
60{
61 TextEditTextToSpeech::TextToSpeech::self()->reloadSettings();
62}
63
64void TextToSpeechInterface::stateChanged(TextToSpeechWidget::State state)
65{
66 switch (state) {
67 case TextToSpeechWidget::Stop:
68 TextEditTextToSpeech::TextToSpeech::self()->stop();
69 break;
70 case TextToSpeechWidget::Play:
71 TextEditTextToSpeech::TextToSpeech::self()->resume();
72 break;
73 case TextToSpeechWidget::Pause:
74 TextEditTextToSpeech::TextToSpeech::self()->pause();
75 break;
76 }
77}
78
79#include "moc_texttospeechinterface.cpp"
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.