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

KDEUI

  • sources
  • kde-4.12
  • 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  parent->deleteWordBack();
406  return true;
407  } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
408  parent->deleteWordForward();
409  return true;
410  } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
411  QTextCursor cursor = parent->textCursor();
412  cursor.movePosition( QTextCursor::PreviousWord );
413  parent->setTextCursor( cursor );
414  return true;
415  } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
416  QTextCursor cursor = parent->textCursor();
417  cursor.movePosition( QTextCursor::NextWord );
418  parent->setTextCursor( cursor );
419  return true;
420  } else if ( KStandardShortcut::next().contains( key ) ) {
421  QTextCursor cursor = parent->textCursor();
422  bool moved = false;
423  qreal lastY = parent->cursorRect(cursor).bottom();
424  qreal distance = 0;
425  do {
426  qreal y = parent->cursorRect(cursor).bottom();
427  distance += qAbs(y - lastY);
428  lastY = y;
429  moved = cursor.movePosition(QTextCursor::Down);
430  } while (moved && distance < parent->viewport()->height());
431 
432  if (moved) {
433  cursor.movePosition(QTextCursor::Up);
434  parent->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd);
435  }
436  parent->setTextCursor(cursor);
437  return true;
438  } else if ( KStandardShortcut::prior().contains( key ) ) {
439  QTextCursor cursor = parent->textCursor();
440  bool moved = false;
441  qreal lastY = parent->cursorRect(cursor).bottom();
442  qreal distance = 0;
443  do {
444  qreal y = parent->cursorRect(cursor).bottom();
445  distance += qAbs(y - lastY);
446  lastY = y;
447  moved = cursor.movePosition(QTextCursor::Up);
448  } while (moved && distance < parent->viewport()->height());
449 
450  if (moved) {
451  cursor.movePosition(QTextCursor::Down);
452  parent->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepSub);
453  }
454  parent->setTextCursor(cursor);
455  return true;
456  } else if ( KStandardShortcut::begin().contains( key ) ) {
457  QTextCursor cursor = parent->textCursor();
458  cursor.movePosition( QTextCursor::Start );
459  parent->setTextCursor( cursor );
460  return true;
461  } else if ( KStandardShortcut::end().contains( key ) ) {
462  QTextCursor cursor = parent->textCursor();
463  cursor.movePosition( QTextCursor::End );
464  parent->setTextCursor( cursor );
465  return true;
466  } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
467  QTextCursor cursor = parent->textCursor();
468  cursor.movePosition( QTextCursor::StartOfLine );
469  parent->setTextCursor( cursor );
470  return true;
471  } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
472  QTextCursor cursor = parent->textCursor();
473  cursor.movePosition( QTextCursor::EndOfLine );
474  parent->setTextCursor( cursor );
475  return true;
476  } else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
477  parent->slotFind();
478  return true;
479  } else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
480  parent->slotFindNext();
481  return true;
482  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
483  if (!parent->isReadOnly())
484  parent->slotReplace();
485  return true;
486  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
487  QString text = QApplication::clipboard()->text( QClipboard::Selection );
488  if ( !text.isEmpty() )
489  parent->insertPlainText( text ); // TODO: check if this is html? (MiB)
490  return true;
491  }
492  return false;
493 }
494 
495 static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
496 {
497  cursor.clearSelection();
498  cursor.movePosition( op, QTextCursor::KeepAnchor );
499  cursor.removeSelectedText();
500 }
501 
502 void KTextEdit::deleteWordBack()
503 {
504  deleteWord(textCursor(), QTextCursor::PreviousWord);
505 }
506 
507 void KTextEdit::deleteWordForward()
508 {
509  deleteWord(textCursor(), QTextCursor::WordRight);
510 }
511 
512 QMenu *KTextEdit::mousePopupMenu()
513 {
514  QMenu *popup = createStandardContextMenu();
515  if (!popup) return 0;
516  connect( popup, SIGNAL(triggered(QAction*)),
517  this, SLOT(menuActivated(QAction*)) );
518 
519  const bool emptyDocument = document()->isEmpty();
520  if( !isReadOnly() )
521  {
522  QList<QAction *> actionList = popup->actions();
523  enum { UndoAct, RedoAct, CutAct, CopyAct, PasteAct, ClearAct, SelectAllAct, NCountActs };
524  QAction *separatorAction = 0L;
525  int idx = actionList.indexOf( actionList[SelectAllAct] ) + 1;
526  if ( idx < actionList.count() )
527  separatorAction = actionList.at( idx );
528  if ( separatorAction )
529  {
530  KAction *clearAllAction = KStandardAction::clear(this, SLOT(undoableClear()), popup);
531  if ( emptyDocument )
532  clearAllAction->setEnabled( false );
533  popup->insertAction( separatorAction, clearAllAction );
534  }
535  }
536  KIconTheme::assignIconsToContextMenu( isReadOnly() ? KIconTheme::ReadOnlyText
537  : KIconTheme::TextEditor,
538  popup->actions() );
539 
540  if( !isReadOnly() )
541  {
542  popup->addSeparator();
543  d->spellCheckAction = popup->addAction( KIcon( "tools-check-spelling" ),
544  i18n( "Check Spelling..." ) );
545  if ( emptyDocument )
546  d->spellCheckAction->setEnabled( false );
547  d->autoSpellCheckAction = popup->addAction( i18n( "Auto Spell Check" ) );
548  d->autoSpellCheckAction->setCheckable( true );
549  d->autoSpellCheckAction->setChecked( checkSpellingEnabled() );
550  popup->addSeparator();
551  if (d->showTabAction) {
552  d->allowTab = popup->addAction( i18n("Allow Tabulations") );
553  d->allowTab->setCheckable( true );
554  d->allowTab->setChecked( !tabChangesFocus() );
555  }
556  }
557 
558  if (d->findReplaceEnabled) {
559  KAction *findAction = KStandardAction::find(this, SLOT(slotFind()), popup);
560  KAction *findNextAction = KStandardAction::findNext(this, SLOT(slotFindNext()), popup);
561  if (emptyDocument) {
562  findAction->setEnabled(false);
563  findNextAction->setEnabled(false);
564  } else {
565  findNextAction->setEnabled(d->find != 0);
566  }
567  popup->addSeparator();
568  popup->addAction(findAction);
569  popup->addAction(findNextAction);
570 
571  if (!isReadOnly()) {
572  KAction *replaceAction = KStandardAction::replace(this, SLOT(slotReplace()), popup);
573  if (emptyDocument) {
574  replaceAction->setEnabled(false);
575  }
576  popup->addAction(replaceAction);
577  }
578  }
579  popup->addSeparator();
580  QAction *speakAction = popup->addAction(i18n("Speak Text"));
581  speakAction->setIcon(KIcon("preferences-desktop-text-to-speech"));
582  speakAction->setEnabled(!emptyDocument );
583  connect( speakAction, SIGNAL(triggered(bool)), this, SLOT(slotSpeakText()) );
584  return popup;
585 }
586 
587 void KTextEdit::slotSpeakText()
588 {
589  // If KTTSD not running, start it.
590  if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
591  {
592  QString error;
593  if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
594  {
595  KMessageBox::error(this, i18n( "Starting Jovie Text-to-Speech Service Failed"), error );
596  return;
597  }
598  }
599  QDBusInterface ktts("org.kde.kttsd", "/KSpeech", "org.kde.KSpeech");
600  QString text;
601  if(textCursor().hasSelection())
602  text = textCursor().selectedText();
603  else
604  text = toPlainText();
605  ktts.asyncCall("say", text, 0);
606 }
607 
608 void KTextEdit::contextMenuEvent(QContextMenuEvent *event)
609 {
610  // Obtain the cursor at the mouse position and the current cursor
611  QTextCursor cursorAtMouse = cursorForPosition(event->pos());
612  const int mousePos = cursorAtMouse.position();
613  QTextCursor cursor = textCursor();
614 
615  // Check if the user clicked a selected word
616  const bool selectedWordClicked = cursor.hasSelection() &&
617  mousePos >= cursor.selectionStart() &&
618  mousePos <= cursor.selectionEnd();
619 
620  // Get the word under the (mouse-)cursor and see if it is misspelled.
621  // Don't include apostrophes at the start/end of the word in the selection.
622  QTextCursor wordSelectCursor(cursorAtMouse);
623  wordSelectCursor.clearSelection();
624  wordSelectCursor.select(QTextCursor::WordUnderCursor);
625  QString selectedWord = wordSelectCursor.selectedText();
626 
627  bool isMouseCursorInsideWord = true;
628  if ((mousePos < wordSelectCursor.selectionStart() ||
629  mousePos >= wordSelectCursor.selectionEnd())
630  && (selectedWord.length() > 1)) {
631  isMouseCursorInsideWord = false;
632  }
633 
634  // Clear the selection again, we re-select it below (without the apostrophes).
635  wordSelectCursor.setPosition(wordSelectCursor.position()-selectedWord.size());
636  if (selectedWord.startsWith('\'') || selectedWord.startsWith('\"')) {
637  selectedWord = selectedWord.right(selectedWord.size() - 1);
638  wordSelectCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
639  }
640  if (selectedWord.endsWith('\'') || selectedWord.endsWith('\"'))
641  selectedWord.chop(1);
642 
643  wordSelectCursor.movePosition(QTextCursor::NextCharacter,
644  QTextCursor::KeepAnchor, selectedWord.size());
645 
646  const bool wordIsMisspelled = isMouseCursorInsideWord &&
647  checkSpellingEnabled() &&
648  !selectedWord.isEmpty() &&
649  highlighter() &&
650  highlighter()->isWordMisspelled(selectedWord);
651 
652  // If the user clicked a selected word, do nothing.
653  // If the user clicked somewhere else, move the cursor there.
654  // If the user clicked on a misspelled word, select that word.
655  // Same behavior as in OpenOffice Writer.
656  bool inQuote = false;
657  if (d->spellInterface &&
658  !d->spellInterface->shouldBlockBeSpellChecked(cursorAtMouse.block().text()))
659  inQuote = true;
660  if (!selectedWordClicked) {
661  if (wordIsMisspelled && !inQuote)
662  setTextCursor(wordSelectCursor);
663  else
664  setTextCursor(cursorAtMouse);
665  cursor = textCursor();
666  }
667 
668  // Use standard context menu for already selected words, correctly spelled
669  // words and words inside quotes.
670  if (!wordIsMisspelled || selectedWordClicked || inQuote) {
671  QMetaObject::invokeMethod(this, "mousePopupMenuImplementation", Q_ARG(QPoint, event->globalPos()));
672  }
673  else {
674  QMenu menu; //don't use KMenu here we don't want auto management accelerator
675 
676  //Add the suggestions to the menu
677  const QStringList reps = highlighter()->suggestionsForWord(selectedWord);
678  if (reps.isEmpty()) {
679  QAction *suggestionsAction = menu.addAction(i18n("No suggestions for %1", selectedWord));
680  suggestionsAction->setEnabled(false);
681  }
682  else {
683  QStringList::const_iterator end(reps.constEnd());
684  for (QStringList::const_iterator it = reps.constBegin(); it != end; ++it) {
685  menu.addAction(*it);
686  }
687  }
688 
689  menu.addSeparator();
690 
691  QAction *ignoreAction = menu.addAction(i18n("Ignore"));
692  QAction *addToDictAction = menu.addAction(i18n("Add to Dictionary"));
693  //Execute the popup inline
694  const QAction *selectedAction = menu.exec(event->globalPos());
695 
696  if (selectedAction) {
697  Q_ASSERT(cursor.selectedText() == selectedWord);
698 
699  if (selectedAction == ignoreAction) {
700  highlighter()->ignoreWord(selectedWord);
701  highlighter()->rehighlight();
702  }
703  else if (selectedAction == addToDictAction) {
704  highlighter()->addWordToDictionary(selectedWord);
705  highlighter()->rehighlight();
706  }
707 
708  // Other actions can only be one of the suggested words
709  else {
710  const QString replacement = selectedAction->text();
711  Q_ASSERT(reps.contains(replacement));
712  cursor.insertText(replacement);
713  setTextCursor(cursor);
714  }
715  }
716  }
717 }
718 
719 void KTextEdit::wheelEvent( QWheelEvent *event )
720 {
721  if ( KGlobalSettings::wheelMouseZooms() )
722  QTextEdit::wheelEvent( event );
723  else // thanks, we don't want to zoom, so skip QTextEdit's impl.
724  QAbstractScrollArea::wheelEvent( event );
725 }
726 
727 void KTextEdit::createHighlighter()
728 {
729  setHighlighter(new Sonnet::Highlighter(this, d->spellCheckingConfigFileName));
730 }
731 
732 Sonnet::Highlighter* KTextEdit::highlighter() const
733 {
734  return d->highlighter;
735 }
736 
737 void KTextEdit::setHighlighter(Sonnet::Highlighter *_highLighter)
738 {
739  delete d->highlighter;
740  d->highlighter = _highLighter;
741 }
742 
743 void KTextEdit::setCheckSpellingEnabled(bool check)
744 {
745  if (d->spellInterface)
746  d->spellInterface->setSpellCheckingEnabled(check);
747  else
748  setCheckSpellingEnabledInternal(check);
749 }
750 
751 void KTextEdit::setCheckSpellingEnabledInternal( bool check )
752 {
753  emit checkSpellingChanged( check );
754  if ( check == d->checkSpellingEnabled )
755  return;
756 
757  // From the above statment we know know that if we're turning checking
758  // on that we need to create a new highlighter and if we're turning it
759  // off we should remove the old one.
760 
761  d->checkSpellingEnabled = check;
762  if ( check )
763  {
764  if ( hasFocus() ) {
765  createHighlighter();
766  if (!spellCheckingLanguage().isEmpty())
767  setSpellCheckingLanguage(spellCheckingLanguage());
768  }
769  }
770  else
771  {
772  delete d->highlighter;
773  d->highlighter = 0;
774  }
775 }
776 
777 void KTextEdit::focusInEvent( QFocusEvent *event )
778 {
779  if ( d->checkSpellingEnabled && !isReadOnly() && !d->highlighter )
780  createHighlighter();
781 
782  QTextEdit::focusInEvent( event );
783 }
784 
785 bool KTextEdit::checkSpellingEnabled() const
786 {
787  if (d->spellInterface)
788  return d->spellInterface->isSpellCheckingEnabled();
789  else
790  return checkSpellingEnabledInternal();
791 }
792 
793 bool KTextEdit::checkSpellingEnabledInternal() const
794 {
795  return d->checkSpellingEnabled;
796 }
797 
798 void KTextEdit::setReadOnly( bool readOnly )
799 {
800  if ( !readOnly && hasFocus() && d->checkSpellingEnabled && !d->highlighter )
801  createHighlighter();
802 
803  if ( readOnly == isReadOnly() )
804  return;
805 
806  if ( readOnly ) {
807  delete d->highlighter;
808  d->highlighter = 0;
809 
810  d->customPalette = testAttribute( Qt::WA_SetPalette );
811  QPalette p = palette();
812  QColor color = p.color( QPalette::Disabled, QPalette::Background );
813  p.setColor( QPalette::Base, color );
814  p.setColor( QPalette::Background, color );
815  setPalette( p );
816  } else {
817  if ( d->customPalette && testAttribute( Qt::WA_SetPalette ) ) {
818  QPalette p = palette();
819  QColor color = p.color( QPalette::Normal, QPalette::Base );
820  p.setColor( QPalette::Base, color );
821  p.setColor( QPalette::Background, color );
822  setPalette( p );
823  } else
824  setPalette( QPalette() );
825  }
826 
827  QTextEdit::setReadOnly( readOnly );
828 }
829 
830 void KTextEdit::checkSpelling()
831 {
832  d->checkSpelling(false);
833 }
834 
835 void KTextEdit::forceSpellChecking()
836 {
837  d->checkSpelling(true);
838 }
839 
840 void KTextEdit::highlightWord( int length, int pos )
841 {
842  QTextCursor cursor(document());
843  cursor.setPosition(pos);
844  cursor.setPosition(pos+length,QTextCursor::KeepAnchor);
845  setTextCursor (cursor);
846  ensureCursorVisible();
847 }
848 
849 void KTextEdit::replace()
850 {
851  if ( document()->isEmpty() ) // saves having to track the text changes
852  return;
853 
854  if ( d->repDlg ) {
855  KWindowSystem::activateWindow( d->repDlg->winId() );
856  } else {
857  d->repDlg = new KReplaceDialog(this, 0,
858  QStringList(), QStringList(), false);
859  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
860  }
861  d->repDlg->show();
862 }
863 
864 void KTextEdit::slotDoReplace()
865 {
866  if (!d->repDlg) {
867  // Should really assert()
868  return;
869  }
870 
871  if(d->repDlg->pattern().isEmpty()) {
872  delete d->replace;
873  d->replace = 0;
874  ensureCursorVisible();
875  return;
876  }
877 
878  delete d->replace;
879  d->replace = new KReplace(d->repDlg->pattern(), d->repDlg->replacement(), d->repDlg->options(), this);
880  d->repIndex = 0;
881  if (d->replace->options() & KFind::FromCursor || d->replace->options() & KFind::FindBackwards) {
882  d->repIndex = textCursor().anchor();
883  }
884 
885  // Connect highlight signal to code which handles highlighting
886  // of found text.
887  connect(d->replace, SIGNAL(highlight(QString,int,int)),
888  this, SLOT(slotFindHighlight(QString,int,int)));
889  connect(d->replace, SIGNAL(findNext()), this, SLOT(slotReplaceNext()));
890  connect(d->replace, SIGNAL(replace(QString,int,int,int)),
891  this, SLOT(slotReplaceText(QString,int,int,int)));
892 
893  d->repDlg->close();
894  slotReplaceNext();
895 }
896 
897 
898 void KTextEdit::slotReplaceNext()
899 {
900  if (!d->replace)
901  return;
902 
903  d->lastReplacedPosition = -1;
904  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
905  textCursor().beginEditBlock(); // #48541
906  viewport()->setUpdatesEnabled(false);
907  }
908 
909  KFind::Result res = KFind::NoMatch;
910 
911  if (d->replace->needData())
912  d->replace->setData(toPlainText(), d->repIndex);
913  res = d->replace->replace();
914  if (!(d->replace->options() & KReplaceDialog::PromptOnReplace)) {
915  textCursor().endEditBlock(); // #48541
916  if (d->lastReplacedPosition >= 0) {
917  QTextCursor tc = textCursor();
918  tc.setPosition(d->lastReplacedPosition);
919  setTextCursor(tc);
920  ensureCursorVisible();
921  }
922 
923  viewport()->setUpdatesEnabled(true);
924  viewport()->update();
925  }
926 
927  if (res == KFind::NoMatch) {
928  d->replace->displayFinalDialog();
929  d->replace->disconnect(this);
930  d->replace->deleteLater(); // we are in a slot connected to m_replace, don't delete it right away
931  d->replace = 0;
932  ensureCursorVisible();
933  //or if ( m_replace->shouldRestart() ) { reinit (w/o FromCursor) and call slotReplaceNext(); }
934  } else {
935  //m_replace->closeReplaceNextDialog();
936  }
937 }
938 
939 
940 void KTextEdit::slotDoFind()
941 {
942  if (!d->findDlg) {
943  // Should really assert()
944  return;
945  }
946  if( d->findDlg->pattern().isEmpty())
947  {
948  delete d->find;
949  d->find = 0;
950  return;
951  }
952  delete d->find;
953  d->find = new KFind(d->findDlg->pattern(), d->findDlg->options(), this);
954  d->findIndex = 0;
955  if (d->find->options() & KFind::FromCursor || d->find->options() & KFind::FindBackwards) {
956  d->findIndex = textCursor().anchor();
957  }
958 
959  // Connect highlight signal to code which handles highlighting
960  // of found text.
961  connect(d->find, SIGNAL(highlight(QString,int,int)),
962  this, SLOT(slotFindHighlight(QString,int,int)));
963  connect(d->find, SIGNAL(findNext()), this, SLOT(slotFindNext()));
964 
965  d->findDlg->close();
966  d->find->closeFindNextDialog();
967  slotFindNext();
968 }
969 
970 
971 void KTextEdit::slotFindNext()
972 {
973  if (!d->find)
974  return;
975  if(document()->isEmpty())
976  {
977  d->find->disconnect(this);
978  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
979  d->find = 0;
980  return;
981  }
982 
983  KFind::Result res = KFind::NoMatch;
984  if (d->find->needData())
985  d->find->setData(toPlainText(), d->findIndex);
986  res = d->find->find();
987 
988  if (res == KFind::NoMatch) {
989  d->find->displayFinalDialog();
990  d->find->disconnect(this);
991  d->find->deleteLater(); // we are in a slot connected to m_find, don't delete right away
992  d->find = 0;
993  //or if ( m_find->shouldRestart() ) { reinit (w/o FromCursor) and call slotFindNext(); }
994  } else {
995  //m_find->closeFindNextDialog();
996  }
997 }
998 
999 
1000 void KTextEdit::slotFind()
1001 {
1002  if ( document()->isEmpty() ) // saves having to track the text changes
1003  return;
1004 
1005  if ( d->findDlg ) {
1006  KWindowSystem::activateWindow( d->findDlg->winId() );
1007  } else {
1008  d->findDlg = new KFindDialog(this);
1009  connect( d->findDlg, SIGNAL(okClicked()), this, SLOT(slotDoFind()) );
1010  }
1011  d->findDlg->show();
1012 }
1013 
1014 
1015 void KTextEdit::slotReplace()
1016 {
1017  if ( document()->isEmpty() ) // saves having to track the text changes
1018  return;
1019 
1020  if ( d->repDlg ) {
1021  KWindowSystem::activateWindow( d->repDlg->winId() );
1022  } else {
1023  d->repDlg = new KReplaceDialog(this, 0,
1024  QStringList(), QStringList(), false);
1025  connect( d->repDlg, SIGNAL(okClicked()), this, SLOT(slotDoReplace()) );
1026  }
1027  d->repDlg->show();
1028 }
1029 
1030 void KTextEdit::enableFindReplace( bool enabled )
1031 {
1032  d->findReplaceEnabled = enabled;
1033 }
1034 
1035 void KTextEdit::showTabAction( bool show )
1036 {
1037  d->showTabAction = show;
1038 }
1039 
1040 void KTextEdit::setSpellInterface(KTextEditSpellInterface *spellInterface)
1041 {
1042  d->spellInterface = spellInterface;
1043 }
1044 
1045 bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
1046 {
1047  const int key = event->key() | event->modifiers();
1048 
1049  if ( KStandardShortcut::copy().contains( key ) ) {
1050  return true;
1051  } else if ( KStandardShortcut::paste().contains( key ) ) {
1052  return true;
1053  } else if ( KStandardShortcut::cut().contains( key ) ) {
1054  return true;
1055  } else if ( KStandardShortcut::undo().contains( key ) ) {
1056  return true;
1057  } else if ( KStandardShortcut::redo().contains( key ) ) {
1058  return true;
1059  } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
1060  return true;
1061  } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
1062  return true;
1063  } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
1064  return true;
1065  } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
1066  return true;
1067  } else if ( KStandardShortcut::next().contains( key ) ) {
1068  return true;
1069  } else if ( KStandardShortcut::prior().contains( key ) ) {
1070  return true;
1071  } else if ( KStandardShortcut::begin().contains( key ) ) {
1072  return true;
1073  } else if ( KStandardShortcut::end().contains( key ) ) {
1074  return true;
1075  } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
1076  return true;
1077  } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
1078  return true;
1079  } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
1080  return true;
1081  } else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
1082  return true;
1083  } else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
1084  return true;
1085  } else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
1086  return true;
1087  } else if (event->matches(QKeySequence::SelectAll)) { // currently missing in QTextEdit
1088  return true;
1089  } else if (event->modifiers() == Qt::ControlModifier &&
1090  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1091  qobject_cast<KDialog*>(parent->window()) ) {
1092  // ignore Ctrl-Return so that KDialogs can close the dialog
1093  return true;
1094  }
1095  return false;
1096 }
1097 
1098 void KTextEdit::keyPressEvent( QKeyEvent *event )
1099 {
1100  if (d->handleShortcut(event)) {
1101  event->accept();
1102  }else if (event->modifiers() == Qt::ControlModifier &&
1103  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
1104  qobject_cast<KDialog*>(window()) ) {
1105  event->ignore();
1106  } else {
1107  QTextEdit::keyPressEvent(event);
1108  }
1109 }
1110 
1111 void KTextEdit::setClickMessage(const QString &msg)
1112 {
1113  if (msg != d->clickMessage) {
1114  if (!d->clickMessage.isEmpty()) {
1115  viewport()->update(d->clickMessageRect());
1116  }
1117  d->clickMessage = msg;
1118  if (!d->clickMessage.isEmpty()) {
1119  viewport()->update(d->clickMessageRect());
1120  }
1121  }
1122 }
1123 
1124 QString KTextEdit::clickMessage() const
1125 {
1126  return d->clickMessage;
1127 }
1128 
1129 void KTextEdit::paintEvent(QPaintEvent *ev)
1130 {
1131  QTextEdit::paintEvent(ev);
1132 
1133  if (!d->clickMessage.isEmpty() && document()->isEmpty()) {
1134  QPainter p(viewport());
1135 
1136  QFont f = font();
1137  f.setItalic(d->italicizePlaceholder);
1138  p.setFont(f);
1139 
1140  QColor color(palette().color(viewport()->foregroundRole()));
1141  color.setAlphaF(0.5);
1142  p.setPen(color);
1143 
1144  QRect cr = d->clickMessageRect();
1145  p.drawText(cr, Qt::AlignTop | Qt::TextWordWrap, d->clickMessage);
1146  }
1147 }
1148 
1149 void KTextEdit::focusOutEvent(QFocusEvent *ev)
1150 {
1151  QTextEdit::focusOutEvent(ev);
1152 }
1153 
1154 void KTextEdit::showAutoCorrectButton(bool show)
1155 {
1156  d->showAutoCorrectionButton = show;
1157 }
1158 
1159 void KTextEdit::mousePopupMenuImplementation(const QPoint& pos)
1160 {
1161  QMenu *popup = mousePopupMenu();
1162  if ( popup ) {
1163  aboutToShowContextMenu(popup);
1164  popup->exec( pos );
1165  delete popup;
1166  }
1167 }
1168 
1169 #include "ktextedit.moc"
KStandardGuiItem::cancel
KGuiItem cancel()
Returns the 'Cancel' 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:743
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
KTextEdit::showAutoCorrectButton
void showAutoCorrectButton(bool show)
Definition: ktextedit.cpp:1154
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:507
KTextEdit::enableFindReplace
void enableFindReplace(bool enabled)
Enable find replace action.
Definition: ktextedit.cpp:1030
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:1035
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:512
KTextEdit::slotFind
void slotFind()
Definition: ktextedit.cpp:1000
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:732
deleteWord
static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
Definition: ktextedit.cpp:495
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:849
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
KTextEdit::slotSpeakText
void slotSpeakText()
Definition: ktextedit.cpp:587
QString
KTextEdit::clickMessage
QString clickMessage() const
ktoolinvocation.h
klocale.h
kreplacedialog.h
kfind.h
configdialog.h
KTextEdit::slotReplace
void slotReplace()
Definition: ktextedit.cpp:1015
KStandardAction::findNext
KAction * findNext(const QObject *recvr, const char *slot, QObject *parent)
Find the next instance of a stored 'find'.
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 "replace" 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:840
KTextEdit::forceSpellChecking
void forceSpellChecking()
Definition: ktextedit.cpp:835
kcursor.h
KTextEdit::mousePopupMenuImplementation
void mousePopupMenuImplementation(const QPoint &pos)
Definition: ktextedit.cpp:1159
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:1040
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 "deactivated" background color.
Definition: ktextedit.cpp:798
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:1111
KTextEdit::slotDoFind
void slotDoFind()
Definition: ktextedit.cpp:940
KTextEdit::paintEvent
virtual void paintEvent(QPaintEvent *)
Reimplemented to paint clickMessage.
Definition: ktextedit.cpp:1129
KTextEdit::setHighlighter
void setHighlighter(Sonnet::Highlighter *_highLighter)
Sets a custom backgound spell highlighter for this text edit.
Definition: ktextedit.cpp:737
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:719
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:727
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:502
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 "find" function.
Definition: kfind.h:101
KTextEdit::slotFindNext
void slotFindNext()
Definition: ktextedit.cpp:971
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:608
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:898
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:777
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:864
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:751
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:793
KTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Reimplemented for internal reasons.
Definition: ktextedit.cpp:1098
KFind::NoMatch
Definition: kfind.h:139
kicon.h
KTextEdit::checkSpelling
void checkSpelling()
Show a dialog to check the spelling.
Definition: ktextedit.cpp:830
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:1149
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 "delete word" 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 "Error" dialog.
Definition: kmessagebox.cpp:818
QTextEdit
KTextEdit
A KDE'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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:15 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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