Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cmdsetprop.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "cmdsetprop.h"
00008 #include "cmdutil.h"
00009 #include "scribuscore.h"
00010 
00011 PyObject *scribus_setgradfill(PyObject* /* self */, PyObject* args)
00012 {
00013        char *Name = const_cast<char*>("");
00014        char *Color1;
00015        char *Color2;
00016        int typ, shade1, shade2;
00017        if (!PyArg_ParseTuple(args, "iesiesi|es", &typ, "utf-8", &Color1, &shade1, "utf-8", &Color2, &shade2, "utf-8", &Name))
00018               return NULL;
00019        if(!checkHaveDocument())
00020               return NULL;
00021        PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
00022        if (currItem == NULL)
00023               return NULL;
00024        QColor tmp;
00025        currItem->fill_gradient.clearStops();
00026        QString c1 = QString::fromUtf8(Color1);
00027        QString c2 = QString::fromUtf8(Color2);
00028        currItem->SetFarbe(&tmp, c1, shade1);
00029        currItem->fill_gradient.addStop(tmp, 0.0, 0.5, 1.0, c1, shade1);
00030        currItem->SetFarbe(&tmp, c2, shade2);
00031        currItem->fill_gradient.addStop(tmp, 1.0, 0.5, 1.0, c2, shade2);
00032        currItem->GrType = typ;
00033        switch (currItem->GrType)
00034        {
00035               case 0:
00036               case 1:
00037                      currItem->GrStartX = 0;
00038                      currItem->GrStartY = currItem->height() / 2.0;
00039                      currItem->GrEndX = currItem->width();
00040                      currItem->GrEndY = currItem->height() / 2.0;
00041                      break;
00042               case 2:
00043                      currItem->GrStartX = currItem->width() / 2.0;
00044                      currItem->GrStartY = 0;
00045                      currItem->GrEndX = currItem->width() / 2.0;
00046                      currItem->GrEndY = currItem->height();
00047                      break;
00048               case 3:
00049                      currItem->GrStartX = 0;
00050                      currItem->GrStartY = 0;
00051                      currItem->GrEndX = currItem->width();
00052                      currItem->GrEndY = currItem->height();
00053                      break;
00054               case 4:
00055                      currItem->GrStartX = 0;
00056                      currItem->GrStartY = currItem->height();
00057                      currItem->GrEndX = currItem->width();
00058                      currItem->GrEndY = 0;
00059                      break;
00060               case 5:
00061                      currItem->GrStartX = currItem->width() / 2.0;
00062                      currItem->GrStartY = currItem->height() / 2.0;
00063                      if (currItem->width() >= currItem->height())
00064                      {
00065                             currItem->GrEndX = currItem->width();
00066                             currItem->GrEndY = currItem->height() / 2.0;
00067                      }
00068                      else
00069                      {
00070                             currItem->GrEndX = currItem->width() / 2.0;
00071                             currItem->GrEndY = currItem->height();
00072                      }
00073                      break;
00074               default:
00075                      break;
00076        }
00077        //ScCore->primaryMainWindow()->view->updateGradientVectors(currItem);
00078        currItem->updateGradientVectors();
00079        ScCore->primaryMainWindow()->view->RefreshItem(currItem);
00080 //     Py_INCREF(Py_None);
00081 //     return Py_None;
00082        Py_RETURN_NONE;
00083 }
00084 
00085 PyObject *scribus_setfillcolor(PyObject* /* self */, PyObject* args)
00086 {
00087        char *Name = const_cast<char*>("");
00088        char *Color;
00089        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name))
00090               return NULL;
00091        if(!checkHaveDocument())
00092               return NULL;
00093        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00094        if (i == NULL)
00095               return NULL;
00096        i->setFillColor(QString::fromUtf8(Color));
00097  //    Py_INCREF(Py_None);
00098  //    return Py_None;
00099        Py_RETURN_NONE;
00100 }
00101 
00102 PyObject *scribus_setfilltrans(PyObject* /* self */, PyObject* args)
00103 {
00104        char *Name = const_cast<char*>("");
00105        double w;
00106        if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
00107               return NULL;
00108        if(!checkHaveDocument())
00109               return NULL;
00110        if ((w < 0.0) || (w > 1.0))
00111        {
00112               PyErr_SetString(PyExc_ValueError, QObject::tr("Transparency out of bounds, must be 0 <= transparency <= 1.","python error"));
00113               return NULL;
00114        }
00115        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00116        if (i == NULL)
00117               return NULL;
00118        i->setFillTransparency(1.0 - w);
00119  //    Py_INCREF(Py_None);
00120 //     return Py_None;
00121        Py_RETURN_NONE;
00122 }
00123 
00124 PyObject *scribus_setfillblend(PyObject* /* self */, PyObject* args)
00125 {
00126        char *Name = const_cast<char*>("");
00127        int w;
00128        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00129               return NULL;
00130        if(!checkHaveDocument())
00131               return NULL;
00132        if ((w < 0) || (w > 15))
00133        {
00134               PyErr_SetString(PyExc_ValueError, QObject::tr("Blendmode out of bounds, must be 0 <= blendmode <= 15.","python error"));
00135               return NULL;
00136        }
00137        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00138        if (i == NULL)
00139               return NULL;
00140        i->setFillBlendmode(w);
00141  //    Py_INCREF(Py_None);
00142  //    return Py_None;
00143        Py_RETURN_NONE;
00144 }
00145 
00146 PyObject *scribus_setlinecolor(PyObject* /* self */, PyObject* args)
00147 {
00148        char *Name = const_cast<char*>("");
00149        char *Color;
00150        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name))
00151               return NULL;
00152        if(!checkHaveDocument())
00153               return NULL;
00154        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00155        if (it == NULL)
00156               return NULL;
00157        it->setLineColor(QString::fromUtf8(Color));
00158 //     Py_INCREF(Py_None);
00159 //     return Py_None;
00160        Py_RETURN_NONE;
00161 }
00162 
00163 PyObject *scribus_setlinetrans(PyObject* /* self */, PyObject* args)
00164 {
00165        char *Name = const_cast<char*>("");
00166        double w;
00167        if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
00168               return NULL;
00169        if(!checkHaveDocument())
00170               return NULL;
00171        if ((w < 0.0) || (w > 1.0))
00172        {
00173               PyErr_SetString(PyExc_ValueError, QObject::tr("Transparency out of bounds, must be 0 <= transparency <= 1.","python error"));
00174               return NULL;
00175        }
00176        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00177        if (i == NULL)
00178               return NULL;
00179        i->setLineTransparency(1.0 - w);
00180  //    Py_INCREF(Py_None);
00181  //    return Py_None;
00182        Py_RETURN_NONE;
00183 }
00184 
00185 PyObject *scribus_setlineblend(PyObject* /* self */, PyObject* args)
00186 {
00187        char *Name = const_cast<char*>("");
00188        int w;
00189        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00190               return NULL;
00191        if(!checkHaveDocument())
00192               return NULL;
00193        if ((w < 0) || (w > 15))
00194        {
00195               PyErr_SetString(PyExc_ValueError, QObject::tr("Blendmode out of bounds, must be 0 <= blendmode <= 15.","python error"));
00196               return NULL;
00197        }
00198        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00199        if (i == NULL)
00200               return NULL;
00201        i->setLineBlendmode(w);
00202  //    Py_INCREF(Py_None);
00203 //     return Py_None;
00204        Py_RETURN_NONE;
00205 }
00206 
00207 PyObject *scribus_setlinewidth(PyObject* /* self */, PyObject* args)
00208 {
00209        char *Name = const_cast<char*>("");
00210        double w;
00211        if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
00212               return NULL;
00213        if(!checkHaveDocument())
00214               return NULL;
00215        if ((w < 0.0) || (w > 12.0))
00216        {
00217               PyErr_SetString(PyExc_ValueError, QObject::tr("Line width out of bounds, must be 0 <= line_width <= 12.","python error"));
00218               return NULL;
00219        }
00220        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00221        if (i == NULL)
00222               return NULL;
00223        i->setLineWidth(w);
00224 //     Py_INCREF(Py_None);
00225 //     return Py_None;
00226        Py_RETURN_NONE;
00227 }
00228 
00229 PyObject *scribus_setlineshade(PyObject* /* self */, PyObject* args)
00230 {
00231        char *Name = const_cast<char*>("");
00232        int w;
00233        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00234               return NULL;
00235        if(!checkHaveDocument())
00236               return NULL;
00237        if ((w < 0) || (w > 100))
00238        {
00239               PyErr_SetString(PyExc_ValueError, QObject::tr("Line shade out of bounds, must be 0 <= shade <= 100.","python error"));
00240               return NULL;
00241        }
00242        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00243        if (it == NULL)
00244               return NULL;
00245        it->setLineShade(w);
00246  //    Py_INCREF(Py_None);
00247 //     return Py_None;
00248        Py_RETURN_NONE;
00249 }
00250 
00251 PyObject *scribus_setfillshade(PyObject* /* self */, PyObject* args)
00252 {
00253        char *Name = const_cast<char*>("");
00254        int w;
00255        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00256               return NULL;
00257        if(!checkHaveDocument())
00258               return NULL;
00259        if ((w < 0) || (w > 100))
00260        {
00261               PyErr_SetString(PyExc_ValueError, QObject::tr("Fill shade out of bounds, must be 0 <= shade <= 100.","python error"));
00262               return NULL;
00263        }
00264        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00265        if (i == NULL)
00266               return NULL;
00267        i->setFillShade(w);
00268  //    Py_INCREF(Py_None);
00269 //     return Py_None;
00270        Py_RETURN_NONE;
00271 }
00272 
00273 PyObject *scribus_setlinejoin(PyObject* /* self */, PyObject* args)
00274 {
00275        char *Name = const_cast<char*>("");
00276        int w;
00277        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00278               return NULL;
00279        if(!checkHaveDocument())
00280               return NULL;
00281        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00282        if (i == NULL)
00283               return NULL;
00284        i->PLineJoin = Qt::PenJoinStyle(w);
00285  //    Py_INCREF(Py_None);
00286  //    return Py_None;
00287        Py_RETURN_NONE;
00288 }
00289 
00290 PyObject *scribus_setlineend(PyObject* /* self */, PyObject* args)
00291 {
00292        char *Name = const_cast<char*>("");
00293        int w;
00294        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00295               return NULL;
00296        if(!checkHaveDocument())
00297               return NULL;
00298        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00299        if (i == NULL)
00300               return NULL;
00301        i->PLineEnd = Qt::PenCapStyle(w);
00302 //     Py_INCREF(Py_None);
00303 //     return Py_None;
00304        Py_RETURN_NONE;
00305 }
00306 
00307 PyObject *scribus_setlinestyle(PyObject* /* self */, PyObject* args)
00308 {
00309        char *Name = const_cast<char*>("");
00310        int w;
00311        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00312               return NULL;
00313        if(!checkHaveDocument())
00314               return NULL;
00315        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00316        if (i == NULL)
00317               return NULL;
00318        i->PLineArt = Qt::PenStyle(w);
00319  //    Py_INCREF(Py_None);
00320 //     return Py_None;
00321        Py_RETURN_NONE;
00322 }
00323 
00324 PyObject *scribus_setcornerrad(PyObject* /* self */, PyObject* args)
00325 {
00326        char *Name = const_cast<char*>("");
00327        int w;
00328        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00329               return NULL;
00330        if(!checkHaveDocument())
00331               return NULL;
00332        if (w < 0)
00333        {
00334               PyErr_SetString(PyExc_ValueError, QObject::tr("Corner radius must be a positive number.","python error"));
00335               return NULL;
00336        }
00337        PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
00338        if (currItem == NULL)
00339               return NULL;
00340        // apply rounding
00341        currItem->setCornerRadius(w);
00342        currItem->SetFrameRound();
00343        ScCore->primaryMainWindow()->doc->setRedrawBounding(currItem);
00344        ScCore->primaryMainWindow()->view->SetFrameRounded();
00345  //    Py_INCREF(Py_None);
00346 //     return Py_None;
00347        Py_RETURN_NONE;
00348 }
00349 
00350 PyObject *scribus_setmultiline(PyObject* /* self */, PyObject* args)
00351 {
00352        char *Name = const_cast<char*>("");
00353        char *Style = NULL;
00354        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Style, "utf-8", &Name))
00355               return NULL;
00356        if(!checkHaveDocument())
00357               return NULL;
00358        PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
00359        if (currItem == NULL)
00360               return NULL;
00361        if (!ScCore->primaryMainWindow()->doc->MLineStyles.contains(QString::fromUtf8(Style)))
00362        {
00363               PyErr_SetString(NotFoundError, QObject::tr("Line style not found.","python error"));
00364               return NULL;
00365        }
00366        currItem->NamedLStyle = QString::fromUtf8(Style);
00367  //    Py_INCREF(Py_None);
00368 //     return Py_None;
00369        Py_RETURN_NONE;
00370 }
00371 
00375 void cmdsetpropdocwarnings()
00376 {
00377     QStringList s;
00378     s << scribus_setgradfill__doc__ << scribus_setfillcolor__doc__ << scribus_setfilltrans__doc__  << scribus_setfillblend__doc__  <<  scribus_setlinecolor__doc__  <<  scribus_setlinetrans__doc__  << scribus_setlineblend__doc__  <<  scribus_setlinewidth__doc__  <<  scribus_setlineshade__doc__  << scribus_setlinejoin__doc__  <<  scribus_setlineend__doc__  <<  scribus_setlinestyle__doc__  << scribus_setfillshade__doc__  <<  scribus_setcornerrad__doc__  <<  scribus_setmultiline__doc__;
00379 }