00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "pointtool.h"
00015
00016 #include "drawpad.h"
00017 #include "drawpadcanvas.h"
00018 #include "page.h"
00019
00020 #include <qimage.h>
00021
00022 PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
00023 : Tool(drawPad, drawPadCanvas)
00024 {
00025 m_mousePressed = false;
00026 m_polyline.resize(3);
00027 }
00028
00029 PointTool::~PointTool()
00030 {
00031 }
00032
00033 void PointTool::mousePressEvent(QMouseEvent* e)
00034 {
00035 m_pDrawPadCanvas->backupPage();
00036
00037 m_mousePressed = true;
00038 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
00039 }
00040
00041 void PointTool::mouseReleaseEvent(QMouseEvent* e)
00042 {
00043 Q_UNUSED(e)
00044
00045 m_mousePressed = false;
00046 }
00047
00048 void PointTool::mouseMoveEvent(QMouseEvent* e)
00049 {
00050 if (m_mousePressed) {
00051 m_polyline[2] = m_polyline[1];
00052 m_polyline[1] = m_polyline[0];
00053 m_polyline[0] = e->pos();
00054
00055 QRect r = m_polyline.boundingRect();
00056 r = r.normalize();
00057 r.setLeft(r.left() - m_pDrawPad->pen().width());
00058 r.setTop(r.top() - m_pDrawPad->pen().width());
00059 r.setRight(r.right() + m_pDrawPad->pen().width());
00060 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
00061
00062 QPainter painter;
00063 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
00064
00065 if (m_pDrawPad->antiAliasing()) {
00066 QPixmap areaPixmap(r.width(), r.height());
00067 bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r);
00068
00069 QImage areaImage = areaPixmap.convertToImage();
00070 QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
00071
00072 QPixmap bigAreaPixmap;
00073 bigAreaPixmap.convertFromImage(bigAreaImage);
00074
00075 QPen bigAreaPen = m_pDrawPad->pen();
00076 bigAreaPen.setWidth(bigAreaPen.width() * 3);
00077
00078 QPainter bigAreaPainter;
00079 bigAreaPainter.begin(&bigAreaPixmap);
00080 bigAreaPainter.setPen(bigAreaPen);
00081
00082 QPointArray bigAreaPolyline(3);
00083 bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1);
00084 bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1);
00085 bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1);
00086
00087 bigAreaPainter.drawPolyline(bigAreaPolyline);
00088 bigAreaPainter.end();
00089
00090 bigAreaImage = bigAreaPixmap.convertToImage();
00091 areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
00092 areaPixmap.convertFromImage(areaImage);
00093
00094 painter.drawPixmap(r.x(), r.y(), areaPixmap);
00095 } else {
00096 painter.setPen(m_pDrawPad->pen());
00097 painter.drawPolyline(m_polyline);
00098 }
00099
00100 painter.end();
00101
00102 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
00103 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
00104
00105 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
00106 m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
00107
00108 m_pDrawPadCanvas->viewport()->update(viewportRect);
00109 }
00110 }