KDEUI
dictionarycombobox.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "dictionarycombobox.h"
00022
00023 #include <kdebug.h>
00024 #include <sonnet/speller.h>
00025
00026 namespace Sonnet
00027 {
00028
00029
00030 class DictionaryComboBox::Private
00031 {
00032 public:
00033 Private( DictionaryComboBox* combo ) : q( combo ) {};
00034 DictionaryComboBox* q;
00035 void slotDictionaryChanged( int idx );
00036 };
00037
00038 void DictionaryComboBox::Private::slotDictionaryChanged( int idx )
00039 {
00040 kDebug() << idx;
00041 emit q->dictionaryChanged( q->itemData( idx ).toString() );
00042 emit q->dictionaryNameChanged( q->itemText( idx ) );
00043 }
00044
00045
00046 DictionaryComboBox::DictionaryComboBox( QWidget * parent )
00047 : KComboBox( parent ), d( new DictionaryComboBox::Private( this ) )
00048 {
00049 reloadCombo();
00050 connect( this, SIGNAL( activated( int ) ),
00051 SLOT( slotDictionaryChanged( int ) ) );
00052 }
00053
00054 DictionaryComboBox::~DictionaryComboBox()
00055 {
00056 delete d;
00057 }
00058
00059 QString DictionaryComboBox::currentDictionaryName() const
00060 {
00061 return currentText();
00062 }
00063
00064 QString DictionaryComboBox::currentDictionary() const
00065 {
00066 return itemData( currentIndex() ).toString();
00067 }
00068
00069 void DictionaryComboBox::setCurrentByDictionaryName( const QString & name )
00070 {
00071 if ( name.isEmpty() || name == currentText() )
00072 return;
00073
00074 int idx = findText( name );
00075 if ( idx == -1 ) {
00076 kDebug() << "name not found" << name;
00077 return;
00078 }
00079
00080 setCurrentIndex( idx );
00081 d->slotDictionaryChanged( idx );
00082 }
00083
00084 void DictionaryComboBox::setCurrentByDictionary( const QString & dictionary )
00085 {
00086 if ( dictionary.isEmpty() || dictionary == itemData( currentIndex() ).toString() )
00087 return;
00088
00089 int idx = findData( dictionary );
00090 if ( idx == -1 ) {
00091 kDebug() << "dictionary not found" << dictionary;
00092 return;
00093 }
00094
00095 setCurrentIndex( idx );
00096 d->slotDictionaryChanged( idx );
00097 }
00098
00099 void DictionaryComboBox::reloadCombo()
00100 {
00101 clear();
00102 Sonnet::Speller* speller = new Sonnet::Speller();
00103 QMap<QString, QString> dictionaries = speller->availableDictionaries();
00104 QMapIterator<QString, QString> i( dictionaries );
00105 while ( i.hasNext() ) {
00106 i.next();
00107 kDebug() << "Populate combo:" << i.key() << ":" << i.value();
00108 addItem( i.key(), i.value() );
00109 }
00110 delete speller;
00111 }
00112
00113 }
00114
00115 #include "dictionarycombobox.moc"