diff options
author | Vlad Voicu <vladv@rosedu.org> | 2012-03-19 18:36:07 (GMT) |
---|---|---|
committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:45 (GMT) |
commit | 5f745ebd56014a68695ac4b6fe7fb5dc96e34384 (patch) | |
tree | 284e1c2f9d41844dd17046d859d2c68225cfa1d6 /Swift | |
parent | b3948434495a18df5c4537a2a6e0feecc0805788 (diff) | |
download | swift-contrib-5f745ebd56014a68695ac4b6fe7fb5dc96e34384.zip swift-contrib-5f745ebd56014a68695ac4b6fe7fb5dc96e34384.tar.bz2 |
Addressed Kev's code review
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtSpellCheckerWindow.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtSpellCheckerWindow.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtSpellCheckerWindow.ui | 90 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 54 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.h | 4 |
5 files changed, 59 insertions, 99 deletions
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp index ff6ef39..e2c5b0d 100644 --- a/Swift/QtUI/QtSpellCheckerWindow.cpp +++ b/Swift/QtUI/QtSpellCheckerWindow.cpp @@ -25,13 +25,11 @@ QtSpellCheckerWindow::QtSpellCheckerWindow(SettingsProvider* settings, QWidget* connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel())); connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply())); connect(ui_.pathButton, SIGNAL(clicked()), this, SLOT(handlePathButton())); - connect(ui_.personalPathButton, SIGNAL(clicked()), this, SLOT(handlePersonalPathButton())); setFromSettings(); } void QtSpellCheckerWindow::setFromSettings() { ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER)); - ui_.personalPathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH))); ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH))); ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE))); std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH); @@ -48,12 +46,9 @@ void QtSpellCheckerWindow::handleChecker(bool state) { void QtSpellCheckerWindow::setEnabled(bool state) { ui_.pathContent->setEnabled(state); - ui_.personalPathContent->setEnabled(state); ui_.languageView->setEnabled(state); ui_.pathButton->setEnabled(state); - ui_.personalPathButton->setEnabled(state); ui_.pathLabel->setEnabled(state); - ui_.personalDictionaryLabel->setEnabled(state); ui_.currentLanguage->setEnabled(state); ui_.currentLanguageValue->setEnabled(state); ui_.language->setEnabled(state); @@ -65,7 +60,6 @@ void QtSpellCheckerWindow::handleApply() { if (!selectedLanguage.empty()) { settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text())); } - emit settingsChanged(); this->done(0); } @@ -76,7 +70,7 @@ void QtSpellCheckerWindow::handleCancel() { void QtSpellCheckerWindow::handlePathButton() { std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH); QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath)); - if (dirpath.compare(P2QSTRING(currentPath))) { + if (dirpath != P2QSTRING(currentPath)) { ui_.languageView->clear(); settings_->storeSetting(SettingConstants::DICT_FILE, ""); ui_.currentLanguageValue->setText(" "); diff --git a/Swift/QtUI/QtSpellCheckerWindow.h b/Swift/QtUI/QtSpellCheckerWindow.h index 40ed882..ad94907 100644 --- a/Swift/QtUI/QtSpellCheckerWindow.h +++ b/Swift/QtUI/QtSpellCheckerWindow.h @@ -22,8 +22,6 @@ namespace Swift { void handlePathButton(); void handlePersonalPathButton(); void handleApply(); - signals: - void settingsChanged(); private: void setEnabled(bool state); diff --git a/Swift/QtUI/QtSpellCheckerWindow.ui b/Swift/QtUI/QtSpellCheckerWindow.ui index 63f3ed4..b98bb6d 100644 --- a/Swift/QtUI/QtSpellCheckerWindow.ui +++ b/Swift/QtUI/QtSpellCheckerWindow.ui @@ -6,110 +6,80 @@ <rect> <x>0</x> <y>0</y> - <width>502</width> - <height>303</height> + <width>353</width> + <height>207</height> </rect> </property> <property name="windowTitle"> <string>Dialog</string> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="2"> + <item row="4" column="3" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="cancel"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="apply"> + <property name="text"> + <string>Apply</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="0" column="0" colspan="3"> <widget class="QCheckBox" name="spellChecker"> <property name="text"> <string>Spell Checker Enabled</string> </property> </widget> </item> - <item row="1" column="0"> + <item row="1" column="0" colspan="2"> <widget class="QLabel" name="pathLabel"> <property name="text"> <string>Dictionary Path:</string> </property> </widget> </item> - <item row="1" column="1"> + <item row="1" column="2" colspan="2"> <widget class="QLineEdit" name="pathContent"/> </item> - <item row="1" column="3"> + <item row="1" column="4"> <widget class="QPushButton" name="pathButton"> <property name="text"> <string>Change</string> </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="personalDictionaryLabel"> - <property name="text"> - <string>Personal Dictionary:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="personalPathContent"/> - </item> - <item row="2" column="3"> - <widget class="QPushButton" name="personalPathButton"> - <property name="text"> - <string>Change</string> - </property> - </widget> - </item> - <item row="3" column="0"> + <item row="2" column="0" colspan="2"> <widget class="QLabel" name="currentLanguage"> <property name="text"> <string>Current Language:</string> </property> </widget> </item> - <item row="3" column="1"> + <item row="2" column="2"> <widget class="QLabel" name="currentLanguageValue"> <property name="text"> <string/> </property> </widget> </item> - <item row="4" column="0"> + <item row="3" column="1" colspan="4"> + <widget class="QListWidget" name="languageView"/> + </item> + <item row="3" column="0"> <widget class="QLabel" name="language"> <property name="text"> <string>Language:</string> </property> </widget> </item> - <item row="4" column="1" colspan="2"> - <widget class="QListWidget" name="languageView"/> - </item> - <item row="5" column="2" colspan="2"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="cancel"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="apply"> - <property name="text"> - <string>Apply</string> - </property> - </widget> - </item> - </layout> - </item> </layout> </widget> <resources/> diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 513e6fd..4807f6b 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -6,7 +6,9 @@ #include <boost/tuple/tuple.hpp> #include <boost/algorithm/string.hpp> -#include <boost/filesystem/operations.hpp> +#include <boost/bind.hpp> + +#include <Swiften/Base/foreach.h> #include <SwifTools/SpellCheckerFactory.h> #include <SwifTools/SpellChecker.h> @@ -14,6 +16,7 @@ #include <Swift/QtUI/QtTextEdit.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtSpellCheckerWindow.h> +#include <Swift/Controllers/SettingConstants.h> #include <QApplication> #include <QFontMetrics> @@ -85,9 +88,9 @@ void QtTextEdit::underlineMisspells() { spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline); std::string fragment = Q2PSTRING(cursor.selectedText()); checker_->checkFragment(fragment, misspelledPositions_); - for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) { - cursor.setPosition(boost::get<0>(*it), QTextCursor::MoveAnchor); - cursor.setPosition(boost::get<1>(*it), QTextCursor::KeepAnchor); + foreach (PositionPair position, misspelledPositions_) { + cursor.setPosition(boost::get<0>(position), QTextCursor::MoveAnchor); + cursor.setPosition(boost::get<1>(position), QTextCursor::KeepAnchor); cursor.setCharFormat(spellingErrorFormat); cursor.clearSelection(); cursor.setCharFormat(normalFormat); @@ -104,14 +107,14 @@ void QtTextEdit::handleTextChanged() { void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition) { QTextCursor cursor = textCursor(); - boost::tuple<int, int> wordPosition = getWordFromCursor(cursorPosition); + PositionPair wordPosition = getWordFromCursor(cursorPosition); cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); QTextCharFormat normalFormat; cursor.insertText(word, normalFormat); } -boost::tuple<int, int> QtTextEdit::getWordFromCursor(int cursorPosition) { +PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) { for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) { if (cursorPosition >= boost::get<0>(*it) && cursorPosition <= boost::get<1>(*it)) { return *it; @@ -134,11 +137,11 @@ QSize QtTextEdit::sizeHint() const { } void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { - QMenu *menu = createStandardContextMenu(); + 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); + 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()); addSuggestions(menu, event); @@ -160,9 +163,9 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) { replaceWordActions_.clear(); - QAction *insertPoint = menu->actions().first(); + QAction* insertPoint = menu->actions().first(); QTextCursor cursor = cursorForPosition(event->pos()); - boost::tuple<int, int> wordPosition = getWordFromCursor(cursor.position()); + PositionPair wordPosition = getWordFromCursor(cursor.position()); if (boost::get<0>(wordPosition) < 0) { // The click was executed outside a spellable word so no // suggestions are necessary @@ -173,13 +176,13 @@ void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) std::vector<std::string> wordList; checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); if (wordList.size() == 0) { - QAction *noSuggestions = new QAction(QApplication::translate("QtTextEdit", "No Suggestions", 0, QApplication::UnicodeUTF8), menu); + QAction* noSuggestions = new QAction(QApplication::translate("QtTextEdit", "No Suggestions", 0, QApplication::UnicodeUTF8), menu); noSuggestions->setDisabled(true); menu->insertAction(insertPoint, noSuggestions); } else { for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { - QAction *wordAction = new QAction(it->c_str(), menu); + QAction* wordAction = new QAction(it->c_str(), menu); menu->insertAction(insertPoint, wordAction); replaceWordActions_.push_back(wordAction); } @@ -190,21 +193,12 @@ void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) void QtTextEdit::setUpSpellChecker() { - SpellCheckerFactory *checkerFactory = new SpellCheckerFactory(); + SpellCheckerFactory* checkerFactory = new SpellCheckerFactory(); delete checker_; if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH); std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE); - 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 { - // If dictionaries don't exist disable the checker - checker_ = NULL; - } + checker_ = checkerFactory->createSpellChecker(dictPath + dictFile); delete checkerFactory; } else { @@ -215,7 +209,7 @@ void QtTextEdit::setUpSpellChecker() void QtTextEdit::spellCheckerSettingsWindow() { if (!spellCheckerWindow_) { spellCheckerWindow_ = new QtSpellCheckerWindow(settings_); - connect(spellCheckerWindow_, SIGNAL(settingsChanged()), this, SLOT(handleModifiedSettings())); + settings_->onSettingChanged.connect(boost::bind(&QtTextEdit::handleSettingChanged, this, _1)); spellCheckerWindow_->show(); } else { @@ -225,9 +219,13 @@ void QtTextEdit::spellCheckerSettingsWindow() { } } -void QtTextEdit::handleModifiedSettings() { - setUpSpellChecker(); - underlineMisspells(); +void QtTextEdit::handleSettingChanged(const std::string& settings) { + if (settings == SettingConstants::SPELL_CHECKER.getKey() + || settings == SettingConstants::DICT_PATH.getKey() + || settings == SettingConstants::DICT_FILE.getKey()) { + setUpSpellChecker(); + underlineMisspells(); + } } } diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h index b40c935..a8df4d3 100644 --- a/Swift/QtUI/QtTextEdit.h +++ b/Swift/QtUI/QtTextEdit.h @@ -28,7 +28,7 @@ namespace Swift { void returnPressed(); void unhandledKeyPressEvent(QKeyEvent* event); public slots: - void handleModifiedSettings(); + void handleSettingChanged(const std::string& settings); protected: virtual void keyPressEvent(QKeyEvent* event); virtual void contextMenuEvent(QContextMenuEvent* event); @@ -45,6 +45,6 @@ namespace Swift { void setUpSpellChecker(); void underlineMisspells(); void spellCheckerSettingsWindow(); - boost::tuple<int,int> getWordFromCursor(int cursorPosition); + PositionPair getWordFromCursor(int cursorPosition); }; } |