Subversion Repositories Scribus

Rev

Rev 17457 | Rev 17485 | 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
 
14
HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, PageItem *frameToCheck)
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;
26
        fTC=frameToCheck;
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;
69
        QString sentence(fTC->itemText.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
        m_docChanged=true;
93
        goToNextWord();
94
}
95
 
96
void HunspellDialog::changeAllWords()
97
{
98
        if(m_wfList->at(wfListIndex).ignore && !m_wfList->at(wfListIndex).changed)
99
                return;
100
        QString wordToChange=m_wfList->at(wfListIndex).w;
101
        //Do we start from 0 or from the instance of the word where we are... 0 for now
102
        for(int i=0;i<m_wfList->count();++i)
103
                if(m_wfList->at(i).w==wordToChange)
17455 craig 104
                        replaceWord(i);
17437 craig 105
        m_docChanged=true;
106
        goToNextWord();
107
}
108
 
109
void HunspellDialog::replaceWord(int i)
110
{
17469 craig 111
        //qDebug()<<"Replacing word"<<i<m_wfList->at(i).w<<m_wfList->at(i).start;
17437 craig 112
        QString newText(suggestionsListWidget->currentItem()->text());
17469 craig 113
        int lengthDiff=fTC->itemText.replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText);
114
        if (lengthDiff!=0)
17437 craig 115
        {
17457 craig 116
                for (int k=i; k<m_wfList->count();++k)
117
                        (*m_wfList)[k].changeOffset+=lengthDiff;
17437 craig 118
        }
17469 craig 119
        (*m_wfList)[i].changed=true;
17437 craig 120
        m_docChanged=true;
121
}