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

KDEUI

  • kdeui
  • widgets
ktextedit.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
3  2005 Michael Brade <brade@kde.org>
4  2012 Laurent Montel <montel@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
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 "ktextedit.h"
23 #include <ktoolinvocation.h>
24 #include <kdebug.h>
25 
26 #include <QApplication>
27 #include <QClipboard>
28 #include <QKeyEvent>
29 #include <QMenu>
30 #include <QPainter>
31 #include <QScrollBar>
32 #include <QTextCursor>
33 #include <QTextDocumentFragment>
34 #include <QDBusInterface>
35 #include <QDBusConnection>
36 #include <QDBusConnectionInterface>
37 
38 #include <configdialog.h>
39 #include <dialog.h>
40 #include "backgroundchecker.h"
41 #include <kaction.h>
42 #include <kcursor.h>
43 #include <kglobalsettings.h>
44 #include <kstandardaction.h>
45 #include <kstandardshortcut.h>
46 #include <kicon.h>
47 #include <kiconloader.h>
48 #include <klocale.h>
49 #include <kdialog.h>
50 #include <kreplacedialog.h>
51 #include <kfinddialog.h>
52 #include <kfind.h>
53 #include <kreplace.h>
54 #include <kmessagebox.h>
55 #include <kmenu.h>
56 #include <kwindowsystem.h>
57 #include <QDebug>
58 
59 class KTextEdit::Private
60 {
61  public:
62  Private( KTextEdit *_parent )
63  : parent( _parent ),
64  customPalette( false ),
65  checkSpellingEnabled( false ),
66  findReplaceEnabled(true),
67  showTabAction(true),
68  showAutoCorrectionButton(false),
69  highlighter( 0 ), findDlg(0),find(0),repDlg(0),replace(0), findIndex(0), repIndex(0),
70  lastReplacedPosition(-1)
71  {
72  //Check the default sonnet settings to see if spellchecking should be enabled.
73  KConfig sonnetKConfig("sonnetrc");
74  KConfigGroup group(&sonnetKConfig, "Spelling");
75  checkSpellingEnabled = group.readEntry("checkerEnabledByDefault", false);
76 
77  // i18n: Placeholder text in text edit widgets is the text appearing
78  // before any user input, briefly explaining to the user what to type
79  // (e.g. "Enter message").
80  // By default the text is set in italic, which may not be appropriate
81  // for some languages and scripts (e.g. for CJK ideographs).
82  QString metaMsg = i18nc("Italic placeholder text in line edits: 0 no, 1 yes", "1");
83  italicizePlaceholder = (metaMsg.trimmed() != QString('0'));
84  }
85 
86  ~Private()
87  {
88  delete highlighter;
89  delete findDlg;
90  delete find;
91  delete replace;
92  delete repDlg;
93  }
94 
100  bool overrideShortcut(const QKeyEvent* e);
104  bool handleShortcut(const QKeyEvent* e);
105 
106  void spellCheckerMisspelling( const QString &text, int pos );
107  void spellCheckerCorrected( const QString &, int,const QString &);
108  void spellCheckerAutoCorrect(const QString&,const QString&);
109  void spellCheckerCanceled();
110  void spellCheckerFinished();
111  void toggleAutoSpellCheck();
112 
113  void slotFindHighlight(const QString& text, int matchingIndex, int matchingLength);
114  void slotReplaceText(const QString &text, int replacementIndex, int /*replacedLength*/, int matchedLength);
115 
120  void undoableClear();
121 
122  void slotAllowTab();
123  void menuActivated( QAction* action );
124 
125  QRect clickMessageRect() const;
126 
127  void init();
128 
129  void checkSpelling(bool force);
130  KTextEdit *parent;
131  KTextEditSpellInterface *spellInterface;
132  QAction *autoSpellCheckAction;
133  QAction *allowTab;
134  QAction *spellCheckAction;
135  QString clickMessage;
136  bool italicizePlaceholder : 1;
137  bool customPalette : 1;
138 
139  bool checkSpellingEnabled : 1;
140  bool findReplaceEnabled: 1;
141  bool showTabAction: 1;
142  bool showAutoCorrectionButton: 1;
143  QTextDocumentFragment originalDoc;
144  QString spellCheckingConfigFileName;
145  QString spellCheckingLanguage;
146  Sonnet::Highlighter *highlighter;
147  KFindDialog *findDlg;
148  KFind *find;
149  KReplaceDialog *repDlg;
150  KReplace *replace;
151  int findIndex, repIndex;
152  int lastReplacedPosition;
153  KConfig *sonnetKConfig;
154 };
155 
156 void KTextEdit::Private::checkSpelling(bool force)
157 {
158  if(parent->document()->isEmpty())
159  {
160  KMessageBox::information(parent, i18n("Nothing to spell check."));
161  if(force) {
162  emit parent->spellCheckingFinished();
163  }
164  return;
165  }
166  Sonnet::BackgroundChecker *backgroundSpellCheck = new Sonnet::BackgroundChecker;
167  if(!spellCheckingLanguage.isEmpty())
168  backgroundSpellCheck->changeLanguage(spellCheckingLanguage);
169  Sonnet::Dialog *spellDialog = new Sonnet::Dialog(
170  backgroundSpellCheck, force ? parent : 0);
171  backgroundSpellCheck->setParent(spellDialog);
172  spellDialog->setAttribute(Qt::WA_DeleteOnClose, true);
173  spellDialog->activeAutoCorrect(showAutoCorrectionButton);
174  connect(spellDialog, SIGNAL(replace(QString,int,QString)),
175  parent, SLOT(spellCheckerCorrected(QString,int,QString)));
176  connect(spellDialog, SIGNAL(misspelling(QString,int)),
177  parent, SLOT(spellCheckerMisspelling(QString,int)));
178  connect(spellDialog, SIGNAL(autoCorrect(QString,QString)),
179  parent, SLOT(spellCheckerAutoCorrect(QString,QString)));
180  connect(spellDialog, SIGNAL(done(QString)),
181  parent, SLOT(spellCheckerFinished()));
182  connect(spellDialog, SIGNAL(cancel()),
183  parent, SLOT(spellCheckerCanceled()));
184  //Laurent in sonnet/dialog.cpp we emit done(QString) too => it calls here twice spellCheckerFinished not necessary
185  /*
186  connect(spellDialog, SIGNAL(stop()),
187  parent, SLOT(spellCheckerFinished()));
188  */
189  connect(spellDialog, SIGNAL(spellCheckStatus(QString)),
190  parent, SIGNAL(spellCheckStatus(QString)));
191  connect(spellDialog, SIGNAL(languageChanged(QString)),
192  parent, SIGNAL(languageChanged(QString)));
193  if(force) {
194  connect(spellDialog, SIGNAL(done(QString)),parent, SIGNAL(spellCheckingFinished()));
195  connect(spellDialog, SIGNAL(cancel()), parent, SIGNAL(spellCheckingCanceled()));
196  //Laurent in sonnet/dialog.cpp we emit done(QString) too => it calls here twice spellCheckerFinished not necessary
197  //connect(spellDialog, SIGNAL(stop()), parent, SIGNAL(spellCheckingFinished()));
198  }
199  originalDoc = QTextDocumentFragment(parent->document());
200  spellDialog->setBuffer(parent->toPlainText());
201  spellDialog->show();
202 }
203 
204 
205 void KTextEdit::Private::spellCheckerCanceled()
206 {
207  QTextDocument *doc = parent->document();
208  doc->clear();
209  QTextCursor cursor(doc);
210  cursor.insertFragment(originalDoc);
211  spellCheckerFinished();
212 }
213 
214 void KTextEdit::Private::spellCheckerAutoCorrect(const QString& currentWord,const QString& autoCorrectWord)
215 {
216  emit parent->spellCheckerAutoCorrect(currentWord, autoCorrectWord);
217 }
218 
219 void KTextEdit::Private::spellCheckerMisspelling( const QString &text, int pos )
220 {
221  //kDebug()<<"TextEdit::Private::spellCheckerMisspelling :"<<text<<" pos :"<<pos;
222  parent->highlightWord( text.length(), pos );
223 }
224 
225 void KTextEdit::Private::spellCheckerCorrected( const QString& oldWord, int pos,const QString& newWord)
226 {
227  //kDebug()<<" oldWord :"<<oldWord<<" newWord :"<<newWord<<" pos : "<<pos;
228  if (oldWord != newWord ) {
229  QTextCursor cursor(parent->document());
230  cursor.setPosition(pos);
231  cursor.setPosition(pos+oldWord.length(),QTextCursor::KeepAnchor);
232  cursor.insertText(newWord);
233  }
234 }
235 
236 void KTextEdit::Private::spellCheckerFinished()
237 {
238  QTextCursor cursor(parent->document());
239  cursor.clearSelection();
240  parent->setTextCursor(cursor);
241  if (parent->highlighter())
242  parent->highlighter()->rehighlight();
243 }
244 
245 void KTextEdit::Private::toggleAutoSpellCheck()
246 {
247  parent->setCheckSpellingEnabled( !parent->checkSpellingEnabled() );
248 }
249 
250 void KTextEdit::Private::undoableClear()
251 {
252  QTextCursor cursor = parent->textCursor();
253  cursor.beginEditBlock();
254  cursor.movePosition(QTextCursor::Start);
255  cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
256  cursor.removeSelectedText();
257  cursor.endEditBlock();
258 }
259 
260 void KTextEdit::Private::slotAllowTab()
261 {
262  parent->setTabChangesFocus( !parent->tabChangesFocus() );
263 }
264 
265 void KTextEdit::Private::menuActivated( QAction* action )
266 {
267  if ( action == spellCheckAction )
268  parent->checkSpelling();
269  else if ( action == autoSpellCheckAction )
270  toggleAutoSpellCheck();
271  else if ( action == allowTab )
272  slotAllowTab();
273 }
274 
275 
276 void KTextEdit::Private::slotFindHighlight(const QString& text, int matchingIndex, int matchingLength)
277 {
278  Q_UNUSED(text)
279  //kDebug() << "Highlight: [" << text << "] mi:" << matchingIndex << " ml:" << matchingLength;
280  QTextCursor tc = parent->textCursor();
281  tc.setPosition(matchingIndex);
282  tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, matchingLength);
283  parent->setTextCursor(tc);
284  parent->ensureCursorVisible();
285 }
286 
287 
288 void KTextEdit::Private::slotReplaceText(const QString &text, int replacementIndex, int replacedLength, int matchedLength) {
289  //kDebug() << "Replace: [" << text << "] ri:" << replacementIndex << " rl:" << replacedLength << " ml:" << matchedLength;
290  QTextCursor tc = parent->textCursor();
291  tc.setPosition(replacementIndex);
292  tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, matchedLength);
293  tc.removeSelectedText();
294  tc.insertText(text.mid(replacementIndex, replacedLength));
295  if (replace->options() & KReplaceDialog::PromptOnReplace) {
296  parent->setTextCursor(tc);
297  parent->ensureCursorVisible();
298  }
299  lastReplacedPosition = replacementIndex;
300 }
301 
302 QRect KTextEdit::Private::clickMessageRect() const
303 {
304  int margin = int(parent->document()->documentMargin());
305  QRect rect = parent->viewport()->rect().adjusted(margin, margin, -margin, -margin);
306  return parent->fontMetrics().boundingRect(rect, Qt::AlignTop | Qt::TextWordWrap, clickMessage);
307 }
308 
309 void KTextEdit::Private::init()
310 {
311  spellInterface = 0;
312  KCursor::setAutoHideCursor(parent, true, false);
313  parent->connect(parent, SIGNAL(languageChanged(QString)),
314  parent, SLOT(setSpellCheckingLanguage(QString)));
315 }
316 
317 KTextEdit::KTextEdit( const QString& text, QWidget *parent )
318  : QTextEdit( text, parent ), d( new Private( this ) )
319 {
320  d->init();
321 }
322 
323 KTextEdit::KTextEdit( QWidget *parent )
324  : QTextEdit( parent ), d( new Private( this ) )
325 {
326  d->init();
327 }
328 
329 KTextEdit::~KTextEdit()
330 {
331  delete d;
332 }
333 
334 void KTextEdit::setSpellCheckingConfigFileName(const QString &_fileName)
335 {
336  d->spellCheckingConfigFileName = _fileName;
337 }
338 
339 const QString& KTextEdit::spellCheckingLanguage() const
340 {
341  return d->spellCheckingLanguage;
342 }
343 
344 void KTextEdit::setSpellCheckingLanguage(const QString &_language)
345 {
346  if (highlighter()) {
347  highlighter()->setCurrentLanguage(_language);
348  highlighter()->rehighlight();
349  }
350 
351  if (_language != d->spellCheckingLanguage) {
352  d->spellCheckingLanguage = _language;
353  emit languageChanged(_language);
354  }
355 }
356 
357 void KTextEdit::showSpellConfigDialog(const QString &configFileName,
358  const QString &windowIcon)
359 {
360  KConfig config(configFileName);
361  Sonnet::ConfigDialog dialog(&config, this);
362  if (!d->spellCheckingLanguage.isEmpty())
363  dialog.setLanguage(d->spellCheckingLanguage);
364  if (!windowIcon.isEmpty())
365  dialog.setWindowIcon(KIcon(windowIcon));
366  if(dialog.exec()) {
367  setSpellCheckingLanguage( dialog.language() );
368  }
369 }
370 
371 bool KTextEdit::event(QEvent* ev)
372 {
373  if (ev->type() == QEvent::ShortcutOverride) {
374  QKeyEvent *e = static_cast<QKeyEvent *>( ev );
375  if (d->overrideShortcut(e)) {
376  e->accept();
377  return true;
378  }
379  }
380  return QTextEdit::event(ev);
381 }
382 
383 bool KTextEdit::Private::handleShortcut(const QKeyEvent* event)
384 {
385  const int key = event->key() | event->modifiers();
386 
387  if ( KStandardShortcut::copy().contains( key ) ) {
388  parent->copy();
389  return true;
390  } else if ( KStandardShortcut::paste().contains( key ) ) {
391  parent->paste();
392  return true;
393  } else if ( KStandardShortcut::cut().contains( key ) ) {
394  parent->cut();
395  return true;
396  } else if ( KStandardShortcut::undo().contains( key ) ) {
397  if(!parent->isReadOnly())
398  parent->undo();
399  return true;
400  } else if ( KStandardShortcut::redo().contains( key ) ) {
401  if(!parent->isReadOnly())
402  parent->redo();
403  return true;
404  } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
405  if (!parent->isReadOnly())
406  parent->deleteWordBack();
407  return true;
408  } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
409  if (!parent->isReadOnly())
410  parent->deleteWordForward();
411  return true;
412  } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
413  QTextCursor cursor = parent->textCursor();
414  cursor.movePosition( QTextCursor::PreviousWord );
415  parent->setTextCursor( cursor );
416  return true;
417  } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
418  QTextCursor cursor = parent->textCursor();
419  cursor.movePosition( QTextCursor::NextWord );
420  parent->setTextCursor( cursor );
421  return true;
422  } else if ( KStandardShortcut::next().contains( key ) ) {
423  QTextCursor cursor = parent->textCursor();
424  bool moved = false;
425  qreal lastY = parent->cursorRect(cursor).bottom();
426  qreal distance = 0;
427  do {
428  qreal y = parent->cursorRect(cursor).bottom();
429  distance += qAbs(y - lastY);
430  lastY = y;
431  moved = cursor.movePosition(QTextCursor::Down);
432  } while (moved && distance < parent->viewport()->height());
433 
434  if (moved) {
435  cursor.movePosition(QTextCursor::Up);
436  parent->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd);
437  }
438  parent->setTextCursor(cursor);
439  return true;
440  } else if ( KStandardShortcut::prior().contains( key ) ) {
441  QTextCursor cursor = parent->textCursor();
442  bool moved = false;
443  qreal lastY = parent->cursorRect(cursor).bottom();
444  qreal distance = 0;
445  do {
446  qreal y = parent->cursorRect(cursor).bottom();
447  distance += qAbs(y - lastY);
448  lastY = y;
449  moved = cursor.movePosition(QTextCursor::Up);
450  } while (moved && distance < parent->viewport()->height());
451 
452  if (moved) {
453  cursor.movePosition(QTextCursor::Down);
454  parent->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepSub);
455  }
456  parent->setTextCursor(cursor);
457  return true;
458  } else if ( KStandardShortcut::begin().contains( key ) ) {
459  QTextCursor cursor = parent->textCursor();
460  cursor.movePosition( QTextCursor::Start );
461  parent->setTextCursor( cursor );
462  return true;
463  } else if ( KStandardShortcut::end().contains( key ) ) {
464  QTextCursor cursor = parent->textCursor();
465  cursor.movePosition( QTextCursor::End );
466  parent->setTextCursor( cursor );
467  return true;
468  } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
469  QTextCursor cursor = parent->textCursor();
470  cursor.movePosition( QTextCursor::StartOfLine );
471  parent->setTextCursor( cursor );
472  return true;
473  } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
474  QTextCursor cursor = parent->textCursor();
475  cursor.movePosition( QTextCursor::EndOfLine );
476  parent->setTextCursor( cursor );
477  return true;
478  } else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
479  parent->slotFind();
480  return true;
481  } else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
482  parent->slotFindNext();
483  return true;
484  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
485  if (!parent->isReadOnly())
486  parent->slotReplace();
487  return true;
488  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
489  QString text = QApplication::clipboard()->text( QClipboard::Selection );
490  if ( !text.isEmpty() )
491  parent->insertPlainText( text ); // TODO: check if this is html? (MiB)
492  return true;
493  }
494  return false;
495 }
496 
497 static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
498 {
499  cursor.clearSelection();
500  cursor.movePosition( op, QTextCursor::KeepAnchor );
501  cursor.removeSelectedText();
502 }
503 
504 void KTextEdit::deleteWordBack()
505 {
506  deleteWord(textCursor(), QTextCursor::PreviousWord);
507 }
508 
509 void KTextEdit::deleteWordForward()
510 {
511  deleteWord(textCursor(), QTextCursor::WordRight);
512 }
513 
514 QMenu *KTextEdit::mousePopupMenu()
515 {
516  QMenu *popup = createStandardContextMenu();
517  if (!popup) return 0;
518  connect( popup, SIGNAL(triggered(QAction*)),
519  this, SLOT(menuActivated(QAction*)) );
520 
521  const bool emptyDocument = document()->isEmpty();
522  if( !isReadOnly() )
523  {
524  QList<QAction *> actionList = popup->actions();
525  enum { UndoAct, RedoAct, CutAct, CopyAct, PasteAct, ClearAct, SelectAllAct, NCountActs };
526  QAction *separatorAction = 0L;
527  int idx = actionList.indexOf( actionList[SelectAllAct] ) + 1;
528  if ( idx < actionList.count() )
529  separatorAction = actionList.at( idx );
530  if ( separatorAction )
531  {
532  KAction *clearAllAction = KStandardAction::clear(this, SLOT(undoableClear()), popup);
533  if ( emptyDocument )
534  clearAllAction->setEnabled( false );
535  popup->insertAction( separatorAction, clearAllAction );
536  }
537  }
538  KIconTheme::assignIconsToContextMenu( isReadOnly() ? KIconTheme::ReadOnlyText
539  : KIconTheme::TextEditor,
540  popup->actions() );
541 
542  if( !isReadOnly() )
543  {
544  popup->addSeparator();
545  d->spellCheckAction = popup->addAction( KIcon( "tools-check-spelling" ),
546  i18n( "Check Spelling..." ) );
547  if ( emptyDocument )
548  d->spellCheckAction->setEnabled( false );
549  d->autoSpellCheckAction = popup->addAction( i18n( "Auto Spell Check" ) );
550  d->autoSpellCheckAction->setCheckable( true );
551  d->autoSpellCheckAction->setChecked( checkSpellingEnabled() );
552  popup->addSeparator();
553  if (d->showTabAction) {
554  d->allowTab = popup->addAction( i18n("Allow Tabulations") );
555  d->allowTab->setCheckable( true );
556  d->allowTab->setChecked( !tabChangesFocus() );
557  }
558  }
559 
560  if (d->findReplaceEnabled) {
561  KAction *findAction = KStandardAction::find(this, SLOT(slotFind()), popup);
562  KAction *findNextAction = KStandardAction::findNext(this, SLOT(slotFindNext()), popup);
563  if (emptyDocument) {
564  findAction->setEnabled(false);
565  findNextAction->setEnabled(false);
566  } else {
567  findNextAction->setEnabled(d->find != 0);
568  }
569  popup->addSeparator();
570  popup->addAction(findAction);
571  popup->addAction(findNextAction);
572 
573  if (!isReadOnly()) {
574  KAction *replaceAction = KStandardAction::replace(this, SLOT(slotReplace()), popup);
575  if (emptyDocument) {
576  replaceAction->setEnabled(false);
577  }
578  popup->addAction(replaceAction);
579  }
580  }
581  popup->addSeparator();
582  QAction *speakAction = popup->addAction(i18n("Speak Text"));
583  speakAction->setIcon(KIcon("preferences-desktop-text-to-speech"));
584  speakAction->setEnabled(!emptyDocument );
585  connect( speakAction, SIGNAL(triggered(bool)), this, SLOT(slotSpeakText()) );
586  return popup;
587 }
588 
589 void KTextEdit::slotSpeakText()
590 {
591  // If KTTSD not running, start it.
592  if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
593  {
594  QString error;
595  if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
596  {
597  KMessageBox::error(this, i18n( "Starting Jovie Text-to-Speech Service Failed"), error );
598  return;
599  }
600  }
601  QDBusInterface ktts("org.kde.kttsd", "/KSpeech", "org.kde.KSpeech");
602  QString text;
603  if(textCursor().hasSelection())
604  text = textCursor().selectedText();
605  else
606  text = toPlainText();
607  ktts.asyncCall("say", text, 0);
608 }
609 
610 void KTextEdit::contextMenuEvent(QContextMenuEvent *event)
611 {
612  // Obtain the cursor at the mouse position and the current cursor
613  QTextCursor cursorAtMouse = cursorForPosition(event->pos());
614  const int mousePos = cursorAtMouse.position();
615  QTextCursor cursor = textCursor();
616 
617  // Check if the user clicked a selected word
618  const bool selectedWordClicked = cursor.hasSelection() &&
619  mousePos >= cursor.selectionStart() &&
620  mousePos <= cursor.selectionEnd();
621 
622  // Get the word under the (mouse-)cursor and see if it is misspelled.
623  // Don't include apostrophes at the start/end of the word in the selection.
624  QTextCursor wordSelectCursor(cursorAtMouse);
625  wordSelectCursor.clearSelection();
626  wordSelectCursor.select(QTextCursor::WordUnderCursor);
627  QString selectedWord = wordSelectCursor.selectedText();
628 
629  bool isMouseCursorInsideWord = true;
630  if ((mousePos < wordSelectCursor.selectionStart() ||
631  mousePos >= wordSelectCursor.selectionEnd())
632  && (selectedWord.length() > 1)) {
633  isMouseCursorInsideWord = false;
634  }
635 
636  // Clear the selection again, we re-select it below (without the apostrophes).
637  wordSelectCursor.setPosition(wordSelectCursor.position()-selectedWord.size());
638  if (selectedWord.startsWith('\'') || selectedWord.startsWith('\"')) {
639  selectedWord = selectedWord.right(selectedWord.size() - 1);
640  wordSelectCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
641  }
642  if (selectedWord.endsWith('\'') || selectedWord.endsWith('\"'))
643  selectedWord.chop(1);
644 
645  wordSelectCursor.movePosition(QTextCursor::NextCharacter,
646  QTextCursor::KeepAnchor, selectedWord.size());
647 
648  const bool wordIsMisspelled = isMouseCursorInsideWord &&
649  checkSpellingEnabled() &&
650  !selectedWord.isEmpty() &&
651  highlighter() &&
652  highlighter()->isWordMisspelled(selectedWord);
653 
654  // If the user clicked a selected word, do nothing.
655  // If the user clicked somewhere else, move the cursor there.
656  // If the user clicked on a misspelled word, select that word.
657  // Same behavior as in OpenOffice Writer.
658  bool inQuote = false;
659  if (d->spellInterface &&
660  !d->spellInterface->shouldBlockBeSpellChecked(cursorAtMouse.block().text()))
661  inQuote = true;
662  if (!selectedWordClicked) {
663  if (wordIsMisspelled && !inQuote)
664  setTextCursor(wordSelectCursor);
665  else
666  setTextCursor(cursorAtMouse);
667  cursor = textCursor();
668  }
669 
670  // Use standard context menu for already selected words, correctly spelled
671  // words and words inside quotes.
672  if (!wordIsMisspelled || selectedWordClicked || inQuote) {
673  QMetaObject::invokeMethod(this, "mousePopupMenuImplementation", Q_ARG(QPoint, event->globalPos()));
674  }
675  else {
676  QMenu menu; //don't use KMenu here we don't want auto management accelerator
677 
678  //Add the suggestions to the menu
679  const QStringList reps = highlighter()->suggestionsForWord(selectedWord);
680  if (reps.isEmpty()) {
681  QAction *suggestionsAction = menu.addAction(i18n("No suggestions for %1", selectedWord));
682  suggestionsAction->setEnabled(false);
683  }
684  else {
685  QStringList::const_iterator end(reps.constEnd());
686  for (QStringList::const_iterator it = reps.constBegin(); it != end; ++it) {
687  menu.addAction(*it);
688  }
689  }
690 
691  menu.addSeparator();
692 
693  QAction *ignoreAction = menu.addAction(i18n("Ignore"));
694  QAction *addToDictAction = menu.addAction(i18n("Add to Dictionary"));
695  //Execute the popup inline
696  const QAction *selectedAction = menu.exec(event->globalPos());
697 
698  if (selectedAction) {
699  Q_ASSERT(cursor.selectedText() == selectedWord);
700 
701  if (selectedAction == ignoreAction) {
702  highlighter()->ignoreWord(selectedWord);
703  highlighter()->rehighlight();
704  }
705  else if (selectedAction == addToDictAction) {
706  highlighter()->addWordToDictionary(selectedWord);
707  highlighter()->rehighlight();
708  }
709 
710  // Other actions can only be one of the suggested words
711  else {
712  const QString replacement = selectedAction->text();
713  Q_ASSERT(reps.contains(replacement));
714  cursor.insertText(replacement);
715  setTextCursor(cursor);
716  }
717  }
718  }
719 }
720 
721 void KTextEdit::wheelEvent( QWheelEvent *event )
722 {
723  if ( KGlobalSettings::wheelMouseZooms() )
724  QTextEdit::wheelEvent( event );
725  else // thanks, we don't want to zoom, so skip QTextEdit's impl.
726  QAbstractScrollArea::wheelEvent( event );
727 }
728 
729 void KTextEdit::createHighlighter()
730 {
731  setHighlighter(new Sonnet::Highlighter(this, d->spellCheckingConfigFileName));
732 }
733 
734 Sonnet::Highlighter* KTextEdit::highlighter() const
735 {
736  return d->highlighter;
737 }
738 
739 void KTextEdit::setHighlighter(Sonnet::Highlighter *_highLighter)
740 {
741  delete d->highlighter;
742  d->highlighter = _highLighter;
743 }
744 
745 void KTextEdit::setCheckSpellingEnabled(bool check)
746 {
747  if (d->spellInterface)
748  d->spellInterface->setSpellCheckingEnabled(check);
749  else
750  setCheckSpellingEnabledInternal(check);
751 }
752 
753 void KTextEdit::setCheckSpellingEnabledInternal( bool check )
754 {
755  emit checkSpellingChanged( check );
756  if ( check == d->checkSpellingEnabled )
757  return;
758 
759  // From the above statment we know know that if we're turning checking
760  // on that we need to create a new highlighter and if we're turning it
761  // off we should remove the old one.
762 
763  d->checkSpellingEnabled = check;
764  if ( check )
765  {
766  if ( hasFocus() ) {
767  createHighlighter();
768  if (!spellCheckingLanguage().isEmpty())
769  setSpellCheckingLanguage(spellCheckingLanguage());
770  }
771  }
772  else
773  {
774  delete d->highlighter;
775  d->highlighter = 0;
776  }
777 }
778 
779 void KTextEdit::focusInEvent( QFocusEvent *event )
780 {
781  if ( d->checkSpellingEnabled && !isReadOnly() && !d->highlighter )
782  createHighlighter();
783 
784  QTextEdit::focusInEvent( event );
785 }
786 
787 bool KTextEdit::checkSpellingEnabled() const
788 {
789  if (d->spellInterface)
790  return d->spellInterface->isSpellCheckingEnabled();
791  else
792  return checkSpellingEnabledInternal();
793 }
794 
795 bool KTextEdit::checkSpellingEnabledInternal() const
796 {
797  return d->checkSpellingEnabled;
798 }
799 
800 void KTextEdit::setReadOnly( bool readOnly )
801 {
802  if ( !readOnly && hasFocus() && d->checkSpellingEnabled && !d->highlighter )
803  createHighlighter();
804 
805  if ( readOnly == isReadOnly() )
806  return;
807 
808  if ( readOnly ) {
809  delete d->highlighter;
810  d->highlighter = 0;
811 
812  d->customPalette = testAttribute( Qt::WA_SetPalette );
813  QPalette p = palette();
814  QColor color = p.color( QPalette::Disabled, QPalette::Background );
815  p.setColor( QPalette::Base, color );
816  p.setColor( QPalette::Background, color );
817  setPalette( p );
818  } else {
819  if ( d->customPalette && testAttribute( Qt::WA_SetPalette ) ) {
820  QPalette p = palette();
821  QColor color = p.color( QPalette::Normal, QPalette::Base );
822  p.setColor( QPalette::Base, color );
823  p.setColor( QPalette::Background, color );
824  setPalette( p );
825  } else
826  setPalette( QPalette() );
827  }
828 
829  QTextEdit::setReadOnly( readOnly );
830 }
831 
832 void KTextEdit::checkSpelling()
833 {
834  d->checkSpelling(false);
835 }
836 
837 void KTextEdit::forceSpellChecking()
838 {
839  d->checkSpelling(true);
840 }
841 
842 void KTextEdit::highlightWord( int length, int pos )
843 {
844  QTextCursor cursor(document());
845  cursor.setPosition(pos);
846  cursor.setPosition(pos+length,QTextCursor::KeepAnchor);
847  setTextCursor (cursor);
848  ensureCursorVisible();
849 }
850 
851 void KTextEdit::replace()
852 {
853  if ( document()->isEmpty() ) // saves having to track the text changes
854  return;
855 
856  if ( d->repDlg ) {
857  KWindowSystem::activateWindow( d->repDlg->winId() );
858  } else {
859  d->repDlg = new KReplaceDialog(this, 0,
860  QStringList(), QStringList(), false);
861  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
862  }
863  d->repDlg->show();
864 }
865 
866 void KTextEdit::slotDoReplace()
867 {
868  if (!d->repDlg) {
869  // Should really assert()
870  return;
871  }
872 
873  if(d->repDlg->pattern().isEmpty()) {
874  delete d->replace;
875  d->replace = 0;
876  ensureCursorVisible();
877  return;
878  }
879 
880  delete d->replace;
881  d->replace = new KReplace(d->repDlg->pattern(), d->repDlg->replacement(), d->repDlg->options(), this);
882  d->repIndex = 0;
883  if (d->replace->options() & KFind::FromCursor || d->replace->options() & KFind::FindBackwards) {
884  d->repIndex = textCursor().anchor();
885  }
886 
887  // Connect highlight signal to code which handles highlighting
888  // of found text.
889  connect(d->replace, SIGNAL(highlight(QString,int,int)),
890  this, SLOT(slotFindHighlight(QString,int,int)));
891  connect(d->replace, SIGNAL(findNext()), this, SLOT(slotReplaceNext()));
892  connect(d->replace, SIGNAL(replace(QString,int,int,int)),
893  this, SLOT(slotReplaceText(QString,int,int,int)));
894 
895  d->repDlg->close();
896  slotReplaceNext();
897 }
898 
899 
900 void KTextEdit::slotReplaceNext()
901 {
902  if (!d->replace)
903  return;
904 
905  d->lastReplacedPosition = -1;
906  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
907  textCursor().beginEditBlock(); // #48541
908  viewport()->setUpdatesEnabled(false);
909  }
910 
911  KFind::Result res = KFind::NoMatch;
912 
913  if (d->replace->needData())
914  d->replace->setData(toPlainText(), d->repIndex);
915  res = d->replace->replace();
916  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
917  textCursor().endEditBlock(); // #48541
918  if (d->lastReplacedPosition >= 0) {
919  QTextCursor tc = textCursor();
920  tc.setPosition(d->lastReplacedPosition);
921  setTextCursor(tc);
922  ensureCursorVisible();
923  }
924 
925  viewport()->setUpdatesEnabled(true);
926  viewport()->update();
927  }
928 
929  if (res == KFind::NoMatch) {
930  d->replace->displayFinalDialog();
931  d->replace->disconnect(this);
932  d->replace->deleteLater(); // we are in a slot connected to m_replace, don't delete it right away
933  d->replace = 0;
934  ensureCursorVisible();
935  //or if ( m_replace->shouldRestart() ) { reinit (w/o FromCursor) and call slotReplaceNext(); }
936  } else {
937  //m_replace->closeReplaceNextDialog();
938  }
939 }
940 
941 
942 void KTextEdit::slotDoFind()
943 {
944  if (!d->findDlg) {
945  // Should really assert()
946  return;
947  }
948  if( d->findDlg->pattern().isEmpty())
949  {
950  delete d->find;
951  d->find = 0;
952  return;
953  }
954  delete d->find;
955  d->find = new KFind(d->findDlg->pattern(), d->findDlg->options(), this);
956  d->findIndex = 0;
957  if (d->find->options() & KFind::FromCursor || d->find->options() & KFind::FindBackwards) {
958  d->findIndex = textCursor().anchor();
959  }
960 
961  // Connect highlight signal to code which handles highlighting
962  // of found text.
963  connect(d->find, SIGNAL(highlight(QString,int,int)),
964  this, SLOT(slotFindHighlight(QString,int,int)));
965  connect(d->find, SIGNAL(findNext()), this, SLOT(slotFindNext()));
966 
967  d->findDlg->close();
968  d->find->closeFindNextDialog();
969  slotFindNext();
970 }
971 
972 
973 void KTextEdit::slotFindNext()
974 {
975  if (!d->find)
976  return;
977  if(document()->isEmpty())
978  {
979  d->find->disconnect(this);
980  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
981  d->find = 0;
982  return;
983  }
984 
985  KFind::Result res = KFind::NoMatch;
986  if (d->find->needData())
987  d->find->setData(toPlainText(), d->findIndex);
988  res = d->find->find();
989 
990  if (res == KFind::NoMatch) {
991  d->find->displayFinalDialog();
992  d->find->disconnect(this);
993  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
994  d->find = 0;
995  //or if ( m_find->shouldRestart() ) { reinit (w/o FromCursor) and call slotFindNext(); }
996  } else {
997  //m_find->closeFindNextDialog();
998  }
999 }
1000 
1001 
1002 void KTextEdit::slotFind()
1003 {
1004  if ( document()->isEmpty() ) // saves having to track the text changes
1005  return;
1006 
1007  if ( d->findDlg ) {
1008  KWindowSystem::activateWindow( d->findDlg->winId() );
1009  } else {
1010  d->findDlg = new KFindDialog(this);
1011  connect( d->findDlg, SIGNAL(okClicked()), this, SLOT(slotDoFind()) );
1012  }
1013  d->findDlg->show();
1014 }
1015 
1016 
1017 void KTextEdit::slotReplace()
1018 {
1019  if ( document()->isEmpty() ) // saves having to track the text changes
1020  return;
1021 
1022  if ( d->repDlg ) {
1023  KWindowSystem::activateWindow( d->repDlg->winId() );
1024  } else {
1025  d->repDlg = new KReplaceDialog(this, 0,
1026  QStringList(), QStringList(), false);
1027  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
1028  }
1029  d->repDlg->show();
1030 }
1031 
1032 void KTextEdit::enableFindReplace( bool enabled )
1033 {
1034  d->findReplaceEnabled = enabled;
1035 }
1036 
1037 void KTextEdit::showTabAction( bool show )
1038 {
1039  d->showTabAction = show;
1040 }
1041 
1042 void KTextEdit::setSpellInterface(KTextEditSpellInterface *spellInterface)
1043 {
1044  d->spellInterface = spellInterface;
1045 }
1046 
1047 bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
1048 {
1049  const int key = event->key() | event->modifiers();
1050 
1051  if ( KStandardShortcut::copy().contains( key ) ) {
1052  return true;
1053  } else if ( KStandardShortcut::paste().contains( key ) ) {
1054  return true;
1055  } else if ( KStandardShortcut::cut().contains( key ) ) {
1056  return true;
1057  } else if ( KStandardShortcut::undo().contains( key ) ) {
1058  return true;
1059  } else if ( KStandardShortcut::redo().contains( key ) ) {
1060  return true;
1061  } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
1062  return true;
1063  } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
1064  return true;
1065  } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
1066  return true;
1067  } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
1068  return true;
1069  } else if ( KStandardShortcut::next().contains( key ) ) {
1070  return true;
1071  } else if ( KStandardShortcut::prior().contains( key ) ) {
1072  return true;
1073  } else if ( KStandardShortcut::begin().contains( key ) ) {
1074  return true;
1075  } else if ( KStandardShortcut::end().contains( key ) ) {
1076  return true;
1077  } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
1078  return true;
1079  } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
1080  return true;
1081  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
1082  return true;
1083  } else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
1084  return true;
1085  } else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
1086  return true;
1087  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
1088  return true;
1089  } else if (event->matches(QKeySequence::SelectAll)) { // currently missing in QTextEdit
1090  return true;
1091  } else if (event->modifiers() == Qt::ControlModifier &&
1092  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1093  qobject_cast<KDialog*>(parent->window()) ) {
1094  // ignore Ctrl-Return so that KDialogs can close the dialog
1095  return true;
1096  }
1097  return false;
1098 }
1099 
1100 void KTextEdit::keyPressEvent( QKeyEvent *event )
1101 {
1102  if (d->handleShortcut(event)) {
1103  event->accept();
1104  }else if (event->modifiers() == Qt::ControlModifier &&
1105  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1106  qobject_cast<KDialog*>(window()) ) {
1107  event->ignore();
1108  } else {
1109  QTextEdit::keyPressEvent(event);
1110  }
1111 }
1112 
1113 void KTextEdit::setClickMessage(const QString &msg)
1114 {
1115  if (msg != d->clickMessage) {
1116  if (!d->clickMessage.isEmpty()) {
1117  viewport()->update(d->clickMessageRect());
1118  }
1119  d->clickMessage = msg;
1120  if (!d->clickMessage.isEmpty()) {
1121  viewport()->update(d->clickMessageRect());
1122  }
1123  }
1124 }
1125 
1126 QString KTextEdit::clickMessage() const
1127 {
1128  return d->clickMessage;
1129 }
1130 
1131 void KTextEdit::paintEvent(QPaintEvent *ev)
1132 {
1133  QTextEdit::paintEvent(ev);
1134 
1135  if (!d->clickMessage.isEmpty() && document()->isEmpty()) {
1136  QPainter p(viewport());
1137 
1138  QFont f = font();
1139  f.setItalic(d->italicizePlaceholder);
1140  p.setFont(f);
1141 
1142  QColor color(palette().color(viewport()->foregroundRole()));
1143  color.setAlphaF(0.5);
1144  p.setPen(color);
1145 
1146  QRect cr = d->clickMessageRect();
1147  p.drawText(cr, Qt::AlignTop | Qt::TextWordWrap, d->clickMessage);
1148  }
1149 }
1150 
1151 void KTextEdit::focusOutEvent(QFocusEvent *ev)
1152 {
1153  QTextEdit::focusOutEvent(ev);
1154 }
1155 
1156 void KTextEdit::showAutoCorrectButton(bool show)
1157 {
1158  d->showAutoCorrectionButton = show;
1159 }
1160 
1161 void KTextEdit::mousePopupMenuImplementation(const QPoint& pos)
1162 {
1163  QMenu *popup = mousePopupMenu();
1164  if ( popup ) {
1165  aboutToShowContextMenu(popup);
1166  popup->exec( pos );
1167  delete popup;
1168  }
1169 }
1170 
1171 #include "ktextedit.moc"
KStandardGuiItem::cancel
KGuiItem cancel()
Returns the &#39;Cancel&#39; gui item.
Definition: kstandardguiitem.cpp:113
QColor
KTextEdit::setCheckSpellingEnabled
void setCheckSpellingEnabled(bool check)
Turns background spell checking for this text edit on or off.
Definition: ktextedit.cpp:745
kdialog.h
i18n
QString i18n(const char *text)
KStandardShortcut::findNext
const KShortcut & findNext()
Find/search next.
Definition: kstandardshortcut.cpp:343
KFindDialog
A generic &quot;find&quot; dialog.
Definition: kfinddialog.h:78
KTextEdit::showAutoCorrectButton
void showAutoCorrectButton(bool show)
Definition: ktextedit.cpp:1156
KStandardShortcut::deleteWordForward
const KShortcut & deleteWordForward()
Delete a word forward from mouse/cursor position.
Definition: kstandardshortcut.cpp:339
KTextEdit::checkSpellingChanged
void checkSpellingChanged(bool)
emit signal when we activate or not autospellchecking
KStandardShortcut::next
const KShortcut & next()
Scroll down one page.
Definition: kstandardshortcut.cpp:352
kdebug.h
KTextEdit::deleteWordForward
virtual void deleteWordForward()
Deletes a word forwards from the current cursor position, if available.
Definition: ktextedit.cpp:509
KTextEdit::enableFindReplace
void enableFindReplace(bool enabled)
Enable find replace action.
Definition: ktextedit.cpp:1032
KStandardShortcut::forwardWord
const KShortcut & forwardWord()
ForwardWord.
Definition: kstandardshortcut.cpp:354
group
Sonnet::Highlighter
The Sonnet Highlighter.
Definition: highlighter.h:34
kglobalsettings.h
kreplace.h
KStandardShortcut::redo
const KShortcut & redo()
Redo.
Definition: kstandardshortcut.cpp:341
KStandardShortcut::find
StandardShortcut find(const QKeySequence &seq)
Return the StandardShortcut id of the standard accel action which uses this key sequence, or AccelNone if none of them do.
Definition: kstandardshortcut.cpp:295
backgroundchecker.h
KTextEdit::checkSpellingEnabled
bool checkSpellingEnabled() const
Returns true if background spell checking is enabled for this text edit.
KTextEdit::showTabAction
void showTabAction(bool show)
Definition: ktextedit.cpp:1037
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
Display an &quot;Information&quot; dialog.
Definition: kmessagebox.cpp:960
KTextEdit::mousePopupMenu
QMenu * mousePopupMenu()
Return standard KTextEdit popupMenu.
Definition: ktextedit.cpp:514
KTextEdit::slotFind
void slotFind()
Definition: ktextedit.cpp:1002
KStandardShortcut::undo
const KShortcut & undo()
Undo last operation.
Definition: kstandardshortcut.cpp:340
KTextEditSpellInterface
This interface is a workaround to keep binary compatibility in KDE4, because adding the virtual keywo...
Definition: ktextedit.h:45
QWidget
KTextEdit::highlighter
Sonnet::Highlighter * highlighter() const
Returns the current highlighter, which is 0 if spell checking is disabled.
Definition: ktextedit.cpp:734
deleteWord
static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
Definition: ktextedit.cpp:497
Sonnet::Highlighter::ignoreWord
void ignoreWord(const QString &word)
Ignores the given word.
Definition: highlighter.cpp:418
KTextEdit::replace
void replace()
Create replace dialogbox.
Definition: ktextedit.cpp:851
kiconloader.h
Sonnet::Dialog::setBuffer
void setBuffer(const QString &)
Definition: dialog.cpp:271
KStandardAction::find
KAction * find(const QObject *recvr, const char *slot, QObject *parent)
Initiate a &#39;find&#39; request in the current document.
Definition: kstandardaction.cpp:329
KTextEdit::slotSpeakText
void slotSpeakText()
Definition: ktextedit.cpp:589
QString
KTextEdit::clickMessage
QString clickMessage() const
ktoolinvocation.h
klocale.h
kreplacedialog.h
kfind.h
configdialog.h
KTextEdit::slotReplace
void slotReplace()
Definition: ktextedit.cpp:1017
KStandardAction::findNext
KAction * findNext(const QObject *recvr, const char *slot, QObject *parent)
Find the next instance of a stored &#39;find&#39;.
Definition: kstandardaction.cpp:334
i18nc
QString i18nc(const char *ctxt, const char *text)
config
KSharedConfigPtr config()
KTextEdit::setSpellCheckingConfigFileName
void setSpellCheckingConfigFileName(const QString &fileName)
Allows to override the config file where the settings for spell checking, like the current language o...
Definition: ktextedit.cpp:334
KReplaceDialog
A generic &quot;replace&quot; dialog.
Definition: kreplacedialog.h:54
KTextEdit::languageChanged
void languageChanged(const QString &language)
Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when ...
KTextEdit::highlightWord
void highlightWord(int length, int pos)
Selects the characters at the specified position.
Definition: ktextedit.cpp:842
KTextEdit::forceSpellChecking
void forceSpellChecking()
Definition: ktextedit.cpp:837
kcursor.h
KTextEdit::mousePopupMenuImplementation
void mousePopupMenuImplementation(const QPoint &pos)
Definition: ktextedit.cpp:1161
KWindowSystem::activateWindow
static void activateWindow(WId win, long time=0)
Requests that window win is activated.
Definition: kwindowsystem_mac.cpp:355
KTextEdit::setSpellInterface
void setSpellInterface(KTextEditSpellInterface *spellInterface)
Sets the spell interface, which is used to delegate certain function calls to the interface...
Definition: ktextedit.cpp:1042
Sonnet::Dialog::show
void show()
Definition: dialog.cpp:307
KFind::FromCursor
Start from current cursor position.
Definition: kfind.h:112
KStandardAction::Up
Definition: kstandardaction.h:141
KStandardShortcut::End
Definition: kstandardshortcut.h:69
Sonnet::BackgroundChecker::changeLanguage
void changeLanguage(const QString &lang)
KTextEdit::setReadOnly
virtual void setReadOnly(bool readOnly)
Reimplemented to set a proper &quot;deactivated&quot; background color.
Definition: ktextedit.cpp:800
KReplace
A generic implementation of the &quot;replace&quot; function.
Definition: kreplace.h:96
KTextEdit::setClickMessage
void setClickMessage(const QString &msg)
This makes the text edit display a grayed-out hinting text as long as the user didn&#39;t enter any text...
Definition: ktextedit.cpp:1113
KTextEdit::slotDoFind
void slotDoFind()
Definition: ktextedit.cpp:942
KTextEdit::paintEvent
virtual void paintEvent(QPaintEvent *)
Reimplemented to paint clickMessage.
Definition: ktextedit.cpp:1131
KTextEdit::setHighlighter
void setHighlighter(Sonnet::Highlighter *_highLighter)
Sets a custom backgound spell highlighter for this text edit.
Definition: ktextedit.cpp:739
kmenu.h
KStandardShortcut::endOfLine
const KShortcut & endOfLine()
Goto end of current line.
Definition: kstandardshortcut.cpp:350
QStringList
Sonnet::Dialog
Spellcheck dialog.
Definition: dialog.h:50
KStandardAction::SelectAll
Definition: kstandardaction.h:133
KGlobalSettings::wheelMouseZooms
static bool wheelMouseZooms()
Typically, QScrollView derived classes can be scrolled fast by holding down the Ctrl-button during wh...
Definition: kglobalsettings.cpp:707
KTextEdit::wheelEvent
virtual void wheelEvent(QWheelEvent *)
Reimplemented to allow fast-wheelscrolling with Ctrl-Wheel or zoom.
Definition: ktextedit.cpp:721
KReplaceDialog::PromptOnReplace
Definition: kreplacedialog.h:66
KStandardShortcut::backwardWord
const KShortcut & backwardWord()
BackwardWord.
Definition: kstandardshortcut.cpp:353
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KStandardShortcut::beginningOfLine
const KShortcut & beginningOfLine()
Goto beginning of current line.
Definition: kstandardshortcut.cpp:349
KStandardAction::clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
Clear the content of the focus widget.
Definition: kstandardaction.cpp:314
KStandardShortcut::replace
const KShortcut & replace()
Find and replace matches.
Definition: kstandardshortcut.cpp:345
kstandardaction.h
KTextEdit::createHighlighter
virtual void createHighlighter()
Allows to create a specific highlighter if reimplemented.
Definition: ktextedit.cpp:729
KTextEdit::~KTextEdit
~KTextEdit()
Destroys the KTextEdit object.
Definition: ktextedit.cpp:329
Sonnet::Highlighter::addWordToDictionary
void addWordToDictionary(const QString &word)
Adds the given word permanently to the dictionary.
Definition: highlighter.cpp:413
Sonnet::ConfigDialog::language
QString language() const
return selected language
Definition: configdialog.cpp:97
Sonnet::Dialog::activeAutoCorrect
void activeAutoCorrect(bool _active)
Definition: dialog.cpp:175
KStandardShortcut::copy
const KShortcut & copy()
Copy selected area into the clipboard.
Definition: kstandardshortcut.cpp:335
KTextEdit::KTextEdit
KTextEdit(const QString &text, QWidget *parent=0)
Constructs a KTextEdit object.
Definition: ktextedit.cpp:317
KTextEdit::spellCheckingLanguage
const QString & spellCheckingLanguage() const
Sonnet::Highlighter::setCurrentLanguage
void setCurrentLanguage(const QString &lang)
Definition: highlighter.cpp:300
KTextEdit::deleteWordBack
virtual void deleteWordBack()
Deletes a word backwards from the current cursor position, if available.
Definition: ktextedit.cpp:504
Sonnet::Highlighter::isWordMisspelled
bool isWordMisspelled(const QString &word)
Checks if a given word is marked as misspelled by the highlighter.
Definition: highlighter.cpp:433
kaction.h
KCursor::setAutoHideCursor
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
Sets auto-hiding the cursor for widget w.
Definition: kcursor.cpp:202
kstandardshortcut.h
KFind::Result
Result
Definition: kfind.h:139
KFind
A generic implementation of the &quot;find&quot; function.
Definition: kfind.h:101
KTextEdit::slotFindNext
void slotFindNext()
Definition: ktextedit.cpp:973
KToolInvocation::startServiceByDesktopName
static int startServiceByDesktopName(const QString &_name, const QString &URL, QString *error=0, QString *serviceName=0, int *pid=0, const QByteArray &startup_id=QByteArray(), bool noWait=false)
KStandardShortcut::cut
const KShortcut & cut()
Cut selected area and store it in the clipboard.
Definition: kstandardshortcut.cpp:334
Sonnet::Highlighter::suggestionsForWord
QStringList suggestionsForWord(const QString &word, int max=10)
Returns a list of suggested replacements for the given misspelled word.
Definition: highlighter.cpp:423
KTextEdit::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *)
Reimplemented from QTextEdit to add spelling related items when appropriate.
Definition: ktextedit.cpp:610
QMenu
KStandardAction::replace
KAction * replace(const QObject *recvr, const char *slot, QObject *parent)
Find and replace matches.
Definition: kstandardaction.cpp:344
KConfigGroup
KTextEdit::slotReplaceNext
void slotReplaceNext()
Definition: ktextedit.cpp:900
QFont
KConfig
dialog.h
KStandardShortcut::deleteWordBack
const KShortcut & deleteWordBack()
Delete a word back from mouse/cursor position.
Definition: kstandardshortcut.cpp:338
KTextEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *)
Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
Definition: ktextedit.cpp:779
QPoint
KStandardShortcut::prior
const KShortcut & prior()
Scroll up one page.
Definition: kstandardshortcut.cpp:351
KStandardShortcut::pasteSelection
const KShortcut & pasteSelection()
Paste the selection at mouse/cursor position.
Definition: kstandardshortcut.cpp:337
ktextedit.h
KFind::FindBackwards
Go backwards.
Definition: kfind.h:115
Sonnet::BackgroundChecker
QRect
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KIconTheme::ReadOnlyText
Definition: kicontheme.h:203
KTextEdit::showSpellConfigDialog
void showSpellConfigDialog(const QString &configFileName, const QString &windowIcon=QString())
Opens a Sonnet::ConfigDialog for this text edit.
Definition: ktextedit.cpp:357
KTextEdit::slotDoReplace
void slotDoReplace()
Definition: ktextedit.cpp:866
kwindowsystem.h
Sonnet::ConfigDialog
The sonnet ConfigDialog.
Definition: configdialog.h:30
KTextEdit::spellCheckerAutoCorrect
void spellCheckerAutoCorrect(const QString &currentWord, const QString &autoCorrectWord)
KTextEdit::setCheckSpellingEnabledInternal
void setCheckSpellingEnabledInternal(bool check)
Enable or disable the spellchecking.
Definition: ktextedit.cpp:753
Sonnet::ConfigDialog::setLanguage
void setLanguage(const QString &language)
Sets the language/dictionary that will be selected by default in this config dialog.
Definition: configdialog.cpp:92
KTextEdit::checkSpellingEnabledInternal
bool checkSpellingEnabledInternal() const
Checks whether spellchecking is enabled or disabled.
Definition: ktextedit.cpp:795
KTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Reimplemented for internal reasons.
Definition: ktextedit.cpp:1100
KFind::NoMatch
Definition: kfind.h:139
kicon.h
KTextEdit::checkSpelling
void checkSpelling()
Show a dialog to check the spelling.
Definition: ktextedit.cpp:832
KIconTheme::assignIconsToContextMenu
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
Definition: kicontheme.cpp:599
KTextEdit::setSpellCheckingLanguage
void setSpellCheckingLanguage(const QString &language)
Set the spell check language which will be used for highlighting spelling mistakes and for the spellc...
Definition: ktextedit.cpp:344
kfinddialog.h
kmessagebox.h
KTextEdit::focusOutEvent
virtual void focusOutEvent(QFocusEvent *)
Definition: ktextedit.cpp:1151
KStandardShortcut::end
const KShortcut & end()
Goto end of the document.
Definition: kstandardshortcut.cpp:348
KIconTheme::TextEditor
Definition: kicontheme.h:202
KTextEdit::event
virtual bool event(QEvent *)
Reimplemented to catch &quot;delete word&quot; shortcut events.
Definition: ktextedit.cpp:371
QAction
KTextEdit::aboutToShowContextMenu
void aboutToShowContextMenu(QMenu *menu)
Emitted before the context menu is displayed.
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
Display an &quot;Error&quot; dialog.
Definition: kmessagebox.cpp:818
QTextEdit
KTextEdit
A KDE&#39;ified QTextEdit.
Definition: ktextedit.h:90
QList< QAction * >
KStandardShortcut::paste
const KShortcut & paste()
Paste contents of clipboard at mouse/cursor position.
Definition: kstandardshortcut.cpp:336
KStandardShortcut::begin
const KShortcut & begin()
Goto beginning of the document.
Definition: kstandardshortcut.cpp:347
KStandardShortcut::EndOfLine
Definition: kstandardshortcut.h:72
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Oct 13 2020 16:12:38 by doxygen 1.8.5 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-4.14.8 API Reference

Skip menu "kdelibs-4.14.8 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
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