1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "sclayer.h"
#include <QHash> //necessary to avoid msvc warnings induced by SCRIBUS_API on ScLayers + early instanciation of templates
#include <QVector> //necessary to avoid msvc warnings induced by SCRIBUS_API on ScLayers + early instanciation of templates
#include <QtAlgorithms>
ScLayer::ScLayer(void)
{
Name = QObject::tr("New Layer");
LNr = 0;
Level = 0;
isPrintable = true;
isViewable = true;
isEditable = true;
flowControl = true;
outlineMode = false;
transparency = 1.0;
blendMode = 0;
markerColor = QColor(0, 0, 0);
}
ScLayer::ScLayer(const QString& name, int level, int nr)
{
Name = name;
LNr = nr;
Level = level;
isPrintable = true;
isViewable = true;
isEditable = true;
flowControl = true;
outlineMode = false;
transparency = 1.0;
blendMode = 0;
markerColor = QColor(0, 0, 0);
switch (LNr % 7)
{
case 0:
markerColor = Qt::black;
break;
case 1:
markerColor = Qt::red;
break;
case 2:
markerColor = Qt::green;
break;
case 3:
markerColor = Qt::blue;
break;
case 4:
markerColor = Qt::cyan;
break;
case 5:
markerColor = Qt::magenta;
break;
case 6:
markerColor = Qt::yellow;;
break;
}
}
bool ScLayer::operator< (const ScLayer& other) const
{
return (Level < other.Level);
}
bool ScLayer::operator== (const ScLayer& other) const
{
// ignore markerColor?
if (Name == other.Name && LNr == other.LNr && Level == other.Level &&
isPrintable == other.isPrintable && isViewable == other.isViewable &&
flowControl == other.flowControl && outlineMode == other.outlineMode &&
transparency == other.transparency && isEditable == other.isEditable &&
blendMode == other.blendMode)
{
return true;
}
return false;
}
int ScLayers::getMaxNumber(void)
{
int nr, maxNr = -1;
for (int i = 0; i < this->count(); ++i)
{
nr = this->at(i).LNr;;
if (nr > maxNr)
maxNr = nr;
}
return maxNr;
}
const ScLayer* ScLayers::bottomLayer (void) const
{
const ScLayer* layer, *bLayer = NULL;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if (!bLayer || (layer->Level < bLayer->Level))
bLayer = layer;
}
return bLayer;
}
const ScLayer* ScLayers::topLayer(void) const
{
const ScLayer *layer, *tLayer = NULL;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if (!tLayer || (layer->Level > tLayer->Level))
tLayer = layer;
}
return tLayer;
}
void ScLayers::levelToLayer (ScLayer& layer, int level) const
{
uint layerCount = count();
for (uint la2 = 0; la2 < layerCount; ++la2)
{
if (this->at(la2).Level == level)
{
const ScLayer& ll = this->at(la2);
layer.isViewable = ll.isViewable;
layer.isPrintable = ll.isPrintable;
layer.isEditable = ll.isEditable;
layer.LNr = ll.LNr;
layer.Name = ll.Name;
layer.flowControl = ll.flowControl;
layer.transparency = ll.transparency;
layer.blendMode = ll.blendMode;
break;
}
}
}
ScLayer* ScLayers::byLevel(const int level)
{
ScLayers::Iterator itend = end();
for (ScLayers::Iterator it = 0; it != itend; ++it)
{
if( it->Level == level)
return &(*it);
}
return NULL;
}
ScLayer* ScLayers::byNumber(const int nr)
{
ScLayers::Iterator itend = end();
for (ScLayers::Iterator it = 0; it != itend; ++it)
{
if( it->LNr == nr)
return &(*it);
}
return NULL;
}
ScLayer* ScLayers::bottom(void)
{
ScLayer* bLayer = NULL;
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if (!bLayer || (it->Level < bLayer->Level))
bLayer = &(*it);
}
return bLayer;
}
ScLayer* ScLayers::top(void)
{
ScLayer *tLayer = NULL;
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if (!tLayer || (it->Level > tLayer->Level))
tLayer = &(*it);
}
return tLayer;
}
ScLayer* ScLayers::above (int nr)
{
ScLayer* lyr = byNumber(nr);
if (lyr)
{
ScLayer *rlyr = top();
int level = lyr->Level;
int maxLevel = rlyr->Level;
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if (it->Level > level && it->Level < maxLevel)
{
maxLevel = it->Level;
rlyr = &(*it);
}
}
return rlyr;
}
return NULL;
}
ScLayer* ScLayers::below (int nr)
{
ScLayer* lyr = byNumber(nr);
if (lyr)
{
ScLayer *rlyr = bottom();
int level = lyr->Level;
int minLevel = lyr->Level;
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if (it->Level < level && it->Level > minLevel)
{
minLevel = it->Level;
rlyr = &(*it);
}
}
return rlyr;
}
return NULL;
}
const ScLayer* ScLayers::layerByLevel (int level) const
{
const ScLayer *layer = NULL;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if( layer->Level == level)
return layer;
}
return NULL;
}
const ScLayer* ScLayers::layerByNumber (int nr) const
{
const ScLayer *layer = NULL;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if( layer->LNr == nr)
return layer;
}
return NULL;
}
const ScLayer* ScLayers::layerByName (const QString& name) const
{
const ScLayer *layer = NULL;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if( layer->Name == name)
return layer;
}
return NULL;
}
const ScLayer* ScLayers::layerAbove (int level) const
{
const ScLayer* top = topLayer();
if (top)
{
const ScLayer *layer, *retlay = top;
int maxLevel = top->Level;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if (layer->Level > level && layer->Level < maxLevel)
{
retlay = layer;
maxLevel = layer->Level;
}
}
return retlay;
}
return NULL;
}
const ScLayer* ScLayers::layerAbove (const ScLayer& layer) const
{
const ScLayer* top = topLayer();
if (top)
{
const ScLayer *curlay, *retlay = top;
int level = layer.Level;
int maxLevel = top->Level;
for (int i = 0; i < this->count(); ++i)
{
curlay = &this->at(i);
if (curlay->Level > level && curlay->Level < maxLevel)
{
maxLevel = curlay->Level;
retlay = curlay;
}
}
return retlay;
}
return NULL;
}
const ScLayer* ScLayers::layerBelow (int level) const
{
const ScLayer* bottom = bottomLayer();
if (bottom)
{
const ScLayer *layer, *retlay = bottom;
int minLevel = bottom->Level;
for (int i = 0; i < this->count(); ++i)
{
layer = &this->at(i);
if (layer->Level < level && layer->Level > minLevel)
{
minLevel = layer->Level;
retlay = layer;
}
}
return retlay;
}
return NULL;
}
const ScLayer* ScLayers::layerBelow (const ScLayer& layer) const
{
const ScLayer* bottom = bottomLayer();
if (bottom)
{
const ScLayer *curlay, *retlay = bottom;
int level = layer.Level;
int minLevel = bottom->Level;
for (int i = 0; i < this->count(); ++i)
{
curlay = &this->at(i);
if (curlay->Level < level && curlay->Level > minLevel)
{
minLevel = curlay->Level;
retlay = curlay;
}
}
return retlay;
}
return NULL;
}
int ScLayers::addLayer(const QString& layerName)
{
ScLayer* nl = newLayer(layerName);
if (nl)
return nl->LNr;
return -1;
}
int ScLayers::addLayer(const ScLayer& layer)
{
int newID = layer.LNr;
const ScLayer* lid = layerByNumber(newID);
if (lid)
{
ScLayer newLyr(layer);
newLyr.LNr = newID = getMaxNumber() + 1;
append(newLyr);
}
else
append(layer);
sort();
return newID;
}
ScLayer* ScLayers::newLayer(const QString& layerName)
{
QString lname;
int lnr = getMaxNumber() + 1;
int llevel = count();
if (layerName.isEmpty())
{
QString tmp;
lname = QObject::tr("New Layer")+" "+tmp.setNum(lnr);
}
else
lname = layerName;
ScLayer ll(lname, llevel, lnr);
ScLayers::Iterator it = insert(end(), ll);
return &(*it);
}
bool ScLayers::removeLayerByNumber(int nr)
{
int index = -1;
int layerLevel = -1;
for (int i = 0; i < count(); ++i)
{
if (this->at(i).LNr == nr)
{
index = i;
layerLevel = this->at(i).Level;
break;
}
}
if (index >= 0)
{
removeAt(index);
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if ((*it).Level > layerLevel)
(*it).Level -= 1;
}
return true;
}
return false;
}
bool ScLayers::removeLayerByLevel(int level)
{
int index = -1;
for (int i = 0; i < count(); ++i)
{
if (this->at(i).Level == level)
{
index = i;
break;
}
}
if (index >= 0)
{
removeAt(index);
ScLayers::Iterator it, itEnd = end();
for (it = begin(); it != itEnd; ++it)
{
if ((*it).Level > level)
(*it).Level -= 1;
}
}
return false;
}
bool ScLayers::raiseLayer(int nr)
{
ScLayer* clyr = byNumber(nr);
if (!clyr)
return false;
ScLayer* alyr = above(clyr->LNr);
if ((!alyr) || (clyr == alyr))
return false;
clyr->LNr += 1;
alyr->LNr -= 1;
return true;
}
bool ScLayers::lowerLayer(int nr)
{
ScLayer* clyr = byNumber(nr);
if (!clyr)
return false;
ScLayer* blyr = below(clyr->LNr);
if (!blyr || (clyr == blyr))
return false;
clyr->LNr -= 1;
blyr->LNr += 1;
return true;
}
void ScLayers::sort(void)
{
int level = 0;
ScLayers::Iterator it, itend = end();
qStableSort(begin(), end());
for(it = begin(); it != itend; ++it, ++level)
it->Level = level;
}
bool ScLayers::layerPrintable(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->isPrintable;
return false;
}
bool ScLayers::setLayerPrintable(const int layerNumber, const bool isPrintable)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->isPrintable = isPrintable;
return true;
}
return false;
}
bool ScLayers::layerVisible(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->isViewable;
return false;
}
bool ScLayers::setLayerVisible(const int layerNumber, const bool isViewable)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->isViewable = isViewable;
return true;
}
return false;
}
bool ScLayers::layerLocked(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return !(layer->isEditable);
return false;
}
bool ScLayers::setLayerLocked(const int layerNumber, const bool isLocked)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->isEditable = !isLocked;
return true;
}
return false;
}
bool ScLayers::layerFlow(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->flowControl;
return false;
}
bool ScLayers::setLayerFlow(const int layerNumber, const bool flow)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->flowControl = flow;
return true;
}
return false;
}
bool ScLayers::layerOutline(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->outlineMode;
return false;
}
bool ScLayers::setLayerOutline(const int layerNumber, const bool outline)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->outlineMode = outline;
return true;
}
return false;
}
double ScLayers::layerTransparency(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->transparency;
return 1.0;
}
bool ScLayers::setLayerTransparency(const int layerNumber, double trans)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->transparency = trans;
return true;
}
return false;
}
int ScLayers::layerBlendMode(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->blendMode;
return 0;
}
bool ScLayers::setLayerBlendMode(const int layerNumber, int blend)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->blendMode = blend;
return true;
}
return false;
}
QColor ScLayers::layerMarker(const int layerNumber) const
{
const ScLayer* layer = layerByNumber(layerNumber);
if (layer)
return layer->markerColor;
return Qt::black;
}
bool ScLayers::setLayerMarker(const int layerNumber, QColor color)
{
ScLayer* layer = byNumber(layerNumber);
if (layer)
{
layer->markerColor = color;
return true;
}
return false;
}
uint qHash(const ScLayer& layer)
{
return qHash(&layer);
}
|