summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp39
-rw-r--r--noncore/graphics/drawpad/drawpad.h3
-rw-r--r--noncore/graphics/drawpad/drawpad.pro8
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp128
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h18
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.cpp63
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.h16
-rw-r--r--noncore/graphics/drawpad/erasedrawmode.cpp8
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp2
-rw-r--r--noncore/graphics/drawpad/linedrawmode.cpp60
-rw-r--r--noncore/graphics/drawpad/linedrawmode.h16
-rw-r--r--noncore/graphics/drawpad/newpagedialog.cpp61
-rw-r--r--noncore/graphics/drawpad/newpagedialog.h40
-rw-r--r--noncore/graphics/drawpad/pointdrawmode.cpp8
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.cpp60
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.h16
-rw-r--r--noncore/graphics/drawpad/shapedrawmode.cpp92
-rw-r--r--noncore/graphics/drawpad/shapedrawmode.h41
18 files changed, 410 insertions, 269 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index f67bef8..e94187f 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -22,50 +22,43 @@
#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)
+DrawPad::DrawPad(QWidget* parent, const char* name)
+ : QMainWindow(parent, name)
{
- setCaption(tr("DrawPad"));
-
// init members
m_pDrawPadCanvas = new DrawPadCanvas(this, this);
+
connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
+ connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
- QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
-
- if (file.open(IO_ReadOnly)) {
- m_pDrawPadCanvas->load(&file);
- file.close();
- }
-
setCentralWidget(m_pDrawPadCanvas);
// 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()), m_pDrawPadCanvas, SLOT(clearAll()));
clearAllAction->addTo(toolsPopupMenu);
toolsPopupMenu->insertSeparator();
@@ -93,52 +86,48 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
QPEToolBar* emptyToolBar = new QPEToolBar(this);
emptyToolBar->setHorizontalStretchable(true);
// init navigation toolbar
QPEToolBar* navigationToolBar = new QPEToolBar(this);
m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
m_pUndoAction->addTo(navigationToolBar);
m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
m_pRedoAction->addTo(navigationToolBar);
- updateUndoRedoToolButtons();
-
m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, 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()), m_pDrawPadCanvas, 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()), m_pDrawPadCanvas, 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()), m_pDrawPadCanvas, SLOT(goLastPage()));
m_pLastPageAction->addTo(navigationToolBar);
- updateNavigationToolButtons();
-
// 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);
@@ -204,32 +193,43 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu);
connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&)));
brushColorPopupMenu->insertItem(brushColorPanel);
brushColorPopupMenu->insertSeparator();
QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this);
connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor()));
chooseBrushColorAction->addTo(brushColorPopupMenu);
QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
m_pBrushColorToolButton->setPopupDelay(0);
brushColorPopupMenu->activateItemAt(1);
+
+ // init pages
+
+ QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
+
+ if (file.open(IO_ReadOnly)) {
+ m_pDrawPadCanvas->load(&file);
+ file.close();
+ } else {
+ m_pDrawPadCanvas->initialPage();
+ }
}
DrawPad::~DrawPad()
{
QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
if (file.open(IO_WriteOnly)) {
m_pDrawPadCanvas->save(&file);
file.close();
}
}
void DrawPad::setPointDrawMode()
{
if (m_pDrawMode) {
delete m_pDrawMode;
@@ -366,16 +366,25 @@ void DrawPad::chooseBrushColor()
changeBrushColor(newBrushColor);
}
void DrawPad::updateUndoRedoToolButtons()
{
m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled());
m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled());
}
void DrawPad::updateNavigationToolButtons()
{
m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
}
+
+void DrawPad::updateCaption()
+{
+ uint pagePosition = m_pDrawPadCanvas->pagePosition();
+ uint pageCount = m_pDrawPadCanvas->pageCount();
+
+ setCaption(tr("DrawPad") + " - " + tr("Page") + " "
+ + QString::number(pagePosition) + "/" + QString::number(pageCount));
+}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 35b3be4..c49a559 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -18,55 +18,56 @@
#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(QWidget* parent = 0, const char* name = 0);
~DrawPad();
DrawMode* drawMode() { return m_pDrawMode; }
QPen pen() { return m_pen; }
QBrush brush() { return m_brush; }
private slots:
void setPointDrawMode();
void setLineDrawMode();
void setRectangleDrawMode();
void setEllipseDrawMode();
void setFillDrawMode();
void setEraseDrawMode();
void changePenWidth(int value);
void changePenColor(const QColor& color);
void changeBrushColor(const QColor& color);
void choosePenColor();
void chooseBrushColor();
void updateUndoRedoToolButtons();
void updateNavigationToolButtons();
+ void updateCaption();
private:
DrawPadCanvas* m_pDrawPadCanvas;
DrawMode* m_pDrawMode;
QPen m_pen;
QBrush m_brush;
QAction* m_pUndoAction;
QAction* m_pRedoAction;
QAction* m_pFirstPageAction;
QAction* m_pPreviousPageAction;
QAction* m_pNextPageAction;
QAction* m_pLastPageAction;
diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro
index 407a039..b0eb009 100644
--- a/noncore/graphics/drawpad/drawpad.pro
+++ b/noncore/graphics/drawpad/drawpad.pro
@@ -1,31 +1,35 @@
TEMPLATE = app
CONFIG = qt warn_on release
HEADERS = colordialog.h \
colorpanel.h \
drawmode.h \
drawpad.h \
drawpadcanvas.h \
ellipsedrawmode.h \
erasedrawmode.h \
filldrawmode.h \
linedrawmode.h \
+ newpagedialog.h \
pointdrawmode.h \
- rectangledrawmode.h
+ rectangledrawmode.h \
+ shapedrawmode.h
SOURCES = colordialog.cpp \
colorpanel.cpp \
drawmode.cpp \
drawpad.cpp \
drawpadcanvas.cpp \
ellipsedrawmode.cpp \
erasedrawmode.cpp \
filldrawmode.cpp \
linedrawmode.cpp \
main.cpp \
+ newpagedialog.cpp \
pointdrawmode.cpp \
- rectangledrawmode.cpp
+ rectangledrawmode.cpp \
+ shapedrawmode.cpp
INCLUDEPATH += $(OPIEDIR)/include \
$(QTDIR)/src/3rdparty/zlib
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe
DESTDIR = $(OPIEDIR)/bin
TARGET = drawpad
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 08f7b66..49a8cf0 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -2,32 +2,33 @@
* *
* 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 "newpagedialog.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();
@@ -124,72 +125,86 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch)
}
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)
+DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
+ : QScrollView(parent, name)
{
- setBackgroundMode(QWidget::PaletteBase);
-
m_pDrawPad = drawPad;
m_pages.setAutoDelete(true);
- m_pages.append(new QPixmap(width(), height()));
- m_pages.current()->fill(Qt::white);
m_pageBackups.setAutoDelete(true);
- m_pageBackups.append(new QPixmap(*(m_pages.current())));
}
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_pages = drawPadCanvasXmlHandler.pixmaps();
if (m_pages.isEmpty()) {
- m_pages.append(new QPixmap(width(), height()));
+ m_pages.append(new QPixmap(contentsRect().size()));
m_pages.current()->fill(Qt::white);
}
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
+
+ emit pagesChanged();
+ emit pageBackupsChanged();
+}
+
+void DrawPadCanvas::initialPage()
+{
+ m_pages.append(new QPixmap(234, 252));
+ m_pages.current()->fill(Qt::white);
+
+ m_pageBackups.clear();
+ m_pageBackups.append(new QPixmap(*(m_pages.current())));
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
+
+ emit pagesChanged();
+ emit pageBackupsChanged();
}
void DrawPadCanvas::save(QIODevice* ioDevice)
{
QTextStream textStream(ioDevice);
textStream.setCodec(QTextCodec::codecForName("UTF-8"));
textStream << "<drawpad>" << endl;
textStream << " <images>" << endl;
QListIterator<QPixmap> bufferIterator(m_pages);
for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
textStream << " <image>" << endl;
QImage image = bufferIterator.current()->convertToImage();
@@ -216,205 +231,216 @@ void DrawPadCanvas::save(QIODevice* ioDevice)
textStream << hexchars[s & 0x0f];
}
textStream << "</data>" << endl;
textStream << " </image>" << endl;
}
textStream << " </images>" << endl;
textStream << "</drawpad>";
}
QPixmap* DrawPadCanvas::currentPage()
{
return m_pages.current();
}
+uint DrawPadCanvas::pagePosition()
+{
+ return (m_pages.at() + 1);
+}
+
+uint DrawPadCanvas::pageCount()
+{
+ return m_pages.count();
+}
+
void DrawPadCanvas::clearAll()
{
m_pages.clear();
- m_pages.append(new QPixmap(width(), height()));
+ m_pages.append(new QPixmap(contentsRect().size()));
m_pages.current()->fill(Qt::white);
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
void DrawPadCanvas::newPage()
{
- m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height()));
+ QRect rect = contentsRect();
+
+ NewPageDialog newPageDialog(this);
+ newPageDialog.setWidth(rect.width());
+ newPageDialog.setHeight(rect.height());
+
+ if (newPageDialog.exec() == QDialog::Accepted) {
+ m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height()));
m_pages.current()->fill(Qt::white);
+
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
+}
void DrawPadCanvas::clearPage()
{
m_pages.current()->fill(Qt::white);
- repaint();
+
+ viewport()->update();
}
void DrawPadCanvas::deletePage()
{
m_pages.remove(m_pages.current());
if (m_pages.isEmpty()) {
- m_pages.append(new QPixmap(width(), height()));
+ m_pages.append(new QPixmap(contentsRect().size()));
m_pages.current()->fill(Qt::white);
}
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
bool DrawPadCanvas::undoEnabled()
{
return (m_pageBackups.current() != m_pageBackups.getFirst());
}
bool DrawPadCanvas::redoEnabled()
{
return (m_pageBackups.current() != m_pageBackups.getLast());
}
bool DrawPadCanvas::goPreviousPageEnabled()
{
return (m_pages.current() != m_pages.getFirst());
}
bool DrawPadCanvas::goNextPageEnabled()
{
return (m_pages.current() != m_pages.getLast());
}
void DrawPadCanvas::undo()
{
*(m_pages.current()) = *(m_pageBackups.prev());
- repaint();
+
+ viewport()->update();
emit pageBackupsChanged();
}
void DrawPadCanvas::redo()
{
*(m_pages.current()) = *(m_pageBackups.next());
- repaint();
+
+ viewport()->update();
emit pageBackupsChanged();
}
void DrawPadCanvas::goFirstPage()
{
m_pages.first();
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
void DrawPadCanvas::goPreviousPage()
{
m_pages.prev();
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
void DrawPadCanvas::goNextPage()
{
m_pages.next();
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
void DrawPadCanvas::goLastPage()
{
m_pages.last();
m_pageBackups.clear();
m_pageBackups.append(new QPixmap(*(m_pages.current())));
- repaint();
+
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
-void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
+void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
{
m_pDrawPad->drawMode()->mousePressEvent(e);
}
-void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e)
+void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
{
m_pDrawPad->drawMode()->mouseReleaseEvent(e);
QPixmap* currentBackup = m_pageBackups.current();
while (m_pageBackups.last() != currentBackup) {
m_pageBackups.removeLast();
}
while (m_pageBackups.count() >= (5 + 1)) {
m_pageBackups.removeFirst();
}
m_pageBackups.append(new QPixmap(*(m_pages.current())));
emit pageBackupsChanged();
}
-void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e)
+void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
{
m_pDrawPad->drawMode()->mouseMoveEvent(e);
}
-void DrawPadCanvas::resizeEvent(QResizeEvent* e)
+void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
{
- QWidget::resizeEvent(e);
+ QRect clipRect(cx, cy, cw, ch);
- QListIterator<QPixmap> bufferIterator(m_pages);
-
- 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_pages.current(), r.x(), r.y(), r.width(), r.height());
- }
+ p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect);
}
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index eddcb43..4836a3f 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -1,75 +1,77 @@
/***************************************************************************
* *
* 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 <qscrollview.h>
#include <qlist.h>
#include <qpointarray.h>
class DrawPad;
class QPixmap;
-class DrawPadCanvas : public QWidget
+class DrawPadCanvas : public QScrollView
{
Q_OBJECT
public:
- DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0);
+ DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0);
~DrawPadCanvas();
void load(QIODevice* ioDevice);
+ void initialPage();
void save(QIODevice* ioDevice);
bool undoEnabled();
bool redoEnabled();
bool goPreviousPageEnabled();
bool goNextPageEnabled();
QPixmap* currentPage();
+ uint pagePosition();
+ uint pageCount();
public slots:
void clearAll();
void newPage();
void clearPage();
void deletePage();
void undo();
void redo();
void goFirstPage();
void goPreviousPage();
void goNextPage();
void goLastPage();
signals:
void pagesChanged();
void pageBackupsChanged();
protected:
- void mousePressEvent(QMouseEvent* e);
- void mouseReleaseEvent(QMouseEvent* e);
- void mouseMoveEvent(QMouseEvent* e);
- void resizeEvent(QResizeEvent* e);
- void paintEvent(QPaintEvent* e);
+ void contentsMousePressEvent(QMouseEvent* e);
+ void contentsMouseReleaseEvent(QMouseEvent* e);
+ void contentsMouseMoveEvent(QMouseEvent* e);
+ void drawContents(QPainter* p, int cx, int cy, int cw, int ch);
private:
DrawPad* m_pDrawPad;
QList<QPixmap> m_pages;
QList<QPixmap> m_pageBackups;
};
#endif // DRAWPADCANVAS_H
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.cpp b/noncore/graphics/drawpad/ellipsedrawmode.cpp
index 12a1113..f9cfa73 100644
--- a/noncore/graphics/drawpad/ellipsedrawmode.cpp
+++ b/noncore/graphics/drawpad/ellipsedrawmode.cpp
@@ -7,80 +7,39 @@
* 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)
+ : ShapeDrawMode(drawPad, drawPadCanvas)
{
- m_mousePressed = false;
- m_polyline.resize(3);
}
EllipseDrawMode::~EllipseDrawMode()
{
}
-void EllipseDrawMode::mousePressEvent(QMouseEvent* e)
+void EllipseDrawMode::drawFinalShape(QPainter& p)
{
- m_mousePressed = true;
- m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+ p.setRasterOp(Qt::NotROP);
+ p.drawRect(QRect(m_polyline[2], m_polyline[0]));
+ p.setPen(m_pDrawPad->pen());
+ p.setRasterOp(Qt::CopyROP);
+ p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
}
-void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e)
+void EllipseDrawMode::drawTemporaryShape(QPainter& p)
{
- 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];
- }
+ p.setRasterOp(Qt::NotROP);
+ p.drawRect(QRect(m_polyline[2], m_polyline[1]));
+ p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.h b/noncore/graphics/drawpad/ellipsedrawmode.h
index 4787518..0246caa 100644
--- a/noncore/graphics/drawpad/ellipsedrawmode.h
+++ b/noncore/graphics/drawpad/ellipsedrawmode.h
@@ -1,36 +1,30 @@
/***************************************************************************
* *
* 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 "shapedrawmode.h"
-#include <qpointarray.h>
-
-class EllipseDrawMode : public DrawMode
+class EllipseDrawMode : public ShapeDrawMode
{
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;
+protected:
+ void drawFinalShape(QPainter& p);
+ void drawTemporaryShape(QPainter& p);
};
#endif // ELLIPSEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/erasedrawmode.cpp b/noncore/graphics/drawpad/erasedrawmode.cpp
index 990cecb..0e585cc 100644
--- a/noncore/graphics/drawpad/erasedrawmode.cpp
+++ b/noncore/graphics/drawpad/erasedrawmode.cpp
@@ -50,19 +50,25 @@ void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
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());
+ QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
+ m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
+
+ bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
+ m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_pDrawPadCanvas->viewport()->update(viewportRect);
}
}
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp
index 8f68550..1f81cd5 100644
--- a/noncore/graphics/drawpad/filldrawmode.cpp
+++ b/noncore/graphics/drawpad/filldrawmode.cpp
@@ -32,33 +32,33 @@ 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();
+ m_pDrawPadCanvas->viewport()->update();
}
}
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()) {
diff --git a/noncore/graphics/drawpad/linedrawmode.cpp b/noncore/graphics/drawpad/linedrawmode.cpp
index 15445fc..d432fad 100644
--- a/noncore/graphics/drawpad/linedrawmode.cpp
+++ b/noncore/graphics/drawpad/linedrawmode.cpp
@@ -3,81 +3,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. *
* *
***************************************************************************/
#include "linedrawmode.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
-#include <qpainter.h>
-#include <qpixmap.h>
-
LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
- : DrawMode(drawPad, drawPadCanvas)
+ : ShapeDrawMode(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)
+void LineDrawMode::drawFinalShape(QPainter& p)
{
- 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;
+ p.setPen(m_pDrawPad->pen());
+ p.drawLine(m_polyline[2], m_polyline[0]);
}
-void LineDrawMode::mouseMoveEvent(QMouseEvent* e)
+void LineDrawMode::drawTemporaryShape(QPainter& p)
{
- 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];
- }
+ p.setRasterOp(Qt::NotROP);
+ p.drawLine(m_polyline[2], m_polyline[1]);
+ p.drawLine(m_polyline[2], m_polyline[0]);
}
diff --git a/noncore/graphics/drawpad/linedrawmode.h b/noncore/graphics/drawpad/linedrawmode.h
index 25ae2cf..0ddd0ad 100644
--- a/noncore/graphics/drawpad/linedrawmode.h
+++ b/noncore/graphics/drawpad/linedrawmode.h
@@ -1,36 +1,30 @@
/***************************************************************************
* *
* 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 "shapedrawmode.h"
-#include <qpointarray.h>
-
-class LineDrawMode : public DrawMode
+class LineDrawMode : public ShapeDrawMode
{
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;
+protected:
+ void drawFinalShape(QPainter& p);
+ void drawTemporaryShape(QPainter& p);
};
#endif // LINEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/newpagedialog.cpp b/noncore/graphics/drawpad/newpagedialog.cpp
new file mode 100644
index 0000000..c11d977
--- a/dev/null
+++ b/noncore/graphics/drawpad/newpagedialog.cpp
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * *
+ * 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 "newpagedialog.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qspinbox.h>
+
+NewPageDialog::NewPageDialog(QWidget* parent, const char* name)
+ : QDialog(parent, name, true)
+{
+ setCaption(tr("New Page"));
+
+ QLabel* widthLabel = new QLabel(tr("Width :"), this);
+ QLabel* heightLabel = new QLabel(tr("Height :"), this);
+
+ m_pWidthSpinBox = new QSpinBox(1, 1024, 1, this);
+ m_pHeightSpinBox = new QSpinBox(1, 1024, 1, this);
+
+ QGridLayout* gridLayout = new QGridLayout(this, 2, 2, 2, 2);
+
+ gridLayout->addWidget(widthLabel, 0, 0);
+ gridLayout->addWidget(heightLabel, 1, 0);
+ gridLayout->addWidget(m_pWidthSpinBox, 0, 1);
+ gridLayout->addWidget(m_pHeightSpinBox, 1, 1);
+}
+
+NewPageDialog::~NewPageDialog()
+{
+}
+
+void NewPageDialog::setWidth(int width)
+{
+ m_pWidthSpinBox->setValue(width);
+}
+
+void NewPageDialog::setHeight(int height)
+{
+ m_pHeightSpinBox->setValue(height);
+}
+
+int NewPageDialog::width()
+{
+ return m_pWidthSpinBox->value();
+}
+
+int NewPageDialog::height()
+{
+ return m_pHeightSpinBox->value();
+}
diff --git a/noncore/graphics/drawpad/newpagedialog.h b/noncore/graphics/drawpad/newpagedialog.h
new file mode 100644
index 0000000..a2b6b87
--- a/dev/null
+++ b/noncore/graphics/drawpad/newpagedialog.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * *
+ * 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 NEWPAGEDIALOG_H
+#define NEWPAGEDIALOG_H
+
+#include <qdialog.h>
+
+class QSpinBox;
+
+class NewPageDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ NewPageDialog(QWidget* parent = 0, const char* name = 0);
+ ~NewPageDialog();
+
+ void setWidth(int width);
+ void setHeight(int height);
+
+ int width();
+ int height();
+
+private:
+ QSpinBox* m_pWidthSpinBox;
+ QSpinBox* m_pHeightSpinBox;
+};
+
+#endif // NEWPAGEDIALOG_H
diff --git a/noncore/graphics/drawpad/pointdrawmode.cpp b/noncore/graphics/drawpad/pointdrawmode.cpp
index 30753d6..e251f1b 100644
--- a/noncore/graphics/drawpad/pointdrawmode.cpp
+++ b/noncore/graphics/drawpad/pointdrawmode.cpp
@@ -49,19 +49,25 @@ void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
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());
+ QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
+ m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
+
+ bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
+ m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_pDrawPadCanvas->viewport()->update(viewportRect);
}
}
diff --git a/noncore/graphics/drawpad/rectangledrawmode.cpp b/noncore/graphics/drawpad/rectangledrawmode.cpp
index 60d7cea..0226544 100644
--- a/noncore/graphics/drawpad/rectangledrawmode.cpp
+++ b/noncore/graphics/drawpad/rectangledrawmode.cpp
@@ -3,81 +3,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. *
* *
***************************************************************************/
#include "rectangledrawmode.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
-#include <qpainter.h>
-#include <qpixmap.h>
-
RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
- : DrawMode(drawPad, drawPadCanvas)
+ : ShapeDrawMode(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)
+void RectangleDrawMode::drawFinalShape(QPainter& p)
{
- 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;
+ p.setPen(m_pDrawPad->pen());
+ p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
-void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e)
+void RectangleDrawMode::drawTemporaryShape(QPainter& p)
{
- 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];
- }
+ p.setRasterOp(Qt::NotROP);
+ p.drawRect(QRect(m_polyline[2], m_polyline[1]));
+ p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
diff --git a/noncore/graphics/drawpad/rectangledrawmode.h b/noncore/graphics/drawpad/rectangledrawmode.h
index 62b85b1..186533d 100644
--- a/noncore/graphics/drawpad/rectangledrawmode.h
+++ b/noncore/graphics/drawpad/rectangledrawmode.h
@@ -1,36 +1,30 @@
/***************************************************************************
* *
* 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 "shapedrawmode.h"
-#include <qpointarray.h>
-
-class RectangleDrawMode : public DrawMode
+class RectangleDrawMode : public ShapeDrawMode
{
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;
+protected:
+ void drawFinalShape(QPainter& p);
+ void drawTemporaryShape(QPainter& p);
};
#endif // RECTANGLEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/shapedrawmode.cpp b/noncore/graphics/drawpad/shapedrawmode.cpp
new file mode 100644
index 0000000..8b9877d
--- a/dev/null
+++ b/noncore/graphics/drawpad/shapedrawmode.cpp
@@ -0,0 +1,92 @@
+/***************************************************************************
+ * *
+ * 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 "shapedrawmode.h"
+
+#include "drawpad.h"
+#include "drawpadcanvas.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+
+ShapeDrawMode::ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
+ : DrawMode(drawPad, drawPadCanvas)
+{
+ m_mousePressed = false;
+ m_polyline.resize(3);
+}
+
+ShapeDrawMode::~ShapeDrawMode()
+{
+}
+
+void ShapeDrawMode::mousePressEvent(QMouseEvent* e)
+{
+ m_mousePressed = true;
+ m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
+}
+
+void ShapeDrawMode::mouseReleaseEvent(QMouseEvent* e)
+{
+ Q_UNUSED(e)
+
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ drawFinalShape(painter);
+ 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());
+
+ QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
+ m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
+
+ bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
+ m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_pDrawPadCanvas->viewport()->update(viewportRect);
+
+ m_mousePressed = false;
+}
+
+void ShapeDrawMode::mouseMoveEvent(QMouseEvent* e)
+{
+ if (m_mousePressed) {
+ m_polyline[0] = e->pos();
+ QPainter painter;
+ painter.begin(m_pDrawPadCanvas->currentPage());
+ drawTemporaryShape(painter);
+ 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());
+
+ QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
+ m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
+
+ bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
+ m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
+
+ m_pDrawPadCanvas->viewport()->update(viewportRect);
+
+ m_polyline[1] = m_polyline[0];
+ }
+}
diff --git a/noncore/graphics/drawpad/shapedrawmode.h b/noncore/graphics/drawpad/shapedrawmode.h
new file mode 100644
index 0000000..292478f
--- a/dev/null
+++ b/noncore/graphics/drawpad/shapedrawmode.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * *
+ * 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 SHAPEDRAWMODE_H
+#define SHAPEDRAWMODE_H
+
+#include "drawmode.h"
+
+#include <qpointarray.h>
+
+class ShapeDrawMode : public DrawMode
+{
+public:
+ ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
+ ~ShapeDrawMode();
+
+ void mousePressEvent(QMouseEvent* e);
+ void mouseReleaseEvent(QMouseEvent* e);
+ void mouseMoveEvent(QMouseEvent* e);
+
+protected:
+ virtual void drawFinalShape(QPainter& p) = 0;
+ virtual void drawTemporaryShape(QPainter& p) = 0;
+
+ QPointArray m_polyline;
+
+private:
+ bool m_mousePressed;
+};
+
+#endif // SHAPEDRAWMODE_H