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
@@ -37,7 +37,5 @@
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
@@ -45,12 +43,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
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);
@@ -108,4 +101,2 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
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);
@@ -126,4 +117,2 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
126 117
127 updateNavigationToolButtons();
128
129 // init draw mode toolbar 118 // init draw mode toolbar
@@ -219,2 +208,13 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
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}
@@ -381 +381,10 @@ void DrawPad::updateNavigationToolButtons()
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
@@ -33,3 +33,3 @@ class DrawPad : public QMainWindow
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();
@@ -56,2 +56,3 @@ private slots:
56 void updateNavigationToolButtons(); 56 void updateNavigationToolButtons();
57 void updateCaption();
57 58
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
@@ -11,4 +11,6 @@ HEADERS = colordialog.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 \
@@ -23,4 +25,6 @@ SOURCES = colordialog.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 \
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
@@ -17,2 +17,3 @@
17#include "drawpad.h" 17#include "drawpad.h"
18#include "newpagedialog.h"
18 19
@@ -139,13 +140,8 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch)
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}
@@ -171,3 +167,3 @@ void DrawPadCanvas::load(QIODevice* ioDevice)
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);
@@ -178,3 +174,22 @@ void DrawPadCanvas::load(QIODevice* ioDevice)
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}
@@ -231,2 +246,12 @@ QPixmap* DrawPadCanvas::currentPage()
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()
@@ -235,3 +260,3 @@ void DrawPadCanvas::clearAll()
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);
@@ -241,3 +266,4 @@ void DrawPadCanvas::clearAll()
241 266
242 repaint(); 267 resizeContents(m_pages.current()->width(), m_pages.current()->height());
268 viewport()->update();
243 269
@@ -249,10 +275,21 @@ void 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}
@@ -262,3 +299,4 @@ void DrawPadCanvas::clearPage()
262 m_pages.current()->fill(Qt::white); 299 m_pages.current()->fill(Qt::white);
263 repaint(); 300
301 viewport()->update();
264} 302}
@@ -270,3 +308,3 @@ void DrawPadCanvas::deletePage()
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);
@@ -277,3 +315,4 @@ void DrawPadCanvas::deletePage()
277 315
278 repaint(); 316 resizeContents(m_pages.current()->width(), m_pages.current()->height());
317 viewport()->update();
279 318
@@ -306,3 +345,4 @@ void DrawPadCanvas::undo()
306 *(m_pages.current()) = *(m_pageBackups.prev()); 345 *(m_pages.current()) = *(m_pageBackups.prev());
307 repaint(); 346
347 viewport()->update();
308 348
@@ -314,3 +354,4 @@ void DrawPadCanvas::redo()
314 *(m_pages.current()) = *(m_pageBackups.next()); 354 *(m_pages.current()) = *(m_pageBackups.next());
315 repaint(); 355
356 viewport()->update();
316 357
@@ -324,3 +365,5 @@ void DrawPadCanvas::goFirstPage()
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
@@ -335,3 +378,5 @@ void DrawPadCanvas::goPreviousPage()
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
@@ -346,3 +391,5 @@ void DrawPadCanvas::goNextPage()
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
@@ -357,3 +404,5 @@ void DrawPadCanvas::goLastPage()
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
@@ -363,3 +412,3 @@ void DrawPadCanvas::goLastPage()
363 412
364void DrawPadCanvas::mousePressEvent(QMouseEvent* e) 413void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
365{ 414{
@@ -368,3 +417,3 @@ void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
368 417
369void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) 418void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
370{ 419{
@@ -386,3 +435,3 @@ void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e)
386 435
387void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) 436void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
388{ 437{
@@ -391,30 +440,7 @@ void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e)
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
@@ -16,3 +16,3 @@
16 16
17#include <qwidget.h> 17#include <qscrollview.h>
18 18
@@ -25,3 +25,3 @@ class QPixmap;
25 25
26class DrawPadCanvas : public QWidget 26class DrawPadCanvas : public QScrollView
27{ 27{
@@ -30,3 +30,3 @@ class DrawPadCanvas : public QWidget
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();
@@ -34,2 +34,3 @@ public:
34 void load(QIODevice* ioDevice); 34 void load(QIODevice* ioDevice);
35 void initialPage();
35 void save(QIODevice* ioDevice); 36 void save(QIODevice* ioDevice);
@@ -42,2 +43,4 @@ public:
42 QPixmap* currentPage(); 43 QPixmap* currentPage();
44 uint pagePosition();
45 uint pageCount();
43 46
@@ -62,7 +65,6 @@ signals:
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
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
@@ -22,6 +22,4 @@
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}
@@ -32,55 +30,16 @@ EllipseDrawMode::~EllipseDrawMode()
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
@@ -16,7 +16,5 @@
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{
@@ -26,9 +24,5 @@ public:
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};
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
@@ -65,3 +65,9 @@ void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
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 }
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
@@ -47,3 +47,3 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e)
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 }
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
@@ -18,10 +18,5 @@
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}
@@ -32,52 +27,13 @@ LineDrawMode::~LineDrawMode()
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
@@ -16,7 +16,5 @@
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{
@@ -26,9 +24,5 @@ public:
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};
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
@@ -64,3 +64,9 @@ void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
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 }
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
@@ -18,10 +18,5 @@
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}
@@ -32,52 +27,13 @@ RectangleDrawMode::~RectangleDrawMode()
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
@@ -16,7 +16,5 @@
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{
@@ -26,9 +24,5 @@ public:
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};
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