Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
4430 cbradney 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
*/
104 Franz 7
#include "cmdcolor.h"
8
#include "cmdutil.h"
2834 cbradney 9
#include "prefsmanager.h"
4546 subik 10
#include "commonstrings.h"
5781 cbradney 11
#include "scribuscore.h"
7478 jghali 12
#include "sccolorengine.h"
82 Franz 13
 
2790 craig 14
PyObject *scribus_colornames(PyObject* /* self */)
82 Franz 15
{
1065 cbradney 16
        ColorList edc;
82 Franz 17
        PyObject *l;
18
        int cc = 0;
5781 cbradney 19
        edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
1065 cbradney 20
        ColorList::Iterator it;
82 Franz 21
        l = PyList_New(edc.count());
22
        for (it = edc.begin(); it != edc.end(); ++it)
900 cbradney 23
        {
899 cbradney 24
                PyList_SetItem(l, cc, PyString_FromString(it.key().utf8()));
82 Franz 25
                cc++;
900 cbradney 26
        }
82 Franz 27
        return l;
28
}
29
 
2790 craig 30
PyObject *scribus_getcolor(PyObject* /* self */, PyObject* args)
82 Franz 31
{
1065 cbradney 32
        ColorList edc;
934 subik 33
        char *Name = const_cast<char*>("");
82 Franz 34
        int c, m, y, k;
899 cbradney 35
        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
82 Franz 36
                return NULL;
899 cbradney 37
        if (strcmp(Name, "") == 0)
38
        {
1525 cbradney 39
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error"));
899 cbradney 40
                return NULL;
41
        }
5781 cbradney 42
        edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
9621 jghali 43
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL;
899 cbradney 44
        QString col = QString::fromUtf8(Name);
82 Franz 45
        if (!edc.contains(col))
899 cbradney 46
        {
1971 mrdocs 47
                PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
899 cbradney 48
                return NULL;
49
        }
9621 jghali 50
        CMYKColor cmykValues;
51
        ScColorEngine::getCMYKValues(edc[col], currentDoc, cmykValues);
52
        cmykValues.getValues(c, m, y, k);
82 Franz 53
        return Py_BuildValue("(iiii)", static_cast<long>(c), static_cast<long>(m), static_cast<long>(y), static_cast<long>(k));
54
}
55
 
2790 craig 56
PyObject *scribus_getcolorasrgb(PyObject* /* self */, PyObject* args)
1517 craig 57
{
58
        ColorList edc;
59
        char *Name = const_cast<char*>("");
60
        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
61
                return NULL;
62
        if (strcmp(Name, "") == 0)
63
        {
1525 cbradney 64
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error"));
1517 craig 65
                return NULL;
66
        }
5781 cbradney 67
        edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
7478 jghali 68
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL;
1517 craig 69
        QString col = QString::fromUtf8(Name);
70
        if (!edc.contains(col))
71
        {
1971 mrdocs 72
                PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
1517 craig 73
                return NULL;
74
        }
7478 jghali 75
        QColor rgb = ScColorEngine::getRGBColor(edc[col], currentDoc);
1517 craig 76
        return Py_BuildValue("(iii)", static_cast<long>(rgb.red()), static_cast<long>(rgb.green()), static_cast<long>(rgb.blue()));
77
}
78
 
2790 craig 79
PyObject *scribus_setcolor(PyObject* /* self */, PyObject* args)
82 Franz 80
{
934 subik 81
        char *Name = const_cast<char*>("");
82 Franz 82
        int c, m, y, k;
899 cbradney 83
        if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k))
82 Franz 84
                return NULL;
899 cbradney 85
        if (strcmp(Name, "") == 0)
720 subik 86
        {
1525 cbradney 87
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot change a color with an empty name.","python error"));
720 subik 88
                return NULL;
89
        }
899 cbradney 90
        QString col = QString::fromUtf8(Name);
5781 cbradney 91
        if (ScCore->primaryMainWindow()->HaveDoc)
332 Franz 92
        {
5781 cbradney 93
                if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col))
720 subik 94
                {
1971 mrdocs 95
                        PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error"));
720 subik 96
                        return NULL;
97
                }
5781 cbradney 98
                ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k);
332 Franz 99
        }
82 Franz 100
        else
332 Franz 101
        {
2871 cbradney 102
                ColorList* colorList=PrefsManager::instance()->colorSetPtr();
103
                if (!colorList->contains(col))
720 subik 104
                {
1971 mrdocs 105
                        PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error"));
720 subik 106
                        return NULL;
107
                }
2871 cbradney 108
                (*colorList)[col].setColor(c, m, y, k);
332 Franz 109
        }
8319 fschmid 110
//      Py_INCREF(Py_None);
111
//      return Py_None;
8306 cbradney 112
        Py_RETURN_NONE;
82 Franz 113
}
114
 
2790 craig 115
PyObject *scribus_newcolor(PyObject* /* self */, PyObject* args)
82 Franz 116
{
934 subik 117
        char *Name = const_cast<char*>("");
82 Franz 118
        int c, m, y, k;
899 cbradney 119
        if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k))
82 Franz 120
                return NULL;
