From 29bc377fb4bb25c7d0e5bb5471e80c497f0a98c5 Mon Sep 17 00:00:00 2001 From: craig Date: Wed, 2 May 2012 15:34:05 +0000 Subject: Bump the hunspell checker a bit git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17486 11d20701-8431-0410-a711-e3c959e3b870 --- .../plugins/tools/hunspellcheck/hunspelldialog.cpp | 64 ++++++++++++++++++++-- .../plugins/tools/hunspellcheck/hunspelldialog.h | 4 ++ 2 files changed, 62 insertions(+), 6 deletions(-) (limited to 'scribus/plugins') diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp index 7c2c5a7..8322a0d 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp @@ -9,6 +9,7 @@ for which a new license (GPL+exception) is in place. #include #include #include "hunspelldialog.h" +#include "langmgr.h" HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iText) @@ -20,10 +21,13 @@ HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iTex connect (ignoreAllPushButton, SIGNAL(clicked()), this, SLOT(ignoreAllWords())); connect (changePushButton, SIGNAL(clicked()), this, SLOT(changeWord())); connect (changeAllPushButton, SIGNAL(clicked()), this, SLOT(changeAllWords())); + connect (languagesComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(languageComboChanged(int))); m_doc=doc; m_docChanged=false; m_Itext=iText; + m_returnToDefaultLang=false; + m_primaryLangIndex=0; } void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList *wfList) @@ -31,15 +35,32 @@ void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QListaddItems(*dictEntries); - + bool b=languagesComboBox->blockSignals(true); + languagesComboBox->clear(); + for(int i=0;icount();++i) + languagesComboBox->addItem(LanguageManager::instance()->getLangFromAbbrev(dictEntries->at(i), true)); + languagesComboBox->setCurrentIndex(0); + m_primaryLangIndex=0; + languagesComboBox->blockSignals(b); wfListIndex=0; goToNextWord(0); } +void HunspellDialog::updateSuggestions(QStringList &newSuggestions) +{ + suggestionsListWidget->clear(); + suggestionsListWidget->addItems(newSuggestions); + suggestionsListWidget->setCurrentRow(0); +} + void HunspellDialog::goToNextWord(int i) { + if (m_returnToDefaultLang) + { + bool b=languagesComboBox->blockSignals(true); + languagesComboBox->setCurrentIndex(m_primaryLangIndex); + languagesComboBox->blockSignals(b); + } if (i>=0) wfListIndex=i; else @@ -61,9 +82,7 @@ void HunspellDialog::goToNextWord(int i) else statusLabel->setText(""); currWF=m_wfList->at(wfListIndex); - suggestionsListWidget->clear(); - suggestionsListWidget->addItems(currWF.replacements); - suggestionsListWidget->setCurrentRow(0); + updateSuggestions(currWF.replacements); int sentencePos=0; QString sentence(m_Itext->sentence(currWF.start, sentencePos)); @@ -106,6 +125,7 @@ void HunspellDialog::changeAllWords() void HunspellDialog::replaceWord(int i) { + //TODO: rehypenate after the replacement //qDebug()<<"Replacing word"<at(i).w<at(i).start; QString newText(suggestionsListWidget->currentItem()->text()); int lengthDiff=m_Itext->replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText); @@ -117,3 +137,35 @@ void HunspellDialog::replaceWord(int i) (*m_wfList)[i].changed=true; m_docChanged=true; } + +void HunspellDialog::languageComboChanged(int index) +{ + m_returnToDefaultLang=true; + QString newLanguage=languagesComboBox->itemText(index); + QString wordToCheck=m_wfList->at(wfListIndex).w; +// qDebug()<<"You changed the language to:"<spell(wordToCheck.toUtf8().constData())==0) + { + char **sugglist = NULL; + int suggCount=m_hspellers[index]->suggest(&sugglist, wordToCheck.toUtf8().constData()); + QStringList replacements; + for (int j=0; j < suggCount; ++j) + { + //qDebug()<<"Suggestion "<free_list(&sugglist, suggCount); + updateSuggestions(replacements); + } + else + { + (*m_wfList)[wfListIndex].changed=true; + m_docChanged=true; + goToNextWord(); + } +} diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h index 634490c..85a7da1 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h @@ -24,6 +24,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase ~HunspellDialog() {}; void set(QStringList* dictEntries, Hunspell **hspellers, QList* wfList); bool docChanged() {return m_docChanged;} + void updateSuggestions(QStringList& newSuggestions); public slots: void goToNextWord(int i=-1); @@ -31,6 +32,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase void changeWord(); void changeAllWords(); void replaceWord(int i); + void languageComboChanged(int index); private: ScribusDoc* m_doc; @@ -41,6 +43,8 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase WordsFound currWF; int wfListIndex; bool m_docChanged; + bool m_returnToDefaultLang; + int m_primaryLangIndex; }; #endif // HUNSPELLDIALOG_H -- cgit