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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • sonnet
dictionarycombobox.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
3  * Copyright (c) 2008 Tom Albers <tomalbers@kde.nl>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19 */
20 
21 #include "dictionarycombobox.h"
22 
23 #include <kdebug.h>
24 #include <sonnet/speller.h>
25 
26 namespace Sonnet
27 {
28 
29 //@cond PRIVATE
30 class DictionaryComboBox::Private
31 {
32  public:
33  Private( DictionaryComboBox* combo ) : q( combo ) {};
34  DictionaryComboBox* q;
35  void slotDictionaryChanged( int idx );
36 };
37 
38 void DictionaryComboBox::Private::slotDictionaryChanged( int idx )
39 {
40  kDebug() << idx;
41  emit q->dictionaryChanged( q->itemData( idx ).toString() );
42  emit q->dictionaryNameChanged( q->itemText( idx ) );
43 }
44 //@endcon
45 
46 DictionaryComboBox::DictionaryComboBox( QWidget * parent )
47  : KComboBox( parent ), d( new DictionaryComboBox::Private( this ) )
48 {
49  reloadCombo();
50  connect( this, SIGNAL(activated(int)),
51  SLOT(slotDictionaryChanged(int)) );
52 }
53 
54 DictionaryComboBox::~DictionaryComboBox()
55 {
56  delete d;
57 }
58 
59 QString DictionaryComboBox::currentDictionaryName() const
60 {
61  return currentText();
62 }
63 
64 QString DictionaryComboBox::currentDictionary() const
65 {
66  return itemData( currentIndex() ).toString();
67 }
68 
69 void DictionaryComboBox::setCurrentByDictionaryName( const QString & name )
70 {
71  if ( name.isEmpty() || name == currentText() )
72  return;
73 
74  int idx = findText( name );
75  if ( idx == -1 ) {
76  kDebug() << "name not found" << name;
77  return;
78  }
79 
80  setCurrentIndex( idx );
81  d->slotDictionaryChanged( idx );
82 }
83 
84 void DictionaryComboBox::setCurrentByDictionary( const QString & dictionary )
85 {
86  if ( dictionary.isEmpty() || dictionary == itemData( currentIndex() ).toString() )
87  return;
88 
89  int idx = findData( dictionary );
90  if ( idx == -1 ) {
91  kDebug() << "dictionary not found" << dictionary;
92  return;
93  }
94 
95  setCurrentIndex( idx );
96  d->slotDictionaryChanged( idx );
97 }
98 
99 void DictionaryComboBox::reloadCombo()
100 {
101  clear();
102  Sonnet::Speller* speller = new Sonnet::Speller();
103  QMap<QString, QString> dictionaries = speller->availableDictionaries();
104  QMapIterator<QString, QString> i( dictionaries );
105  while ( i.hasNext() ) {
106  i.next();
107  kDebug() << "Populate combo:" << i.key() << ":" << i.value();
108  addItem( i.key(), i.value() );
109  }
110  delete speller;
111 }
112 
113 }
114 
115 #include "dictionarycombobox.moc"
QWidget
kdebug.h
QMap< QString, QString >
QComboBox::clear
void clear()
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QComboBox::addItem
void addItem(const QString &text, const QVariant &userData)
Sonnet::DictionaryComboBox::DictionaryComboBox
DictionaryComboBox(QWidget *parent=0)
Constructor.
QComboBox::findText
int findText(const QString &text, QFlags< Qt::MatchFlag > flags) const
QObject::name
const char * name() const
QMapIterator
QString::isEmpty
bool isEmpty() const
speller.h
Sonnet::DictionaryComboBox::currentDictionaryName
QString currentDictionaryName() const
Returns the current dictionary name, for example "German (Switzerland)".
QString
Sonnet::Speller
QComboBox::itemData
QVariant itemData(int index, int role) const
dictionarycombobox.h
Sonnet::DictionaryComboBox::reloadCombo
void reloadCombo()
Clears the widget and reloads the dictionaries from Sonnet.
Sonnet::DictionaryComboBox::currentDictionary
QString currentDictionary() const
Returns the current dictionary, for example "de_CH".
Sonnet::Speller::availableDictionaries
QMap< QString, QString > availableDictionaries() const
QComboBox::findData
int findData(const QVariant &data, int role, QFlags< Qt::MatchFlag > flags) const
Sonnet::DictionaryComboBox::setCurrentByDictionaryName
void setCurrentByDictionaryName(const QString &dictionaryName)
Sets the current dictionaryName to the given dictionaryName.
KComboBox
An enhanced combo box.
Definition: kcombobox.h:148
QComboBox::currentIndex
int currentIndex() const
QComboBox::currentText
QString currentText() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVariant::toString
QString toString() const
Sonnet::DictionaryComboBox::~DictionaryComboBox
~DictionaryComboBox()
Destructor.
Sonnet::DictionaryComboBox::setCurrentByDictionary
void setCurrentByDictionary(const QString &dictionary)
Sets the current dictionary to the given dictionary.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal