diff options
author | Vlad Voicu <vladv@rosedu.org> | 2012-03-05 18:28:47 (GMT) |
---|---|---|
committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:45 (GMT) |
commit | 5ca749621b991e6a1e10d7a809d0fe1f0680ca74 (patch) | |
tree | 0b9683d47ce43376a48103d7e7381f207681cd2c /Swift/QtUI/QtTextEdit.cpp | |
parent | a74153f0af0149b445eb5fd18f616e8a3e7f8462 (diff) | |
download | swift-contrib-5ca749621b991e6a1e10d7a809d0fe1f0680ca74.zip swift-contrib-5ca749621b991e6a1e10d7a809d0fe1f0680ca74.tar.bz2 |
Improved settings for Spell Checker
Diffstat (limited to 'Swift/QtUI/QtTextEdit.cpp')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 60f0939..e523dca 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -5,12 +5,14 @@ */ #include <boost/tuple/tuple.hpp> +#include <boost/algorithm/string.hpp> #include <SwifTools/SpellCheckerFactory.h> #include <SwifTools/SpellChecker.h> #include <Swift/QtUI/QtTextEdit.h> #include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtSpellCheckerWindow.h> #include <QApplication> #include <QFontMetrics> @@ -20,12 +22,11 @@ namespace Swift { -QtTextEdit::QtTextEdit(QWidget* parent) : QTextEdit(parent) { +QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent) { connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged())); + settings_ = settings; + setUpSpellChecker(); handleTextChanged(); - SpellCheckerFactory *checkerFactory = new SpellCheckerFactory(); - checker_ = checkerFactory->createSpellChecker(); - delete checkerFactory; }; QtTextEdit::~QtTextEdit() { @@ -57,11 +58,21 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { } else { QTextEdit::keyPressEvent(event); - underlineMisspells(); + if(settings_->getSetting(SettingConstants::SPELL_CHECKER)) { + underlineMisspells(); + } } } void QtTextEdit::underlineMisspells() { + if (checker_ == NULL) { + // Try to setUp the checker again in case that + // settings changed. + setUpSpellChecker(); + if (checker_ == NULL) { + return; + } + } misspelledPositions_.clear(); QTextCharFormat spellingErrorFormat; QTextCharFormat normalFormat; @@ -160,4 +171,26 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { delete menu; } +void QtTextEdit::setUpSpellChecker() +{ + SpellCheckerFactory *checkerFactory = new SpellCheckerFactory(); + std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE); + if (dictFile.empty()) { + // Disable the dictionary to force the user to select a dictionary + settings_->storeSetting(SettingConstants::SPELL_CHECKER, false); + } + if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { + std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH); + std::string affixFile(dictFile); + boost::replace_all(affixFile, ".dic", ".aff"); + if (checker_ != NULL) { + delete checker_; + } + checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str()); + delete checkerFactory; + } else { + checker_ = NULL; + } +} + } |