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
*/
103 Franz 7
#include "cmdobj.h"
8
#include "cmdutil.h"
3934 cbradney 9
#include "selection.h"
2529 craig 10
#include "util.h"
4546 subik 11
#include "commonstrings.h"
5781 cbradney 12
#include "scribuscore.h"
740 fschmid 13
 
3934 cbradney 14
 
2790 craig 15
PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
82 Franz 16
{
4520 subik 17
        double x, y, w, h;
934 subik 18
        char *Name = const_cast<char*>("");
4520 subik 19
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 20
                return NULL;
649 fschmid 21
        if(!checkHaveDocument())
22
                return NULL;
900 cbradney 23
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 24
        {
1525 cbradney 25
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 26
                return NULL;
27
        }
5781 cbradney 28
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Rectangle,
4520 subik 29
                                                                pageUnitXToDocX(x), pageUnitYToDocY(y),
30
                                                                ValueToPoint(w), ValueToPoint(h),
5781 cbradney 31
                                                                ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
32
                                                                ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
33
        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
2879 cbradney 34
        if (Name != "")
5781 cbradney 35
                ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
36
        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
82 Franz 37
}
38
 
243 Franz 39
 
2790 craig 40
PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args)
82 Franz 41
{
4520 subik 42
        double x, y, w, h;
934 subik 43
        char *Name = const_cast<char*>("");
4520 subik 44
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 45
                return NULL;
649 fschmid 46
        if(!checkHaveDocument())
47
                return NULL;
5781 cbradney 48
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Ellipse,
4520 subik 49
                                                                                pageUnitXToDocX(x),
50
                                                                                pageUnitYToDocY(y),
51
                                                                                ValueToPoint(w),
52
                                                                                ValueToPoint(h),
5781 cbradney 53
                                                                                ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
54
                                                                                ScCore->primaryMainWindow()->doc->toolSettings.dBrush,
55
                                                                                ScCore->primaryMainWindow()->doc->toolSettings.dPen,
3690 cbradney 56
                                                                                true);
900 cbradney 57
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 58
        {
1525 cbradney 59
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 60
                return NULL;
61
        }
5781 cbradney 62
        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
2879 cbradney 63
        if (Name != "")
5781 cbradney 64
                ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
65
        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
82 Franz 66
}
67
 
243 Franz 68
 
2790 craig 69
PyObject *scribus_newimage(PyObject* /* self */, PyObject* args)
82 Franz 70
{
3292 cbradney 71
        double x, y, w, h;
934 subik 72
        char *Name = const_cast<char*>("");
3292 cbradney 73
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 74
                return NULL;
649 fschmid 75
        if(!checkHaveDocument())
76
                return NULL;
5781 cbradney 77
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified,
4520 subik 78
                                                                        pageUnitXToDocX(x),
79
                                                                        pageUnitYToDocY(y),
80
                                                                        ValueToPoint(w),
81
                                                                        ValueToPoint(h),
5781 cbradney 82
                                                                        1, ScCore->primaryMainWindow()->doc->toolSettings.dBrushPict,
4546 subik 83
                                                                        CommonStrings::None, true);
900 cbradney 84
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 85
        {
1525 cbradney 86
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 87
                return NULL;
88
        }
5781 cbradney 89
        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
2879 cbradney 90
        if (Name != "")
5781 cbradney 91
                ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
92
        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
82 Franz 93
}
94
 
243 Franz 95
 
2790 craig 96
PyObject *scribus_newtext(PyObject* /* self */, PyObject* args)
82 Franz 97
{
4520 subik 98
        double x, y, w, h;
934 subik 99
        char *Name = const_cast<char*>("");
4520 subik 100
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 101
                return NULL;
649 fschmid 102
        if(!checkHaveDocument())
103
                return NULL;
5781 cbradney 104
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified,
4520 subik 105
                                                                pageUnitXToDocX(x),
106
                                                                pageUnitYToDocY(y),
107
                                                                ValueToPoint(w),
108
                                                                ValueToPoint(h),
5781 cbradney 109
                                                                ScCore->primaryMainWindow()->doc->toolSettings.dWidth, CommonStrings::None,
110
                                                                ScCore->primaryMainWindow()->doc->toolSettings.dPenText, true);
900 cbradney 111
        if (ItemExists(QString::fromUtf8(Name)))
