Subversion Repositories Scribus

Rev

Rev 17560 | Rev 19310 | 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
*/
7
#include "api_item.h"
17560 jainbasil 8
#include "utils.h"
9
#include "undomanager.h"
10
#include "selection.h"
14647 cbradney 11
 
17638 jainbasil 12
ItemAPI::ItemAPI(PageItem* it) : QObject(COLLECTOR)
14647 cbradney 13
{
17560 jainbasil 14
        qDebug() << "ItemAPI loaded";
17638 jainbasil 15
    setObjectName("ItemAPI");
17560 jainbasil 16
        item = it;
14647 cbradney 17
}
18
 
17638 jainbasil 19
QString ItemAPI::name()
17560 jainbasil 20
{
21
        return item->itemName();
22
}
14647 cbradney 23
 
17638 jainbasil 24
void ItemAPI::setName(QString name)
17560 jainbasil 25
{
26
        item->setItemName(name);
27
}
14647 cbradney 28
 
17560 jainbasil 29
 
17638 jainbasil 30
QString ItemAPI::fillColor()
14647 cbradney 31
{
17560 jainbasil 32
        return item->fillColor();
14647 cbradney 33
}
34
 
17638 jainbasil 35
void ItemAPI::setFillColor(QString color)
17560 jainbasil 36
{
37
        item->setFillColor(color);
38
}
14647 cbradney 39
 
17638 jainbasil 40
QString ItemAPI::lineColor()
17560 jainbasil 41
{
42
        return item->lineColor();
43
}
44
 
17638 jainbasil 45
void ItemAPI::setLineColor(QString color)
17560 jainbasil 46
{
47
        item->setLineColor(color);
48
}
49
 
50
 
17638 jainbasil 51
double ItemAPI::fillShade()
17560 jainbasil 52
{
53
        return item->fillShade();
54
}
55
 
17638 jainbasil 56
void ItemAPI::setFillShade(double value)
17560 jainbasil 57
{
58
        item->setFillShade(value);
59
}
60
 
17638 jainbasil 61
double ItemAPI::lineShade()
17560 jainbasil 62
{
63
        return item->lineShade();
64
}
65
 
17638 jainbasil 66
void ItemAPI::setLineShade(double value)
17560 jainbasil 67
{
68
        item->setLineShade(value);
69
}
70
 
17638 jainbasil 71
double ItemAPI::fillTransparency()
17560 jainbasil 72
{
73
        return item->fillTransparency();
74
}
75
 
17638 jainbasil 76
void ItemAPI::setFillTransparency(double value)
17560 jainbasil 77
{
78
        item->setFillTransparency(value);
79
}
80
 
81
 
17638 jainbasil 82
double ItemAPI::lineTransparency()
17560 jainbasil 83
{
84
        return item->lineTransparency();
85
}
86
 
17638 jainbasil 87
void ItemAPI::setLineTransparency(double value)
17560 jainbasil 88
{
89
        item->setLineTransparency(value);
90
}
91
 
17638 jainbasil 92
bool ItemAPI::locked()
17560 jainbasil 93
{
94
        return item->locked();
95
}
96
 
17638 jainbasil 97
void ItemAPI::setLocked(bool value)
17560 jainbasil 98
{
99
        item->setLocked(value);
100
}
101
 
17638 jainbasil 102
bool ItemAPI::sizeLocked()
17560 jainbasil 103
{
104
        return item->sizeLocked();
105
}
106
 
17638 jainbasil 107
void ItemAPI::setSizeLocked(bool value)
17560 jainbasil 108
{
109
        item->setSizeLocked(value);
110
}
111
 
17638 jainbasil 112
bool ItemAPI::imageFlippedV()
17560 jainbasil 113
{
114
        return item->imageFlippedV();
115
}
116
 
17638 jainbasil 117
void ItemAPI::setImageFlippedV(bool value)
17560 jainbasil 118
{
119
        item->setImageFlippedV(value);
120
}
121
 
17638 jainbasil 122
bool ItemAPI::imageFlippedH()
17560 jainbasil 123
{
124
        return item->imageFlippedH();
125
}
126
 
17638 jainbasil 127
void ItemAPI::setImageFlippedH(bool value)
17560 jainbasil 128
{
129
        item->setImageFlippedH(value);
130
}
131
 
17638 jainbasil 132
double ItemAPI::lineWidth()
17560 jainbasil 133
{
134
        return item->lineWidth();
135
}
136
 
17638 jainbasil 137
void ItemAPI::setLineWidth(double value)
17560 jainbasil 138
{
139
        item->setLineWidth(value);
140
}
141
 
17638 jainbasil 142
QString ItemAPI::customLineStyle()
17560 jainbasil 143
{
144
        return item->customLineStyle();
145
}
146
 
17638 jainbasil 147
void ItemAPI::setCustomLineStyle(QString name)
17560 jainbasil 148
{
149
        item->setCustomLineStyle(name);
150
}
151
 
17638 jainbasil 152
int ItemAPI::startArrowIndex()
17560 jainbasil 153
{
154
        return item->startArrowIndex();
155
}
156
 
17638 jainbasil 157
void ItemAPI::setStartArrowIndex(int value)
17560 jainbasil 158
{
159
        item->setStartArrowIndex(value);
160
}
161
 
17638 jainbasil 162
int ItemAPI::endArrowIndex()
17560 jainbasil 163
{
164
        return item->endArrowIndex();
165
}
166
 
17638 jainbasil 167
void ItemAPI::setEndArrowIndex(int value)
17560 jainbasil 168
{
169
        item->setEndArrowIndex(value);
170
}
171
 
17638 jainbasil 172
bool ItemAPI::printEnabled()
17560 jainbasil 173
{
174
        return item->printEnabled();
175
}
176
 
17638 jainbasil 177
void ItemAPI::setPrintEnabled(bool value)
17560 jainbasil 178
{
179
        item->setPrintEnabled(value);
180
}
181
 
17638 jainbasil 182
double ItemAPI::xPos()
17560 jainbasil 183
{
184
        return item->xPos();
185
}
186
 
17638 jainbasil 187
void ItemAPI::setXPos(double value)
17560 jainbasil 188
{
189
        item->setXPos(value);
190
}
191
 
17638 jainbasil 192
double ItemAPI::yPos()
17560 jainbasil 193
{
194
        return item->yPos();
195
}
196
 
17638 jainbasil 197
void ItemAPI::setYPos(double value)
17560 jainbasil 198
{
199
        item->setYPos(value);
200
}
201
 
17638 jainbasil 202
double ItemAPI::width()
17560 jainbasil 203
{
204
        return item->width();
205
}
206
 
17638 jainbasil 207
void ItemAPI::setWidth(double value)
17560 jainbasil 208
{
209
        item->setWidth(value);
210
}
211
 
17638 jainbasil 212
double ItemAPI::height()
17560 jainbasil 213
{
214
        return item->height();
215
}
216
 
17638 jainbasil 217
void ItemAPI::setHeight(double value)
17560 jainbasil 218
{
219
        item->setHeight(value);
220
}
221
 
17638 jainbasil 222
double ItemAPI::rotation()
17560 jainbasil 223
{
224
        return item->rotation();
225
}
226
 
17638 jainbasil 227
void ItemAPI::setRotation(double rotation)
17560 jainbasil 228
{
229
        item->setRotation(rotation);
230
}
231
 
17638 jainbasil 232
bool ItemAPI::reversed()
17560 jainbasil 233
{
234
        return item->reversed();
235
}
236
 
17638 jainbasil 237
void ItemAPI::setReversed(bool value)
17560 jainbasil 238
{
239
        item->setReversed(value);
240
}
241
 
17638 jainbasil 242
double ItemAPI::cornerRadius()
17560 jainbasil 243
{
244
        return item->cornerRadius();
245
}
246
 
17638 jainbasil 247
void ItemAPI::setCornerRadius(double value)
17560 jainbasil 248
{
249
        item->setCornerRadius(value);
250
}
251
 
17638 jainbasil 252
double ItemAPI::columnGap()
17560 jainbasil 253
{
254
        return item->columnGap();
255
}
256
 
17638 jainbasil 257
void ItemAPI::setColumnGap(double value)
17560 jainbasil 258
{
259
        if (!checkHaveDocument())
260
                RAISE("No document open");
261
        if (value < 0.0)
262
        {
263
                RAISE("Column gap out of bounds, must be positive.");
264
        }
265
        item->ColGap = ValueToPoint(value);
266
}
267
 
