File indexing completed on 2025-04-20 12:50:01
0001 /* 0002 SPDX-FileCopyrightText: 2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "texttospeechvoicecombobox.h" 0008 #include <QDebug> 0009 using namespace TextEditTextToSpeech; 0010 0011 TextToSpeechVoiceComboBox::TextToSpeechVoiceComboBox(QWidget *parent) 0012 : QComboBox(parent) 0013 { 0014 } 0015 0016 TextToSpeechVoiceComboBox::~TextToSpeechVoiceComboBox() = default; 0017 0018 QVoice TextToSpeechVoiceComboBox::currentVoice() const 0019 { 0020 return currentData().value<QVoice>(); 0021 } 0022 0023 void TextToSpeechVoiceComboBox::setCurrentVoice(const QVoice &voice) 0024 { 0025 const int index = findData(QVariant::fromValue(voice)); 0026 qDebug() << " count " << count(); 0027 qDebug() << " index " << index; 0028 if (index != -1) { 0029 setCurrentIndex(index); 0030 } 0031 } 0032 0033 void TextToSpeechVoiceComboBox::updateVoices(const QVector<QVoice> &voices) 0034 { 0035 clear(); 0036 for (const QVoice &voice : voices) { 0037 addItem(voice.name(), QVariant::fromValue(voice)); 0038 } 0039 setSizeAdjustPolicy(QComboBox::AdjustToContents); 0040 // Sort it after loading list. 0041 model()->sort(0, Qt::AscendingOrder); 0042 } 0043 0044 #include "moc_texttospeechvoicecombobox.cpp"