author | leseb <leseb> | 2002-03-16 22:19:40 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-16 22:19:40 (UTC) |
commit | 8111d4bf6281420b7f44ae70c26d2531cfe34401 (patch) (unidiff) | |
tree | 4c106c80125ec35faa57df9d7af492c4b481db58 /noncore/graphics/drawpad/rectangledrawmode.cpp | |
parent | 54f8d1b709b198dbdedf17dc2b4a8dd4625c5751 (diff) | |
download | opie-8111d4bf6281420b7f44ae70c26d2531cfe34401.zip opie-8111d4bf6281420b7f44ae70c26d2531cfe34401.tar.gz opie-8111d4bf6281420b7f44ae70c26d2531cfe34401.tar.bz2 |
Initial commit
Diffstat (limited to 'noncore/graphics/drawpad/rectangledrawmode.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/rectangledrawmode.cpp b/noncore/graphics/drawpad/rectangledrawmode.cpp new file mode 100644 index 0000000..f54b47b --- a/dev/null +++ b/noncore/graphics/drawpad/rectangledrawmode.cpp | |||
@@ -0,0 +1,83 @@ | |||
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 "rectangledrawmode.h" | ||
15 | |||
16 | #include "drawpad.h" | ||
17 | #include "drawpadcanvas.h" | ||
18 | |||
19 | #include <qpainter.h> | ||
20 | #include <qpixmap.h> | ||
21 | |||
22 | RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | ||
23 | : DrawMode(drawPad, drawPadCanvas) | ||
24 | { | ||
25 | m_mousePressed = false; | ||
26 | m_polyline.resize(3); | ||
27 | } | ||
28 | |||
29 | RectangleDrawMode::~RectangleDrawMode() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void RectangleDrawMode::mousePressEvent(QMouseEvent* e) | ||
34 | { | ||
35 | m_mousePressed = true; | ||
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | ||
37 | } | ||
38 | |||
39 | void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) | ||
40 | { | ||
41 | Q_UNUSED(e); | ||
42 | |||
43 | QPainter painter; | ||
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | ||
45 | painter.setPen(m_pDrawPad->pen()); | ||
46 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); | ||
47 | painter.end(); | ||
48 | |||
49 | QRect r = m_polyline.boundingRect(); | ||
50 | r = r.normalize(); | ||
51 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | ||
52 | r.setTop(r.top() - m_pDrawPad->pen().width()); | ||
53 | r.setRight(r.right() + m_pDrawPad->pen().width()); | ||
54 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
55 | |||
56 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | ||
57 | |||
58 | m_mousePressed = false; | ||
59 | } | ||
60 | |||
61 | void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e) | ||
62 | { | ||
63 | if (m_mousePressed) { | ||
64 | QPainter painter; | ||
65 | painter.begin(m_pDrawPadCanvas->currentPage()); | ||
66 | painter.setRasterOp(Qt::NotROP); | ||
67 | m_polyline[0] = e->pos(); | ||
68 | painter.drawRect(QRect(m_polyline[2], m_polyline[1])); | ||
69 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); | ||
70 | painter.end(); | ||
71 | |||
72 | QRect r = m_polyline.boundingRect(); | ||
73 | r = r.normalize(); | ||
74 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | ||
75 | r.setTop(r.top() - m_pDrawPad->pen().width()); | ||
76 | r.setRight(r.right() + m_pDrawPad->pen().width()); | ||
77 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
78 | |||
79 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | ||
80 | |||
81 | m_polyline[1] = m_polyline[0]; | ||
82 | } | ||
83 | } | ||