Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Functions
cmdcolor.cpp File Reference
#include "cmdcolor.h"
#include "cmdutil.h"
#include "prefsmanager.h"
#include "commonstrings.h"
#include "scribuscore.h"
#include "sccolorengine.h"

Go to the source code of this file.

Functions

PyObject * scribus_colornames (PyObject *)
 Returns a list with colours available in doc or in prefs.
PyObject * scribus_getcolor (PyObject *, PyObject *args)
 Returns a CMYK tuple of the specified color.
PyObject * scribus_getcolorasrgb (PyObject *, PyObject *args)
 Returns a CMYK tuple of the specified color.
PyObject * scribus_setcolor (PyObject *, PyObject *args)
 Sets named color with C,M,Y,K params.
PyObject * scribus_newcolor (PyObject *, PyObject *args)
 Creates new color with name, C, M, Y, K params.
PyObject * scribus_delcolor (PyObject *, PyObject *args)
 Deletes named color.
PyObject * scribus_replcolor (PyObject *, PyObject *args)
 Replaces color with the 2nd one.
void cmdcolordocswarnings ()
 HACK: this removes "warning: 'blash' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Function Documentation

HACK: this removes "warning: 'blash' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Definition at line 224 of file cmdcolor.cpp.

{
    QStringList s;
    s << scribus_colornames__doc__ << scribus_getcolor__doc__ << scribus_getcolorasrgb__doc__;
    s << scribus_setcolor__doc__ << scribus_newcolor__doc__ << scribus_delcolor__doc__;
    s << scribus_replcolor__doc__;
}
PyObject* scribus_colornames ( PyObject *  )

Returns a list with colours available in doc or in prefs.

Definition at line 14 of file cmdcolor.cpp.

{
       ColorList edc;
       PyObject *l;
       int cc = 0;
       edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
       ColorList::Iterator it;
       l = PyList_New(edc.count());
       for (it = edc.begin(); it != edc.end(); ++it)
       {
              PyList_SetItem(l, cc, PyString_FromString(it.key().utf8()));
              cc++;
       }
       return l;
}

Here is the call graph for this function:

PyObject* scribus_delcolor ( PyObject *  ,
PyObject *  args 
)

Deletes named color.

Definition at line 151 of file cmdcolor.cpp.

{
       char *Name = const_cast<char*>("");
       char *Repl = const_cast<char*>(CommonStrings::None.latin1());
       if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl))
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot delete a color with an empty name.","python error"));
              return NULL;
       }
       QString col = QString::fromUtf8(Name);
       QString rep = QString::fromUtf8(Repl);
       if (ScCore->primaryMainWindow()->HaveDoc)
       {
              if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None)))
                     {
                            ScCore->primaryMainWindow()->doc->PageColors.remove(col);
                            ReplaceColor(col, rep);
                     }
              else
              {
                     PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error"));
                     return NULL;
              }
       }
       else
       {
              ColorList* colorList=PrefsManager::instance()->colorSetPtr();
              if (colorList->contains(col))
                     colorList->remove(col);
              else
              {
                     PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error"));
                     return NULL;
              }
       }
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_getcolor ( PyObject *  ,
PyObject *  args 
)

Returns a CMYK tuple of the specified color.

Definition at line 30 of file cmdcolor.cpp.

{
       ColorList edc;
       char *Name = const_cast<char*>("");
       int c, m, y, k;
       if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error"));
              return NULL;
       }
       edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
       ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL;
       QString col = QString::fromUtf8(Name);
       if (!edc.contains(col))
       {
              PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
              return NULL;
       }
       CMYKColor cmykValues;
       ScColorEngine::getCMYKValues(edc[col], currentDoc, cmykValues);
       cmykValues.getValues(c, m, y, k);
       return Py_BuildValue("(iiii)", static_cast<long>(c), static_cast<long>(m), static_cast<long>(y), static_cast<long>(k));
}

Here is the call graph for this function:

PyObject* scribus_getcolorasrgb ( PyObject *  ,
PyObject *  args 
)

Returns a CMYK tuple of the specified color.

Definition at line 56 of file cmdcolor.cpp.

{
       ColorList edc;
       char *Name = const_cast<char*>("");
       if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error"));
              return NULL;
       }
       edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet();
       ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL;
       QString col = QString::fromUtf8(Name);
       if (!edc.contains(col))
       {
              PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
              return NULL;
       }
       QColor rgb = ScColorEngine::getRGBColor(edc[col], currentDoc);
       return Py_BuildValue("(iii)", static_cast<long>(rgb.red()), static_cast<long>(rgb.green()), static_cast<long>(rgb.blue()));
}

Here is the call graph for this function:

PyObject* scribus_newcolor ( PyObject *  ,
PyObject *  args 
)

Creates new color with name, C, M, Y, K params.

Definition at line 115 of file cmdcolor.cpp.

{
       char *Name = const_cast<char*>("");
       int c, m, y, k;
       if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k))
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot create a color with an empty name.","python error"));
              return NULL;
       }
       QString col = QString::fromUtf8(Name);
       if (ScCore->primaryMainWindow()->HaveDoc)
              {
                     if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col))
                            ScCore->primaryMainWindow()->doc->PageColors.insert(col, ScColor(c, m, y, k));
                     else
                            // FIXME: Given that we have a changeColour function, should we really be
                            // silently changing colours in newColour?
                            ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k);
              }
       else
              {
                     ColorList* colorList=PrefsManager::instance()->colorSetPtr();
                     if (!colorList->contains(col))
                            colorList->insert(col, ScColor(c, m, y, k));
                     else
                            // FIXME: Given that we have a changeColour function, should we really be
                            // silently changing colours in newColour?
                            (*colorList)[col].setColor(c, m, y, k);
              }
 //    Py_INCREF(Py_None);
 //    return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_replcolor ( PyObject *  ,
PyObject *  args 
)

Replaces color with the 2nd one.

Definition at line 193 of file cmdcolor.cpp.

{
       char *Name = const_cast<char*>("");
       char *Repl = const_cast<char*>(CommonStrings::None.latin1());
       //FIXME: this should definitely use keyword arguments
       if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot replace a color with an empty name.","python error"));
              return NULL;
       }
       QString col = QString::fromUtf8(Name);
       QString rep = QString::fromUtf8(Repl);
       if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None)))
              ReplaceColor(col, rep);
       else
       {
              PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error"));
              return NULL;
       }
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_setcolor ( PyObject *  ,
PyObject *  args 
)

Sets named color with C,M,Y,K params.

Definition at line 79 of file cmdcolor.cpp.

{
       char *Name = const_cast<char*>("");
       int c, m, y, k;
       if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k))
              return NULL;
       if (strcmp(Name, "") == 0)
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot change a color with an empty name.","python error"));
              return NULL;
       }
       QString col = QString::fromUtf8(Name);
       if (ScCore->primaryMainWindow()->HaveDoc)
       {
              if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col))
              {
                     PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error"));
                     return NULL;
              }
              ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k);
       }
       else
       {
              ColorList* colorList=PrefsManager::instance()->colorSetPtr();
              if (!colorList->contains(col))
              {
                     PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error"));
                     return NULL;
              }
              (*colorList)[col].setColor(c, m, y, k);
       }
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function: