• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

dictionarycombobox.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
00003  * Copyright (c) 2008 Tom Albers <tomalbers@kde.nl>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301  USA
00019 */
00020 
00021 #include "dictionarycombobox.h"
00022 
00023 #include <kdebug.h>
00024 #include <sonnet/speller.h>
00025 
00026 namespace Sonnet
00027 {
00028 
00029 //@cond PRIVATE 
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 //@endcon
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"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal