QtSpell  0.8.2
Spell checking for Qt text widgets
Public Slots | Signals | Public Member Functions | Private Member Functions
QtSpell::TextEditChecker Class Reference

Checker class for QTextEdit widgets. More...

#include <QtSpell.hpp>

Inherits QtSpell::Checker.

List of all members.

Public Slots

void undo ()
 Undo the last edit operation.
void redo ()
 Redo the last edit operation.
void clearUndoRedo ()
 Clears the undo/redo stack.

Signals

void undoAvailable (bool available)
 Emitted when the undo stack changes.
void redoAvailable (bool available)
 Emitted when the redo stak changes.

Public Member Functions

 TextEditChecker (QObject *parent=0)
 TextEditChecker object constructor.
 ~TextEditChecker ()
 TextEditChecker object destructor.
void setTextEdit (QTextEdit *textEdit)
 Set the QTextEdit to check.
void setTextEdit (QPlainTextEdit *textEdit)
 Set the QPlainTextEdit to check.
void setNoSpellingPropertyId (int propertyId)
 Set the QTextCharFormat property identifier which marks whether a word ought to be spell-checked.
int noSpellingPropertyId () const
 Returns the current QTextCharFormat property identifier which marks whether a word ought to be spell-checked.
void checkSpelling (int start=0, int end=-1)
 Check the spelling.
void setUndoRedoEnabled (bool enabled)
 Sets whether undo/redo functionality is enabled.

Private Member Functions

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

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);


                QtSpell::TextEditChecker* checker = new QtSpell::TextEditChecker(this);
                checker->setTextEdit(textEdit);
                checker->setDecodeLanguageCodes(true);
                checker->setShowCheckSpellingCheckbox(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

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(), and QtSpell::TextCursor::moveWordEnd().

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.

QString QtSpell::TextEditChecker::getWord ( int  pos,
int *  start = 0,
int *  end = 0 
) const [private, virtual]

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::moveWordStart().

void QtSpell::TextEditChecker::insertWord ( int  start,
int  end,
const QString &  word 
) [private, virtual]

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.

bool QtSpell::TextEditChecker::isAttached ( ) const [inline, private, virtual]

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.

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 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.

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().

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.

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().

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().

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 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.

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: