Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
13761 cbradney 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
*/
14437 cbradney 7
#include <QInputDialog>
8
#include <QListWidget>
17501 craig 9
#include <QDebug>
13761 cbradney 10
 
11
#include "prefs_hyphenator.h"
14437 cbradney 12
#include "langmgr.h"
13
#include "prefsstructs.h"
14
#include "scribuscore.h" //FIXME: for the ScCore call (remove this call)
15021 cbradney 15
#include "scribusdoc.h"
14437 cbradney 16
#include "scribus.h" //FIXME: for the ScCore call (remove this call)
17
#include "util_icon.h"
18
#include "util.h"
13761 cbradney 19
 
15021 cbradney 20
Prefs_Hyphenator::Prefs_Hyphenator(QWidget* parent, ScribusDoc* doc)
14437 cbradney 21
        : Prefs_Pane(parent)
13761 cbradney 22
{
23
        setupUi(this);
14437 cbradney 24
        LanguageManager *lmg(LanguageManager::instance());
25
        hyphLanguageComboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
26
        foreach(QString hlang, lmg->hyphLangs())
27
        {
28
                hyphLanguageComboBox->addItem( lmg->getLangFromAbbrev(hlang), lmg->getLangFromAbbrev(hlang,false) );
29
        }
13761 cbradney 30
 
14437 cbradney 31
        exceptionAddButton->setIcon(QIcon(loadIcon("16/list-add.png")));
32
        exceptionEditButton->setEnabled(false);
33
        exceptionRemoveButton->setIcon(QIcon(loadIcon("16/list-remove.png")));
34
        exceptionRemoveButton->setEnabled(false);
35
        ignoreAddButton->setIcon(QIcon(loadIcon("16/list-add.png")));
36
        ignoreEditButton->setEnabled(false);
37
        ignoreRemoveButton->setIcon(QIcon(loadIcon("16/list-remove.png")));
38
        ignoreRemoveButton->setEnabled(false);
39
        connect(ignoreAddButton, SIGNAL(clicked()), this, SLOT(addToIgnoreList()));
40
        connect(ignoreEditButton, SIGNAL(clicked()), this, SLOT(editIgnoreListEntry()));
41
        connect(ignoreRemoveButton, SIGNAL(clicked()), this, SLOT(removeIgnoreListEntry()));
42
        connect(ignoreListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableIgnoreButtons()));
43
        connect(exceptionAddButton, SIGNAL(clicked()), this, SLOT(addToExceptList()));
44
        connect(exceptionEditButton, SIGNAL(clicked()), this, SLOT(editExceptListEntry()));
45
        connect(exceptionRemoveButton, SIGNAL(clicked()), this, SLOT(removeExceptListEntry()));
46
        connect(exceptionListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableExceptButtons()));
13761 cbradney 47
}
48
 
49
Prefs_Hyphenator::~Prefs_Hyphenator()
50
{
51
}
52
 
14437 cbradney 53
void Prefs_Hyphenator::languageChange()
54
{
55
}
56
 
57
void Prefs_Hyphenator::restoreDefaults(struct ApplicationPrefs *prefsData)
58
{
59
        hyphSuggestionsCheckBox->setChecked(!prefsData->hyphPrefs.Automatic);
60
        hyphAutoCheckBox->setChecked(prefsData->hyphPrefs.AutoCheck);
17501 craig 61
        setCurrentComboItem(hyphLanguageComboBox, LanguageManager::instance()->getLangFromAbbrev(prefsData->hyphPrefs.Language, true));
14437 cbradney 62
        smallestWordSpinBox->setValue(prefsData->hyphPrefs.MinWordLen);
63
        maxConsecutiveCountSpinBox->setValue(prefsData->hyphPrefs.HyCount);
64
        ignoreListWidget->addItems(prefsData->hyphPrefs.ignoredWords.toList());
65
        ignoreListWidget->sortItems();
66
        exceptionListWidget->addItems(prefsData->hyphPrefs.specialWords.values());
67
        exceptionListWidget->sortItems();
68
}
69
 
