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 */
7 #include "cmdmani.h"
8 #include "cmdutil.h"
9 #include "scribuscore.h"
10 #include "scribusdoc.h"
11 #include "scribusview.h"
12 #include "sctextstream.h"
13 #include "selection.h"
14 #include "undomanager.h"
15
scribus_loadimage(PyObject *,PyObject * args)16 PyObject *scribus_loadimage(PyObject* /* self */, PyObject* args)
17 {
18 char *Name = const_cast<char*>("");
19 char *Image;
20 if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Image, "utf-8", &Name))
21 return nullptr;
22 if (!checkHaveDocument())
23 return nullptr;
24 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
25 if (item == nullptr)
26 return nullptr;
27 if (!item->isImageFrame())
28 {
29 PyErr_SetString(WrongFrameTypeError, QObject::tr("Target is not an image frame.","python error").toLocal8Bit().constData());
30 return nullptr;
31 }
32 ScCore->primaryMainWindow()->doc->loadPict(QString::fromUtf8(Image), item);
33 Py_RETURN_NONE;
34 }
35
scribus_scaleimage(PyObject *,PyObject * args)36 PyObject *scribus_scaleimage(PyObject* /* self */, PyObject* args)
37 {
38 char *Name = const_cast<char*>("");
39 double x, y;
40 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
41 return nullptr;
42 if (!checkHaveDocument())
43 return nullptr;
44 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
45 if (item == nullptr)
46 return nullptr;
47 if (!item->isImageFrame())
48 {
49 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
50 return nullptr;
51 }
52
53 // Grab the old selection - but use it only where is there any
54 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
55 ScribusView* currentView = ScCore->primaryMainWindow()->view;
56 Selection tempSelection(*currentDoc->m_Selection);
57 bool hadOrigSelection = (tempSelection.count() != 0);
58
59 currentDoc->m_Selection->clear();
60 // Clear the selection
61 currentView->deselectItems();
62 // Select the item, which will also select its group if
63 // there is one.
64 currentView->selectItem(item);
65
66 // scale
67 currentDoc->itemSelection_SetImageScale(x, y); //CB why when this is done above?
68 currentDoc->updatePic();
69
70 // Now restore the selection.
71 currentView->deselectItems();
72 if (hadOrigSelection)
73 *currentDoc->m_Selection=tempSelection;
74
75 Py_RETURN_NONE;
76 }
77
scribus_setimagescale(PyObject *,PyObject * args)78 PyObject *scribus_setimagescale(PyObject* /* self */, PyObject* args)
79 {
80 char *Name = const_cast<char*>("");
81 double x, y;
82 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
83 return nullptr;
84 if (!checkHaveDocument())
85 return nullptr;
86 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
87 if (item == nullptr)
88 return nullptr;
89 if (!item->isImageFrame())
90 {
91 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
92 return nullptr;
93 }
94
95 // Grab the old selection - but use it only where is there any
96 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
97 ScribusView* currentView = ScCore->primaryMainWindow()->view;
98 Selection tempSelection(*currentDoc->m_Selection);
99 bool hadOrigSelection = (tempSelection.count() != 0);
100
101 currentDoc->m_Selection->clear();
102 // Clear the selection
103 currentView->deselectItems();
104 // Select the item, which will also select its group if
105 // there is one.
106 currentView->selectItem(item);
107
108 // scale
109 double newScaleX = x / item->pixm.imgInfo.xres * 72.0;
110 double newScaleY = y / item->pixm.imgInfo.yres * 72.0;
111 currentDoc->itemSelection_SetImageScale(newScaleX, newScaleY); //CB why when this is done above?
112 currentDoc->updatePic();
113
114 // Now restore the selection.
115 currentView->deselectItems();
116 if (hadOrigSelection)
117 *currentDoc->m_Selection=tempSelection;
118
119 Py_RETURN_NONE;
120 }
scribus_setimageoffset(PyObject *,PyObject * args)121 PyObject *scribus_setimageoffset(PyObject* /* self */, PyObject* args)
122 {
123 char *Name = const_cast<char*>("");
124 double x, y;
125 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
126 return nullptr;
127 if (!checkHaveDocument())
128 return nullptr;
129 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
130 if (item == nullptr)
131 return nullptr;
132 if (!item->isImageFrame())
133 {
134 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
135 return nullptr;
136 }
137
138 // Grab the old selection - but use it only where is there any
139 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
140 ScribusView* currentView = ScCore->primaryMainWindow()->view;
141 Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
142 bool hadOrigSelection = (tempSelection.count() != 0);
143
144 currentDoc->m_Selection->clear();
145 // Clear the selection
146 currentView->deselectItems();
147 // Select the item, which will also select its group if
148 // there is one.
149 currentView->selectItem(item);
150
151 // offset
152 double newOffsetX = x / ((item->imageXScale() != 0.0) ? item->imageXScale() : 1);
153 double newOffsetY = y / ((item->imageYScale() != 0.0) ? item->imageYScale() : 1);
154 currentDoc->itemSelection_SetImageOffset(newOffsetX, newOffsetY); //CB why when this is done above?
155 currentDoc->updatePic();
156
157 // Now restore the selection.
158 currentView->deselectItems();
159 if (hadOrigSelection)
160 *currentDoc->m_Selection=tempSelection;
161
162 Py_RETURN_NONE;
163 }
164
scribus_setimagebrightness(PyObject *,PyObject * args)165 PyObject *scribus_setimagebrightness(PyObject* /* self */, PyObject* args)
166 {
167 char *Name = const_cast<char*>("");
168 double n;
169 if (!PyArg_ParseTuple(args, "d|es", &n, "utf-8", &Name))
170 return nullptr;
171 if (!checkHaveDocument())
172 return nullptr;
173 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
174 if (item == nullptr)
175 return nullptr;
176 if (!item->isImageFrame())
177 {
178 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
179 return nullptr;
180 }
181
182 ImageEffect ef;
183 ef.effectCode = ImageEffect::EF_BRIGHTNESS;
184 ScTextStream fp(&ef.effectParameters, QIODevice::WriteOnly);
185 fp << n;
186
187 item->effectsInUse.append(ef);
188 item->pixm.applyEffect(item->effectsInUse, ScCore->primaryMainWindow()->doc->PageColors, false);
189
190 ScCore->primaryMainWindow()->doc->updatePic();
191 Py_RETURN_NONE;
192 }
193
scribus_setimagegrayscale(PyObject *,PyObject * args)194 PyObject *scribus_setimagegrayscale(PyObject* /* self */, PyObject* args)
195 {
196 char *Name = const_cast<char*>("");
197 if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
198 return nullptr;
199 if (!checkHaveDocument())
200 return nullptr;
201 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
202 if (item == nullptr)
203 return nullptr;
204 if (!item->isImageFrame())
205 {
206 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
207 return nullptr;
208 }
209
210 ImageEffect ef;
211 ef.effectCode = ImageEffect::EF_GRAYSCALE;
212
213 item->effectsInUse.append(ef);
214 item->pixm.applyEffect(item->effectsInUse, ScCore->primaryMainWindow()->doc->PageColors, false);
215
216 ScCore->primaryMainWindow()->doc->updatePic();
217 Py_RETURN_NONE;
218 }
219
scribus_moveobjectrel(PyObject *,PyObject * args)220 PyObject *scribus_moveobjectrel(PyObject* /* self */, PyObject* args)
221 {
222 char *Name = const_cast<char*>("");
223 double x, y;
224 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
225 return nullptr;
226 if (!checkHaveDocument())
227 return nullptr;
228 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
229 if (item==nullptr)
230 return nullptr;
231
232 // Grab the old selection - but use it only where is there any
233 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
234 ScribusView* currentView = ScCore->primaryMainWindow()->view;
235 Selection tempSelection(*currentDoc->m_Selection);
236 bool hadOrigSelection = (tempSelection.count() != 0);
237
238 currentDoc->m_Selection->clear();
239 // Clear the selection
240 currentView->deselectItems();
241 // Select the item, which will also select its group if
242 // there is one.
243 currentView->selectItem(item);
244 // Move the item, or items
245 if (currentDoc->m_Selection->count() > 1)
246 {
247 currentView->startGroupTransaction(Um::Move, "", Um::IMove);
248 currentDoc->moveGroup(ValueToPoint(x), ValueToPoint(y));
249 currentView->endGroupTransaction();
250 }
251 else {
252 currentDoc->moveItem(ValueToPoint(x), ValueToPoint(y), item);
253 }
254 // Now restore the selection.
255 currentView->deselectItems();
256 if (hadOrigSelection)
257 *currentDoc->m_Selection=tempSelection;
258 Py_RETURN_NONE;
259 }
260
scribus_moveobjectabs(PyObject *,PyObject * args)261 PyObject *scribus_moveobjectabs(PyObject* /* self */, PyObject* args)
262 {
263 char *Name = const_cast<char*>("");
264 double x, y;
265 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
266 return nullptr;
267 if (!checkHaveDocument())
268 return nullptr;
269 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
270 if (item == nullptr)
271 return nullptr;
272
273 // Grab the old selection - but use it only where is there any
274 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
275 ScribusView* currentView = ScCore->primaryMainWindow()->view;
276 Selection tempSelection(*currentDoc->m_Selection);
277 bool hadOrigSelection = (tempSelection.count() != 0);
278
279 // Clear the selection
280 currentView->deselectItems();
281 // Select the item, which will also select its group if
282 // there is one.
283 currentView->selectItem(item);
284 // Move the item, or items
285 if (currentDoc->m_Selection->count() > 1)
286 {
287 currentView->startGroupTransaction(Um::Move, "", Um::IMove);
288 double x2, y2, w, h;
289 currentDoc->m_Selection->getGroupRect(&x2, &y2, &w, &h);
290 currentDoc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
291 currentView->endGroupTransaction();
292 }
293 else
294 currentDoc->moveItem(pageUnitXToDocX(x) - item->xPos(), pageUnitYToDocY(y) - item->yPos(), item);
295 // Now restore the selection.
296 currentView->deselectItems();
297 if (hadOrigSelection)
298 *currentDoc->m_Selection=tempSelection;
299
300 Py_RETURN_NONE;
301 }
302
scribus_rotateobjectrel(PyObject *,PyObject * args)303 PyObject *scribus_rotateobjectrel(PyObject* /* self */, PyObject* args)
304 {
305 char *Name = const_cast<char*>("");
306 double x;
307 if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name))
308 return nullptr;
309 if (!checkHaveDocument())
310 return nullptr;
311 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
312 if (item == nullptr)
313 return nullptr;
314 ScCore->primaryMainWindow()->doc->rotateItem(item->rotation() - x, item);
315 Py_RETURN_NONE;
316 }
317
scribus_rotateobjectabs(PyObject *,PyObject * args)318 PyObject *scribus_rotateobjectabs(PyObject* /* self */, PyObject* args)
319 {
320 char *Name = const_cast<char*>("");
321 double x;
322 if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name))
323 return nullptr;
324 if (!checkHaveDocument())
325 return nullptr;
326 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
327 if (item == nullptr)
328 return nullptr;
329 ScCore->primaryMainWindow()->doc->rotateItem(x * -1.0, item);
330 Py_RETURN_NONE;
331 }
332
scribus_sizeobject(PyObject *,PyObject * args)333 PyObject *scribus_sizeobject(PyObject* /* self */, PyObject* args)
334 {
335 char *Name = const_cast<char*>("");
336 double x, y;
337 if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
338 return nullptr;
339 if (!checkHaveDocument())
340 return nullptr;
341 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
342 if (item == nullptr)
343 return nullptr;
344 ScCore->primaryMainWindow()->doc->sizeItem(ValueToPoint(x), ValueToPoint(y), item);
345 Py_RETURN_NONE;
346 }
347
scribus_groupobjects(PyObject *,PyObject * args)348 PyObject *scribus_groupobjects(PyObject* /* self */, PyObject* args)
349 {
350 char *Name = const_cast<char*>("");
351 PyObject *il = nullptr;
352 if (!PyArg_ParseTuple(args, "|O", &il))
353 return nullptr;
354 if (!checkHaveDocument())
355 return nullptr;
356 if (il == nullptr && ScCore->primaryMainWindow()->doc->m_Selection->count() < 2)
357 {
358 PyErr_SetString(PyExc_TypeError, QObject::tr("Need selection or argument list of items to group", "python error").toLocal8Bit().constData());
359 return nullptr;
360 }
361 Selection *tempSelection = nullptr;
362 Selection *finalSelection = nullptr;
363 //uint ap = ScCore->primaryMainWindow()->doc->currentPage()->pageNr();
364 // If we were passed a list of items to group...
365 if (il != nullptr)
366 {
367 int len = PyList_Size(il);
368 tempSelection = new Selection(ScCore->primaryMainWindow(), false);
369 for (int i = 0; i < len; i++)
370 {
371 // FIXME: We might need to explicitly get this string as utf8
372 // but as sysdefaultencoding is utf8 it should be a no-op to do
373 // so anyway.
374 Name = PyString_AsString(PyList_GetItem(il, i));
375 PageItem *ic = GetUniqueItem(QString::fromUtf8(Name));
376 if (ic == nullptr)
377 {
378 delete tempSelection;
379 return nullptr;
380 }
381 tempSelection->addItem (ic, true);
382 }
383 finalSelection = tempSelection;
384 }
385 else
386 finalSelection = ScCore->primaryMainWindow()->doc->m_Selection;
387 if (finalSelection->count() < 2)
388 {
389 // We can't very well group only one item
390 PyErr_SetString(NoValidObjectError, QObject::tr("Cannot group less than two items", "python error").toLocal8Bit().constData());
391 finalSelection=nullptr;
392 delete tempSelection;
393 return nullptr;
394 }
395
396 const PageItem* group = ScCore->primaryMainWindow()->doc->itemSelection_GroupObjects(false, false, finalSelection);
397 finalSelection=nullptr;
398 delete tempSelection;
399
400 return (group ? PyString_FromString(group->itemName().toUtf8()) : nullptr);
401 }
402
scribus_ungroupobjects(PyObject *,PyObject * args)403 PyObject *scribus_ungroupobjects(PyObject* /* self */, PyObject* args)
404 {
405 char *Name = const_cast<char*>("");
406 if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
407 return nullptr;
408 if (!checkHaveDocument())
409 return nullptr;
410 PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
411 if (i == nullptr)
412 return nullptr;
413
414 ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
415 currentWin->view->deselectItems();
416 currentWin->view->selectItem(i);
417 currentWin->UnGroupObj();
418
419 Py_RETURN_NONE;
420 }
421
scribus_scalegroup(PyObject *,PyObject * args)422 PyObject *scribus_scalegroup(PyObject* /* self */, PyObject* args)
423 {
424 char *Name = const_cast<char*>("");
425 double sc;
426 if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name))
427 return nullptr;
428 if (!checkHaveDocument())
429 return nullptr;
430 if (sc == 0.0)
431 {
432 PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot scale by 0%.","python error").toLocal8Bit().constData());
433 return nullptr;
434 }
435 PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
436 if (i == nullptr)
437 return nullptr;
438
439 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
440 ScribusView* currentView = ScCore->primaryMainWindow()->view;
441
442 currentView->deselectItems();
443 currentView->selectItem(i);
444 // int h = currentView->frameResizeHandle;
445 // currentView->frameResizeHandle = 1;
446 currentView->startGroupTransaction(Um::Resize, "", Um::IResize);
447 currentDoc->scaleGroup(sc, sc);
448 currentView->endGroupTransaction();
449 // currentView->frameResizeHandle = h;
450 Py_RETURN_NONE;
451 }
452
scribus_getselectedobject(PyObject *,PyObject * args)453 PyObject *scribus_getselectedobject(PyObject* /* self */, PyObject* args)
454 {
455 int i = 0;
456 if (!PyArg_ParseTuple(args, "|i", &i))
457 return nullptr;
458 if (!checkHaveDocument())
459 return nullptr;
460 Selection * selection = ScCore->primaryMainWindow()->doc->m_Selection;
461 if ((i < selection->count()) && (i > -1))
462 return PyString_FromString(selection->itemAt(i)->itemName().toUtf8());
463 // FIXME: Should probably return None if no selection?
464 return PyString_FromString("");
465 }
466
scribus_selectioncount(PyObject *)467 PyObject *scribus_selectioncount(PyObject* /* self */)
468 {
469 if (!checkHaveDocument())
470 return nullptr;
471 return PyInt_FromLong(static_cast<long>(ScCore->primaryMainWindow()->doc->m_Selection->count()));
472 }
473
scribus_selectobject(PyObject *,PyObject * args)474 PyObject *scribus_selectobject(PyObject* /* self */, PyObject* args)
475 {
476 char *Name = const_cast<char*>("");
477 if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
478 return nullptr;
479 if (!checkHaveDocument())
480 return nullptr;
481 PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
482 if (i == nullptr)
483 return nullptr;
484 ScCore->primaryMainWindow()->view->selectItem(i);
485 Py_RETURN_NONE;
486 }
487
scribus_deselectall(PyObject *)488 PyObject *scribus_deselectall(PyObject* /* self */)
489 {
490 if (!checkHaveDocument())
491 return nullptr;
492 ScCore->primaryMainWindow()->view->deselectItems();
493 Py_RETURN_NONE;
494 }
495
scribus_lockobject(PyObject *,PyObject * args)496 PyObject *scribus_lockobject(PyObject* /* self */, PyObject* args)
497 {
498 char *name = const_cast<char*>("");
499 if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
500 return nullptr;
501 if (!checkHaveDocument())
502 return nullptr;
503 PageItem *item = GetUniqueItem(QString::fromUtf8(name));
504 if (item == nullptr)
505 return nullptr;
506 // FIXME: Rather than toggling the lock, we should probably let the user set the lock state
507 // and instead provide a different function like toggleLock()
508 item->toggleLock();
509 if (item->locked())
510 return PyInt_FromLong(1);
511 return PyInt_FromLong(0);
512 }
513
scribus_islocked(PyObject *,PyObject * args)514 PyObject *scribus_islocked(PyObject* /* self */, PyObject* args)
515 {
516 char *name = const_cast<char*>("");
517 if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
518 return nullptr;
519 if (!checkHaveDocument())
520 return nullptr;
521 PageItem *item = GetUniqueItem(QString::fromUtf8(name));
522 if (item == nullptr)
523 return nullptr;
524 if (item->locked())
525 return PyBool_FromLong(1);
526 return PyBool_FromLong(0);
527 }
528
scribus_setscaleframetoimage(PyObject *,PyObject * args)529 PyObject *scribus_setscaleframetoimage(PyObject* /* self */, PyObject* args)
530 {
531 if (!checkHaveDocument())
532 return nullptr;
533 char *Name = const_cast<char*>("");
534 if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
535 return nullptr;
536 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
537 if (item == nullptr)
538 return nullptr;
539 if (!item->isImageFrame())
540 {
541 PyErr_SetString(WrongFrameTypeError, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
542 return nullptr;
543 }
544 Selection *sel = new Selection(ScCore->primaryMainWindow());
545 sel->addItem(item);
546 ScCore->primaryMainWindow()->doc->itemSelection_AdjustFrametoImageSize(sel);
547 delete sel;
548
549 Py_RETURN_NONE;
550 }
551
scribus_setscaleimagetoframe(PyObject *,PyObject * args,PyObject * kw)552 PyObject *scribus_setscaleimagetoframe(PyObject* /* self */, PyObject* args, PyObject* kw)
553 {
554 char *name = const_cast<char*>("");
555 long int scaleToFrame = 0;
556 long int proportional = 1;
557 char* kwargs[] = {const_cast<char*>("scaletoframe"),
558 const_cast<char*>("proportional"), const_cast<char*>("name"), nullptr};
559 if (!PyArg_ParseTupleAndKeywords(args, kw, "i|ies", kwargs, &scaleToFrame, &proportional, "utf-8", &name))
560 return nullptr;
561 if (!checkHaveDocument())
562 return nullptr;
563 PageItem *item = GetUniqueItem(QString::fromUtf8(name));
564 if (item == nullptr)
565 return nullptr;
566 if (!item->isImageFrame())
567 {
568 PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
569 return nullptr;
570 }
571 // Set the item to scale if appropriate. ScaleType 1 is free
572 // scale, 0 is scale to frame.
573 item->ScaleType = scaleToFrame == 0;
574 // Now, if the user has chosen to set the proportional mode,
575 // set it. 1 is proportional, 0 is free aspect.
576 if (proportional != -1)
577 item->AspectRatio = proportional > 0;
578
579 item->adjustPictScale();
580 item->update();
581
582 Py_RETURN_NONE;
583 }
scribus_flipobject(PyObject *,PyObject * args)584 PyObject *scribus_flipobject(PyObject* /* self */, PyObject* args)
585 {
586 char *Name = const_cast<char*>("");
587 double h, v;
588 if (!PyArg_ParseTuple(args, "dd|es", &h, &v, "utf-8", &Name))
589 return nullptr;
590 if (!checkHaveDocument())
591 return nullptr;
592 PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
593 if (item == nullptr)
594 return nullptr;
595
596 // Grab the old selection - but use it only where is there any
597 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
598 ScribusView* currentView = ScCore->primaryMainWindow()->view;
599 Selection tempSelection(*currentDoc->m_Selection);
600 bool hadOrigSelection = (tempSelection.count() != 0);
601
602 currentDoc->m_Selection->clear();
603 // Clear the selection
604 currentView->deselectItems();
605 // Select the item, which will also select its group if
606 // there is one.
607 currentView->selectItem(item);
608
609 // flip
610 if (h == 1)
611 currentDoc->itemSelection_FlipH();
612 if (v == 1)
613 currentDoc->itemSelection_FlipV();
614 // Now restore the selection.
615 currentView->deselectItems();
616 if (hadOrigSelection)
617 *currentDoc->m_Selection = tempSelection;
618
619 Py_RETURN_NONE;
620 }
621
scribus_combinepolygons(PyObject *)622 PyObject *scribus_combinepolygons(PyObject * /* self */)
623 {
624 if (!checkHaveDocument())
625 return nullptr;
626
627 ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
628 Selection* curSelection = currentDoc->m_Selection;
629 if (curSelection->count() <= 1)
630 Py_RETURN_NONE;
631
632 bool canUniteItems = true;
633 for (int i = 0; i < curSelection->count(); ++i)
634 {
635 PageItem* it = currentDoc->m_Selection->itemAt(i);
636 if ((!it->isPolygon()) || (!it->isPolyLine()))
637 canUniteItems = false;
638 }
639
640 if (!canUniteItems)
641 {
642 PyErr_SetString(WrongFrameTypeError, QObject::tr("Selection must contain only shapes or bezier curves.", "python error").toLocal8Bit().constData());
643 return nullptr;
644 }
645 currentDoc->itemSelection_UniteItems(nullptr);
646
647 Py_RETURN_NONE;
648 }
649
650 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
651 with header files structure untouched (docstrings are kept near declarations)
652 PV */
cmdmanidocwarnings()653 void cmdmanidocwarnings()
654 {
655 QStringList s;
656 s << scribus_combinepolygons__doc__
657 << scribus_deselectall__doc__
658 << scribus_flipobject__doc__
659 << scribus_getselectedobject__doc__
660 << scribus_groupobjects__doc__
661 << scribus_islocked__doc__
662 << scribus_loadimage__doc__
663 << scribus_lockobject__doc__
664 << scribus_moveobjectabs__doc__
665 << scribus_moveobjectrel__doc__
666 << scribus_rotateobjectabs__doc__
667 << scribus_rotateobjectrel__doc__
668 << scribus_scalegroup__doc__
669 << scribus_scaleimage__doc__
670 << scribus_selectioncount__doc__
671 << scribus_selectobject__doc__
672 << scribus_setimagebrightness__doc__
673 << scribus_setimagegrayscale__doc__
674 << scribus_setimageoffset__doc__
675 << scribus_setimagescale__doc__
676 << scribus_setscaleframetoimage__doc__
677 << scribus_setscaleimagetoframe__doc__
678 << scribus_sizeobject__doc__
679 << scribus_ungroupobjects__doc__;
680 }
681