diff options
author | Vlad Voicu <vladv@rosedu.org> | 2012-03-08 13:10:15 (GMT) |
---|---|---|
committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:45 (GMT) |
commit | afdb2b3a61695b42162d09189d083e728da0c74f (patch) | |
tree | 5b99b51d9888bd8bd0d74f677751689acb6111a7 /Swift | |
parent | 9a4873e153ae16ef68e7c60de376ade7882874f0 (diff) | |
download | swift-contrib-afdb2b3a61695b42162d09189d083e728da0c74f.zip swift-contrib-afdb2b3a61695b42162d09189d083e728da0c74f.tar.bz2 |
Gracefully degrade when hunspell is not present
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 24 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 2 |
2 files changed, 16 insertions, 10 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 75bc292..513e6fd 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -27,7 +27,9 @@ QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit( connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged())); checker_ = NULL; settings_ = settings; +#ifdef HAVE_SPELLCHECKER setUpSpellChecker(); +#endif handleTextChanged(); }; @@ -60,9 +62,11 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { } else { QTextEdit::keyPressEvent(event); - if(settings_->getSetting(SettingConstants::SPELL_CHECKER)) { +#ifdef HAVE_SPELLCHECKER + if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { underlineMisspells(); } +#endif } } @@ -82,12 +86,10 @@ void QtTextEdit::underlineMisspells() { std::string fragment = Q2PSTRING(cursor.selectedText()); checker_->checkFragment(fragment, misspelledPositions_); for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) { - if (textCursor().position() > boost::get<1>(*it)) { - cursor.setPosition(boost::get<0>(*it), QTextCursor::MoveAnchor); - cursor.setPosition(boost::get<1>(*it), QTextCursor::KeepAnchor); - cursor.setCharFormat(spellingErrorFormat); - cursor.clearSelection(); - } + cursor.setPosition(boost::get<0>(*it), QTextCursor::MoveAnchor); + cursor.setPosition(boost::get<1>(*it), QTextCursor::KeepAnchor); + cursor.setCharFormat(spellingErrorFormat); + cursor.clearSelection(); cursor.setCharFormat(normalFormat); } } @@ -134,8 +136,8 @@ QSize QtTextEdit::sizeHint() const { void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { QMenu *menu = createStandardContextMenu(); QTextCursor cursor = cursorForPosition(event->pos()); +#ifdef HAVE_SPELLCHECKER QAction *insertPoint = menu->actions().first(); - QAction *settingsAction = new QAction(QApplication::translate("QtTextEdit", "Spell Checker Options", 0, QApplication::UnicodeUTF8), menu); menu->insertAction(insertPoint, settingsAction); menu->insertAction(insertPoint, menu->addSeparator()); @@ -149,6 +151,9 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { replaceMisspelledWord((*it)->text(), cursor.position()); } } +#else + menu->exec(event->globalPos()); +#endif delete menu; } @@ -193,6 +198,7 @@ void QtTextEdit::setUpSpellChecker() std::string affixFile(dictFile); boost::replace_all(affixFile, ".dic", ".aff"); if ((boost::filesystem::exists(dictPath + dictFile)) && (boost::filesystem::exists(dictPath + affixFile))) { + std::cout << dictPath + dictFile << std::endl; checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str()); } else { @@ -220,8 +226,6 @@ void QtTextEdit::spellCheckerSettingsWindow() { } void QtTextEdit::handleModifiedSettings() { - delete checker_; - checker_ = NULL; setUpSpellChecker(); underlineMisspells(); } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 0a9cec5..fcb0dfb 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -40,6 +40,8 @@ if myenv["swift_mobile"] : if myenv.get("HAVE_SNARL", False) : myenv.UseFlags(myenv["SNARL_FLAGS"]) myenv.Append(CPPDEFINES = ["HAVE_SNARL"]) +if myenv.get("HAVE_HUNSPELL", True): + myenv.Append(CPPDEFINES = ["HAVE_HUNSPELL"]) if env["PLATFORM"] == "win32" : myenv.Append(LIBS = ["cryptui"]) myenv.UseFlags(myenv["PLATFORM_FLAGS"]) |