Subversion Repositories Scribus

Rev

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