70
void Prefs_Hyphenator::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
71
{
72
        prefsData->hyphPrefs.MinWordLen = smallestWordSpinBox->value();
73
         //FIXME: remove this ScCore call
17501 craig 74
        QString langFromCombo(ScCore->primaryMainWindow()->GetLang(hyphLanguageComboBox->itemData(hyphLanguageComboBox->currentIndex()).toString()));
75
        prefsData->hyphPrefs.Language = LanguageManager::instance()->getAbbrevFromLang(langFromCombo, true, false);
14437 cbradney 76
        prefsData->hyphPrefs.Automatic = !hyphSuggestionsCheckBox->isChecked();
77
        prefsData->hyphPrefs.AutoCheck = hyphAutoCheckBox->isChecked();
78
        prefsData->hyphPrefs.HyCount = maxConsecutiveCountSpinBox->value();
79
        QSet<QString> ignoreList;
80
        for (int row = 0; row < ignoreListWidget->count(); row++)
81
        {
82
                ignoreList.insert(ignoreListWidget->item(row)->text());
83
        }
84
        prefsData->hyphPrefs.ignoredWords = ignoreList;
85
        QHash<QString, QString> exceptionList;
86
        for (int row = 0; row < exceptionListWidget->count(); row++)
87
        {
88
                exceptionList.insert(exceptionListWidget->item(row)->text().remove("-"), exceptionListWidget->item(row)->text());
89
        }
90
        prefsData->hyphPrefs.specialWords = exceptionList;
91
}
92
 
93
void Prefs_Hyphenator::addToIgnoreList()
94
{
95
        bool ok;
96
        QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
97
        if ((ok) && (!text.isEmpty()))
98
        {
99
                if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
100
                        ignoreListWidget->addItem(text);
101
                ignoreListWidget->sortItems();
102
        }
103
}
104
 
105
void Prefs_Hyphenator::editIgnoreListEntry()
106
{
107
        bool ok;
108
        QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Edit Entry"), QLineEdit::Normal, ignoreListWidget->currentItem()->text(), &ok);
109
        if ((ok) && (!text.isEmpty()))
110
        {
111
                if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
112
                        ignoreListWidget->currentItem()->setText(text);
113
                ignoreListWidget->sortItems();
114
        }
115
}
116
 
117
void Prefs_Hyphenator::removeIgnoreListEntry()
118
{
119
        QListWidgetItem *item = ignoreListWidget->takeItem(ignoreListWidget->row(ignoreListWidget->currentItem()));
120
        delete item;
121
        if (ignoreListWidget->count() == 0)
122
        {
123
                ignoreEditButton->setEnabled(false);
124
                ignoreRemoveButton->setEnabled(false);
125
        }
126
}
127
 
128
void Prefs_Hyphenator::enableIgnoreButtons()
129
{
130
        ignoreEditButton->setEnabled(true);
131
        ignoreRemoveButton->setEnabled(true);
132
}
133
 
134
void Prefs_Hyphenator::addToExceptList()
135
{
136
        bool ok;
137
        QString text = QInputDialog::getText(this, tr("Exception List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
138
        if ((ok) && (!text.isEmpty()))
139
        {
140
                if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
141
                        exceptionListWidget->addItem(text);
142
                exceptionListWidget->sortItems();
143
        }
144
}
145
 
146
void Prefs_Hyphenator::editExceptListEntry()
147
{
148
        bool ok;
149
        QString text = QInputDialog::getText(this, tr("Exception List"), tr("Edit Entry"), QLineEdit::Normal, exceptionListWidget->currentItem()->text(), &ok);
150
        if ((ok) && (!text.isEmpty()))
151
        {
152
                if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
153
                        exceptionListWidget->currentItem()->setText(text);
154
                exceptionListWidget->sortItems();
155
        }
156
}
157
 
158
void Prefs_Hyphenator::removeExceptListEntry()
159
{
160
        QListWidgetItem *item = exceptionListWidget->takeItem(exceptionListWidget->row(exceptionListWidget->currentItem()));
161
        delete item;
162
        if (exceptionListWidget->count() == 0)
163
        {
164
                exceptionEditButton->setEnabled(false);
165
                exceptionRemoveButton->setEnabled(false);
166
        }
167
}
168
 
169
void Prefs_Hyphenator::enableExceptButtons()
170
{
171
        exceptionEditButton->setEnabled(true);
172
        exceptionRemoveButton->setEnabled(true);
173
}