Subversion Repositories Scribus

Rev

Rev 23691 | Rev 23861 | Go to most recent revision | 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"
19067 craig 8
 
9
#include "appmodes.h"
103 Franz 10
#include "cmdutil.h"
4546 subik 11
#include "commonstrings.h"
19067 craig 12
#include "pageitem_table.h"
5781 cbradney 13
#include "scribuscore.h"
13805 jghali 14
#include "scribusdoc.h"
19093 craig 15
#include "scribusview.h"
19067 craig 16
#include "selection.h"
17
#include "util_math.h"
740 fschmid 18
 
19067 craig 19
 
2790 craig 20
PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
82 Franz 21
{
4520 subik 22
        double x, y, w, h;
934 subik 23
        char *Name = const_cast<char*>("");
11955 subik 24
 
4520 subik 25
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
22537 craig 26
                return nullptr;
22654 jghali 27
        if (!checkHaveDocument())
22537 craig 28
                return nullptr;
10039 fschmid 29
//      if (ItemExists(QString::fromUtf8(Name)))
30
//      {
31
//              PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
22537 craig 32
//              return nullptr;
10039 fschmid 33
//      }
23278 jghali 34
        ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
35
        int i = doc->itemAdd(PageItem::Polygon, PageItem::Rectangle,
36
                                                pageUnitXToDocX(x), pageUnitYToDocY(y),
37
                                                ValueToPoint(w), ValueToPoint(h),
38
                                                doc->itemToolPrefs().shapeLineWidth,
39
                                                doc->itemToolPrefs().shapeFillColor, doc->itemToolPrefs().shapeLineColor);
10039 fschmid 40
//      ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
20895 jghali 41
        if (strlen(Name) > 0)
10039 fschmid 42
        {
13735 jghali 43
                QString objName = QString::fromUtf8(Name);
44
                if (!ItemExists(objName))
23278 jghali 45
                        doc->Items->at(i)->setItemName(objName);
10039 fschmid 46
        }
23278 jghali 47
        return PyUnicode_FromString(doc->Items->at(i)->itemName().toUtf8());
82 Franz 48
}
49
 
243 Franz 50
 
2790 craig 51
PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args)
82 Franz 52
{
4520 subik 53
        double x, y, w, h;
934 subik 54
        char *Name = const_cast<char*>("");
4520 subik 55
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
22537 craig 56
                return nullptr;
22654 jghali 57
        if (!checkHaveDocument())
22537 craig 58
                return nullptr;
5781 cbradney 59
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Ellipse,
4520 subik 60
                                                                                pageUnitXToDocX(x),
61
                                                                                pageUnitYToDocY(y),
62
                                                                                ValueToPoint(w),
63
                                                                                ValueToPoint(h),
14932 cbradney 64
                                                                                ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth,
65
                                                                                ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor,
20561 jghali 66
                                                                                ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
20895 jghali 67
        if (strlen(Name) > 0)
720 subik 68
        {
13735 jghali 69
                QString objName = QString::fromUtf8(Name);
70
                if (!ItemExists(objName))
71
                        ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
720 subik 72
        }
23278 jghali 73
        return PyUnicode_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
82 Franz 74
}
75
 
243 Franz 76
 
2790 craig 77
PyObject *scribus_newimage(PyObject* /* self */, PyObject* args)
82 Franz 78
{
3292 cbradney 79
        double x, y, w, h;
934 subik 80
        char *Name = const_cast<char*>("");
3292 cbradney 81
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
22537 craig 82
                return nullptr;
22654 jghali 83
        if (!checkHaveDocument())
22537 craig 84
                return nullptr;
5781 cbradney 85
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified,
4520 subik 86
                                                                        pageUnitXToDocX(x),
87
                                                                        pageUnitYToDocY(y),
88
                                                                        ValueToPoint(w),
89
                                                                        ValueToPoint(h),
14932 cbradney 90
                                                                        1, ScCore->primaryMainWindow()->doc->itemToolPrefs().imageFillColor,
20561 jghali 91
                                                                        ScCore->primaryMainWindow()->doc->itemToolPrefs().imageStrokeColor);
20895 jghali 92
        if (strlen(Name) > 0)
720 subik 93
        {
13735 jghali 94
                QString objName = QString::fromUtf8(Name);
95
                if (!ItemExists(objName))
96
                        ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
720 subik 97
        }
23278 jghali 98
        return PyUnicode_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
82 Franz 99
}
100
 
243 Franz 101
 
2790 craig 102
PyObject *scribus_newtext(PyObject* /* self */, PyObject* args)
82 Franz 103
{
4520 subik 104
        double x, y, w, h;
934 subik 105
        char *Name = const_cast<char*>("");
4520 subik 106
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
22537 craig 107
                return nullptr;
22654 jghali 108
        if (!checkHaveDocument())
22537 craig 109
                return nullptr;
5781 cbradney 110
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified,
4520 subik 111
                                                                pageUnitXToDocX(x),
112
                                                                pageUnitYToDocY(y),
113
                                                                ValueToPoint(w),
114
                                                                ValueToPoint(h),
14932 cbradney 115
                                                                ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, CommonStrings::None,
20561 jghali 116
                                                                ScCore->primaryMainWindow()->doc->itemToolPrefs().textColor);
20895 jghali 117
        if (strlen(Name) > 0)
332 Franz 118
        {
13735 jghali 119
                QString objName = QString::fromUtf8(Name);
120
                if (!ItemExists(objName))
121
                        ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
332 Franz 122
        }
23278 jghali 123
        return PyUnicode_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
82 Franz 124
}
125
 
16856 craig 126
PyObject *scribus_newtable(PyObject* /* self */, PyObject* args)
127
{
128
        double x, y, w, h;
129
        int numRows, numColumns;
130
        char *Name = const_cast<char*>("");
131
        if (!PyArg_ParseTuple(args, "ddddii|es", &x, &y, &w, &h, &numRows, &numColumns, "utf-8", &Name))
22537 craig 132
                return nullptr;
16856 craig 133
        if (!checkHaveDocument())
22537 craig 134
                return nullptr;
16856 craig 135
        if (numRows < 1 || numColumns < 1)
136
        {
137
                PyErr_SetString(PyExc_ValueError, QObject::tr("Both numRows and numColumns must be greater than 0.","python error").toLocal8Bit().constData());
22537 craig 138
                return nullptr;
16856 craig 139
        }
140
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Table, PageItem::Unspecified,
141
                                                                pageUnitXToDocX(x),
142
                                                                pageUnitYToDocY(y),
143
                                                                ValueToPoint(w),
144
                                                                ValueToPoint(h),
145
                                                                0,                    // Unused.
146
                                                                CommonStrings::None,  // Unused.
20561 jghali 147
                                                                CommonStrings::None); // Unused.
16856 craig 148
        PageItem_Table *table = ScCore->primaryMainWindow()->doc->Items->at(i)->asTable();
149
        table->insertRows(0, numRows - 1);
150
        table->insertColumns(0, numColumns - 1);
151
        table->adjustTableToFrame();
152
        table->adjustFrameToTable();
20895 jghali 153
        if (strlen(Name) > 0)
16856 craig 154
        {
155
                QString objName = QString::fromUtf8(Name);
156
                if (!ItemExists(objName))
157
                        ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
158
        }
23278 jghali 159
        return PyUnicode_FromString(table->itemName().toUtf8());
16856 craig 160
}
161
 
2790 craig 162
PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
82 Franz 163
{
4520 subik 164
        double x, y, w, h;
934 subik 165
        char *Name = const_cast<char*>("");
4520 subik 166
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
22537 craig 167
                return nullptr;
22654 jghali 168
        if (!checkHaveDocument())
22537 craig 169
                return nullptr;
2029 craig 170
        x = pageUnitXToDocX(x);
1283 subik 171
        y = pageUnitYToDocY(y);
4520 subik 172
        w = pageUnitXToDocX(w);
1283 subik 173
        h = pageUnitYToDocY(h);
10039 fschmid 174
//      if (ItemExists(QString::fromUtf8(Name)))
175
//      {
176
//              PyErr_SetString(NameExistsError,
177
//                                              QObject::tr("An object with the requested name already exists.",
178
//                                                                      "python error"));
22537 craig 179
//              return nullptr;
10039 fschmid 180
//      }
5781 cbradney 181
        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Line, PageItem::Unspecified,
5332 subik 182
                                                           x, y, w, h,
14932 cbradney 183
                                                           ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth,
184
                                                           ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor,
20561 jghali 185
                                                           ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
5781 cbradney 186
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i);
5332 subik 187
        it->setRotation(xy2Deg(w-x, h-y));
188
        it->setWidthHeight(sqrt(pow(x-w, 2.0) + pow(y-h, 2.0)), 1.0);
189
        it->Sizing = false;
190
        it->updateClip();
13374 jghali 191
        it->setRedrawBounding();
10039 fschmid 192
//      ScCore->primaryMainWindow()->doc->setRedrawBounding(it);
5332 subik 193
/* WTF? maybe I'll examine who's author later. Or maybe I'll remove it later ;)
82 Franz 194
        it->PoLine.resize(4);
195
        it->PoLine.setPoint(0, 0, 0);
196
        it->PoLine.setPoint(1, 0, 0);
4520 subik 197
        it->PoLine.setPoint(2, w-x, h-y);
198
        it->PoLine.setPoint(3, w-x, h-y);
1065 cbradney 199
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 200
        if (np2.x() < 0)
647 fschmid 201
        {
82 Franz 202
                it->PoLine.translate(-np2.x(), 0);
5781 cbradney 203
                ScCore->primaryMainWindow()->view->MoveItem(np2.x(), 0, it);
647 fschmid 204
        }
82 Franz 205
        if (np2.y() < 0)
647 fschmid 206
        {
82 Franz 207
                it->PoLine.translate(0, -np2.y());
5781 cbradney 208
                ScCore->primaryMainWindow()->view->MoveItem(0, np2.y(), it);
647 fschmid 209
        }
23038 jghali 210
        ScCore->primaryMainWindow()->view->SizeItem(it->PoLine.widthHeight().x(),
211
                                                 it->PoLine.widthHeight().y(), i, false, false, false);
5781 cbradney 212
        ScCore->primaryMainWindow()->view->AdjustItemSize(it);*/
20895 jghali 213
        if (strlen(Name) > 0)
10039 fschmid 214
        {
13735 jghali 215
                QString objName = QString::fromUtf8(Name);
216
                if (!ItemExists(objName))
217
                        ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
10039 fschmid 218
        }
23278 jghali 219
        return PyUnicode_FromString(it->itemName().toUtf8());
82 Franz 220
}
221
 
243 Franz 222
 
2790 craig 223
PyObject *scribus_polyline(PyObject* /* self */, PyObject* args)
82 Franz 224
{
934 subik 225
        char *Name = const_cast<char*>("");
82 Franz 226
        PyObject *il;
22537 craig 227
        // FIXME: PyList_Check failing will cause the function to return nullptr w/o an exception. Separarate out the check.
900 cbradney 228
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
22537 craig 229
                return nullptr;
22654 jghali 230
        if (!checkHaveDocument())
22537 craig 231
                return nullptr;
87 Franz 232
        int len = PyList_Size(il);
720 subik 233
        if (len < 4)
234
        {
10598 cbradney 235
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error").toLocal8Bit().constData());
22537 craig 236
                return nullptr;
720 subik 237
        }
238
        if ((len % 2) != 0)
239
        {
10598 cbradney 240
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error").toLocal8Bit().constData());
22537 craig 241
                return nullptr;
720 subik 242
        }
10039 fschmid 243
//      if (ItemExists(QString::fromUtf8(Name)))
244
//      {
10598 cbradney 245
//              PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData());
22537 craig 246
//              return nullptr;
10039 fschmid 247
//      }
4520 subik 248
        double x, y, w, h;
237 Franz 249
        int i = 0;
1283 subik 250
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 251
        i++;
1283 subik 252
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 253
        i++;
20561 jghali 254
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
5781 cbradney 255
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 256
        it->PoLine.resize(2);
257
        it->PoLine.setPoint(0, 0, 0);
258
        it->PoLine.setPoint(1, 0, 0);
87 Franz 259
        int pp = 6;
82 Franz 260
        for (i = 2; i < len - 2; i += 2)
647 fschmid 261
        {
4520 subik 262
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 263
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 264
                it->PoLine.resize(pp);
4520 subik 265
                it->PoLine.setPoint(pp-4, w-x, h-y);
266
                it->PoLine.setPoint(pp-3, w-x, h-y);
267
                it->PoLine.setPoint(pp-2, w-x, h-y);
268
                it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 269
                pp += 4;
647 fschmid 270
        }
82 Franz 271
        pp -= 2;
4520 subik 272
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
1283 subik 273
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 274
        it->PoLine.resize(pp);
4520 subik 275
        it->PoLine.setPoint(pp-2, w-x, h-y);
276
        it->PoLine.setPoint(pp-1, w-x, h-y);
1065 cbradney 277
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 278
        if (np2.x() < 0)
647 fschmid 279
        {
82 Franz 280
                it->PoLine.translate(-np2.x(), 0);
20694 craig 281
                ScCore->primaryMainWindow()->doc->moveItem(np2.x(), 0, it);
647 fschmid 282
        }
82 Franz 283
        if (np2.y() < 0)
647 fschmid 284
        {
82 Franz 285
                it->PoLine.translate(0, -np2.y());
20694 craig 286
                ScCore->primaryMainWindow()->doc->moveItem(0, np2.y(), it);
647 fschmid 287
        }
23038 jghali 288
        ScCore->primaryMainWindow()->doc->sizeItem(it->PoLine.widthHeight().x(), it->PoLine.widthHeight().y(), it, false, false, false);
20694 craig 289
        ScCore->primaryMainWindow()->doc->adjustItemSize(it);
20895 jghali 290
        if (strlen(Name) > 0)
720 subik 291
        {
13735 jghali 292
                QString objName = QString::fromUtf8(Name);
293
                if (!ItemExists(objName))
14696 jghali 294
                        ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
720 subik 295
        }
23278 jghali 296
        return PyUnicode_FromString(it->itemName().toUtf8());
82 Franz 297
}
298
 
243 Franz 299
 
