Diffstat (limited to 'noncore/graphics/drawpad/drawpadcanvas.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 144 |
1 files changed, 112 insertions, 32 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 40c27b5..8818c03 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -13,12 +13,17 @@ | |||
13 | 13 | ||
14 | #include "drawpadcanvas.h" | 14 | #include "drawpadcanvas.h" |
15 | 15 | ||
16 | #include "drawmode.h" | ||
17 | #include "drawpad.h" | 16 | #include "drawpad.h" |
18 | #include "newpagedialog.h" | 17 | #include "newpagedialog.h" |
18 | #include "tool.h" | ||
19 | |||
20 | #include <qpe/applnk.h> | ||
21 | #include <qpe/filemanager.h> | ||
22 | #include <qpe/mimetype.h> | ||
19 | 23 | ||
20 | #include <qbuffer.h> | 24 | #include <qbuffer.h> |
21 | #include <qimage.h> | 25 | #include <qimage.h> |
26 | #include <qmessagebox.h> | ||
22 | #include <qpainter.h> | 27 | #include <qpainter.h> |
23 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
24 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
@@ -239,6 +244,60 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
239 | textStream << "</drawpad>"; | 244 | textStream << "</drawpad>"; |
240 | } | 245 | } |
241 | 246 | ||
247 | void DrawPadCanvas::importPage(const QString& fileName) | ||
248 | { | ||
249 | QPixmap* importedPixmap = new QPixmap(); | ||
250 | |||
251 | importedPixmap->load(fileName); | ||
252 | m_pages.insert(m_pages.at() + 1, importedPixmap); | ||
253 | |||
254 | m_pageBackups.clear(); | ||
255 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
256 | |||
257 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
258 | viewport()->update(); | ||
259 | |||
260 | emit pagesChanged(); | ||
261 | emit pageBackupsChanged(); | ||
262 | } | ||
263 | |||
264 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | ||
265 | { | ||
266 | if (fromPage == toPage) { | ||
267 | DocLnk docLnk; | ||
268 | MimeType mimeType(format); | ||
269 | |||
270 | docLnk.setName(name); | ||
271 | docLnk.setType(mimeType.id()); | ||
272 | |||
273 | FileManager fileManager; | ||
274 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | ||
275 | QImageIO imageIO(ioDevice, format); | ||
276 | |||
277 | QImage image = m_pages.current()->convertToImage(); | ||
278 | imageIO.setImage(image); | ||
279 | imageIO.write(); | ||
280 | delete ioDevice; | ||
281 | } else { | ||
282 | for (uint i = fromPage; i <= toPage; i++) { | ||
283 | DocLnk docLnk; | ||
284 | MimeType mimeType(format); | ||
285 | |||
286 | docLnk.setName(name + QString::number(i)); | ||
287 | docLnk.setType(mimeType.id()); | ||
288 | |||
289 | FileManager fileManager; | ||
290 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | ||
291 | QImageIO imageIO(ioDevice, format); | ||
292 | |||
293 | QImage image = m_pages.at(i - 1)->convertToImage(); | ||
294 | imageIO.setImage(image); | ||
295 | imageIO.write(); | ||
296 | delete ioDevice; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | |||
242 | QPixmap* DrawPadCanvas::currentPage() | 301 | QPixmap* DrawPadCanvas::currentPage() |
243 | { | 302 | { |
244 | return m_pages.current(); | 303 | return m_pages.current(); |
@@ -254,34 +313,41 @@ uint DrawPadCanvas::pageCount() | |||
254 | return m_pages.count(); | 313 | return m_pages.count(); |
255 | } | 314 | } |
256 | 315 | ||
257 | void DrawPadCanvas::clearAll() | 316 | void DrawPadCanvas::deleteAll() |
258 | { | 317 | { |
259 | m_pages.clear(); | 318 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
319 | QMessageBox::Information, QMessageBox::Yes, | ||
320 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
321 | QMessageBox::NoButton, this); | ||
260 | 322 | ||
261 | m_pages.append(new QPixmap(contentsRect().size())); | 323 | if (messageBox.exec() == QMessageBox::Yes) { |
262 | m_pages.current()->fill(Qt::white); | 324 | m_pages.clear(); |
263 | 325 | ||
264 | m_pageBackups.clear(); | 326 | m_pages.append(new QPixmap(contentsRect().size())); |
265 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 327 | m_pages.current()->fill(Qt::white); |
266 | 328 | ||
267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 329 | m_pageBackups.clear(); |
268 | viewport()->update(); | 330 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
269 | 331 | ||
270 | emit pagesChanged(); | 332 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
271 | emit pageBackupsChanged(); | 333 | viewport()->update(); |
334 | |||
335 | emit pagesChanged(); | ||
336 | emit pageBackupsChanged(); | ||
337 | } | ||
272 | } | 338 | } |
273 | 339 | ||
274 | void DrawPadCanvas::newPage() | 340 | void DrawPadCanvas::newPage() |
275 | { | 341 | { |
276 | QRect rect = contentsRect(); | 342 | QRect rect = contentsRect(); |
277 | 343 | ||
278 | NewPageDialog newPageDialog(this); | 344 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
279 | newPageDialog.setWidth(rect.width()); | 345 | m_pDrawPad->brush().color(), this); |
280 | newPageDialog.setHeight(rect.height()); | ||
281 | 346 | ||
282 | if (newPageDialog.exec() == QDialog::Accepted) { | 347 | if (newPageDialog.exec() == QDialog::Accepted) { |
283 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height())); | 348 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), |
284 | m_pages.current()->fill(Qt::white); | 349 | newPageDialog.selectedHeight())); |
350 | m_pages.current()->fill(newPageDialog.selectedColor()); | ||
285 | 351 | ||
286 | m_pageBackups.clear(); | 352 | m_pageBackups.clear(); |
287 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 353 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
@@ -296,28 +362,42 @@ void DrawPadCanvas::newPage() | |||
296 | 362 | ||
297 | void DrawPadCanvas::clearPage() | 363 | void DrawPadCanvas::clearPage() |
298 | { | 364 | { |
299 | m_pages.current()->fill(Qt::white); | 365 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
366 | QMessageBox::Information, QMessageBox::Yes, | ||
367 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
368 | QMessageBox::NoButton, this); | ||
300 | 369 | ||
301 | viewport()->update(); | 370 | if (messageBox.exec() == QMessageBox::Yes) { |
371 | m_pages.current()->fill(Qt::white); | ||
372 | |||
373 | viewport()->update(); | ||
374 | } | ||
302 | } | 375 | } |
303 | 376 | ||
304 | void DrawPadCanvas::deletePage() | 377 | void DrawPadCanvas::deletePage() |
305 | { | 378 | { |
306 | m_pages.remove(m_pages.current()); | 379 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), |
380 | QMessageBox::Information, QMessageBox::Yes, | ||
381 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
382 | QMessageBox::NoButton, this); | ||
307 | 383 | ||
308 | if (m_pages.isEmpty()) { | 384 | if (messageBox.exec() == QMessageBox::Yes) { |
309 | m_pages.append(new QPixmap(contentsRect().size())); | 385 | m_pages.remove(m_pages.current()); |
310 | m_pages.current()->fill(Qt::white); | ||
311 | } | ||
312 | 386 | ||
313 | m_pageBackups.clear(); | 387 | if (m_pages.isEmpty()) { |
314 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 388 | m_pages.append(new QPixmap(contentsRect().size())); |
389 | m_pages.current()->fill(Qt::white); | ||
390 | } | ||
315 | 391 | ||
316 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 392 | m_pageBackups.clear(); |
317 | viewport()->update(); | 393 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
318 | 394 | ||
319 | emit pagesChanged(); | 395 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
320 | emit pageBackupsChanged(); | 396 | viewport()->update(); |
397 | |||
398 | emit pagesChanged(); | ||
399 | emit pageBackupsChanged(); | ||
400 | } | ||
321 | } | 401 | } |
322 | 402 | ||
323 | bool DrawPadCanvas::undoEnabled() | 403 | bool DrawPadCanvas::undoEnabled() |
@@ -412,12 +492,12 @@ void DrawPadCanvas::goLastPage() | |||
412 | 492 | ||
413 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 493 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
414 | { | 494 | { |
415 | m_pDrawPad->drawMode()->mousePressEvent(e); | 495 | m_pDrawPad->tool()->mousePressEvent(e); |
416 | } | 496 | } |
417 | 497 | ||
418 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | 498 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
419 | { | 499 | { |
420 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); | 500 | m_pDrawPad->tool()->mouseReleaseEvent(e); |
421 | 501 | ||
422 | QPixmap* currentBackup = m_pageBackups.current(); | 502 | QPixmap* currentBackup = m_pageBackups.current(); |
423 | while (m_pageBackups.last() != currentBackup) { | 503 | while (m_pageBackups.last() != currentBackup) { |
@@ -435,7 +515,7 @@ void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | |||
435 | 515 | ||
436 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | 516 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
437 | { | 517 | { |
438 | m_pDrawPad->drawMode()->mouseMoveEvent(e); | 518 | m_pDrawPad->tool()->mouseMoveEvent(e); |
439 | } | 519 | } |
440 | 520 | ||
441 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 521 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |