QElectroTech  0.70
elementpicturefactory.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "elementpicturefactory.h"
19 #include "elementslocation.h"
20 #include "qet.h"
21 #include "qetapp.h"
22 #include "partline.h"
23 
24 #include <QDomElement>
25 #include <QPainter>
26 #include <QTextDocument>
27 #include <QPicture>
28 #include <iostream>
29 #include <QAbstractTextDocumentLayout>
30 #include <QGraphicsSimpleTextItem>
31 
33 
42 void ElementPictureFactory::getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture)
43 {
44  if(!location.exist()) {
45  return;
46  }
47 
48  QUuid uuid = location.uuid();
49  if(Q_UNLIKELY(uuid.isNull()))
50  {
51  build(location, &picture, &low_picture);
52  return;
53  }
54 
55  if(m_pictures_H.keys().contains(uuid))
56  {
57  picture = m_pictures_H.value(uuid);
58  low_picture = m_low_pictures_H.value(uuid);
59  }
60  else
61  {
62  if (build(location))
63  {
64  picture = m_pictures_H.value(uuid);
65  low_picture = m_low_pictures_H.value(uuid);
66  }
67  }
68 }
69 
77 {
78  QUuid uuid = location.uuid();
79 
80  if (m_pixmap_H.contains(uuid)) {
81  return m_pixmap_H.value(uuid);
82  }
83 
84  if(build(location))
85  {
86  QDomElement dom = location.xml();
87  //size
88  int w = dom.attribute("width").toInt();
89  int h = dom.attribute("height").toInt();
90  while (w % 10) ++ w;
91  while (h % 10) ++ h;
92  //hotspot
93  int hsx = qMin(dom.attribute("hotspot_x").toInt(), w);
94  int hsy = qMin(dom.attribute("hotspot_y").toInt(), h);
95 
96  QPixmap pix(w, h);
97  pix.fill(QColor(255, 255, 255, 0));
98 
99  QPainter painter(&pix);
100  painter.setRenderHint(QPainter::Antialiasing, true);
101  painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
102  painter.translate(hsx, hsy);
103  painter.drawPicture(0, 0, m_pictures_H.value(uuid));
104 
105  if (!uuid.isNull()) {
106  m_pixmap_H.insert(uuid, pix);
107  }
108  return pix;
109  }
110 
111  return QPixmap();
112 }
113 
114 
121 {
122  if(!m_primitives_H.contains(location.uuid()))
123  build(location);
124 
125  return m_primitives_H.value(location.uuid());
126 }
127 
129  for (primitives p : m_primitives_H.values()) {
130  qDeleteAll(p.m_texts);
131  }
132 }
133 
144 bool ElementPictureFactory::build(const ElementsLocation &location, QPicture *picture, QPicture *low_picture)
145 {
146  QDomElement dom = location.xml();
147 
148  //Check if the curent version can read the xml description
149  if (dom.hasAttribute("version"))
150  {
151  bool conv_ok;
152  qreal element_version = dom.attribute("version").toDouble(&conv_ok);
153  if (conv_ok && QET::version.toDouble() < element_version)
154  {
155  std::cerr << qPrintable(
156  QObject::tr("Avertissement : l'élément "
157  " a été enregistré avec une version"
158  " ultérieure de QElectroTech.")
159  ) << std::endl;
160  }
161  }
162 
163  //This attributes must be present and valid
164  int w, h, hot_x, hot_y;
165  if (!QET::attributeIsAnInteger(dom, QString("width"), &w) ||\
166  !QET::attributeIsAnInteger(dom, QString("height"), &h) ||\
167  !QET::attributeIsAnInteger(dom, QString("hotspot_x"), &hot_x) ||\
168  !QET::attributeIsAnInteger(dom, QString("hotspot_y"), &hot_y))
169  {
170  return(false);
171  }
172 
173  QPainter painter;
174  QPicture pic;
175  primitives primitives_;
176  if (picture) {
177  painter.begin(picture);
178  }
179  else {
180  painter.begin(&pic);
181  }
182  painter.setRenderHint(QPainter::Antialiasing, true);
183  painter.setRenderHint(QPainter::TextAntialiasing, true);
184  painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
185 
186 
187  QPainter low_painter;
188  QPicture low_pic;
189  if (low_picture) {
190  low_painter.begin(low_picture);
191  }
192  else {
193  low_painter.begin(&low_pic);
194  }
195  low_painter.setRenderHint(QPainter::Antialiasing, true);
196  low_painter.setRenderHint(QPainter::TextAntialiasing, true);
197  low_painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
198 
199  QPen tmp;
200  tmp.setWidthF(1.0); //Vaudoo line to take into account the setCosmetic - don't remove
201  tmp.setCosmetic(true);
202  low_painter.setPen(tmp);
203 
204  //scroll of the Children of the Definition: Parts of the Drawing
205  for (QDomNode node = dom.firstChild() ; !node.isNull() ; node = node.nextSibling())
206  {
207  QDomElement elmts = node.toElement();
208  if (elmts.isNull()) {
209  continue;
210  }
211 
212  if (elmts.tagName() == "description")
213  {
214  //Manage the graphic description = part of drawing
215  for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
216  {
217  QDomElement qde = n.toElement();
218  if (qde.isNull()) {
219  continue;
220  }
221  parseElement(qde, painter, primitives_);
222  primitives fake_prim;
223  parseElement(qde, low_painter, fake_prim);
224  }
225  }
226  }
227 
228  //End of the drawing
229  painter.end();
230  low_painter.end();
231 
232  if (!picture) {
233  m_pictures_H.insert(location.uuid(), pic);
234  m_primitives_H.insert(location.uuid(), primitives_);
235  }
236  if (!low_picture) {
237  m_low_pictures_H.insert(location.uuid(), low_pic);
238  m_primitives_H.insert(location.uuid(), primitives_);
239  }
240  return true;
241 }
242 
243 void ElementPictureFactory::parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const
244 {
245  if (dom.tagName() == "line") (parseLine (dom, painter, prim));
246  else if (dom.tagName() == "rect") (parseRect (dom, painter, prim));
247  else if (dom.tagName() == "ellipse") (parseEllipse(dom, painter, prim));
248  else if (dom.tagName() == "circle") (parseCircle (dom, painter, prim));
249  else if (dom.tagName() == "arc") (parseArc (dom, painter, prim));
250  else if (dom.tagName() == "polygon") (parsePolygon(dom, painter, prim));
251  else if (dom.tagName() == "text") (parseText (dom, painter, prim));
252 }
253 
254 void ElementPictureFactory::parseLine(const QDomElement &dom, QPainter &painter, primitives &prim) const
255 {
256  //This attributes must be present and valid
257  qreal x1, y1, x2, y2;
258  if (!QET::attributeIsAReal(dom, QString("x1"), &x1)) return;
259  if (!QET::attributeIsAReal(dom, QString("y1"), &y1)) return;
260  if (!QET::attributeIsAReal(dom, QString("x2"), &x2)) return;
261  if (!QET::attributeIsAReal(dom, QString("y2"), &y2)) return;
262 
263  Qet::EndType first_end = Qet::endTypeFromString(dom.attribute("end1"));
264  Qet::EndType second_end = Qet::endTypeFromString(dom.attribute("end2"));
265  qreal length1, length2;
266  if (!QET::attributeIsAReal(dom, QString("length1"), &length1)) length1 = 1.5;
267  if (!QET::attributeIsAReal(dom, QString("length2"), &length2)) length2 = 1.5;
268 
269  painter.save();
270  setPainterStyle(dom, painter);
271  QPen t = painter.pen();
272  t.setJoinStyle(Qt::MiterJoin);
273  painter.setPen(t);
274 
275  QLineF line(x1, y1, x2, y2);
276 
277  prim.m_lines << line;
278 
279  QPointF point1(line.p1());
280  QPointF point2(line.p2());
281 
282  qreal line_length(line.length());
283  qreal pen_width = painter.pen().widthF();
284 
285  //Check if we must to draw extremity
286  bool draw_1st_end, draw_2nd_end;
287  qreal reduced_line_length = line_length - (length1 * PartLine::requiredLengthForEndType(first_end));
288  draw_1st_end = first_end && reduced_line_length >= 0;
289  if (draw_1st_end) {
290  reduced_line_length -= (length2 * PartLine::requiredLengthForEndType(second_end));
291  } else {
292  reduced_line_length = line_length - (length2 * PartLine::requiredLengthForEndType(second_end));
293  }
294  draw_2nd_end = second_end && reduced_line_length >= 0;
295 
296  //Draw first extremity
297  QPointF start_point, stop_point;
298  if (draw_1st_end) {
299  QList<QPointF> four_points1(PartLine::fourEndPoints(point1, point2, length1));
300  if (first_end == Qet::Circle) {
301  painter.drawEllipse(QRectF(four_points1[0] - QPointF(length1, length1), QSizeF(length1 * 2.0, length1 * 2.0)));
302  start_point = four_points1[1];
303  } else if (first_end == Qet::Diamond) {
304  painter.drawPolygon(QPolygonF() << four_points1[1] << four_points1[2] << point1 << four_points1[3]);
305  start_point = four_points1[1];
306  } else if (first_end == Qet::Simple) {
307  painter.drawPolyline(QPolygonF() << four_points1[3] << point1 << four_points1[2]);
308  start_point = point1;
309 
310  } else if (first_end == Qet::Triangle) {
311  painter.drawPolygon(QPolygonF() << four_points1[0] << four_points1[2] << point1 << four_points1[3]);
312  start_point = four_points1[0];
313  }
314 
315  //Adjust the begining according to the width of the pen
316  if (pen_width && (first_end == Qet::Simple || first_end == Qet::Circle)) {
317  start_point = QLineF(start_point, point2).pointAt(pen_width / 2.0 / line_length);
318  }
319  } else {
320  start_point = point1;
321  }
322 
323  //Draw second extremity
324  if (draw_2nd_end) {
325  QList<QPointF> four_points2(PartLine::fourEndPoints(point2, point1, length2));
326  if (second_end == Qet::Circle) {
327  painter.drawEllipse(QRectF(four_points2[0] - QPointF(length2, length2), QSizeF(length2 * 2.0, length2 * 2.0)));
328  stop_point = four_points2[1];
329  } else if (second_end == Qet::Diamond) {
330  painter.drawPolygon(QPolygonF() << four_points2[2] << point2 << four_points2[3] << four_points2[1]);
331  stop_point = four_points2[1];
332  } else if (second_end == Qet::Simple) {
333  painter.drawPolyline(QPolygonF() << four_points2[3] << point2 << four_points2[2]);
334  stop_point = point2;
335  } else if (second_end == Qet::Triangle) {
336  painter.drawPolygon(QPolygonF() << four_points2[0] << four_points2[2] << point2 << four_points2[3] << four_points2[0]);
337  stop_point = four_points2[0];
338  }
339 
340  //Adjust the end according to the width of the pen
341  if (pen_width && (second_end == Qet::Simple || second_end == Qet::Circle)) {
342  stop_point = QLineF(point1, stop_point).pointAt((line_length - (pen_width / 2.0)) / line_length);
343  }
344  } else {
345  stop_point = point2;
346  }
347 
348  painter.drawLine(start_point, stop_point);
349 
350  painter.restore();
351 }
352 
353 void ElementPictureFactory::parseRect(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
354 {
355  //This attributes must be present and valid
356  qreal rect_x, rect_y, rect_w, rect_h, rect_rx, rect_ry;
357  if (!QET::attributeIsAReal(dom, QString("x"), &rect_x)) return;
358  if (!QET::attributeIsAReal(dom, QString("y"), &rect_y)) return;
359  if (!QET::attributeIsAReal(dom, QString("width"), &rect_w)) return;
360  if (!QET::attributeIsAReal(dom, QString("height"), &rect_h)) return;
361  rect_rx = dom.attribute("rx", "0").toDouble();
362  rect_ry = dom.attribute("ry", "0").toDouble();
363 
364  prim.m_rectangles << QRectF(rect_x, rect_y, rect_w, rect_h);
365 
366  painter.save();
367  setPainterStyle(dom, painter);
368 
369  QPen p = painter.pen();
370  p.setJoinStyle(Qt::MiterJoin);
371  painter.setPen(p);
372 
373  painter.drawRoundedRect(QRectF(rect_x, rect_y, rect_w, rect_h), rect_rx, rect_ry);
374  painter.restore();
375 }
376 
377 void ElementPictureFactory::parseEllipse(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
378 {
379  //This attributes must be present and valid
380  qreal ellipse_x, ellipse_y, ellipse_l, ellipse_h;
381  if (!QET::attributeIsAReal(dom, QString("x"), &ellipse_x)) return;
382  if (!QET::attributeIsAReal(dom, QString("y"), &ellipse_y)) return;
383  if (!QET::attributeIsAReal(dom, QString("width"), &ellipse_l)) return;
384  if (!QET::attributeIsAReal(dom, QString("height"), &ellipse_h)) return;
385  painter.save();
386  setPainterStyle(dom, painter);
387 
388  QVector<qreal> arc;
389  arc.push_back(ellipse_x);
390  arc.push_back(ellipse_y);
391  arc.push_back(ellipse_l);
392  arc.push_back(ellipse_h);
393  arc.push_back(0);
394  arc.push_back(360);
395  prim.m_arcs << arc;
396 
397  painter.drawEllipse(QRectF(ellipse_x, ellipse_y, ellipse_l, ellipse_h));
398  painter.restore();
399 }
400 
401 void ElementPictureFactory::parseCircle(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
402 {
403  //This attributes must be present and valid
404  qreal cercle_x, cercle_y, cercle_r;
405  if (!QET::attributeIsAReal(dom, QString("x"), &cercle_x)) return;
406  if (!QET::attributeIsAReal(dom, QString("y"), &cercle_y)) return;
407  if (!QET::attributeIsAReal(dom, QString("diameter"), &cercle_r)) return;
408  painter.save();
409  setPainterStyle(dom, painter);
410  QRectF circle_bounding_rect(cercle_x, cercle_y, cercle_r, cercle_r);
411 
412  prim.m_circles << circle_bounding_rect;
413 
414  painter.drawEllipse(circle_bounding_rect);
415  painter.restore();
416 }
417 
418 void ElementPictureFactory::parseArc(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
419 {
420  //This attributes must be present and valid
421  qreal arc_x, arc_y, arc_l, arc_h, arc_s, arc_a;
422  if (!QET::attributeIsAReal(dom, QString("x"), &arc_x)) return;
423  if (!QET::attributeIsAReal(dom, QString("y"), &arc_y)) return;
424  if (!QET::attributeIsAReal(dom, QString("width"), &arc_l)) return;
425  if (!QET::attributeIsAReal(dom, QString("height"), &arc_h)) return;
426  if (!QET::attributeIsAReal(dom, QString("start"), &arc_s)) return;
427  if (!QET::attributeIsAReal(dom, QString("angle"), &arc_a)) return;
428 
429  painter.save();
430  setPainterStyle(dom, painter);
431 
432  QVector<qreal> arc;
433  arc.push_back(arc_x);
434  arc.push_back(arc_y);
435  arc.push_back(arc_l);
436  arc.push_back(arc_h);
437  arc.push_back(arc_s);
438  arc.push_back(arc_a);
439  prim.m_arcs << arc;
440 
441  painter.drawArc(QRectF(arc_x, arc_y, arc_l, arc_h), (int)(arc_s * 16), (int)(arc_a * 16));
442  painter.restore();
443 }
444 
445 void ElementPictureFactory::parsePolygon(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
446 {
447  int i = 1;
448  while(true) {
449  if (QET::attributeIsAReal(dom, QString("x%1").arg(i)) && QET::attributeIsAReal(dom, QString("y%1").arg(i))) ++ i;
450  else break;
451  }
452  if (i < 3) {
453  return;
454  }
455 
456  QVector<QPointF> points; // empty vector created instead of default initialized vector with i-1 elements.
457  for (int j = 1 ; j < i ; ++ j) {
458  points.insert(
459  j - 1,
460  QPointF(
461  dom.attribute(QString("x%1").arg(j)).toDouble(),
462  dom.attribute(QString("y%1").arg(j)).toDouble()
463  )
464  );
465  }
466 
467  painter.save();
468  setPainterStyle(dom, painter);
469  if (dom.attribute("closed") == "false") painter.drawPolyline(points.data(), i-1);
470  else {
471  painter.drawPolygon(points.data(), i-1);
472 
473  // insert first point at the end again for DXF export.
474  points.push_back(points[0]);
475  }
476 
477  prim.m_polygons << points;
478 
479  painter.restore();
480 }
481 
482 void ElementPictureFactory::parseText(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
483 {
484  Q_UNUSED(prim);
485 
486  if (dom.tagName() != "text") {
487  return;
488  }
489 
490  painter.save();
491  setPainterStyle(dom, painter);
492 
493  //Get the font and metric
494  QFont font_;
495  if (dom.hasAttribute("size")) {
496  font_ = QETApp::diagramTextsFont(dom.attribute("size").toDouble());
497  }
498  else if (dom.hasAttribute("font")) {
499  font_.fromString(dom.attribute("font"));
500  }
501 
502  QColor text_color(dom.attribute("color", "#000000"));
503 
504  //Instanciate a QTextDocument (like the QGraphicsTextItem class)
505  //for generate the graphics rendering of the text
506  QTextDocument text_document;
507  text_document.setDefaultFont(font_);
508  text_document.setPlainText(dom.attribute("text"));
509 
510  painter.setTransform(QTransform(), false);
511  painter.translate(dom.attribute("x").toDouble(), dom.attribute("y").toDouble());
512  painter.rotate(dom.attribute("rotation", "0").toDouble());
513 
514  /*
515  Deplace le systeme de coordonnees du QPainter pour effectuer le rendu au
516  bon endroit ; note : on soustrait l'ascent() de la police pour
517  determiner le coin superieur gauche du texte alors que la position
518  indiquee correspond a la baseline.
519  */
520  QFontMetrics qfm(font_);
521  QPointF qpainter_offset(0.0, -qfm.ascent());
522 
523  //adjusts the offset by the margin of the text document
524  text_document.setDocumentMargin(0.0);
525 
526  painter.translate(qpainter_offset);
527 
528  // force the palette used to render the QTextDocument
529  QAbstractTextDocumentLayout::PaintContext ctx;
530  ctx.palette.setColor(QPalette::Text, text_color);
531  text_document.documentLayout() -> draw(&painter, ctx);
532 
533  //A very dirty workaround for export this text to dxf
534  QGraphicsSimpleTextItem *qgsti = new QGraphicsSimpleTextItem();
535  qgsti->setText(dom.attribute("text"));
536  qgsti->setFont(font_);
537  qgsti->setPos(dom.attribute("x").toDouble(), dom.attribute("y").toDouble());
538  qgsti->setRotation(dom.attribute("rotation", "0").toDouble());
539  prim.m_texts << qgsti;
540 
541  painter.restore();
542 }
543 
550 void ElementPictureFactory::setPainterStyle(const QDomElement &dom, QPainter &painter) const
551 {
552  QPen pen = painter.pen();
553  QBrush brush = painter.brush();
554 
555  pen.setJoinStyle(Qt::BevelJoin);
556  pen.setCapStyle(Qt::SquareCap);
557 
558  //Get the couples style/value
559  const QStringList styles = dom.attribute("style").split(";", QString::SkipEmptyParts);
560 
561  QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*$");
562  for (QString style : styles) {
563  if (rx.exactMatch(style)) {
564  QString style_name = rx.cap(1);
565  QString style_value = rx.cap(2);
566  if (style_name == "line-style") {
567  if (style_value == "dashed") pen.setStyle(Qt::DashLine);
568  else if (style_value == "dotted") pen.setStyle(Qt::DotLine);
569  else if (style_value == "dashdotted") pen.setStyle(Qt::DashDotLine);
570  else if (style_value == "normal") pen.setStyle(Qt::SolidLine);
571  } else if (style_name == "line-weight") {
572  if (style_value == "none") pen.setColor(QColor(0, 0, 0, 0));
573  else if (style_value == "thin") pen.setWidth(0);
574  else if (style_value == "normal") pen.setWidthF(1.0);
575  else if (style_value == "hight") pen.setWidthF(2.0);
576  else if (style_value == "eleve") pen.setWidthF(5.0);
577 
578  } else if (style_name == "filling") {
579  if (style_value == "white") {
580  brush.setStyle(Qt::SolidPattern);
581  brush.setColor(Qt::white);
582  } else if (style_value == "black") {
583  brush.setStyle(Qt::SolidPattern);
584  brush.setColor(Qt::black);
585  } else if (style_value == "blue") {
586  brush.setStyle(Qt::SolidPattern);
587  brush.setColor(Qt::blue);
588  } else if (style_value == "red") {
589  brush.setStyle(Qt::SolidPattern);
590  brush.setColor(Qt::red);
591  } else if (style_value == "green") {
592  brush.setStyle(Qt::SolidPattern);
593  brush.setColor(Qt::green);
594  } else if (style_value == "gray") {
595  brush.setStyle(Qt::SolidPattern);
596  brush.setColor(Qt::gray);
597  } else if (style_value == "brun") {
598  brush.setStyle(Qt::SolidPattern);
599  brush.setColor(QColor(97, 44, 0));
600  } else if (style_value == "yellow") {
601  brush.setStyle(Qt::SolidPattern);
602  brush.setColor(Qt::yellow);
603  } else if (style_value == "cyan") {
604  brush.setStyle(Qt::SolidPattern);
605  brush.setColor(Qt::cyan);
606  } else if (style_value == "magenta") {
607  brush.setStyle(Qt::SolidPattern);
608  brush.setColor(Qt::magenta);
609  } else if (style_value == "lightgray") {
610  brush.setStyle(Qt::SolidPattern);
611  brush.setColor(Qt::lightGray);
612  } else if (style_value == "orange") {
613  brush.setStyle(Qt::SolidPattern);
614  brush.setColor(QColor(255, 128, 0));
615  } else if (style_value == "purple") {
616  brush.setStyle(Qt::SolidPattern);
617  brush.setColor(QColor(136, 28, 168));
618  }else if (style_value == "hor") {
619  brush.setStyle(Qt::HorPattern);
620  brush.setColor(Qt::black);
621  } else if (style_value == "ver") {
622  brush.setStyle(Qt::VerPattern);
623  brush.setColor(Qt::black);
624  } else if (style_value == "bdiag") {
625  brush.setStyle(Qt::BDiagPattern);
626  brush.setColor(Qt::black);
627  } else if (style_value == "fdiag") {
628  brush.setStyle(Qt::FDiagPattern);
629  brush.setColor(Qt::black);
630  } else if (style_value == "none") {
631  brush.setStyle(Qt::NoBrush);
632  }
633  } else if (style_name == "color") {
634  if (style_value == "black") {
635  pen.setColor(QColor(0, 0, 0, pen.color().alpha()));
636  } else if (style_value == "white") {
637  pen.setColor(QColor(255, 255, 255, pen.color().alpha()));
638  } else if (style_value == "red") {
639  pen.setColor(Qt::red);
640  }else if (style_value == "blue") {
641  pen.setColor(Qt::blue);
642  }else if (style_value == "green") {
643  pen.setColor(Qt::green);
644  }else if (style_value == "gray") {
645  pen.setColor(Qt::gray);
646  }else if (style_value == "brun") {
647  pen.setColor(QColor(97, 44, 0));
648  }else if (style_value == "yellow") {
649  pen.setColor(Qt::yellow);
650  }else if (style_value == "cyan") {
651  pen.setColor(Qt::cyan);
652  }else if (style_value == "magenta") {
653  pen.setColor(Qt::magenta);
654  }else if (style_value == "lightgray") {
655  pen.setColor(Qt::lightGray);
656  }else if (style_value == "orange") {
657  pen.setColor(QColor(255, 128, 0));
658  }else if (style_value == "purple") {
659  pen.setColor(QColor(136, 28, 168));
660  } else if (style_value == "none") {
661  pen.setBrush(Qt::transparent);
662  }
663  }
664  }
665  }
666 
667  painter.setPen(pen);
668  painter.setBrush(brush);
669 }
EndType
This enum lists the various available endings for line primitives when drawing an electrical element...
Definition: qet.h:191
void parseCircle(const QDomElement &dom, QPainter &painter, primitives &prim) const
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
Definition: qet.cpp:200
static ElementPictureFactory * m_factory
QHash< QUuid, primitives > m_primitives_H
Circle.
Definition: qet.h:195
QHash< QUuid, QPicture > m_pictures_H
Diamond.
Definition: qet.h:196
void parseEllipse(const QDomElement &dom, QPainter &painter, primitives &prim) const
void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const
void setPainterStyle(const QDomElement &dom, QPainter &painter) const
ElementPictureFactory::setPainterStyle apply the style store in dom to painter.
void parseText(const QDomElement &dom, QPainter &painter, primitives &prim) const
void parseArc(const QDomElement &dom, QPainter &painter, primitives &prim) const
void getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture)
ElementPictureFactory::getPictures Set the picture of the element at location. Note, picture can be null.
const QString version
QElectroTech version (as string, used to mark projects and elements XML documents) ...
Definition: qet.h:30
void parseRect(const QDomElement &dom, QPainter &painter, primitives &prim) const
QUuid uuid() const
ElementsLocation::uuid.
static uint requiredLengthForEndType(const Qet::EndType &)
PartLine::requiredLengthForEndType.
Definition: partline.cpp:54
ElementPictureFactory::primitives getPrimitives(const ElementsLocation &location)
ElementPictureFactory::getPrimitives.
QIcon tr
Definition: qeticons.cpp:204
QPixmap pixmap(const ElementsLocation &location)
ElementPictureFactory::pixmap.
static Qet::EndType endTypeFromString(const QString &)
Definition: qet.cpp:466
QDomElement xml() const
ElementsLocation::xml.
Triangle.
Definition: qet.h:194
QHash< QUuid, QPixmap > m_pixmap_H
bool attributeIsAReal(const QDomElement &, const QString &, qreal *=nullptr)
Definition: qet.cpp:219
bool exist() const
ElementsLocation::exist.
Base-less triangle.
Definition: qet.h:193
QList< QVector< QPointF > > m_polygons
QList< QGraphicsSimpleTextItem * > m_texts
static QList< QPointF > fourEndPoints(const QPointF &, const QPointF &, const qreal &)
PartLine::fourEndPoints Return the four interesting point needed to draw the shape at extremity of li...
Definition: partline.cpp:601
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9...
Definition: qetapp.cpp:910
void parseLine(const QDomElement &dom, QPainter &painter, primitives &prim) const
bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr)
ElementPictureFactory::build Build the picture from location.
void parsePolygon(const QDomElement &dom, QPainter &painter, primitives &prim) const
The ElementPictureFactory class This class is singleton factory, use to create and get the picture us...
QHash< QUuid, QPicture > m_low_pictures_H