1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
/*
SPDX-FileCopyrightText: 2015-2026 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "texttospeechlanguagecombobox.h"
using namespace TextEditTextToSpeech;
TextToSpeechLanguageComboBox::TextToSpeechLanguageComboBox(QWidget *parent)
: QComboBox(parent)
{
}
TextToSpeechLanguageComboBox::~TextToSpeechLanguageComboBox() = default;
void TextToSpeechLanguageComboBox::selectLocaleName(const QString &localeName)
{
const int countItem(count());
for (int i = 0; i < countItem; ++i) {
if (itemData(i).toLocale().name() == localeName) {
setCurrentIndex(i);
break;
}
}
}
void TextToSpeechLanguageComboBox::updateAvailableLocales(const QVector<QLocale> &locales, const QLocale ¤t)
{
clear();
for (const QLocale &locale : locales) {
const QVariant localeVariant(locale);
addItem(QLocale::languageToString(locale.language()), localeVariant);
if (locale.name() == current.name()) {
setCurrentIndex(count() - 1);
}
}
setSizeAdjustPolicy(QComboBox::AdjustToContents);
// Sort it after loading list.
model()->sort(0, Qt::AscendingOrder);
}
#include "moc_texttospeechlanguagecombobox.cpp"
|