LibreCAD
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
linepatternpainter.cpp
Go to the documentation of this file.
1 #include "linepatternpainter.h"
2 
3 LinePatternPainter::LinePatternPainter(QPaintDevice *device, lc::DxfLinePatternByValue_CSPtr linePattern, int width) :
4  _device(device),
5  _linePattern(linePattern),
6  _width(width) {
7 }
8 
9 LinePatternPainter::LinePatternPainter(QPaintDevice *device, double width, lc::DxfLinePatternByValue_CSPtr linePattern) :
10  _device(device),
11  _linePattern(linePattern),
12  _width(width) {
13 }
14 
16  if(_device == NULL) {
17  return;
18  }
19 
20  QPen pen;
21 
22  if(_linePattern != nullptr && _linePattern->length() != 0) {
23  QVector<qreal> dashes;
24 
25  for(auto a : _linePattern->lcPattern(_width)) {
26  dashes << a;
27  }
28 
29  //Qt always want a space at end
30  if(dashes.size() % 2 != 0) {
31  dashes << 0;
32  }
33 
34  pen.setDashPattern(dashes);
35  }
36 
37  pen.setColor(Qt::black);
38  pen.setWidth(_width);
39 
40  QPainter painter(_device);
41  painter.fillRect(QRect(0, 0, _device->width(), _device->height()), QBrush(Qt::white));
42 
43  painter.setPen(pen);
44  painter.drawLine(0, _device->height()/2, _device->width(), _device->height()/2);
45 }
QPaintDevice * _device
lc::DxfLinePatternByValue_CSPtr _linePattern
LinePatternPainter(QPaintDevice *device, lc::DxfLinePatternByValue_CSPtr linePattern, int width=1)
Constructor used to paint DxfLinePatterns.
void drawLinePattern()
Paint line.