diff options
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; + } +} + } |