Diffstat (limited to 'noncore/graphics/drawpad/drawpadcanvas.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 135 |
1 files changed, 108 insertions, 27 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index f02f478..08f7b66 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -145,5 +145,7 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name m_pDrawPad = drawPad; - m_buffers.setAutoDelete(true); - m_buffers.append(new QPixmap(width(), height())); - m_buffers.current()->fill(Qt::white); + m_pages.setAutoDelete(true); + m_pages.append(new QPixmap(width(), height())); + m_pages.current()->fill(Qt::white); + m_pageBackups.setAutoDelete(true); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); } @@ -166,9 +168,12 @@ void DrawPadCanvas::load(QIODevice* ioDevice) - m_buffers = drawPadCanvasXmlHandler.pixmaps(); + m_pages = drawPadCanvasXmlHandler.pixmaps(); - if (m_buffers.isEmpty()) { - m_buffers.append(new QPixmap(width(), height())); - m_buffers.current()->fill(Qt::white); + if (m_pages.isEmpty()) { + m_pages.append(new QPixmap(width(), height())); + m_pages.current()->fill(Qt::white); } + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); + repaint(); @@ -184,3 +189,3 @@ void DrawPadCanvas::save(QIODevice* ioDevice) - QListIterator<QPixmap> bufferIterator(m_buffers); + QListIterator<QPixmap> bufferIterator(m_pages); @@ -223,3 +228,3 @@ QPixmap* DrawPadCanvas::currentPage() { - return m_buffers.current(); + return m_pages.current(); } @@ -228,8 +233,14 @@ void DrawPadCanvas::clearAll() { - m_buffers.clear(); + m_pages.clear(); + + m_pages.append(new QPixmap(width(), height())); + m_pages.current()->fill(Qt::white); - m_buffers.append(new QPixmap(width(), height())); - m_buffers.current()->fill(Qt::white); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -238,5 +249,10 @@ void DrawPadCanvas::newPage() { - m_buffers.insert(m_buffers.at() + 1, new QPixmap(width(), height())); - m_buffers.current()->fill(Qt::white); + m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height())); + m_pages.current()->fill(Qt::white); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -245,3 +261,3 @@ void DrawPadCanvas::clearPage() { - m_buffers.current()->fill(Qt::white); + m_pages.current()->fill(Qt::white); repaint(); @@ -251,10 +267,26 @@ void DrawPadCanvas::deletePage() { - m_buffers.remove(m_buffers.current()); + m_pages.remove(m_pages.current()); - if (m_buffers.isEmpty()) { - m_buffers.append(new QPixmap(width(), height())); - m_buffers.current()->fill(Qt::white); + if (m_pages.isEmpty()) { + m_pages.append(new QPixmap(width(), height())); + m_pages.current()->fill(Qt::white); } + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); + repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); +} + +bool DrawPadCanvas::undoEnabled() +{ + return (m_pageBackups.current() != m_pageBackups.getFirst()); +} + +bool DrawPadCanvas::redoEnabled() +{ + return (m_pageBackups.current() != m_pageBackups.getLast()); } @@ -263,3 +295,3 @@ bool DrawPadCanvas::goPreviousPageEnabled() { - return (m_buffers.current() != m_buffers.getFirst()); + return (m_pages.current() != m_pages.getFirst()); } @@ -268,3 +300,19 @@ bool DrawPadCanvas::goNextPageEnabled() { - return (m_buffers.current() != m_buffers.getLast()); + return (m_pages.current() != m_pages.getLast()); +} + +void DrawPadCanvas::undo() +{ + *(m_pages.current()) = *(m_pageBackups.prev()); + repaint(); + + emit pageBackupsChanged(); +} + +void DrawPadCanvas::redo() +{ + *(m_pages.current()) = *(m_pageBackups.next()); + repaint(); + + emit pageBackupsChanged(); } @@ -273,4 +321,9 @@ void DrawPadCanvas::goFirstPage() { - m_buffers.first(); + m_pages.first(); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -279,4 +332,9 @@ void DrawPadCanvas::goPreviousPage() { - m_buffers.prev(); + m_pages.prev(); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -285,4 +343,9 @@ void DrawPadCanvas::goNextPage() { - m_buffers.next(); + m_pages.next(); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -291,4 +354,9 @@ void DrawPadCanvas::goLastPage() { - m_buffers.last(); + m_pages.last(); + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); repaint(); + + emit pagesChanged(); + emit pageBackupsChanged(); } @@ -303,2 +371,15 @@ void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) m_pDrawPad->drawMode()->mouseReleaseEvent(e); + + QPixmap* currentBackup = m_pageBackups.current(); + while (m_pageBackups.last() != currentBackup) { + m_pageBackups.removeLast(); + } + + while (m_pageBackups.count() >= (5 + 1)) { + m_pageBackups.removeFirst(); + } + + m_pageBackups.append(new QPixmap(*(m_pages.current()))); + + emit pageBackupsChanged(); } @@ -314,3 +395,3 @@ void DrawPadCanvas::resizeEvent(QResizeEvent* e) - QListIterator<QPixmap> bufferIterator(m_buffers); + QListIterator<QPixmap> bufferIterator(m_pages); @@ -336,3 +417,3 @@ void DrawPadCanvas::paintEvent(QPaintEvent* e) QRect r = rects[i]; - bitBlt(this, r.x(), r.y(), m_buffers.current(), r.x(), r.y(), r.width(), r.height()); + bitBlt(this, r.x(), r.y(), m_pages.current(), r.x(), r.y(), r.width(), r.height()); } |