diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-04-19 20:32:43 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-04-19 20:32:43 +0000 |
| commit | b45e4dbc89aa6f864721eba5278b8b0c11eb4ff8 (patch) | |
| tree | 070be75e957291e6e3257a676b77c0d12464206f /scribus/plugins | |
| parent | 9722f324f4a4e6b4d14026dbed8b0d6cd11618ba (diff) | |
| download | scribus-b45e4dbc89aa6f864721eba5278b8b0c11eb4ff8.tar.gz scribus-b45e4dbc89aa6f864721eba5278b8b0c11eb4ff8.tar.xz scribus-b45e4dbc89aa6f864721eba5278b8b0c11eb4ff8.zip | |
Fix change offset for word replacements, and simplify code a decent amount
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17457 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins')
4 files changed, 16 insertions, 19 deletions
diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp index 5a22666..f0eb3a6 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp @@ -24,7 +24,6 @@ HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, PageItem *frame m_doc=doc; m_docChanged=false; fTC=frameToCheck; - changeOffset=0; } void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList<WordsFound> *wfList) @@ -70,8 +69,8 @@ void HunspellDialog::goToNextWord(int i) sentencePos=qMax(sentencePos, iText->nextWord(sentencePos)); int nextSentencePos=qMin(iText->length(), iText->nextSentence(currWF.end)); QString sentence=iText->text(sentencePos, nextSentencePos-sentencePos); - sentence.insert(currWF.end-sentencePos+changeOffset,"</b></font>"); - sentence.insert(currWF.start-sentencePos+changeOffset,"<font color=red><b>"); + sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>"); + sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>"); sentenceTextEdit->setText(sentence); } @@ -118,30 +117,27 @@ void HunspellDialog::replaceWord(int i) QString newText(suggestionsListWidget->currentItem()->text()); if (newText.length()==currWF.w.length()) { - for (int i = 0; i < currWF.w.length(); ++i) - iText->replaceChar(currWF.start+i+changeOffset, newText[i]); + for (int j = 0; j < currWF.w.length(); ++j) + iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]); } else { + int lengthDiff=newText.length()-currWF.w.length(); if (newText.length()>currWF.w.length()) { - for (int i = 0; i < currWF.w.length(); ++i) - iText->replaceChar(currWF.start+i+changeOffset, newText[i]); - for (int i = currWF.w.length(); i < newText.length(); ++i) - iText->insertChars(currWF.start+i+changeOffset, newText.mid(i,1), true); - int lengthDiff=newText.length()-currWF.w.length(); - changeOffset+=lengthDiff; - qDebug()<<"Change Offset is:"<<changeOffset; + for (int j = 0; j < currWF.w.length(); ++j) + iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]); + for (int j = currWF.w.length(); j < newText.length(); ++j) + iText->insertChars(currWF.start+j+currWF.changeOffset, newText.mid(j,1), true); } else { - for (int i = 0; i < newText.length(); ++i) - iText->replaceChar(currWF.start+i+changeOffset, newText[i]); - int lengthDiff=currWF.w.length() - newText.length(); - iText->removeChars(currWF.start+changeOffset+newText.length(), lengthDiff); - changeOffset-=lengthDiff; - qDebug()<<"Change Offset is:"<<changeOffset; + for (int j = 0; j < newText.length(); ++j) + iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]); + iText->removeChars(currWF.start+currWF.changeOffset+newText.length(), -lengthDiff); } + for (int k=i; k<m_wfList->count();++k) + (*m_wfList)[k].changeOffset+=lengthDiff; } m_docChanged=true; } diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h index b3e5a0f..668966d 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h @@ -41,7 +41,6 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase WordsFound currWF; int wfListIndex; bool m_docChanged; - int changeOffset; }; #endif // HUNSPELLDIALOG_H diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp index 61abd38..7af6181 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -177,6 +177,7 @@ bool HunspellPluginImpl::parseTextFrame(PageItem *frameToCheck) wf.replacements=replacements; wf.changed=false; wf.ignore=false; + wf.changeOffset=0; wordsToCorrect.append(wf); } } diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h b/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h index 0515cbb..5b2c8ce 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h @@ -11,6 +11,7 @@ struct WordsFound { QStringList replacements; bool changed; bool ignore; + int changeOffset; }; #endif // HUNSPELLPLUGINSTRUCTS_H |
