summaryrefslogtreecommitdiff
path: root/noncore
authorleseb <leseb>2002-03-16 22:19:40 (UTC)
committer leseb <leseb>2002-03-16 22:19:40 (UTC)
commit8111d4bf6281420b7f44ae70c26d2531cfe34401 (patch) (side-by-side diff)
tree4c106c80125ec35faa57df9d7af492c4b481db58 /noncore
parent54f8d1b709b198dbdedf17dc2b4a8dd4625c5751 (diff)
downloadopie-8111d4bf6281420b7f44ae70c26d2531cfe34401.zip
opie-8111d4bf6281420b7f44ae70c26d2531cfe34401.tar.gz
opie-8111d4bf6281420b7f44ae70c26d2531cfe34401.tar.bz2
Initial commit
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-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
21 files changed, 1719 insertions, 0 deletions
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 @@
+moc_*
+*.moc
+Makefile*
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "drawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+DrawMode::DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : QObject()
+{
+ m_pDrawPad = drawPad;
+ m_pDrawPadCanvas = drawPadCanvas;
+}
+
+DrawMode::~DrawMode()
+{
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DRAWMODE_H
+#define DRAWMODE_H
+
+#include <qobject.h>
+
+class DrawPad;
+class DrawPadCanvas;
+
+class DrawMode : QObject
+{
+public:
+ DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~DrawMode();
+
+ virtual void mousePressEvent(QMouseEvent* e) = 0;
+ virtual void mouseReleaseEvent(QMouseEvent* e) = 0;
+ virtual void mouseMoveEvent(QMouseEvent* e) = 0;
+
+protected:
+ DrawPad* m_pDrawPad;
+ DrawPadCanvas* m_pDrawPadCanvas;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "drawpad.h"
+
+#include "drawpadcanvas.h"
+#include "ellipsedrawmode.h"
+#include "erasedrawmode.h"
+#include "filldrawmode.h"
+#include "linedrawmode.h"
+#include "pointdrawmode.h"
+#include "rectangledrawmode.h"
+
+#include <qpe/global.h>
+#include <qpe/qpemenubar.h>
+#include <qpe/qpetoolbar.h>
+#include <qpe/resource.h>
+
+#include <qaction.h>
+#include <qfile.h>
+#include <qpainter.h>
+#include <qspinbox.h>
+#include <qtoolbutton.h>
+#include <qtooltip.h>
+
+DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
+ : QMainWindow(parent, name, f)
+{
+ setCaption(tr("DrawPad"));
+
+ // init members
+
+ m_pDrawPadCanvas = new DrawPadCanvas(this, this);
+
+ QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
+
+ if (file.open(IO_ReadOnly)) {
+ m_pDrawPadCanvas->load(&file);
+ file.close();
+ }
+
+ setCentralWidget(m_pDrawPadCanvas);
+
+ m_colors.resize(8);
+ m_colors.at(0) = Qt::black;
+ m_colors.at(1) = Qt::white;
+ m_colors.at(2) = Qt::red;
+ m_colors.at(3) = Qt::green;
+ m_colors.at(4) = Qt::blue;
+ m_colors.at(5) = Qt::cyan;
+ m_colors.at(6) = Qt::magenta;
+ m_colors.at(7) = Qt::yellow;
+
+ // init menu
+
+ setToolBarsMovable(false);
+
+ QPEToolBar* menuToolBar = new QPEToolBar(this);
+ QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
+
+ QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar);
+
+ QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this);
+ connect(clearAllAction, SIGNAL(activated()), this, SLOT(clearAll()));
+ clearAllAction->addTo(toolsPopupMenu);
+
+ toolsPopupMenu->insertSeparator();
+
+ QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this);
+ setOptionsAction->addTo(toolsPopupMenu);
+
+ menuBar->insertItem(tr("Tools"), toolsPopupMenu);
+
+ // init page toolbar
+
+ QPEToolBar* pageToolBar = new QPEToolBar(this);
+
+ QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
+ connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
+ newPageAction->addTo(pageToolBar);
+
+ QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
+ connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage()));
+ clearPageAction->addTo(pageToolBar);
+
+ QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
+ connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
+ deletePageAction->addTo(pageToolBar);
+
+ QPEToolBar* emptyToolBar = new QPEToolBar(this);
+ emptyToolBar->setHorizontalStretchable(true);
+
+ // init navigation toolbar
+
+ QPEToolBar* navigationToolBar = new QPEToolBar(this);
+
+ m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
+ connect(m_pFirstPageAction, SIGNAL(activated()), this, SLOT(goFirstPage()));
+ m_pFirstPageAction->addTo(navigationToolBar);
+
+ m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
+ connect(m_pPreviousPageAction, SIGNAL(activated()), this, SLOT(goPreviousPage()));
+ m_pPreviousPageAction->addTo(navigationToolBar);
+
+ m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
+ connect(m_pNextPageAction, SIGNAL(activated()), this, SLOT(goNextPage()));
+ m_pNextPageAction->addTo(navigationToolBar);
+
+ m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
+ connect(m_pLastPageAction, SIGNAL(activated()), this, SLOT(goLastPage()));
+ m_pLastPageAction->addTo(navigationToolBar);
+
+ updateNavigationToolBar();
+
+ // init draw mode toolbar
+
+ QPEToolBar* drawModeToolBar = new QPEToolBar(this);
+
+ m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this);
+ m_pPointDrawModeAction->setToggleAction(true);
+ connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode()));
+ m_pPointDrawModeAction->addTo(drawModeToolBar);
+
+ m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this);
+ m_pLineDrawModeAction->setToggleAction(true);
+ connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode()));
+ m_pLineDrawModeAction->addTo(drawModeToolBar);
+
+ m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this);
+ m_pRectangleDrawModeAction->setToggleAction(true);
+ connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode()));
+ m_pRectangleDrawModeAction->addTo(drawModeToolBar);
+
+ m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this);
+ m_pEllipseDrawModeAction->setToggleAction(true);
+ connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode()));
+ m_pEllipseDrawModeAction->addTo(drawModeToolBar);
+
+ m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this);
+ m_pFillDrawModeAction->setToggleAction(true);
+ connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode()));
+ m_pFillDrawModeAction->addTo(drawModeToolBar);
+
+ m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this);
+ m_pEraseDrawModeAction->setToggleAction(true);
+ connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode()));
+ m_pEraseDrawModeAction->addTo(drawModeToolBar);
+
+ m_pDrawMode = 0;
+ setPointDrawMode();
+
+ emptyToolBar = new QPEToolBar(this);
+ emptyToolBar->setHorizontalStretchable(true);
+
+ QPEToolBar* drawParametersToolBar = new QPEToolBar(this);
+
+ QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
+
+ penWidthSpinBox->setValue(1);
+
+ m_pPenColorToolButton = new QToolButton(drawParametersToolBar);
+ m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png"));
+
+ QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton);
+ connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int)));
+
+ QPixmap penColorPixmap(14, 14);
+
+ for (uint i = 0; i < m_colors.size(); i++) {
+ penColorPixmap.fill(m_colors.at(i));
+ penColorPopupMenu->insertItem(penColorPixmap, i);
+ }
+
+ QToolTip::add(m_pPenColorToolButton, tr("Pen Color"));
+ m_pPenColorToolButton->setPopup(penColorPopupMenu);
+ m_pPenColorToolButton->setPopupDelay(0);
+
+ penColorPopupMenu->activateItemAt(0);
+
+ m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
+ m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png"));
+
+ QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton);
+ connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int)));
+
+ QPixmap brushColorPixmap(14, 14);
+
+ for (uint i = 0; i < m_colors.size(); i++) {
+ brushColorPixmap.fill(m_colors.at(i));
+ brushColorPopupMenu->insertItem(brushColorPixmap, i);
+ }
+
+ QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
+ m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
+ m_pBrushColorToolButton->setPopupDelay(0);
+
+ brushColorPopupMenu->activateItemAt(1);
+}
+
+DrawPad::~DrawPad()
+{
+ QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
+
+ if (file.open(IO_WriteOnly)) {
+ m_pDrawPadCanvas->save(&file);
+ file.close();
+ }
+}
+
+void DrawPad::clearAll()
+{
+ m_pDrawPadCanvas->clearAll();
+ updateNavigationToolBar();
+}
+
+void DrawPad::newPage()
+{
+ m_pDrawPadCanvas->newPage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::deletePage()
+{
+ m_pDrawPadCanvas->deletePage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::goFirstPage()
+{
+ m_pDrawPadCanvas->goFirstPage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::goPreviousPage()
+{
+ m_pDrawPadCanvas->goPreviousPage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::goNextPage()
+{
+ m_pDrawPadCanvas->goNextPage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::goLastPage()
+{
+ m_pDrawPadCanvas->goLastPage();
+ updateNavigationToolBar();
+}
+
+void DrawPad::setPointDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(true);
+ m_pLineDrawModeAction->setOn(false);
+ m_pRectangleDrawModeAction->setOn(false);
+ m_pEllipseDrawModeAction->setOn(false);
+ m_pFillDrawModeAction->setOn(false);
+ m_pEraseDrawModeAction->setOn(false);
+}
+
+void DrawPad::setLineDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(false);
+ m_pLineDrawModeAction->setOn(true);
+ m_pRectangleDrawModeAction->setOn(false);
+ m_pEllipseDrawModeAction->setOn(false);
+ m_pFillDrawModeAction->setOn(false);
+ m_pEraseDrawModeAction->setOn(false);
+}
+
+void DrawPad::setRectangleDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new RectangleDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(false);
+ m_pLineDrawModeAction->setOn(false);
+ m_pRectangleDrawModeAction->setOn(true);
+ m_pEllipseDrawModeAction->setOn(false);
+ m_pFillDrawModeAction->setOn(false);
+ m_pEraseDrawModeAction->setOn(false);
+}
+
+void DrawPad::setEllipseDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new EllipseDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(false);
+ m_pLineDrawModeAction->setOn(false);
+ m_pRectangleDrawModeAction->setOn(false);
+ m_pEllipseDrawModeAction->setOn(true);
+ m_pFillDrawModeAction->setOn(false);
+ m_pEraseDrawModeAction->setOn(false);
+}
+
+void DrawPad::setFillDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new FillDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(false);
+ m_pLineDrawModeAction->setOn(false);
+ m_pRectangleDrawModeAction->setOn(false);
+ m_pEllipseDrawModeAction->setOn(false);
+ m_pFillDrawModeAction->setOn(true);
+ m_pEraseDrawModeAction->setOn(false);
+}
+
+void DrawPad::setEraseDrawMode()
+{
+ if (m_pDrawMode) {
+ delete m_pDrawMode;
+ }
+
+ m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas);
+
+ m_pPointDrawModeAction->setOn(false);
+ m_pLineDrawModeAction->setOn(false);
+ m_pRectangleDrawModeAction->setOn(false);
+ m_pEllipseDrawModeAction->setOn(false);
+ m_pFillDrawModeAction->setOn(false);
+ m_pEraseDrawModeAction->setOn(true);
+}
+
+void DrawPad::changePenWidth(int value)
+{
+ m_pen.setWidth(value);
+}
+
+void DrawPad::changePenColor(int index)
+{
+ m_pen.setColor(m_colors.at(index));
+
+ QPainter painter;
+ painter.begin(m_pPenColorToolButton->pixmap());
+ painter.fillRect(QRect(0, 12, 14, 2), m_pen.color());
+ painter.end();
+}
+
+void DrawPad::changeBrushColor(int index)
+{
+ m_brush = QBrush(m_colors.at(index));
+
+ QPainter painter;
+ painter.begin(m_pBrushColorToolButton->pixmap());
+ painter.fillRect(QRect(0, 12, 14, 2), m_brush.color());
+ painter.end();
+}
+
+void DrawPad::updateNavigationToolBar()
+{
+ m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
+ m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
+ m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
+ m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DRAWPAD_H
+#define DRAWPAD_H
+
+#include <qmainwindow.h>
+
+#include <qpen.h>
+
+class DrawMode;
+class DrawPadCanvas;
+
+class QAction;
+class QColor;
+class QToolButton;
+class QWidgetStack;
+
+class DrawPad : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel);
+ ~DrawPad();
+
+ DrawMode* drawMode() { return m_pDrawMode; }
+ QPen pen() { return m_pen; }
+ QBrush brush() { return m_brush; }
+
+private slots:
+ void clearAll();
+ void newPage();
+ void deletePage();
+
+ void goFirstPage();
+ void goPreviousPage();
+ void goNextPage();
+ void goLastPage();
+
+ void setPointDrawMode();
+ void setLineDrawMode();
+ void setRectangleDrawMode();
+ void setEllipseDrawMode();
+ void setFillDrawMode();
+ void setEraseDrawMode();
+
+ void changePenWidth(int value);
+ void changePenColor(int index);
+ void changeBrushColor(int index);
+
+private:
+ void updateNavigationToolBar();
+
+ DrawPadCanvas* m_pDrawPadCanvas;
+ QArray<QColor> m_colors;
+
+ DrawMode* m_pDrawMode;
+ QPen m_pen;
+ QBrush m_brush;
+
+ QAction* m_pFirstPageAction;
+ QAction* m_pPreviousPageAction;
+ QAction* m_pNextPageAction;
+ QAction* m_pLastPageAction;
+
+ QAction* m_pPointDrawModeAction;
+ QAction* m_pLineDrawModeAction;
+ QAction* m_pRectangleDrawModeAction;
+ QAction* m_pEllipseDrawModeAction;
+ QAction* m_pFillDrawModeAction;
+ QAction* m_pEraseDrawModeAction;
+
+ QToolButton* m_pPenColorToolButton;
+ QToolButton* m_pBrushColorToolButton;
+};
+
+#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 @@
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS = drawmode.h \
+ drawpad.h \
+ drawpadcanvas.h \
+ ellipsedrawmode.h \
+ erasedrawmode.h \
+ filldrawmode.h \
+ linedrawmode.h \
+ pointdrawmode.h \
+ rectangledrawmode.h
+SOURCES = main.cpp \
+ drawmode.cpp \
+ drawpad.cpp \
+ drawpadcanvas.cpp \
+ ellipsedrawmode.cpp \
+ erasedrawmode.cpp \
+ filldrawmode.cpp \
+ linedrawmode.cpp \
+ pointdrawmode.cpp \
+ rectangledrawmode.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe
+DESTDIR = $(OPIEDIR)/bin
+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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "drawpadcanvas.h"
+
+#include "drawmode.h"
+#include "drawpad.h"
+
+#include <qbuffer.h>
+#include <qimage.h>
+#include <qpainter.h>
+#include <qpixmap.h>
+#include <qtextcodec.h>
+#include <qtextstream.h>
+#include <qxml.h>
+
+#include <zlib.h>
+
+class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
+{
+public:
+ DrawPadCanvasXmlHandler();
+ ~DrawPadCanvasXmlHandler();
+
+ QList<QPixmap> pixmaps();
+
+ bool startElement(const QString& namespaceURI, const QString& localName,
+ const QString& qName, const QXmlAttributes& atts);
+ bool endElement(const QString& namespaceURI, const QString& localName,
+ const QString& qName);
+ bool characters(const QString& ch);
+
+private:
+ enum State {
+ Unknown,
+ InData
+ };
+
+ State m_state;
+ ulong m_dataLenght;
+ QList<QPixmap> m_pixmaps;
+};
+
+DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler()
+{
+ m_state = Unknown;
+}
+
+DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler()
+{
+}
+
+QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps()
+{
+ return m_pixmaps;
+}
+
+bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName,
+ const QString& qName, const QXmlAttributes& atts)
+{
+ Q_CONST_UNUSED(namespaceURI)
+ Q_CONST_UNUSED(localName)
+
+ if (qName.compare("data") == 0) {
+ m_state = InData;
+ m_dataLenght = atts.value("length").toULong();
+ }
+
+ return true;
+}
+
+bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName,
+ const QString& qName)
+{
+ Q_CONST_UNUSED(namespaceURI)
+ Q_CONST_UNUSED(localName)
+
+ if (qName.compare("data") == 0) {
+ m_state = Unknown;
+ }
+
+ return true;
+}
+
+bool DrawPadCanvasXmlHandler::characters(const QString& ch)
+{
+ if (m_state == InData) {
+ QByteArray byteArray(ch.length() / 2);
+
+ for (int i = 0; i < (int)ch.length() / 2; i++) {
+ char h = ch[2 * i].latin1();
+ char l = ch[2 * i + 1].latin1();
+ uchar r = 0;
+
+ if (h <= '9') {
+ r += h - '0';
+ } else {
+ r += h - 'a' + 10;
+ }
+
+ r = r << 4;
+
+ if (l <= '9') {
+ r += l - '0';
+ } else {
+ r += l - 'a' + 10;
+ }
+
+ byteArray[i] = r;
+ }
+
+ if (m_dataLenght < ch.length() * 5) {
+ m_dataLenght = ch.length() * 5;
+ }
+
+ QByteArray byteArrayUnzipped(m_dataLenght);
+ ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size());
+
+ QImage image;
+ image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM");
+
+ QPixmap* pixmap = new QPixmap(image.width(), image.height());
+ pixmap->convertFromImage(image);
+ m_pixmaps.append(pixmap);
+ }
+
+ return true;
+}
+
+DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f)
+ : QWidget(parent, name, f)
+{
+ setBackgroundMode(QWidget::PaletteBase);
+
+ m_pDrawPad = drawPad;
+ m_buffers.setAutoDelete(true);
+ m_buffers.append(new QPixmap(width(), height()));
+ m_buffers.current()->fill(Qt::white);
+}
+
+DrawPadCanvas::~DrawPadCanvas()
+{
+}
+
+void DrawPadCanvas::load(QIODevice* ioDevice)
+{
+ QTextStream textStream(ioDevice);
+ textStream.setCodec(QTextCodec::codecForName("UTF-8"));
+
+ QXmlInputSource xmlInputSource(textStream);
+ QXmlSimpleReader xmlSimpleReader;
+ DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
+
+ xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
+ xmlSimpleReader.parse(xmlInputSource);
+
+ m_buffers = drawPadCanvasXmlHandler.pixmaps();
+
+ if (m_buffers.isEmpty()) {
+ m_buffers.append(new QPixmap(width(), height()));
+ m_buffers.current()->fill(Qt::white);
+ }
+
+ repaint();
+}
+
+void DrawPadCanvas::save(QIODevice* ioDevice)
+{
+ QTextStream textStream(ioDevice);
+ textStream.setCodec(QTextCodec::codecForName("UTF-8"));
+
+ textStream << "<drawpad>" << endl;
+ textStream << " <images>" << endl;
+
+ QListIterator<QPixmap> bufferIterator(m_buffers);
+
+ for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
+ textStream << " <image>" << endl;
+
+ QImage image = bufferIterator.current()->convertToImage();
+ QByteArray byteArray;
+ QBuffer buffer(byteArray);
+ QImageIO imageIO(&buffer, "XPM");
+
+ buffer.open(IO_WriteOnly);
+ imageIO.setImage(image);
+ imageIO.write();
+ buffer.close();
+
+ ulong size = byteArray.size() * 2;
+ QByteArray byteArrayZipped(size);
+ ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size());
+
+ textStream << " <data length=\"" << byteArray.size() << "\">";
+
+ static const char hexchars[] = "0123456789abcdef";
+
+ for (int i = 0; i < (int)size; i++ ) {
+ uchar s = (uchar)byteArrayZipped[i];
+ textStream << hexchars[s >> 4];
+ textStream << hexchars[s & 0x0f];
+ }
+
+ textStream << "</data>" << endl;
+ textStream << " </image>" << endl;
+ }
+
+ textStream << " </images>" << endl;
+ textStream << "</drawpad>";
+}
+
+QPixmap* DrawPadCanvas::currentPage()
+{
+ return m_buffers.current();
+}
+
+void DrawPadCanvas::clearAll()
+{
+ m_buffers.clear();
+
+ m_buffers.append(new QPixmap(width(), height()));
+ m_buffers.current()->fill(Qt::white);
+
+ repaint();
+}
+
+void DrawPadCanvas::newPage()
+{
+ m_buffers.insert(m_buffers.at() + 1, new QPixmap(width(), height()));
+ m_buffers.current()->fill(Qt::white);
+ repaint();
+}
+
+void DrawPadCanvas::clearPage()
+{
+ m_buffers.current()->fill(Qt::white);
+ repaint();
+}
+
+void DrawPadCanvas::deletePage()
+{
+ m_buffers.remove(m_buffers.current());
+
+ if (m_buffers.isEmpty()) {
+ m_buffers.append(new QPixmap(width(), height()));
+ m_buffers.current()->fill(Qt::white);
+ }
+
+ repaint();
+}
+
+bool DrawPadCanvas::goPreviousPageEnabled()
+{
+ return (m_buffers.current() != m_buffers.getFirst());
+}
+
+bool DrawPadCanvas::goNextPageEnabled()
+{
+ return (m_buffers.current() != m_buffers.getLast());
+}
+
+void DrawPadCanvas::goFirstPage()
+{
+ m_buffers.first();
+ repaint();
+}
+
+void DrawPadCanvas::goPreviousPage()
+{
+ m_buffers.prev();
+ repaint();
+}
+
+void DrawPadCanvas::goNextPage()
+{
+ m_buffers.next();
+ repaint();
+}
+
+void DrawPadCanvas::goLastPage()
+{
+ m_buffers.last();
+ repaint();
+}
+
+void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
+{
+ m_pDrawPad->drawMode()->mousePressEvent(e);
+}
+
+void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e)
+{
+ m_pDrawPad->drawMode()->mouseReleaseEvent(e);
+}
+
+void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e)
+{
+ m_pDrawPad->drawMode()->mouseMoveEvent(e);
+}
+
+void DrawPadCanvas::resizeEvent(QResizeEvent* e)
+{
+ QWidget::resizeEvent(e);
+
+ QListIterator<QPixmap> bufferIterator(m_buffers);
+
+ for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
+ int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width();
+ int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height();
+
+ QPixmap tmpPixmap(*(bufferIterator.current()));
+ bufferIterator.current()->resize(w, h);
+ bufferIterator.current()->fill(Qt::white);
+
+ bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height());
+ }
+}
+
+void DrawPadCanvas::paintEvent(QPaintEvent* e)
+{
+ QWidget::paintEvent(e);
+
+ QArray<QRect> rects = e->region().rects();
+
+ for (uint i = 0; i < rects.count(); i++) {
+ QRect r = rects[i];
+ bitBlt(this, r.x(), r.y(), m_buffers.current(), r.x(), r.y(), r.width(), r.height());
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DRAWPADCANVAS_H
+#define DRAWPADCANVAS_H
+
+#include <qwidget.h>
+
+#include <qlist.h>
+#include <qpointarray.h>
+
+class DrawPad;
+
+class QPixmap;
+
+class DrawPadCanvas : public QWidget
+{
+ Q_OBJECT
+
+public:
+ DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0);
+ ~DrawPadCanvas();
+
+ void load(QIODevice* ioDevice);
+ void save(QIODevice* ioDevice);
+
+ bool goPreviousPageEnabled();
+ bool goNextPageEnabled();
+
+ QPixmap* currentPage();
+
+public slots:
+ void clearAll();
+ void newPage();
+ void clearPage();
+ void deletePage();
+
+ void goFirstPage();
+ void goPreviousPage();
+ void goNextPage();
+ void goLastPage();
+
+protected:
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+ void resizeEvent(QResizeEvent* e);
+ void paintEvent(QPaintEvent* e);
+
+private:
+ DrawPad* m_pDrawPad;
+ QList<QPixmap> m_buffers;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "ellipsedrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+EllipseDrawMode::~EllipseDrawMode()
+{
+}
+
+void EllipseDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setRasterOp(Qt::NotROP);
+ painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
+ painter.setPen(m_pDrawPad->pen());
+ painter.setRasterOp(Qt::CopyROP);
+ painter.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_mousePressed = false;
+}
+
+void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setRasterOp(Qt::NotROP);
+ m_polyline[0] = e->pos();
+ painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
+ painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_polyline[1] = m_polyline[0];
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef ELLIPSEDRAWMODE_H
+#define ELLIPSEDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class EllipseDrawMode : public DrawMode
+{
+public:
+ EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~EllipseDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ bool m_mousePressed;
+ QPointArray m_polyline;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "erasedrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+EraseDrawMode::~EraseDrawMode()
+{
+}
+
+void EraseDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+
+ m_mousePressed = false;
+}
+
+void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ QPainter painter;
+ QPen pen(Qt::white, m_pDrawPad->pen().width());
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setPen(pen);
+ m_polyline[2] = m_polyline[1];
+ m_polyline[1] = m_polyline[0];
+ m_polyline[0] = e->pos();
+ painter.drawPolyline(m_polyline);
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef ERASEDRAWMODE_H
+#define ERASEPOINTDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class EraseDrawMode : public DrawMode
+{
+public:
+ EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~EraseDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ bool m_mousePressed;
+ QPointArray m_polyline;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "filldrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qimage.h>
+#include <qpixmap.h>
+
+FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+}
+
+FillDrawMode::~FillDrawMode()
+{
+}
+
+void FillDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ int x = e->x();
+ int y = e->y();
+
+ m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
+ m_fillRgb = m_pDrawPad->brush().color().rgb();
+ m_oldRgb = m_image.pixel(x, y);
+
+ if (m_oldRgb != m_fillRgb) {
+ m_image.setPixel(x, y, m_fillRgb);
+ fillEast(x + 1, y);
+ fillSouth(x, y + 1);
+ fillWest(x - 1, y);
+ fillNorth(x, y - 1);
+
+ m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
+ m_pDrawPadCanvas->repaint();
+ }
+}
+
+void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+}
+
+void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+}
+
+void FillDrawMode::fillEast(int x, int y)
+{
+ if (x < m_image.width()) {
+ if (m_image.pixel(x, y) == m_oldRgb) {
+ m_image.setPixel(x, y, m_fillRgb);
+ fillEast(x + 1, y);
+ fillSouth(x, y + 1);
+ fillNorth(x, y - 1);
+ }
+ }
+}
+
+void FillDrawMode::fillSouth(int x, int y)
+{
+ if (y < m_image.height()) {
+ if (m_image.pixel(x, y) == m_oldRgb) {
+ m_image.setPixel(x, y, m_fillRgb);
+ fillEast(x + 1, y);
+ fillSouth(x, y + 1);
+ fillWest(x - 1, y);
+ }
+ }
+}
+
+void FillDrawMode::fillWest(int x, int y)
+{
+ if (x >= 0) {
+ if (m_image.pixel(x, y) == m_oldRgb) {
+ m_image.setPixel(x, y, m_fillRgb);
+ fillSouth(x, y + 1);
+ fillWest(x - 1, y);
+ fillNorth(x, y - 1);
+ }
+ }
+}
+
+void FillDrawMode::fillNorth(int x, int y)
+{
+ if (y >= 0) {
+ if (m_image.pixel(x, y) == m_oldRgb) {
+ m_image.setPixel(x, y, m_fillRgb);
+ fillEast(x + 1, y);
+ fillWest(x - 1, y);
+ fillNorth(x, y - 1);
+ }
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef FILLDRAWMODE_H
+#define FILLDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qimage.h>
+
+class FillDrawMode : public DrawMode
+{
+public:
+ FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~FillDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ void fillEast(int x, int y);
+ void fillSouth(int x, int y);
+ void fillWest(int x, int y);
+ void fillNorth(int x, int y);
+
+ QImage m_image;
+ QRgb m_fillRgb;
+ QRgb m_oldRgb;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "linedrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+LineDrawMode::~LineDrawMode()
+{
+}
+
+void LineDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void LineDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setPen(m_pDrawPad->pen());
+ painter.drawLine(m_polyline[2], m_polyline[0]);
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_mousePressed = false;
+}
+
+void LineDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setRasterOp(Qt::NotROP);
+ m_polyline[0] = e->pos();
+ painter.drawLine(m_polyline[2], m_polyline[1]);
+ painter.drawLine(m_polyline[2], m_polyline[0]);
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_polyline[1] = m_polyline[0];
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef LINEDRAWMODE_H
+#define LINEDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class LineDrawMode : public DrawMode
+{
+public:
+ LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~LineDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ bool m_mousePressed;
+ QPointArray m_polyline;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "drawpad.h"
+
+#include <qpe/qpeapplication.h>
+
+int main(int argc, char **argv)
+{
+ QPEApplication a(argc, argv);
+
+ DrawPad mw;
+ a.showMainWidget(&mw);
+
+ return a.exec();
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "pointdrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+PointDrawMode::~PointDrawMode()
+{
+}
+
+void PointDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void PointDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+
+ m_mousePressed = false;
+}
+
+void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setPen(m_pDrawPad->pen());
+ m_polyline[2] = m_polyline[1];
+ m_polyline[1] = m_polyline[0];
+ m_polyline[0] = e->pos();
+ painter.drawPolyline(m_polyline);
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef POINTDRAWMODE_H
+#define POINTDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class PointDrawMode : public DrawMode
+{
+public:
+ PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~PointDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ bool m_mousePressed;
+ QPointArray m_polyline;
+};
+
+#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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "rectangledrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+RectangleDrawMode::~RectangleDrawMode()
+{
+}
+
+void RectangleDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e);
+
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setPen(m_pDrawPad->pen());
+ painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_mousePressed = false;
+}
+
+void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ painter.setRasterOp(Qt::NotROP);
+ m_polyline[0] = e->pos();
+ painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
+ painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
+ painter.end();
+
+ QRect r = m_polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft(r.left() - m_pDrawPad->pen().width());
+ r.setTop(r.top() - m_pDrawPad->pen().width());
+ r.setRight(r.right() + m_pDrawPad->pen().width());
+ r.setBottom(r.bottom() + m_pDrawPad->pen().width());
+
+ bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_polyline[1] = m_polyline[0];
+ }
+}
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 @@
+/***************************************************************************
+ * *
+ * DrawPad - a drawing program for Opie Environment *
+ * *
+ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef RECTANGLEDRAWMODE_H
+#define RECTANGLEDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class RectangleDrawMode : public DrawMode
+{
+public:
+ RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~RectangleDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+private:
+ bool m_mousePressed;
+ QPointArray m_polyline;
+};
+
+#endif // RECTANGLEDRAWMODE_H