7#include "texttospeechwidget.h"
8#include "texttospeechactions.h"
9#include "texttospeechconfigdialog.h"
10#include "texttospeechinterface.h"
11#include "texttospeechsliderwidget.h"
12#include <KLocalizedString>
20using namespace std::chrono_literals;
23using namespace TextEditTextToSpeech;
25class Q_DECL_HIDDEN TextEditTextToSpeech::TextToSpeechWidgetPrivate
28 TextToSpeechWidgetPrivate() =
default;
36 TextToSpeechSliderWidget *mVolume =
nullptr;
37 bool mNeedToHide =
false;
40TextToSpeechWidget::TextToSpeechWidget(
QWidget *parent)
42 , d(new TextEditTextToSpeech::TextToSpeechWidgetPrivate)
45 hbox->setObjectName(QStringLiteral(
"hbox"));
46 hbox->setContentsMargins(
QMargins{});
49 connect(d->mTextToSpeechActions, &TextToSpeechActions::stateChanged,
this, &TextToSpeechWidget::stateChanged);
52 close->setObjectName(QStringLiteral(
"close-button"));
54 close->setToolTip(
i18nc(
"@info:tooltip",
"Close"));
56 hbox->addWidget(close);
60 hbox->addWidget(volume);
61 d->mVolume =
new TextToSpeechSliderWidget(QStringLiteral(
"%1 %"),
this);
62 d->mVolume->setMinimumWidth(100);
63 d->mVolume->setObjectName(QStringLiteral(
"volumeslider"));
64 d->mVolume->setRange(0, 100);
65 connect(d->mVolume, &TextToSpeechSliderWidget::valueChanged,
this, &TextToSpeechWidget::slotVolumeChanged);
66 hbox->addWidget(d->mVolume);
69 d->mStopButton->setObjectName(QStringLiteral(
"stopbutton"));
70 d->mStopButton->setDefaultAction(d->mTextToSpeechActions->stopAction());
71 hbox->addWidget(d->mStopButton);
74 d->mPlayPauseButton->setObjectName(QStringLiteral(
"playpausebutton"));
75 d->mPlayPauseButton->setDefaultAction(d->mTextToSpeechActions->playPauseAction());
76 hbox->addWidget(d->mPlayPauseButton);
80 d->mConfigureButton->setToolTip(
i18nc(
"@info:tooltip",
"Configureā¦"));
81 d->mConfigureButton->setObjectName(QStringLiteral(
"configurebutton"));
83 hbox->addWidget(d->mConfigureButton);
91TextToSpeechWidget::~TextToSpeechWidget() =
default;
93void TextToSpeechWidget::slotCloseTextToSpeechWidget()
95 d->mTextToSpeechActions->slotStop();
99void TextToSpeechWidget::slotConfigure()
101 if (!d->mConfigDialog.data()) {
102 d->mNeedToHide =
false;
103 d->mConfigDialog =
new TextToSpeechConfigDialog(
this);
104 if (d->mConfigDialog->exec()) {
105 d->mTextToSpeechInterface->reloadSettings();
108 delete d->mConfigDialog;
109 if (d->mNeedToHide) {
111 d->mNeedToHide =
false;
116void TextToSpeechWidget::slotVolumeChanged(
int value)
118 d->mTextToSpeechInterface->setVolume(value / 100.0);
121bool TextToSpeechWidget::isReady()
const
123 return d->mTextToSpeechInterface->isReady();
126void TextToSpeechWidget::say(
const QString &text)
129 if (d->mTextToSpeechInterface->isReady()) {
130 d->mTextToSpeechInterface->say(text);
137TextToSpeechWidget::State TextToSpeechWidget::state()
const
139 return d->mTextToSpeechActions->state();
142void TextToSpeechWidget::slotStateChanged(TextEditTextToSpeech::TextToSpeech::State state)
145 case TextEditTextToSpeech::TextToSpeech::Ready:
146 if (state == TextEditTextToSpeech::TextToSpeech::Ready) {
147 d->mTextToSpeechActions->setState(TextToSpeechWidget::Stop);
148 if (d->mConfigDialog) {
149 d->mNeedToHide =
true;
161void TextToSpeechWidget::showWidget()
164 Q_EMIT changeVisibility(
true);
167void TextToSpeechWidget::hideWidget()
170 Q_EMIT changeVisibility(
false);
173void TextToSpeechWidget::setState(TextToSpeechWidget::State state)
175 d->mTextToSpeechActions->setState(state);
180 delete d->mTextToSpeechInterface;
181 d->mTextToSpeechInterface = interface;
183 if (d->mTextToSpeechInterface) {
184 d->mTextToSpeechInterface->reloadSettings();
189void TextToSpeechWidget::applyVolume()
193 d->mVolume->setValue(d->mTextToSpeechInterface->volume() * 100);
196#include "moc_texttospeechwidget.cpp"
The TextToSpeechActions class.
The TextToSpeechInterface class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
const QList< QKeySequence > & close()
QIcon fromTheme(const QString &name)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)