diff --git a/src/texttospeechbar.cpp b/src/texttospeechbar.cpp index 6ebb00c76..08b590fe9 100644 --- a/src/texttospeechbar.cpp +++ b/src/texttospeechbar.cpp @@ -9,7 +9,6 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent) { close(); mp_ui->setupUi(this); - mp_speech->setLocale(QLocale::system().language()); mp_ui->stopButton->setText(gt("stop")); connect(mp_speech, &QTextToSpeech::stateChanged, this, &TextToSpeechBar::onStateChanged); @@ -17,6 +16,29 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent) &TextToSpeechBar::stop); connect(mp_ui->closeButton, &QPushButton::released, this, &TextToSpeechBar::speechBarClose); + + mp_ui->langLabel->setText(gt("language")); + mp_ui->langComboBox->setMaxVisibleItems(10); + QLocale current = QLocale::system().language(); + for (auto locale : mp_speech->availableLocales()) + { + QString name(QString("%1 (%2)") + .arg(QLocale::languageToString(locale.language())) + .arg(locale.nativeLanguageName())); + QVariant localeVariant(locale); + mp_ui->langComboBox->addItem(name, localeVariant); + if (locale.name() == current.name()) + current = locale; + } + + /* Work around to both have max visible item and a read-only combobox.*/ + mp_ui->langComboBox->lineEdit()->setReadOnly(true); + mp_ui->langComboBox->lineEdit()->setFrame(false); + + connect(mp_ui->langComboBox, &QComboBox::currentIndexChanged, + this, &TextToSpeechBar::languageSelected); + mp_ui->langComboBox->setCurrentIndex(mp_ui->langComboBox->findData(current)); + languageSelected(mp_ui->langComboBox->currentIndex()); } void TextToSpeechBar::speak(const QString &text) @@ -34,6 +56,12 @@ void TextToSpeechBar::onStateChanged(QTextToSpeech::State state) mp_ui->stopButton->setEnabled(state != QTextToSpeech::Ready); } +void TextToSpeechBar::languageSelected(int index) +{ + QLocale locale = mp_ui->langComboBox->itemData(index).toLocale(); + mp_speech->setLocale(locale); +} + void TextToSpeechBar::speechBarClose() { /* Prevent webview from scrolling to up to the top after losing focus. */ diff --git a/src/texttospeechbar.h b/src/texttospeechbar.h index ba9c517e5..56621aeaa 100644 --- a/src/texttospeechbar.h +++ b/src/texttospeechbar.h @@ -19,6 +19,7 @@ class TextToSpeechBar : public QFrame public slots: void speechBarClose(); + void languageSelected(int index); void onStateChanged(QTextToSpeech::State state); private: diff --git a/src/texttospeechbar.ui b/src/texttospeechbar.ui index b0c84dfd1..819c91cf0 100644 --- a/src/texttospeechbar.ui +++ b/src/texttospeechbar.ui @@ -21,10 +21,30 @@ - + + + + + + + + + + Qt::LeftToRight + + + true + + + + + Qt::Horizontal + + QSizePolicy::Expanding + 40 @@ -57,7 +77,7 @@ - + Qt::Horizontal