2790 craig 300
PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
82 Franz 301
{
934 subik 302
        char *Name = const_cast<char*>("");
82 Franz 303
        PyObject *il;
22537 craig 304
        // FIXME: PyList_Check failing will cause the function to return nullptr w/o an exception. Separarate out the check.
900 cbradney 305
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
22537 craig 306
                return nullptr;
22654 jghali 307
        if (!checkHaveDocument())
22537 craig 308
                return nullptr;
87 Franz 309
        int len = PyList_Size(il);
720 subik 310
        if (len < 6)
311
        {
10598 cbradney 312
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error").toLocal8Bit().constData());
22537 craig 313
                return nullptr;
720 subik 314
        }
315
        if ((len % 2) != 0)
316
        {
10598 cbradney 317
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error").toLocal8Bit().constData());
22537 craig 318
                return nullptr;
720 subik 319
        }
10039 fschmid 320
//      if (ItemExists(QString::fromUtf8(Name)))
321
//      {
10598 cbradney 322
//              PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData());
22537 craig 323
//              return nullptr;
10039 fschmid 324
//      }
4520 subik 325
        double x, y, w, h;
237 Franz 326
        int i = 0;
1283 subik 327
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 328
        i++;
1283 subik 329
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 330
        i++;
20561 jghali 331
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1,        ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
5781 cbradney 332
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 333
        it->PoLine.resize(2);
334
        it->PoLine.setPoint(0, 0, 0);
335
        it->PoLine.setPoint(1, 0, 0);
87 Franz 336
        int pp = 6;
82 Franz 337
        for (i = 2; i < len - 2; i += 2)
647 fschmid 338
        {
4520 subik 339
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 340
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 341
                it->PoLine.resize(pp);
4520 subik 342
                it->PoLine.setPoint(pp-4, w-x, h-y);
343
                it->PoLine.setPoint(pp-3, w-x, h-y);
344
                it->PoLine.setPoint(pp-2, w-x, h-y);
345
                it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 346
                pp += 4;
647 fschmid 347
        }
4520 subik 348
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
1283 subik 349
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 350
        it->PoLine.resize(pp);
4520 subik 351
        it->PoLine.setPoint(pp-4, w-x, h-y);
352
        it->PoLine.setPoint(pp-3, w-x, h-y);
353
        it->PoLine.setPoint(pp-2, w-x, h-y);
354
        it->PoLine.setPoint(pp-1, w-x, h-y);
82 Franz 355
        pp += 2;
356
        it->PoLine.resize(pp);
357
        it->PoLine.setPoint(pp-2, 0, 0);
358
        it->PoLine.setPoint(pp-1, 0, 0);
1065 cbradney 359
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 360
        if (np2.x() < 0)
647 fschmid 361
        {
82 Franz 362
                it->PoLine.translate(-np2.x(), 0);
20694 craig 363
                ScCore->primaryMainWindow()->doc->moveItem(np2.x(), 0, it);
647 fschmid 364
        }
82 Franz 365
        if (np2.y() < 0)
647 fschmid 366
        {
82 Franz 367
                it->PoLine.translate(0, -np2.y());
20694 craig 368
                ScCore->primaryMainWindow()->doc->moveItem(0, np2.y(), it);
647 fschmid 369
        }
23038 jghali 370
        ScCore->primaryMainWindow()->doc->sizeItem(it->PoLine.widthHeight().x(), it->PoLine.widthHeight().y(), it, false, false, false);
20694 craig 371
        ScCore->primaryMainWindow()->doc->adjustItemSize(it);
20895 jghali 372
        if (strlen(Name) > 0)
10039 fschmid 373
        {
13735 jghali 374
                QString objName = QString::fromUtf8(Name);
375
                if (!ItemExists(objName))
14696 jghali 376
                        ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
10039 fschmid 377
        }
23278 jghali 378
        return PyUnicode_FromString(it->itemName().toUtf8());
82 Franz 379
}
380
 
2790 craig 381
PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
82 Franz 382
{
934 subik 383
        char *Name = const_cast<char*>("");
82 Franz 384
        PyObject *il;
22537 craig 385
        // FIXME: PyList_Check failing will cause the function to return nullptr w/o an exception. Separarate out the check.
900 cbradney 386
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
22537 craig 387
                return nullptr;
22654 jghali 388
        if (!checkHaveDocument())
22537 craig 389
                return nullptr;
87 Franz 390
        int len = PyList_Size(il);
720 subik 391
        if (len < 8)
392
        {
10598 cbradney 393
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error").toLocal8Bit().constData());
22537 craig 394
                return nullptr;
720 subik 395
        }
396
        if ((len % 6) != 0)
397
        {
10598 cbradney 398
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error").toLocal8Bit().constData());
22537 craig 399
                return nullptr;
720 subik 400
        }
10039 fschmid 401
//      if (ItemExists(QString::fromUtf8(Name)))
402
//      {
10598 cbradney 403
//              PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData());
22537 craig 404
//              return nullptr;
10039 fschmid 405
//      }
4520 subik 406
        double x, y, w, h, kx, ky, kx2, ky2;
237 Franz 407
        int i = 0;
1283 subik 408
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 409
        i++;
1283 subik 410
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 411
        i++;
1283 subik 412
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 413
        i++;
1283 subik 414
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 415
        i++;
1283 subik 416
        kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 417
        i++;
1283 subik 418
        ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 419
        i++;
5781 cbradney 420
        //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);
20561 jghali 421
        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
5781 cbradney 422
        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
82 Franz 423
        it->PoLine.resize(2);
424
        it->PoLine.setPoint(0, 0, 0);
425
        it->PoLine.setPoint(1, kx-x, ky-y);
87 Franz 426
        int pp = 6;
82 Franz 427
        for (i = 6; i < len - 6; i += 6)
647 fschmid 428
        {
4520 subik 429
                w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
1283 subik 430
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
431
                kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
432
                ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
433
                kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
434
                ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
82 Franz 435
                it->PoLine.resize(pp);
4520 subik 436
                it->PoLine.setPoint(pp-4, w-x, h-y);
82 Franz 437
                it->PoLine.setPoint(pp-3, kx-x, ky-y);
438
                it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
439
                it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
440
                pp += 4;
647 fschmid 441
        }
82 Franz 442
        pp -= 2;
4520 subik 443
        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
1283 subik 444
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
445
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
446
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
82 Franz 447
        it->PoLine.resize(pp);
4520 subik 448
        it->PoLine.setPoint(pp-2, w-x, h-y);
82 Franz 449
        it->PoLine.setPoint(pp-1, kx-x, ky-y);
1065 cbradney 450
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 451
        if (np2.x() < 0)
647 fschmid 452
        {
82 Franz 453
                it->PoLine.translate(-np2.x(), 0);
20694 craig 454
                ScCore->primaryMainWindow()->doc->moveItem(np2.x(), 0, it);
647 fschmid 455
        }
82 Franz 456
        if (np2.y() < 0)
647 fschmid 457
        {
82 Franz 458
                it->PoLine.translate(0, -np2.y());
20694 craig 459
                ScCore->primaryMainWindow()->doc->moveItem(0, np2.y(), it);
647 fschmid 460
        }
23038 jghali 461
        ScCore->primaryMainWindow()->doc->sizeItem(it->PoLine.widthHeight().x(), it->PoLine.widthHeight().y(), it, false, false, false);
20694 craig 462
        ScCore->primaryMainWindow()->doc->adjustItemSize(it);
20895 jghali 463
        if (strlen(Name) > 0)
10039 fschmid 464
        {
13735 jghali 465
                QString objName = QString::fromUtf8(Name);
466
                if (!ItemExists(objName))
14696 jghali 467
                        ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
10039 fschmid 468
        }
23278 jghali 469
        return PyUnicode_FromString(it->itemName().toUtf8());
82 Franz 470
}
471
 
243 Franz 472
 
473
/* 03/31/2004 - xception handling
474
 */
2790 craig 475
PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args)
82 Franz 476
{
477
        double x, y;
934 subik 478
        char *Name = const_cast<char*>("");
479
        char *TextB = const_cast<char*>("");
480
        char *PolyB = const_cast<char*>("");
900 cbradney 481
        if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
22537 craig 482
                return nullptr;
22654 jghali 483
        if (!checkHaveDocument())
22537 craig 484
                return nullptr;
10039 fschmid 485
//      if (ItemExists(QString::fromUtf8(Name)))
486
//      {
487
//              PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
22537 craig 488
//              return nullptr;
10039 fschmid 489
//      }
720 subik 490
        //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
491
        // its sets for us?
16943 fschmid 492
        PageItem *i = GetItem(QString::fromUtf8(TextB));
493
        PageItem *ii = GetItem(QString::fromUtf8(PolyB));
22537 craig 494
        if ((i == nullptr) || (ii == nullptr))
243 Franz 495
        {
10598 cbradney 496
                PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error").toLocal8Bit().constData());
22537 craig 497
                return nullptr;
243 Franz 498
        }
5781 cbradney 499
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
16943 fschmid 500
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
501
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(ii);
5781 cbradney 502
        ScCore->primaryMainWindow()->view->ToPathText();
20694 craig 503
        ScCore->primaryMainWindow()->doc->moveItem(pageUnitXToDocX(x) - i->xPos(), pageUnitYToDocY(y) - i->yPos(), i);
20895 jghali 504
        if (strlen(Name) > 0)
10039 fschmid 505
        {
13735 jghali 506
                QString objName = QString::fromUtf8(Name);
507
                if (!ItemExists(objName))
16943 fschmid 508
                        i->setItemName(objName);
10039 fschmid 509
        }
23278 jghali 510
        return PyUnicode_FromString(i->itemName().toUtf8());
82 Franz 511
}
512
 
243 Franz 513
 
237 Franz 514
/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
515
 */
2790 craig 516
PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args)
82 Franz 517
{
934 subik 518
        char *Name = const_cast<char*>("");
900 cbradney 519
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
22537 craig 520
                return nullptr;
22654 jghali 521
        if (!checkHaveDocument())
22537 craig 522
                return nullptr;
900 cbradney 523
        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
22537 craig 524
        if (i == nullptr)
525
                return nullptr;
5781 cbradney 526
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
527
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
528
        ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem();
22658 jghali 529
 
8319 fschmid 530
        Py_RETURN_NONE;
82 Franz 531
}
532
 
23691 jghali 533
PyObject *scribus_gettextflowmode(PyObject* /* self */, PyObject* args)
534
{
535
        char *name = const_cast<char*>("");
536
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
537
                return NULL;
538
        if (!checkHaveDocument())
539
                return NULL;
540
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
541
        if (item == NULL)
542
                return NULL;
243 Franz 543
 
23691 jghali 544
        return PyLong_FromLong(static_cast<int>(item->textFlowMode()));
545
};
546
 
237 Franz 547
/* 03/21/2004 - exception raises by non existent name (subik)
548
 */
