summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Voicu <vladv@rosedu.org>2012-03-06 14:37:35 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-09 15:04:10 (GMT)
commit7c868599331a7b4156c3572ba4f3dc75af57ce97 (patch)
tree37a2ce59535bb19dc5136f1f09da01e89290a44b
parent91f344444c54f11de132cf22a7ba323727104989 (diff)
downloadswift-contrib-7c868599331a7b4156c3572ba4f3dc75af57ce97.zip
swift-contrib-7c868599331a7b4156c3572ba4f3dc75af57ce97.tar.bz2
Moved the settings from main window to chat window, also added lots of small improvments
-rw-r--r--BuildTools/SCons/SConstruct4
-rw-r--r--SwifTools/SpellCheckerFactory.cpp1
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp17
-rw-r--r--Swift/QtUI/QtLoginWindow.h3
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.cpp3
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.h2
-rw-r--r--Swift/QtUI/QtTextEdit.cpp86
-rw-r--r--Swift/QtUI/QtTextEdit.h9
8 files changed, 71 insertions, 54 deletions
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct
index 3f15695..ce3b020 100644
--- a/BuildTools/SCons/SConstruct
+++ b/BuildTools/SCons/SConstruct
@@ -421,9 +421,9 @@ openssl_conf.Finish()
#Hunspell
env["HAVE_HUNSPELL"] = 0;
conf = Configure(conf_env.Clone())
-if conf.CheckLib("hunspell-1.3") :
+if conf.CheckCXXHeader("hunspell/hunspell.hxx") and conf.CheckLib("hunspell-1.3") :
env["HAVE_HUNSPELL"] = 1
- env["HUNSPELL_FLAGS"] = {"LIBS": ["libhunspell-1.3"]}
+ env["HUNSPELL_FLAGS"] = {"LIBS": ["hunspell-1.3"]}
# Bonjour
diff --git a/SwifTools/SpellCheckerFactory.cpp b/SwifTools/SpellCheckerFactory.cpp
index 9ac33cd..835cda9 100644
--- a/SwifTools/SpellCheckerFactory.cpp
+++ b/SwifTools/SpellCheckerFactory.cpp
@@ -19,7 +19,6 @@ SpellCheckerFactory::SpellCheckerFactory() {
SpellChecker* SpellCheckerFactory::createSpellChecker(const char* affixPath, const char* dictPath) {
#ifdef HAVE_HUNSPELL
- std::cout << affixPath << std::endl << dictPath << std::endl;
return new HunspellChecker(affixPath, dictPath);
#endif
return NULL;
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index f7fc3a7..a3b7837 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -193,11 +193,6 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set
toggleNotificationsAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
connect(toggleNotificationsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleNotifications(bool)));
- QAction* spellCheckerAction_ = new QAction(tr("Spell &Checker"), this);
- connect(spellCheckerAction_, SIGNAL(triggered()), SLOT(handleSpellChecker()));
- generalMenu_->addAction(spellCheckerAction_);
-
-
#ifndef SWIFTEN_PLATFORM_MACOSX
swiftMenu_->addSeparator();
#endif
@@ -409,18 +404,6 @@ void QtLoginWindow::handleAbout() {
}
}
-void QtLoginWindow::handleSpellChecker() {
- if (!spellCheckerDialog_) {
- spellCheckerDialog_ = new QtSpellCheckerWindow(settings_);
- spellCheckerDialog_->show();
- }
- else {
- spellCheckerDialog_->show();
- spellCheckerDialog_->raise();
- spellCheckerDialog_->activateWindow();
- }
-}
-
void QtLoginWindow::handleShowXMLConsole() {
uiEventStream_->send(boost::shared_ptr<RequestXMLConsoleUIEvent>(new RequestXMLConsoleUIEvent()));
}
diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h
index ed15182..dcd7c18 100644
--- a/Swift/QtUI/QtLoginWindow.h
+++ b/Swift/QtUI/QtLoginWindow.h
@@ -18,7 +18,6 @@
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/MainWindow.h>
#include <QtAboutWidget.h>
-#include <QtSpellCheckerWindow.h>
class QLabel;
class QToolButton;
@@ -64,7 +63,6 @@ namespace Swift {
void handleToggleSounds(bool enabled);
void handleToggleNotifications(bool enabled);
void handleAbout();
- void handleSpellChecker();
void bringToFront();
void handleUsernameTextChanged();
void resizeEvent(QResizeEvent* event);
@@ -97,7 +95,6 @@ namespace Swift {
QAction* toggleNotificationsAction_;
UIEventStream* uiEventStream_;
QPointer<QtAboutWidget> aboutDialog_;
- QPointer<QtSpellCheckerWindow> spellCheckerDialog_;
SettingsProvider* settings_;
QAction* xmlConsoleAction_;
QAction* fileTransferOverviewAction_;
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp
index ef1985e..f955668 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.cpp
+++ b/Swift/QtUI/QtSpellCheckerWindow.cpp
@@ -64,9 +64,8 @@ void QtSpellCheckerWindow::handleApply() {
QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
if (!selectedLanguage.empty()) {
settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING(selectedLanguage[0]->text()));
- } else {
- settings_->storeSetting(SettingConstants::SPELL_CHECKER, false);
}
+ emit settingsChanged();
this->done(0);
}
diff --git a/Swift/QtUI/QtSpellCheckerWindow.h b/Swift/QtUI/QtSpellCheckerWindow.h
index ad94907..40ed882 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.h
+++ b/Swift/QtUI/QtSpellCheckerWindow.h
@@ -22,6 +22,8 @@ namespace Swift {
void handlePathButton();
void handlePersonalPathButton();
void handleApply();
+ signals:
+ void settingsChanged();
private:
void setEnabled(bool state);
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index e523dca..f115d1c 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -65,23 +65,18 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) {
}
void QtTextEdit::underlineMisspells() {
- if (checker_ == NULL) {
- // Try to setUp the checker again in case that
- // settings changed.
- setUpSpellChecker();
- if (checker_ == NULL) {
- return;
- }
- }
+ QTextCursor cursor = textCursor();
misspelledPositions_.clear();
- QTextCharFormat spellingErrorFormat;
QTextCharFormat normalFormat;
- spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
- spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
- QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor, 1);
cursor.setCharFormat(normalFormat);
+ if (checker_ == NULL) {
+ return;
+ }
+ QTextCharFormat spellingErrorFormat;
+ spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
+ spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
std::string fragment = Q2PSTRING(cursor.selectedText());
checker_->checkFragment(fragment, misspelledPositions_);
for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) {
@@ -103,8 +98,9 @@ void QtTextEdit::handleTextChanged() {
}
}
-void QtTextEdit::handleReplaceMisspellWord(const QString& word, const boost::tuple<int, int>& wordPosition) {
+void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition) {
QTextCursor cursor = textCursor();
+ boost::tuple<int, int> wordPosition = getWordFromCursor(cursorPosition);
cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
QTextCharFormat normalFormat;
@@ -136,41 +132,55 @@ QSize QtTextEdit::sizeHint() const {
void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) {
QMenu *menu = createStandardContextMenu();
QTextCursor cursor = cursorForPosition(event->pos());
+ 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);
+ QAction* result = menu->exec(event->globalPos());
+ if (result == settingsAction) {
+ spellCheckerSettingsWindow();
+ }
+ for (std::vector<QAction*>::iterator it = replaceWordActions_.begin(); it != replaceWordActions_.end(); ++it) {
+ if (*it == result) {
+ replaceMisspelledWord((*it)->text(), cursor.position());
+ }
+ }
+ delete menu;
+}
+
+void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event)
+{
+ replaceWordActions_.clear();
+ QAction *insertPoint = menu->actions().first();
+ QTextCursor cursor = cursorForPosition(event->pos());
boost::tuple<int, int> wordPosition = getWordFromCursor(cursor.position());
if (boost::get<0>(wordPosition) < 0) {
// The click was executed outside a spellable word so no
- // suggestion menu is necessary
- menu->exec(event->globalPos());
- delete menu;
+ // suggestions are necessary
return;
}
cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
std::vector<std::string> wordList;
checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList);
- std::vector<QAction*> replaceWordActions;
- QAction *insertPoint = menu->actions().first();
if (wordList.size() == 0) {
QAction *noSuggestions = new QAction(QApplication::translate("QtTextEdit", "No Suggestions", 0, QApplication::UnicodeUTF8), menu);
noSuggestions->setDisabled(true);
menu->insertAction(insertPoint, noSuggestions);
- } else {
+ }
+ else {
for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) {
QAction *wordAction = new QAction(it->c_str(), menu);
menu->insertAction(insertPoint, wordAction);
- replaceWordActions.push_back(wordAction);
+ replaceWordActions_.push_back(wordAction);
}
}
menu->insertAction(insertPoint, menu->addSeparator());
- QAction* result = menu->exec(event->globalPos());
- for (std::vector<QAction*>::iterator it = replaceWordActions.begin(); it != replaceWordActions.end(); ++it) {
- if (*it == result) {
- handleReplaceMisspellWord((*it)->text(), wordPosition);
- }
- }
- delete menu;
}
+
void QtTextEdit::setUpSpellChecker()
{
SpellCheckerFactory *checkerFactory = new SpellCheckerFactory();
@@ -188,9 +198,29 @@ void QtTextEdit::setUpSpellChecker()
}
checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str());
delete checkerFactory;
- } else {
+ }
+ else {
checker_ = NULL;
}
}
+void QtTextEdit::spellCheckerSettingsWindow() {
+ if (!spellCheckerWindow_) {
+ spellCheckerWindow_ = new QtSpellCheckerWindow(settings_);
+ connect(spellCheckerWindow_, SIGNAL(settingsChanged()), this, SLOT(handleModifiedSettings()));
+ spellCheckerWindow_->show();
+ }
+ else {
+ spellCheckerWindow_->show();
+ spellCheckerWindow_->raise();
+ spellCheckerWindow_->activateWindow();
+ }
+}
+
+void QtTextEdit::handleModifiedSettings() {
+ delete checker_;
+ setUpSpellChecker();
+ underlineMisspells();
+}
+
}
diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h
index 38d5d0a..b40c935 100644
--- a/Swift/QtUI/QtTextEdit.h
+++ b/Swift/QtUI/QtTextEdit.h
@@ -12,9 +12,11 @@
#include <Swift/Controllers/SettingConstants.h>
#include <QTextEdit>
+#include <QPointer>
namespace Swift {
class SpellChecker;
+ class QtSpellCheckerWindow;
class QtTextEdit : public QTextEdit {
Q_OBJECT
public:
@@ -26,7 +28,7 @@ namespace Swift {
void returnPressed();
void unhandledKeyPressEvent(QKeyEvent* event);
public slots:
- void handleReplaceMisspellWord(const QString& word, const boost::tuple<int,int>& wordPosition);
+ void handleModifiedSettings();
protected:
virtual void keyPressEvent(QKeyEvent* event);
virtual void contextMenuEvent(QContextMenuEvent* event);
@@ -34,10 +36,15 @@ namespace Swift {
void handleTextChanged();
private:
SpellChecker *checker_;
+ std::vector<QAction*> replaceWordActions_;
PositionPairList misspelledPositions_;
SettingsProvider *settings_;
+ QPointer<QtSpellCheckerWindow> spellCheckerWindow_;
+ void addSuggestions(QMenu* menu, QContextMenuEvent* event);
+ void replaceMisspelledWord(const QString& word, int cursorPosition);
void setUpSpellChecker();
void underlineMisspells();
+ void spellCheckerSettingsWindow();
boost::tuple<int,int> getWordFromCursor(int cursorPosition);
};
}