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.
7
/**************************************************************************
8
* Copyright (C) 2008 by Franz Schmid *
9
* franz.schmid@altmuehlnet.de *
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. *
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. *
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
***************************************************************************/
27
#include "replacecolors.h"
28
#include "replaceonecolor.h"
29
#include "commonstrings.h"
30
#include "sccolorengine.h"
31
#include "util_color.h"
32
#include "util_icon.h"
33
#include <QHeaderView>
35
replaceColorsDialog::replaceColorsDialog(QWidget* parent, ColorList &colorList, ColorList &colorListUsed) : QDialog(parent)
39
setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
40
EditColors = colorList;
41
UsedColors = colorListUsed;
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);
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();
57
replacementTable->setIconSize(QSize(60, 15));
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()));
63
connect(editButton, SIGNAL(clicked()), this, SLOT(editReplacement()));
66
void replaceColorsDialog::addColor()
68
replaceColorDialog *dia = new replaceColorDialog(this, EditColors, UsedColors);
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();
83
void replaceColorsDialog::selReplacement(int sel)
86
removeButton->setEnabled(true);
87
editButton->setEnabled(true);
90
void replaceColorsDialog::delReplacement()
94
replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
95
replacementTable->removeRow(selectedRow);
97
removeButton->setEnabled(false);
98
editButton->setEnabled(false);
102
void replaceColorsDialog::editReplacement()
104
if (selectedRow > -1)
106
replaceColorDialog *dia = new replaceColorDialog(this, EditColors, UsedColors);
107
dia->setReplacementColor(replacementTable->item(selectedRow, 1)->text());
108
dia->setOriginalColor(replacementTable->item(selectedRow, 0)->text());
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();
125
void replaceColorsDialog::updateReplacementTable()
127
replacementTable->clearContents();
128
replacementTable->setRowCount(0);
130
removeButton->setEnabled(false);
131
editButton->setEnabled(false);
132
if (replaceMap.count() > 0)
134
replacementTable->setRowCount(replaceMap.count());
136
QMap<QString,QString>::Iterator it;
137
for (it = replaceMap.begin(); it != replaceMap.end(); ++it)
139
QTableWidgetItem *tW;
140
if (it.key() == CommonStrings::None)
141
tW = new QTableWidgetItem(CommonStrings::tr_NoneColor);
143
tW = new QTableWidgetItem(getColorIcon(it.key()), it.key());
144
tW->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
145
replacementTable->setItem(row, 0, tW);
146
QTableWidgetItem *tW2;
147
if (it.value() == CommonStrings::None)
148
tW2 = new QTableWidgetItem(CommonStrings::tr_NoneColor);
150
tW2 = new QTableWidgetItem(getColorIcon(it.value()), it.value());
151
tW2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
152
replacementTable->setItem(row, 1, tW2);
158
QPixmap replaceColorsDialog::getColorIcon(QString color)
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());
166
QPainter painter(&smallPix);
167
painter.setBrush(Qt::NoBrush);
168
QPen b(Qt::black, 1);
170
painter.drawRect(0, 0, 15, 15);
172
paintAlert(smallPix, pPixmap, 0, 0);
173
bool isOutOfGamut = ScColorEngine::isOutOfGamut(m_color, EditColors.document());
175
paintAlert(alertIcon, pPixmap, 15, 0);
176
if (m_color.getColorModel() == colorModelCMYK)
177
paintAlert(cmykIcon, pPixmap, 30, 0);
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);