Subversion Repositories Scribus

Rev

Rev 3718 | Rev 3727 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 Franz 1
#include "cmdobj.h"
2
#include "cmdutil.h"
82 Franz 3
 
2529 craig 4
#include "util.h"
740 fschmid 5
 
2790 craig 6
PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
82 Franz 7
{
8
        double x, y, b, h;
934 subik 9
        char *Name = const_cast<char*>("");
900 cbradney 10
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 11
                return NULL;
649 fschmid 12
        if(!checkHaveDocument())
13
                return NULL;
900 cbradney 14
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 15
        {
1525 cbradney 16
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 17
                return NULL;
18
        }
3292 cbradney 19
        int i = ScApp->doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, pageUnitXToDocX(x), pageUnitYToDocY(y),
20
                                                                         ValueToPoint(b), ValueToPoint(h), ScApp->doc->toolSettings.dWidth,
3690 cbradney 21
                                                                         ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen, true);
3242 cbradney 22
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 23
        if (Name != "")
3207 craig 24
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
25
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 26
}
27
 
243 Franz 28
 
2790 craig 29
PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args)
82 Franz 30
{
31
        double x, y, b, h;
934 subik 32
        char *Name = const_cast<char*>("");
900 cbradney 33
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 34
                return NULL;
649 fschmid 35
        if(!checkHaveDocument())
36
                return NULL;
3292 cbradney 37
        int i = ScApp->doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, pageUnitXToDocX(x),
38
                                                                                pageUnitYToDocY(y), b, h,
3207 craig 39
                                                                                ScApp->doc->toolSettings.dWidth,
40
                                                                                ScApp->doc->toolSettings.dBrush,
3292 cbradney 41
                                                                                ScApp->doc->toolSettings.dPen,
3690 cbradney 42
                                                                                true);
900 cbradney 43
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 44
        {
1525 cbradney 45
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 46
                return NULL;
47
        }
3242 cbradney 48
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 49
        if (Name != "")
3207 craig 50
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
51
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 52
}
53
 
243 Franz 54
 
2790 craig 55
PyObject *scribus_newimage(PyObject* /* self */, PyObject* args)
82 Franz 56
{
3292 cbradney 57
        double x, y, w, h;
934 subik 58
        char *Name = const_cast<char*>("");
3292 cbradney 59
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
82 Franz 60
                return NULL;
649 fschmid 61
        if(!checkHaveDocument())
62
                return NULL;
3690 cbradney 63
        int i = ScApp->doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, pageUnitXToDocX(x), pageUnitYToDocY(y), w, h, 1, ScApp->doc->toolSettings.dBrushPict, "None", true);
900 cbradney 64
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 65
        {
1525 cbradney 66
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 67
                return NULL;
68
        }
3242 cbradney 69
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 70
        if (Name != "")
3207 craig 71
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
72
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 73
}
74
 
243 Franz 75
 
2790 craig 76
PyObject *scribus_newtext(PyObject* /* self */, PyObject* args)
82 Franz 77
{
78
        double x, y, b, h;
934 subik 79
        char *Name = const_cast<char*>("");
900 cbradney 80
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 81
                return NULL;
649 fschmid 82
        if(!checkHaveDocument())
83
                return NULL;
3690 cbradney 84
        int i = ScApp->doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, pageUnitXToDocX(x), pageUnitYToDocY(y), b, h, ScApp->doc->toolSettings.dWidth, "None", ScApp->doc->toolSettings.dPenText, true);
900 cbradney 85
        if (ItemExists(QString::fromUtf8(Name)))
332 Franz 86
        {
1525 cbradney 87
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 88
                return NULL;
332 Franz 89
        }
3242 cbradney 90
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 91
        if (Name != "")
3207 craig 92
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
93
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 94
}
95
 
243 Franz 96
 
