KTextWidgets 5.109.0
Properties | Signals | Public Slots | Public Member Functions | Protected Slots | Protected Member Functions | List of all members
KTextEdit

A KDE'ified QTextEdit. More...

#include <KTextEdit>

Properties

bool checkSpellingEnabled
 
QString spellCheckingLanguage
 

Signals

void aboutToShowContextMenu (QMenu *menu)
 Emitted before the context menu is displayed.
 
void checkSpellingChanged (bool)
 emit signal when we activate or not autospellchecking
 
void languageChanged (const QString &language)
 Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when calling setSpellCheckingLanguage().
 
void spellCheckerAutoCorrect (const QString &currentWord, const QString &autoCorrectWord)
 
void spellCheckingCanceled ()
 signal spellCheckingCanceled is sent when we cancel spell checking.
 
void spellCheckingFinished ()
 signal spellCheckingFinished is sent when we finish spell check or we click on "Terminate" button in sonnet dialogbox
 
void spellCheckStatus (const QString &)
 Signal sends when spell checking is finished/stopped/completed.
 

Public Slots

void addTextDecorator (Sonnet::SpellCheckDecorator *decorator)
 Add custom spell checker decorator.
 
void checkSpelling ()
 Show a dialog to check the spelling.
 
void clearDecorator ()
 clearDecorator clear the spellcheckerdecorator
 
void replace ()
 Create replace dialogbox.
 
void setSpellCheckingLanguage (const QString &language)
 Set the spell check language which will be used for highlighting spelling mistakes and for the spellcheck dialog.
 
void showSpellConfigDialog (const QString &windowIcon=QString())
 Opens a Sonnet::ConfigDialog for this text edit.
 

Public Member Functions

 KTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 KTextEdit (QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 ~KTextEdit () override
 Destroys the KTextEdit object.
 
virtual bool checkSpellingEnabled () const
 Returns true if background spell checking is enabled for this text edit.
 
virtual void createHighlighter ()
 Allows to create a specific highlighter if reimplemented.
 
void enableFindReplace (bool enabled)
 Enable find replace action.
 
void forceSpellChecking ()
 
Sonnet::Highlighter * highlighter () const
 Returns the current highlighter, which is 0 if spell checking is disabled.
 
void highlightWord (int length, int pos)
 Selects the characters at the specified position.
 
virtual QMenu * mousePopupMenu ()
 Return standard KTextEdit popupMenu.
 
virtual void setCheckSpellingEnabled (bool check)
 Turns background spell checking for this text edit on or off.
 
void setHighlighter (Sonnet::Highlighter *_highLighter)
 Sets a custom background spell highlighter for this text edit.
 
virtual void setReadOnly (bool readOnly)
 Reimplemented to set a proper "deactivated" background color.
 
virtual bool shouldBlockBeSpellChecked (const QString &block) const
 Returns true if the given paragraph or block should be spellcheck.
 
void showAutoCorrectButton (bool show)
 
void showTabAction (bool show)
 
const QString & spellCheckingLanguage () const
 

Protected Slots

void slotDoFind ()
 
void slotDoReplace ()
 
void slotFind ()
 
void slotFindNext ()
 
void slotFindPrevious ()
 
void slotReplace ()
 
void slotReplaceNext ()
 
void slotSpeakText ()
 

Protected Member Functions

KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, const QString &text, QWidget *parent)
 
KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, QWidget *parent)
 
void contextMenuEvent (QContextMenuEvent *) override
 Reimplemented from QTextEdit to add spelling related items when appropriate.
 
virtual void deleteWordBack ()
 Deletes a word backwards from the current cursor position, if available.
 
virtual void deleteWordForward ()
 Deletes a word forwards from the current cursor position, if available.
 
bool event (QEvent *) override
 Reimplemented to catch "delete word" shortcut events.
 
void focusInEvent (QFocusEvent *) override
 Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
 
void keyPressEvent (QKeyEvent *) override
 Reimplemented for internal reasons.
 

Detailed Description

A KDE'ified QTextEdit.

This is just a little subclass of QTextEdit, implementing some standard KDE features, like cursor auto-hiding, configurable wheelscrolling (fast-scroll or zoom), spell checking and deleting of entire words with Ctrl-Backspace or Ctrl-Delete.

This text edit provides two ways of spell checking: background checking, which will mark incorrectly spelled words red, and a spell check dialog, which lets the user check and correct all incorrectly spelled words.

