author | leseb <leseb> | 2002-06-18 19:27:40 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-18 19:27:40 (UTC) |
commit | bcd6776c3e70efa41e759ac7707b2cae74f56f9c (patch) (unidiff) | |
tree | fcfebc17eb30b04eaaba51e740be6ead1ee5aa53 /noncore/graphics/drawpad | |
parent | 0e0abb9c315ac64f483e127f377ac933878e3519 (diff) | |
download | opie-bcd6776c3e70efa41e759ac7707b2cae74f56f9c.zip opie-bcd6776c3e70efa41e759ac7707b2cae74f56f9c.tar.gz opie-bcd6776c3e70efa41e759ac7707b2cae74f56f9c.tar.bz2 |
Anti-aliasing version!!!
-rw-r--r-- | noncore/graphics/drawpad/ellipsetool.cpp | 37 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filledellipsetool.cpp | 39 |
2 files changed, 69 insertions, 7 deletions
diff --git a/noncore/graphics/drawpad/ellipsetool.cpp b/noncore/graphics/drawpad/ellipsetool.cpp index c3badc3..733bade 100644 --- a/noncore/graphics/drawpad/ellipsetool.cpp +++ b/noncore/graphics/drawpad/ellipsetool.cpp | |||
@@ -7,39 +7,70 @@ | |||
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "ellipsetool.h" | 14 | #include "ellipsetool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | EllipseTool::~EllipseTool() | 27 | EllipseTool::~EllipseTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void EllipseTool::drawFinalShape(QPainter& p) | 31 | void EllipseTool::drawFinalShape(QPainter& p) |
32 | { | 32 | { |
33 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
35 | 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 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, | ||
59 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), | ||
60 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); | ||
61 | bigAreaPainter.end(); | ||
62 | |||
63 | bigAreaImage = bigAreaPixmap.convertToImage(); | ||
64 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | ||
65 | areaPixmap.convertFromImage(areaImage); | ||
66 | |||
36 | p.setRasterOp(Qt::CopyROP); | 67 | p.setRasterOp(Qt::CopyROP); |
37 | p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); | 68 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
38 | } | 69 | } |
39 | 70 | ||
40 | void EllipseTool::drawTemporaryShape(QPainter& p) | 71 | void EllipseTool::drawTemporaryShape(QPainter& p) |
41 | { | 72 | { |
42 | p.setRasterOp(Qt::NotROP); | 73 | p.setRasterOp(Qt::NotROP); |
43 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); | 74 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); |
44 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 75 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
45 | } | 76 | } |
diff --git a/noncore/graphics/drawpad/filledellipsetool.cpp b/noncore/graphics/drawpad/filledellipsetool.cpp index b446000..2f7ec8f 100644 --- a/noncore/graphics/drawpad/filledellipsetool.cpp +++ b/noncore/graphics/drawpad/filledellipsetool.cpp | |||
@@ -7,40 +7,71 @@ | |||
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "filledellipsetool.h" | 14 | #include "filledellipsetool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | FilledEllipseTool::~FilledEllipseTool() | 27 | FilledEllipseTool::~FilledEllipseTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void FilledEllipseTool::drawFinalShape(QPainter& p) | 31 | void FilledEllipseTool::drawFinalShape(QPainter& p) |
32 | { | 32 | { |
33 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
35 | p.setPen(m_pDrawPad->pen()); | 35 | |
36 | p.setBrush(m_pDrawPad->brush()); | 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 | bigAreaPainter.setBrush(m_pDrawPad->brush()); | ||
59 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, | ||
60 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), | ||
61 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); | ||
62 | bigAreaPainter.end(); | ||
63 | |||
64 | bigAreaImage = bigAreaPixmap.convertToImage(); | ||
65 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | ||
66 | areaPixmap.convertFromImage(areaImage); | ||
67 | |||
37 | p.setRasterOp(Qt::CopyROP); | 68 | p.setRasterOp(Qt::CopyROP); |
38 | p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); | 69 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
39 | } | 70 | } |
40 | 71 | ||
41 | void FilledEllipseTool::drawTemporaryShape(QPainter& p) | 72 | void FilledEllipseTool::drawTemporaryShape(QPainter& p) |
42 | { | 73 | { |
43 | p.setRasterOp(Qt::NotROP); | 74 | p.setRasterOp(Qt::NotROP); |
44 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); | 75 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); |
45 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 76 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
46 | } | 77 | } |