23690 jghali 549
PyObject *scribus_settextflowmode(PyObject* /* self */, PyObject* args)
214 Franz 550
{
934 subik 551
        char *name = const_cast<char*>("");
332 Franz 552
        int state = -1;
214 Franz 553
 
900 cbradney 554
        if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
22537 craig 555
                return nullptr;
22654 jghali 556
        if (!checkHaveDocument())
22537 craig 557
                return nullptr;
900 cbradney 558
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
22537 craig 559
        if (i == nullptr)
560
                return nullptr;
214 Franz 561
        if (state == -1)
5620 jghali 562
        {
563
                if (i->textFlowAroundObject())
564
                        i->setTextFlowMode(PageItem::TextFlowDisabled);
565
                else
566
                        i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
567
        }
22654 jghali 568
        else if (state == (int) PageItem::TextFlowDisabled )
5620 jghali 569
                i->setTextFlowMode(PageItem::TextFlowDisabled);
22654 jghali 570
        else if (state == (int) PageItem::TextFlowUsesFrameShape )
5620 jghali 571
                i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
22654 jghali 572
        else if (state == (int) PageItem::TextFlowUsesBoundingBox )
5620 jghali 573
                i->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
22654 jghali 574
        else if (state == (int) PageItem::TextFlowUsesContourLine )
5620 jghali 575
                i->setTextFlowMode(PageItem::TextFlowUsesContourLine);
5781 cbradney 576
        ScCore->primaryMainWindow()->view->DrawNew();
577
        ScCore->primaryMainWindow()->slotDocCh(true);
22658 jghali 578
 
8319 fschmid 579
        Py_RETURN_NONE;
214 Franz 580
}
243 Franz 581
 
582
 
2790 craig 583
PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
243 Franz 584
{
934 subik 585
        char* name = const_cast<char*>("");
900 cbradney 586
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
22537 craig 587
                return nullptr;
22654 jghali 588
        if (!checkHaveDocument())
22537 craig 589
                return nullptr;
900 cbradney 590
        if (ItemExists(QString::fromUtf8(name)))
720 subik 591
                return PyBool_FromLong(static_cast<long>(true));
592
        return PyBool_FromLong(static_cast<long>(false));
243 Franz 593
}
594
 
23687 jghali 595
PyObject *scribus_getcharacterstyle(PyObject* /* self */, PyObject* args)
596
{
597
        char *name = const_cast<char*>("");
598
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
599
                return NULL;
600
        if (!checkHaveDocument())
601
                return NULL;
602
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
603
        if (item == NULL)
604
                return NULL;
605
        if ((item->itemType() != PageItem::TextFrame) && (item->itemType() != PageItem::PathText))
606
        {
607
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get character style of a non-text frame.", "python error").toLocal8Bit().constData());
608
                return NULL;
609
        }
22654 jghali 610
 
23687 jghali 611
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
612
        StoryText&  itemText = item->itemText;
613
 
614
        int selectionLength = itemText.selectionLength();      
615
        if ((selectionLength > 0) || (currentDoc->appMode == modeEdit))
616
        {
617
                int cursorPos = (selectionLength > 0) ? itemText.startOfSelection() : itemText.cursorPosition();
618
                const CharStyle& currentStyle = itemText.charStyle(cursorPos);
619
                if (currentStyle.hasParent())
620
                        return PyUnicode_FromString(currentStyle.parentStyle()->name().toUtf8());
621
        }
622
        else
623
        {
624
                const CharStyle& itemDefaultStyle = itemText.defaultStyle().charStyle();
625
                if (itemDefaultStyle.hasParent())
626
                        return PyUnicode_FromString(itemDefaultStyle.parentStyle()->name().toUtf8());
627
        }
628
        Py_RETURN_NONE;
629
};
630
 
411 Franz 631
/*
22654 jghali 632
 * Vaclav Smilauer, 2017-21-21
633
 * Return style name of the object (or currently selected object)
634
 */
23686 jghali 635
PyObject *scribus_getparagraphstyle(PyObject* /* self */, PyObject* args)
22654 jghali 636
{
637
        char *name = const_cast<char*>("");
638
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
639
                return NULL;
640
        if (!checkHaveDocument())
641
                return NULL;
642
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
643
        if (item == NULL)
644
                return NULL;
645
        if ((item->itemType() != PageItem::TextFrame) && (item->itemType() != PageItem::PathText))
646
        {
647
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get style of a non-text frame.", "python error").toLocal8Bit().constData());
648
                return NULL;
649
        }
650
 
23687 jghali 651
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
652
        StoryText&  itemText = item->itemText;
653
 
654
        int selectionLength = itemText.selectionLength();      
655
        if ((selectionLength > 0) || (currentDoc->appMode == modeEdit))
22654 jghali 656
        {
23687 jghali 657
                int cursorPos = (selectionLength > 0) ? itemText.startOfSelection() : itemText.cursorPosition();
658
                const ParagraphStyle& currentStyle = itemText.paragraphStyle(cursorPos);
22654 jghali 659
                if (currentStyle.hasParent())
23278 jghali 660
                        return PyUnicode_FromString(currentStyle.parentStyle()->name().toUtf8());
22654 jghali 661
        }
662
        else
663
        {
664
                const ParagraphStyle& itemDefaultStyle = item->itemText.defaultStyle();
665
                if (itemDefaultStyle.hasParent())
23278 jghali 666
                        return PyUnicode_FromString(itemDefaultStyle.parentStyle()->name().toUtf8());
22654 jghali 667
        }
668
        Py_RETURN_NONE;
669
};
670
 
671
 
672
 
673
/*
411 Franz 674
 * Craig Ringer, 2004-09-09
675
 * Apply the named style to the currently selected object.
676
 * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
677
 */
