00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "linetool.h"
00015
00016 #include "drawpad.h"
00017 #include "drawpadcanvas.h"
00018
00019 #include <qimage.h>
00020
00021 LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
00022 : ShapeTool(drawPad, drawPadCanvas)
00023 {
00024 }
00025
00026 LineTool::~LineTool()
00027 {
00028 }
00029
00030 void LineTool::drawFinalShape(QPainter& p)
00031 {
00032 p.setRasterOp(Qt::NotROP);
00033 p.drawLine(m_polyline[2], m_polyline[0]);
00034 p.setRasterOp(Qt::CopyROP);
00035
00036 if (m_pDrawPad->antiAliasing()) {
00037 QRect r = m_polyline.boundingRect();
00038 r = r.normalize();
00039 r.setLeft(r.left() - m_pDrawPad->pen().width());
00040 r.setTop(r.top() - m_pDrawPad->pen().width());
00041 r.setRight(r.right() + m_pDrawPad->pen().width());
00042 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
00043
00044 QPixmap areaPixmap(r.width(), r.height());
00045 bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r);
00046
00047 QImage areaImage = areaPixmap.convertToImage();
00048 QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
00049
00050 QPixmap bigAreaPixmap;
00051 bigAreaPixmap.convertFromImage(bigAreaImage);
00052
00053 QPen bigAreaPen = m_pDrawPad->pen();
00054 bigAreaPen.setWidth(bigAreaPen.width() * 3);
00055
00056 QPainter bigAreaPainter;
00057 bigAreaPainter.begin(&bigAreaPixmap);
00058 bigAreaPainter.setPen(bigAreaPen);
00059
00060 bigAreaPainter.drawLine((m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1,
00061 (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1);
00062
00063 bigAreaPainter.end();
00064
00065 bigAreaImage = bigAreaPixmap.convertToImage();
00066 areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
00067 areaPixmap.convertFromImage(areaImage);
00068
00069 p.drawPixmap(r.x(), r.y(), areaPixmap);
00070 } else {
00071 p.setPen(m_pDrawPad->pen());
00072 p.drawLine(m_polyline[2], m_polyline[0]);
00073 }
00074 }
00075
00076 void LineTool::drawTemporaryShape(QPainter& p)
00077 {
00078 p.setRasterOp(Qt::NotROP);
00079 p.drawLine(m_polyline[2], m_polyline[1]);
00080 p.drawLine(m_polyline[2], m_polyline[0]);
00081 }