|
QtSpell
0.8.2
Spell checking for Qt text widgets
|
00001 /* QtSpell - Spell checking for Qt text widgets. 00002 * Copyright (c) 2014 Sandro Mani 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef QTSPELL_TEXTEDITCHECKER_P_HPP 00020 #define QTSPELL_TEXTEDITCHECKER_P_HPP 00021 00022 #include <QTextCursor> 00023 00024 class QMenu; 00025 00026 namespace QtSpell { 00027 00031 class TextCursor : public QTextCursor 00032 { 00033 public: 00034 TextCursor() 00035 : QTextCursor(), m_wordRegEx(QRegExp("^\\w$")) {} 00036 TextCursor(QTextDocument* document) 00037 : QTextCursor(document), m_wordRegEx(QRegExp("^\\w$")) {} 00038 TextCursor(const QTextBlock& block) 00039 : QTextCursor(block), m_wordRegEx(QRegExp("^\\w$")) {} 00040 TextCursor(const QTextCursor& cursor) 00041 : QTextCursor(cursor), m_wordRegEx(QRegExp("^\\w$")) {} 00042 00048 QString nextChar(int num = 1) const; 00049 00055 QString prevChar(int num = 1) const; 00056 00062 void moveWordStart(MoveMode moveMode = MoveAnchor); 00063 00069 void moveWordEnd(MoveMode moveMode = MoveAnchor); 00070 00075 bool isInsideWord() const{ 00076 return nextChar().contains(m_wordRegEx) || prevChar().contains(m_wordRegEx); 00077 } 00078 00083 bool isWordChar(const QString& character) const{ 00084 return character.contains(m_wordRegEx); 00085 } 00086 00087 private: 00088 QRegExp m_wordRegEx; 00089 }; 00090 00092 00093 class TextEditProxy { 00094 public: 00095 virtual ~TextEditProxy(){} 00096 virtual QTextCursor textCursor() const = 0; 00097 virtual QTextDocument* document() const = 0; 00098 virtual QPoint mapToGlobal(const QPoint& pos) const = 0; 00099 virtual QMenu* createStandardContextMenu() = 0; 00100 virtual QTextCursor cursorForPosition(const QPoint& pos) const = 0; 00101 virtual void setContextMenuPolicy(Qt::ContextMenuPolicy policy) = 0; 00102 virtual void setTextCursor(const QTextCursor& cursor) = 0; 00103 virtual Qt::ContextMenuPolicy contextMenuPolicy() const = 0; 00104 virtual void installEventFilter(QObject* filterObj) = 0; 00105 virtual void removeEventFilter(QObject* filterObj) = 0; 00106 virtual void ensureCursorVisible() = 0; 00107 virtual QObject* object() = 0; 00108 }; 00109 00110 template<class T> 00111 class TextEditProxyT : public TextEditProxy { 00112 public: 00113 TextEditProxyT(T* textEdit) : m_textEdit(textEdit) {} 00114 QTextCursor textCursor() const{ return m_textEdit->textCursor(); } 00115 QTextDocument* document() const{ return m_textEdit->document(); } 00116 QPoint mapToGlobal(const QPoint& pos) const{ return m_textEdit->mapToGlobal(pos); } 00117 QMenu* createStandardContextMenu(){ return m_textEdit->createStandardContextMenu(); } 00118 QTextCursor cursorForPosition(const QPoint& pos) const{ return m_textEdit->cursorForPosition(pos); } 00119 void setContextMenuPolicy(Qt::ContextMenuPolicy policy){ m_textEdit->setContextMenuPolicy(policy); } 00120 void setTextCursor(const QTextCursor& cursor){ m_textEdit->setTextCursor(cursor); } 00121 Qt::ContextMenuPolicy contextMenuPolicy() const{ return m_textEdit->contextMenuPolicy(); } 00122 void installEventFilter(QObject* filterObj){ m_textEdit->installEventFilter(filterObj); } 00123 void removeEventFilter(QObject* filterObj){ m_textEdit->removeEventFilter(filterObj); } 00124 void ensureCursorVisible() { m_textEdit->ensureCursorVisible(); } 00125 QObject* object(){ return m_textEdit; } 00126 00127 private: 00128 T* m_textEdit; 00129 }; 00130 00131 } // QtSpell 00132 00133 #endif // QTSPELL_TEXTEDITCHECKER_P_HPP
1.7.6.1