Subversion Repositories Scribus

Rev

Rev 23054 | 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
 
24736 jghali 27
#include <memory>
28
 
11895 fschmid 29
#include "replacecolors.h"
30
#include "replaceonecolor.h"
31
#include "commonstrings.h"
11904 fschmid 32
#include "sccolorengine.h"
33
#include "util_color.h"
20185 craig 34
#include "iconmanager.h"
11895 fschmid 35
#include <QHeaderView>
36
 
37
replaceColorsDialog::replaceColorsDialog(QWidget* parent, ColorList &colorList, ColorList &colorListUsed) : QDialog(parent)
38
{
39
        setupUi(this);
40
        setModal(true);
23054 craig 41
        setWindowIcon(IconManager::instance().loadPixmap("AppIcon.png"));
11895 fschmid 42
        EditColors = colorList;
43
        UsedColors = colorListUsed;
44
        replaceMap.clear();
23054 craig 45
        alertIcon = IconManager::instance().loadPixmap("alert.png", true);
46
        cmykIcon = IconManager::instance().loadPixmap("cmyk.png", true);
47
        rgbIcon = IconManager::instance().loadPixmap("rgb.png", true);
48
        labIcon = IconManager::instance().loadPixmap("lab.png", true);
49
        spotIcon = IconManager::instance().loadPixmap("spot.png", true);
50
        regIcon = IconManager::instance().loadPixmap("register.png", true);
18194 fschmid 51
        replacementTable->horizontalHeader()->setSectionsClickable(false );
52
        replacementTable->horizontalHeader()->setSectionsMovable( false );
53
        replacementTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
11895 fschmid 54
        replacementTable->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Original")));
55
        replacementTable->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Replacement")));
18194 fschmid 56
        replacementTable->verticalHeader()->setSectionsMovable( false );
57
        replacementTable->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
11895 fschmid 58
        replacementTable->verticalHeader()->hide();
11904 fschmid 59
        replacementTable->setIconSize(QSize(60, 15));
11895 fschmid 60
        updateReplacementTable();
61
        removeButton->setEnabled(false);
62
        connect(addButton, SIGNAL(clicked()), this, SLOT(addColor()));
63
        connect(replacementTable, SIGNAL(cellClicked(int, int)), this, SLOT(selReplacement(int)));
64
        connect(removeButton, SIGNAL(clicked()), this, SLOT(delReplacement()));
12162 fschmid 65
        connect(editButton, SIGNAL(clicked()), this, SLOT(editReplacement()));
11895 fschmid 66
}
67
 
68
void replaceColorsDialog::addColor()
69
{
24736 jghali 70
        std::unique_ptr<replaceColorDialog> dia(new replaceColorDialog(this, EditColors, UsedColors));
71
        if (!dia->exec())
72
                return;
73
 
74
        QString orig = dia->getOriginalColor();
75
        if (orig == CommonStrings::tr_NoneColor)
76
                orig = CommonStrings::None;
77
        QString repl = dia->getReplacementColor();
78
        if (repl == CommonStrings::tr_NoneColor)
79
                repl = CommonStrings::None;
80
        replaceMap.insert(orig, repl);
81
        updateReplacementTable();
11895 fschmid 82
}
83
 
84
void replaceColorsDialog::selReplacement(int sel)
85
{
86
        selectedRow = sel;
87
        removeButton->setEnabled(true);
12162 fschmid 88
        editButton->setEnabled(true);
11895 fschmid 89
}
90
 
91
void replaceColorsDialog::delReplacement()
92
{
93
        if (selectedRow > -1)
94
        {
95
                replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
96
                replacementTable->removeRow(selectedRow);
97
                selectedRow = -1;
11896 fschmid 98
                removeButton->setEnabled(false);
12162 fschmid 99
                editButton->setEnabled(false);
11895 fschmid 100
        }
101
}
102
 
12162 fschmid 103
void replaceColorsDialog::editReplacement()
104
{
24736 jghali 105
        if (selectedRow < 0)
106
                return;
107
 
108
        std::unique_ptr<replaceColorDialog> dia(new replaceColorDialog(this, EditColors, UsedColors));
109
        dia->setReplacementColor(replacementTable->item(selectedRow, 1)->text());
110
        dia->setOriginalColor(replacementTable->item(selectedRow, 0)->text());
111
        if (!dia->exec())
112
                return;
113
 
114
        replaceMap.remove(replacementTable->item(selectedRow, 0)->text());
115
        QString orig = dia->getOriginalColor();
116
        if (orig == CommonStrings::tr_NoneColor)
117
                orig = CommonStrings::None;
118
        QString repl = dia->getReplacementColor();
119
        if (repl == CommonStrings::tr_NoneColor)
120
                repl = CommonStrings::None;
121
        replaceMap.insert(orig, repl);
122
        updateReplacementTable();
12162 fschmid 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
 
24736 jghali 158
QPixmap replaceColorsDialog::getColorIcon(const QString& color) const
11904 fschmid 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);
21654 jghali 178
        else if (m_color.getColorModel() == colorModelRGB)
11904 fschmid 179
                paintAlert(rgbIcon, pPixmap, 30, 0);
21654 jghali 180
        else if (m_color.getColorModel() == colorModelLab)
181
                paintAlert(labIcon, pPixmap, 30, 0);
11904 fschmid 182
        if (m_color.isSpotColor())
183
                paintAlert(spotIcon, pPixmap, 45, 0);
184
        if (m_color.isRegistrationColor())
185
                paintAlert(regIcon, pPixmap, 46, 0);
186
        return pPixmap;
187
}