author | leseb <leseb> | 2002-06-19 06:28:00 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-19 06:28:00 (UTC) |
commit | f2cf56b43d80c16329bda01f9e37e52fb8546816 (patch) (unidiff) | |
tree | e94db34e932ca1f135f98642a6f15b03f32c920d | |
parent | b83e9d1f794fdd6089beda10697243bb087e3d0a (diff) | |
download | opie-f2cf56b43d80c16329bda01f9e37e52fb8546816.zip opie-f2cf56b43d80c16329bda01f9e37e52fb8546816.tar.gz opie-f2cf56b43d80c16329bda01f9e37e52fb8546816.tar.bz2 |
Anti-aliasing support
-rw-r--r-- | noncore/graphics/drawpad/linetool.cpp | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/noncore/graphics/drawpad/linetool.cpp b/noncore/graphics/drawpad/linetool.cpp index 94ca165..1480df2 100644 --- a/noncore/graphics/drawpad/linetool.cpp +++ b/noncore/graphics/drawpad/linetool.cpp | |||
@@ -13,12 +13,15 @@ | |||
13 | 13 | ||
14 | #include "linetool.h" | 14 | #include "linetool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qimage.h> | ||
20 | #include <qpixmap.h> | ||
21 | |||
19 | LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
20 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
21 | { | 24 | { |
22 | } | 25 | } |
23 | 26 | ||
24 | LineTool::~LineTool() | 27 | LineTool::~LineTool() |
@@ -26,15 +29,55 @@ LineTool::~LineTool() | |||
26 | } | 29 | } |
27 | 30 | ||
28 | void LineTool::drawFinalShape(QPainter& p) | 31 | void LineTool::drawFinalShape(QPainter& p) |
29 | { | 32 | { |
30 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
31 | p.drawLine(m_polyline[2], m_polyline[0]); | 34 | p.drawLine(m_polyline[2], m_polyline[0]); |
32 | p.setPen(m_pDrawPad->pen()); | 35 | |
36 | QRect r = m_polyline.boundingRect(); | ||
37 | r = r.normalize(); | ||
38 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | ||
39 | r.setTop(r.top() - m_pDrawPad->pen().width()); | ||
40 | r.setRight(r.right() + m_pDrawPad->pen().width()); | ||
41 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
42 | |||
43 | QPixmap areaPixmap(r.width(), r.height()); | ||
44 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); | ||
45 | |||
46 | QImage areaImage = areaPixmap.convertToImage(); | ||
47 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | ||
48 | |||
49 | QPixmap bigAreaPixmap; | ||
50 | bigAreaPixmap.convertFromImage(bigAreaImage); | ||
51 | |||
52 | QPen bigAreaPen = m_pDrawPad->pen(); | ||
53 | bigAreaPen.setWidth(bigAreaPen.width() * 3); | ||
54 | |||
55 | QPainter bigAreaPainter; | ||
56 | bigAreaPainter.begin(&bigAreaPixmap); | ||
57 | bigAreaPainter.setPen(bigAreaPen); | ||
58 | |||
59 | if (((m_polyline[2].x() < m_polyline[0].x()) && (m_polyline[2].y() < m_polyline[0].y())) | ||
60 | || ((m_polyline[2].x() > m_polyline[0].x()) && (m_polyline[2].y() > m_polyline[0].y()))) { | ||
61 | |||
62 | bigAreaPainter.drawLine(bigAreaPen.width() + 1, bigAreaPen.width() + 1, | ||
63 | bigAreaPixmap.width() - bigAreaPen.width() - 2, | ||
64 | bigAreaPixmap.height() - bigAreaPen.width() - 2); | ||
65 | } else { | ||
66 | bigAreaPainter.drawLine(bigAreaPen.width() + 1, bigAreaPixmap.height() - bigAreaPen.width() - 2, | ||
67 | bigAreaPixmap.width() - bigAreaPen.width() - 2, bigAreaPen.width() + 1); | ||
68 | } | ||
69 | |||
70 | bigAreaPainter.end(); | ||
71 | |||
72 | bigAreaImage = bigAreaPixmap.convertToImage(); | ||
73 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | ||
74 | areaPixmap.convertFromImage(areaImage); | ||
75 | |||
33 | p.setRasterOp(Qt::CopyROP); | 76 | p.setRasterOp(Qt::CopyROP); |
34 | p.drawLine(m_polyline[2], m_polyline[0]); | 77 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
35 | } | 78 | } |
36 | 79 | ||
37 | void LineTool::drawTemporaryShape(QPainter& p) | 80 | void LineTool::drawTemporaryShape(QPainter& p) |
38 | { | 81 | { |
39 | p.setRasterOp(Qt::NotROP); | 82 | p.setRasterOp(Qt::NotROP); |
40 | p.drawLine(m_polyline[2], m_polyline[1]); | 83 | p.drawLine(m_polyline[2], m_polyline[1]); |