7#include "texttospeechactions.h"
8#include <KLocalizedString>
11using namespace TextEditTextToSpeech;
13class Q_DECL_HIDDEN TextEditTextToSpeech::TextToSpeechActionsPrivate
16 TextToSpeechActionsPrivate() =
default;
18 void updateButtonState();
19 TextToSpeechWidget::State mState = TextToSpeechWidget::Stop;
21 QAction *mPlayPauseAction =
nullptr;
24TextToSpeechActions::TextToSpeechActions(
QObject *parent)
26 , d(new TextEditTextToSpeech::TextToSpeechActionsPrivate)
28 d->mStopAction =
new QAction(
i18nc(
"@action",
"Stop"),
this);
29 d->mStopAction->setObjectName(QStringLiteral(
"stopbutton"));
30 d->mStopAction->setIcon(
QIcon::fromTheme(QStringLiteral(
"media-playback-stop")));
31 d->mStopAction->setToolTip(
i18nc(
"@info:tooltip",
"Stop"));
34 d->mPlayPauseAction =
new QAction(
this);
35 d->mPlayPauseAction->setObjectName(QStringLiteral(
"playpausebutton"));
36 d->mPlayPauseAction->setIcon(
QIcon::fromTheme(QStringLiteral(
"media-playback-start")));
39 d->updateButtonState();
42TextToSpeechActions::~TextToSpeechActions() =
default;
44QAction *TextToSpeechActions::stopAction()
const
46 return d->mStopAction;
49QAction *TextToSpeechActions::playPauseAction()
const
51 return d->mPlayPauseAction;
54TextToSpeechWidget::State TextToSpeechActions::state()
const
59void TextToSpeechActions::setState(TextToSpeechWidget::State state)
61 if (d->mState != state) {
63 d->updateButtonState();
67void TextToSpeechActionsPrivate::updateButtonState()
70 QIcon::fromTheme((mState == TextToSpeechWidget::Stop) ? QStringLiteral(
"media-playback-start") : QStringLiteral(
"media-playback-pause")));
71 mPlayPauseAction->
setEnabled((mState != TextToSpeechWidget::Stop));
72 const QString text = (mState != TextToSpeechWidget::Play) ?
i18n(
"Pause") :
i18n(
"Play");
74 mPlayPauseAction->
setText(text);
77void TextToSpeechActions::slotPlayPause()
79 if (d->mState == TextEditTextToSpeech::TextToSpeechWidget::Pause) {
80 d->mState = TextEditTextToSpeech::TextToSpeechWidget::Play;
81 }
else if (d->mState == TextEditTextToSpeech::TextToSpeechWidget::Play) {
82 d->mState = TextEditTextToSpeech::TextToSpeechWidget::Pause;
83 }
else if (d->mState == TextEditTextToSpeech::TextToSpeechWidget::Stop) {
84 d->mState = TextEditTextToSpeech::TextToSpeechWidget::Play;
88 d->updateButtonState();
89 Q_EMIT stateChanged(d->mState);
92void TextToSpeechActions::slotStop()
94 if (d->mState != TextEditTextToSpeech::TextToSpeechWidget::Stop) {
95 d->mState = TextEditTextToSpeech::TextToSpeechWidget::Stop;
96 d->updateButtonState();
97 Q_EMIT stateChanged(d->mState);
101#include "moc_texttospeechactions.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void setIcon(const QIcon &icon)
void setText(const QString &text)
void triggered(bool checked)
QIcon fromTheme(const QString &name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)