Subversion Repositories Scribus

Rev

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