summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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.cpp138
-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, 415 insertions, 274 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
@@ -35,24 +35,17 @@
35#include <qtoolbutton.h> 35#include <qtoolbutton.h>
36#include <qtooltip.h> 36#include <qtooltip.h>
37 37
38DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) 38DrawPad::DrawPad(QWidget* parent, const char* name)
39 : QMainWindow(parent, name, f) 39 : QMainWindow(parent, name)
40{ 40{
41 setCaption(tr("DrawPad"));
42
43 // init members 41 // init members
44 42
45 m_pDrawPadCanvas = new DrawPadCanvas(this, this); 43 m_pDrawPadCanvas = new DrawPadCanvas(this, this);
44
46 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); 45 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
46 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
47 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); 47 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
48 48
49 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
50
51 if (file.open(IO_ReadOnly)) {
52 m_pDrawPadCanvas->load(&file);
53 file.close();
54 }
55
56 setCentralWidget(m_pDrawPadCanvas); 49 setCentralWidget(m_pDrawPadCanvas);
57 50
58 // init menu 51 // init menu
@@ -106,8 +99,6 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
106 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); 99 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
107 m_pRedoAction->addTo(navigationToolBar); 100 m_pRedoAction->addTo(navigationToolBar);
108 101
109 updateUndoRedoToolButtons();
110
111 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); 102 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
112 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); 103 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
113 m_pFirstPageAction->addTo(navigationToolBar); 104 m_pFirstPageAction->addTo(navigationToolBar);
@@ -124,8 +115,6 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
124 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); 115 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
125 m_pLastPageAction->addTo(navigationToolBar); 116 m_pLastPageAction->addTo(navigationToolBar);
126 117
127 updateNavigationToolButtons();
128
129 // init draw mode toolbar 118 // init draw mode toolbar
130 119
131 QPEToolBar* drawModeToolBar = new QPEToolBar(this); 120 QPEToolBar* drawModeToolBar = new QPEToolBar(this);
@@ -217,6 +206,17 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
217 m_pBrushColorToolButton->setPopupDelay(0); 206 m_pBrushColorToolButton->setPopupDelay(0);
218 207
219 brushColorPopupMenu->activateItemAt(1); 208 brushColorPopupMenu->activateItemAt(1);
209
210 // init pages
211
212 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
213
214 if (file.open(IO_ReadOnly)) {
215 m_pDrawPadCanvas->load(&file);
216 file.close();
217 } else {
218 m_pDrawPadCanvas->initialPage();
219 }
220} 220}
221 221
222DrawPad::~DrawPad() 222DrawPad::~DrawPad()
@@ -379,3 +379,12 @@ void DrawPad::updateNavigationToolButtons()
379 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 379 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
380 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 380 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
381} 381}
382
383void DrawPad::updateCaption()
384{
385 uint pagePosition = m_pDrawPadCanvas->pagePosition();
386 uint pageCount = m_pDrawPadCanvas->pageCount();
387
388 setCaption(tr("DrawPad") + " - " + tr("Page") + " "
389 + QString::number(pagePosition) + "/" + QString::number(pageCount));
390}
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
@@ -31,7 +31,7 @@ class DrawPad : public QMainWindow
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
34 DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); 34 DrawPad(QWidget* parent = 0, const char* name = 0);
35 ~DrawPad(); 35 ~DrawPad();
36 36
37 DrawMode* drawMode() { return m_pDrawMode; } 37 DrawMode* drawMode() { return m_pDrawMode; }
@@ -54,6 +54,7 @@ private slots:
54 54
55 void updateUndoRedoToolButtons(); 55 void updateUndoRedoToolButtons();
56 void updateNavigationToolButtons(); 56 void updateNavigationToolButtons();
57 void updateCaption();
57 58
58private: 59private:
59 DrawPadCanvas* m_pDrawPadCanvas; 60 DrawPadCanvas* m_pDrawPadCanvas;
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
@@ -9,8 +9,10 @@ HEADERS = colordialog.h \
9 erasedrawmode.h \ 9 erasedrawmode.h \
10 filldrawmode.h \ 10 filldrawmode.h \
11 linedrawmode.h \ 11 linedrawmode.h \
12 newpagedialog.h \
12 pointdrawmode.h \ 13 pointdrawmode.h \
13 rectangledrawmode.h 14 rectangledrawmode.h \
15 shapedrawmode.h
14 SOURCES = colordialog.cpp \ 16 SOURCES = colordialog.cpp \
15 colorpanel.cpp \ 17 colorpanel.cpp \
16 drawmode.cpp \ 18 drawmode.cpp \
@@ -21,8 +23,10 @@ SOURCES = colordialog.cpp \
21 filldrawmode.cpp \ 23 filldrawmode.cpp \
22 linedrawmode.cpp \ 24 linedrawmode.cpp \
23 main.cpp \ 25 main.cpp \
26 newpagedialog.cpp \
24 pointdrawmode.cpp \ 27 pointdrawmode.cpp \
25 rectangledrawmode.cpp 28 rectangledrawmode.cpp \
29 shapedrawmode.cpp
26 INCLUDEPATH+= $(OPIEDIR)/include \ 30 INCLUDEPATH+= $(OPIEDIR)/include \
27 $(QTDIR)/src/3rdparty/zlib 31 $(QTDIR)/src/3rdparty/zlib
28 DEPENDPATH+= $(OPIEDIR)/include 32 DEPENDPATH+= $(OPIEDIR)/include
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
@@ -15,6 +15,7 @@
15 15
16#include "drawmode.h" 16#include "drawmode.h"
17#include "drawpad.h" 17#include "drawpad.h"
18#include "newpagedialog.h"
18 19
19#include <qbuffer.h> 20#include <qbuffer.h>
20#include <qimage.h> 21#include <qimage.h>
@@ -137,17 +138,12 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch)
137 return true; 138 return true;
138} 139}
139 140
140DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) 141DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
141 : QWidget(parent, name, f) 142 : QScrollView(parent, name)
142{ 143{
143 setBackgroundMode(QWidget::PaletteBase);
144
145 m_pDrawPad = drawPad; 144 m_pDrawPad = drawPad;
146 m_pages.setAutoDelete(true); 145 m_pages.setAutoDelete(true);
147 m_pages.append(new QPixmap(width(), height()));
148 m_pages.current()->fill(Qt::white);
149 m_pageBackups.setAutoDelete(true); 146 m_pageBackups.setAutoDelete(true);
150 m_pageBackups.append(new QPixmap(*(m_pages.current())));
151} 147}
152 148
153DrawPadCanvas::~DrawPadCanvas() 149DrawPadCanvas::~DrawPadCanvas()
@@ -169,14 +165,33 @@ void DrawPadCanvas::load(QIODevice* ioDevice)
169 m_pages = drawPadCanvasXmlHandler.pixmaps(); 165 m_pages = drawPadCanvasXmlHandler.pixmaps();
170 166
171 if (m_pages.isEmpty()) { 167 if (m_pages.isEmpty()) {
172 m_pages.append(new QPixmap(width(), height())); 168 m_pages.append(new QPixmap(contentsRect().size()));
173 m_pages.current()->fill(Qt::white); 169 m_pages.current()->fill(Qt::white);
174 } 170 }
175 171
176 m_pageBackups.clear(); 172 m_pageBackups.clear();
177 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 173 m_pageBackups.append(new QPixmap(*(m_pages.current())));
178 174
179 repaint(); 175 resizeContents(m_pages.current()->width(), m_pages.current()->height());
176 viewport()->update();
177
178 emit pagesChanged();
179 emit pageBackupsChanged();
180}
181
182void DrawPadCanvas::initialPage()
183{
184 m_pages.append(new QPixmap(234, 252));
185 m_pages.current()->fill(Qt::white);
186
187 m_pageBackups.clear();
188 m_pageBackups.append(new QPixmap(*(m_pages.current())));
189
190 resizeContents(m_pages.current()->width(), m_pages.current()->height());
191 viewport()->update();
192
193 emit pagesChanged();
194 emit pageBackupsChanged();
180} 195}
181 196
182void DrawPadCanvas::save(QIODevice* ioDevice) 197void DrawPadCanvas::save(QIODevice* ioDevice)
@@ -229,17 +244,28 @@ QPixmap* DrawPadCanvas::currentPage()
229 return m_pages.current(); 244 return m_pages.current();
230} 245}
231 246
247uint DrawPadCanvas::pagePosition()
248{
249 return (m_pages.at() + 1);
250}
251
252uint DrawPadCanvas::pageCount()
253{
254 return m_pages.count();
255}
256
232void DrawPadCanvas::clearAll() 257void DrawPadCanvas::clearAll()
233{ 258{
234 m_pages.clear(); 259 m_pages.clear();
235 260
236 m_pages.append(new QPixmap(width(), height())); 261 m_pages.append(new QPixmap(contentsRect().size()));
237 m_pages.current()->fill(Qt::white); 262 m_pages.current()->fill(Qt::white);
238 263
239 m_pageBackups.clear(); 264 m_pageBackups.clear();
240 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 265 m_pageBackups.append(new QPixmap(*(m_pages.current())));
241 266
242 repaint(); 267 resizeContents(m_pages.current()->width(), m_pages.current()->height());
268 viewport()->update();
243 269
244 emit pagesChanged(); 270 emit pagesChanged();
245 emit pageBackupsChanged(); 271 emit pageBackupsChanged();
@@ -247,20 +273,32 @@ void DrawPadCanvas::clearAll()
247 273
248void DrawPadCanvas::newPage() 274void DrawPadCanvas::newPage()
249{ 275{
250 m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height())); 276 QRect rect = contentsRect();
251 m_pages.current()->fill(Qt::white);
252 m_pageBackups.clear();
253 m_pageBackups.append(new QPixmap(*(m_pages.current())));
254 repaint();
255 277
256 emit pagesChanged(); 278 NewPageDialog newPageDialog(this);
257 emit pageBackupsChanged(); 279 newPageDialog.setWidth(rect.width());
280 newPageDialog.setHeight(rect.height());
281
282 if (newPageDialog.exec() == QDialog::Accepted) {
283 m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height()));
284 m_pages.current()->fill(Qt::white);
285
286 m_pageBackups.clear();
287 m_pageBackups.append(new QPixmap(*(m_pages.current())));
288
289 resizeContents(m_pages.current()->width(), m_pages.current()->height());
290 viewport()->update();
291
292 emit pagesChanged();
293 emit pageBackupsChanged();
294 }
258} 295}
259 296
260void DrawPadCanvas::clearPage() 297void DrawPadCanvas::clearPage()
261{ 298{
262 m_pages.current()->fill(Qt::white); 299 m_pages.current()->fill(Qt::white);
263 repaint(); 300
301 viewport()->update();
264} 302}
265 303
266void DrawPadCanvas::deletePage() 304void DrawPadCanvas::deletePage()
@@ -268,14 +306,15 @@ void DrawPadCanvas::deletePage()
268 m_pages.remove(m_pages.current()); 306 m_pages.remove(m_pages.current());
269 307
270 if (m_pages.isEmpty()) { 308 if (m_pages.isEmpty()) {
271 m_pages.append(new QPixmap(width(), height())); 309 m_pages.append(new QPixmap(contentsRect().size()));
272 m_pages.current()->fill(Qt::white); 310 m_pages.current()->fill(Qt::white);
273 } 311 }
274 312
275 m_pageBackups.clear(); 313 m_pageBackups.clear();
276 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 314 m_pageBackups.append(new QPixmap(*(m_pages.current())));
277 315
278 repaint(); 316 resizeContents(m_pages.current()->width(), m_pages.current()->height());
317 viewport()->update();
279 318
280 emit pagesChanged(); 319 emit pagesChanged();
281 emit pageBackupsChanged(); 320 emit pageBackupsChanged();
@@ -304,7 +343,8 @@ bool DrawPadCanvas::goNextPageEnabled()
304void DrawPadCanvas::undo() 343void DrawPadCanvas::undo()
305{ 344{
306 *(m_pages.current()) = *(m_pageBackups.prev()); 345 *(m_pages.current()) = *(m_pageBackups.prev());
307 repaint(); 346
347 viewport()->update();
308 348
309 emit pageBackupsChanged(); 349 emit pageBackupsChanged();
310} 350}
@@ -312,7 +352,8 @@ void DrawPadCanvas::undo()
312void DrawPadCanvas::redo() 352void DrawPadCanvas::redo()
313{ 353{
314 *(m_pages.current()) = *(m_pageBackups.next()); 354 *(m_pages.current()) = *(m_pageBackups.next());
315 repaint(); 355
356 viewport()->update();
316 357
317 emit pageBackupsChanged(); 358 emit pageBackupsChanged();
318} 359}
@@ -322,7 +363,9 @@ void DrawPadCanvas::goFirstPage()
322 m_pages.first(); 363 m_pages.first();
323 m_pageBackups.clear(); 364 m_pageBackups.clear();
324 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 365 m_pageBackups.append(new QPixmap(*(m_pages.current())));
325 repaint(); 366
367 resizeContents(m_pages.current()->width(), m_pages.current()->height());
368 viewport()->update();
326 369
327 emit pagesChanged(); 370 emit pagesChanged();
328 emit pageBackupsChanged(); 371 emit pageBackupsChanged();
@@ -333,7 +376,9 @@ void DrawPadCanvas::goPreviousPage()
333 m_pages.prev(); 376 m_pages.prev();
334 m_pageBackups.clear(); 377 m_pageBackups.clear();
335 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 378 m_pageBackups.append(new QPixmap(*(m_pages.current())));
336 repaint(); 379
380 resizeContents(m_pages.current()->width(), m_pages.current()->height());
381 viewport()->update();
337 382
338 emit pagesChanged(); 383 emit pagesChanged();
339 emit pageBackupsChanged(); 384 emit pageBackupsChanged();
@@ -344,7 +389,9 @@ void DrawPadCanvas::goNextPage()
344 m_pages.next(); 389 m_pages.next();
345 m_pageBackups.clear(); 390 m_pageBackups.clear();
346 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 391 m_pageBackups.append(new QPixmap(*(m_pages.current())));
347 repaint(); 392
393 resizeContents(m_pages.current()->width(), m_pages.current()->height());
394 viewport()->update();
348 395
349 emit pagesChanged(); 396 emit pagesChanged();
350 emit pageBackupsChanged(); 397 emit pageBackupsChanged();
@@ -355,18 +402,20 @@ void DrawPadCanvas::goLastPage()
355 m_pages.last(); 402 m_pages.last();
356 m_pageBackups.clear(); 403 m_pageBackups.clear();
357 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 404 m_pageBackups.append(new QPixmap(*(m_pages.current())));
358 repaint(); 405
406 resizeContents(m_pages.current()->width(), m_pages.current()->height());
407 viewport()->update();
359 408
360 emit pagesChanged(); 409 emit pagesChanged();
361 emit pageBackupsChanged(); 410 emit pageBackupsChanged();
362} 411}
363 412
364void DrawPadCanvas::mousePressEvent(QMouseEvent* e) 413void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
365{ 414{
366 m_pDrawPad->drawMode()->mousePressEvent(e); 415 m_pDrawPad->drawMode()->mousePressEvent(e);
367} 416}
368 417
369void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) 418void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
370{ 419{
371 m_pDrawPad->drawMode()->mouseReleaseEvent(e); 420 m_pDrawPad->drawMode()->mouseReleaseEvent(e);
372 421
@@ -384,37 +433,14 @@ void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e)
384 emit pageBackupsChanged(); 433 emit pageBackupsChanged();
385} 434}
386 435
387void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) 436void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
388{ 437{
389 m_pDrawPad->drawMode()->mouseMoveEvent(e); 438 m_pDrawPad->drawMode()->mouseMoveEvent(e);
390} 439}
391 440
392void DrawPadCanvas::resizeEvent(QResizeEvent* e) 441void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
393{ 442{
394 QWidget::resizeEvent(e); 443 QRect clipRect(cx, cy, cw, ch);
395
396 QListIterator<QPixmap> bufferIterator(m_pages);
397 444
398 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 445 p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect);
399 int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width();
400 int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height();
401
402 QPixmap tmpPixmap(*(bufferIterator.current()));
403 bufferIterator.current()->resize(w, h);
404 bufferIterator.current()->fill(Qt::white);
405
406 bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height());
407 }
408}
409
410void DrawPadCanvas::paintEvent(QPaintEvent* e)
411{
412 QWidget::paintEvent(e);
413
414 QArray<QRect> rects = e->region().rects();
415
416 for (uint i = 0; i < rects.count(); i++) {
417 QRect r = rects[i];
418 bitBlt(this, r.x(), r.y(), m_pages.current(), r.x(), r.y(), r.width(), r.height());
419 }
420} 446}
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
@@ -14,7 +14,7 @@
14#ifndef DRAWPADCANVAS_H 14#ifndef DRAWPADCANVAS_H
15#define DRAWPADCANVAS_H 15#define DRAWPADCANVAS_H
16 16
17#include <qwidget.h> 17#include <qscrollview.h>
18 18
19#include <qlist.h> 19#include <qlist.h>
20#include <qpointarray.h> 20#include <qpointarray.h>
@@ -23,15 +23,16 @@ class DrawPad;
23 23
24class QPixmap; 24class QPixmap;
25 25
26class DrawPadCanvas : public QWidget 26class DrawPadCanvas : public QScrollView
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30public: 30public:
31 DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0); 31 DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0);
32 ~DrawPadCanvas(); 32 ~DrawPadCanvas();
33 33
34 void load(QIODevice* ioDevice); 34 void load(QIODevice* ioDevice);
35 void initialPage();
35 void save(QIODevice* ioDevice); 36 void save(QIODevice* ioDevice);
36 37
37 bool undoEnabled(); 38 bool undoEnabled();
@@ -40,6 +41,8 @@ public:
40 bool goNextPageEnabled(); 41 bool goNextPageEnabled();
41 42
42 QPixmap* currentPage(); 43 QPixmap* currentPage();
44 uint pagePosition();
45 uint pageCount();
43 46
44public slots: 47public slots:
45 void clearAll(); 48 void clearAll();
@@ -60,11 +63,10 @@ signals:
60 void pageBackupsChanged(); 63 void pageBackupsChanged();
61 64
62protected: 65protected:
63 void mousePressEvent(QMouseEvent* e); 66 void contentsMousePressEvent(QMouseEvent* e);
64 void mouseReleaseEvent(QMouseEvent* e); 67 void contentsMouseReleaseEvent(QMouseEvent* e);
65 void mouseMoveEvent(QMouseEvent* e); 68 void contentsMouseMoveEvent(QMouseEvent* e);
66 void resizeEvent(QResizeEvent* e); 69 void drawContents(QPainter* p, int cx, int cy, int cw, int ch);
67 void paintEvent(QPaintEvent* e);
68 70
69private: 71private:
70 DrawPad* m_pDrawPad; 72 DrawPad* m_pDrawPad;
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
@@ -20,67 +20,26 @@
20#include <qpixmap.h> 20#include <qpixmap.h>
21 21
22EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 22EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 23 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 25}
28 26
29EllipseDrawMode::~EllipseDrawMode() 27EllipseDrawMode::~EllipseDrawMode()
30{ 28{
31} 29}
32 30
33void EllipseDrawMode::mousePressEvent(QMouseEvent* e) 31void EllipseDrawMode::drawFinalShape(QPainter& p)
34{ 32{
35 m_mousePressed = true; 33 p.setRasterOp(Qt::NotROP);
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 34 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
35 p.setPen(m_pDrawPad->pen());
36 p.setRasterOp(Qt::CopyROP);
37 p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
37} 38}
38 39
39void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) 40void EllipseDrawMode::drawTemporaryShape(QPainter& p)
40{ 41{
41 Q_UNUSED(e) 42 p.setRasterOp(Qt::NotROP);
42 43 p.drawRect(QRect(m_polyline[2], m_polyline[1]));
43 QPainter painter; 44 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setRasterOp(Qt::NotROP);
46 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
47 painter.setPen(m_pDrawPad->pen());
48 painter.setRasterOp(Qt::CopyROP);
49 painter.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
50 painter.end();
51
52 QRect r = m_polyline.boundingRect();
53 r = r.normalize();
54 r.setLeft(r.left() - m_pDrawPad->pen().width());
55 r.setTop(r.top() - m_pDrawPad->pen().width());
56 r.setRight(r.right() + m_pDrawPad->pen().width());
57 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
58
59 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
60
61 m_mousePressed = false;
62}
63
64void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e)
65{
66 if (m_mousePressed) {
67 QPainter painter;
68 painter.begin(m_pDrawPadCanvas->currentPage());
69 painter.setRasterOp(Qt::NotROP);
70 m_polyline[0] = e->pos();
71 painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
72 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
73 painter.end();
74
75 QRect r = m_polyline.boundingRect();
76 r = r.normalize();
77 r.setLeft(r.left() - m_pDrawPad->pen().width());
78 r.setTop(r.top() - m_pDrawPad->pen().width());
79 r.setRight(r.right() + m_pDrawPad->pen().width());
80 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
81
82 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
83
84 m_polyline[1] = m_polyline[0];
85 }
86} 45}
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
@@ -14,23 +14,17 @@
14#ifndef ELLIPSEDRAWMODE_H 14#ifndef ELLIPSEDRAWMODE_H
15#define ELLIPSEDRAWMODE_H 15#define ELLIPSEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class EllipseDrawMode : public ShapeDrawMode
20
21class EllipseDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~EllipseDrawMode(); 23 ~EllipseDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // ELLIPSEDRAWMODE_H 30#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
@@ -63,6 +63,12 @@ void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
63 r.setRight(r.right() + m_pDrawPad->pen().width()); 63 r.setRight(r.right() + m_pDrawPad->pen().width());
64 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 64 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
65 65
66 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 66 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
67 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
68
69 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
70 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
71
72 m_pDrawPadCanvas->viewport()->update(viewportRect);
67 } 73 }
68} 74}
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
@@ -45,7 +45,7 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e)
45 fillNorth(x, y - 1); 45 fillNorth(x, y - 1);
46 46
47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); 47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
48 m_pDrawPadCanvas->repaint(); 48 m_pDrawPadCanvas->viewport()->update();
49 } 49 }
50} 50}
51 51
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
@@ -16,68 +16,24 @@
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 19LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 20 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 21{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 22}
28 23
29LineDrawMode::~LineDrawMode() 24LineDrawMode::~LineDrawMode()
30{ 25{
31} 26}
32 27
33void LineDrawMode::mousePressEvent(QMouseEvent* e) 28void LineDrawMode::drawFinalShape(QPainter& p)
34{ 29{
35 m_mousePressed = true; 30 p.setPen(m_pDrawPad->pen());
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 31 p.drawLine(m_polyline[2], m_polyline[0]);
37} 32}
38 33
39void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) 34void LineDrawMode::drawTemporaryShape(QPainter& p)
40{ 35{
41 Q_UNUSED(e) 36 p.setRasterOp(Qt::NotROP);
42 37 p.drawLine(m_polyline[2], m_polyline[1]);
43 QPainter painter; 38 p.drawLine(m_polyline[2], m_polyline[0]);
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setPen(m_pDrawPad->pen());
46 painter.drawLine(m_polyline[2], m_polyline[0]);
47 painter.end();
48
49 QRect r = m_polyline.boundingRect();
50 r = r.normalize();
51 r.setLeft(r.left() - m_pDrawPad->pen().width());
52 r.setTop(r.top() - m_pDrawPad->pen().width());
53 r.setRight(r.right() + m_pDrawPad->pen().width());
54 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
55
56 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
57
58 m_mousePressed = false;
59}
60
61void LineDrawMode::mouseMoveEvent(QMouseEvent* e)
62{
63 if (m_mousePressed) {
64 QPainter painter;
65 painter.begin(m_pDrawPadCanvas->currentPage());
66 painter.setRasterOp(Qt::NotROP);
67 m_polyline[0] = e->pos();
68 painter.drawLine(m_polyline[2], m_polyline[1]);
69 painter.drawLine(m_polyline[2], m_polyline[0]);
70 painter.end();
71
72 QRect r = m_polyline.boundingRect();
73 r = r.normalize();
74 r.setLeft(r.left() - m_pDrawPad->pen().width());
75 r.setTop(r.top() - m_pDrawPad->pen().width());
76 r.setRight(r.right() + m_pDrawPad->pen().width());
77 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
78
79 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
80
81 m_polyline[1] = m_polyline[0];
82 }
83} 39}
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
@@ -14,23 +14,17 @@
14#ifndef LINEDRAWMODE_H 14#ifndef LINEDRAWMODE_H
15#define LINEDRAWMODE_H 15#define LINEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class LineDrawMode : public ShapeDrawMode
20
21class LineDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~LineDrawMode(); 23 ~LineDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // LINEDRAWMODE_H 30#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 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "newpagedialog.h"
15
16#include <qlabel.h>
17#include <qlayout.h>
18#include <qspinbox.h>
19
20NewPageDialog::NewPageDialog(QWidget* parent, const char* name)
21 : QDialog(parent, name, true)
22{
23 setCaption(tr("New Page"));
24
25 QLabel* widthLabel = new QLabel(tr("Width :"), this);
26 QLabel* heightLabel = new QLabel(tr("Height :"), this);
27
28 m_pWidthSpinBox = new QSpinBox(1, 1024, 1, this);
29 m_pHeightSpinBox = new QSpinBox(1, 1024, 1, this);
30
31 QGridLayout* gridLayout = new QGridLayout(this, 2, 2, 2, 2);
32
33 gridLayout->addWidget(widthLabel, 0, 0);
34 gridLayout->addWidget(heightLabel, 1, 0);
35 gridLayout->addWidget(m_pWidthSpinBox, 0, 1);
36 gridLayout->addWidget(m_pHeightSpinBox, 1, 1);
37}
38
39NewPageDialog::~NewPageDialog()
40{
41}
42
43void NewPageDialog::setWidth(int width)
44{
45 m_pWidthSpinBox->setValue(width);
46}
47
48void NewPageDialog::setHeight(int height)
49{
50 m_pHeightSpinBox->setValue(height);
51}
52
53int NewPageDialog::width()
54{
55 return m_pWidthSpinBox->value();
56}
57
58int NewPageDialog::height()
59{
60 return m_pHeightSpinBox->value();
61}
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 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#ifndef NEWPAGEDIALOG_H
15#define NEWPAGEDIALOG_H
16
17#include <qdialog.h>
18
19class QSpinBox;
20
21class NewPageDialog : public QDialog
22{
23 Q_OBJECT
24
25public:
26 NewPageDialog(QWidget* parent = 0, const char* name = 0);
27 ~NewPageDialog();
28
29 void setWidth(int width);
30 void setHeight(int height);
31
32 int width();
33 int height();
34
35private:
36 QSpinBox* m_pWidthSpinBox;
37 QSpinBox* m_pHeightSpinBox;
38};
39
40#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
@@ -62,6 +62,12 @@ void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
62 r.setRight(r.right() + m_pDrawPad->pen().width()); 62 r.setRight(r.right() + m_pDrawPad->pen().width());
63 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 63 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
64 64
65 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 65 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
66 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
67
68 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
69 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
70
71 m_pDrawPadCanvas->viewport()->update(viewportRect);
66 } 72 }
67} 73}
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
@@ -16,68 +16,24 @@
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 19RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 20 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 21{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 22}
28 23
29RectangleDrawMode::~RectangleDrawMode() 24RectangleDrawMode::~RectangleDrawMode()
30{ 25{
31} 26}
32 27
33void RectangleDrawMode::mousePressEvent(QMouseEvent* e) 28void RectangleDrawMode::drawFinalShape(QPainter& p)
34{ 29{
35 m_mousePressed = true; 30 p.setPen(m_pDrawPad->pen());
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 31 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
37} 32}
38 33
39void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) 34void RectangleDrawMode::drawTemporaryShape(QPainter& p)
40{ 35{
41 Q_UNUSED(e) 36 p.setRasterOp(Qt::NotROP);
42 37 p.drawRect(QRect(m_polyline[2], m_polyline[1]));
43 QPainter painter; 38 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setPen(m_pDrawPad->pen());
46 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
47 painter.end();
48
49 QRect r = m_polyline.boundingRect();
50 r = r.normalize();
51 r.setLeft(r.left() - m_pDrawPad->pen().width());
52 r.setTop(r.top() - m_pDrawPad->pen().width());
53 r.setRight(r.right() + m_pDrawPad->pen().width());
54 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
55
56 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
57
58 m_mousePressed = false;
59}
60
61void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e)
62{
63 if (m_mousePressed) {
64 QPainter painter;
65 painter.begin(m_pDrawPadCanvas->currentPage());
66 painter.setRasterOp(Qt::NotROP);
67 m_polyline[0] = e->pos();
68 painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
69 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
70 painter.end();
71
72 QRect r = m_polyline.boundingRect();
73 r = r.normalize();
74 r.setLeft(r.left() - m_pDrawPad->pen().width());
75 r.setTop(r.top() - m_pDrawPad->pen().width());
76 r.setRight(r.right() + m_pDrawPad->pen().width());
77 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
78
79 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
80
81 m_polyline[1] = m_polyline[0];
82 }
83} 39}
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
@@ -14,23 +14,17 @@
14#ifndef RECTANGLEDRAWMODE_H 14#ifndef RECTANGLEDRAWMODE_H
15#define RECTANGLEDRAWMODE_H 15#define RECTANGLEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class RectangleDrawMode : public ShapeDrawMode
20
21class RectangleDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~RectangleDrawMode(); 23 ~RectangleDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // RECTANGLEDRAWMODE_H 30#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 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "shapedrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22ShapeDrawMode::ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29ShapeDrawMode::~ShapeDrawMode()
30{
31}
32
33void ShapeDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void ShapeDrawMode::mouseReleaseEvent(QMouseEvent* e)
40{
41 Q_UNUSED(e)
42
43 QPainter painter;
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 drawFinalShape(painter);
46 painter.end();
47
48 QRect r = m_polyline.boundingRect();
49 r = r.normalize();
50 r.setLeft(r.left() - m_pDrawPad->pen().width());
51 r.setTop(r.top() - m_pDrawPad->pen().width());
52 r.setRight(r.right() + m_pDrawPad->pen().width());
53 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
54
55 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
56 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
57
58 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
59 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
60
61 m_pDrawPadCanvas->viewport()->update(viewportRect);
62
63 m_mousePressed = false;
64}
65
66void ShapeDrawMode::mouseMoveEvent(QMouseEvent* e)
67{
68 if (m_mousePressed) {
69 m_polyline[0] = e->pos();
70 QPainter painter;
71 painter.begin(m_pDrawPadCanvas->currentPage());
72 drawTemporaryShape(painter);
73 painter.end();
74
75 QRect r = m_polyline.boundingRect();
76 r = r.normalize();
77 r.setLeft(r.left() - m_pDrawPad->pen().width());
78 r.setTop(r.top() - m_pDrawPad->pen().width());
79 r.setRight(r.right() + m_pDrawPad->pen().width());
80 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
81
82 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
83 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
84
85 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
86 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
87
88 m_pDrawPadCanvas->viewport()->update(viewportRect);
89
90 m_polyline[1] = m_polyline[0];
91 }
92}
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 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#ifndef SHAPEDRAWMODE_H
15#define SHAPEDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class ShapeDrawMode : public DrawMode
22{
23public:
24 ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~ShapeDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31protected:
32 virtual void drawFinalShape(QPainter& p) = 0;
33 virtual void drawTemporaryShape(QPainter& p) = 0;
34
35 QPointArray m_polyline;
36
37private:
38 bool m_mousePressed;
39};
40
41#endif // SHAPEDRAWMODE_H