Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
14647 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
*/
17560 jainbasil 7
#include <QImageWriter>
8
 
14647 cbradney 9
#include "api_document.h"
10
#include "selection.h"
17560 jainbasil 11
#include "api_color.h"
12
#include "api_layer.h"
13
#include "api_imageexport.h"
14
#include "api_printer.h"
15
#include "api_textitem.h"
16
#include "api_imageitem.h"
17
#include "util.h"
18
#include "utils.h"
19
#include "pageitem_textframe.h"
20
#include "undomanager.h"
19310 craig 21
#include "scribusview.h"
14647 cbradney 22
 
23
DocumentAPI::DocumentAPI() : QObject(COLLECTOR)
24
{
17560 jainbasil 25
        qDebug() << "DocumentAPI loaded";
26
        setObjectName("document"); // XXX: support other documents later
14647 cbradney 27
}
28
 
29
 
30
 
31
DocumentAPI::~DocumentAPI()
32
{
17560 jainbasil 33
        qDebug() << "DocumentAPI deleted";
14647 cbradney 34
}
35
 
17560 jainbasil 36
/**
37
 * Scripter.activeDocument.name
38
 */
39
QString DocumentAPI::getName()
40
{
41
        if (!check()) return NULL;
42
        if (! ScCore->primaryMainWindow()->doc->hasName)
43
        {
44
                return QString("");
45
        }
46
        return ScCore->primaryMainWindow()->doc->DocName;
47
}
14647 cbradney 48
 
49
 
50
/**
51
 * Scripter.activeDocument.available
52
 * Property
53
 * bool value if a document is active
54
 */
55
bool DocumentAPI::available()
56
{
17560 jainbasil 57
        if (ScCore->primaryMainWindow()->HaveDoc)
58
                return true;
59
        return false;
14647 cbradney 60
}
61
 
62
 
63
/**
64
 * Scripter.activeDocument.check
65
 * returns True if found else False and raises error
66
 */
67
bool DocumentAPI::check()
68
{
17560 jainbasil 69
        if (!available())
70
        {
71
                RAISE("Method call requires an open document, none found.");
72
                return false;
73
        }
74
        return true;
14647 cbradney 75
}
76
 
77
 
78
/**
79
 * Scripter.activeDocument.modified
80
 * Property
81
 * boolean flag if document is modified
82
 *
83
 * If a document is modified you will be asked to save it
84
 * on close or quit.
85
 */
86
void DocumentAPI::setModified(bool flag)
87
{
17560 jainbasil 88
        if (!check()) return;
89
        ScCore->primaryMainWindow()->doc->setModified(flag);
14647 cbradney 90
}
91
 
92
bool DocumentAPI::modified()
93
{
17560 jainbasil 94
        if (!check()) return NULL;
95
        return ScCore->primaryMainWindow()->doc->isModified();
14647 cbradney 96
}
97
 
18085 craig 98
/**
99
 * Scripter.activeDocument.unit
100
 * Property
101
 * boolean flag current measurement unit of the document
102
 *
103
 * When starting a script you should query its current unit,
104
 * Use your preferred unit during the script life and don't forget
105
 * to set again the previous unit before finishing the script
106
 */
107
void DocumentAPI::setUnit(int value)
108
{
109
        if (!check()) return;
110
        ScCore->primaryMainWindow()->doc->setUnitIndex(value);
111
}
14647 cbradney 112
 
18085 craig 113
int DocumentAPI::unit()
114
{
22333 jghali 115
        if (!check()) return 0;
18085 craig 116
        return ScCore->primaryMainWindow()->doc->unitIndex();
117
}
14647 cbradney 118
 
119
/**
120
 * Scripter.activeDocument.close()
121
 *
122
 * closes the active document without asking save
123
 */
124
bool DocumentAPI::close()
125
{
17560 jainbasil 126
        if (!check()) return NULL;
127
        setModified(false);
128
        bool ret = ScCore->primaryMainWindow()->slotFileClose();
129
        qApp->processEvents();
130
        return ret;
14647 cbradney 131
}
132
 
17560 jainbasil 133
/**
134
 * Scripter.activeDocument.save()
135
 *
136
 * Saves the activeDocument
137
 */
138
bool DocumentAPI::save()
139
{
140
        if (!check()) return NULL;
141
        bool ret = ScCore->primaryMainWindow()->slotFileSave();
142
        qApp->processEvents();
143
        return ret;
144
}
14647 cbradney 145
 
