• 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
  • 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::findPrev().contains(key)) {
485  parent->slotFindPrevious();
486  return true;
487  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
488  if (!parent->isReadOnly())
489  parent->slotReplace();
490  return true;
491  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
492  QString text = QApplication::clipboard()->text( QClipboard::Selection );
493  if ( !text.isEmpty() )
494  parent->insertPlainText( text ); // TODO: check if this is html? (MiB)
495  return true;
496  }
497  return false;
498 }
499 
500 static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
501 {
502  cursor.clearSelection();
503  cursor.movePosition( op, QTextCursor::KeepAnchor );
504  cursor.removeSelectedText();
505 }
506 
507 void KTextEdit::deleteWordBack()
508 {
509  deleteWord(textCursor(), QTextCursor::PreviousWord);
510 }
511 
512 void KTextEdit::deleteWordForward()
513 {
514  deleteWord(textCursor(), QTextCursor::WordRight);
515 }
516 
517 QMenu *KTextEdit::mousePopupMenu()
518 {
519  QMenu *popup = createStandardContextMenu();
520  if (!popup) return 0;
521  connect( popup, SIGNAL(triggered(QAction*)),
522  this, SLOT(menuActivated(QAction*)) );
523 
524  const bool emptyDocument = document()->isEmpty();
525  if( !isReadOnly() )
526  {
527  QList<QAction *> actionList = popup->actions();
528  enum { UndoAct, RedoAct, CutAct, CopyAct, PasteAct, ClearAct, SelectAllAct, NCountActs };
529  QAction *separatorAction = 0L;
530  int idx = actionList.indexOf( actionList[SelectAllAct] ) + 1;
531  if ( idx < actionList.count() )
532  separatorAction = actionList.at( idx );
533  if ( separatorAction )
534  {
535  KAction *clearAllAction = KStandardAction::clear(this, SLOT(undoableClear()), popup);
536  if ( emptyDocument )
537  clearAllAction->setEnabled( false );
538  popup->insertAction( separatorAction, clearAllAction );
539  }
540  }
541  KIconTheme::assignIconsToContextMenu( isReadOnly() ? KIconTheme::ReadOnlyText
542  : KIconTheme::TextEditor,
543  popup->actions() );
544 
545  if( !isReadOnly() )
546  {
547  popup->addSeparator();
548  d->spellCheckAction = popup->addAction( KIcon( "tools-check-spelling" ),
549  i18n( "Check Spelling..." ) );
550  if ( emptyDocument )
551  d->spellCheckAction->setEnabled( false );
552  d->autoSpellCheckAction = popup->addAction( i18n( "Auto Spell Check" ) );
553  d->autoSpellCheckAction->setCheckable( true );
554  d->autoSpellCheckAction->setChecked( checkSpellingEnabled() );
555  popup->addSeparator();
556  if (d->showTabAction) {
557  d->allowTab = popup->addAction( i18n("Allow Tabulations") );
558  d->allowTab->setCheckable( true );
559  d->allowTab->setChecked( !tabChangesFocus() );
560  }
561  }
562 
563  if (d->findReplaceEnabled) {
564  KAction *findAction = KStandardAction::find(this, SLOT(slotFind()), popup);
565  KAction *findNextAction = KStandardAction::findNext(this, SLOT(slotFindNext()), popup);
566  KAction *findPrevAction = KStandardAction::findPrev(this, SLOT(slotFindPrevious()), popup);
567  if (emptyDocument) {
568  findAction->setEnabled(false);
569  findNextAction->setEnabled(false);
570  findPrevAction->setEnabled(false);
571  } else {
572  findNextAction->setEnabled(d->find != 0);
573  findPrevAction->setEnabled(d->find != 0);
574  }
575  popup->addSeparator();
576  popup->addAction(findAction);
577  popup->addAction(findNextAction);
578  popup->addAction(findPrevAction);
579 
580  if (!isReadOnly()) {
581  KAction *replaceAction = KStandardAction::replace(this, SLOT(slotReplace()), popup);
582  if (emptyDocument) {
583  replaceAction->setEnabled(false);
584  }
585  popup->addAction(replaceAction);
586  }
587  }
588  popup->addSeparator();
589  QAction *speakAction = popup->addAction(i18n("Speak Text"));
590  speakAction->setIcon(KIcon("preferences-desktop-text-to-speech"));
591  speakAction->setEnabled(!emptyDocument );
592  connect( speakAction, SIGNAL(triggered(bool)), this, SLOT(slotSpeakText()) );
593  return popup;
594 }
595 
596 void KTextEdit::slotSpeakText()
597 {
598  // If KTTSD not running, start it.
599  if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
600  {
601  QString error;
602  if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
603  {
604  KMessageBox::error(this, i18n( "Starting Jovie Text-to-Speech Service Failed"), error );
605  return;
606  }
607  }
608  QDBusInterface ktts("org.kde.kttsd", "/KSpeech", "org.kde.KSpeech");
609  QString text;
610  if(textCursor().hasSelection())
611  text = textCursor().selectedText();
612  else
613  text = toPlainText();
614  ktts.asyncCall("say", text, 0);
615 }
616 
617 void KTextEdit::contextMenuEvent(QContextMenuEvent *event)
618 {
619  // Obtain the cursor at the mouse position and the current cursor
620  QTextCursor cursorAtMouse = cursorForPosition(event->pos());
621  const int mousePos = cursorAtMouse.position();
622  QTextCursor cursor = textCursor();
623 
624  // Check if the user clicked a selected word
625  const bool selectedWordClicked = cursor.hasSelection() &&
626  mousePos >= cursor.selectionStart() &&
627  mousePos <= cursor.selectionEnd();
628 
629  // Get the word under the (mouse-)cursor and see if it is misspelled.
630  // Don't include apostrophes at the start/end of the word in the selection.
631  QTextCursor wordSelectCursor(cursorAtMouse);
632  wordSelectCursor.clearSelection();
633  wordSelectCursor.select(QTextCursor::WordUnderCursor);
634  QString selectedWord = wordSelectCursor.selectedText();
635 
636  bool isMouseCursorInsideWord = true;
637  if ((mousePos < wordSelectCursor.selectionStart() ||
638  mousePos >= wordSelectCursor.selectionEnd())
639  && (selectedWord.length() > 1)) {
640  isMouseCursorInsideWord = false;
641  }
642 
643  // Clear the selection again, we re-select it below (without the apostrophes).
644  wordSelectCursor.setPosition(wordSelectCursor.position()-selectedWord.size());
645  if (selectedWord.startsWith('\'') || selectedWord.startsWith('\"')) {
646  selectedWord = selectedWord.right(selectedWord.size() - 1);
647  wordSelectCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
648  }
649  if (selectedWord.endsWith('\'') || selectedWord.endsWith('\"'))
650  selectedWord.chop(1);
651 
652  wordSelectCursor.movePosition(QTextCursor::NextCharacter,
653  QTextCursor::KeepAnchor, selectedWord.size());
654 
655  const bool wordIsMisspelled = isMouseCursorInsideWord &&
656  checkSpellingEnabled() &&
657  !selectedWord.isEmpty() &&
658  highlighter() &&
659  highlighter()->isWordMisspelled(selectedWord);
660 
661  // If the user clicked a selected word, do nothing.
662  // If the user clicked somewhere else, move the cursor there.
663  // If the user clicked on a misspelled word, select that word.
664  // Same behavior as in OpenOffice Writer.
665  bool inQuote = false;
666  if (d->spellInterface &&
667  !d->spellInterface->shouldBlockBeSpellChecked(cursorAtMouse.block().text()))
668  inQuote = true;
669  if (!selectedWordClicked) {
670  if (wordIsMisspelled && !inQuote)
671  setTextCursor(wordSelectCursor);
672  else
673  setTextCursor(cursorAtMouse);
674  cursor = textCursor();
675  }
676 
677  // Use standard context menu for already selected words, correctly spelled
678  // words and words inside quotes.
679  if (!wordIsMisspelled || selectedWordClicked || inQuote) {
680  QMetaObject::invokeMethod(this, "mousePopupMenuImplementation", Q_ARG(QPoint, event->globalPos()));
681  }
682  else {
683  QMenu menu; //don't use KMenu here we don't want auto management accelerator
684 
685  //Add the suggestions to the menu
686  const QStringList reps = highlighter()->suggestionsForWord(selectedWord);
687  if (reps.isEmpty()) {
688  QAction *suggestionsAction = menu.addAction(i18n("No suggestions for %1", selectedWord));
689  suggestionsAction->setEnabled(false);
690  }
691  else {
692  QStringList::const_iterator end(reps.constEnd());
693  for (QStringList::const_iterator it = reps.constBegin(); it != end; ++it) {
694  menu.addAction(*it);
695  }
696  }
697 
698  menu.addSeparator();
699 
700  QAction *ignoreAction = menu.addAction(i18n("Ignore"));
701  QAction *addToDictAction = menu.addAction(i18n("Add to Dictionary"));
702  //Execute the popup inline
703  const QAction *selectedAction = menu.exec(event->globalPos());
704 
705  if (selectedAction) {
706  Q_ASSERT(cursor.selectedText() == selectedWord);
707 
708  if (selectedAction == ignoreAction) {
709  highlighter()->ignoreWord(selectedWord);
710  highlighter()->rehighlight();
711  }
712  else if (selectedAction == addToDictAction) {
713  highlighter()->addWordToDictionary(selectedWord);
714  highlighter()->rehighlight();
715  }
716 
717  // Other actions can only be one of the suggested words
718  else {
719  const QString replacement = selectedAction->text();
720  Q_ASSERT(reps.contains(replacement));
721  cursor.insertText(replacement);
722  setTextCursor(cursor);
723  }
724  }
725  }
726 }
727 
728 void KTextEdit::wheelEvent( QWheelEvent *event )
729 {
730  if ( KGlobalSettings::wheelMouseZooms() )
731  QTextEdit::wheelEvent( event );
732  else // thanks, we don't want to zoom, so skip QTextEdit's impl.
733  QAbstractScrollArea::wheelEvent( event );
734 }
735 
736 void KTextEdit::createHighlighter()
737 {
738  setHighlighter(new Sonnet::Highlighter(this, d->spellCheckingConfigFileName));
739 }
740 
741 Sonnet::Highlighter* KTextEdit::highlighter() const
742 {
743  return d->highlighter;
744 }
745 
746 void KTextEdit::setHighlighter(Sonnet::Highlighter *_highLighter)
747 {
748  delete d->highlighter;
749  d->highlighter = _highLighter;
750 }
751 
752 void KTextEdit::setCheckSpellingEnabled(bool check)
753 {
754  if (d->spellInterface)
755  d->spellInterface->setSpellCheckingEnabled(check);
756  else
757  setCheckSpellingEnabledInternal(check);
758 }
759 
760 void KTextEdit::setCheckSpellingEnabledInternal( bool check )
761 {
762  emit checkSpellingChanged( check );
763  if ( check == d->checkSpellingEnabled )
764  return;
765 
766  // From the above statment we know know that if we're turning checking
767  // on that we need to create a new highlighter and if we're turning it
768  // off we should remove the old one.
769 
770  d->checkSpellingEnabled = check;
771  if ( check )
772  {
773  if ( hasFocus() ) {
774  createHighlighter();
775  if (!spellCheckingLanguage().isEmpty())
776  setSpellCheckingLanguage(spellCheckingLanguage());
777  }
778  }
779  else
780  {
781  delete d->highlighter;
782  d->highlighter = 0;
783  }
784 }
785 
786 void KTextEdit::focusInEvent( QFocusEvent *event )
787 {
788  if ( d->checkSpellingEnabled && !isReadOnly() && !d->highlighter )
789  createHighlighter();
790 
791  QTextEdit::focusInEvent( event );
792 }
793 
794 bool KTextEdit::checkSpellingEnabled() const
795 {
796  if (d->spellInterface)
797  return d->spellInterface->isSpellCheckingEnabled();
798  else
799  return checkSpellingEnabledInternal();
800 }
801 
802 bool KTextEdit::checkSpellingEnabledInternal() const
803 {
804  return d->checkSpellingEnabled;
805 }
806 
807 void KTextEdit::setReadOnly( bool readOnly )
808 {
809  if ( !readOnly && hasFocus() && d->checkSpellingEnabled && !d->highlighter )
810  createHighlighter();
811 
812  if ( readOnly == isReadOnly() )
813  return;
814 
815  if ( readOnly ) {
816  delete d->highlighter;
817  d->highlighter = 0;
818 
819  d->customPalette = testAttribute( Qt::WA_SetPalette );
820  QPalette p = palette();
821  QColor color = p.color( QPalette::Disabled, QPalette::Background );
822  p.setColor( QPalette::Base, color );
823  p.setColor( QPalette::Background, color );
824  setPalette( p );
825  } else {
826  if ( d->customPalette && testAttribute( Qt::WA_SetPalette ) ) {
827  QPalette p = palette();
828  QColor color = p.color( QPalette::Normal, QPalette::Base );
829  p.setColor( QPalette::Base, color );
830  p.setColor( QPalette::Background, color );
831  setPalette( p );
832  } else
833  setPalette( QPalette() );
834  }
835 
836  QTextEdit::setReadOnly( readOnly );
837 }
838 
839 void KTextEdit::checkSpelling()
840 {
841  d->checkSpelling(false);
842 }
843 
844 void KTextEdit::forceSpellChecking()
845 {
846  d->checkSpelling(true);
847 }
848 
849 void KTextEdit::highlightWord( int length, int pos )
850 {
851  QTextCursor cursor(document());
852  cursor.setPosition(pos);
853  cursor.setPosition(pos+length,QTextCursor::KeepAnchor);
854  setTextCursor (cursor);
855  ensureCursorVisible();
856 }
857 
858 void KTextEdit::replace()
859 {
860  if ( document()->isEmpty() ) // saves having to track the text changes
861  return;
862 
863  if ( d->repDlg ) {
864  KWindowSystem::activateWindow( d->repDlg->winId() );
865  } else {
866  d->repDlg = new KReplaceDialog(this, 0,
867  QStringList(), QStringList(), false);
868  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
869  }
870  d->repDlg->show();
871 }
872 
873 void KTextEdit::slotDoReplace()
874 {
875  if (!d->repDlg) {
876  // Should really assert()
877  return;
878  }
879 
880  if(d->repDlg->pattern().isEmpty()) {
881  delete d->replace;
882  d->replace = 0;
883  ensureCursorVisible();
884  return;
885  }
886 
887  delete d->replace;
888  d->replace = new KReplace(d->repDlg->pattern(), d->repDlg->replacement(), d->repDlg->options(), this);
889  d->repIndex = 0;
890  if (d->replace->options() & KFind::FromCursor || d->replace->options() & KFind::FindBackwards) {
891  d->repIndex = textCursor().anchor();
892  }
893 
894  // Connect highlight signal to code which handles highlighting
895  // of found text.
896  connect(d->replace, SIGNAL(highlight(QString,int,int)),
897  this, SLOT(slotFindHighlight(QString,int,int)));
898  connect(d->replace, SIGNAL(findNext()), this, SLOT(slotReplaceNext()));
899  connect(d->replace, SIGNAL(replace(QString,int,int,int)),
900  this, SLOT(slotReplaceText(QString,int,int,int)));
901 
902  d->repDlg->close();
903  slotReplaceNext();
904 }
905 
906 
907 void KTextEdit::slotReplaceNext()
908 {
909  if (!d->replace)
910  return;
911 
912  d->lastReplacedPosition = -1;
913  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
914  textCursor().beginEditBlock(); // #48541
915  viewport()->setUpdatesEnabled(false);
916  }
917 
918  KFind::Result res = KFind::NoMatch;
919 
920  if (d->replace->needData())
921  d->replace->setData(toPlainText(), d->repIndex);
922  res = d->replace->replace();
923  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
924  textCursor().endEditBlock(); // #48541
925  if (d->lastReplacedPosition >= 0) {
926  QTextCursor tc = textCursor();
927  tc.setPosition(d->lastReplacedPosition);
928  setTextCursor(tc);
929  ensureCursorVisible();
930  }
931 
932  viewport()->setUpdatesEnabled(true);
933  viewport()->update();
934  }
935 
936  if (res == KFind::NoMatch) {
937  d->replace->displayFinalDialog();
938  d->replace->disconnect(this);
939  d->replace->deleteLater(); // we are in a slot connected to m_replace, don't delete it right away
940  d->replace = 0;
941  ensureCursorVisible();
942  //or if ( m_replace->shouldRestart() ) { reinit (w/o FromCursor) and call slotReplaceNext(); }
943  } else {
944  //m_replace->closeReplaceNextDialog();
945  }
946 }
947 
948 
949 void KTextEdit::slotDoFind()
950 {
951  if (!d->findDlg) {
952  // Should really assert()
953  return;
954  }
955  if( d->findDlg->pattern().isEmpty())
956  {
957  delete d->find;
958  d->find = 0;
959  return;
960  }
961  delete d->find;
962  d->find = new KFind(d->findDlg->pattern(), d->findDlg->options(), this);
963  d->findIndex = 0;
964  if (d->find->options() & KFind::FromCursor || d->find->options() & KFind::FindBackwards) {
965  d->findIndex = textCursor().anchor();
966  }
967 
968  // Connect highlight signal to code which handles highlighting
969  // of found text.
970  connect(d->find, SIGNAL(highlight(QString,int,int)),
971  this, SLOT(slotFindHighlight(QString,int,int)));
972  connect(d->find, SIGNAL(findNext()), this, SLOT(slotFindNext()));
973 
974  d->findDlg->close();
975  d->find->closeFindNextDialog();
976  slotFindNext();
977 }
978 
979 void KTextEdit::slotFindPrevious()
980 {
981  if (!d->find) {
982  return;
983  }
984  const long oldOptions = d->find->options();
985  d->find->setOptions(oldOptions ^ KFind::FindBackwards);
986  slotFindNext();
987  if (d->find) {
988  d->find->setOptions(oldOptions);
989  }
990 }
991 
992 void KTextEdit::slotFindNext()
993 {
994  if (!d->find)
995  return;
996  if(document()->isEmpty())
997  {
998  d->find->disconnect(this);
999  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
1000  d->find = 0;
1001  return;
1002  }
1003 
1004  KFind::Result res = KFind::NoMatch;
1005  if (d->find->needData())
1006  d->find->setData(toPlainText(), d->findIndex);
1007  res = d->find->find();
1008 
1009  if (res == KFind::NoMatch) {
1010  d->find->displayFinalDialog();
1011  d->find->disconnect(this);
1012  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
1013  d->find = 0;
1014  //or if ( m_find->shouldRestart() ) { reinit (w/o FromCursor) and call slotFindNext(); }
1015  } else {
1016  //m_find->closeFindNextDialog();
1017  }
1018 }
1019 
1020 
1021 void KTextEdit::slotFind()
1022 {
1023  if ( document()->isEmpty() ) // saves having to track the text changes
1024  return;
1025 
1026  if ( d->findDlg ) {
1027  KWindowSystem::activateWindow( d->findDlg->winId() );
1028  } else {
1029  d->findDlg = new KFindDialog(this);
1030  connect( d->findDlg, SIGNAL(okClicked()), this, SLOT(slotDoFind()) );
1031  }
1032  d->findDlg->show();
1033 }
1034 
1035 
1036 void KTextEdit::slotReplace()
1037 {
1038  if ( document()->isEmpty() ) // saves having to track the text changes
1039  return;
1040 
1041  if ( d->repDlg ) {
1042  KWindowSystem::activateWindow( d->repDlg->winId() );
1043  } else {
1044  d->repDlg = new KReplaceDialog(this, 0,
1045  QStringList(), QStringList(), false);
1046  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
1047  }
1048  d->repDlg->show();
1049 }
1050 
1051 void KTextEdit::enableFindReplace( bool enabled )
1052 {
1053  d->findReplaceEnabled = enabled;
1054 }
1055 
1056 void KTextEdit::showTabAction( bool show )
1057 {
1058  d->showTabAction = show;
1059 }
1060 
1061 void KTextEdit::setSpellInterface(KTextEditSpellInterface *spellInterface)
1062 {
1063  d->spellInterface = spellInterface;
1064 }
1065 
1066 bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
1067 {
1068  const int key = event->key() | event->modifiers();
1069 
1070  if ( KStandardShortcut::copy().contains( key ) ) {
1071  return true;
1072  } else if ( KStandardShortcut::paste().contains( key ) ) {
1073  return true;
1074  } else if ( KStandardShortcut::cut().contains( key ) ) {
1075  return true;
1076  } else if ( KStandardShortcut::undo().contains( key ) ) {
1077  return true;
1078  } else if ( KStandardShortcut::redo().contains( key ) ) {
1079  return true;
1080  } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
1081  return true;
1082  } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
1083  return true;
1084  } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
1085  return true;
1086  } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
1087  return true;
1088  } else if ( KStandardShortcut::next().contains( key ) ) {
1089  return true;
1090  } else if ( KStandardShortcut::prior().contains( key ) ) {
1091  return true;
1092  } else if ( KStandardShortcut::begin().contains( key ) ) {
1093  return true;
1094  } else if ( KStandardShortcut::end().contains( key ) ) {
1095  return true;
1096  } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
1097  return true;
1098  } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
1099  return true;
1100  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
1101  return true;
1102  } else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
1103  return true;
1104  } else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
1105  return true;
1106  } else if (findReplaceEnabled && KStandardShortcut::findPrev().contains(key)) {
1107  return true;
1108  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
1109  return true;
1110  } else if (event->matches(QKeySequence::SelectAll)) { // currently missing in QTextEdit
1111  return true;
1112  } else if (event->modifiers() == Qt::ControlModifier &&
1113  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1114  qobject_cast<KDialog*>(parent->window()) ) {
1115  // ignore Ctrl-Return so that KDialogs can close the dialog
1116  return true;
1117  }
1118  return false;
1119 }
1120 
1121 void KTextEdit::keyPressEvent( QKeyEvent *event )
1122 {
1123  if (d->handleShortcut(event)) {
1124  event->accept();
1125  }else if (event->modifiers() == Qt::ControlModifier &&
1126  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1127  qobject_cast<KDialog*>(window()) ) {
1128  event->ignore();
1129  } else {
1130  QTextEdit::keyPressEvent(event);
1131  }
1132 }
1133 
1134 void KTextEdit::setClickMessage(const QString &msg)
1135 {
1136  if (msg != d->clickMessage) {
1137  if (!d->clickMessage.isEmpty()) {
1138  viewport()->update(d->clickMessageRect());
1139  }
1140  d->clickMessage = msg;
1141  if (!d->clickMessage.isEmpty()) {
1142  viewport()->update(d->clickMessageRect());
1143  }
1144  }
1145 }
1146 
1147 QString KTextEdit::clickMessage() const
1148 {
1149  return d->clickMessage;
1150 }
1151 
1152 void KTextEdit::paintEvent(QPaintEvent *ev)
1153 {
1154  QTextEdit::paintEvent(ev);
1155 
1156  if (!d->clickMessage.isEmpty() && document()->isEmpty()) {
1157  QPainter p(viewport());
1158 
1159  QFont f = font();
1160  f.setItalic(d->italicizePlaceholder);
1161  p.setFont(f);
1162 
1163  QColor color(palette().color(viewport()->foregroundRole()));
1164  color.setAlphaF(0.5);
1165  p.setPen(color);
1166 
1167  QRect cr = d->clickMessageRect();
1168  p.drawText(cr, Qt::AlignTop | Qt::TextWordWrap, d->clickMessage);
1169  }
1170 }
1171 
1172 void KTextEdit::focusOutEvent(QFocusEvent *ev)
1173 {
1174  QTextEdit::focusOutEvent(ev);
1175 }
1176 
1177 void KTextEdit::showAutoCorrectButton(bool show)
1178 {
1179  d->showAutoCorrectionButton = show;
1180 }
1181 
1182 void KTextEdit::mousePopupMenuImplementation(const QPoint& pos)
1183 {
1184  QMenu *popup = mousePopupMenu();
1185  if ( popup ) {
1186  aboutToShowContextMenu(popup);
1187  popup->exec( pos );
1188  delete popup;
1189  }
1190 }
1191 
1192 #include "ktextedit.moc"
QTextCursor::position
int position() const
QAction::text
text
KStandardGuiItem::cancel
KGuiItem cancel()
Returns the 'Cancel' gui item.
Definition: kstandardguiitem.cpp:113
KTextEdit::setCheckSpellingEnabled
void setCheckSpellingEnabled(bool check)
Turns background spell checking for this text edit on or off.
Definition: ktextedit.cpp:752
kdialog.h
i18n
QString i18n(const char *text)
KStandardShortcut::findNext
const KShortcut & findNext()
Find/search next.
Definition: kstandardshortcut.cpp:343
KFindDialog
A generic "find" dialog.
Definition: kfinddialog.h:78
QEvent
KTextEdit::showAutoCorrectButton
void showAutoCorrectButton(bool show)
Definition: ktextedit.cpp:1177
QWidget
QKeyEvent::modifiers
Qt::KeyboardModifiers modifiers() const
KStandardShortcut::deleteWordForward
const KShortcut & deleteWordForward()
Delete a word forward from mouse/cursor position.
Definition: kstandardshortcut.cpp:339
QTextCursor::removeSelectedText
void removeSelectedText()
QEvent::type
Type type() const
QWidget::palette
const QPalette & palette() const
QSyntaxHighlighter::rehighlight
void rehighlight()
KTextEdit::checkSpellingChanged
void checkSpellingChanged(bool)
emit signal when we activate or not autospellchecking
QTextCursor
KStandardShortcut::next
const KShortcut & next()
Scroll down one page.
Definition: kstandardshortcut.cpp:352
QWidget::cursor
QCursor cursor() const
QTextCursor::clearSelection
void clearSelection()
kdebug.h
KTextEdit::deleteWordForward
virtual void deleteWordForward()
Deletes a word forwards from the current cursor position, if available.
Definition: ktextedit.cpp:512
KTextEdit::enableFindReplace
void enableFindReplace(bool enabled)
Enable find replace action.
Definition: ktextedit.cpp:1051
QTextEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QTextEdit::cursorForPosition
QTextCursor cursorForPosition(const QPoint &pos) const
QWidget::window
QWidget * window() const
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
QTextCursor::selectionStart
int selectionStart() const
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:1056
QFont
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
Display an "Information" dialog.
Definition: kmessagebox.cpp:960
KTextEdit::mousePopupMenu
QMenu * mousePopupMenu()
Return standard KTextEdit popupMenu.
Definition: ktextedit.cpp:517
KTextEdit::slotFind
void slotFind()
Definition: ktextedit.cpp:1021
KStandardShortcut::undo
const KShortcut & undo()
Undo last operation.
Definition: kstandardshortcut.cpp:340
QTextEdit::tabChangesFocus
bool tabChangesFocus() const
KTextEditSpellInterface
This interface is a workaround to keep binary compatibility in KDE4, because adding the virtual keywo...
Definition: ktextedit.h:45
QAction::setIcon
void setIcon(const QIcon &icon)
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QList::at
const T & at(int i) const
QString::size
int size() const
QTextEdit::paintEvent
virtual void paintEvent(QPaintEvent *event)
KTextEdit::highlighter
Sonnet::Highlighter * highlighter() const
Returns the current highlighter, which is 0 if spell checking is disabled.
Definition: ktextedit.cpp:741
QMenu::addAction
void addAction(QAction *action)
QTextCursor::selectedText
QString selectedText() const
QWheelEvent
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
deleteWord
static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
Definition: ktextedit.cpp:500
Sonnet::Highlighter::ignoreWord
void ignoreWord(const QString &word)
Ignores the given word.
Definition: highlighter.cpp:418
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QDialog::exec
int exec()
QAbstractScrollArea::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
QAbstractScrollArea::viewport
QWidget * viewport() const
KStandardShortcut::findPrev
const KShortcut & findPrev()
Find/search previous.
Definition: kstandardshortcut.cpp:344
KTextEdit::replace
void replace()
Create replace dialogbox.
Definition: ktextedit.cpp:858
QTextEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *e)
QDBusConnection::sessionBus
QDBusConnection sessionBus()
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 'find' request in the current document.
Definition: kstandardaction.cpp:329
QWidget::hasFocus
bool hasFocus() const
KTextEdit::slotSpeakText
void slotSpeakText()
Definition: ktextedit.cpp:596
QPoint
QTextEdit::toPlainText
QString toPlainText() const
KTextEdit::clickMessage
QString clickMessage() const
ktoolinvocation.h
QString::chop
void chop(int n)
klocale.h
kreplacedialog.h
kfind.h
QContextMenuEvent::globalPos
const QPoint & globalPos() const
QTextCursor::anchor
int anchor() const
configdialog.h
KTextEdit::slotReplace
void slotReplace()
Definition: ktextedit.cpp:1036
QList::const_iterator
QWidget::foregroundRole
QPalette::ColorRole foregroundRole() const
KStandardAction::findNext
KAction * findNext(const QObject *recvr, const char *slot, QObject *parent)
Find the next instance of a stored 'find'.
Definition: kstandardaction.cpp:334
QWidget::update
void update()
QTextCursor::movePosition
bool movePosition(MoveOperation operation, MoveMode mode, int n)
i18nc
QString i18nc(const char *ctxt, const char *text)
QWidget::setWindowIcon
void setWindowIcon(const QIcon &icon)
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
QTextCursor::select
void select(SelectionType selection)
KReplaceDialog
A generic "replace" dialog.
Definition: kreplacedialog.h:54
QList::indexOf
int indexOf(const T &value, int from) const
QTextEdit::find
bool find(const QString &exp, QFlags< QTextDocument::FindFlag > options)
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:849
KTextEdit::forceSpellChecking
void forceSpellChecking()
Definition: ktextedit.cpp:844
kcursor.h
KTextEdit::mousePopupMenuImplementation
void mousePopupMenuImplementation(const QPoint &pos)
Definition: ktextedit.cpp:1182
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:1061
QRect
QTextCursor::hasSelection
bool hasSelection() const
QPainter::setFont
void setFont(const QFont &font)
Sonnet::Dialog::show
void show()
Definition: dialog.cpp:307
QWidget::insertAction
void insertAction(QAction *before, QAction *action)
KFind::FromCursor
Start from current cursor position.
Definition: kfind.h:112
KStandardAction::Up
Definition: kstandardaction.h:141
QWidget::enabled
enabled
QWidget::testAttribute
bool testAttribute(Qt::WidgetAttribute attribute) const
QList::count
int count(const T &value) const
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 "deactivated" background color.
Definition: ktextedit.cpp:807
QTextDocumentFragment
KReplace
A generic implementation of the "replace" 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't enter any text...
Definition: ktextedit.cpp:1134
KTextEdit::slotDoFind
void slotDoFind()
Definition: ktextedit.cpp:949
KTextEdit::paintEvent
virtual void paintEvent(QPaintEvent *)
Reimplemented to paint clickMessage.
Definition: ktextedit.cpp:1152
QApplication::clipboard
QClipboard * clipboard()
KTextEdit::setHighlighter
void setHighlighter(Sonnet::Highlighter *_highLighter)
Sets a custom backgound spell highlighter for this text edit.
Definition: ktextedit.cpp:746
kmenu.h
QContextMenuEvent
QWidget::setUpdatesEnabled
void setUpdatesEnabled(bool enable)
QPainter::setPen
void setPen(const QColor &color)
KStandardShortcut::endOfLine
const KShortcut & endOfLine()
Goto end of current line.
Definition: kstandardshortcut.cpp:350
QTextEdit::focusOutEvent
virtual void focusOutEvent(QFocusEvent *e)
QTextCursor::endEditBlock
void endEditBlock()
QTextCursor::insertText
void insertText(const QString &text)
QList::isEmpty
bool isEmpty() const
QPainter
Sonnet::Dialog
Spellcheck dialog.
Definition: dialog.h:50
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
KStandardAction::SelectAll
Definition: kstandardaction.h:133
QTextEdit::text
QString text() const
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:728
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
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
QWidget::pos
QPoint pos() const
KStandardAction::clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
Clear the content of the focus widget.
Definition: kstandardaction.cpp:314
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QTextDocument::clear
virtual void clear()
QMenu::addSeparator
QAction * addSeparator()
KStandardShortcut::replace
const KShortcut & replace()
Find and replace matches.
Definition: kstandardshortcut.cpp:345
QString
kstandardaction.h
QList< QAction * >
QColor
KTextEdit::createHighlighter
virtual void createHighlighter()
Allows to create a specific highlighter if reimplemented.
Definition: ktextedit.cpp:736
KTextEdit::~KTextEdit
~KTextEdit()
Destroys the KTextEdit object.
Definition: ktextedit.cpp:329
QTextEdit::setTextCursor
void setTextCursor(const QTextCursor &cursor)
QMenu::exec
QAction * exec()
QTextEdit::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
Sonnet::Highlighter::addWordToDictionary
void addWordToDictionary(const QString &word)
Adds the given word permanently to the dictionary.
Definition: highlighter.cpp:413
QKeyEvent::matches
bool matches(QKeySequence::StandardKey key) const
Sonnet::ConfigDialog::language
QString language() const
return selected language
Definition: configdialog.cpp:97
Sonnet::Dialog::activeAutoCorrect
void activeAutoCorrect(bool _active)
Definition: dialog.cpp:175
QStringList
KStandardShortcut::copy
const KShortcut & copy()
Copy selected area into the clipboard.
Definition: kstandardshortcut.cpp:335
QAbstractScrollArea::event
virtual bool event(QEvent *event)
KTextEdit::KTextEdit
KTextEdit(const QString &text, QWidget *parent=0)
Constructs a KTextEdit object.
Definition: ktextedit.cpp:317
QDBusInterface
KTextEdit::spellCheckingLanguage
const QString & spellCheckingLanguage() const
QString::right
QString right(int n) 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:507
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
QTextCursor::block
QTextBlock block() const
QMenu
QTextEdit::document
QTextDocument * document() const
QEvent::accept
void accept()
KFind::Result
Result
Definition: kfind.h:139
QObject::setParent
void setParent(QObject *parent)
KFind
A generic implementation of the "find" function.
Definition: kfind.h:101
KTextEdit::slotFindNext
void slotFindNext()
Definition: ktextedit.cpp:992
QWidget::font
const QFont & font() const
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)
QTextCursor::beginEditBlock
void beginEditBlock()
QTextBlock::text
QString text() const
QMetaObject::invokeMethod
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
QFont::setItalic
void setItalic(bool enable)
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
QTextDocument::isEmpty
bool isEmpty() const
KTextEdit::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *)
Reimplemented from QTextEdit to add spelling related items when appropriate.
Definition: ktextedit.cpp:617
KStandardAction::replace
KAction * replace(const QObject *recvr, const char *slot, QObject *parent)
Find and replace matches.
Definition: kstandardaction.cpp:344
KConfigGroup
QClipboard::text
QString text(Mode mode) const
KTextEdit::slotReplaceNext
void slotReplaceNext()
Definition: ktextedit.cpp:907
QKeyEvent
QTextEdit::ensureCursorVisible
void ensureCursorVisible()
KConfig
QContextMenuEvent::pos
const QPoint & pos() const
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:786
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
QTextDocument
ktextedit.h
KFind::FindBackwards
Go backwards.
Definition: kfind.h:115
Sonnet::BackgroundChecker
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
QTextEdit::color
QColor color() const
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:873
QTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
QString::length
int length() const
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:760
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
QColor::setAlphaF
void setAlphaF(qreal alpha)
KStandardAction::findPrev
KAction * findPrev(const QObject *recvr, const char *slot, QObject *parent)
Find a previous instance of a stored 'find'.
Definition: kstandardaction.cpp:339
KTextEdit::checkSpellingEnabledInternal
bool checkSpellingEnabledInternal() const
Checks whether spellchecking is enabled or disabled.
Definition: ktextedit.cpp:802
QWidget::show
void show()
QTextEdit::isReadOnly
bool isReadOnly() const
KTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Reimplemented for internal reasons.
Definition: ktextedit.cpp:1121
QPaintEvent
KFind::NoMatch
Definition: kfind.h:139
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
kicon.h
KTextEdit::checkSpelling
void checkSpelling()
Show a dialog to check the spelling.
Definition: ktextedit.cpp:839
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
QTextCursor::selectionEnd
int selectionEnd() const
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:1172
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QWidget::actions
QList< QAction * > actions() const
QObject::parent
QObject * parent() const
QTextEdit
QDBusAbstractInterface::asyncCall
QDBusPendingCall asyncCall(const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8)
KStandardShortcut::end
const KShortcut & end()
Goto end of the document.
Definition: kstandardshortcut.cpp:348
KIconTheme::TextEditor
Definition: kicontheme.h:202
QFocusEvent
QAction::setEnabled
void setEnabled(bool)
KTextEdit::event
virtual bool event(QEvent *)
Reimplemented to catch "delete word" shortcut events.
Definition: ktextedit.cpp:371
KTextEdit::aboutToShowContextMenu
void aboutToShowContextMenu(QMenu *menu)
Emitted before the context menu is displayed.
QPalette
QTextEdit::textCursor
QTextCursor textCursor() const
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
Display an "Error" dialog.
Definition: kmessagebox.cpp:818
KTextEdit::slotFindPrevious
void slotFindPrevious()
Definition: ktextedit.cpp:979
KTextEdit
A KDE'ified QTextEdit.
Definition: ktextedit.h:90
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
QRect::rect
void rect(int *x, int *y, int *width, int *height) const
KStandardShortcut::EndOfLine
Definition: kstandardshortcut.h:72
QTextCursor::setPosition
void setPosition(int pos, MoveMode m)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 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