Subversion Repositories Scribus

Rev

Rev 13544 | Rev 18194 | Go to most recent revision | 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.,                                       *
18122 mrdocs 24
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
11895 fschmid 25
***************************************************************************/
26
 
27
#include "replacecolors.h"
28
#include "replaceonecolor.h"
29
#include "commonstrings.h"
11904 fschmid 30
#include "sccolorengine.h"
31
#include "util_color.h"
11895 fschmid 32
#include "util_icon.h"
33
#include <QHeaderView>
34
 
35
replaceColorsDialog::replaceColorsDialog(QWidget* parent, ColorList &colorList, ColorList &colorListUsed) : QDialog(parent)
36
{
37
        setupUi(this);
38
        setModal(true);
39
        setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
40
        EditColors = colorList;
41
        UsedColors = colorListUsed;
42
        selectedRow = -1;
43
        replaceMap.clear();
11904 fschmid 44
        alertIcon = loadIcon("alert.png", true);
45
        cmykIcon = loadIcon("cmyk.png", true);
46
        rgbIcon = loadIcon("rgb.png", true);
47
        spotIcon = loadIcon("spot.png", true);
48
        regIcon = loadIcon("register.png", true);
11895 fschmid 49
        replacementTable->horizontalHeader()->setMovable(false);
50
        replacementTable->horizontalHeader()->setClickable(false);
51
        replacementTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
52
        replacementTable->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Original")));
53
        replacementTable->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Replacement")));
54
        replacementTable->verticalHeader()->setMovable(false);
55
        replacementTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
56
        replacementTable->verticalHeader()->hide();
11904 fschmid 57
        replacementTable->setIconSize(QSize(60, 15));
11895 fschmid 58
        updateReplacementTable();
59
        removeButton->setEnabled(false);
60
        connect(addButton, SIGNAL(clicked()), this, SLOT(addColor()));
61
        connect(replacementTable, SIGNAL(cellClicked(int, int)), this, SLOT(selReplacement(int)));
62
        connect(removeButton, SIGNAL(clicked()), this, SLOT(delReplacement()));
12162 fschmid 63
        connect(editButton, SIGNAL(clicked()), this, SLOT(editReplacement()));
11895 fschmid 64
}
65
 
66
void replaceColorsDialog::addColor()
67
{
68
        replaceColorDialog *dia = new replaceColorDialog(this, EditColors, UsedColors);
69
        if (dia->exec())
70
        {
71
                QString orig = dia->getOriginalColor();
72
                if (orig == CommonStrings::tr_NoneColor)
73
                        orig = CommonStrings::None;
74
                QString repl = dia->getReplacementColor();
75
                if (repl == CommonStrings::tr_NoneColor)
76
                        repl = CommonStrings::None;
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);
12162 fschmid 87
        editButton->setEnabled(true);
11895 fschmid 88
}
89
 
90
void replaceColorsDialog::delReplacement()
91
{
92
        if (selectedRow > -1)
93
        {
94
                replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
95
                replacementTable->removeRow(selectedRow);
96
                selectedRow = -1;
11896 fschmid 97
                removeButton->setEnabled(false);
12162 fschmid 98
                editButton->setEnabled(false);
11895 fschmid 99
        }
100
}
101
 
12162 fschmid 102
void replaceColorsDialog::editReplacement()
103
{
104
        if (selectedRow > -1)
105
        {
106
                replaceColorDialog *dia = new replaceColorDialog(this, EditColors, UsedColors);
107
                dia->setReplacementColor(replacementTable->item(selectedRow, 1)->text());
108
                dia->setOriginalColor(replacementTable->item(selectedRow, 0)->text());
109
                if (dia->exec())
110
                {
111
                        replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
112
                        QString orig = dia->getOriginalColor();
113
                        if (orig == CommonStrings::tr_NoneColor)
114
                                orig = CommonStrings::None;
115
                        QString repl = dia->getReplacementColor();
116
                        if (repl == CommonStrings::tr_NoneColor)
117
                                repl = CommonStrings::None;
118
                        replaceMap.insert(orig, repl);
119
                        updateReplacementTable();
120
                }
121
                delete dia;
122
        }
123
}
124
 
11895 fschmid 125
void replaceColorsDialog::updateReplacementTable()
126
{
127
        replacementTable->clearContents();
128
        replacementTable->setRowCount(0);
129
        selectedRow = -1;
130
        removeButton->setEnabled(false);
12162 fschmid 131
        editButton->setEnabled(false);
11895 fschmid 132
        if (replaceMap.count() > 0)
133
        {
134
                replacementTable->setRowCount(replaceMap.count());
135
                int row = 0;
136
                QMap<QString,QString>::Iterator it;
137
                for (it = replaceMap.begin(); it != replaceMap.end(); ++it)
138
                {
11904 fschmid 139
                        QTableWidgetItem *tW;
140
                        if (it.key() == CommonStrings::None)
11913 fschmid 141
                                tW = new QTableWidgetItem(CommonStrings::tr_NoneColor);
11904 fschmid 142
                        else
143
                                tW = new QTableWidgetItem(getColorIcon(it.key()), it.key());
11895 fschmid 144
                        tW->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
145
                        replacementTable->setItem(row, 0, tW);
11904 fschmid 146
                        QTableWidgetItem *tW2;
147
                        if (it.value() == CommonStrings::None)
11913 fschmid 148
                                tW2 = new QTableWidgetItem(CommonStrings::tr_NoneColor);
11904 fschmid 149
                        else
150
                                tW2 = new QTableWidgetItem(getColorIcon(it.value()), it.value());
12186 fschmid 151
                        tW2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
11895 fschmid 152
                        replacementTable->setItem(row, 1, tW2);
153
                        row++;
154
                }
155
        }
156
}
11904 fschmid 157
 
158
QPixmap replaceColorsDialog::getColorIcon(QString color)
159
{
160
        QPixmap smallPix(15, 15);
161
        QPixmap pPixmap(60,15);
162
        pPixmap.fill(Qt::transparent);
163
        ScColor m_color = EditColors[color];
164
        QColor rgb = ScColorEngine::getDisplayColor(m_color, EditColors.document());
165
        smallPix.fill(rgb);
166
        QPainter painter(&smallPix);
167
        painter.setBrush(Qt::NoBrush);
168
        QPen b(Qt::black, 1);
169
        painter.setPen(b);
170
        painter.drawRect(0, 0, 15, 15);
171
        painter.end();
172
        paintAlert(smallPix, pPixmap, 0, 0);
173
        bool isOutOfGamut = ScColorEngine::isOutOfGamut(m_color, EditColors.document());
174
        if (isOutOfGamut)
175
                paintAlert(alertIcon, pPixmap, 15, 0);
176
        if (m_color.getColorModel() == colorModelCMYK)
177
                paintAlert(cmykIcon, pPixmap, 30, 0);
178
        else
179
                paintAlert(rgbIcon, pPixmap, 30, 0);
180
        if (m_color.isSpotColor())
181
                paintAlert(spotIcon, pPixmap, 45, 0);
182
        if (m_color.isRegistrationColor())
183
                paintAlert(regIcon, pPixmap, 46, 0);
184
        return pPixmap;
185
}