LibreCAD
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
LinePatternPainter Class Reference

Painting line patterns on a QPaintDevice. More...

#include <linepatternpainter.h>

Public Member Functions

 LinePatternPainter (QPaintDevice *device, lc::DxfLinePatternByValue_CSPtr linePattern, int width=1)
 Constructor used to paint DxfLinePatterns. More...
 
 LinePatternPainter (QPaintDevice *device, double width, lc::DxfLinePatternByValue_CSPtr linePattern=nullptr)
 Constructor used to paint line width. More...
 
void drawLinePattern ()
 Paint line. More...
 

Private Attributes

QPaintDevice * _device
 
lc::DxfLinePatternByValue_CSPtr _linePattern
 
int _width
 

Detailed Description

Painting line patterns on a QPaintDevice.

Definition at line 10 of file linepatternpainter.h.

Constructor & Destructor Documentation

LinePatternPainter::LinePatternPainter ( QPaintDevice *  device,
lc::DxfLinePatternByValue_CSPtr  linePattern,
int  width = 1 
)

Constructor used to paint DxfLinePatterns.

Parameters
devicePointer to QPaintDevice
linePatternLinePattern to paint
widthWidth of the line (optional)

Definition at line 3 of file linepatternpainter.cpp.

3  :
4  _device(device),
5  _linePattern(linePattern),
6  _width(width) {
7 }
QPaintDevice * _device
lc::DxfLinePatternByValue_CSPtr _linePattern
LinePatternPainter::LinePatternPainter ( QPaintDevice *  device,
double  width,
lc::DxfLinePatternByValue_CSPtr  linePattern = nullptr 
)

Constructor used to paint line width.

Parameters
devicePointer to QPaintDevice
widthWidth of the line
linePatternLinePattern to paint (optional)

Definition at line 9 of file linepatternpainter.cpp.

9  :
10  _device(device),
11  _linePattern(linePattern),
12  _width(width) {
13 }
QPaintDevice * _device
lc::DxfLinePatternByValue_CSPtr _linePattern

Member Function Documentation

void LinePatternPainter::drawLinePattern ( )

Paint line.

Definition at line 15 of file linepatternpainter.cpp.

15  {
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

Member Data Documentation

QPaintDevice* LinePatternPainter::_device
private

Definition at line 33 of file linepatternpainter.h.

lc::DxfLinePatternByValue_CSPtr LinePatternPainter::_linePattern
private

Definition at line 34 of file linepatternpainter.h.

int LinePatternPainter::_width
private

Definition at line 35 of file linepatternpainter.h.


The documentation for this class was generated from the following files: