summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--apps/Applications/drawpad.desktop6
-rw-r--r--noncore/graphics/drawpad/.cvsignore3
-rw-r--r--noncore/graphics/drawpad/drawmode.cpp28
-rw-r--r--noncore/graphics/drawpad/drawmode.h37
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp390
-rw-r--r--noncore/graphics/drawpad/drawpad.h88
-rw-r--r--noncore/graphics/drawpad/drawpad.pro26
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp339
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h65
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.cpp86
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.h36
-rw-r--r--noncore/graphics/drawpad/erasedrawmode.cpp68
-rw-r--r--noncore/graphics/drawpad/erasedrawmode.h36
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp108
-rw-r--r--noncore/graphics/drawpad/filldrawmode.h42
-rw-r--r--noncore/graphics/drawpad/linedrawmode.cpp83
-rw-r--r--noncore/graphics/drawpad/linedrawmode.h36
-rw-r--r--noncore/graphics/drawpad/main.cpp26
-rw-r--r--noncore/graphics/drawpad/pointdrawmode.cpp67
-rw-r--r--noncore/graphics/drawpad/pointdrawmode.h36
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.cpp83
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.h36
-rw-r--r--pics/DrawPad.pngbin0 -> 2299 bytes
-rw-r--r--pics/drawpad/brushcolor.pngbin0 -> 237 bytes
-rw-r--r--pics/drawpad/clear.pngbin0 -> 648 bytes
-rw-r--r--pics/drawpad/ellipse.pngbin0 -> 338 bytes
-rw-r--r--pics/drawpad/erase.pngbin0 -> 220 bytes
-rw-r--r--pics/drawpad/fill.pngbin0 -> 259 bytes
-rw-r--r--pics/drawpad/line.pngbin0 -> 313 bytes
-rw-r--r--pics/drawpad/pencolor.pngbin0 -> 241 bytes
-rw-r--r--pics/drawpad/point.pngbin0 -> 318 bytes
-rw-r--r--pics/drawpad/rectangle.pngbin0 -> 319 bytes
32 files changed, 1725 insertions, 0 deletions
diff --git a/apps/Applications/drawpad.desktop b/apps/Applications/drawpad.desktop
new file mode 100644
index 0000000..9286acf
--- a/dev/null
+++ b/apps/Applications/drawpad.desktop
@@ -0,0 +1,6 @@
1[Desktop Entry]
2Comment=A Drawing Program
3Exec=drawpad
4Icon=DrawPad
5Type=Application
6Name=DrawPad
diff --git a/noncore/graphics/drawpad/.cvsignore b/noncore/graphics/drawpad/.cvsignore
new file mode 100644
index 0000000..2c33e73
--- a/dev/null
+++ b/noncore/graphics/drawpad/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile*
diff --git a/noncore/graphics/drawpad/drawmode.cpp b/noncore/graphics/drawpad/drawmode.cpp
new file mode 100644
index 0000000..57fd14b
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawmode.cpp
@@ -0,0 +1,28 @@
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 "drawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19DrawMode::DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
20 : QObject()
21{
22 m_pDrawPad = drawPad;
23 m_pDrawPadCanvas = drawPadCanvas;
24}
25
26DrawMode::~DrawMode()
27{
28}
diff --git a/noncore/graphics/drawpad/drawmode.h b/noncore/graphics/drawpad/drawmode.h
new file mode 100644
index 0000000..d4ecadd
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawmode.h
@@ -0,0 +1,37 @@
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#ifndef DRAWMODE_H
15#define DRAWMODE_H
16
17#include <qobject.h>
18
19class DrawPad;
20class DrawPadCanvas;
21
22class DrawMode : QObject
23{
24public:
25 DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
26 ~DrawMode();
27
28 virtual void mousePressEvent(QMouseEvent* e) = 0;
29 virtual void mouseReleaseEvent(QMouseEvent* e) = 0;
30 virtual void mouseMoveEvent(QMouseEvent* e) = 0;
31
32protected:
33 DrawPad* m_pDrawPad;
34 DrawPadCanvas* m_pDrawPadCanvas;
35};
36
37#endif // DRAWMODE_H
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
new file mode 100644
index 0000000..3c593b6
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -0,0 +1,390 @@
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 "drawpad.h"
15
16#include "drawpadcanvas.h"
17#include "ellipsedrawmode.h"
18#include "erasedrawmode.h"
19#include "filldrawmode.h"
20#include "linedrawmode.h"
21#include "pointdrawmode.h"
22#include "rectangledrawmode.h"
23
24#include <qpe/global.h>
25#include <qpe/qpemenubar.h>
26#include <qpe/qpetoolbar.h>
27#include <qpe/resource.h>
28
29#include <qaction.h>
30#include <qfile.h>
31#include <qpainter.h>
32#include <qspinbox.h>
33#include <qtoolbutton.h>
34#include <qtooltip.h>
35
36DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
37 : QMainWindow(parent, name, f)
38{
39 setCaption(tr("DrawPad"));
40
41 // init members
42
43 m_pDrawPadCanvas = new DrawPadCanvas(this, this);
44
45 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
46
47 if (file.open(IO_ReadOnly)) {
48 m_pDrawPadCanvas->load(&file);
49 file.close();
50 }
51
52 setCentralWidget(m_pDrawPadCanvas);
53
54 m_colors.resize(8);
55 m_colors.at(0) = Qt::black;
56 m_colors.at(1) = Qt::white;
57 m_colors.at(2) = Qt::red;
58 m_colors.at(3) = Qt::green;
59 m_colors.at(4) = Qt::blue;
60 m_colors.at(5) = Qt::cyan;
61 m_colors.at(6) = Qt::magenta;
62 m_colors.at(7) = Qt::yellow;
63
64 // init menu
65
66 setToolBarsMovable(false);
67
68 QPEToolBar* menuToolBar = new QPEToolBar(this);
69 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
70
71 QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar);
72
73 QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this);
74 connect(clearAllAction, SIGNAL(activated()), this, SLOT(clearAll()));
75 clearAllAction->addTo(toolsPopupMenu);
76
77 toolsPopupMenu->insertSeparator();
78
79 QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this);
80 setOptionsAction->addTo(toolsPopupMenu);
81
82 menuBar->insertItem(tr("Tools"), toolsPopupMenu);
83
84 // init page toolbar
85
86 QPEToolBar* pageToolBar = new QPEToolBar(this);
87
88 QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
89 connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
90 newPageAction->addTo(pageToolBar);
91
92 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
93 connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage()));
94 clearPageAction->addTo(pageToolBar);
95
96 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
97 connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
98 deletePageAction->addTo(pageToolBar);
99
100 QPEToolBar* emptyToolBar = new QPEToolBar(this);
101 emptyToolBar->setHorizontalStretchable(true);
102
103 // init navigation toolbar
104
105 QPEToolBar* navigationToolBar = new QPEToolBar(this);
106
107 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
108 connect(m_pFirstPageAction, SIGNAL(activated()), this, SLOT(goFirstPage()));
109 m_pFirstPageAction->addTo(navigationToolBar);
110
111 m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
112 connect(m_pPreviousPageAction, SIGNAL(activated()), this, SLOT(goPreviousPage()));
113 m_pPreviousPageAction->addTo(navigationToolBar);
114
115 m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
116 connect(m_pNextPageAction, SIGNAL(activated()), this, SLOT(goNextPage()));
117 m_pNextPageAction->addTo(navigationToolBar);
118
119 m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
120 connect(m_pLastPageAction, SIGNAL(activated()), this, SLOT(goLastPage()));
121 m_pLastPageAction->addTo(navigationToolBar);
122
123 updateNavigationToolBar();
124
125 // init draw mode toolbar
126
127 QPEToolBar* drawModeToolBar = new QPEToolBar(this);
128
129 m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this);
130 m_pPointDrawModeAction->setToggleAction(true);
131 connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode()));
132 m_pPointDrawModeAction->addTo(drawModeToolBar);
133
134 m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this);
135 m_pLineDrawModeAction->setToggleAction(true);
136 connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode()));
137 m_pLineDrawModeAction->addTo(drawModeToolBar);
138
139 m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this);
140 m_pRectangleDrawModeAction->setToggleAction(true);
141 connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode()));
142 m_pRectangleDrawModeAction->addTo(drawModeToolBar);
143
144 m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this);
145 m_pEllipseDrawModeAction->setToggleAction(true);
146 connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode()));
147 m_pEllipseDrawModeAction->addTo(drawModeToolBar);
148
149 m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this);
150 m_pFillDrawModeAction->setToggleAction(true);
151 connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode()));
152 m_pFillDrawModeAction->addTo(drawModeToolBar);
153
154 m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this);
155 m_pEraseDrawModeAction->setToggleAction(true);
156 connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode()));
157 m_pEraseDrawModeAction->addTo(drawModeToolBar);
158
159 m_pDrawMode = 0;
160 setPointDrawMode();
161
162 emptyToolBar = new QPEToolBar(this);
163 emptyToolBar->setHorizontalStretchable(true);
164
165 QPEToolBar* drawParametersToolBar = new QPEToolBar(this);
166
167 QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
168 connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
169
170 penWidthSpinBox->setValue(1);
171
172 m_pPenColorToolButton = new QToolButton(drawParametersToolBar);
173 m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png"));
174
175 QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton);
176 connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int)));
177
178 QPixmap penColorPixmap(14, 14);
179
180 for (uint i = 0; i < m_colors.size(); i++) {
181 penColorPixmap.fill(m_colors.at(i));
182 penColorPopupMenu->insertItem(penColorPixmap, i);
183 }
184
185 QToolTip::add(m_pPenColorToolButton, tr("Pen Color"));
186 m_pPenColorToolButton->setPopup(penColorPopupMenu);
187 m_pPenColorToolButton->setPopupDelay(0);
188
189 penColorPopupMenu->activateItemAt(0);
190
191 m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
192 m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png"));
193
194 QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton);
195 connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int)));
196
197 QPixmap brushColorPixmap(14, 14);
198
199 for (uint i = 0; i < m_colors.size(); i++) {
200 brushColorPixmap.fill(m_colors.at(i));
201 brushColorPopupMenu->insertItem(brushColorPixmap, i);
202 }
203
204 QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
205 m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
206 m_pBrushColorToolButton->setPopupDelay(0);
207
208 brushColorPopupMenu->activateItemAt(1);
209}
210
211DrawPad::~DrawPad()
212{
213 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
214
215 if (file.open(IO_WriteOnly)) {
216 m_pDrawPadCanvas->save(&file);
217 file.close();
218 }
219}
220
221void DrawPad::clearAll()
222{
223 m_pDrawPadCanvas->clearAll();
224 updateNavigationToolBar();
225}
226
227void DrawPad::newPage()
228{
229 m_pDrawPadCanvas->newPage();
230 updateNavigationToolBar();
231}
232
233void DrawPad::deletePage()
234{
235 m_pDrawPadCanvas->deletePage();
236 updateNavigationToolBar();
237}
238
239void DrawPad::goFirstPage()
240{
241 m_pDrawPadCanvas->goFirstPage();
242 updateNavigationToolBar();
243}
244
245void DrawPad::goPreviousPage()
246{
247 m_pDrawPadCanvas->goPreviousPage();
248 updateNavigationToolBar();
249}
250
251void DrawPad::goNextPage()
252{
253 m_pDrawPadCanvas->goNextPage();
254 updateNavigationToolBar();
255}
256
257void DrawPad::goLastPage()
258{
259 m_pDrawPadCanvas->goLastPage();
260 updateNavigationToolBar();
261}
262
263void DrawPad::setPointDrawMode()
264{
265 if (m_pDrawMode) {
266 delete m_pDrawMode;
267 }
268
269 m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas);
270
271 m_pPointDrawModeAction->setOn(true);
272 m_pLineDrawModeAction->setOn(false);
273 m_pRectangleDrawModeAction->setOn(false);
274 m_pEllipseDrawModeAction->setOn(false);
275 m_pFillDrawModeAction->setOn(false);
276 m_pEraseDrawModeAction->setOn(false);
277}
278
279void DrawPad::setLineDrawMode()
280{
281 if (m_pDrawMode) {
282 delete m_pDrawMode;
283 }
284
285 m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas);
286
287 m_pPointDrawModeAction->setOn(false);
288 m_pLineDrawModeAction->setOn(true);
289 m_pRectangleDrawModeAction->setOn(false);
290 m_pEllipseDrawModeAction->setOn(false);
291 m_pFillDrawModeAction->setOn(false);
292 m_pEraseDrawModeAction->setOn(false);
293}
294
295void DrawPad::setRectangleDrawMode()
296{
297 if (m_pDrawMode) {
298 delete m_pDrawMode;
299 }
300
301 m_pDrawMode = new RectangleDrawMode(this, m_pDrawPadCanvas);
302
303 m_pPointDrawModeAction->setOn(false);
304 m_pLineDrawModeAction->setOn(false);
305 m_pRectangleDrawModeAction->setOn(true);
306 m_pEllipseDrawModeAction->setOn(false);
307 m_pFillDrawModeAction->setOn(false);
308 m_pEraseDrawModeAction->setOn(false);
309}
310
311void DrawPad::setEllipseDrawMode()
312{
313 if (m_pDrawMode) {
314 delete m_pDrawMode;
315 }
316
317 m_pDrawMode = new EllipseDrawMode(this, m_pDrawPadCanvas);
318
319 m_pPointDrawModeAction->setOn(false);
320 m_pLineDrawModeAction->setOn(false);
321 m_pRectangleDrawModeAction->setOn(false);
322 m_pEllipseDrawModeAction->setOn(true);
323 m_pFillDrawModeAction->setOn(false);
324 m_pEraseDrawModeAction->setOn(false);
325}
326
327void DrawPad::setFillDrawMode()
328{
329 if (m_pDrawMode) {
330 delete m_pDrawMode;
331 }
332
333 m_pDrawMode = new FillDrawMode(this, m_pDrawPadCanvas);
334
335 m_pPointDrawModeAction->setOn(false);
336 m_pLineDrawModeAction->setOn(false);
337 m_pRectangleDrawModeAction->setOn(false);
338 m_pEllipseDrawModeAction->setOn(false);
339 m_pFillDrawModeAction->setOn(true);
340 m_pEraseDrawModeAction->setOn(false);
341}
342
343void DrawPad::setEraseDrawMode()
344{
345 if (m_pDrawMode) {
346 delete m_pDrawMode;
347 }
348
349 m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas);
350
351 m_pPointDrawModeAction->setOn(false);
352 m_pLineDrawModeAction->setOn(false);
353 m_pRectangleDrawModeAction->setOn(false);
354 m_pEllipseDrawModeAction->setOn(false);
355 m_pFillDrawModeAction->setOn(false);
356 m_pEraseDrawModeAction->setOn(true);
357}
358
359void DrawPad::changePenWidth(int value)
360{
361 m_pen.setWidth(value);
362}
363
364void DrawPad::changePenColor(int index)
365{
366 m_pen.setColor(m_colors.at(index));
367
368 QPainter painter;
369 painter.begin(m_pPenColorToolButton->pixmap());
370 painter.fillRect(QRect(0, 12, 14, 2), m_pen.color());
371 painter.end();
372}
373
374void DrawPad::changeBrushColor(int index)
375{
376 m_brush = QBrush(m_colors.at(index));
377
378 QPainter painter;
379 painter.begin(m_pBrushColorToolButton->pixmap());
380 painter.fillRect(QRect(0, 12, 14, 2), m_brush.color());
381 painter.end();
382}
383
384void DrawPad::updateNavigationToolBar()
385{
386 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
387 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
388 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
389 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
390}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
new file mode 100644
index 0000000..0ece408
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -0,0 +1,88 @@
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#ifndef DRAWPAD_H
15#define DRAWPAD_H
16
17#include <qmainwindow.h>
18
19#include <qpen.h>
20
21class DrawMode;
22class DrawPadCanvas;
23
24class QAction;
25class QColor;
26class QToolButton;
27class QWidgetStack;
28
29class DrawPad : public QMainWindow
30{
31 Q_OBJECT
32
33public:
34 DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel);
35 ~DrawPad();
36
37 DrawMode* drawMode() { return m_pDrawMode; }
38 QPen pen() { return m_pen; }
39 QBrush brush() { return m_brush; }
40
41private slots:
42 void clearAll();
43 void newPage();
44 void deletePage();
45
46 void goFirstPage();
47 void goPreviousPage();
48 void goNextPage();
49 void goLastPage();
50
51 void setPointDrawMode();
52 void setLineDrawMode();
53 void setRectangleDrawMode();
54 void setEllipseDrawMode();
55 void setFillDrawMode();
56 void setEraseDrawMode();
57
58 void changePenWidth(int value);
59 void changePenColor(int index);
60 void changeBrushColor(int index);
61
62private:
63 void updateNavigationToolBar();
64
65 DrawPadCanvas* m_pDrawPadCanvas;
66 QArray<QColor> m_colors;
67
68 DrawMode* m_pDrawMode;
69 QPen m_pen;
70 QBrush m_brush;
71
72 QAction* m_pFirstPageAction;
73 QAction* m_pPreviousPageAction;
74 QAction* m_pNextPageAction;
75 QAction* m_pLastPageAction;
76
77 QAction* m_pPointDrawModeAction;
78 QAction* m_pLineDrawModeAction;
79 QAction* m_pRectangleDrawModeAction;
80 QAction* m_pEllipseDrawModeAction;
81 QAction* m_pFillDrawModeAction;
82 QAction* m_pEraseDrawModeAction;
83
84 QToolButton* m_pPenColorToolButton;
85 QToolButton* m_pBrushColorToolButton;
86};
87
88#endif // DRAWPAD_H
diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro
new file mode 100644
index 0000000..348500c
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawpad.pro
@@ -0,0 +1,26 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = drawmode.h \
4 drawpad.h \
5 drawpadcanvas.h \
6 ellipsedrawmode.h \
7 erasedrawmode.h \
8 filldrawmode.h \
9 linedrawmode.h \
10 pointdrawmode.h \
11 rectangledrawmode.h
12 SOURCES = main.cpp \
13 drawmode.cpp \
14 drawpad.cpp \
15 drawpadcanvas.cpp \
16 ellipsedrawmode.cpp \
17 erasedrawmode.cpp \
18 filldrawmode.cpp \
19 linedrawmode.cpp \
20 pointdrawmode.cpp \
21 rectangledrawmode.cpp
22 INCLUDEPATH+= $(OPIEDIR)/include
23 DEPENDPATH+= $(OPIEDIR)/include
24 LIBS += -lqpe
25 DESTDIR = $(OPIEDIR)/bin
26 TARGET = drawpad
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
new file mode 100644
index 0000000..f02f478
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -0,0 +1,339 @@
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 "drawpadcanvas.h"
15
16#include "drawmode.h"
17#include "drawpad.h"
18
19#include <qbuffer.h>
20#include <qimage.h>
21#include <qpainter.h>
22#include <qpixmap.h>
23#include <qtextcodec.h>
24#include <qtextstream.h>
25#include <qxml.h>
26
27#include <zlib.h>
28
29class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
30{
31public:
32 DrawPadCanvasXmlHandler();
33 ~DrawPadCanvasXmlHandler();
34
35 QList<QPixmap> pixmaps();
36
37 bool startElement(const QString& namespaceURI, const QString& localName,
38 const QString& qName, const QXmlAttributes& atts);
39 bool endElement(const QString& namespaceURI, const QString& localName,
40 const QString& qName);
41 bool characters(const QString& ch);
42
43private:
44 enum State {
45 Unknown,
46 InData
47 };
48
49 State m_state;
50 ulong m_dataLenght;
51 QList<QPixmap> m_pixmaps;
52};
53
54DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler()
55{
56 m_state = Unknown;
57}
58
59DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler()
60{
61}
62
63QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps()
64{
65 return m_pixmaps;
66}
67
68bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName,
69 const QString& qName, const QXmlAttributes& atts)
70{
71 Q_CONST_UNUSED(namespaceURI)
72 Q_CONST_UNUSED(localName)
73
74 if (qName.compare("data") == 0) {
75 m_state = InData;
76 m_dataLenght = atts.value("length").toULong();
77 }
78
79 return true;
80}
81
82bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName,
83 const QString& qName)
84{
85 Q_CONST_UNUSED(namespaceURI)
86 Q_CONST_UNUSED(localName)
87
88 if (qName.compare("data") == 0) {
89 m_state = Unknown;
90 }
91
92 return true;
93}
94
95bool DrawPadCanvasXmlHandler::characters(const QString& ch)
96{
97 if (m_state == InData) {
98 QByteArray byteArray(ch.length() / 2);
99
100 for (int i = 0; i < (int)ch.length() / 2; i++) {
101 char h = ch[2 * i].latin1();
102 char l = ch[2 * i + 1].latin1();
103 uchar r = 0;
104
105 if (h <= '9') {
106 r += h - '0';
107 } else {
108 r += h - 'a' + 10;
109 }
110
111 r = r << 4;
112
113 if (l <= '9') {
114 r += l - '0';
115 } else {
116 r += l - 'a' + 10;
117 }
118
119 byteArray[i] = r;
120 }
121
122 if (m_dataLenght < ch.length() * 5) {
123 m_dataLenght = ch.length() * 5;
124 }
125
126 QByteArray byteArrayUnzipped(m_dataLenght);
127 ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size());
128
129 QImage image;
130 image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM");
131
132 QPixmap* pixmap = new QPixmap(image.width(), image.height());
133 pixmap->convertFromImage(image);
134 m_pixmaps.append(pixmap);
135 }
136
137 return true;
138}
139
140DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f)
141 : QWidget(parent, name, f)
142{
143 setBackgroundMode(QWidget::PaletteBase);
144
145 m_pDrawPad = drawPad;
146 m_buffers.setAutoDelete(true);
147 m_buffers.append(new QPixmap(width(), height()));
148 m_buffers.current()->fill(Qt::white);
149}
150
151DrawPadCanvas::~DrawPadCanvas()
152{
153}
154
155void DrawPadCanvas::load(QIODevice* ioDevice)
156{
157 QTextStream textStream(ioDevice);
158 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
159
160 QXmlInputSource xmlInputSource(textStream);
161 QXmlSimpleReader xmlSimpleReader;
162 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
163
164 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
165 xmlSimpleReader.parse(xmlInputSource);
166
167 m_buffers = drawPadCanvasXmlHandler.pixmaps();
168
169 if (m_buffers.isEmpty()) {
170 m_buffers.append(new QPixmap(width(), height()));
171 m_buffers.current()->fill(Qt::white);
172 }
173
174 repaint();
175}
176
177void DrawPadCanvas::save(QIODevice* ioDevice)
178{
179 QTextStream textStream(ioDevice);
180 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
181
182 textStream << "<drawpad>" << endl;
183 textStream << " <images>" << endl;
184
185 QListIterator<QPixmap> bufferIterator(m_buffers);
186
187 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
188 textStream << " <image>" << endl;
189
190 QImage image = bufferIterator.current()->convertToImage();
191 QByteArray byteArray;
192 QBuffer buffer(byteArray);
193 QImageIO imageIO(&buffer, "XPM");
194
195 buffer.open(IO_WriteOnly);
196 imageIO.setImage(image);
197 imageIO.write();
198 buffer.close();
199
200 ulong size = byteArray.size() * 2;
201 QByteArray byteArrayZipped(size);
202 ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size());
203
204 textStream << " <data length=\"" << byteArray.size() << "\">";
205
206 static const char hexchars[] = "0123456789abcdef";
207
208 for (int i = 0; i < (int)size; i++ ) {
209 uchar s = (uchar)byteArrayZipped[i];
210 textStream << hexchars[s >> 4];
211 textStream << hexchars[s & 0x0f];
212 }
213
214 textStream << "</data>" << endl;
215 textStream << " </image>" << endl;
216 }
217
218 textStream << " </images>" << endl;
219 textStream << "</drawpad>";
220}
221
222QPixmap* DrawPadCanvas::currentPage()
223{
224 return m_buffers.current();
225}
226
227void DrawPadCanvas::clearAll()
228{
229 m_buffers.clear();
230
231 m_buffers.append(new QPixmap(width(), height()));
232 m_buffers.current()->fill(Qt::white);
233
234 repaint();
235}
236
237void DrawPadCanvas::newPage()
238{
239 m_buffers.insert(m_buffers.at() + 1, new QPixmap(width(), height()));
240 m_buffers.current()->fill(Qt::white);
241 repaint();
242}
243
244void DrawPadCanvas::clearPage()
245{
246 m_buffers.current()->fill(Qt::white);
247 repaint();
248}
249
250void DrawPadCanvas::deletePage()
251{
252 m_buffers.remove(m_buffers.current());
253
254 if (m_buffers.isEmpty()) {
255 m_buffers.append(new QPixmap(width(), height()));
256 m_buffers.current()->fill(Qt::white);
257 }
258
259 repaint();
260}
261
262bool DrawPadCanvas::goPreviousPageEnabled()
263{
264 return (m_buffers.current() != m_buffers.getFirst());
265}
266
267bool DrawPadCanvas::goNextPageEnabled()
268{
269 return (m_buffers.current() != m_buffers.getLast());
270}
271
272void DrawPadCanvas::goFirstPage()
273{
274 m_buffers.first();
275 repaint();
276}
277
278void DrawPadCanvas::goPreviousPage()
279{
280 m_buffers.prev();
281 repaint();
282}
283
284void DrawPadCanvas::goNextPage()
285{
286 m_buffers.next();
287 repaint();
288}
289
290void DrawPadCanvas::goLastPage()
291{
292 m_buffers.last();
293 repaint();
294}
295
296void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
297{
298 m_pDrawPad->drawMode()->mousePressEvent(e);
299}
300
301void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e)
302{
303 m_pDrawPad->drawMode()->mouseReleaseEvent(e);
304}
305
306void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e)
307{
308 m_pDrawPad->drawMode()->mouseMoveEvent(e);
309}
310
311void DrawPadCanvas::resizeEvent(QResizeEvent* e)
312{
313 QWidget::resizeEvent(e);
314
315 QListIterator<QPixmap> bufferIterator(m_buffers);
316
317 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
318 int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width();
319 int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height();
320
321 QPixmap tmpPixmap(*(bufferIterator.current()));
322 bufferIterator.current()->resize(w, h);
323 bufferIterator.current()->fill(Qt::white);
324
325 bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height());
326 }
327}
328
329void DrawPadCanvas::paintEvent(QPaintEvent* e)
330{
331 QWidget::paintEvent(e);
332
333 QArray<QRect> rects = e->region().rects();
334
335 for (uint i = 0; i < rects.count(); i++) {
336 QRect r = rects[i];
337 bitBlt(this, r.x(), r.y(), m_buffers.current(), r.x(), r.y(), r.width(), r.height());
338 }
339}
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
new file mode 100644
index 0000000..2ec9298
--- a/dev/null
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -0,0 +1,65 @@
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#ifndef DRAWPADCANVAS_H
15#define DRAWPADCANVAS_H
16
17#include <qwidget.h>
18
19#include <qlist.h>
20#include <qpointarray.h>
21
22class DrawPad;
23
24class QPixmap;
25
26class DrawPadCanvas : public QWidget
27{
28 Q_OBJECT
29
30public:
31 DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0);
32 ~DrawPadCanvas();
33
34 void load(QIODevice* ioDevice);
35 void save(QIODevice* ioDevice);
36
37 bool goPreviousPageEnabled();
38 bool goNextPageEnabled();
39
40 QPixmap* currentPage();
41
42public slots:
43 void clearAll();
44 void newPage();
45 void clearPage();
46 void deletePage();
47
48 void goFirstPage();
49 void goPreviousPage();
50 void goNextPage();
51 void goLastPage();
52
53protected:
54 void mousePressEvent(QMouseEvent* e);
55 void mouseReleaseEvent(QMouseEvent* e);
56 void mouseMoveEvent(QMouseEvent* e);
57 void resizeEvent(QResizeEvent* e);
58 void paintEvent(QPaintEvent* e);
59
60private:
61 DrawPad* m_pDrawPad;
62 QList<QPixmap> m_buffers;
63};
64
65#endif // DRAWPADCANVAS_H
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}
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.h b/noncore/graphics/drawpad/ellipsedrawmode.h
new file mode 100644
index 0000000..4787518
--- a/dev/null
+++ b/noncore/graphics/drawpad/ellipsedrawmode.h
@@ -0,0 +1,36 @@
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#ifndef ELLIPSEDRAWMODE_H
15#define ELLIPSEDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class EllipseDrawMode : public DrawMode
22{
23public:
24 EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~EllipseDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34};
35
36#endif // ELLIPSEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/erasedrawmode.cpp b/noncore/graphics/drawpad/erasedrawmode.cpp
new file mode 100644
index 0000000..b8e80bc
--- a/dev/null
+++ b/noncore/graphics/drawpad/erasedrawmode.cpp
@@ -0,0 +1,68 @@
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 "erasedrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29EraseDrawMode::~EraseDrawMode()
30{
31}
32
33void EraseDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e)
40{
41 Q_UNUSED(e);
42
43 m_mousePressed = false;
44}
45
46void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
47{
48 if (m_mousePressed) {
49 QPainter painter;
50 QPen pen(Qt::white, m_pDrawPad->pen().width());
51 painter.begin(m_pDrawPadCanvas->currentPage());
52 painter.setPen(pen);
53 m_polyline[2] = m_polyline[1];
54 m_polyline[1] = m_polyline[0];
55 m_polyline[0] = e->pos();
56 painter.drawPolyline(m_polyline);
57 painter.end();
58
59 QRect r = m_polyline.boundingRect();
60 r = r.normalize();
61 r.setLeft(r.left() - m_pDrawPad->pen().width());
62 r.setTop(r.top() - m_pDrawPad->pen().width());
63 r.setRight(r.right() + m_pDrawPad->pen().width());
64 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
65
66 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
67 }
68}
diff --git a/noncore/graphics/drawpad/erasedrawmode.h b/noncore/graphics/drawpad/erasedrawmode.h
new file mode 100644
index 0000000..c64b010
--- a/dev/null
+++ b/noncore/graphics/drawpad/erasedrawmode.h
@@ -0,0 +1,36 @@
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#ifndef ERASEDRAWMODE_H
15#define ERASEPOINTDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class EraseDrawMode : public DrawMode
22{
23public:
24 EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~EraseDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34};
35
36#endif // ERASEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp
new file mode 100644
index 0000000..db86b63
--- a/dev/null
+++ b/noncore/graphics/drawpad/filldrawmode.cpp
@@ -0,0 +1,108 @@
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 "filldrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qimage.h>
20#include <qpixmap.h>
21
22FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25}
26
27FillDrawMode::~FillDrawMode()
28{
29}
30
31void FillDrawMode::mousePressEvent(QMouseEvent* e)
32{
33 int x = e->x();
34 int y = e->y();
35
36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
37 m_fillRgb = m_pDrawPad->brush().color().rgb();
38 m_oldRgb = m_image.pixel(x, y);
39
40 if (m_oldRgb != m_fillRgb) {
41 m_image.setPixel(x, y, m_fillRgb);
42 fillEast(x + 1, y);
43 fillSouth(x, y + 1);
44 fillWest(x - 1, y);
45 fillNorth(x, y - 1);
46
47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
48 m_pDrawPadCanvas->repaint();
49 }
50}
51
52void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
53{
54 Q_UNUSED(e);
55}
56
57void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
58{
59 Q_UNUSED(e);
60}
61
62void FillDrawMode::fillEast(int x, int y)
63{
64 if (x < m_image.width()) {
65 if (m_image.pixel(x, y) == m_oldRgb) {
66 m_image.setPixel(x, y, m_fillRgb);
67 fillEast(x + 1, y);
68 fillSouth(x, y + 1);
69 fillNorth(x, y - 1);
70 }
71 }
72}
73
74void FillDrawMode::fillSouth(int x, int y)
75{
76 if (y < m_image.height()) {
77 if (m_image.pixel(x, y) == m_oldRgb) {
78 m_image.setPixel(x, y, m_fillRgb);
79 fillEast(x + 1, y);
80 fillSouth(x, y + 1);
81 fillWest(x - 1, y);
82 }
83 }
84}
85
86void FillDrawMode::fillWest(int x, int y)
87{
88 if (x >= 0) {
89 if (m_image.pixel(x, y) == m_oldRgb) {
90 m_image.setPixel(x, y, m_fillRgb);
91 fillSouth(x, y + 1);
92 fillWest(x - 1, y);
93 fillNorth(x, y - 1);
94 }
95 }
96}
97
98void FillDrawMode::fillNorth(int x, int y)
99{
100 if (y >= 0) {
101 if (m_image.pixel(x, y) == m_oldRgb) {
102 m_image.setPixel(x, y, m_fillRgb);
103 fillEast(x + 1, y);
104 fillWest(x - 1, y);
105 fillNorth(x, y - 1);
106 }
107 }
108}
diff --git a/noncore/graphics/drawpad/filldrawmode.h b/noncore/graphics/drawpad/filldrawmode.h
new file mode 100644
index 0000000..1b7e7b5
--- a/dev/null
+++ b/noncore/graphics/drawpad/filldrawmode.h
@@ -0,0 +1,42 @@
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#ifndef FILLDRAWMODE_H
15#define FILLDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qimage.h>
20
21class FillDrawMode : public DrawMode
22{
23public:
24 FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~FillDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 void fillEast(int x, int y);
33 void fillSouth(int x, int y);
34 void fillWest(int x, int y);
35 void fillNorth(int x, int y);
36
37 QImage m_image;
38 QRgb m_fillRgb;
39 QRgb m_oldRgb;
40};
41
42#endif // FILLDRAWMODE_H
diff --git a/noncore/graphics/drawpad/linedrawmode.cpp b/noncore/graphics/drawpad/linedrawmode.cpp
new file mode 100644
index 0000000..57295f8
--- a/dev/null
+++ b/noncore/graphics/drawpad/linedrawmode.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 "linedrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29LineDrawMode::~LineDrawMode()
30{
31}
32
33void LineDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void LineDrawMode::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.drawLine(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
61void LineDrawMode::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.drawLine(m_polyline[2], m_polyline[1]);
69 painter.drawLine(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}
diff --git a/noncore/graphics/drawpad/linedrawmode.h b/noncore/graphics/drawpad/linedrawmode.h
new file mode 100644
index 0000000..25ae2cf
--- a/dev/null
+++ b/noncore/graphics/drawpad/linedrawmode.h
@@ -0,0 +1,36 @@
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#ifndef LINEDRAWMODE_H
15#define LINEDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class LineDrawMode : public DrawMode
22{
23public:
24 LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~LineDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34};
35
36#endif // LINEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/main.cpp b/noncore/graphics/drawpad/main.cpp
new file mode 100644
index 0000000..b362962
--- a/dev/null
+++ b/noncore/graphics/drawpad/main.cpp
@@ -0,0 +1,26 @@
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 "drawpad.h"
15
16#include <qpe/qpeapplication.h>
17
18int main(int argc, char **argv)
19{
20 QPEApplication a(argc, argv);
21
22 DrawPad mw;
23 a.showMainWidget(&mw);
24
25 return a.exec();
26}
diff --git a/noncore/graphics/drawpad/pointdrawmode.cpp b/noncore/graphics/drawpad/pointdrawmode.cpp
new file mode 100644
index 0000000..11722c8
--- a/dev/null
+++ b/noncore/graphics/drawpad/pointdrawmode.cpp
@@ -0,0 +1,67 @@
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 "pointdrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29PointDrawMode::~PointDrawMode()
30{
31}
32
33void PointDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void PointDrawMode::mouseReleaseEvent(QMouseEvent* e)
40{
41 Q_UNUSED(e);
42
43 m_mousePressed = false;
44}
45
46void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
47{
48 if (m_mousePressed) {
49 QPainter painter;
50 painter.begin(m_pDrawPadCanvas->currentPage());
51 painter.setPen(m_pDrawPad->pen());
52 m_polyline[2] = m_polyline[1];
53 m_polyline[1] = m_polyline[0];
54 m_polyline[0] = e->pos();
55 painter.drawPolyline(m_polyline);
56 painter.end();
57
58 QRect r = m_polyline.boundingRect();
59 r = r.normalize();
60 r.setLeft(r.left() - m_pDrawPad->pen().width());
61 r.setTop(r.top() - m_pDrawPad->pen().width());
62 r.setRight(r.right() + m_pDrawPad->pen().width());
63 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
64
65 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
66 }
67}
diff --git a/noncore/graphics/drawpad/pointdrawmode.h b/noncore/graphics/drawpad/pointdrawmode.h
new file mode 100644
index 0000000..78da31f
--- a/dev/null
+++ b/noncore/graphics/drawpad/pointdrawmode.h
@@ -0,0 +1,36 @@
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#ifndef POINTDRAWMODE_H
15#define POINTDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class PointDrawMode : public DrawMode
22{
23public:
24 PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~PointDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34};
35
36#endif // POINTDRAWMODE_H
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
22RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29RectangleDrawMode::~RectangleDrawMode()
30{
31}
32
33void RectangleDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void 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
61void 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}
diff --git a/noncore/graphics/drawpad/rectangledrawmode.h b/noncore/graphics/drawpad/rectangledrawmode.h
new file mode 100644
index 0000000..62b85b1
--- a/dev/null
+++ b/noncore/graphics/drawpad/rectangledrawmode.h
@@ -0,0 +1,36 @@
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#ifndef RECTANGLEDRAWMODE_H
15#define RECTANGLEDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class RectangleDrawMode : public DrawMode
22{
23public:
24 RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~RectangleDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34};
35
36#endif // RECTANGLEDRAWMODE_H
diff --git a/pics/DrawPad.png b/pics/DrawPad.png
new file mode 100644
index 0000000..6f3ebe9
--- a/dev/null
+++ b/pics/DrawPad.png
Binary files differ
diff --git a/pics/drawpad/brushcolor.png b/pics/drawpad/brushcolor.png
new file mode 100644
index 0000000..814ad57
--- a/dev/null
+++ b/pics/drawpad/brushcolor.png
Binary files differ
diff --git a/pics/drawpad/clear.png b/pics/drawpad/clear.png
new file mode 100644
index 0000000..e9fdf4e
--- a/dev/null
+++ b/pics/drawpad/clear.png
Binary files differ
diff --git a/pics/drawpad/ellipse.png b/pics/drawpad/ellipse.png
new file mode 100644
index 0000000..a61dc92
--- a/dev/null
+++ b/pics/drawpad/ellipse.png
Binary files differ
diff --git a/pics/drawpad/erase.png b/pics/drawpad/erase.png
new file mode 100644
index 0000000..54dd258
--- a/dev/null
+++ b/pics/drawpad/erase.png
Binary files differ
diff --git a/pics/drawpad/fill.png b/pics/drawpad/fill.png
new file mode 100644
index 0000000..a905c6a
--- a/dev/null
+++ b/pics/drawpad/fill.png
Binary files differ
diff --git a/pics/drawpad/line.png b/pics/drawpad/line.png
new file mode 100644
index 0000000..0c9f8f6
--- a/dev/null
+++ b/pics/drawpad/line.png
Binary files differ
diff --git a/pics/drawpad/pencolor.png b/pics/drawpad/pencolor.png
new file mode 100644
index 0000000..bcbc26a
--- a/dev/null
+++ b/pics/drawpad/pencolor.png
Binary files differ
diff --git a/pics/drawpad/point.png b/pics/drawpad/point.png
new file mode 100644
index 0000000..29d2d17
--- a/dev/null
+++ b/pics/drawpad/point.png
Binary files differ
diff --git a/pics/drawpad/rectangle.png b/pics/drawpad/rectangle.png
new file mode 100644
index 0000000..7d05d53
--- a/dev/null
+++ b/pics/drawpad/rectangle.png
Binary files differ