Skip to content

Commit

Permalink
Grey-out stop button when not speaking
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaopengLin committed Aug 5, 2024
1 parent 66fef4d commit e06256d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,7 @@ TextToSpeechBar > #closeButton:pressed {
background-color: #D9E9FF;
border: 1px solid #3366CC;
}

TextToSpeechBar > #stopButton:disabled {
color: grey;
}
9 changes: 9 additions & 0 deletions src/texttospeechbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent)
close();
mp_ui->setupUi(this);
mp_ui->stopButton->setText(gt("stop"));
connect(mp_speech, &QTextToSpeech::stateChanged, this, &TextToSpeechBar::onStateChanged);
connect(mp_ui->stopButton, &QPushButton::released, [=](){
mp_speech->stop();
});
Expand Down Expand Up @@ -71,6 +72,14 @@ void TextToSpeechBar::voiceSelected(int index)
mp_speech->setVoice(m_voices.at(index));
}

void TextToSpeechBar::onStateChanged(QTextToSpeech::State state)
{
if (state == QTextToSpeech::Ready)
mp_ui->stopButton->setDisabled(true);
else
mp_ui->stopButton->setDisabled(false);
}

void TextToSpeechBar::speechBarClose()
{
/* Prevent webview from scrolling to up to the top after losing focus. */
Expand Down
1 change: 1 addition & 0 deletions src/texttospeechbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public slots:
void speechBarClose();
void languageSelected(int index);
void voiceSelected(int index);
void onStateChanged(QTextToSpeech::State state);

private:
QTextToSpeech *mp_speech;
Expand Down

0 comments on commit e06256d

Please sign in to comment.