Basic rule: whenever you want to use QTextEdit, use KTextEdit!

KTextEdit Widget
See also
QTextEdit
Author
Carsten Pfeiffer pfeif.nosp@m.fer@.nosp@m.kde.o.nosp@m.rg

Constructor & Destructor Documentation

◆ KTextEdit() [1/2]

KTextEdit::KTextEdit ( const QString &  text,
QWidget *  parent = nullptr 
)
explicit

Constructs a KTextEdit object.

See QTextEdit::QTextEdit for details.

◆ KTextEdit() [2/2]

KTextEdit::KTextEdit ( QWidget *  parent = nullptr)
explicit

Constructs a KTextEdit object.

See QTextEdit::QTextEdit for details.

◆ ~KTextEdit()

KTextEdit::~KTextEdit ( )
override

Destroys the KTextEdit object.

Member Function Documentation

◆ aboutToShowContextMenu

void KTextEdit::aboutToShowContextMenu ( QMenu *  menu)
signal

Emitted before the context menu is displayed.

The signal allows you to add your own entries into the the context menu that is created on demand.

NOTE: Do not store the pointer to the QMenu provided through since it is created and deleted on demand.

Parameters
pthe context menu about to be displayed
Since
4.5

◆ addTextDecorator

void KTextEdit::addTextDecorator ( Sonnet::SpellCheckDecorator *  decorator)
slot

Add custom spell checker decorator.

Since
5.11

◆ checkSpelling

void KTextEdit::checkSpelling ( )
slot

Show a dialog to check the spelling.

The spellCheckStatus() signal will be emitted when the spell checking dialog is closed.

◆ checkSpellingChanged

void KTextEdit::checkSpellingChanged ( bool  )
signal

emit signal when we activate or not autospellchecking

Since
4.1

◆ checkSpellingEnabled()

virtual bool KTextEdit::checkSpellingEnabled ( ) const
virtual

Returns true if background spell checking is enabled for this text edit.

Note that it even returns true if this is a read-only KTextEdit, where spell checking is actually disabled. By default spell checking is disabled.

See also
setCheckSpellingEnabled()

◆ clearDecorator

void KTextEdit::clearDecorator ( )
slot

clearDecorator clear the spellcheckerdecorator

Since
5.11

◆ contextMenuEvent()

void KTextEdit::contextMenuEvent ( QContextMenuEvent *  )
overrideprotected

Reimplemented from QTextEdit to add spelling related items when appropriate.

◆ createHighlighter()

virtual void KTextEdit::createHighlighter ( )
virtual

Allows to create a specific highlighter if reimplemented.

By default, it creates a normal highlighter, based on the config file given to setSpellCheckingConfigFileName().

This highlighter is set each time spell checking is toggled on by calling setCheckSpellingEnabled(), but can later be overridden by calling setHighlighter().

See also
setHighlighter()
highlighter()
setSpellCheckingConfigFileName()

◆ deleteWordBack()

virtual void KTextEdit::deleteWordBack ( )
protectedvirtual

Deletes a word backwards from the current cursor position, if available.

◆ deleteWordForward()

virtual void KTextEdit::deleteWordForward ( )
protectedvirtual

Deletes a word forwards from the current cursor position, if available.

◆ enableFindReplace()

void KTextEdit::enableFindReplace ( bool  enabled)

Enable find replace action.

Since
4.1

◆ event()

bool KTextEdit::event ( QEvent *  )
overrideprotected

Reimplemented to catch "delete word" shortcut events.

◆ focusInEvent()

void KTextEdit::focusInEvent ( QFocusEvent *  )
overrideprotected

Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.

◆ forceSpellChecking()

void KTextEdit::forceSpellChecking ( )
Since
4.10 create a modal spellcheck dialogbox and spellCheckingFinished signal we sent when we finish spell checking or spellCheckingCanceled signal when we cancel spell checking

◆ highlighter()

Sonnet::Highlighter * KTextEdit::highlighter ( ) const

Returns the current highlighter, which is 0 if spell checking is disabled.

The default highlighter is the one created by createHighlighter(), but might be overridden by setHighlighter().

See also
setHighlighter()
createHighlighter()

◆ highlightWord()

void KTextEdit::highlightWord ( int  length,
int  pos 
)

Selects the characters at the specified position.

Any previous selection will be lost. The cursor is moved to the first character of the new selection.

Parameters
lengthThe length of the selection, in number of characters
posThe position of the first character of the selection

◆ keyPressEvent()

