1 #include "Painter.h"
2 #include "SvgCache.h"
3
4 #include <QtCore/QString>
5 #include <QtGui/QPainter>
6 #include <QtGui/QPainterPath>
7 #include <QMatrix>
8 #include <QDomElement>
9 #include <QFileInfo>
10 #include <QDir>
11
Painter()12 Painter::Painter()
13 : ZoomLimitSet(false), ZoomUnder(0), ZoomUpper(10e6),
14 DrawBackground(false), BackgroundScale(0), BackgroundOffset(3),
15 DrawForeground(false), ForegroundScale(0), ForegroundOffset(2),
16 ForegroundDashSet(false),
17 DrawTouchup(false), TouchupScale(0), TouchupOffset(1),
18 TouchupDashSet(false),
19 ForegroundFill(false), ForegroundFillUseIcon(false),
20 DrawTrafficDirectionMarks(false),
21 DrawIcon(false), IconScale(0), IconOffset(0),
22 DrawLabel(false), LabelScale(0), LabelOffset(0),
23 DrawLabelBackground(false), LabelHalo(false), LabelArea(false),
24 BackgroundInterior(false), BackgroundExterior(false)
25 {
26 }
27
Painter(const Painter & f)28 Painter::Painter(const Painter& f)
29 : ZoomLimitSet(f.ZoomLimitSet), ZoomUnder(f.ZoomUnder), ZoomUpper(f.ZoomUpper),
30 DrawBackground(f.DrawBackground), BackgroundColor(f.BackgroundColor),
31 BackgroundScale(f.BackgroundScale), BackgroundOffset(f.BackgroundOffset),
32 DrawForeground(f.DrawForeground), ForegroundColor(f.ForegroundColor),
33 ForegroundScale(f.ForegroundScale), ForegroundOffset(f.ForegroundOffset),
34 ForegroundDashSet(f.ForegroundDashSet), ForegroundDash(f.ForegroundDash), ForegroundWhite(f.ForegroundWhite),
35 DrawTouchup(f.DrawTouchup), TouchupColor(f.TouchupColor),
36 TouchupScale(f.TouchupScale), TouchupOffset(f.TouchupOffset),
37 TouchupDashSet(f.TouchupDashSet),
38 TouchupDash(f.TouchupDash), TouchupWhite(f.TouchupWhite),
39 ForegroundFill(f.ForegroundFill), ForegroundFillFillColor(f.ForegroundFillFillColor), ForegroundFillUseIcon(f.ForegroundFillUseIcon),
40 DrawTrafficDirectionMarks(f.DrawTrafficDirectionMarks), TrafficDirectionMarksColor(f.TrafficDirectionMarksColor),
41 DrawIcon(f.DrawIcon), IconName(f.IconName), IconScale(f.IconScale), IconOffset(f.IconOffset),
42 DrawLabel(f.DrawLabel), LabelTag(f.LabelTag), LabelColor(f.LabelColor), LabelScale(f.LabelScale), LabelOffset(f.LabelOffset),
43 DrawLabelBackground(f.DrawLabelBackground), LabelBackgroundColor(f.LabelBackgroundColor), LabelBackgroundTag(f.LabelBackgroundTag),
44 LabelFont(f.LabelFont), LabelHalo(f.LabelHalo), LabelArea(f.LabelArea),
45 BackgroundInterior(f.BackgroundInterior), BackgroundExterior(f.BackgroundExterior),
46 theSelector(f.theSelector)
47 {
48 }
49
operator =(const Painter & f)50 Painter& Painter::operator=(const Painter& f)
51 {
52 if (&f == this) return *this;
53
54 ZoomLimitSet = f.ZoomLimitSet;
55 ZoomUnder = f.ZoomUnder;
56 ZoomUpper = f.ZoomUpper;
57 DrawBackground = f.DrawBackground;
58 BackgroundColor = f.BackgroundColor;
59 BackgroundScale = f.BackgroundScale;
60 BackgroundOffset = f.BackgroundOffset;
61 DrawForeground = f.DrawForeground;
62 ForegroundColor = f.ForegroundColor;
63 ForegroundScale = f.ForegroundScale;
64 ForegroundOffset = f.ForegroundOffset;
65 ForegroundDashSet = f.ForegroundDashSet ;
66 ForegroundDash = f.ForegroundDash;
67 ForegroundWhite = f.ForegroundWhite;
68 DrawTouchup = f.DrawTouchup;
69 TouchupColor = f.TouchupColor;
70 TouchupScale = f.TouchupScale;
71 TouchupOffset = f.TouchupOffset;
72 TouchupDashSet = f.TouchupDashSet;
73 TouchupDash = f.TouchupDash;
74 TouchupWhite = f.TouchupWhite;
75 ForegroundFill = f.ForegroundFill;
76 ForegroundFillFillColor = f.ForegroundFillFillColor;
77 ForegroundFillUseIcon = f.ForegroundFillUseIcon;
78 DrawTrafficDirectionMarks = f.DrawTrafficDirectionMarks;
79 TrafficDirectionMarksColor = f.TrafficDirectionMarksColor;
80 DrawIcon = f.DrawIcon;
81 IconName = f.IconName;
82 IconScale = f.IconScale;
83 IconOffset = f.IconOffset;
84 DrawLabel = f.DrawLabel;
85 LabelColor = f.LabelColor;
86 LabelScale = f.LabelScale;
87 LabelOffset = f.LabelOffset;
88 DrawLabelBackground = f.DrawLabelBackground;
89 LabelBackgroundColor = f.LabelBackgroundColor;
90 LabelFont = f.LabelFont;
91 LabelTag = f.LabelTag;
92 LabelBackgroundTag = f.LabelBackgroundTag;
93 LabelHalo = f.LabelHalo;
94 LabelArea = f.LabelArea;
95 theSelector = f.theSelector;
96 BackgroundInterior = f.BackgroundInterior;
97 BackgroundExterior = f.BackgroundExterior;
98
99 return *this;
100 }
101
~Painter()102 Painter::~Painter()
103 {
104 }
105
paddedHexa(int i)106 QString paddedHexa(int i)
107 {
108 QString r=QString::number(i,16);
109 if (r.length() < 2)
110 r = "0"+r;
111 return r;
112 }
113
asXML(const QColor & c)114 QString asXML(const QColor& c)
115 {
116 return "#"+paddedHexa(c.red())+paddedHexa(c.green())+paddedHexa(c.blue())+paddedHexa(c.alpha());
117 }
118
colorAsXML(const QString & name,const QColor & c)119 QString colorAsXML(const QString& name, const QColor& c)
120 {
121 return
122 name+"Color=\""+asXML(c)+"\"\n";
123 }
124
boundaryAsXML(const QString & name,const QColor & c,qreal Scale,qreal Offset)125 QString boundaryAsXML(const QString& name, const QColor& c, qreal Scale, qreal Offset)
126 {
127 return
128 name+"Color=\""+asXML(c)+"\" "+name+"Scale=\""+QString::number(Scale)+"\" "+name+"Offset=\""+QString::number(Offset)+"\"\n";
129 }
130
iconAsXML(const QString & name,const QString & fn,qreal Scale,qreal Offset)131 QString iconAsXML(const QString& name, const QString& fn, qreal Scale, qreal Offset)
132 {
133 return
134 name+"=\""+fn+"\" "+name+"Scale=\""+QString::number(Scale)+"\" "+name+"Offset=\""+QString::number(Offset)+"\"\n";
135 }
136
toColor(const QString & s)137 QColor toColor(const QString& s)
138 {
139 return
140 QColor(
141 s.mid(1,2).toInt(0,16),
142 s.mid(3,2).toInt(0,16),
143 s.mid(5,2).toInt(0,16),
144 s.mid(7,2).toInt(0,16));
145 }
146
147
toXML(QString filename) const148 QString Painter::toXML(QString filename) const
149 {
150 QString r;
151 r += "<painter\n";
152 if (ZoomLimitSet)
153 r += " zoomUnder=\""+QString::number(ZoomUnder)+"\" zoomUpper=\""+QString::number(ZoomUpper)+"\"\n";
154 if (DrawBackground)
155 r += " " + boundaryAsXML("background",BackgroundColor, BackgroundScale, BackgroundOffset);
156 if (BackgroundInterior)
157 r += " interior=\"yes\"";
158 if (BackgroundExterior)
159 r += " exterior=\"yes\"";
160 if (DrawForeground)
161 r += " " + boundaryAsXML("foreground",ForegroundColor, ForegroundScale, ForegroundOffset);
162 if (ForegroundDashSet && DrawForeground)
163 r += " foregroundDashDown=\""+QString::number(ForegroundDash)+"\" foregroundDashUp=\""+QString::number(ForegroundWhite)+"\"\n";
164 if (DrawTouchup)
165 r += " " + boundaryAsXML("touchup",TouchupColor, TouchupScale, TouchupOffset);
166 if (TouchupDashSet && DrawTouchup)
167 r += " touchupDashDown=\""+QString::number(TouchupDash)+"\" touchupDashUp=\""+QString::number(TouchupWhite)+"\"\n";
168 if (ForegroundFill)
169 r += " fillColor=\""+::asXML(ForegroundFillFillColor)+"\"\n";
170 if (ForegroundFillUseIcon)
171 r += " fillWithIcon=\"yes\"";
172 if (!IconName.isEmpty() && DrawIcon)
173 {
174 QString iconFilename;
175 if (!IconName.startsWith(':')) {
176 iconFilename = QFileInfo(filename).absoluteDir().relativeFilePath(QFileInfo(IconName).absoluteFilePath());
177 } else {
178 iconFilename = IconName;
179 }
180 r += " " + iconAsXML("icon",iconFilename, IconScale, IconOffset);
181 }
182 if (DrawTrafficDirectionMarks)
183 r += " drawTrafficDirectionMarks=\"yes\" trafficDirectionMarksColor=\"" + ::asXML(TrafficDirectionMarksColor) +"\"\n";
184 if (DrawLabel) {
185 r += " " + boundaryAsXML("label",LabelColor, LabelScale, LabelOffset);
186 r += " labelFont=\"" + LabelFont.toString() + "\"";
187 r += " labelTag=\"" + LabelTag + "\"";
188 if (LabelHalo)
189 r += " labelHalo=\"yes\"";
190 if (LabelArea)
191 r += " labelArea=\"yes\"";
192 }
193 if (DrawLabelBackground) {
194 r += " labelBackgroundColor=\""+::asXML(LabelBackgroundColor)+"\"";
195 r += " labelBackgroundTag=\""+ LabelBackgroundTag +"\"\n";
196 }
197 r += ">\n";
198
199 if (!theSelector.isEmpty())
200 r += " <selector expr=\""+theSelector+"\"/>\n";
201
202 r += "</painter>\n";
203 return r;
204 }
205
fromXML(const QDomElement & e,QString filename)206 Painter Painter::fromXML(const QDomElement& e, QString filename)
207 {
208 Painter FP;
209
210 if (e.hasAttribute("zoomUnder") || e.hasAttribute("zoomUpper"))
211 FP.zoomBoundary(e.attribute("zoomUnder","0").toDouble(),e.attribute("zoomUpper","10e6").toDouble());
212 if (e.hasAttribute("foregroundColor"))
213 {
214 FP.foreground(
215 toColor(e.attribute("foregroundColor")),e.attribute("foregroundScale").toDouble(),e.attribute("foregroundOffset").toDouble());
216 if (e.hasAttribute("foregroundDashDown"))
217 FP.foregroundDash(e.attribute("foregroundDashDown").toDouble(),e.attribute("foregroundDashUp").toDouble());
218 }
219 if (e.hasAttribute("fillWithIcon"))
220 FP.foregroundUseIcon(e.attribute("fillWithIcon") == "yes");
221 if (e.hasAttribute("backgroundColor"))
222 FP.background(
223 toColor(e.attribute("backgroundColor")),e.attribute("backgroundScale").toDouble(),e.attribute("backgroundOffset").toDouble());
224 if (e.attribute("interior") == "yes")
225 FP.BackgroundInterior = true;
226 if (e.attribute("exterior") == "yes")
227 FP.BackgroundExterior = true;
228 if (e.hasAttribute("touchupColor"))
229 {
230 FP.touchup(
231 toColor(e.attribute("touchupColor")),e.attribute("touchupScale").toDouble(),e.attribute("touchupOffset").toDouble());
232 if (e.hasAttribute("touchupDashDown"))
233 FP.touchupDash(e.attribute("touchupDashDown").toDouble(),e.attribute("touchupDashUp").toDouble());
234 }
235 if (e.hasAttribute("fillColor"))
236 FP.foregroundFill(toColor(e.attribute("fillColor")));
237 if (e.hasAttribute("icon"))
238 {
239 QString iconFilename = e.attribute("icon");
240 if (!QFileInfo(iconFilename).isAbsolute())
241 iconFilename = QFileInfo(filename).absolutePath().append("/").append(iconFilename);
242 FP.setIcon(iconFilename,e.attribute("iconScale", "0.0").toDouble(),e.attribute("iconOffset", "0.0").toDouble());
243 }
244 if (e.attribute("drawTrafficDirectionMarks") == "yes")
245 FP.drawTrafficDirectionMarks(true);
246 if (e.hasAttribute("trafficDirectionMarksColor"))
247 FP.TrafficDirectionMarksColor = toColor((e.attribute("trafficDirectionMarksColor")));
248 if (e.hasAttribute("labelColor"))
249 {
250 FP.label(
251 toColor(e.attribute("labelColor")),e.attribute("labelScale").toDouble(),e.attribute("labelOffset").toDouble());
252 FP.setLabelFont(e.attribute("labelFont"));
253 FP.labelTag(e.attribute("labelTag"));
254 if (e.hasAttribute("labelHalo"))
255 FP.labelHalo((e.attribute("labelHalo") == "yes"));
256 if (e.hasAttribute("labelArea"))
257 FP.labelArea((e.attribute("labelArea") == "yes"));
258 if (e.hasAttribute("labelBackgroundColor"))
259 FP.labelBackground(toColor(e.attribute("labelBackgroundColor")));
260 if (e.hasAttribute("labelBackgroundTag"))
261 FP.labelBackgroundTag(e.attribute("labelBackgroundTag"));
262 }
263
264 QDomNode n = e.firstChild();
265 QList<QPair<QString,QString> > Pairs;
266 while (!n.isNull())
267 {
268 if (n.isElement())
269 {
270 QDomElement t = n.toElement();
271 if (t.tagName() == "selector")
272 {
273 if (!t.attribute("key").isEmpty())
274 Pairs.push_back(qMakePair(t.attribute("key"),t.attribute("value")));
275 else
276 {
277 FP.setSelector(t.attribute("expr"));
278 return FP;
279 }
280 }
281 }
282 n = n.nextSibling();
283 }
284 if (Pairs.size() == 1)
285 FP.setSelector(Pairs[0].first+"="+Pairs[0].second);
286 else if (Pairs.size())
287 {
288 bool Same = true;
289 for (int i=1; i<Pairs.size(); ++i)
290 if (Pairs[0].first != Pairs[i].first)
291 Same = false;
292 if (Same)
293 {
294 QStringList Options;
295 for (int i=0; i<Pairs.size(); ++i)
296 Options.push_back(Pairs[i].second);
297 FP.setSelector("["+ Pairs[0].first +"] isoneof ("+ Options.join(",") + ")");
298 }
299 else
300 {
301 QStringList Options;
302 for (int i=0; i<Pairs.size(); ++i)
303 Options.push_back(Pairs[i].first+"="+Pairs[i].second);
304 FP.setSelector(Options.join(" or "));
305 }
306 }
307
308 return FP;
309 }
310
userName() const311 QString Painter::userName() const
312 {
313 if (!theSelector.isEmpty())
314 return theSelector;
315 return "Unnamed";
316 }
317
zoomBoundaries() const318 QPair<qreal, qreal> Painter::zoomBoundaries() const
319 {
320 if (ZoomLimitSet)
321 return qMakePair(ZoomUnder,ZoomUpper);
322 return qMakePair((qreal)0.0,(qreal)0.0);
323 }
324
fillColor() const325 QColor Painter::fillColor() const
326 {
327 if (!ForegroundFill)
328 return QColor();
329 return ForegroundFillFillColor;
330 }
331
isFilled() const332 bool Painter::isFilled() const
333 {
334 return ForegroundFill;
335 }
336
drawTrafficDirectionMarks(bool b)337 Painter& Painter::drawTrafficDirectionMarks(bool b)
338 {
339 DrawTrafficDirectionMarks = b;
340 return *this;
341 }
342
zoomBoundary(qreal anUnder,qreal anUpper)343 Painter& Painter::zoomBoundary(qreal anUnder, qreal anUpper)
344 {
345 ZoomLimitSet = true;
346 ZoomUnder = anUnder;
347 ZoomUpper = anUpper;
348 return *this;
349 }
350
fillActive(bool b)351 Painter& Painter::fillActive(bool b)
352 {
353 ForegroundFill = b;
354 if (ForegroundFill && !ForegroundFillFillColor.isValid())
355 ForegroundFillFillColor.setRgb(0,0,0);
356 return *this;
357 }
358
foregroundFill(QColor FillColor)359 Painter& Painter::foregroundFill(QColor FillColor)
360 {
361 ForegroundFill = true;
362 ForegroundFillFillColor = FillColor;
363 return *this;
364 }
365
backgroundActive(bool b)366 Painter& Painter::backgroundActive(bool b)
367 {
368 DrawBackground = b;
369 return *this;
370 }
371
background(QColor Color,qreal Scale,qreal Offset)372 Painter& Painter::background(QColor Color, qreal Scale, qreal Offset)
373 {
374 DrawBackground = true;
375 BackgroundColor = Color;
376 BackgroundScale = Scale;
377 BackgroundOffset = Offset;
378 return *this;
379 }
380
backgroundBoundary() const381 LineParameters Painter::backgroundBoundary() const
382 {
383 LineParameters P;
384 P.Draw = DrawBackground;
385 P.Color = BackgroundColor;
386 P.Proportional = BackgroundScale;
387 P.Fixed = BackgroundOffset;
388 P.Dashed = false;
389 P.DashOn = P.DashOff = 0;
390 return P;
391 }
392
touchupActive(bool b)393 Painter& Painter::touchupActive(bool b)
394 {
395 DrawTouchup = b;
396 return *this;
397 }
398
touchupDash(qreal Dash,qreal White)399 Painter& Painter::touchupDash(qreal Dash, qreal White)
400 {
401 TouchupDashSet = true;
402 TouchupDash = Dash;
403 TouchupWhite = White;
404 return *this;
405 }
406
touchup(QColor Color,qreal Scale,qreal Offset)407 Painter& Painter::touchup(QColor Color, qreal Scale, qreal Offset)
408 {
409 DrawTouchup = true;
410 TouchupColor = Color;
411 TouchupScale = Scale;
412 TouchupOffset = Offset;
413 TouchupDashSet = false;
414 return *this;
415 }
416
foregroundActive(bool b)417 Painter& Painter::foregroundActive(bool b)
418 {
419 DrawForeground = b;
420 return *this;
421 }
422
foregroundDash(qreal Dash,qreal White)423 Painter& Painter::foregroundDash(qreal Dash, qreal White)
424 {
425 ForegroundDashSet = true;
426 ForegroundDash = Dash;
427 ForegroundWhite = White;
428 return *this;
429 }
430
foreground(QColor Color,qreal Scale,qreal Offset)431 Painter& Painter::foreground(QColor Color, qreal Scale, qreal Offset)
432 {
433 DrawForeground = true;
434 ForegroundColor = Color;
435 ForegroundScale = Scale;
436 ForegroundOffset = Offset;
437 ForegroundDashSet = false;
438 return *this;
439 }
440
foregroundUseIcon(bool b)441 Painter& Painter::foregroundUseIcon(bool b)
442 {
443 ForegroundFillUseIcon = b;
444 return *this;
445 }
446
clearForegroundDash()447 void Painter::clearForegroundDash()
448 {
449 ForegroundDashSet = false;
450 }
451
labelActive(bool b)452 Painter& Painter::labelActive(bool b)
453 {
454 DrawLabel = b;
455 return *this;
456 }
457
labelHalo(bool b)458 Painter& Painter::labelHalo(bool b)
459 {
460 LabelHalo = b;
461 return *this;
462 }
463
labelArea(bool b)464 Painter& Painter::labelArea(bool b)
465 {
466 LabelArea = b;
467 return *this;
468 }
469
labelTag(const QString & val)470 Painter& Painter::labelTag(const QString& val)
471 {
472 LabelTag = val;
473 return *this;
474 }
475
labelBackgroundTag(const QString & val)476 Painter& Painter::labelBackgroundTag(const QString& val)
477 {
478 LabelBackgroundTag = val;
479 return *this;
480 }
481
label(QColor Color,qreal Scale,qreal Offset)482 Painter& Painter::label(QColor Color, qreal Scale, qreal Offset)
483 {
484 DrawLabel = true;
485 LabelColor = Color;
486 LabelScale = Scale;
487 LabelOffset = Offset;
488 return *this;
489 }
490
labelBackgroundActive(bool b)491 Painter& Painter::labelBackgroundActive(bool b)
492 {
493 DrawLabelBackground = b;
494 if (DrawLabelBackground && !LabelBackgroundColor.isValid())
495 LabelBackgroundColor.setRgb(0,0,0);
496 return *this;
497 }
498
labelBackground(QColor bgColor)499 Painter& Painter::labelBackground(QColor bgColor)
500 {
501 DrawLabelBackground = true;
502 LabelBackgroundColor = bgColor;
503 return *this;
504 }
505
setLabelFont(const QString & descFont)506 Painter& Painter::setLabelFont(const QString& descFont)
507 {
508 LabelFont.fromString(descFont);
509 return *this;
510 }
511
labelBackgroundColor() const512 QColor Painter::labelBackgroundColor() const
513 {
514 if (!DrawLabelBackground)
515 return QColor();
516 return LabelBackgroundColor;
517 }
518
getLabelFont() const519 QFont Painter::getLabelFont() const
520 {
521 return LabelFont;
522 }
523
getLabelTag() const524 QString Painter::getLabelTag() const
525 {
526 return LabelTag;
527 }
528
getLabelHalo() const529 bool Painter::getLabelHalo() const
530 {
531 return LabelHalo;
532 }
533
getLabelArea() const534 bool Painter::getLabelArea() const
535 {
536 return LabelArea;
537 }
538
getLabelBackgroundTag() const539 QString Painter::getLabelBackgroundTag() const
540 {
541 return LabelBackgroundTag;
542 }
543
getBackgroundInterior() const544 bool Painter::getBackgroundInterior() const
545 {
546 return BackgroundInterior;
547 }
548
getBackgroundExterior() const549 bool Painter::getBackgroundExterior() const
550 {
551 return BackgroundExterior;
552 }
553
foregroundBoundary() const554 LineParameters Painter::foregroundBoundary() const
555 {
556 LineParameters P;
557 P.Draw = DrawForeground;
558 P.Color = ForegroundColor;
559 P.Proportional = ForegroundScale;
560 P.Fixed = ForegroundOffset;
561 P.Dashed = ForegroundDashSet;
562 P.DashOn = ForegroundDash;
563 P.DashOff = ForegroundWhite;
564 if (!P.Dashed)
565 P.DashOff = P.DashOn = 0;
566 return P;
567 }
568
clearTouchupDash()569 void Painter::clearTouchupDash()
570 {
571 TouchupDashSet = false;
572 }
573
touchupBoundary() const574 LineParameters Painter::touchupBoundary() const
575 {
576 LineParameters P;
577 P.Draw = DrawTouchup;
578 P.Color = TouchupColor;
579 P.Proportional = TouchupScale;
580 P.Fixed = TouchupOffset;
581 P.Dashed = TouchupDashSet;
582 P.DashOn = TouchupDash;
583 P.DashOff = TouchupWhite;
584 if (!P.Dashed)
585 P.DashOff = P.DashOn = 0;
586 return P;
587 }
588
labelBoundary() const589 LineParameters Painter::labelBoundary() const
590 {
591 LineParameters P;
592 P.Draw = DrawLabel;
593 P.Color = LabelColor;
594 P.Proportional = LabelScale;
595 P.Fixed = LabelOffset;
596 P.Dashed = false;
597 if (!P.Dashed)
598 P.DashOff = P.DashOn = 0.0;
599 return P;
600 }
601
setIcon(const QString & Name,qreal Scale,qreal Offset)602 Painter& Painter::setIcon(const QString& Name, qreal Scale, qreal Offset)
603 {
604 DrawIcon = true;
605 IconName = Name;
606 IconScale = Scale;
607 IconOffset = Offset;
608 return *this;
609 }
610
icon() const611 IconParameters Painter::icon() const
612 {
613 IconParameters P;
614 P.Draw = DrawIcon;
615 P.Name = IconName;
616 P.Proportional = IconScale;
617 P.Fixed = IconOffset;
618 return P;
619 }
620
iconActive(bool b)621 Painter& Painter::iconActive(bool b)
622 {
623 DrawIcon = b;
624 return *this;
625 }
626
setSelector(const QString & anExpression)627 void Painter::setSelector(const QString& anExpression)
628 {
629 theSelector = anExpression;
630 }
631
matchesZoom(qreal PixelPerM) const632 bool Painter::matchesZoom(qreal PixelPerM) const
633 {
634 if (ZoomLimitSet)
635 return (ZoomUnder <= PixelPerM) && (PixelPerM <= ZoomUpper);
636 return true;
637 }
638
639 /* GlobalPainter */
640
GlobalPainter()641 GlobalPainter::GlobalPainter()
642 : DrawBackground(false), DrawNodes(false)
643 {
644 }
645
GlobalPainter(const GlobalPainter & f)646 GlobalPainter::GlobalPainter(const GlobalPainter& f)
647 : DrawBackground(f.DrawBackground), BackgroundColor(f.BackgroundColor)
648 , DrawNodes(f.DrawNodes), NodesColor(f.NodesColor), NodesProportional(f.NodesProportional), NodesFixed(f.NodesFixed)
649 {
650 }
651
operator =(const GlobalPainter & f)652 GlobalPainter& GlobalPainter::operator=(const GlobalPainter& f)
653 {
654 if (&f == this) return *this;
655
656 DrawBackground = f.DrawBackground;
657 BackgroundColor = f.BackgroundColor;
658
659 DrawNodes = f.DrawNodes;
660 NodesColor = f.NodesColor;
661 NodesProportional = f.NodesProportional;
662 NodesFixed = f.NodesFixed;
663
664 return *this;
665 }
666
~GlobalPainter()667 GlobalPainter::~GlobalPainter()
668 {
669 }
670
toXML() const671 QString GlobalPainter::toXML() const
672 {
673 QString r;
674 r += "<global\n";
675 if (DrawBackground)
676 r += " " + colorAsXML("background",BackgroundColor);
677 if (DrawNodes)
678 r += " " + boundaryAsXML("nodes",NodesColor, NodesProportional, NodesFixed);
679 r += "/>\n";
680 return r;
681 }
682
fromXML(const QDomElement & e)683 GlobalPainter GlobalPainter::fromXML(const QDomElement& e)
684 {
685 GlobalPainter FP;
686
687 if (e.hasAttribute("backgroundColor")) {
688 FP.backgroundActive(true);
689 FP.background(toColor(e.attribute("backgroundColor")));
690 }
691 if (e.hasAttribute("nodesColor")) {
692 FP.nodesActive(true);
693 FP.NodesColor = toColor(e.attribute("nodesColor"));
694 FP.NodesProportional = e.attribute("nodesScale").toDouble();
695 FP.NodesFixed = e.attribute("nodesOffset").toDouble();
696 }
697
698 return FP;
699 }
700
backgroundActive(bool b)701 GlobalPainter& GlobalPainter::backgroundActive(bool b)
702 {
703 DrawBackground = b;
704 return *this;
705 }
706
getDrawBackground() const707 bool GlobalPainter::getDrawBackground() const
708 {
709 return DrawBackground;
710 }
711
background(QColor Color)712 GlobalPainter& GlobalPainter::background(QColor Color)
713 {
714 DrawBackground = true;
715 BackgroundColor = Color;
716 return *this;
717 }
718
getBackgroundColor() const719 QColor GlobalPainter::getBackgroundColor() const
720 {
721 return BackgroundColor;
722 }
723
nodesActive(bool b)724 GlobalPainter & GlobalPainter::nodesActive(bool b)
725 {
726 DrawNodes = b;
727 return *this;
728 }
729
nodes(QColor Color)730 GlobalPainter & GlobalPainter::nodes(QColor Color)
731 {
732 DrawNodes = true;
733 NodesColor = Color;
734 return *this;
735 }
736
getDrawNodes() const737 bool GlobalPainter::getDrawNodes() const
738 {
739 return DrawNodes;
740 }
741
getNodesColor() const742 QColor GlobalPainter::getNodesColor() const
743 {
744 return NodesColor;
745 }
746