00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "ellipsetool.h"
00015
00016 #include "drawpad.h"
00017 #include "drawpadcanvas.h"
00018
00019 #include <qimage.h>
00020
00021 EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
00022 : ShapeTool(drawPad, drawPadCanvas)
00023 {
00024 }
00025
00026 EllipseTool::~EllipseTool()
00027 {
00028 }
00029
00030 void EllipseTool::drawFinalShape(QPainter& p)
00031 {
00032 p.setRasterOp(Qt::NotROP);
00033 p.drawRect(QRect(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 bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1,
00060 bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1),
00061 bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1)));
00062 bigAreaPainter.end();
00063
00064 bigAreaImage = bigAreaPixmap.convertToImage();
00065 areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
00066 areaPixmap.convertFromImage(areaImage);
00067
00068 p.drawPixmap(r.x(), r.y(), areaPixmap);
00069 } else {
00070 p.setPen(m_pDrawPad->pen());
00071 p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
00072 }
00073 }
00074
00075 void EllipseTool::drawTemporaryShape(QPainter& p)
00076 {
00077 p.setRasterOp(Qt::NotROP);
00078 p.drawRect(QRect(m_polyline[2], m_polyline[1]));
00079 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
00080 }