void KTextEdit::keyPressEvent ( QKeyEvent *  )
overrideprotected

Reimplemented for internal reasons.

◆ languageChanged

void KTextEdit::languageChanged ( const QString &  language)
signal

Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when calling setSpellCheckingLanguage().

Parameters
languagethe new language the user selected
Since
4.1

◆ mousePopupMenu()

virtual QMenu * KTextEdit::mousePopupMenu ( )
virtual

Return standard KTextEdit popupMenu.

Since
4.1

◆ replace

void KTextEdit::replace ( )
slot

Create replace dialogbox.

Since
4.1

◆ setCheckSpellingEnabled()

virtual void KTextEdit::setCheckSpellingEnabled ( bool  check)
virtual

Turns background spell checking for this text edit on or off.

Note that spell checking is only available in read-writable KTextEdits.

Enabling spell checking will set back the current highlighter to the one returned by createHighlighter().

See also
checkSpellingEnabled()
isReadOnly()
setReadOnly()

◆ setHighlighter()

void KTextEdit::setHighlighter ( Sonnet::Highlighter *  _highLighter)

Sets a custom background spell highlighter for this text edit.

Normally, the highlighter returned by createHighlighter() will be used to detect and highlight incorrectly spelled words, but this function allows to set a custom highlighter.

This has to be called after enabling spell checking with setCheckSpellingEnabled(), otherwise it has no effect.

Ownership is transferred to the KTextEdit

See also
highlighter()
createHighlighter()
Parameters
highLighterthe new highlighter which will be used now

◆ setReadOnly()

virtual void KTextEdit::setReadOnly ( bool  readOnly)
virtual

Reimplemented to set a proper "deactivated" background color.

◆ setSpellCheckingLanguage

void KTextEdit::setSpellCheckingLanguage ( const QString &  language)
slot

Set the spell check language which will be used for highlighting spelling mistakes and for the spellcheck dialog.

The languageChanged() signal will be emitted when the new language is different from the old one.

Since
4.1

◆ shouldBlockBeSpellChecked()

virtual bool KTextEdit::shouldBlockBeSpellChecked ( const QString &  block) const
virtual

Returns true if the given paragraph or block should be spellcheck.

For example, a mail client does not want to check quoted text, and would return false here (by checking whether the block starts with a quote sign).

Always returns true by default.

◆ showAutoCorrectButton()

void KTextEdit::showAutoCorrectButton ( bool  show)
Since
4.10

◆ showSpellConfigDialog

void KTextEdit::showSpellConfigDialog ( const QString &  windowIcon = QString())
slot

Opens a Sonnet::ConfigDialog for this text edit.

The spellcheck language of the config dialog is set to the current spellcheck language of the textedit. If the user changes the language in that dialog, the languageChanged() signal is emitted.

Parameters
configFileNameThe file which is used to store and load the config settings
windowIconthe icon which is used for the titlebar of the spell dialog window. Can be empty, then no icon is set.
Since
4.2

◆ showTabAction()

void KTextEdit::showTabAction ( bool  show)
Since
4.10

◆ slotDoReplace

void KTextEdit::slotDoReplace ( )
protectedslot
Since
4.1

◆ slotFindPrevious

void KTextEdit::slotFindPrevious ( )
protectedslot
Since
5.11

◆ slotSpeakText

void KTextEdit::slotSpeakText ( )
protectedslot
Since
4.3

◆ spellCheckerAutoCorrect

void KTextEdit::spellCheckerAutoCorrect ( const QString &  currentWord,
const QString &  autoCorrectWord 
)
signal
Since
4.10

◆ spellCheckingCanceled

void KTextEdit::spellCheckingCanceled ( )
signal

signal spellCheckingCanceled is sent when we cancel spell checking.

Since
4.10

◆ spellCheckingFinished

void KTextEdit::spellCheckingFinished ( )
signal

signal spellCheckingFinished is sent when we finish spell check or we click on "Terminate" button in sonnet dialogbox

Since
4.10

◆ spellCheckingLanguage()

const QString & KTextEdit::spellCheckingLanguage ( ) const
Returns
the spell checking language which was set by setSpellCheckingLanguage(), the spellcheck dialog or the spellcheck config dialog, or an empty string if that has never been called.
Since
4.2

◆ spellCheckStatus

void KTextEdit::spellCheckStatus ( const QString &  )
signal

Signal sends when spell checking is finished/stopped/completed.

Since
4.1