899 cbradney 121
        if (strcmp(Name, "") == 0)
720 subik 122
        {
1525 cbradney 123
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot create a color with an empty name.","python error"));
720 subik 124
                return NULL;
125
        }
899 cbradney 126
        QString col = QString::fromUtf8(Name);
5781 cbradney 127
        if (ScCore->primaryMainWindow()->HaveDoc)
82 Franz 128
                {
5781 cbradney 129
                        if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col))
130
                                ScCore->primaryMainWindow()->doc->PageColors.insert(col, ScColor(c, m, y, k));
720 subik 131
                        else
132
                                // FIXME: Given that we have a changeColour function, should we really be
133
                                // silently changing colours in newColour?
5781 cbradney 134
                                ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k);
82 Franz 135
                }
136
        else
137
                {
2871 cbradney 138
                        ColorList* colorList=PrefsManager::instance()->colorSetPtr();
139
                        if (!colorList->contains(col))
2886 fschmid 140
                                colorList->insert(col, ScColor(c, m, y, k));
720 subik 141
                        else
142
                                // FIXME: Given that we have a changeColour function, should we really be
143
                                // silently changing colours in newColour?
2871 cbradney 144
                                (*colorList)[col].setColor(c, m, y, k);
82 Franz 145
                }
8319 fschmid 146
 //     Py_INCREF(Py_None);
147
 //     return Py_None;
8306 cbradney 148
        Py_RETURN_NONE;
82 Franz 149
}
150
 
2790 craig 151
PyObject *scribus_delcolor(PyObject* /* self */, PyObject* args)
82 Franz 152
{
934 subik 153
        char *Name = const_cast<char*>("");
4546 subik 154
        char *Repl = const_cast<char*>(CommonStrings::None.latin1());
899 cbradney 155
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl))
82 Franz 156
                return NULL;
8306 cbradney 157
        if (strcmp(Name, "") == 0)
720 subik 158
        {
1525 cbradney 159
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot delete a color with an empty name.","python error"));
720 subik 160
                return NULL;
161
        }
899 cbradney 162
        QString col = QString::fromUtf8(Name);
163
        QString rep = QString::fromUtf8(Repl);
5781 cbradney 164
        if (ScCore->primaryMainWindow()->HaveDoc)
720 subik 165
        {
5781 cbradney 166
                if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None)))
82 Franz 167
                        {
5781 cbradney 168
                                ScCore->primaryMainWindow()->doc->PageColors.remove(col);
720 subik 169
                                ReplaceColor(col, rep);
82 Franz 170
                        }
899 cbradney 171
                else
172
                {
1971 mrdocs 173
                        PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error"));
899 cbradney 174
                        return NULL;
175
                }
720 subik 176
        }
82 Franz 177
        else
720 subik 178
        {
2871 cbradney 179
                ColorList* colorList=PrefsManager::instance()->colorSetPtr();
180
                if (colorList->contains(col))
181
                        colorList->remove(col);
899 cbradney 182
                else
183
                {
1971 mrdocs 184
                        PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error"));
899 cbradney 185
                        return NULL;
186
                }
720 subik 187
        }
8319 fschmid 188
//      Py_INCREF(Py_None);
189
//      return Py_None;
8306 cbradney 190
        Py_RETURN_NONE;
82 Franz 191
}
192
 
2790 craig 193
PyObject *scribus_replcolor(PyObject* /* self */, PyObject* args)
82 Franz 194
{
934 subik 195
        char *Name = const_cast<char*>("");
4546 subik 196
        char *Repl = const_cast<char*>(CommonStrings::None.latin1());
720 subik 197
        //FIXME: this should definitely use keyword arguments
899 cbradney 198
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl))
82 Franz 199
                return NULL;
720 subik 200
        if(!checkHaveDocument())
201
                return NULL;
899 cbradney 202
        if (strcmp(Name, "") == 0)
720 subik 203
        {
1525 cbradney 204
                PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot replace a color with an empty name.","python error"));
720 subik 205
                return NULL;
206
        }
899 cbradney 207
        QString col = QString::fromUtf8(Name);
208
        QString rep = QString::fromUtf8(Repl);
5781 cbradney 209
        if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None)))
82 Franz 210
                ReplaceColor(col, rep);
899 cbradney 211
        else
212
        {
1971 mrdocs 213
                PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
899 cbradney 214
                return NULL;
215
        }
8319 fschmid 216
//      Py_INCREF(Py_None);
217
//      return Py_None;
8306 cbradney 218
        Py_RETURN_NONE;
82 Franz 219
}
6200 subik 220
 
221
/*! HACK: this removes "warning: 'blash' defined but not used" compiler warnings
222
with header files structure untouched (docstrings are kept near declarations)
223
PV */
224
void cmdcolordocswarnings()
225
{
226
    QStringList s;
227
    s << scribus_colornames__doc__ << scribus_getcolor__doc__ << scribus_getcolorasrgb__doc__;
228
    s << scribus_setcolor__doc__ << scribus_newcolor__doc__ << scribus_delcolor__doc__;
229
    s << scribus_replcolor__doc__;
230
}