|
QtSpell
0.8.2
Spell checking for Qt text widgets
|
Checker class for QTextEdit widgets. More...
#include <QtSpell.hpp>
Inherits QtSpell::Checker.
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. | |
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.
| void QtSpell::TextEditChecker::checkSpelling | ( | int | start = 0, |
| int | end = -1 |
||
| ) | [virtual] |
Check the spelling.
| start | The start position within the buffer. |
| end | The 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().
| void QtSpell::TextEditChecker::clearUndoRedo | ( | ) | [slot] |
Clears the undo/redo stack.
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.
| pos | The cursor position. |
| start | If not 0, will contain the start position of the word. |
| end | If not 0, will contain the end position of 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.
| start | The start position. |
| end | The end position. |
| word | The 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.
Implements QtSpell::Checker.
Definition at line 340 of file QtSpell.hpp.
| int QtSpell::TextEditChecker::noSpellingPropertyId | ( | ) | const [inline] |
Returns the current QTextCharFormat property identifier which marks whether a word ought to be spell-checked.
Definition at line 273 of file QtSpell.hpp.
| void QtSpell::TextEditChecker::redo | ( | ) | [slot] |
Redo the last edit operation.
Definition at line 363 of file TextEditChecker.cpp.
| void QtSpell::TextEditChecker::redoAvailable | ( | bool | available | ) | [signal] |
Emitted when the redo stak changes.
| available | Whether redo steps are available. |
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.
| propertyId | By default this is -1, meaning that no such property is set. To enable, pass a value above QTextFormat::UserProperty. |
Definition at line 266 of file QtSpell.hpp.
| void QtSpell::TextEditChecker::setTextEdit | ( | QTextEdit * | textEdit | ) |
Set the QTextEdit to check.
| textEdit | The 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.
| textEdit | The QPlainTextEdit to check, or 0 to detach. |
Definition at line 112 of file TextEditChecker.cpp.
References setTextEdit().
| void QtSpell::TextEditChecker::setUndoRedoEnabled | ( | bool | enabled | ) |
Sets whether undo/redo functionality is enabled.
| enabled | Whether undo/redo is enabled. |
Definition at line 249 of file TextEditChecker.cpp.
References redoAvailable(), and undoAvailable().
| void QtSpell::TextEditChecker::undo | ( | ) | [slot] |
Undo the last edit operation.
Definition at line 353 of file TextEditChecker.cpp.
| void QtSpell::TextEditChecker::undoAvailable | ( | bool | available | ) | [signal] |
Emitted when the undo stack changes.
| available | Whether undo steps are available. |
Referenced by setUndoRedoEnabled().
1.7.6.1