23686 jghali 678
PyObject *scribus_setparagraphstyle(PyObject* /* self */, PyObject* args)
411 Franz 679
{
934 subik 680
        char *style = const_cast<char*>("");
681
        char *name = const_cast<char*>("");
900 cbradney 682
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
22537 craig 683
                return nullptr;
22654 jghali 684
        if (!checkHaveDocument())
22537 craig 685
                return nullptr;
900 cbradney 686
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
22537 craig 687
        if (item == nullptr)
688
                return nullptr;
22114 jghali 689
        if ((item->itemType() != PageItem::TextFrame) && (item->itemType() != PageItem::PathText))
411 Franz 690
        {
22114 jghali 691
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.", "python error").toLocal8Bit().constData());
22537 craig 692
                return nullptr;
22114 jghali 693
        }
23689 jghali 694
 
22114 jghali 695
        ScribusDoc*  currentDoc = ScCore->primaryMainWindow()->doc;
696
        ScribusView* currentView = ScCore->primaryMainWindow()->view;
697
        ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
23689 jghali 698
 
699
        // First, check if style name provided by user is available in document
700
        QString paraStyleName = QString::fromUtf8(style);
701
        if (!currentDoc->paragraphStyles().contains(paraStyleName))
22114 jghali 702
        {
703
                // whoops, the user specified an invalid style, complain loudly.
23689 jghali 704
                // FIXME: Should use a more specific exception.
22114 jghali 705
                PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error").toLocal8Bit().constData());
22537 craig 706
                return nullptr;
22114 jghali 707
        }
23689 jghali 708
 
709
        // For multiple selections or if current item has no text selected, we apply style in normal mode
710
        if (currentDoc->m_Selection->isMultipleSelection() || (item->itemText.selectionLength() <= 0))
22114 jghali 711
        {
712
                int mode = currentDoc->appMode;
713
                currentDoc->appMode = modeNormal;
714
                currentDoc->itemSelection_SetNamedParagraphStyle(paraStyleName);
715
                currentDoc->appMode = mode;
23689 jghali 716
                Py_RETURN_NONE;
720 subik 717
        }
22658 jghali 718
 
23689 jghali 719
        // For single items which have a text selection, we apply style in edit mode
720
        // Store text selection as clearing object selection
721
        // will also clear text selection
722
        int selectionStart =  item->itemText.startOfSelection();
723
        int selectionLength = item->itemText.selectionLength();
724
        // Quick hack to always apply on the right frame - pv
725
        currentView->deselectItems(true);
726
        //CB I dont think we need to draw here. Its faster if we dont.
727
        currentView->selectItem(item, false);
728
        // Restore text selection if necessary
729
        if (selectionStart >= 0)
730
        {
731
                item->itemText.deselectAll();
732
                item->itemText.select(selectionStart, selectionLength);
733
                item->HasSel = true;
734
        }
735
        // Now apply the style.
736
        int mode = currentDoc->appMode;
737
        currentDoc->appMode = modeEdit;
738
        currentWin->setNewParStyle(paraStyleName);
739
        currentDoc->appMode = mode;
740
 
8319 fschmid 741
        Py_RETURN_NONE;
411 Franz 742
}
743
 
744
/*
22113 jghali 745
* Jean Ghali, 2017-07-18
746
* Apply the named character style to the currently selected object.
747
* pv, 2004-09-13, optionaly param objectName + "check the page" stuff
748
*/
749
PyObject *scribus_setcharstyle(PyObject* /* self */, PyObject* args)
750
{
751
        char *style = const_cast<char*>("");
752
        char *name = const_cast<char*>("");
753
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
22537 craig 754
                return nullptr;
22113 jghali 755
        if (!checkHaveDocument())
22537 craig 756
                return nullptr;
22113 jghali 757
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
22537 craig 758
        if (item == nullptr)
759
                return nullptr;
22114 jghali 760
        if ((item->itemType() != PageItem::TextFrame) && (item->itemType() != PageItem::PathText))
22113 jghali 761
        {
22114 jghali 762
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character style on a non-text frame.", "python error").toLocal8Bit().constData());
22537 craig 763
                return nullptr;
22114 jghali 764
        }
23689 jghali 765
 
22114 jghali 766
        ScribusDoc*  currentDoc = ScCore->primaryMainWindow()->doc;
767
        ScribusView* currentView = ScCore->primaryMainWindow()->view;
768
        ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
23689 jghali 769
 
770
        // First, check if style name provided by user is available in document
771
        QString charStyleName = QString::fromUtf8(style);
772
        if (!currentDoc->charStyles().contains(charStyleName))
22114 jghali 773
        {
774
                // whoops, the user specified an invalid style, complain loudly.
23689 jghali 775
                // FIXME: Should use a more specific exception.
22114 jghali 776
                PyErr_SetString(NotFoundError, QObject::tr("Character style not found.", "python error").toLocal8Bit().constData());
22537 craig 777
                return nullptr;
22114 jghali 778
        }
23689 jghali 779
 
780
        // For multiple selections or if current item has no text selected, we apply style in normal mode
781
        if (currentDoc->m_Selection->isMultipleSelection() || (item->itemText.selectionLength() <= 0))
22114 jghali 782
        {
783
                int mode = currentDoc->appMode;
784
                currentDoc->appMode = modeNormal;
785
                currentDoc->itemSelection_SetNamedCharStyle(charStyleName);
786
                currentDoc->appMode = mode;
23689 jghali 787
                Py_RETURN_NONE;
22113 jghali 788
        }
22658 jghali 789
 
23689 jghali 790
        // For single items which have a text selection, we apply style in edit mode
791
        // Store text selection as clearing object selection
792
        // will also clear text selection
793
        int selectionStart =  item->itemText.startOfSelection();
794
        int selectionLength = item->itemText.selectionLength();
795
 
796
        // Quick hack to always apply on the right frame - pv
797
        currentView->deselectItems(true);
798
        //CB I dont think we need to draw here. Its faster if we dont.
799
        currentView->selectItem(item, false);
800
        // Restore text selection if necessary
801
        if (selectionStart >= 0)
802
        {
803
                item->itemText.deselectAll();
804
                item->itemText.select(selectionStart, selectionLength);
805
                item->HasSel = true;
806
        }      
807
        // Now apply the style.
808
        int mode = ScCore->primaryMainWindow()->doc->appMode;
809
        currentDoc->appMode = modeEdit;
810
        currentWin->setNewCharStyle(charStyleName);
811
        currentDoc->appMode = mode;
812
 
22113 jghali 813
        Py_RETURN_NONE;
814
}
815
 
