Subversion Repositories Scribus

Rev

Rev 17469 | Rev 17486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17437 craig 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
 
8
#include <QComboBox>
9
#include <QListWidget>
10
#include <QTextEdit>
11
#include "hunspelldialog.h"
12
 
13
 
17485 craig 14
HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iText)
17437 craig 15
{
16
        setupUi( this );
17
        setModal( true );
18
 
19
        connect (ignoreOncePushButton, SIGNAL(clicked()), this, SLOT(goToNextWord()));
20
        connect (ignoreAllPushButton, SIGNAL(clicked()), this, SLOT(ignoreAllWords()));
21
        connect (changePushButton, SIGNAL(clicked()), this, SLOT(changeWord()));
22
        connect (changeAllPushButton, SIGNAL(clicked()), this, SLOT(changeAllWords()));
23
 
24
        m_doc=doc;
25
        m_docChanged=false;
17485 craig 26
        m_Itext=iText;
17437 craig 27
}
28
 
29
void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList<WordsFound> *wfList)
30
{
31
        m_dictEntries=dictEntries;
32
        m_hspellers=hspellers;
33
        m_wfList=wfList;
34
 
35
        languagesComboBox->addItems(*dictEntries);
36
 
37
        wfListIndex=0;
38
        goToNextWord(0);
39
}
40
 
41
void HunspellDialog::goToNextWord(int i)
42
{
43
        if (i>=0)
44
                wfListIndex=i;
45
        else
17455 craig 46
        {
47
                do {
48
                        ++wfListIndex;
49
                } while (wfListIndex<m_wfList->count() && (m_wfList->at(wfListIndex).changed || m_wfList->at(wfListIndex).ignore));
50
                //qDebug()<<"selected word index"<<wfListIndex;
51
        }
17437 craig 52
        if (wfListIndex>=m_wfList->count())
53
        {
54
                statusLabel->setText(tr("Spelling check complete"));
55
                suggestionsListWidget->clear();
56
                sentenceTextEdit->clear();
57
                changePushButton->setEnabled(false);
58
                changeAllPushButton->setEnabled(false);
59
                return;
60
        }
61
        else
62
                statusLabel->setText("");
63
        currWF=m_wfList->at(wfListIndex);
64
        suggestionsListWidget->clear();
65
        suggestionsListWidget->addItems(currWF.replacements);
66
        suggestionsListWidget->setCurrentRow(0);
17469 craig 67
 
68
        int sentencePos=0;
17485 craig 69
        QString sentence(m_Itext->sentence(currWF.start, sentencePos));
17457 craig 70
        sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>");
71
        sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>");
17437 craig 72
        sentenceTextEdit->setText(sentence);
73
 
74
}
75
 
76
void HunspellDialog::ignoreAllWords()
77
{
78
        QString wordToIgnore=m_wfList->at(wfListIndex).w;
79
        //Do we start from 0 or from the instance of the word where we are... 0 for now
80
        for(int i=0;i<m_wfList->count();++i)
81
                if(m_wfList->at(i).w==wordToIgnore)
17455 craig 82
                        (*m_wfList)[i].ignore=true;
17437 craig 83
        goToNextWord();
84
}
85
 
86
void HunspellDialog::changeWord()
87
{
17455 craig 88
        //If we have ignored a word or its already changed, skip to the next.
89
        if(m_wfList->at(wfListIndex).ignore || m_wfList->at(wfListIndex).changed)
17437 craig 90
                goToNextWord();
91
        replaceWord(wfListIndex);
92
        goToNextWord();
93
}
94
 
95
void HunspellDialog::changeAllWords()
96
{
97
        if(m_wfList->at(wfListIndex).ignore && !m_wfList->at(wfListIndex).changed)
98
                return;
99
        QString wordToChange=m_wfList->at(wfListIndex).w;
100
        //Do we start from 0 or from the instance of the word where we are... 0 for now
101
        for(int i=0;i<m_wfList->count();++i)
102
                if(m_wfList->at(i).w==wordToChange)
17455 craig 103
                        replaceWord(i);
17437 craig 104
        goToNextWord();
105
}
106
 
107
void HunspellDialog::replaceWord(int i)
108
{
17469 craig 109
        //qDebug()<<"Replacing word"<<i<m_wfList->at(i).w<<m_wfList->at(i).start;
17437 craig 110
        QString newText(suggestionsListWidget->currentItem()->text());
17485 craig 111
        int lengthDiff=m_Itext->replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText);
17469 craig 112
        if (lengthDiff!=0)
17437 craig 113
        {
17457 craig 114
                for (int k=i; k<m_wfList->count();++k)
115
                        (*m_wfList)[k].changeOffset+=lengthDiff;
17437 craig 116
        }
17469 craig 117
        (*m_wfList)[i].changed=true;
17437 craig 118
        m_docChanged=true;
119
}