17638 jainbasil 268
int ItemAPI::columns()
17560 jainbasil 269
{
270
        return item->columns();
271
}
272
 
17638 jainbasil 273
void ItemAPI::setColumns(int value)
17560 jainbasil 274
{
275
        if (!checkHaveDocument())
276
                RAISE("No document open");
277
        if (value < 1)
278
        {
279
                RAISE("Column count out of bounds, must be > 1.");
280
        }
281
        item->Cols = value;
282
}
283
 
284
 
285
/**
286
 * Methods
287
 */
288
 
17638 jainbasil 289
void ItemAPI::move(double dx, double dy)
17560 jainbasil 290
{
291
        if (!checkHaveDocument())
292
                return;
293
        if (item==NULL)
294
                return;
295
        // Grab the old selection - but use it only where is there any
296
        Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
297
        bool hadOrigSelection = (tempSelection.count() != 0);
298
 
299
        ScCore->primaryMainWindow()->doc->m_Selection->clear();
300
        // Clear the selection
301
        ScCore->primaryMainWindow()->view->Deselect();
302
        // Select the item, which will also select its group if
303
        // there is one.
304
        ScCore->primaryMainWindow()->view->SelectItem(item);
305
        // Move the item, or items
306
        if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1)
307
        {
308
                ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove);
309
                ScCore->primaryMainWindow()->doc->moveGroup(ValueToPoint(dx), ValueToPoint(dy));
310
                ScCore->primaryMainWindow()->view->endGroupTransaction();
311
        }
312
        else
313
        {
314
                ScCore->primaryMainWindow()->doc->MoveItem(ValueToPoint(dx), ValueToPoint(dy), item);
315
        }
316
        // Now restore the selection.
317
        ScCore->primaryMainWindow()->view->Deselect();
318
        if (hadOrigSelection)
319
                *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
320
 
321
}
322
 
17638 jainbasil 323
void ItemAPI::moveAbs(double x, double y)
17560 jainbasil 324
{
325
        if (!checkHaveDocument())
326
                return;
327
        if (item == NULL)
328
                return;
329
        // Grab the old selection - but use it only where is there any
330
        Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
331
        bool hadOrigSelection = (tempSelection.count() != 0);
332
 
333
        // Clear the selection
334
        ScCore->primaryMainWindow()->view->Deselect();
335
        // Select the item, which will also select its group if
336
        // there is one.
337
        ScCore->primaryMainWindow()->view->SelectItem(item);
338
        // Move the item, or items
339
        if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1)
340
        {
341
                ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove);
342
                double x2, y2, w, h;
343
                ScCore->primaryMainWindow()->doc->m_Selection->getGroupRect(&x2, &y2, &w, &h);
344
                ScCore->primaryMainWindow()->doc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
345
                ScCore->primaryMainWindow()->view->endGroupTransaction();
346
        }
347
        else
348
                ScCore->primaryMainWindow()->doc->MoveItem(pageUnitXToDocX(x) - item->xPos(), pageUnitYToDocY(y) - item->yPos(), item);
349
        // Now restore the selection.
350
        ScCore->primaryMainWindow()->view->Deselect();
351
        if (hadOrigSelection)
352
                *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
353
}
354
 
17638 jainbasil 355
void ItemAPI::resize(double width, double height)
17560 jainbasil 356
{
357
        if (!checkHaveDocument())
358
                return;
359
        if (item == NULL)
360
                return;
361
        ScCore->primaryMainWindow()->doc->SizeItem(ValueToPoint(width), ValueToPoint(height), item);
362
}
363
 
17638 jainbasil 364
void ItemAPI::rotate(double rot)
17560 jainbasil 365
{
366
        if (!checkHaveDocument())
367
                return;
368
        if (item == NULL)
369
                return;
370
        ScCore->primaryMainWindow()->doc->RotateItem(item->rotation() - rot, item);
371
 
372
}
17638 jainbasil 373
void ItemAPI::rotateAbs(double rot)
17560 jainbasil 374
{
375
        if (!checkHaveDocument())
376
                return;
377
        if (item == NULL)
378
                return;
379
        ScCore->primaryMainWindow()->doc->RotateItem(rot * -1.0, item);
380
}
381
 
382
 
17638 jainbasil 383
ItemAPI::~ItemAPI()
17560 jainbasil 384
{
385
        qDebug() << "ItemAPI deleted";
386
}
387
 
388