QtSpell  0.8.5
Spell checking for Qt text widgets
Public Slots | Signals | Public Member Functions | Private Member Functions | List of all members
QtSpell::TextEditChecker Class Reference

Checker class for QTextEdit widgets. More...

#include <QtSpell.hpp>

Inherits QtSpell::Checker.

Public Slots

void undo ()
 Undo the last edit operation. More...
 
void redo ()
 Redo the last edit operation. More...
 
void clearUndoRedo ()
 Clears the undo/redo stack. More...
 
- Public Slots inherited from QtSpell::Checker
void setSpellingEnabled (bool enabled)
 Set whether spell checking should be performed. More...
 

Signals

void undoAvailable (bool available)
 Emitted when the undo stack changes. More...
 
void redoAvailable (bool available)
 Emitted when the redo stak changes. More...
 
- Signals inherited from QtSpell::Checker
void languageChanged (const QString &newLang)
 This signal is emitted when the user selects a new language from the spellchecker UI. More...
 

Public Member Functions

 TextEditChecker (QObject *parent=0)
 TextEditChecker object constructor.
 
 ~TextEditChecker ()
 TextEditChecker object destructor.
 
void setTextEdit (QTextEdit *textEdit)
 Set the QTextEdit to check. More...
 
void setTextEdit (QPlainTextEdit *textEdit)
 Set the QPlainTextEdit to check. More...
 
void setNoSpellingPropertyId (int propertyId)
 Set the QTextCharFormat property identifier which marks whether a word ought to be spell-checked. More...
 
int noSpellingPropertyId () const
 Returns the current QTextCharFormat property identifier which marks whether a word ought to be spell-checked. More...
 
void checkSpelling (int start=0, int end=-1)
 Check the spelling. More...
 
void setUndoRedoEnabled (bool enabled)
 Sets whether undo/redo functionality is enabled. More...
 
- Public Member Functions inherited from QtSpell::Checker
 Checker (QObject *parent=0)
 QtSpell::Checker object constructor.
 
virtual ~Checker ()
 QtSpell::Checker object destructor.
 
bool setLanguage (const QString &lang)
 Set the spell checking language. More...
 
const QString & getLanguage () const
 Retreive the current spelling language. More...
 
void setDecodeLanguageCodes (bool decode)
 Set whether to decode language codes in the UI. More...
 
bool getDecodeLanguageCodes () const
 Return whether langauge codes are decoded in the UI. More...
 
void setShowCheckSpellingCheckbox (bool show)
 Set whether to display an "Check spelling" checkbox in the UI. More...
 
bool getShowCheckSpellingCheckbox () const
 Return whether a "Check spelling" checkbox is displayed in the UI. More...
 
bool getSpellingEnabled () const
 Return whether spellchecking is performed. More...
 
void addWordToDictionary (const QString &word)
 Add the specified word to the user dictionary. More...
 
bool checkWord (const QString &word) const
 Check the specified word. More...
 
void ignoreWord (const QString &word) const
 Ignore a word for the current session. More...
 
QList< QString > getSpellingSuggestions (const QString &word) const
 Retreive a list of spelling suggestions for the misspelled word. More...
 

Private Member Functions

QString getWord (int pos, int *start=0, int *end=0) const
 Get the word at the specified cursor position. More...
 
void insertWord (int start, int end, const QString &word)
 Replaces the specified range with the specified word. More...
 
bool isAttached () const
 Returns whether a widget is attached to the checker. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from QtSpell::Checker
static QList< QString > getLanguageList ()
 Requests the list of languages available for spell checking. More...
 
static QString decodeLanguageCode (const QString &lang)
 Translates a language code to a human readable format (i.e. "en_US" -> "English (United States)"). More...
 

Detailed Description

Checker class for QTextEdit widgets.

Sample usage:

