~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/replacecolors.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2009-02-09 09:25:18 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090209092518-iqsxmh3pjspgrdyd
Tags: 1.3.5.dfsg~svn20090208-2
debian/control: Use "type-handling -n arm,armel,armeb any" to generate the
list of architectures to build on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "sccolorengine.h"
 
31
#include "util_color.h"
 
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();
 
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()));
 
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);
 
87
        editButton->setEnabled(true);
 
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;
 
97
                removeButton->setEnabled(false);
 
98
                editButton->setEnabled(false);
 
99
        }
 
100
}
 
101
 
 
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
 
 
125
void replaceColorsDialog::updateReplacementTable()
 
126
{
 
127
        replacementTable->clearContents();
 
128
        replacementTable->setRowCount(0);
 
129
        selectedRow = -1;
 
130
        removeButton->setEnabled(false);
 
131
        editButton->setEnabled(false);
 
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
                {
 
139
                        QTableWidgetItem *tW;
 
140
                        if (it.key() == CommonStrings::None)
 
141
                                tW = new QTableWidgetItem(CommonStrings::tr_NoneColor);
 
142
                        else
 
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);
 
149
                        else
 
150
                                tW2 = new QTableWidgetItem(getColorIcon(it.value()), it.value());
 
151
                        tW2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 
152
                        replacementTable->setItem(row, 1, tW2);
 
153
                        row++;
 
154
                }
 
155
        }
 
156
}
 
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
}