2790 craig 97
PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
82 Franz 98
{
99
        double x, y, b, h;
934 subik 100
        char *Name = const_cast<char*>("");
900 cbradney 101
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 102
                return NULL;
649 fschmid 103
        if(!checkHaveDocument())
104
                return NULL;
2029 craig 105
        x = pageUnitXToDocX(x);
1283 subik 106
        y = pageUnitYToDocY(y);
107
        b = pageUnitXToDocX(b);
108
        h = pageUnitYToDocY(h);
900 cbradney 109
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 110
        {
1525 cbradney 111
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 112
                return NULL;
113
        }
3690 cbradney 114
        int i = ScApp->doc->itemAdd(PageItem::Line, PageItem::Unspecified, x, y, 1, 1, ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen, true);
115
 
3207 craig 116
        PageItem *it = ScApp->doc->Items.at(i);
82 Franz 117
        it->PoLine.resize(4);
118
        it->PoLine.setPoint(0, 0, 0);
119
        it->PoLine.setPoint(1, 0, 0);
120
        it->PoLine.setPoint(2, b-x, h-y);
121
        it->PoLine.setPoint(3, b-x, h-y);
1065 cbradney 122
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 123
        if (np2.x() < 0)
647 fschmid 124
        {
82 Franz 125
                it->PoLine.translate(-np2.x(), 0);
3207 craig 126
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 127
        }
82 Franz 128
        if (np2.y() < 0)
647 fschmid 129
        {
82 Franz 130
                it->PoLine.translate(0, -np2.y());
3207 craig 131
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 132
        }
3207 craig 133
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), i, false, false);
134
        ScApp->view->AdjustItemSize(it);
2879 cbradney 135
        if (Name != "")
1361 tsoots 136
                it->setItemName(QString::fromUtf8(Name));
137
        return PyString_FromString(it->itemName().utf8());
82 Franz 138
}
139
 
243 Franz 140
 
2790 craig 141
PyObject *scribus_polyline(PyObject* /* self */, PyObject* args)
82 Franz 142
{
934 subik 143
        char *Name = const_cast<char*>("");
82 Franz 144
        PyObject *il;
900 cbradney 145
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
146
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 147
                return NULL;
649 fschmid 148
        if(!checkHaveDocument())
149
                return NULL;
87 Franz 150
        int len = PyList_Size(il);
720 subik 151
        if (len < 4)
152
        {
1525 cbradney 153
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error"));
720 subik 154
                return NULL;
155
        }
156
        if ((len % 2) != 0)
157
        {
1525 cbradney 158
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 159
                return NULL;
160
        }
900 cbradney 161
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 162
        {
1525 cbradney 163
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 164
                return NULL;
165
        }
87 Franz 166
        double x, y, b, h;
237 Franz 167
        int i = 0;
1283 subik 168
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 169
        i++;
1283 subik 170
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 171
        i++;
3690 cbradney 172
        int ic = ScApp->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,     ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen, true);
3207 craig 173
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 174
        it->PoLine.resize(2);
175
        it->PoLine.setPoint(0, 0, 0);
176
        it->PoLine.setPoint(1, 0, 0);
87 Franz 177
        int pp = 6;
82 Franz 178
        for (i = 2; i < len - 2; i += 2)
647 fschmid 179
        {
1283 subik 180
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
181
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 182
                it->PoLine.resize(pp);
183
                it->PoLine.setPoint(pp-4, b-x, h-y);
184
                it->PoLine.setPoint(pp-3, b-x, h-y);
185
                it->PoLine.setPoint(pp-2, b-x, h-y);
186
                it->PoLine.setPoint(pp-1, b-x, h-y);
187
                pp += 4;
647 fschmid 188
        }
82 Franz 189
        pp -= 2;
1283 subik 190
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
191
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 192
        it->PoLine.resize(pp);
193
        it->PoLine.setPoint(pp-2, b-x, h-y);
194
        it->PoLine.setPoint(pp-1, b-x, h-y);
1065 cbradney 195
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 196
        if (np2.x() < 0)
647 fschmid 197
        {
82 Franz 198
                it->PoLine.translate(-np2.x(), 0);
3207 craig 199
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 200
        }
82 Franz 201
        if (np2.y() < 0)
647 fschmid 202
        {
82 Franz 203
                it->PoLine.translate(0, -np2.y());
3207 craig 204
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 205
        }
3207 craig 206
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
207
        ScApp->view->AdjustItemSize(it);
2879 cbradney 208
        if (Name != "")
720 subik 209
        {
1361 tsoots 210
                it->setItemName(QString::fromUtf8(Name));
720 subik 211
        }
1361 tsoots 212
        return PyString_FromString(it->itemName().utf8());
82 Franz 213
}
214
 
243 Franz 215
 
2790 craig 216
PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
82 Franz 217
{
934 subik 218
        char *Name = const_cast<char*>("");
82 Franz 219
        PyObject *il;
900 cbradney 220
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
221
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 222
                return NULL;
649 fschmid 223
        if(!checkHaveDocument())
224
                return NULL;
87 Franz 225
        int len = PyList_Size(il);
720 subik 226
        if (len < 6)
227
        {
1525 cbradney 228
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error"));
720 subik 229
                return NULL;
230
        }
231
        if ((len % 2) != 0)
232
        {
1525 cbradney 233
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 234
                return NULL;
235
        }
900 cbradney 236
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 237
        {
1525 cbradney 238
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 239
                return NULL;
240
        }
87 Franz 241
        double x, y, b, h;
237 Franz 242
        int i = 0;
1283 subik 243
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 244
        i++;
1283 subik 245
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 246
        i++;
3690 cbradney 247
        int ic = ScApp->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1,      ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen, true);
3207 craig 248
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 249
        it->PoLine.resize(2);
250
        it->PoLine.setPoint(0, 0, 0);
251
        it->PoLine.setPoint(1, 0, 0);
87 Franz 252
        int pp = 6;
82 Franz 253
        for (i = 2; i < len - 2; i += 2)
647 fschmid 254
        {
1283 subik 255
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
256
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 257
                it->PoLine.resize(pp);
258
                it->PoLine.setPoint(pp-4, b-x, h-y);
259
                it->PoLine.setPoint(pp-3, b-x, h-y);
260
                it->PoLine.setPoint(pp-2, b-x, h-y);
261
                it->PoLine.setPoint(pp-1, b-x, h-y);
262
                pp += 4;
647 fschmid 263
        }
1283 subik 264
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
265
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 266
        it->PoLine.resize(pp);
267
        it->PoLine.setPoint(pp-4, b-x, h-y);
268
        it->PoLine.setPoint(pp-3, b-x, h-y);
269
        it->PoLine.setPoint(pp-2, b-x, h-y);
270
        it->PoLine.setPoint(pp-1, b-x, h-y);
271
        pp += 2;
272
        it->PoLine.resize(pp);
273
        it->PoLine.setPoint(pp-2, 0, 0);
274
        it->PoLine.setPoint(pp-1, 0, 0);
1065 cbradney 275
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 276
        if (np2.x() < 0)
647 fschmid 277
        {
82 Franz 278
                it->PoLine.translate(-np2.x(), 0);
3207 craig 279
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 280
        }
82 Franz 281
        if (np2.y() < 0)
647 fschmid 282
        {
82 Franz 283
                it->PoLine.translate(0, -np2.y());
3207 craig 284
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 285
        }
3207 craig 286
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
287
        ScApp->view->AdjustItemSize(it);
2879 cbradney 288
        if (Name != "")
1361 tsoots 289
                it->setItemName(QString::fromUtf8(Name));
290
        return PyString_FromString(it->itemName().utf8());
82 Franz 291
}
292
 
2790 craig 293
PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
82 Franz 294
{
934 subik 295
        char *Name = const_cast<char*>("");
82 Franz 296
        PyObject *il;
900 cbradney 297
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
298
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 299
                return NULL;
649 fschmid 300
        if(!checkHaveDocument())
301
                return NULL;
87 Franz 302
        int len = PyList_Size(il);
720 subik 303
        if (len < 8)
304
        {
1525 cbradney 305
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error"));
720 subik 306
                return NULL;
307
        }
308
        if ((len % 6) != 0)
309
        {
1525 cbradney 310
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error"));
720 subik 311
                return NULL;
312
        }
900 cbradney 313
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 314
        {
1525 cbradney 315
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 316
                return NULL;
317
        }
87 Franz 318
        double x, y, b, h, kx, ky, kx2, ky2;
237 Franz 319
        int i = 0;
1283 subik 320
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 321
        i++;
1283 subik 322
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 323
        i++;
1283 subik 324
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 325
        i++;
1283 subik 326
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 327
        i++;
1283 subik 328
        kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 329
        i++;
1283 subik 330
        ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 331
        i++;
3292 cbradney 332
        //int ic = ScApp->view->PaintPolyLine(x, y, 1, 1,       ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen);
3690 cbradney 333
        int ic = ScApp->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,     ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen, true);
3207 craig 334
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 335
        it->PoLine.resize(2);
336
        it->PoLine.setPoint(0, 0, 0);
337
        it->PoLine.setPoint(1, kx-x, ky-y);
87 Franz 338
        int pp = 6;
82 Franz 339
        for (i = 6; i < len - 6; i += 6)