/* QtSpell - Spell checking for Qt text widgets.
* Copyright (c) 2014 Sandro Mani
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef EXAMPLE_HPP
#define EXAMPLE_HPP
#include <QCheckBox>
#include <QLabel>
#include <QMainWindow>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QtSpell.hpp>
#include <QDialogButtonBox>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow()
: QMainWindow()
{
setWindowTitle("QtSpell Example");
QLabel* label = new QLabel("Type some text into the text box.\n"
"Try misspelling some words. Then right click them.");
QTextEdit* textEdit = new QTextEdit(this);
QDialogButtonBox* bbox = new QDialogButtonBox(this);
QPushButton* buttonUndo = bbox->addButton("Undo", QDialogButtonBox::ActionRole);
buttonUndo->setEnabled(false);
QPushButton* buttonRedo = bbox->addButton("Redo", QDialogButtonBox::ActionRole);
buttonRedo->setEnabled(false);
QPushButton* buttonClear = bbox->addButton("Clear", QDialogButtonBox::ActionRole);
QWidget* widget = new QWidget(this);
setCentralWidget(widget);
QVBoxLayout* layout = new QVBoxLayout(widget);
layout->addWidget(label);
layout->addWidget(textEdit, 1);
layout->addWidget(bbox);
checker->setTextEdit(textEdit);
checker->setDecodeLanguageCodes(true);
checker->setUndoRedoEnabled(true);
connect(checker, SIGNAL(undoAvailable(bool)), buttonUndo, SLOT(setEnabled(bool)));
connect(checker, SIGNAL(redoAvailable(bool)), buttonRedo, SLOT(setEnabled(bool)));
connect(buttonUndo, SIGNAL(clicked()), checker, SLOT(undo()));
connect(buttonRedo, SIGNAL(clicked()), checker, SLOT(redo()));
connect(buttonClear, SIGNAL(clicked()), textEdit, SLOT(clear()));
connect(buttonClear, SIGNAL(clicked()), checker, SLOT(clearUndoRedo()));
}
};
#endif // EXAMPLE_HPP

Definition at line 231 of file QtSpell.hpp.

Member Function Documentation

◆ checkSpelling()

void QtSpell::TextEditChecker::checkSpelling ( int  start = 0,
int  end = -1 
)
virtual

Check the spelling.

Parameters
startThe start position within the buffer.
endThe end position within the buffer (-1 for the buffer end).

Implements QtSpell::Checker.

Definition at line 172 of file TextEditChecker.cpp.

References QtSpell::Checker::checkWord(), QtSpell::TextCursor::isWordChar(), QtSpell::TextCursor::moveWordEnd(), and QtSpell::TextCursor::nextChar().

◆ clearUndoRedo

void QtSpell::TextEditChecker::clearUndoRedo ( )
slot

Clears the undo/redo stack.

Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Definition at line 242 of file TextEditChecker.cpp.

◆ getWord()

QString QtSpell::TextEditChecker::getWord ( int  pos,
int *  start = 0,
int *  end = 0 
) const
privatevirtual

Get the word at the specified cursor position.

Parameters
posThe cursor position.
startIf not 0, will contain the start position of the word.
endIf not 0, will contain the end position of the word.
Returns
The word.

Implements QtSpell::Checker.

Definition at line 266 of file TextEditChecker.cpp.

References QtSpell::TextCursor::moveWordEnd(), and QtSpell::TextCursor::moveWordStart().

◆ insertWord()

void QtSpell::TextEditChecker::insertWord ( int  start,
int  end,
const QString &  word 
)
privatevirtual

Replaces the specified range with the specified word.

Parameters
startThe start position.
endThe end position.
wordThe word to insert.

Implements QtSpell::Checker.

Definition at line 279 of file TextEditChecker.cpp.

◆ isAttached()

bool QtSpell::TextEditChecker::isAttached ( ) const
inlineprivatevirtual

Returns whether a widget is attached to the checker.

Returns
Whether a widget is attached to the checker.

Implements QtSpell::Checker.

Definition at line 340 of file QtSpell.hpp.

◆ noSpellingPropertyId()

int QtSpell::TextEditChecker::noSpellingPropertyId ( ) const
inline

Returns the current QTextCharFormat property identifier which marks whether a word ought to be spell-checked.

Returns
The no-spelling QTextCharFormat property identifier.

Definition at line 273 of file QtSpell.hpp.

◆ redo

void QtSpell::TextEditChecker::redo ( )
slot

Redo the last edit operation.

Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Definition at line 363 of file TextEditChecker.cpp.

◆ redoAvailable

void QtSpell::TextEditChecker::redoAvailable ( bool  available)
signal

Emitted when the redo stak changes.

Parameters
availableWhether redo steps are available.
Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Referenced by setUndoRedoEnabled().

◆ setNoSpellingPropertyId()

void QtSpell::TextEditChecker::setNoSpellingPropertyId ( int  propertyId)
inline

Set the QTextCharFormat property identifier which marks whether a word ought to be spell-checked.

Parameters
propertyIdBy default this is -1, meaning that no such property is set. To enable, pass a value above QTextFormat::UserProperty.
Note
If the value returned by QTextFormat::intProperty is 1, spelling is skipped. To work correctly, this property needs to be set for the entire word.

Definition at line 266 of file QtSpell.hpp.

◆ setTextEdit() [1/2]

void QtSpell::TextEditChecker::setTextEdit ( QPlainTextEdit *  textEdit)

Set the QPlainTextEdit to check.

Parameters
textEditThe QPlainTextEdit to check, or 0 to detach.

Definition at line 112 of file TextEditChecker.cpp.

References setTextEdit().

◆ setTextEdit() [2/2]

void QtSpell::TextEditChecker::setTextEdit ( QTextEdit *  textEdit)

Set the QTextEdit to check.

Parameters
textEditThe QTextEdit to check, or 0 to detach.

Definition at line 107 of file TextEditChecker.cpp.

Referenced by setTextEdit(), and ~TextEditChecker().

◆ setUndoRedoEnabled()

void QtSpell::TextEditChecker::setUndoRedoEnabled ( bool  enabled)

Sets whether undo/redo functionality is enabled.

Parameters
enabledWhether undo/redo is enabled.
Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Definition at line 249 of file TextEditChecker.cpp.

References redoAvailable(), and undoAvailable().

◆ undo

void QtSpell::TextEditChecker::undo ( )
slot

Undo the last edit operation.

Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Definition at line 353 of file TextEditChecker.cpp.

◆ undoAvailable

void QtSpell::TextEditChecker::undoAvailable ( bool  available)
signal

Emitted when the undo stack changes.

Parameters
availableWhether undo steps are available.
Note
QtSpell::TextEditChecker reimplements the undo/redo functionality since the one provided by QTextDocument also tracks text format changes (i.e. underlining of spelling errors) which is undesirable.

Referenced by setUndoRedoEnabled().


The documentation for this class was generated from the following files:
QtSpell::TextEditChecker::redoAvailable
void redoAvailable(bool available)
Emitted when the redo stak changes.
QtSpell::Checker::setDecodeLanguageCodes
void setDecodeLanguageCodes(bool decode)
Set whether to decode language codes in the UI.
Definition: QtSpell.hpp:97
QtSpell::TextEditChecker::clearUndoRedo
void clearUndoRedo()
Clears the undo/redo stack.
Definition: TextEditChecker.cpp:242
QtSpell::TextEditChecker::undo
void undo()
Undo the last edit operation.
Definition: TextEditChecker.cpp:353
QtSpell::Checker::setShowCheckSpellingCheckbox
void setShowCheckSpellingCheckbox(bool show)
Set whether to display an "Check spelling" checkbox in the UI.
Definition: QtSpell.hpp:109
QtSpell::TextEditChecker::redo
void redo()
Redo the last edit operation.
Definition: TextEditChecker.cpp:363
QtSpell::TextEditChecker::setUndoRedoEnabled
void setUndoRedoEnabled(bool enabled)
Sets whether undo/redo functionality is enabled.
Definition: TextEditChecker.cpp:249
QtSpell::TextEditChecker
Checker class for QTextEdit widgets.
Definition: QtSpell.hpp:232
QtSpell::TextEditChecker::undoAvailable
void undoAvailable(bool available)
Emitted when the undo stack changes.
QtSpell::TextEditChecker::setTextEdit
void setTextEdit(QTextEdit *textEdit)
Set the QTextEdit to check.
Definition: TextEditChecker.cpp:107