332 Franz 112
        {
1525 cbradney 113
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 114
                return NULL;
332 Franz 115
        }
5781 cbradney 116
        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
2879 cbradney 117
        if (Name != "")
5781 cbradney 118
                ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
119
        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
82 Franz 120
}
121
 
2790 craig 122
PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
82 Franz 123
{
4520 subik 124
        double x, y, w, h;
934 subik 125
        char *Name = const_cast<char*>("");
4520 subik 126
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 127
                return NULL;
649 fschmid 128
        if(!checkHaveDocument())
129
                return NULL;
2029 craig 130
        x = pageUnitXToDocX(x);
1283 subik 131
        y = pageUnitYToDocY(y);
4520 subik 132
        w = pageUnitXToDocX(w);
1283 subik 133
        h = pageUnitYToDocY(h);
900 cbradney 134
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 135
        {
5332 subik 136
                PyErr_SetString(NameExistsError,
137
                                                QObject::tr("An object with the requested name already exists.",
138
                                                                        "python error"));
720 subik 139
                return NULL;
140
        }
5781 cbradney 141
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Line, PageItem::Unspecified,
5332 subik 142
                                                           x, y, w, h,
5781 cbradney 143
                                                           ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
144
                                                           ScCore->primaryMainWindow()->doc->toolSettings.dBrush,
145
                                                           ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
146
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i);
5332 subik 147
        it->setRotation(xy2Deg(w-x, h-y));
148
        it->setWidthHeight(sqrt(pow(x-w, 2.0) + pow(y-h, 2.0)), 1.0);
149
        it->Sizing = false;
150
        it->updateClip();
5781 cbradney 151
        ScCore->primaryMainWindow()->doc->setRedrawBounding(it);
5332 subik 152
/* WTF? maybe I'll examine who's author later. Or maybe I'll remove it later ;)
82 Franz 153
        it->PoLine.resize(4);
154
        it->PoLine.setPoint(0, 0, 0);
155
        it->PoLine.setPoint(1, 0, 0);
4520 subik 156
        it->PoLine.setPoint(2, w-x, h-y);
157
        it->PoLine.setPoint(3, w-x, h-y);
1065 cbradney 158
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 159
        if (np2.x() < 0)
647 fschmid 160
        {
82 Franz 161
                it->PoLine.translate(-np2.x(), 0);
5781 cbradney 162
                ScCore->primaryMainWindow()->view->MoveItem(np2.x(), 0, it);
647 fschmid 163
        }
82 Franz 164
        if (np2.y() < 0)
647 fschmid 165
        {
82 Franz 166
                it->PoLine.translate(0, -np2.y());
5781 cbradney 167
                ScCore->primaryMainWindow()->view->MoveItem(0, np2.y(), it);
647 fschmid 168
        }
5781 cbradney 169
        ScCore->primaryMainWindow()->view->SizeItem(it->PoLine.WidthHeight().x(),
5332 subik 170
                                                 it->PoLine.WidthHeight().y(), i, false, false, false);
5781 cbradney 171
        ScCore->primaryMainWindow()->view->AdjustItemSize(it);*/
2879 cbradney 172
        if (Name != "")
1361 tsoots 173
                it->setItemName(QString::fromUtf8(Name));
174
        return PyString_FromString(it->itemName().utf8());
82 Franz 175
}
176
 
243 Franz 177
 
