Diffstat (limited to 'noncore/graphics/drawpad/drawpadcanvas.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 146 |
1 files changed, 37 insertions, 109 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 05dd408..025bebb 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -28,8 +28,6 @@ | |||
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qxml.h> | 29 | #include <qxml.h> |
30 | 30 | ||
31 | const int PAGE_BACKUPS = 99; | ||
32 | |||
33 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 31 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
34 | { | 32 | { |
35 | public: | 33 | public: |
@@ -149,7 +147,7 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) | |||
149 | 147 | ||
150 | Page* page = new Page(m_title, image.width(), image.height()); | 148 | Page* page = new Page(m_title, image.width(), image.height()); |
151 | page->setLastModified(m_date); | 149 | page->setLastModified(m_date); |
152 | page->convertFromImage(image); | 150 | page->pixmap()->convertFromImage(image); |
153 | m_pages.append(page); | 151 | m_pages.append(page); |
154 | } | 152 | } |
155 | 153 | ||
@@ -161,7 +159,6 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name | |||
161 | { | 159 | { |
162 | m_pDrawPad = drawPad; | 160 | m_pDrawPad = drawPad; |
163 | m_pages.setAutoDelete(true); | 161 | m_pages.setAutoDelete(true); |
164 | m_pageBackups.setAutoDelete(true); | ||
165 | 162 | ||
166 | viewport()->setBackgroundMode(QWidget::NoBackground); | 163 | viewport()->setBackgroundMode(QWidget::NoBackground); |
167 | } | 164 | } |
@@ -186,32 +183,24 @@ void DrawPadCanvas::load(QIODevice* ioDevice) | |||
186 | 183 | ||
187 | if (m_pages.isEmpty()) { | 184 | if (m_pages.isEmpty()) { |
188 | m_pages.append(new Page("", contentsRect().size())); | 185 | m_pages.append(new Page("", contentsRect().size())); |
189 | m_pages.current()->fill(Qt::white); | 186 | m_pages.current()->pixmap()->fill(Qt::white); |
190 | } | 187 | } |
191 | 188 | ||
192 | m_pageBackups.clear(); | 189 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
193 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
194 | |||
195 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
196 | viewport()->update(); | 190 | viewport()->update(); |
197 | 191 | ||
198 | emit pagesChanged(); | 192 | emit pagesChanged(); |
199 | emit pageBackupsChanged(); | ||
200 | } | 193 | } |
201 | 194 | ||
202 | void DrawPadCanvas::initialPage() | 195 | void DrawPadCanvas::initialPage() |
203 | { | 196 | { |
204 | m_pages.append(new Page("", 236, 232)); | 197 | m_pages.append(new Page("", 236, 232)); |
205 | m_pages.current()->fill(Qt::white); | 198 | m_pages.current()->pixmap()->fill(Qt::white); |
206 | |||
207 | m_pageBackups.clear(); | ||
208 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
209 | 199 | ||
210 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 200 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
211 | viewport()->update(); | 201 | viewport()->update(); |
212 | 202 | ||
213 | emit pagesChanged(); | 203 | emit pagesChanged(); |
214 | emit pageBackupsChanged(); | ||
215 | } | 204 | } |
216 | 205 | ||
217 | void DrawPadCanvas::save(QIODevice* ioDevice) | 206 | void DrawPadCanvas::save(QIODevice* ioDevice) |
@@ -227,11 +216,11 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
227 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 216 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
228 | textStream << " <image>" << endl; | 217 | textStream << " <image>" << endl; |
229 | textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; | 218 | textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; |
230 | 219 | ||
231 | int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); | 220 | int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); |
232 | textStream << " <date>" << intDate << "</date>" << endl; | 221 | textStream << " <date>" << intDate << "</date>" << endl; |
233 | 222 | ||
234 | QImage image = bufferIterator.current()->convertToImage(); | 223 | QImage image = bufferIterator.current()->pixmap()->convertToImage(); |
235 | QByteArray byteArray; | 224 | QByteArray byteArray; |
236 | QBuffer buffer(byteArray); | 225 | QBuffer buffer(byteArray); |
237 | QImageIO imageIO(&buffer, "PNG"); | 226 | QImageIO imageIO(&buffer, "PNG"); |
@@ -263,17 +252,13 @@ void DrawPadCanvas::importPage(const QString& fileName) | |||
263 | { | 252 | { |
264 | Page* importedPage = new Page(); | 253 | Page* importedPage = new Page(); |
265 | 254 | ||
266 | importedPage->load(fileName); | 255 | importedPage->pixmap()->load(fileName); |
267 | m_pages.insert(m_pages.at() + 1, importedPage); | 256 | m_pages.insert(m_pages.at() + 1, importedPage); |
268 | 257 | ||
269 | m_pageBackups.clear(); | 258 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
270 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
271 | |||
272 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
273 | viewport()->update(); | 259 | viewport()->update(); |
274 | 260 | ||
275 | emit pagesChanged(); | 261 | emit pagesChanged(); |
276 | emit pageBackupsChanged(); | ||
277 | } | 262 | } |
278 | 263 | ||
279 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 264 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
@@ -289,7 +274,7 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c | |||
289 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 274 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
290 | QImageIO imageIO(ioDevice, format); | 275 | QImageIO imageIO(ioDevice, format); |
291 | 276 | ||
292 | QImage image = m_pages.current()->convertToImage(); | 277 | QImage image = m_pages.current()->pixmap()->convertToImage(); |
293 | imageIO.setImage(image); | 278 | imageIO.setImage(image); |
294 | imageIO.write(); | 279 | imageIO.write(); |
295 | delete ioDevice; | 280 | delete ioDevice; |
@@ -305,7 +290,7 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c | |||
305 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 290 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
306 | QImageIO imageIO(ioDevice, format); | 291 | QImageIO imageIO(ioDevice, format); |
307 | 292 | ||
308 | QImage image = m_pages.at(i - 1)->convertToImage(); | 293 | QImage image = m_pages.at(i - 1)->pixmap()->convertToImage(); |
309 | imageIO.setImage(image); | 294 | imageIO.setImage(image); |
310 | imageIO.write(); | 295 | imageIO.write(); |
311 | delete ioDevice; | 296 | delete ioDevice; |
@@ -336,45 +321,28 @@ uint DrawPadCanvas::pageCount() | |||
336 | void DrawPadCanvas::selectPage(Page* page) | 321 | void DrawPadCanvas::selectPage(Page* page) |
337 | { | 322 | { |
338 | m_pages.findRef(page); | 323 | m_pages.findRef(page); |
339 | m_pageBackups.clear(); | ||
340 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
341 | 324 | ||
342 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 325 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
343 | viewport()->update(); | 326 | viewport()->update(); |
344 | 327 | ||
345 | emit pagesChanged(); | 328 | emit pagesChanged(); |
346 | emit pageBackupsChanged(); | ||
347 | } | 329 | } |
348 | 330 | ||
349 | void DrawPadCanvas::selectPage(uint pagePosition) | 331 | void DrawPadCanvas::backupPage() |
350 | { | 332 | { |
351 | m_pages.at(pagePosition - 1); | 333 | m_pages.current()->backup(); |
352 | m_pageBackups.clear(); | ||
353 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
354 | |||
355 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
356 | viewport()->update(); | ||
357 | 334 | ||
358 | emit pagesChanged(); | 335 | emit pagesChanged(); |
359 | emit pageBackupsChanged(); | ||
360 | } | 336 | } |
361 | 337 | ||
362 | void DrawPadCanvas::backupPage() | 338 | void DrawPadCanvas::selectPage(uint pagePosition) |
363 | { | 339 | { |
364 | m_pages.current()->setLastModified(QDateTime::currentDateTime()); | 340 | m_pages.at(pagePosition - 1); |
365 | |||
366 | Page* currentBackup = m_pageBackups.current(); | ||
367 | while (m_pageBackups.last() != currentBackup) { | ||
368 | m_pageBackups.removeLast(); | ||
369 | } | ||
370 | |||
371 | while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) { | ||
372 | m_pageBackups.removeFirst(); | ||
373 | } | ||
374 | 341 | ||
375 | m_pageBackups.append(new Page(*(m_pages.current()))); | 342 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
343 | viewport()->update(); | ||
376 | 344 | ||
377 | emit pageBackupsChanged(); | 345 | emit pagesChanged(); |
378 | } | 346 | } |
379 | 347 | ||
380 | void DrawPadCanvas::deleteAll() | 348 | void DrawPadCanvas::deleteAll() |
@@ -382,44 +350,31 @@ void DrawPadCanvas::deleteAll() | |||
382 | m_pages.clear(); | 350 | m_pages.clear(); |
383 | 351 | ||
384 | m_pages.append(new Page("", contentsRect().size())); | 352 | m_pages.append(new Page("", contentsRect().size())); |
385 | m_pages.current()->fill(Qt::white); | 353 | m_pages.current()->pixmap()->fill(Qt::white); |
386 | 354 | ||
387 | m_pageBackups.clear(); | 355 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
388 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
389 | |||
390 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
391 | viewport()->update(); | 356 | viewport()->update(); |
392 | 357 | ||
393 | emit pagesChanged(); | 358 | emit pagesChanged(); |
394 | emit pageBackupsChanged(); | ||
395 | } | 359 | } |
396 | 360 | ||
397 | void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) | 361 | void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) |
398 | { | 362 | { |
399 | m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); | 363 | m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); |
400 | m_pages.current()->fill(color); | 364 | m_pages.current()->pixmap()->fill(color); |
401 | |||
402 | m_pageBackups.clear(); | ||
403 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
404 | 365 | ||
405 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 366 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
406 | viewport()->update(); | 367 | viewport()->update(); |
407 | 368 | ||
408 | emit pagesChanged(); | 369 | emit pagesChanged(); |
409 | emit pageBackupsChanged(); | ||
410 | } | 370 | } |
411 | 371 | ||
412 | void DrawPadCanvas::clearPage() | 372 | void DrawPadCanvas::clearPage() |
413 | { | 373 | { |
414 | m_pages.current()->fill(Qt::white); | 374 | m_pages.current()->pixmap()->fill(Qt::white); |
415 | 375 | ||
416 | m_pageBackups.clear(); | 376 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
417 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
418 | |||
419 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
420 | viewport()->update(); | 377 | viewport()->update(); |
421 | |||
422 | emit pageBackupsChanged(); | ||
423 | } | 378 | } |
424 | 379 | ||
425 | void DrawPadCanvas::deletePage() | 380 | void DrawPadCanvas::deletePage() |
@@ -428,17 +383,13 @@ void DrawPadCanvas::deletePage() | |||
428 | 383 | ||
429 | if (m_pages.isEmpty()) { | 384 | if (m_pages.isEmpty()) { |
430 | m_pages.append(new Page("", contentsRect().size())); | 385 | m_pages.append(new Page("", contentsRect().size())); |
431 | m_pages.current()->fill(Qt::white); | 386 | m_pages.current()->pixmap()->fill(Qt::white); |
432 | } | 387 | } |
433 | 388 | ||
434 | m_pageBackups.clear(); | 389 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
435 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
436 | |||
437 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
438 | viewport()->update(); | 390 | viewport()->update(); |
439 | 391 | ||
440 | emit pagesChanged(); | 392 | emit pagesChanged(); |
441 | emit pageBackupsChanged(); | ||
442 | } | 393 | } |
443 | 394 | ||
444 | void DrawPadCanvas::movePageUp() | 395 | void DrawPadCanvas::movePageUp() |
@@ -459,16 +410,6 @@ void DrawPadCanvas::movePageDown() | |||
459 | emit pagesChanged(); | 410 | emit pagesChanged(); |
460 | } | 411 | } |
461 | 412 | ||
462 | bool DrawPadCanvas::undoEnabled() | ||
463 | { | ||
464 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | ||
465 | } | ||
466 | |||
467 | bool DrawPadCanvas::redoEnabled() | ||
468 | { | ||
469 | return (m_pageBackups.current() != m_pageBackups.getLast()); | ||
470 | } | ||
471 | |||
472 | bool DrawPadCanvas::goPreviousPageEnabled() | 413 | bool DrawPadCanvas::goPreviousPageEnabled() |
473 | { | 414 | { |
474 | return (m_pages.current() != m_pages.getFirst()); | 415 | return (m_pages.current() != m_pages.getFirst()); |
@@ -481,72 +422,59 @@ bool DrawPadCanvas::goNextPageEnabled() | |||
481 | 422 | ||
482 | void DrawPadCanvas::undo() | 423 | void DrawPadCanvas::undo() |
483 | { | 424 | { |
484 | *(m_pages.current()) = *(m_pageBackups.prev()); | 425 | m_pages.current()->undo(); |
485 | 426 | ||
486 | viewport()->update(); | 427 | viewport()->update(); |
487 | 428 | ||
488 | emit pageBackupsChanged(); | 429 | emit pagesChanged(); |
489 | } | 430 | } |
490 | 431 | ||
491 | void DrawPadCanvas::redo() | 432 | void DrawPadCanvas::redo() |
492 | { | 433 | { |
493 | *(m_pages.current()) = *(m_pageBackups.next()); | 434 | m_pages.current()->redo(); |
494 | 435 | ||
495 | viewport()->update(); | 436 | viewport()->update(); |
496 | 437 | ||
497 | emit pageBackupsChanged(); | 438 | emit pagesChanged(); |
498 | } | 439 | } |
499 | 440 | ||
500 | void DrawPadCanvas::goFirstPage() | 441 | void DrawPadCanvas::goFirstPage() |
501 | { | 442 | { |
502 | m_pages.first(); | 443 | m_pages.first(); |
503 | m_pageBackups.clear(); | ||
504 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
505 | 444 | ||
506 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 445 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
507 | viewport()->update(); | 446 | viewport()->update(); |
508 | 447 | ||
509 | emit pagesChanged(); | 448 | emit pagesChanged(); |
510 | emit pageBackupsChanged(); | ||
511 | } | 449 | } |
512 | 450 | ||
513 | void DrawPadCanvas::goPreviousPage() | 451 | void DrawPadCanvas::goPreviousPage() |
514 | { | 452 | { |
515 | m_pages.prev(); | 453 | m_pages.prev(); |
516 | m_pageBackups.clear(); | ||
517 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
518 | 454 | ||
519 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 455 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
520 | viewport()->update(); | 456 | viewport()->update(); |
521 | 457 | ||
522 | emit pagesChanged(); | 458 | emit pagesChanged(); |
523 | emit pageBackupsChanged(); | ||
524 | } | 459 | } |
525 | 460 | ||
526 | void DrawPadCanvas::goNextPage() | 461 | void DrawPadCanvas::goNextPage() |
527 | { | 462 | { |
528 | m_pages.next(); | 463 | m_pages.next(); |
529 | m_pageBackups.clear(); | 464 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
530 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
531 | |||
532 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
533 | viewport()->update(); | 465 | viewport()->update(); |
534 | 466 | ||
535 | emit pagesChanged(); | 467 | emit pagesChanged(); |
536 | emit pageBackupsChanged(); | ||
537 | } | 468 | } |
538 | 469 | ||
539 | void DrawPadCanvas::goLastPage() | 470 | void DrawPadCanvas::goLastPage() |
540 | { | 471 | { |
541 | m_pages.last(); | 472 | m_pages.last(); |
542 | m_pageBackups.clear(); | ||
543 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
544 | 473 | ||
545 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 474 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
546 | viewport()->update(); | 475 | viewport()->update(); |
547 | 476 | ||
548 | emit pagesChanged(); | 477 | emit pagesChanged(); |
549 | emit pageBackupsChanged(); | ||
550 | } | 478 | } |
551 | 479 | ||
552 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 480 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
@@ -567,10 +495,10 @@ void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | |||
567 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 495 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
568 | { | 496 | { |
569 | QRect clipRect(cx, cy, cw, ch); | 497 | QRect clipRect(cx, cy, cw, ch); |
570 | QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); | 498 | QRect pixmapRect(0, 0, m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
571 | QRect drawRect = pixmapRect.intersect(clipRect); | 499 | QRect drawRect = pixmapRect.intersect(clipRect); |
572 | 500 | ||
573 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); | 501 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()->pixmap()), drawRect); |
574 | 502 | ||
575 | if (drawRect.right() < clipRect.right()) { | 503 | if (drawRect.right() < clipRect.right()) { |
576 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); | 504 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); |