5997 subik 816
PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args)
817
{
818
        char* name = const_cast<char*>("");
22659 jghali 819
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
22537 craig 820
                return nullptr;
22659 jghali 821
        if (!checkHaveDocument())
22537 craig 822
                return nullptr;
22659 jghali 823
 
5997 subik 824
        // Is there a special name given? Yes -> add this to selection
22659 jghali 825
        ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
826
        ScribusDoc* currentDoc = currentWin->doc;
827
 
5997 subik 828
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
22659 jghali 829
        if (i == nullptr)
22537 craig 830
                return nullptr;
22659 jghali 831
        currentDoc->m_Selection->clear();
832
        currentDoc->m_Selection->addItem(i);
833
 
5997 subik 834
        // do the duplicate
22659 jghali 835
        currentWin->slotEditCopy();
836
        currentWin->slotEditPaste();
22658 jghali 837
 
23373 craig 838
        return PyUnicode_FromString(currentDoc->m_Selection->itemAt(0)->itemName().toUtf8());
5997 subik 839
}
6200 subik 840
 
19332 gpittman 841
PyObject *scribus_copyobject(PyObject * /* self */, PyObject *args)
842
{
843
        char* name = const_cast<char*>("");
22659 jghali 844
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
22537 craig 845
                return nullptr;
22659 jghali 846
        if (!checkHaveDocument())
22537 craig 847
                return nullptr;
22659 jghali 848
 
19332 gpittman 849
        // Is there a special name given? Yes -> add this to selection
22659 jghali 850
        ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
851
        ScribusDoc* currentDoc = currentWin->doc;
852
 
19332 gpittman 853
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
22659 jghali 854
        if (i == nullptr)
22537 craig 855
                return nullptr;
22659 jghali 856
        currentDoc->m_Selection->clear();
857
        currentDoc->m_Selection->addItem(i);
858
 
19332 gpittman 859
        // do the copy
22659 jghali 860
        currentWin->slotEditCopy();
22658 jghali 861
 
19332 gpittman 862
        Py_RETURN_NONE;
863
}
864
 
865
PyObject *scribus_pasteobject(PyObject * /* self */, PyObject *args)
866
{
867
        char* name = const_cast<char*>("");
22659 jghali 868
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
22537 craig 869
                return nullptr;
22659 jghali 870
        if (!checkHaveDocument())
22537 craig 871
                return nullptr;
19332 gpittman 872
 
873
        // do the paste
874
        ScCore->primaryMainWindow()->slotEditPaste();
22658 jghali 875
 
19332 gpittman 876
        Py_RETURN_NONE;
877
}
878
 
6200 subik 879
/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
880
with header files structure untouched (docstrings are kept near declarations)
881
PV */
882
void cmdobjdocwarnings()
883
{
20424 jghali 884
        QStringList s;
23427 jghali 885
        s << scribus_bezierline__doc__
886
          << scribus_copyobject__doc__
887
          << scribus_deleteobj__doc__
888
          << scribus_duplicateobject__doc__
23687 jghali 889
          << scribus_getcharacterstyle__doc__
23686 jghali 890
          << scribus_getparagraphstyle__doc__
23427 jghali 891
          << scribus_getstyle__doc__
892
          << scribus_newellipse__doc__
893
          << scribus_newimage__doc__
894
          << scribus_newline__doc__
895
          << scribus_newrect__doc__
896
          << scribus_newtable__doc__
897
          << scribus_newtext__doc__
898
          << scribus_objectexists__doc__
899
          << scribus_pasteobject__doc__
900
          << scribus_pathtext__doc__
901
          << scribus_polygon__doc__
902
          << scribus_polyline__doc__
23492 jghali 903
          << scribus_setcharstyle__doc__
23686 jghali 904
          << scribus_setparagraphstyle__doc__
23427 jghali 905
          << scribus_setstyle__doc__
23690 jghali 906
          << scribus_settextflowmode__doc__
907
          << scribus_textflowmode__doc__;
6200 subik 908
}