2790 craig 178
PyObject *scribus_polyline(PyObject* /* self */, PyObject* args)
82 Franz 179
{
934 subik 180
        char *Name = const_cast<char*>("");
82 Franz 181
        PyObject *il;
900 cbradney 182
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
183
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 184
                return NULL;
649 fschmid 185
        if(!checkHaveDocument())
186
                return NULL;
87 Franz 187
        int len = PyList_Size(il);
720 subik 188
        if (len < 4)
189
        {
1525 cbradney 190
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error"));
720 subik 191
                return NULL;
192
        }
193
        if ((len % 2) != 0)
194
        {
1525 cbradney 195
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 196
                return NULL;
197
        }
900 cbradney 198
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 199
        {
1525 cbradney 200
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 201
                return NULL;
202
        }
4520 subik 203
        double x, y, w, h;
237 Franz 204
        int i = 0;
1283 subik 205
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 206
        i++;
1283 subik 207
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 208
        i++;
5781 cbradney 209
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
210
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 211
        it->PoLine.resize(2);
212
        it->PoLine.setPoint(0, 0, 0);
213
        it->PoLine.setPoint(1, 0, 0);
87 Franz 214
        int pp = 6;
82 Franz 215
        for (i = 2; i < len - 2; i += 2)
647 fschmid 216
        {
4520 subik 217
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 218
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 219
                it->PoLine.resize(pp);
4520 subik 220
                it->PoLine.setPoint(pp-4, w-x, h-y);
221
                it->PoLine.setPoint(pp-3, w-x, h-y);
222
                it->PoLine.setPoint(pp-2, w-x, h-y);
223
                it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 224
                pp += 4;
647 fschmid 225
        }
82 Franz 226
        pp -= 2;
4520 subik 227
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
1283 subik 228
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 229
        it->PoLine.resize(pp);
4520 subik 230
        it->PoLine.setPoint(pp-2, w-x, h-y);
231
        it->PoLine.setPoint(pp-1, w-x, h-y);
1065 cbradney 232
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 233
        if (np2.x() < 0)
647 fschmid 234
        {
82 Franz 235
                it->PoLine.translate(-np2.x(), 0);
7736 cbradney 236
                ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
647 fschmid 237
        }
82 Franz 238
        if (np2.y() < 0)
647 fschmid 239
        {
82 Franz 240
                it->PoLine.translate(0, -np2.y());
7736 cbradney 241
                ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
647 fschmid 242
        }
7736 cbradney 243
        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
244
        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
2879 cbradney 245
        if (Name != "")
720 subik 246
        {
1361 tsoots 247
                it->setItemName(QString::fromUtf8(Name));
720 subik 248
        }
1361 tsoots 249
        return PyString_FromString(it->itemName().utf8());
82 Franz 250
}
251
 
243 Franz 252
 
2790 craig 253
PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
82 Franz 254
{
934 subik 255
        char *Name = const_cast<char*>("");
82 Franz 256
        PyObject *il;
900 cbradney 257
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
258
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 259
                return NULL;
649 fschmid 260
        if(!checkHaveDocument())
261
                return NULL;
87 Franz 262
        int len = PyList_Size(il);
720 subik 263
        if (len < 6)
264
        {
1525 cbradney 265
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error"));
720 subik 266
                return NULL;
267
        }
268
        if ((len % 2) != 0)
269
        {
1525 cbradney 270
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 271
                return NULL;
272
        }
900 cbradney 273
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 274
        {
1525 cbradney 275
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 276
                return NULL;
277
        }
4520 subik 278
        double x, y, w, h;
237 Franz 279
        int i = 0;
1283 subik 280
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 281
        i++;
1283 subik 282
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 283
        i++;
5781 cbradney 284
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1,        ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
285
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 286
        it->PoLine.resize(2);
287
        it->PoLine.setPoint(0, 0, 0);
288
        it->PoLine.setPoint(1, 0, 0);
87 Franz 289
        int pp = 6;
82 Franz 290
        for (i = 2; i < len - 2; i += 2)
647 fschmid 291
        {
4520 subik 292
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 293
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 294
                it->PoLine.resize(pp);
4520 subik 295
                it->PoLine.setPoint(pp-4, w-x, h-y);
296
                it->PoLine.setPoint(pp-3, w-x, h-y);
297
                it->PoLine.setPoint(pp-2, w-x, h-y);
298
                it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 299
                pp += 4;
647 fschmid 300
        }
4520 subik 301
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
1283 subik 302
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 303
        it->PoLine.resize(pp);
4520 subik 304
        it->PoLine.setPoint(pp-4, w-x, h-y);
305
        it->PoLine.setPoint(pp-3, w-x, h-y);
306
        it->PoLine.setPoint(pp-2, w-x, h-y);
307
        it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 308
        pp += 2;
309
        it->PoLine.resize(pp);
310
        it->PoLine.setPoint(pp-2, 0, 0);
311
        it->PoLine.setPoint(pp-1, 0, 0);
1065 cbradney 312
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 313
        if (np2.x() < 0)
647 fschmid 314
        {
82 Franz 315
                it->PoLine.translate(-np2.x(), 0);
7736 cbradney 316
                ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
647 fschmid 317
        }
82 Franz 318
        if (np2.y() < 0)
647 fschmid 319
        {
82 Franz 320
                it->PoLine.translate(0, -np2.y());
7736 cbradney 321
                ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
647 fschmid 322
        }
7736 cbradney 323
        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
324
        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
2879 cbradney 325
        if (Name != "")
1361 tsoots 326
                it->setItemName(QString::fromUtf8(Name));
327
        return PyString_FromString(it->itemName().utf8());
82 Franz 328
}
329
 
