forked from unruhschuh/MrWriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stroke.cpp
71 lines (66 loc) · 1.68 KB
/
stroke.cpp
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
#include "stroke.h"
namespace MrDoc
{
Stroke::Stroke()
{
}
void Stroke::paint(QPainter &painter, qreal zoom, bool last)
{
if (points.length() == 1)
{
QRectF pointRect(zoom * points[0], QSizeF(0, 0));
qreal pad = penWidth * zoom / 2;
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(color));
painter.drawEllipse(pointRect.adjusted(-pad, -pad, pad, pad));
}
else
{
QPen pen;
pen.setColor(color);
if (pattern != solidLinePattern)
{
pen.setDashPattern(pattern);
}
pen.setCapStyle(Qt::RoundCap);
painter.setPen(pen);
qreal dashOffset = 0.0;
for (int j = 1; j < points.length(); ++j)
{
qreal tmpPenWidth = zoom * penWidth * (pressures.at(j - 1) + pressures.at(j)) / 2.0;
if (pattern != solidLinePattern)
{
pen.setDashOffset(dashOffset);
}
pen.setWidthF(tmpPenWidth);
painter.setPen(pen);
// painter.drawLine(zoom * points.at(j-1), zoom * points.at(j));
if (last == false)
{
painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j));
}
else if (last == true && j == points.length() - 1)
{
painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j));
}
if (tmpPenWidth != 0)
dashOffset += 1.0 / tmpPenWidth * (QLineF(zoom * points.at(j - 1), zoom * points.at(j))).length();
}
}
}
QRectF Stroke::boundingRect() const
{
QPolygonF tmpPoints = points;
QRectF bRect = tmpPoints.boundingRect();
qreal maxPressure = 0.0;
for (qreal p : pressures)
{
if (p > maxPressure)
{
maxPressure = p;
}
}
qreal pad = maxPressure * penWidth;
return bRect.adjusted(-pad, -pad, pad, pad);
}
}