Issue #25: Bad dialog size

This commit is contained in:
Jakub Melka 2022-09-04 16:51:50 +02:00
parent 0219139cf9
commit 72ad433467
5 changed files with 43 additions and 23 deletions

View File

@ -83,6 +83,18 @@ void PDFTextToSpeech::setDocument(const pdf::PDFModifiedDocument& document)
}
}
void PDFTextToSpeech::updateVoices()
{
QVector<QVoice> 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<QVoice> 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);
}
}
}

View File

@ -114,6 +114,7 @@ private:
void onStopClicked();
void updatePlay();
void updateVoices();
void updateToNextPage(pdf::PDFInteger pageIndex);
QTextToSpeech* m_textToSpeech;

View File

@ -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),

View File

@ -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,15 +794,19 @@ 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));
if (m_currentSpeechEngine != engine)
{
m_currentSpeechEngine = engine;
QVector<QLocale> locales = textToSpeech.availableLocales();
ui->speechLocaleComboBox->setUpdatesEnabled(false);
@ -813,6 +816,9 @@ void PDFViewerSettingsDialog::setSpeechEngine(const QString& engine)
ui->speechLocaleComboBox->addItem(QString("%1 (%2)").arg(locale.nativeLanguageName(), locale.nativeCountryName()), locale.name());
}
ui->speechLocaleComboBox->setUpdatesEnabled(true);
}
m_currentSpeechLocale = locale;
QVector<QVoice> voices = textToSpeech.availableVoices();
ui->speechVoiceComboBox->setUpdatesEnabled(false);

View File

@ -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;