17560 jainbasil 146
/**
147
 * Scripter.activeDocument.saveAs(name)
148
 *
149
 * saves a document
150
 */
151
bool DocumentAPI::saveAs(QString name)
152
{
153
        if (!check()) return NULL;
154
        bool ret = ScCore->primaryMainWindow()->DoFileSave(name);
155
        if (!ret)
156
        {
157
                RAISE("Failed to save document.");
158
                return NULL;
159
        }
160
        return true;
161
}
14647 cbradney 162
 
17560 jainbasil 163
 
14647 cbradney 164
/**
165
 * Scripter.activeDocument.pageCount()
166
 * returns number of pages in active document as int
167
 */
168
int DocumentAPI::pageCount()
169
{
17560 jainbasil 170
        return ScCore->primaryMainWindow()->doc->Pages->count();
14647 cbradney 171
}
172
 
173
 
174
 
175
/**
176
 * Scripter.activeDocument.activePage
177
 * Property
178
 * Page object of active page in active Document
179
 */
17560 jainbasil 180
QObject *DocumentAPI::activePage()
181
{
17935 jainbasil 182
        return new PageAPI(ScCore->primaryMainWindow()->doc->currentPage());
14647 cbradney 183
}
184
 
185
 
186
/**
187
 * Scripter.activeDocument.activeItem
188
 * Property
189
 * Currently active page item
190
 */
191
QObject *DocumentAPI::activeItem()
192
{
17560 jainbasil 193
        if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0)
194
                return NULL;
195
        else
196
        {
197
                PageItem* item = ScCore->primaryMainWindow()->doc->m_Selection->itemAt(0);
198
                if(item->asTextFrame())
199
                {
17638 jainbasil 200
                        TextAPI *textItem = new TextAPI(item->asTextFrame());
17560 jainbasil 201
                        return textItem;
202
                }
203
                else if(item->asImageFrame())
204
                {
17638 jainbasil 205
                        ImageAPI *imageItem = new ImageAPI(item->asImageFrame());
17560 jainbasil 206
                        return imageItem;
207
                }
208
                else
209
                {
17638 jainbasil 210
                        ItemAPI *otherItem = new ItemAPI(item);
17560 jainbasil 211
                        return otherItem;
212
                }
213
        }
14647 cbradney 214
}
215
 
17560 jainbasil 216
int DocumentAPI::selectionCount()
217
{
218
        if(!check())
219
                RAISE("No document open.");
220
        return ScCore->primaryMainWindow()->doc->m_Selection->count();
221
}
14647 cbradney 222
 
17560 jainbasil 223
 
14647 cbradney 224
/**
225
 * Scripter.activeDocument.selection
226
 * Property
227
 * List of selected Item objects on active document
228
 */
229
QList<QVariant> DocumentAPI::selection()
230
{
17560 jainbasil 231
        QList<QVariant> l;
232
        Selection *sel = ScCore->primaryMainWindow()->doc->m_Selection;
233
        for (int i=0; i < sel->count(); i++)
234
        {
235
                /**
236
                 * Checking whether it is a textframe. If yes, we are trying to cast
237
                 * it onto TextWrapper class, which can effectively perform all
238
                 * the text operations
239
                 */
240
                PageItem *item = sel->itemAt(i);
241
                if (item->asTextFrame())
242
                {
17638 jainbasil 243
                        TextAPI *textItem = new TextAPI(item->asTextFrame());
17560 jainbasil 244
                        l.append(qVariantFromValue((QObject *)(textItem)));
245
                }
246
                else if(item->asImageFrame())
247
                {
17638 jainbasil 248
                        ImageAPI *imageItem = new ImageAPI(item->asImageFrame());
17560 jainbasil 249
                        l.append(qVariantFromValue((QObject *)(imageItem)));
250
                }
251
                else
252
                {
17638 jainbasil 253
                        ItemAPI *otherItem = new ItemAPI(item);
17560 jainbasil 254
                        l.append(qVariantFromValue(
255
                                     (QObject *)(otherItem)
256
                                 ));
257
                }
258
        }
259
        return l;
14647 cbradney 260
}
261
 
262
 
263
/**
264
 * Scripter.activeDocument.dimensions
265
 * Property
266
 * Dimensions object of active page
267
 */
268
QObject *DocumentAPI::dimensions()
269
{
17560 jainbasil 270
        return new Dimensions(this);
14647 cbradney 271
}
272
 
273
/**
274
 * Scripter.activeDocument.items
275
 * Property
276
 * List of all Item objects of active document
277
 */
278
QList<QVariant> DocumentAPI::items()
279
{
17560 jainbasil 280
        QList<QVariant> l;
281
        for (int i = 0; i<ScCore->primaryMainWindow()->doc->Items->count(); ++i)
282
        {
283
                PageItem *item = ScCore->primaryMainWindow()->doc->Items->at(i);
284
                if (item->asTextFrame())
285
                {
17638 jainbasil 286
                        TextAPI *textItem = new TextAPI(item->asTextFrame());
17560 jainbasil 287
                        l.append(qVariantFromValue((QObject *)(textItem)));
288
                }
289
                else if(item->asImageFrame())
290
                {
17638 jainbasil 291
                        ImageAPI *imageItem = new ImageAPI(item->asImageFrame());
17560 jainbasil 292
                        l.append(qVariantFromValue((QObject *)(imageItem)));
293
                }
294
                else
295
                {
17638 jainbasil 296
                        ItemAPI *otherItem = new ItemAPI(item);
17560 jainbasil 297
                        l.append(qVariantFromValue(
298
                                     (QObject *)(otherItem)
299
                                 ));
300
                }
301
        }
302
        return l;
14647 cbradney 303
}
17560 jainbasil 304
//FIXME is there a need to make these informations separate properties?
305
//jainbasil
14647 cbradney 306
 
307
 
17560 jainbasil 308
void DocumentAPI::setInformation(QString author, QString title, QString desc)
309
{
310
        if (!check())
311
                return;
312
        ScCore->primaryMainWindow()->doc->documentInfo().setAuthor(author);
313
        ScCore->primaryMainWindow()->doc->documentInfo().setTitle(title);
314
        ScCore->primaryMainWindow()->doc->documentInfo().setComments(desc);
315
        ScCore->primaryMainWindow()->slotDocCh();
14647 cbradney 316
}
317
 
318
 
17560 jainbasil 319
QList<QVariant> DocumentAPI::layers()
320
{
321
        QList<QVariant> l;
322
        for (int i = 0; i<ScCore->primaryMainWindow()->doc->Layers.count() ; ++i)
323
        {
324
                ScLayer *L = &(ScCore->primaryMainWindow()->doc->Layers[i]);
17638 jainbasil 325
                LayerAPI *layer = new LayerAPI(L);
17560 jainbasil 326
                l.append(qVariantFromValue((QObject *)(layer)));
327
        }
328
        return l;
329
}
14647 cbradney 330
 
17560 jainbasil 331
QObject *DocumentAPI::newLayer(QString name)
332
{
17638 jainbasil 333
        LayerAPI *l = new LayerAPI(ScCore->primaryMainWindow()->doc->Layers.newLayer(name));
17560 jainbasil 334
        return (QObject *)(l);
335
}
336
 
337
void DocumentAPI::removeLayer(QString name)
338
{
339
        if (ScCore->primaryMainWindow()->doc->Layers.count() == 1)
340
        {
341
                RAISE("Cannot remove the last layer.");
342
        }
343
        bool found = false;
344
        for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
345
        {
346
                if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == name)
347
                {
348
                        ScLayer it2 = ScCore->primaryMainWindow()->doc->Layers.at(lam);
349
                        int num2 = it2.ID;
350
                        if (!num2)
351
                        {
352
                                return;
353
                        }
354
                        ScCore->primaryMainWindow()->doc->removeLayer(num2);
355
                        ScCore->primaryMainWindow()->doc->Layers.removeLayerByID(num2);
356
                        ScCore->primaryMainWindow()->doc->setActiveLayer(0);
357
                        ScCore->primaryMainWindow()->changeLayer(0);
358
                        found = true;
359
                        break;
360
                }
361
        }
362
        if (!found)
363
        {
364
                RAISE("Layer not found.");
365
        }
366
}
367
 
