summaryrefslogtreecommitdiff
path: root/noncore/graphics/drawpad/ellipsedrawmode.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/drawpad/ellipsedrawmode.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.cpp b/noncore/graphics/drawpad/ellipsedrawmode.cpp
new file mode 100644
index 0000000..1051335
--- a/dev/null
+++ b/noncore/graphics/drawpad/ellipsedrawmode.cpp
@@ -0,0 +1,86 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "ellipsedrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29EllipseDrawMode::~EllipseDrawMode()
30{
31}
32
33void EllipseDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e)
40{
41 Q_UNUSED(e);
42
43 QPainter painter;
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setRasterOp(Qt::NotROP);
46 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
47 painter.setPen(m_pDrawPad->pen());
48 painter.setRasterOp(Qt::CopyROP);
49 painter.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
50 painter.end();
51
52 QRect r = m_polyline.boundingRect();
53 r = r.normalize();
54 r.setLeft(r.left() - m_pDrawPad->pen().width());
55 r.setTop(r.top() - m_pDrawPad->pen().width());
56 r.setRight(r.right() + m_pDrawPad->pen().width());
57 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
58
59 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
60
61 m_mousePressed = false;
62}
63
64void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e)
65{
66 if (m_mousePressed) {
67 QPainter painter;
68 painter.begin(m_pDrawPadCanvas->currentPage());
69 painter.setRasterOp(Qt::NotROP);
70 m_polyline[0] = e->pos();
71 painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
72 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
73 painter.end();
74
75 QRect r = m_polyline.boundingRect();
76 r = r.normalize();
77 r.setLeft(r.left() - m_pDrawPad->pen().width());
78 r.setTop(r.top() - m_pDrawPad->pen().width());
79 r.setRight(r.right() + m_pDrawPad->pen().width());
80 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
81
82 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
83
84 m_polyline[1] = m_polyline[0];
85 }
86}