647 fschmid 340
        {
1283 subik 341
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
342
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
343
                kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
344
                ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
345
                kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
346
                ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
82 Franz 347
                it->PoLine.resize(pp);
348
                it->PoLine.setPoint(pp-4, b-x, h-y);
349
                it->PoLine.setPoint(pp-3, kx-x, ky-y);
350
                it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
351
                it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
352
                pp += 4;
647 fschmid 353
        }
82 Franz 354
        pp -= 2;
1283 subik 355
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
356
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
357
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
358
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
82 Franz 359
        it->PoLine.resize(pp);
360
        it->PoLine.setPoint(pp-2, b-x, h-y);
361
        it->PoLine.setPoint(pp-1, kx-x, ky-y);
1065 cbradney 362
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 363
        if (np2.x() < 0)
647 fschmid 364
        {
82 Franz 365
                it->PoLine.translate(-np2.x(), 0);
3207 craig 366
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 367
        }
82 Franz 368
        if (np2.y() < 0)
647 fschmid 369
        {
82 Franz 370
                it->PoLine.translate(0, -np2.y());
3207 craig 371
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 372
        }
3207 craig 373
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
374
        ScApp->view->AdjustItemSize(it);
2879 cbradney 375
        if (Name != "")
1361 tsoots 376
                it->setItemName(QString::fromUtf8(Name));
377
        return PyString_FromString(it->itemName().utf8());
82 Franz 378
}
379
 
243 Franz 380
 
381
/* 03/31/2004 - xception handling
382
 */
2790 craig 383
PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args)
82 Franz 384
{
385
        double x, y;
934 subik 386
        char *Name = const_cast<char*>("");
387
        char *TextB = const_cast<char*>("");
388
        char *PolyB = const_cast<char*>("");
900 cbradney 389
        if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
82 Franz 390
                return NULL;
649 fschmid 391
        if(!checkHaveDocument())
392
                return NULL;
900 cbradney 393
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 394
        {
1525 cbradney 395
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 396
                return NULL;
397
        }
398
        //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
399
        // its sets for us?
900 cbradney 400
        int i = GetItem(QString::fromUtf8(TextB));
401
        int ii = GetItem(QString::fromUtf8(PolyB));
82 Franz 402
        if ((i == -1) || (ii == -1))
243 Franz 403
        {
1525 cbradney 404
                PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error"));
243 Franz 405
                return NULL;
406
        }
3207 craig 407
        ScApp->view->SelItem.clear();
408
        ScApp->view->SelItem.append(ScApp->doc->Items.at(i));
409
        ScApp->view->SelItem.append(ScApp->doc->Items.at(ii));
410
        PageItem *it = ScApp->doc->Items.at(i);
411
        ScApp->view->ToPathText();
412
        ScApp->view->MoveItem(pageUnitXToDocX(x) - it->Xpos, pageUnitYToDocY(y) - it->Ypos, it);
2879 cbradney 413
        if (Name != "")
1361 tsoots 414
                it->setItemName(QString::fromUtf8(Name));
415
        return PyString_FromString(it->itemName().utf8());
82 Franz 416
}
417
 
243 Franz 418
 
237 Franz 419
/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
420
 */
2790 craig 421
PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args)
82 Franz 422
{
934 subik 423
        char *Name = const_cast<char*>("");
900 cbradney 424
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
82 Franz 425
                return NULL;
649 fschmid 426
        if(!checkHaveDocument())
427
                return NULL;
900 cbradney 428
        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
720 subik 429
        if (i == NULL)
332 Franz 430
                return NULL;
3207 craig 431
        ScApp->view->SelItem.clear();
432
        ScApp->view->SelItem.append(i);
433
        ScApp->view->DeleteItem();
647 fschmid 434
        Py_INCREF(Py_None);
82 Franz 435
        return Py_None;
436
}
437
 
243 Franz 438
 
237 Franz 439
/* 03/21/2004 - exception raises by non existent name (subik)
440
 */