2790 craig 330
PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
82 Franz 331
{
934 subik 332
        char *Name = const_cast<char*>("");
82 Franz 333
        PyObject *il;
900 cbradney 334
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
335
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 336
                return NULL;
649 fschmid 337
        if(!checkHaveDocument())
338
                return NULL;
87 Franz 339
        int len = PyList_Size(il);
720 subik 340
        if (len < 8)
341
        {
1525 cbradney 342
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error"));
720 subik 343
                return NULL;
344
        }
345
        if ((len % 6) != 0)
346
        {
1525 cbradney 347
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error"));
720 subik 348
                return NULL;
349
        }
900 cbradney 350
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 351
        {
1525 cbradney 352
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 353
                return NULL;
354
        }
4520 subik 355
        double x, y, w, h, kx, ky, kx2, ky2;
237 Franz 356
        int i = 0;
1283 subik 357
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 358
        i++;
1283 subik 359
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 360
        i++;
1283 subik 361
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 362
        i++;
1283 subik 363
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 364
        i++;
1283 subik 365
        kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 366
        i++;
1283 subik 367
        ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 368
        i++;
5781 cbradney 369
        //int ic = ScCore->primaryMainWindow()->view->PaintPolyLine(x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen);
370
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
371
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 372
        it->PoLine.resize(2);
373
        it->PoLine.setPoint(0, 0, 0);
374
        it->PoLine.setPoint(1, kx-x, ky-y);
87 Franz 375
        int pp = 6;
82 Franz 376
        for (i = 6; i < len - 6; i += 6)
647 fschmid 377
        {
4520 subik 378
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 379
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
380
                kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
381
                ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
382
                kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
383
                ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
82 Franz 384
                it->PoLine.resize(pp);
4520 subik 385
                it->PoLine.setPoint(pp-4, w-x, h-y);
82 Franz 386
                it->PoLine.setPoint(pp-3, kx-x, ky-y);
387
                it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
388
                it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
389
                pp += 4;
647 fschmid 390
        }
82 Franz 391
        pp -= 2;
4520 subik 392
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
1283 subik 393
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
394
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
395
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
82 Franz 396
        it->PoLine.resize(pp);
4520 subik 397
        it->PoLine.setPoint(pp-2, w-x, h-y);
82 Franz 398
        it->PoLine.setPoint(pp-1, kx-x, ky-y);
1065 cbradney 399
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 400
        if (np2.x() < 0)
647 fschmid 401
        {
82 Franz 402
                it->PoLine.translate(-np2.x(), 0);
7736 cbradney 403
                ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
647 fschmid 404
        }
82 Franz 405
        if (np2.y() < 0)
647 fschmid 406
        {
82 Franz 407
                it->PoLine.translate(0, -np2.y());
7736 cbradney 408
                ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
647 fschmid 409
        }
7736 cbradney 410
        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
411
        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
2879 cbradney 412
        if (Name != "")
1361 tsoots 413
                it->setItemName(QString::fromUtf8(Name));
414
        return PyString_FromString(it->itemName().utf8());
82 Franz 415
}
416
 
243 Franz 417
 
418
/* 03/31/2004 - xception handling
419
 */
2790 craig 420
PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args)
82 Franz 421
{
422
        double x, y;
934 subik 423
        char *Name = const_cast<char*>("");
424
        char *TextB = const_cast<char*>("");
425
        char *PolyB = const_cast<char*>("");
900 cbradney 426
        if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
82 Franz 427
                return NULL;
649 fschmid 428
        if(!checkHaveDocument())
429
                return NULL;
900 cbradney 430
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 431
        {
1525 cbradney 432
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 433
                return NULL;
434
        }
435
        //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
436
        // its sets for us?
900 cbradney 437
        int i = GetItem(QString::fromUtf8(TextB));
438
        int ii = GetItem(QString::fromUtf8(PolyB));
82 Franz 439
        if ((i == -1) || (ii == -1))
243 Franz 440
        {
1525 cbradney 441
                PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error"));
243 Franz 442
                return NULL;
443
        }
5781 cbradney 444
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
445
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(i));
446
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(ii));
447
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i);
448
        ScCore->primaryMainWindow()->view->ToPathText();
