r17486 by craig - Bump the hunspell checker a bit
scribus-commit
scribus-commit at lists.scribus.net
Wed May 2 15:34:06 UTC 2012
Author: craig
Date: Wed May 2 15:34:05 2012
New Revision: 17486
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17486
Log:
Bump the hunspell checker a bit
Modified:
branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17486&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp Wed May 2 15:34:05 2012
@@ -9,6 +9,7 @@
#include <QListWidget>
#include <QTextEdit>
#include "hunspelldialog.h"
+#include "langmgr.h"
HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iText)
@@ -20,10 +21,13 @@
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<WordsFound> *wfList)
@@ -31,15 +35,32 @@
m_dictEntries=dictEntries;
m_hspellers=hspellers;
m_wfList=wfList;
-
- languagesComboBox->addItems(*dictEntries);
-
+ bool b=languagesComboBox->blockSignals(true);
+ languagesComboBox->clear();
+ for(int i=0;i<dictEntries->count();++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 @@
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::replaceWord(int i)
{
+ //TODO: rehypenate after the replacement
//qDebug()<<"Replacing word"<<i<m_wfList->at(i).w<<m_wfList->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 @@
(*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:"<<newLanguage;
+ if (!m_hspellers[index])
+ {
+ qDebug()<<"hspeller"<<index<<"does not exist";
+ return;
+ }
+ if (m_hspellers[index]->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 "<<j<<":"<<sugglist[j];
+ replacements << QString::fromUtf8(sugglist[j]);
+ }
+ m_hspellers[index]->free_list(&sugglist, suggCount);
+ updateSuggestions(replacements);
+ }
+ else
+ {
+ (*m_wfList)[wfListIndex].changed=true;
+ m_docChanged=true;
+ goToNextWord();
+ }
+}
Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17486&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h Wed May 2 15:34:05 2012
@@ -24,6 +24,7 @@
~HunspellDialog() {};
void set(QStringList* dictEntries, Hunspell **hspellers, QList<WordsFound>* wfList);
bool docChanged() {return m_docChanged;}
+ void updateSuggestions(QStringList& newSuggestions);
public slots:
void goToNextWord(int i=-1);
@@ -31,6 +32,7 @@
void changeWord();
void changeAllWords();
void replaceWord(int i);
+ void languageComboChanged(int index);
private:
ScribusDoc* m_doc;
@@ -41,6 +43,8 @@
WordsFound currWF;
int wfListIndex;
bool m_docChanged;
+ bool m_returnToDefaultLang;
+ int m_primaryLangIndex;
};
#endif // HUNSPELLDIALOG_H
More information about the scribus-commit
mailing list