diff --git a/Pdf4QtViewer/pdftexttospeech.cpp b/Pdf4QtViewer/pdftexttospeech.cpp index db2c651..bae88a9 100644 --- a/Pdf4QtViewer/pdftexttospeech.cpp +++ b/Pdf4QtViewer/pdftexttospeech.cpp @@ -83,6 +83,18 @@ void PDFTextToSpeech::setDocument(const pdf::PDFModifiedDocument& document) } } +void PDFTextToSpeech::updateVoices() +{ + QVector voices = m_textToSpeech->availableVoices(); + m_speechVoiceComboBox->setUpdatesEnabled(false); + m_speechVoiceComboBox->clear(); + for (const QVoice& voice : voices) + { + m_speechVoiceComboBox->addItem(QString("%1 (%2, %3)").arg(voice.name(), QVoice::genderName(voice.gender()), QVoice::ageName(voice.age())), voice.name()); + } + m_speechVoiceComboBox->setUpdatesEnabled(true); +} + void PDFTextToSpeech::setSettings(const PDFViewerSettings* viewerSettings) { Q_ASSERT(viewerSettings); @@ -103,6 +115,7 @@ void PDFTextToSpeech::setSettings(const PDFViewerSettings* viewerSettings) if (!settings.m_speechEngine.isEmpty()) { m_textToSpeech = new QTextToSpeech(settings.m_speechEngine, this); + m_textToSpeech->setLocale(QLocale(settings.m_speechLocale)); connect(m_textToSpeech, &QTextToSpeech::stateChanged, this, &PDFTextToSpeech::updatePlay); m_state = m_document ? Ready : NoDocument; @@ -115,14 +128,7 @@ void PDFTextToSpeech::setSettings(const PDFViewerSettings* viewerSettings) } m_speechLocaleComboBox->setUpdatesEnabled(true); - QVector voices = m_textToSpeech->availableVoices(); - m_speechVoiceComboBox->setUpdatesEnabled(false); - m_speechVoiceComboBox->clear(); - for (const QVoice& voice : voices) - { - m_speechVoiceComboBox->addItem(QString("%1 (%2, %3)").arg(voice.name(), QVoice::genderName(voice.gender()), QVoice::ageName(voice.age())), voice.name()); - } - m_speechVoiceComboBox->setUpdatesEnabled(true); + updateVoices(); } else { @@ -340,6 +346,12 @@ void PDFTextToSpeech::onLocaleChanged() if (m_textToSpeech) { m_textToSpeech->setLocale(QLocale(m_speechLocaleComboBox->currentData().toString())); + updateVoices(); + + if (m_speechVoiceComboBox->currentIndex() == -1) + { + m_speechVoiceComboBox->setCurrentIndex(0); + } } } diff --git a/Pdf4QtViewer/pdftexttospeech.h b/Pdf4QtViewer/pdftexttospeech.h index db4feff..7e19f82 100644 --- a/Pdf4QtViewer/pdftexttospeech.h +++ b/Pdf4QtViewer/pdftexttospeech.h @@ -114,6 +114,7 @@ private: void onStopClicked(); void updatePlay(); + void updateVoices(); void updateToNextPage(pdf::PDFInteger pageIndex); QTextToSpeech* m_textToSpeech; diff --git a/Pdf4QtViewer/pdfviewersettings.cpp b/Pdf4QtViewer/pdfviewersettings.cpp index 2ad124b..0dab45a 100644 --- a/Pdf4QtViewer/pdfviewersettings.cpp +++ b/Pdf4QtViewer/pdfviewersettings.cpp @@ -264,7 +264,7 @@ PDFViewerSettings::Settings::Settings() : m_allowLaunchURI(true), m_allowDeveloperMode(false), m_multithreadingStrategy(pdf::PDFExecutionPolicy::Strategy::AlwaysMultithreaded), - m_compiledPageCacheLimit(128 * 1024), + m_compiledPageCacheLimit(512 * 1024), m_thumbnailsCacheLimit(PIXMAP_CACHE_LIMIT), m_fontCacheLimit(pdf::DEFAULT_FONT_CACHE_LIMIT), m_instancedFontCacheLimit(pdf::DEFAULT_REALIZED_FONT_CACHE_LIMIT), diff --git a/Pdf4QtViewer/pdfviewersettingsdialog.cpp b/Pdf4QtViewer/pdfviewersettingsdialog.cpp index 063c665..78796ff 100644 --- a/Pdf4QtViewer/pdfviewersettingsdialog.cpp +++ b/Pdf4QtViewer/pdfviewersettingsdialog.cpp @@ -189,16 +189,16 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin connect(ui->trustedCertificateStoreTableWidget, &QTableWidget::itemSelectionChanged, this, &PDFViewerSettingsDialog::updateTrustedCertificatesTableActions); connect(ui->pluginsTableWidget, &QTableWidget::itemSelectionChanged, this, &PDFViewerSettingsDialog::updatePluginInformation); - setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(1000, 700))); + setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(1000, 800))); pdf::PDFWidgetUtils::style(this); ui->optionsPagesWidget->setCurrentRow(0); - adjustSize(); loadData(); loadActionShortcutsTable(); loadPluginsTable(); updateTrustedCertificatesTable(); updateTrustedCertificatesTableActions(); + resize(sizeHint()); } PDFViewerSettingsDialog::~PDFViewerSettingsDialog() @@ -387,8 +387,7 @@ void PDFViewerSettingsDialog::loadData() // Text-to-speech ui->speechEnginesComboBox->setCurrentIndex(ui->speechEnginesComboBox->findData(m_settings.m_speechEngine)); - QString speechEngine = ui->speechEnginesComboBox->currentData().toString(); - setSpeechEngine(speechEngine); + setSpeechEngine(m_settings.m_speechEngine, m_settings.m_speechLocale); ui->speechLocaleComboBox->setCurrentIndex(ui->speechLocaleComboBox->findData(m_settings.m_speechLocale)); ui->speechVoiceComboBox->setCurrentIndex(ui->speechVoiceComboBox->findData(m_settings.m_speechVoice)); ui->speechRateEdit->setValue(m_settings.m_speechRate); @@ -795,24 +794,31 @@ void PDFViewerSettingsDialog::updatePluginInformation() } } -void PDFViewerSettingsDialog::setSpeechEngine(const QString& engine) +void PDFViewerSettingsDialog::setSpeechEngine(const QString& engine, const QString& locale) { - if (m_currentSpeechEngine == engine) + if (m_currentSpeechEngine == engine && m_currentSpeechLocale == locale) { return; } - m_currentSpeechEngine = engine; QTextToSpeech textToSpeech(engine, nullptr); + textToSpeech.setLocale(QLocale(locale)); - QVector locales = textToSpeech.availableLocales(); - ui->speechLocaleComboBox->setUpdatesEnabled(false); - ui->speechLocaleComboBox->clear(); - for (const QLocale& locale : locales) + if (m_currentSpeechEngine != engine) { - ui->speechLocaleComboBox->addItem(QString("%1 (%2)").arg(locale.nativeLanguageName(), locale.nativeCountryName()), locale.name()); + m_currentSpeechEngine = engine; + + QVector locales = textToSpeech.availableLocales(); + ui->speechLocaleComboBox->setUpdatesEnabled(false); + ui->speechLocaleComboBox->clear(); + for (const QLocale& locale : locales) + { + ui->speechLocaleComboBox->addItem(QString("%1 (%2)").arg(locale.nativeLanguageName(), locale.nativeCountryName()), locale.name()); + } + ui->speechLocaleComboBox->setUpdatesEnabled(true); } - ui->speechLocaleComboBox->setUpdatesEnabled(true); + + m_currentSpeechLocale = locale; QVector voices = textToSpeech.availableVoices(); ui->speechVoiceComboBox->setUpdatesEnabled(false); diff --git a/Pdf4QtViewer/pdfviewersettingsdialog.h b/Pdf4QtViewer/pdfviewersettingsdialog.h index e7613ef..c21563d 100644 --- a/Pdf4QtViewer/pdfviewersettingsdialog.h +++ b/Pdf4QtViewer/pdfviewersettingsdialog.h @@ -107,7 +107,7 @@ private: void savePluginsTable(); void updatePluginInformation(); - void setSpeechEngine(const QString& engine); + void setSpeechEngine(const QString& engine, const QString& locale); /// Returns true, if dialog can be closed. If not, then message is displayed /// and false is returned. @@ -121,6 +121,7 @@ private: bool m_isLoadingData; QStringList m_textToSpeechEngines; QString m_currentSpeechEngine; + QString m_currentSpeechLocale; pdf::PDFCertificateStore m_certificateStore; QStringList m_enabledPlugins; pdf::PDFPluginInfos m_plugins;