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

KDE3Support

  • sources
  • kde-4.14
  • kdelibs
  • kde3support
  • kdeui
k3spelldlg.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 David Sweet <dsweet@kde.org>
3  Copyright (C) 2000 Rik Hemsley <rik@kde.org>
4  Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de>
5  Copyright (C) 2003 Zack Rusin <zack@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "k3spelldlg.h"
23 
24 #include <QProgressBar>
25 
26 #include <kconfig.h>
27 #include <kglobal.h>
28 #include <klocale.h>
29 #include <kdebug.h>
30 
31 #include "k3sconfig.h"
32 #include "ui_k3spellui.h"
33 #include <kconfiggroup.h>
34 #include <kdebug.h>
35 
36 //to initially disable sorting in the suggestions listview
37 #define NONSORTINGCOLUMN 2
38 
39 class K3SpellDlg::K3SpellDlgPrivate {
40 public:
41  Ui_K3SpellUI ui;
42  K3SpellConfig* spellConfig;
43 };
44 
45 K3SpellDlg::K3SpellDlg( QWidget * parent, bool _progressbar, bool _modal )
46  : KDialog(parent)
47  , d(0),progressbar( false )
48 {
49  setCaption( i18n("Check Spelling") );
50  setButtons( Help|Cancel|User1 );
51  setModal( _modal );
52  setDefaultButton( Cancel );
53  setButtonText( Cancel, i18n("&Finished") );
54 
55  KConfigGroup cg( KGlobal::config(),"K3Spell" );
56  kDebug() << (cg.readEntry("K3Spell_DoSpellChecking"));
57  kDebug() << "dospellchecking is " << cg.readEntry("K3Spell_DoSpellChecking", false);
58  if ( (cg.readEntry("K3Spell_DoSpellChecking", false) == true) ) //dospellcheck ?
59  {
60  Q_UNUSED( _progressbar );
61  d = new K3SpellDlgPrivate;
62  d->ui.setupUi(this);
63 
64  connect( d->ui.m_replaceBtn, SIGNAL(clicked()),
65  this, SLOT(replace()));
66  connect( this, SIGNAL(ready(bool)),
67  d->ui.m_replaceBtn, SLOT(setEnabled(bool)) );
68 
69  connect( d->ui.m_replaceAllBtn, SIGNAL(clicked()), this, SLOT(replaceAll()));
70  connect(this, SIGNAL(ready(bool)), d->ui.m_replaceAllBtn, SLOT(setEnabled(bool)));
71 
72  connect( d->ui.m_skipBtn, SIGNAL(clicked()), this, SLOT(ignore()));
73  connect( this, SIGNAL(ready(bool)), d->ui.m_skipBtn, SLOT(setEnabled(bool)));
74 
75  connect( d->ui.m_skipAllBtn, SIGNAL(clicked()), this, SLOT(ignoreAll()));
76  connect( this, SIGNAL(ready(bool)), d->ui.m_skipAllBtn, SLOT(setEnabled(bool)));
77 
78  connect( d->ui.m_addBtn, SIGNAL(clicked()), this, SLOT(add()));
79  connect( this, SIGNAL(ready(bool)), d->ui.m_addBtn, SLOT(setEnabled(bool)));
80 
81  connect( d->ui.m_suggestBtn, SIGNAL(clicked()), this, SLOT(suggest()));
82  connect( this, SIGNAL(ready(bool)), d->ui.m_suggestBtn, SLOT(setEnabled(bool)) );
83  d->ui.m_suggestBtn->hide();
84 
85  connect(this, SIGNAL(user1Clicked()), this, SLOT(stop()));
86 
87  connect( d->ui.m_replacement, SIGNAL(textChanged(QString)),
88  SLOT(textChanged(QString)) );
89 
90  connect( d->ui.m_replacement, SIGNAL(returnPressed()), SLOT(replace()) );
91  connect( d->ui.m_suggestions, SIGNAL(selectionChanged(Q3ListViewItem*)),
92  SLOT(slotSelectionChanged(Q3ListViewItem*)) );
93 
94  connect( d->ui.m_suggestions, SIGNAL(doubleClicked(Q3ListViewItem*,QPoint,int)),
95  SLOT(replace()) );
96  d->spellConfig = new K3SpellConfig( 0, 0 , false );
97  d->spellConfig->fillDicts( d->ui.m_language );
98  connect( d->ui.m_language, SIGNAL(activated(int)),
99  d->spellConfig, SLOT(sSetDictionary(int)) );
100  connect( d->spellConfig, SIGNAL(configChanged()),
101  SLOT(slotConfigChanged()) );
102 
103  setHelp( "spelldlg", "k3spell" );
104  setMinimumSize( sizeHint() );
105  emit ready( false );
106  }
107 }
108 
109 K3SpellDlg::~K3SpellDlg()
110 {
111  delete d;
112 }
113 
114 QString K3SpellDlg::replacement() const
115 {
116  return newword;
117 }
118 
119 void
120 K3SpellDlg::init( const QString & _word, QStringList * _sugg )
121 {
122  sugg = _sugg;
123  word = _word;
124 
125  d->ui.m_suggestions->clear();
126  d->ui.m_suggestions->setSorting( NONSORTINGCOLUMN );
127  for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
128  Q3ListViewItem *item = new Q3ListViewItem( d->ui.m_suggestions,
129  d->ui.m_suggestions->lastItem() );
130  item->setText( 0, *it );
131  }
132  kDebug(750) << "K3SpellDlg::init [" << word << "]";
133 
134  emit ready( true );
135 
136  d->ui.m_unknownWord->setText( _word );
137 
138  if ( sugg->count() == 0 ) {
139  d->ui.m_replacement->setText( _word );
140  d->ui.m_replaceBtn->setEnabled( false );
141  d->ui.m_replaceAllBtn->setEnabled( false );
142  d->ui.m_suggestBtn->setEnabled( false );
143  } else {
144  d->ui.m_replacement->setText( (*sugg)[0] );
145  d->ui.m_replaceBtn->setEnabled( true );
146  d->ui.m_replaceAllBtn->setEnabled( true );
147  d->ui.m_suggestBtn->setEnabled( false );
148  d->ui.m_suggestions->setSelected( d->ui.m_suggestions->firstChild(), true );
149  }
150 }
151 
152 void
153 K3SpellDlg::init( const QString& _word, QStringList* _sugg,
154  const QString& context )
155 {
156  sugg = _sugg;
157  word = _word;
158 
159  d->ui.m_suggestions->clear();
160  d->ui.m_suggestions->setSorting( NONSORTINGCOLUMN );
161  for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
162  Q3ListViewItem *item = new Q3ListViewItem( d->ui.m_suggestions,
163  d->ui.m_suggestions->lastItem() );
164  item->setText( 0, *it );
165  }
166 
167  kDebug(750) << "K3SpellDlg::init [" << word << "]";
168 
169  emit ready( true );
170 
171  d->ui.m_unknownWord->setText( _word );
172  d->ui.m_contextLabel->setText( context );
173 
174  if ( sugg->count() == 0 ) {
175  d->ui.m_replacement->setText( _word );
176  d->ui.m_replaceBtn->setEnabled( false );
177  d->ui.m_replaceAllBtn->setEnabled( false );
178  d->ui.m_suggestBtn->setEnabled( false );
179  } else {
180  d->ui.m_replacement->setText( (*sugg)[0] );
181  d->ui.m_replaceBtn->setEnabled( true );
182  d->ui.m_replaceAllBtn->setEnabled( true );
183  d->ui.m_suggestBtn->setEnabled( false );
184  d->ui.m_suggestions->setSelected( d->ui.m_suggestions->firstChild(), true );
185  }
186 }
187 
188 void K3SpellDlg::standby()
189 {
190  ready( false );
191 }
192 
193 void
194 K3SpellDlg::slotProgress( unsigned int p )
195 {
196  if (!progressbar)
197  return;
198 
199  progbar->setValue( (int) p );
200 }
201 
202 void
203 K3SpellDlg::textChanged( const QString & )
204 {
205  d->ui.m_replaceBtn->setEnabled( true );
206  d->ui.m_replaceAllBtn->setEnabled( true );
207  d->ui.m_suggestBtn->setEnabled( true );
208 }
209 
210 void
211 K3SpellDlg::slotSelectionChanged( Q3ListViewItem* item )
212 {
213  if ( item )
214  d->ui.m_replacement->setText( item->text( 0 ) );
215 }
216 
217 /*
218  exit functions
219  */
220 
221 void
222 K3SpellDlg::closeEvent( QCloseEvent * )
223 {
224  cancel();
225 }
226 
227 void
228 K3SpellDlg::done( int result )
229 {
230  emit command( result );
231 }
232 void
233 K3SpellDlg::ignore()
234 {
235  newword = word;
236  done( KS_IGNORE );
237 }
238 
239 void
240 K3SpellDlg::ignoreAll()
241 {
242  newword = word;
243  done( KS_IGNOREALL );
244 }
245 
246 void
247 K3SpellDlg::add()
248 {
249  newword = word;
250  done( KS_ADD );
251 }
252 
253 
254 void
255 K3SpellDlg::cancel()
256 {
257  newword = word;
258  done( KS_CANCEL );
259 }
260 
261 void
262 K3SpellDlg::replace()
263 {
264  newword = d->ui.m_replacement->text();
265  done( KS_REPLACE );
266 }
267 
268 void
269 K3SpellDlg::stop()
270 {
271  newword = word;
272  done( KS_STOP );
273 }
274 
275 void
276 K3SpellDlg::replaceAll()
277 {
278  newword = d->ui.m_replacement->text();
279  done( KS_REPLACEALL );
280 }
281 
282 void
283 K3SpellDlg::suggest()
284 {
285  newword = d->ui.m_replacement->text();
286  done( KS_SUGGEST );
287 }
288 
289 void
290 K3SpellDlg::slotConfigChanged()
291 {
292  d->spellConfig->writeGlobalSettings();
293  done( KS_CONFIG );
294 }
295 
296 #include "k3spelldlg.moc"
i18n
QString i18n(const char *text)
Q3ListViewItem::text
virtual QString text(int column) const
QWidget
QDialog::setModal
void setModal(bool modal)
kdebug.h
K3SpellDlg::replacement
QString replacement() const
Definition: k3spelldlg.cpp:114
kconfig.h
KS_REPLACE
Definition: k3spelldlg.h:37
K3SpellDlg::ignoreAll
void ignoreAll()
Definition: k3spelldlg.cpp:240
KS_SUGGEST
Definition: k3spelldlg.h:43
k3sconfig.h
KS_IGNORE
Definition: k3spelldlg.h:39
K3SpellConfig
A configuration class/dialog for K3Spell.
Definition: k3sconfig.h:88
QPoint
KDialog
K3SpellDlg::done
void done(int i)
Definition: k3spelldlg.cpp:228
K3SpellDlg::K3SpellDlg
K3SpellDlg(QWidget *parent, bool _progressbar=false, bool _modal=false)
Definition: k3spelldlg.cpp:45
QProgressBar::setValue
void setValue(int value)
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KS_ADD
Definition: k3spelldlg.h:41
KS_CANCEL
Definition: k3spelldlg.h:36
KGlobal::config
KSharedConfigPtr config()
K3SpellDlg::replaceAll
void replaceAll()
Definition: k3spelldlg.cpp:276
QCloseEvent
QWidget::setMinimumSize
void setMinimumSize(const QSize &)
kglobal.h
QWidget::setEnabled
void setEnabled(bool)
QList::count
int count(const T &value) const
Q3ListViewItem
Q3ListViewItem::setText
virtual void setText(int column, const QString &text)
K3SpellDlg::ready
void ready(bool)
K3SpellDlg::slotProgress
void slotProgress(unsigned int p)
Adjust the progress bar to p percent.
Definition: k3spelldlg.cpp:194
K3SpellDlg::textChanged
void textChanged(const QString &)
Definition: k3spelldlg.cpp:203
QList::Iterator
typedef Iterator
QDialog::sizeHint
virtual QSize sizeHint() const
QString
QStringList
K3SpellDlg::replace
void replace()
Definition: k3spelldlg.cpp:262
K3SpellDlg::ignore
void ignore()
Definition: k3spelldlg.cpp:233
NONSORTINGCOLUMN
#define NONSORTINGCOLUMN
Definition: k3spelldlg.cpp:37
QList::end
iterator end()
Cancel
K3SpellDlg::slotConfigChanged
void slotConfigChanged()
Definition: k3spelldlg.cpp:290
K3SpellDlg::cancel
void cancel()
Definition: k3spelldlg.cpp:255
KConfigGroup
K3SpellDlg::stop
void stop()
Definition: k3spelldlg.cpp:269
K3SpellDlg::closeEvent
virtual void closeEvent(QCloseEvent *e)
Definition: k3spelldlg.cpp:222
k3spelldlg.h
KS_STOP
Definition: k3spelldlg.h:42
KS_IGNOREALL
Definition: k3spelldlg.h:40
Help
QWidget::setCaption
void setCaption(const QString &c)
K3SpellDlg::init
void init(const QString &_word, QStringList *_sugg)
Change the misspelled word and suggested replacements and enable the disabled buttons on the dialog b...
Definition: k3spelldlg.cpp:120
K3SpellDlg::standby
void standby()
Definition: k3spelldlg.cpp:188
KS_REPLACEALL
Definition: k3spelldlg.h:38
KS_CONFIG
Definition: k3spelldlg.h:44
K3SpellDlg::command
void command(int)
This signal is emitted when a button is pressed.
K3SpellDlg::add
void add()
Definition: k3spelldlg.cpp:247
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
K3SpellDlg::slotSelectionChanged
void slotSelectionChanged(Q3ListViewItem *item)
Definition: k3spelldlg.cpp:211
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
K3SpellDlg::suggest
void suggest()
Definition: k3spelldlg.cpp:283
QList::begin
iterator begin()
kconfiggroup.h
K3SpellDlg::~K3SpellDlg
~K3SpellDlg()
Definition: k3spelldlg.cpp:109
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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