368
QObject *DocumentAPI::getActiveLayer()
369
{
370
        for (int i = 0; i<ScCore->primaryMainWindow()->doc->Layers.count(); ++i)
371
        {
372
                if (ScCore->primaryMainWindow()->doc->Layers[i].Name == ScCore->primaryMainWindow()->doc->activeLayerName())
373
                {
374
                        ScLayer *L = &(ScCore->primaryMainWindow()->doc->Layers[i]);
17638 jainbasil 375
                        return new LayerAPI(L);
17560 jainbasil 376
                }
377
        }
378
        return NULL;
379
}
380
 
381
QString DocumentAPI::getActiveLayerName()
382
{
383
        return ScCore->primaryMainWindow()->doc->activeLayerName();
384
}
385
 
386
void DocumentAPI::setActiveLayer(QString name)
387
{
388
        bool found = ScCore->primaryMainWindow()->doc->setActiveLayer(name);
389
        if (found)
390
                ScCore->primaryMainWindow()->changeLayer(ScCore->primaryMainWindow()->doc->activeLayer());
391
        else
392
                RAISE("Layer not found.");
393
}
394
 
14647 cbradney 395
/**
17560 jainbasil 396
 * Scripter.activeDocument.colors
397
 * Property
398
 * Colors of activeDocument
399
 */
400
QList<QVariant> DocumentAPI::colors()
401
{
402
        QList<QVariant> l;
403
 
404
        ColorList names = ScCore->primaryMainWindow()->doc->PageColors;
405
        ColorList::Iterator it;
406
        for (it = names.begin(); it != names.end(); ++it)
407
        {
408
                ScColor *value = &(names[it.key()]);
17638 jainbasil 409
                ColorAPI *color = new ColorAPI(value, it.key());
17560 jainbasil 410
                l.append(qVariantFromValue((QObject *)(color)));
411
        }
412
        return l;
413
}
414
 
415
QObject *DocumentAPI::getColor(QString name)
416
{
17638 jainbasil 417
        return new ColorAPI(&(ScCore->primaryMainWindow()->doc->PageColors[name]), name);
17560 jainbasil 418
}
419
 
420
QObject *DocumentAPI::newColorCMYK(QString name, int c, int m, int y, int k)
421
{
422
        if (name.isEmpty())
423
        {
424
                RAISE("Cannot create a color with an empty name");
425
        }
426
        if (ScCore->primaryMainWindow()->doc->PageColors.contains(name))
427
        {
428
                ScCore->primaryMainWindow()->doc->PageColors.insert(name, ScColor(c, m, y, k));
429
        }
430
        else
431
        {
432
                ScCore->primaryMainWindow()->doc->PageColors[name].setColor(c, m, y, k);
433
        }
434
        return getColor(name);
435
}
436
 
437
QObject *DocumentAPI::newColorRGB(QString name, int r, int g, int b)
438
{
439
        if (name.isEmpty())
440
        {
441
                RAISE("Cannot create a color with an empty name");
442
        }
443
        if (ScCore->primaryMainWindow()->doc->PageColors.contains(name))
444
        {
445
                ScCore->primaryMainWindow()->doc->PageColors.insert(name, ScColor(r, g, b));
446
        }
447
        else
448
        {
22333 jghali 449
                ScCore->primaryMainWindow()->doc->PageColors[name].setRgbColor(r, g, b);
17560 jainbasil 450
        }
451
        return getColor(name);
452
}
453
 
454
QList<QVariant> DocumentAPI::supportedImageTypes()
455
{
456
        QList<QVariant> l;
457
        QList<QByteArray> list = QImageWriter::supportedImageFormats();
458
        for (QList<QByteArray>::Iterator it = list.begin(); it != list.end(); ++it)
459
        {
460
                l.append(QString((*it)).toLatin1().constData());
461
        }
462
        return l;
463
}
464
 
465
bool DocumentAPI::exportAsImages(QString dirName, QString type, double scale, double quality, double dpi, bool overwrite)
466
{
467
        std::vector<int> pageNs;
468
        ImageExport *ie = new ImageExport(dirName, type, scale, quality, dpi, overwrite);
469
        parsePagesString("*", &pageNs, ScCore->primaryMainWindow()->doc->DocPages.count());
470
        bool result = ie->exportInterval(ScCore->primaryMainWindow()->doc, pageNs);
471
        return result;
472
}
473
 
474
QObject* DocumentAPI::Printer()
475
{
476
        return new PrinterAPI();
477
}
478
 
479
QList<QVariant> DocumentAPI::masterPages()
480
{
481
        QList<QVariant> names;
482
        if (!check())
483
                return names;
484
        QMap<QString,int>::const_iterator it(ScCore->primaryMainWindow()->doc->MasterNames.constBegin());
485
        QMap<QString,int>::const_iterator itEnd(ScCore->primaryMainWindow()->doc->MasterNames.constEnd());
486
        for (; it != itEnd; ++it)
487
        {
488
                names.append(it.key());
489
        }
490
        return names;
491
}
492
 
493
/**
494
 * Scripter.activeDocument.createMasterPage(name)
495
 */
496
void DocumentAPI::createMasterPage(QString name)
497
{
498
        if (!check()) return;
499
        if (ScCore->primaryMainWindow()->doc->MasterNames.contains(name))
500
        {
501
                RAISE("Master page already exists");
502
                return;
503
        }
504
        ScCore->primaryMainWindow()->doc->addMasterPage(ScCore->primaryMainWindow()->doc->MasterPages.count(), name);
505
}
506
 
507
/**
508
 * Scripter.activeDocument.deleteMasterPage(name)
509
 */
510
void DocumentAPI::deleteMasterPage(QString name)
511
{
512
        if (!check()) return;
513
 
514
        if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(name))
515
        {
516
                RAISE("Master page does not exist");
517
                return;
518
        }
519
        if (name == "Normal")
520
        {
521
                RAISE("Can not delete the Normal master page");
522
                return;
523
        }
524
        bool oldMode = ScCore->primaryMainWindow()->doc->masterPageMode();
525
        ScCore->primaryMainWindow()->doc->setMasterPageMode(true);
526
        ScCore->primaryMainWindow()->deletePage2(ScCore->primaryMainWindow()->doc->MasterNames[name]);
527
        ScCore->primaryMainWindow()->doc->setMasterPageMode(oldMode);
528
}
529
 
530
void DocumentAPI::closeMasterPage(QString name)
531
{
532
        if (!check())
533
                return;
534
        ScCore->primaryMainWindow()->view->hideMasterPage();
535
}
536
 
537
void DocumentAPI::editMasterPage(QString name)
538
{
539
        if (!check())
540
                return;
541
        const QMap<QString,int>& masterNames(ScCore->primaryMainWindow()->doc->MasterNames);
542
        const QMap<QString,int>::const_iterator it(masterNames.find(name));
543
        if (it == masterNames.constEnd())
544
        {
545
                RAISE("Master page not found");
546
                return;
547
        }
548
        ScCore->primaryMainWindow()->view->showMasterPage(*it);
549
}
550
 
17935 jainbasil 551
QList< QVariant > DocumentAPI::pages()
552
{
553
        QList<QVariant> pages;
554
        if (!check())
555
                return pages;
556
        QList<ScPage*> *allPages = ScCore->primaryMainWindow()->doc->Pages;
557
        for(int i=0; i< allPages->count(); i++) {
558
          pages.append(qVariantFromValue((QObject *)(new PageAPI(allPages->at(i)))));
559
        }
560
        return pages;
561
}
562
 
563
 
564
void DocumentAPI::setActivePage(int pageNumber)
565
{
566
        if(!check())
567
            return;
568
        pageNumber--;
569
        if ((pageNumber < 0) || (pageNumber > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
570
        {
571
                RAISE("Page number out of range.");
572
                return;
573
        }
574
        ScCore->primaryMainWindow()->view->GotoPage(pageNumber);
575
}
576
 
577
 
17560 jainbasil 578
void DocumentAPI::loadStylesFromFile(QString name)
579
{
580
        if (!check())
581
                return;
582
        ScCore->primaryMainWindow()->doc->loadStylesFromFile(name);
583
}
584
 
585
QObject* DocumentAPI::selectItem(QString name)
586
{
587
        if (!check())
588
                RAISE("No document open");
589
        PageItem *i = GetUniqueItem(name);
590
        if (i == NULL)
591
        {
592
                RAISE("No item with this name");
593
        }
594
        ScCore->primaryMainWindow()->view->SelectItem(i);
595
        return activeItem();
596
}
597
 
598
void DocumentAPI::deleteItem(QString name)
599
{
600
        if (name.isEmpty())
601
        {
602
                RAISE("name cannot be empty.");
603
                return;
604
        }
605
        if (!check())
606
                return;
607
        PageItem *i = GetUniqueItem(name);
608
        if (i == NULL)
609
        {
610
                RAISE("Unable to find the item.");
611
                return;
612
        }
613
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
614
        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
615
        ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem();
616
}
617
 
618
bool DocumentAPI::itemExists(QString name)
619
{
620
        if (name.isEmpty())
621
        {
622
                RAISE("Name cannot be empty");
623
                return false;
624
        }
625
        if (!check())
626
        {
627
                RAISE("No active document");
628
        }
629
        if (ItemExists(name))
630
                return true;
631
        return false;
632
}
633
 
634
QList< QVariant > DocumentAPI::styles()
635
{
636
        QList<QVariant> styleList;
637
        if (!check())
638
                RAISE("No active document.");
639
        for (int i=0; i < ScCore->primaryMainWindow()->doc->paragraphStyles().count(); ++i)
640
        {
641
                styleList.append(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name());
642
        }
643
        return styleList;
644
}
645
 
646
void DocumentAPI::deselectItems()
647
{
648
        if (!check())
649
                return;
650
        ScCore->primaryMainWindow()->view->Deselect();
651
}
652
 
653
QString DocumentAPI::groupItems(QList< QVariant > list)
654
{
655
        QString name;
656
        if (!check())
657
                RAISE("No document open");
658
        if (list.isEmpty() && ScCore->primaryMainWindow()->doc->m_Selection->count() < 2)
659
        {
660
                RAISE("Need selection or argument list of items to group");
661
        }
662
        Selection *tempSelection=0;
663
        Selection *finalSelection=0;
664
        //uint ap = ScCore->primaryMainWindow()->doc->currentPage()->pageNr();
665
        // If we were passed a list of items to group...
666
        if (!list.isEmpty())
667
        {
668
                int len = list.length();
669
                tempSelection = new Selection(ScCore->primaryMainWindow(), false);
670
                for (int i = 0; i < len; i++)
671
                {
672
                        // FIXME: We might need to explicitly get this string as utf8
673
                        // but as sysdefaultencoding is utf8 it should be a no-op to do
674
                        // so anyway.
675
                        name = list[i].toString();
676
                        PageItem *ic = GetUniqueItem(name);
677
                        if (ic == NULL)
678
                        {
679
                                delete tempSelection;
680
                                return NULL;
681
                        }
682
                        tempSelection->addItem(ic, true);
683
                }
684
                finalSelection=tempSelection;
685
        }
686
        else
687
                finalSelection=ScCore->primaryMainWindow()->doc->m_Selection;
688
        if (finalSelection->count() < 2)
689
        {
690
                // We can't very well group only one item
691
                RAISE("Cannot group less than two items");
692
                finalSelection=0;
693
                delete tempSelection;
694
                return NULL;
695
        }
696
 
697
        const PageItem* group = ScCore->primaryMainWindow()->doc->itemSelection_GroupObjects(false, false, finalSelection);
698
        finalSelection=0;
699
        delete tempSelection;
700
 
701
        return (group ? group->itemName() : NULL);
702
}
703
 
704
void DocumentAPI::unGroupItems(QString name)
705
{
706
        if (!check())
707
                RAISE("No document open");
708
        PageItem *i = GetUniqueItem(name);
709
        if (i == NULL)
710
                RAISE("Item not found.");
711
        ScCore->primaryMainWindow()->view->Deselect();
712
        ScCore->primaryMainWindow()->view->SelectItem(i);
713
        ScCore->primaryMainWindow()->UnGroupObj();
714
}
715
 
716
void DocumentAPI::scaleGroup(double factor, QString name)
717
{
718
        if (!check())
719
                RAISE("No document open");
720
        if (factor == 0.0)
721
        {
722
                RAISE("Cannot scale by 0%.");
723
                return;
724
        }
725
        PageItem *i = GetUniqueItem(name);
726
        if (i == NULL)
727
                return;
728
        ScCore->primaryMainWindow()->view->Deselect();
729
        ScCore->primaryMainWindow()->view->SelectItem(i);
730
//      int h = ScCore->primaryMainWindow()->view->frameResizeHandle;
731
//      ScCore->primaryMainWindow()->view->frameResizeHandle = 1;
732
        ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Resize, "", Um::IResize);
733
        ScCore->primaryMainWindow()->doc->scaleGroup(factor, factor);
734
        ScCore->primaryMainWindow()->view->endGroupTransaction();
735
}
736
 
737
Dimensions::Dimensions(QObject *parent) : QObject(COLLECTOR)
738
{
739
        qDebug() << "Dimensions created";
740
}
741
 
742
/**
14647 cbradney 743
 * Scripter.activeDocument.dimensions.width
744
 * Property
745
 * width of active document in points as double (read-only, for now)
746
 */
747
double Dimensions::width()
748
{
14991 cbradney 749
        return ScCore->primaryMainWindow()->doc->pageWidth();
14647 cbradney 750
}
751
 
752
/**
753
 * Scripter.activeDocument.dimensions.height
754
 * Property
755
 * height of active document in points as double (read-only, for now)
756
 */
757
double Dimensions::height()
758
{
14991 cbradney 759
        return ScCore->primaryMainWindow()->doc->pageHeight();
14647 cbradney 760
}
761
 
762
/**
763
 * Scripter.activeDocument.margins
764
 * Property
765
 * Margins object of active document
766
 */
767
QObject *DocumentAPI::margins()
768
{
17560 jainbasil 769
        return new Margins(this);
14647 cbradney 770
}
771
 
772
Margins::Margins(QObject *parent) : QObject(COLLECTOR)
773
{
17560 jainbasil 774
        qDebug() << "Margins created";
14647 cbradney 775
}
776
 
777
/**
778
 * Scripter.activeDocument.margins.top
779
 * Property
780
 * top-margin of active document as double
781
 */
782
double Margins::top()
783
{
20103 avox 784
        return ScCore->primaryMainWindow()->doc->margins()->top();
14647 cbradney 785
}
786
 
787
 
788
 
789
/**
20103 avox 790
 * Scripter.activeDocument.margins.left
14647 cbradney 791
 * Property
792
 * left-margin of active document as double
793
 */
794
double Margins::left()
795
{
20103 avox 796
        return ScCore->primaryMainWindow()->doc->margins()->left();
14647 cbradney 797
}
798
 
799
 
800
 
801
/**
20103 avox 802
 * Scripter.activeDocument.margins.right
14647 cbradney 803
 * Property
804
 * right-margin of active document as double
805
 */
17560 jainbasil 806
double Margins::right()
807
{
20103 avox 808
        return ScCore->primaryMainWindow()->doc->margins()->right();
14647 cbradney 809
}
810
 
811
 
812
 
813
/**
20103 avox 814
 * Scripter.activeDocument.margins.bottom
14647 cbradney 815
 * Property
816
 * top-margin of active document as double
817
 */
17560 jainbasil 818
double Margins::bottom()
819
{
20103 avox 820
        return ScCore->primaryMainWindow()->doc->margins()->bottom();
14647 cbradney 821
}
822
 
823
 
824
/**
825
 * Scripter.activeDocument.margins.set(lr, tpr, btr, rr)
826
 * args are double
827
 *
828
 * Use this method if you want to change more than one margin
829
 * at a time
830
 */
831
 
832
void Margins::set(double lr, double tpr, double btr, double rr)
833
{
17560 jainbasil 834
        MarginStruct margins(tpr, lr, btr, rr);
15407 craig 835
        ScCore->primaryMainWindow()->doc->resetPage(ScCore->primaryMainWindow()->doc->pagePositioning(), &margins);
17560 jainbasil 836
        ScCore->primaryMainWindow()->view->reformPages();
837
        ScCore->primaryMainWindow()->doc->setModified(true);
838
        ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber());
839
        ScCore->primaryMainWindow()->view->DrawNew();
14647 cbradney 840
}
841
 
842
 
843
 
844
void Margins::setTop(double value)
845
{
17560 jainbasil 846
        set(left(), value, bottom(), right());
14647 cbradney 847
}
848
 
849
 
850
 
851
void Margins::setLeft(double value)
852
{
17560 jainbasil 853
        set(value, top(), bottom(), right());
14647 cbradney 854
}
855
 
856
 
857
 
858
void Margins::setRight(double value)
859
{
17560 jainbasil 860
        set(left(), top(), bottom(), value);
14647 cbradney 861
}
862
 
863
 
864
 
865
void Margins::setBottom(double value)
866
{
17560 jainbasil 867
        set(left(), top(), value, right());
14647 cbradney 868
}