Subversion Repositories Scribus

Rev

Rev 11895 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11895 fschmid 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
*   Copyright (C) 2008 by Franz Schmid                                    *
9
*   franz.schmid@altmuehlnet.de                                           *
10
*                                                                         *
11
*   This program is free software; you can redistribute it and/or modify  *
12
*   it under the terms of the GNU General Public License as published by  *
13
*   the Free Software Foundation; either version 2 of the License, or     *
14
*   (at your option) any later version.                                   *
15
*                                                                         *
16
*   This program is distributed in the hope that it will be useful,       *
17
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
*   GNU General Public License for more details.                          *
20
*                                                                         *
21
*   You should have received a copy of the GNU General Public License     *
22
*   along with this program; if not, write to the                         *
23
*   Free Software Foundation, Inc.,                                       *
24
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
25
***************************************************************************/
26
 
27
#include "replacecolors.h"
28
#include "replaceonecolor.h"
29
#include "commonstrings.h"
30
#include "util_icon.h"
31
#include <QHeaderView>
32
 
33
replaceColorsDialog::replaceColorsDialog(QWidget* parent, ColorList &colorList, ColorList &colorListUsed) : QDialog(parent)
34
{
35
        setupUi(this);
36
        setModal(true);
37
        setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
38
        EditColors = colorList;
39
        UsedColors = colorListUsed;
40
        selectedRow = -1;
41
        replaceMap.clear();
42
        replacementTable->horizontalHeader()->setMovable(false);
43
        replacementTable->horizontalHeader()->setClickable(false);
44
        replacementTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
45
        replacementTable->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Original")));
46
        replacementTable->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Replacement")));
47
        replacementTable->verticalHeader()->setMovable(false);
48
        replacementTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
49
        replacementTable->verticalHeader()->hide();
50
        updateReplacementTable();
51
        removeButton->setEnabled(false);
52
        connect(addButton, SIGNAL(clicked()), this, SLOT(addColor()));
53
        connect(replacementTable, SIGNAL(cellClicked(int, int)), this, SLOT(selReplacement(int)));
54
        connect(removeButton, SIGNAL(clicked()), this, SLOT(delReplacement()));
55
}
56
 
57
void replaceColorsDialog::addColor()
58
{
59
        replaceColorDialog *dia = new replaceColorDialog(this, EditColors, UsedColors);
60
        if (dia->exec())
61
        {
62
                QString orig = dia->getOriginalColor();
63
                if (orig == CommonStrings::tr_NoneColor)
64
                        orig = CommonStrings::None;
65
                QString repl = dia->getReplacementColor();
66
                if (repl == CommonStrings::tr_NoneColor)
67
                        repl = CommonStrings::None;
68
                if (replaceMap.values().contains(orig))
69
                {
70
                        QMap<QString,QString>::Iterator it;
71
                        for (it = replaceMap.begin(); it != replaceMap.end(); ++it)
72
                        {
73
                                if (it.value() == orig)
74
                                        it.value() = repl;
75
                        }
76
                }
77
                replaceMap.insert(orig, repl);
78
                updateReplacementTable();
79
        }
80
        delete dia;
81
}
82
 
83
void replaceColorsDialog::selReplacement(int sel)
84
{
85
        selectedRow = sel;
86
        removeButton->setEnabled(true);
87
}
88
 
89
void replaceColorsDialog::delReplacement()
90
{
91
        if (selectedRow > -1)
92
        {
93
                replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
94
                replacementTable->removeRow(selectedRow);
95
                selectedRow = -1;
11896 fschmid 96
                removeButton->setEnabled(false);
11895 fschmid 97
        }
98
}
99
 
100
void replaceColorsDialog::updateReplacementTable()
101
{
102
        replacementTable->clearContents();
103
        replacementTable->setRowCount(0);
104
        selectedRow = -1;
105
        removeButton->setEnabled(false);
106
        if (replaceMap.count() > 0)
107
        {
108
                replacementTable->setRowCount(replaceMap.count());
109
                int row = 0;
110
                QMap<QString,QString>::Iterator it;
111
                for (it = replaceMap.begin(); it != replaceMap.end(); ++it)
112
                {
113
                        QTableWidgetItem *tW = new QTableWidgetItem(it.key());
114
                        tW->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
115
                        replacementTable->setItem(row, 0, tW);
116
                        QTableWidgetItem *tW2 = new QTableWidgetItem(it.value());
117
                        tW->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
118
                        replacementTable->setItem(row, 1, tW2);
119
                        row++;
120
                }
121
        }
122
}