-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 39 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 3 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 138 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 18 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsedrawmode.cpp | 63 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsedrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasedrawmode.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linedrawmode.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linedrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/newpagedialog.cpp | 61 | ||||
-rw-r--r-- | noncore/graphics/drawpad/newpagedialog.h | 40 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointdrawmode.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapedrawmode.cpp | 92 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapedrawmode.h | 41 |
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 | |||
@@ -34,26 +34,19 @@ | |||
34 | #include <qspinbox.h> | 34 | #include <qspinbox.h> |
35 | #include <qtoolbutton.h> | 35 | #include <qtoolbutton.h> |
36 | #include <qtooltip.h> | 36 | #include <qtooltip.h> |
37 | 37 | ||
38 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | 38 | DrawPad::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 |
59 | 52 | ||
@@ -105,10 +98,8 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
105 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); | 98 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); |
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); |
114 | 105 | ||
@@ -123,10 +114,8 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
123 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); | 114 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); |
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); |
132 | 121 | ||
@@ -216,8 +205,19 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
216 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 205 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
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 | ||
222 | DrawPad::~DrawPad() | 222 | DrawPad::~DrawPad() |
223 | { | 223 | { |
@@ -378,4 +378,13 @@ void DrawPad::updateNavigationToolButtons() | |||
378 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 378 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
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 | |||
383 | void 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 | |||
@@ -30,9 +30,9 @@ class DrawPad : public QMainWindow | |||
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
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; } |
38 | QPen pen() { return m_pen; } | 38 | QPen pen() { return m_pen; } |
@@ -53,8 +53,9 @@ private slots: | |||
53 | void chooseBrushColor(); | 53 | void chooseBrushColor(); |
54 | 54 | ||
55 | void updateUndoRedoToolButtons(); | 55 | void updateUndoRedoToolButtons(); |
56 | void updateNavigationToolButtons(); | 56 | void updateNavigationToolButtons(); |
57 | void updateCaption(); | ||
57 | 58 | ||
58 | private: | 59 | private: |
59 | DrawPadCanvas* m_pDrawPadCanvas; | 60 | DrawPadCanvas* m_pDrawPadCanvas; |
60 | 61 | ||
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 | |||
@@ -8,10 +8,12 @@ HEADERS = colordialog.h \ | |||
8 | ellipsedrawmode.h \ | 8 | ellipsedrawmode.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 \ |
17 | drawpad.cpp \ | 19 | drawpad.cpp \ |
@@ -20,10 +22,12 @@ SOURCES = colordialog.cpp \ | |||
20 | erasedrawmode.cpp \ | 22 | erasedrawmode.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 |
29 | LIBS += -lqpe | 33 | LIBS += -lqpe |
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 | |||
@@ -14,8 +14,9 @@ | |||
14 | #include "drawpadcanvas.h" | 14 | #include "drawpadcanvas.h" |
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> |
21 | #include <qpainter.h> | 22 | #include <qpainter.h> |
@@ -136,19 +137,14 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) | |||
136 | 137 | ||
137 | return true; | 138 | return true; |
138 | } | 139 | } |
139 | 140 | ||
140 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) | 141 | DrawPadCanvas::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 | ||
153 | DrawPadCanvas::~DrawPadCanvas() | 149 | DrawPadCanvas::~DrawPadCanvas() |
154 | { | 150 | { |
@@ -168,16 +164,35 @@ void DrawPadCanvas::load(QIODevice* ioDevice) | |||
168 | 164 | ||
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 | |||
182 | void 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 | ||
182 | void DrawPadCanvas::save(QIODevice* ioDevice) | 197 | void DrawPadCanvas::save(QIODevice* ioDevice) |
183 | { | 198 | { |
@@ -228,55 +243,79 @@ QPixmap* DrawPadCanvas::currentPage() | |||
228 | { | 243 | { |
229 | return m_pages.current(); | 244 | return m_pages.current(); |
230 | } | 245 | } |
231 | 246 | ||
247 | uint DrawPadCanvas::pagePosition() | ||
248 | { | ||
249 | return (m_pages.at() + 1); | ||
250 | } | ||
251 | |||
252 | uint DrawPadCanvas::pageCount() | ||
253 | { | ||
254 | return m_pages.count(); | ||
255 | } | ||
256 | |||
232 | void DrawPadCanvas::clearAll() | 257 | void 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(); |
246 | } | 272 | } |
247 | 273 | ||
248 | void DrawPadCanvas::newPage() | 274 | 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 | } |
259 | 296 | ||
260 | void DrawPadCanvas::clearPage() | 297 | void 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 | ||
266 | void DrawPadCanvas::deletePage() | 304 | void DrawPadCanvas::deletePage() |
267 | { | 305 | { |
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(); |
282 | } | 321 | } |
@@ -303,17 +342,19 @@ bool DrawPadCanvas::goNextPageEnabled() | |||
303 | 342 | ||
304 | void DrawPadCanvas::undo() | 343 | void 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 | } |
311 | 351 | ||
312 | void DrawPadCanvas::redo() | 352 | void 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 | } |
319 | 360 | ||
@@ -321,9 +362,11 @@ void DrawPadCanvas::goFirstPage() | |||
321 | { | 362 | { |
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(); |
329 | } | 372 | } |
@@ -332,9 +375,11 @@ void DrawPadCanvas::goPreviousPage() | |||
332 | { | 375 | { |
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(); |
340 | } | 385 | } |
@@ -343,9 +388,11 @@ void DrawPadCanvas::goNextPage() | |||
343 | { | 388 | { |
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(); |
351 | } | 398 | } |
@@ -354,20 +401,22 @@ void DrawPadCanvas::goLastPage() | |||
354 | { | 401 | { |
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 | ||
364 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) | 413 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
365 | { | 414 | { |
366 | m_pDrawPad->drawMode()->mousePressEvent(e); | 415 | m_pDrawPad->drawMode()->mousePressEvent(e); |
367 | } | 416 | } |
368 | 417 | ||
369 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | 418 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
370 | { | 419 | { |
371 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); | 420 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); |
372 | 421 | ||
373 | QPixmap* currentBackup = m_pageBackups.current(); | 422 | QPixmap* currentBackup = m_pageBackups.current(); |
@@ -383,38 +432,15 @@ void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | |||
383 | 432 | ||
384 | emit pageBackupsChanged(); | 433 | emit pageBackupsChanged(); |
385 | } | 434 | } |
386 | 435 | ||
387 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) | 436 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
388 | { | 437 | { |
389 | m_pDrawPad->drawMode()->mouseMoveEvent(e); | 438 | m_pDrawPad->drawMode()->mouseMoveEvent(e); |
390 | } | 439 | } |
391 | 440 | ||
392 | void DrawPadCanvas::resizeEvent(QResizeEvent* e) | 441 | void 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 | |||
410 | void 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 | |||
@@ -13,34 +13,37 @@ | |||
13 | 13 | ||
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> |
21 | 21 | ||
22 | class DrawPad; | 22 | class DrawPad; |
23 | 23 | ||
24 | class QPixmap; | 24 | class QPixmap; |
25 | 25 | ||
26 | class DrawPadCanvas : public QWidget | 26 | class DrawPadCanvas : public QScrollView |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | 29 | ||
30 | public: | 30 | public: |
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(); |
38 | bool redoEnabled(); | 39 | bool redoEnabled(); |
39 | bool goPreviousPageEnabled(); | 40 | bool goPreviousPageEnabled(); |
40 | bool goNextPageEnabled(); | 41 | bool goNextPageEnabled(); |
41 | 42 | ||
42 | QPixmap* currentPage(); | 43 | QPixmap* currentPage(); |
44 | uint pagePosition(); | ||
45 | uint pageCount(); | ||
43 | 46 | ||
44 | public slots: | 47 | public slots: |
45 | void clearAll(); | 48 | void clearAll(); |
46 | void newPage(); | 49 | void newPage(); |
@@ -59,13 +62,12 @@ signals: | |||
59 | void pagesChanged(); | 62 | void pagesChanged(); |
60 | void pageBackupsChanged(); | 63 | void pageBackupsChanged(); |
61 | 64 | ||
62 | protected: | 65 | protected: |
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 | ||
69 | private: | 71 | private: |
70 | DrawPad* m_pDrawPad; | 72 | DrawPad* m_pDrawPad; |
71 | QList<QPixmap> m_pages; | 73 | QList<QPixmap> m_pages; |
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 | |||
@@ -19,68 +19,27 @@ | |||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EllipseDrawMode::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 | ||
29 | EllipseDrawMode::~EllipseDrawMode() | 27 | EllipseDrawMode::~EllipseDrawMode() |
30 | { | 28 | { |
31 | } | 29 | } |
32 | 30 | ||
33 | void EllipseDrawMode::mousePressEvent(QMouseEvent* e) | 31 | void 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 | ||
39 | void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) | 40 | void 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 | |||
64 | void 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 | |||
@@ -13,24 +13,18 @@ | |||
13 | 13 | ||
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> | 19 | class EllipseDrawMode : public ShapeDrawMode |
20 | |||
21 | class EllipseDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~EllipseDrawMode(); | 23 | ~EllipseDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
@@ -62,7 +62,13 @@ void EraseDrawMode::mouseMoveEvent(QMouseEvent* e) | |||
62 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 62 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
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 | |||
@@ -44,9 +44,9 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e) | |||
44 | fillWest(x - 1, y); | 44 | fillWest(x - 1, y); |
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 | ||
52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) | 52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) |
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 | |||
@@ -15,69 +15,25 @@ | |||
15 | 15 | ||
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 | |||
22 | LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 19 | LineDrawMode::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 | ||
29 | LineDrawMode::~LineDrawMode() | 24 | LineDrawMode::~LineDrawMode() |
30 | { | 25 | { |
31 | } | 26 | } |
32 | 27 | ||
33 | void LineDrawMode::mousePressEvent(QMouseEvent* e) | 28 | void 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 | ||
39 | void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) | 34 | void 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 | |||
61 | void 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 | |||
@@ -13,24 +13,18 @@ | |||
13 | 13 | ||
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> | 19 | class LineDrawMode : public ShapeDrawMode |
20 | |||
21 | class LineDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~LineDrawMode(); | 23 | ~LineDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
20 | NewPageDialog::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 | |||
39 | NewPageDialog::~NewPageDialog() | ||
40 | { | ||
41 | } | ||
42 | |||
43 | void NewPageDialog::setWidth(int width) | ||
44 | { | ||
45 | m_pWidthSpinBox->setValue(width); | ||
46 | } | ||
47 | |||
48 | void NewPageDialog::setHeight(int height) | ||
49 | { | ||
50 | m_pHeightSpinBox->setValue(height); | ||
51 | } | ||
52 | |||
53 | int NewPageDialog::width() | ||
54 | { | ||
55 | return m_pWidthSpinBox->value(); | ||
56 | } | ||
57 | |||
58 | int 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 | |||
19 | class QSpinBox; | ||
20 | |||
21 | class NewPageDialog : public QDialog | ||
22 | { | ||
23 | Q_OBJECT | ||
24 | |||
25 | public: | ||
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 | |||
35 | private: | ||
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 | |||
@@ -61,7 +61,13 @@ void PointDrawMode::mouseMoveEvent(QMouseEvent* e) | |||
61 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 61 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
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 | |||
@@ -15,69 +15,25 @@ | |||
15 | 15 | ||
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 | |||
22 | RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 19 | RectangleDrawMode::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 | ||
29 | RectangleDrawMode::~RectangleDrawMode() | 24 | RectangleDrawMode::~RectangleDrawMode() |
30 | { | 25 | { |
31 | } | 26 | } |
32 | 27 | ||
33 | void RectangleDrawMode::mousePressEvent(QMouseEvent* e) | 28 | void 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 | ||
39 | void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) | 34 | void 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 | |||
61 | void 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 | |||
@@ -13,24 +13,18 @@ | |||
13 | 13 | ||
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> | 19 | class RectangleDrawMode : public ShapeDrawMode |
20 | |||
21 | class RectangleDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~RectangleDrawMode(); | 23 | ~RectangleDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
22 | ShapeDrawMode::ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | ||
23 | : DrawMode(drawPad, drawPadCanvas) | ||
24 | { | ||
25 | m_mousePressed = false; | ||
26 | m_polyline.resize(3); | ||
27 | } | ||
28 | |||
29 | ShapeDrawMode::~ShapeDrawMode() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void ShapeDrawMode::mousePressEvent(QMouseEvent* e) | ||
34 | { | ||
35 | m_mousePressed = true; | ||
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | ||
37 | } | ||
38 | |||
39 | void 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 | |||
66 | void 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 | |||
21 | class ShapeDrawMode : public DrawMode | ||
22 | { | ||
23 | public: | ||
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 | |||
31 | protected: | ||
32 | virtual void drawFinalShape(QPainter& p) = 0; | ||
33 | virtual void drawTemporaryShape(QPainter& p) = 0; | ||
34 | |||
35 | QPointArray m_polyline; | ||
36 | |||
37 | private: | ||
38 | bool m_mousePressed; | ||
39 | }; | ||
40 | |||
41 | #endif // SHAPEDRAWMODE_H | ||