7736 cbradney 449
        ScCore->primaryMainWindow()->doc->MoveItem(pageUnitXToDocX(x) - it->xPos(), pageUnitYToDocY(y) - it->yPos(), it);
2879 cbradney 450
        if (Name != "")
1361 tsoots 451
                it->setItemName(QString::fromUtf8(Name));
452
        return PyString_FromString(it->itemName().utf8());
82 Franz 453
}
454
 
243 Franz 455
 
237 Franz 456
/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
457
 */
2790 craig 458
PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args)
82 Franz 459
{
934 subik 460
        char *Name = const_cast<char*>("");
900 cbradney 461
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
82 Franz 462
                return NULL;
649 fschmid 463
        if(!checkHaveDocument())
464
                return NULL;
900 cbradney 465
        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
720 subik 466
        if (i == NULL)
332 Franz 467
                return NULL;
5781 cbradney 468
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
469
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
470
        ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem();
8319 fschmid 471
//      Py_INCREF(Py_None);
472
//      return Py_None;
473
        Py_RETURN_NONE;
82 Franz 474
}
475
 
243 Franz 476
 
237 Franz 477
/* 03/21/2004 - exception raises by non existent name (subik)
478
 */
2790 craig 479
PyObject *scribus_textflow(PyObject* /* self */, PyObject* args)
214 Franz 480
{
934 subik 481
        char *name = const_cast<char*>("");
332 Franz 482
        int state = -1;
214 Franz 483
 
900 cbradney 484
        if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
214 Franz 485
                return NULL;
649 fschmid 486
        if(!checkHaveDocument())
487
                return NULL;
900 cbradney 488
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
332 Franz 489
        if (i == NULL)
237 Franz 490
                return NULL;
214 Franz 491
        if (state == -1)
5620 jghali 492
        {
493
                if (i->textFlowAroundObject())
494
                        i->setTextFlowMode(PageItem::TextFlowDisabled);
495
                else
496
                        i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
497
        }
498
        else if( state == (int) PageItem::TextFlowDisabled )
499
                i->setTextFlowMode(PageItem::TextFlowDisabled);
500
        else if( state == (int) PageItem::TextFlowUsesFrameShape )
501
                i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
502
        else if( state == (int) PageItem::TextFlowUsesBoundingBox )
503
                i->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
504
        else if( state == (int) PageItem::TextFlowUsesContourLine )
505
                i->setTextFlowMode(PageItem::TextFlowUsesContourLine);
5781 cbradney 506
        ScCore->primaryMainWindow()->view->DrawNew();
507
        ScCore->primaryMainWindow()->slotDocCh(true);
8319 fschmid 508
//      Py_INCREF(Py_None);
509
//      return Py_None;
510
        Py_RETURN_NONE;
214 Franz 511
}
243 Franz 512
 
513
 
2790 craig 514
PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
243 Franz 515
{
934 subik 516
        char* name = const_cast<char*>("");
900 cbradney 517
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
243 Franz 518
                return NULL;
649 fschmid 519
        if(!checkHaveDocument())
520
                return NULL;
900 cbradney 521
        if (ItemExists(QString::fromUtf8(name)))
720 subik 522
                return PyBool_FromLong(static_cast<long>(true));
523
        return PyBool_FromLong(static_cast<long>(false));
243 Franz 524
}
525
 
411 Franz 526
/*
527
 * Craig Ringer, 2004-09-09
528
 * Apply the named style to the currently selected object.
529
 * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
530
 */
2790 craig 531
PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args)
411 Franz 532
{
934 subik 533
        char *style = const_cast<char*>("");
534
        char *name = const_cast<char*>("");
900 cbradney 535
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
411 Franz 536
                return NULL;
649 fschmid 537
        if(!checkHaveDocument())
538
                return NULL;
900 cbradney 539
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
720 subik 540
        if (item == NULL)
541
                return NULL;
1460 cbradney 542
        if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText))
411 Franz 543
        {
3718 cbradney 544
                // First, find the style number associated with the requested style
545
                // by scanning through the styles looking for the name. If
546
                // we can't find it, raise PyExc_Exception.
547
                // FIXME: Should use a more specific exception.
411 Franz 548
                bool found = false;
549
                uint styleid = 0;
550
                // We start at zero here because it's OK to match an internal name
7442 avox 551
                uint docParagraphStylesCount=ScCore->primaryMainWindow()->doc->paragraphStyles().count();
3718 cbradney 552
                for (uint i=0; i < docParagraphStylesCount; ++i)
411 Franz 553
                {
7442 avox 554
                        if (ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name() == QString::fromUtf8(style)) {
411 Franz 555
                                found = true;
556
                                styleid = i;
557
                                break;
558
                        }
559
                }
560
                if (!found) {
561
                        // whoops, the user specified an invalid style, complain loudly.
1525 cbradney 562
                        PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error"));
411 Franz 563
                        return NULL;
564
                }
3748 subik 565
                // for current item only
5781 cbradney 566
                if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0 || name != "")
3748 subik 567
                {
568
                        // quick hack to always apply on the right frame - pv
5781 cbradney 569
                        ScCore->primaryMainWindow()->view->Deselect(true);
3748 subik 570
                        //CB I dont think we need to draw here. Its faster if we dont.
5781 cbradney 571
                        ScCore->primaryMainWindow()->view->SelectItem(item, false);
3748 subik 572
                        // Now apply the style.
5781 cbradney 573
                        int mode = ScCore->primaryMainWindow()->doc->appMode;
574
                        ScCore->primaryMainWindow()->doc->appMode = modeEdit;
9063 avox 575
                        ScCore->primaryMainWindow()->setNewParStyle(QString::fromUtf8(style));
5781 cbradney 576
                        ScCore->primaryMainWindow()->doc->appMode = mode;
3748 subik 577
                }
578
                else // for multiple selection
579
                {
5781 cbradney 580
                        int mode = ScCore->primaryMainWindow()->doc->appMode;
6733 avox 581
                        ScCore->primaryMainWindow()->doc->appMode = modeNormal;
7442 avox 582
                        ScCore->primaryMainWindow()->doc->itemSelection_ApplyParagraphStyle(ScCore->primaryMainWindow()->doc->paragraphStyles()[styleid]);
5781 cbradney 583
                        ScCore->primaryMainWindow()->doc->appMode = mode;
3748 subik 584
                }
411 Franz 585
        }
720 subik 586
        else
587
        {
1525 cbradney 588
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error"));
720 subik 589
                return NULL;
590
        }
8319 fschmid 591
//      Py_INCREF(Py_None);
592
//      return Py_None;
593
        Py_RETURN_NONE;
411 Franz 594
}
595
 
596
/*
597
 * Craig Ringer, 2004-09-09
598
 * Enumerate all known paragraph styles
599
 */
2790 craig 600
PyObject *scribus_getstylenames(PyObject* /* self */)
411 Franz 601
{
602
        PyObject *styleList;
649 fschmid 603
        if(!checkHaveDocument())
604
                return NULL;
411 Franz 605
        styleList = PyList_New(0);
7442 avox 606
        for (uint i=0; i < ScCore->primaryMainWindow()->doc->paragraphStyles().count(); ++i)
411 Franz 607
        {
7442 avox 608
                if (PyList_Append(styleList, PyString_FromString(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name().utf8())))
411 Franz 609
                {
610
                        // An exception will have already been set by PyList_Append apparently.
611
                        return NULL;
612
                }
613
        }
614
        return styleList;
615
}
5997 subik 616
 
617
PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args)
618
{
619
        char* name = const_cast<char*>("");
620
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
621
                return NULL;
622
        }
623
        if(!checkHaveDocument()) {
624
                return NULL;
625
        }
626
        // Is there a special name given? Yes -> add this to selection
627
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
628
        if (i != NULL) {
629
                ScCore->primaryMainWindow()->doc->m_Selection->clear();
630
                ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
631
        }
5998 subik 632
        else
633
                return NULL;
5997 subik 634
        // do the duplicate
635
        ScCore->primaryMainWindow()->slotEditCopy();
636
        ScCore->primaryMainWindow()->slotEditPaste();
8319 fschmid 637
//      Py_INCREF(Py_None);
638
//      return Py_None;
639
        Py_RETURN_NONE;
5997 subik 640
}
6200 subik 641
 
642
/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
643
with header files structure untouched (docstrings are kept near declarations)
644
PV */
645
void cmdobjdocwarnings()
646
{
647
    QStringList s;
648
    s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_duplicateobject__doc__;
649
}