2790 craig 441
PyObject *scribus_textflow(PyObject* /* self */, PyObject* args)
214 Franz 442
{
934 subik 443
        char *name = const_cast<char*>("");
332 Franz 444
        int state = -1;
214 Franz 445
 
900 cbradney 446
        if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
214 Franz 447
                return NULL;
649 fschmid 448
        if(!checkHaveDocument())
449
                return NULL;
900 cbradney 450
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
332 Franz 451
        if (i == NULL)
237 Franz 452
                return NULL;
214 Franz 453
        if (state == -1)
1653 craig 454
                i->setTextFlowsAroundFrame(!i->textFlowsAroundFrame());
214 Franz 455
        else
1653 craig 456
                i->setTextFlowsAroundFrame( state ? true : false);
3207 craig 457
        ScApp->view->DrawNew();
458
        ScApp->slotDocCh(true);
647 fschmid 459
        Py_INCREF(Py_None);
214 Franz 460
        return Py_None;
461
}
243 Franz 462
 
463
 
2790 craig 464
PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
243 Franz 465
{
934 subik 466
        char* name = const_cast<char*>("");
900 cbradney 467
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
243 Franz 468
                return NULL;
649 fschmid 469
        if(!checkHaveDocument())
470
                return NULL;
900 cbradney 471
        if (ItemExists(QString::fromUtf8(name)))
720 subik 472
                return PyBool_FromLong(static_cast<long>(true));
473
        return PyBool_FromLong(static_cast<long>(false));
243 Franz 474
}
475
 
411 Franz 476
/*
477
 * Craig Ringer, 2004-09-09
478
 * Apply the named style to the currently selected object.
479
 * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
480
 */
2790 craig 481
PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args)
411 Franz 482
{
934 subik 483
        char *style = const_cast<char*>("");
484
        char *name = const_cast<char*>("");
900 cbradney 485
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
411 Franz 486
                return NULL;
649 fschmid 487
        if(!checkHaveDocument())
488
                return NULL;
900 cbradney 489
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
720 subik 490
        if (item == NULL)
491
                return NULL;
1460 cbradney 492
        if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText))
411 Franz 493
        {
3718 cbradney 494
                // First, find the style number associated with the requested style
495
                // by scanning through the styles looking for the name. If
496
                // we can't find it, raise PyExc_Exception.
497
                // FIXME: Should use a more specific exception.
411 Franz 498
                bool found = false;
499
                uint styleid = 0;
500
                // We start at zero here because it's OK to match an internal name
3718 cbradney 501
                uint docParagraphStylesCount=ScApp->doc->docParagraphStyles.count();
502
                for (uint i=0; i < docParagraphStylesCount; ++i)
411 Franz 503
                {
3207 craig 504
                        if (ScApp->doc->docParagraphStyles[i].Vname == QString::fromUtf8(style)) {
411 Franz 505
                                found = true;
506
                                styleid = i;
507
                                break;
508
                        }
509
                }
510
                if (!found) {
511
                        // whoops, the user specified an invalid style, complain loudly.
1525 cbradney 512
                        PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error"));
411 Franz 513
                        return NULL;
514
                }
515
                // quick hack to always apply on the right frame - pv
3207 craig 516
                ScApp->view->Deselect(true);
3720 cbradney 517
                //CB I dont think we need to draw here. Its faster if we dont.
3718 cbradney 518
                ScApp->view->SelectItem(item, false);
411 Franz 519
                // Now apply the style.
3207 craig 520
                ScApp->setNewAbStyle(styleid);
411 Franz 521
        }
720 subik 522
        else
523
        {
1525 cbradney 524
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error"));
720 subik 525
                return NULL;
526
        }
411 Franz 527
        Py_INCREF(Py_None);
528
        return Py_None;
529
}
530
 
531
/*
532
 * Craig Ringer, 2004-09-09
533
 * Enumerate all known paragraph styles
534
 */
2790 craig 535
PyObject *scribus_getstylenames(PyObject* /* self */)
411 Franz 536
{
537
        PyObject *styleList;
649 fschmid 538
        if(!checkHaveDocument())
539
                return NULL;
411 Franz 540
        styleList = PyList_New(0);
541
        /*
421 Franz 542
        We start at 5 because the lower styles are internal names.
543
        pv - changet to get all (with system) objects
649 fschmid 544
        FIXME: this should be a constant defined by the scribus core
421 Franz 545
        */
3207 craig 546
        for (uint i=0; i < ScApp->doc->docParagraphStyles.count(); ++i)
411 Franz 547
        {
3207 craig 548
                if (PyList_Append(styleList, PyString_FromString(ScApp->doc->docParagraphStyles[i].Vname.utf8())))
411 Franz 549
                {
550
                        // An exception will have already been set by PyList_Append apparently.
551
                        return NULL;
552
                }
553
        }
554
        return styleList;
555
}