Diffstat (limited to 'noncore/graphics/drawpad/page.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/noncore/graphics/drawpad/page.cpp b/noncore/graphics/drawpad/page.cpp index 601d1c3..fbf3d01 100644 --- a/noncore/graphics/drawpad/page.cpp +++ b/noncore/graphics/drawpad/page.cpp @@ -15,6 +15,12 @@ +const int PAGE_BACKUPS = 99; + Page::Page() - : QPixmap() { + m_title = ""; m_lastModified = QDateTime::currentDateTime(); + m_pPixmap = new QPixmap(); + + m_backHistory.setAutoDelete(true); + m_forwardHistory.setAutoDelete(true); } @@ -22,3 +28,2 @@ Page::Page() Page::Page(QString title, int w, int h) - : QPixmap(w, h) { @@ -26,2 +31,6 @@ Page::Page(QString title, int w, int h) m_lastModified = QDateTime::currentDateTime(); + m_pPixmap = new QPixmap(w, h); + + m_backHistory.setAutoDelete(true); + m_forwardHistory.setAutoDelete(true); } @@ -29,3 +38,2 @@ Page::Page(QString title, int w, int h) Page::Page(QString title, const QSize& size) - : QPixmap(size) { @@ -33,2 +41,6 @@ Page::Page(QString title, const QSize& size) m_lastModified = QDateTime::currentDateTime(); + m_pPixmap = new QPixmap(size); + + m_backHistory.setAutoDelete(true); + m_forwardHistory.setAutoDelete(true); } @@ -37,2 +49,3 @@ Page::~Page() { + delete m_pPixmap; } @@ -49,2 +62,8 @@ QDateTime Page::lastModified() const +QPixmap* Page::pixmap() const + +{ + return m_pPixmap; +} + void Page::setTitle(QString title) @@ -59 +78,36 @@ void Page::setLastModified(QDateTime lastModified) +bool Page::undoEnabled() +{ + return (!m_backHistory.isEmpty()); +} + +bool Page::redoEnabled() +{ + return (!m_forwardHistory.isEmpty()); +} + +void Page::backup() +{ + setLastModified(QDateTime::currentDateTime()); + + while (m_backHistory.count() >= (PAGE_BACKUPS + 1)) { + m_backHistory.removeFirst(); + } + + m_backHistory.append(new QPixmap(*m_pPixmap)); + m_forwardHistory.clear(); +} + +void Page::undo() +{ + m_forwardHistory.append(new QPixmap(*m_pPixmap)); + m_pPixmap = new QPixmap(*(m_backHistory.last())); + m_backHistory.removeLast(); +} + +void Page::redo() +{ + m_backHistory.append(new QPixmap(*m_pPixmap)); + m_pPixmap = new QPixmap(*(m_forwardHistory.last())); + m_forwardHistory.removeLast(); +} |