author | leseb <leseb> | 2002-07-10 21:59:27 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-07-10 21:59:27 (UTC) |
commit | f568737c20bea96fb79d85681a72e142ec05d66f (patch) (side-by-side diff) | |
tree | 80d08b351bbdeec5be93885a4c18ba0207ef990a /noncore | |
parent | 01b04adb73c8bc49938b71a4bebe6fb6a5477f75 (diff) | |
download | opie-f568737c20bea96fb79d85681a72e142ec05d66f.zip opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.gz opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.bz2 |
Undo/redo reimplemented
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 28 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 146 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasetool.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 46 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.h | 20 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pageinformationdialog.cpp | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointtool.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapetool.cpp | 12 | ||||
-rw-r--r-- | noncore/graphics/drawpad/texttool.cpp | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 6 |
13 files changed, 169 insertions, 187 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 4eb47a5..b0a414e 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -57,5 +57,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name) - connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); - connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); - connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); + connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView())); @@ -544,17 +542,3 @@ void DrawPad::changeBrushColor(const QColor& color) -void DrawPad::updateUndoRedoToolButtons() -{ - m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); - m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); -} - -void DrawPad::updateNavigationToolButtons() -{ - m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); - m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); - m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); - m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); -} - -void DrawPad::updateCaption() +void DrawPad::updateView() { @@ -565,2 +549,10 @@ void DrawPad::updateCaption() + QString::number(pagePosition) + "/" + QString::number(pageCount)); + + m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled()); + m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled()); + + m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); + m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); + m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); + m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); } diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index c57606c..7306228 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -61,6 +61,4 @@ private slots: void changeBrushColor(const QColor& color); - - void updateUndoRedoToolButtons(); - void updateNavigationToolButtons(); - void updateCaption(); + + void updateView(); 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 @@ -30,4 +30,2 @@ -const int PAGE_BACKUPS = 99; - class DrawPadCanvasXmlHandler: public QXmlDefaultHandler @@ -151,3 +149,3 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) page->setLastModified(m_date); - page->convertFromImage(image); + page->pixmap()->convertFromImage(image); m_pages.append(page); @@ -163,3 +161,2 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name m_pages.setAutoDelete(true); - m_pageBackups.setAutoDelete(true); @@ -188,9 +185,6 @@ void DrawPadCanvas::load(QIODevice* ioDevice) m_pages.append(new Page("", contentsRect().size())); - m_pages.current()->fill(Qt::white); + m_pages.current()->pixmap()->fill(Qt::white); } - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -198,3 +192,2 @@ void DrawPadCanvas::load(QIODevice* ioDevice) emit pagesChanged(); - emit pageBackupsChanged(); } @@ -204,8 +197,5 @@ void DrawPadCanvas::initialPage() m_pages.append(new Page("", 236, 232)); - m_pages.current()->fill(Qt::white); - - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); + m_pages.current()->pixmap()->fill(Qt::white); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -213,3 +203,2 @@ void DrawPadCanvas::initialPage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -229,3 +218,3 @@ void DrawPadCanvas::save(QIODevice* ioDevice) textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; - + int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); @@ -233,3 +222,3 @@ void DrawPadCanvas::save(QIODevice* ioDevice) - QImage image = bufferIterator.current()->convertToImage(); + QImage image = bufferIterator.current()->pixmap()->convertToImage(); QByteArray byteArray; @@ -265,9 +254,6 @@ void DrawPadCanvas::importPage(const QString& fileName) - importedPage->load(fileName); + importedPage->pixmap()->load(fileName); m_pages.insert(m_pages.at() + 1, importedPage); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -275,3 +261,2 @@ void DrawPadCanvas::importPage(const QString& fileName) emit pagesChanged(); - emit pageBackupsChanged(); } @@ -291,3 +276,3 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c - QImage image = m_pages.current()->convertToImage(); + QImage image = m_pages.current()->pixmap()->convertToImage(); imageIO.setImage(image); @@ -307,3 +292,3 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c - QImage image = m_pages.at(i - 1)->convertToImage(); + QImage image = m_pages.at(i - 1)->pixmap()->convertToImage(); imageIO.setImage(image); @@ -338,6 +323,4 @@ void DrawPadCanvas::selectPage(Page* page) m_pages.findRef(page); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -345,34 +328,19 @@ void DrawPadCanvas::selectPage(Page* page) emit pagesChanged(); - emit pageBackupsChanged(); } -void DrawPadCanvas::selectPage(uint pagePosition) +void DrawPadCanvas::backupPage() { - m_pages.at(pagePosition - 1); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); - viewport()->update(); + m_pages.current()->backup(); emit pagesChanged(); - emit pageBackupsChanged(); } -void DrawPadCanvas::backupPage() +void DrawPadCanvas::selectPage(uint pagePosition) { - m_pages.current()->setLastModified(QDateTime::currentDateTime()); - - Page* currentBackup = m_pageBackups.current(); - while (m_pageBackups.last() != currentBackup) { - m_pageBackups.removeLast(); - } - - while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) { - m_pageBackups.removeFirst(); - } + m_pages.at(pagePosition - 1); - m_pageBackups.append(new Page(*(m_pages.current()))); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); + viewport()->update(); - emit pageBackupsChanged(); + emit pagesChanged(); } @@ -384,8 +352,5 @@ void DrawPadCanvas::deleteAll() m_pages.append(new Page("", contentsRect().size())); - m_pages.current()->fill(Qt::white); + m_pages.current()->pixmap()->fill(Qt::white); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -393,3 +358,2 @@ void DrawPadCanvas::deleteAll() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -399,8 +363,5 @@ void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); - m_pages.current()->fill(color); - - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); + m_pages.current()->pixmap()->fill(color); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -408,3 +369,2 @@ void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor emit pagesChanged(); - emit pageBackupsChanged(); } @@ -413,11 +373,6 @@ void DrawPadCanvas::clearPage() { - m_pages.current()->fill(Qt::white); + m_pages.current()->pixmap()->fill(Qt::white); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); - - emit pageBackupsChanged(); } @@ -430,9 +385,6 @@ void DrawPadCanvas::deletePage() m_pages.append(new Page("", contentsRect().size())); - m_pages.current()->fill(Qt::white); + m_pages.current()->pixmap()->fill(Qt::white); } - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -440,3 +392,2 @@ void DrawPadCanvas::deletePage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -461,12 +412,2 @@ void DrawPadCanvas::movePageDown() -bool DrawPadCanvas::undoEnabled() -{ - return (m_pageBackups.current() != m_pageBackups.getFirst()); -} - -bool DrawPadCanvas::redoEnabled() -{ - return (m_pageBackups.current() != m_pageBackups.getLast()); -} - bool DrawPadCanvas::goPreviousPageEnabled() @@ -483,3 +424,3 @@ void DrawPadCanvas::undo() { - *(m_pages.current()) = *(m_pageBackups.prev()); + m_pages.current()->undo(); @@ -487,3 +428,3 @@ void DrawPadCanvas::undo() - emit pageBackupsChanged(); + emit pagesChanged(); } @@ -492,3 +433,3 @@ void DrawPadCanvas::redo() { - *(m_pages.current()) = *(m_pageBackups.next()); + m_pages.current()->redo(); @@ -496,3 +437,3 @@ void DrawPadCanvas::redo() - emit pageBackupsChanged(); + emit pagesChanged(); } @@ -502,6 +443,4 @@ void DrawPadCanvas::goFirstPage() m_pages.first(); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -509,3 +448,2 @@ void DrawPadCanvas::goFirstPage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -515,6 +453,4 @@ void DrawPadCanvas::goPreviousPage() m_pages.prev(); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -522,3 +458,2 @@ void DrawPadCanvas::goPreviousPage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -528,6 +463,3 @@ void DrawPadCanvas::goNextPage() m_pages.next(); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -535,3 +467,2 @@ void DrawPadCanvas::goNextPage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -541,6 +472,4 @@ void DrawPadCanvas::goLastPage() m_pages.last(); - m_pageBackups.clear(); - m_pageBackups.append(new Page(*(m_pages.current()))); - resizeContents(m_pages.current()->width(), m_pages.current()->height()); + resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); @@ -548,3 +477,2 @@ void DrawPadCanvas::goLastPage() emit pagesChanged(); - emit pageBackupsChanged(); } @@ -569,6 +497,6 @@ void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) QRect clipRect(cx, cy, cw, ch); - QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); + QRect pixmapRect(0, 0, m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); QRect drawRect = pixmapRect.intersect(clipRect); - p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); + p->drawPixmap(drawRect.topLeft(), *(m_pages.current()->pixmap()), drawRect); diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 2283e5e..80a2a7e 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -39,4 +39,2 @@ public: - bool undoEnabled(); - bool redoEnabled(); bool goPreviousPageEnabled(); @@ -60,3 +58,3 @@ public slots: void movePageDown(); - + void undo(); @@ -71,3 +69,2 @@ signals: void pagesChanged(); - void pageBackupsChanged(); @@ -82,3 +79,2 @@ private: QList<Page> m_pages; - QList<Page> m_pageBackups; }; diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp index f77e038..2326da5 100644 --- a/noncore/graphics/drawpad/erasetool.cpp +++ b/noncore/graphics/drawpad/erasetool.cpp @@ -34,2 +34,4 @@ void EraseTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; @@ -43,4 +45,2 @@ void EraseTool::mouseReleaseEvent(QMouseEvent* e) m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } @@ -52,3 +52,3 @@ void EraseTool::mouseMoveEvent(QMouseEvent* e) QPen pen(Qt::white, m_pDrawPad->pen().width()); - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); painter.setPen(pen); @@ -71,3 +71,3 @@ void EraseTool::mouseMoveEvent(QMouseEvent* e) bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), - m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index 0177e1c..2a39d04 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp @@ -37,3 +37,3 @@ void FillTool::mousePressEvent(QMouseEvent* e) - m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); + m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage(); m_fillRgb = m_pDrawPad->brush().color().rgb(); @@ -42,2 +42,4 @@ void FillTool::mousePressEvent(QMouseEvent* e) if (m_oldRgb != m_fillRgb) { + m_pDrawPadCanvas->backupPage(); + if (m_pDrawPad->antiAliasing()) { @@ -60,6 +62,4 @@ void FillTool::mousePressEvent(QMouseEvent* e) - m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); + m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image); m_pDrawPadCanvas->viewport()->update(); - - m_pDrawPadCanvas->backupPage(); } @@ -113,27 +113,27 @@ void FillTool::fillMaskLine(int x, int y) if (m_mask.pixelIndex(x, y) == 0) { - if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { - int x1, x2; + if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { + int x1, x2; - x1 = x - 1; - x2 = x + 1; + x1 = x - 1; + x2 = x + 1; - while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { - x1--; - } + while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { + x1--; + } - while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { - x2++; - } + while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { + x2++; + } - for (int i = x1 + 1; i < x2; i++) { - m_mask.setPixel(i, y, 1); - } + for (int i = x1 + 1; i < x2; i++) { + m_mask.setPixel(i, y, 1); + } - for (int i = x1 + 1; i < x2; i++) { - fillMaskLine(i, y - 1); - } + for (int i = x1 + 1; i < x2; i++) { + fillMaskLine(i, y - 1); + } - for (int i = x1 + 1; i < x2; i++) { - fillMaskLine(i, y + 1); - } + for (int i = x1 + 1; i < x2; i++) { + fillMaskLine(i, y + 1); + } } 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(); +} diff --git a/noncore/graphics/drawpad/page.h b/noncore/graphics/drawpad/page.h index 20a37b5..8ce7bc9 100644 --- a/noncore/graphics/drawpad/page.h +++ b/noncore/graphics/drawpad/page.h @@ -16,7 +16,9 @@ -#include <qpixmap.h> +#include <qobject.h> #include <qdatetime.h> +#include <qlist.h> +#include <qpixmap.h> -class Page : public QPixmap +class Page : public QObject { @@ -28,5 +30,6 @@ public: ~Page(); - + QString title() const; QDateTime lastModified() const; + QPixmap* pixmap() const; @@ -35,2 +38,9 @@ public: + bool undoEnabled(); + bool redoEnabled(); + + void backup(); + void undo(); + void redo(); + private: @@ -38,2 +48,6 @@ private: QDateTime m_lastModified; + QPixmap* m_pPixmap; + + QList<QPixmap> m_backHistory; + QList<QPixmap> m_forwardHistory; }; diff --git a/noncore/graphics/drawpad/pageinformationdialog.cpp b/noncore/graphics/drawpad/pageinformationdialog.cpp index c0d055e..cb14d73 100644 --- a/noncore/graphics/drawpad/pageinformationdialog.cpp +++ b/noncore/graphics/drawpad/pageinformationdialog.cpp @@ -45,6 +45,6 @@ PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox); - QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->width()), sizeGroupBox); + QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->pixmap()->width()), sizeGroupBox); QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox); - QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->height()), sizeGroupBox); + QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->pixmap()->height()), sizeGroupBox); diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp index a4f846e..b9b52bc 100644 --- a/noncore/graphics/drawpad/pointtool.cpp +++ b/noncore/graphics/drawpad/pointtool.cpp @@ -35,2 +35,4 @@ void PointTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; @@ -44,4 +46,2 @@ void PointTool::mouseReleaseEvent(QMouseEvent* e) m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } @@ -63,3 +63,3 @@ void PointTool::mouseMoveEvent(QMouseEvent* e) QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); @@ -106,3 +106,3 @@ void PointTool::mouseMoveEvent(QMouseEvent* e) bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), - m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp index 8870a78..22e3dd6 100644 --- a/noncore/graphics/drawpad/shapetool.cpp +++ b/noncore/graphics/drawpad/shapetool.cpp @@ -34,2 +34,4 @@ void ShapeTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; @@ -43,3 +45,3 @@ void ShapeTool::mouseReleaseEvent(QMouseEvent* e) QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); drawFinalShape(painter); @@ -58,3 +60,3 @@ void ShapeTool::mouseReleaseEvent(QMouseEvent* e) bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), - m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); @@ -63,4 +65,2 @@ void ShapeTool::mouseReleaseEvent(QMouseEvent* e) m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } @@ -72,3 +72,3 @@ void ShapeTool::mouseMoveEvent(QMouseEvent* e) QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); drawTemporaryShape(painter); @@ -87,3 +87,3 @@ void ShapeTool::mouseMoveEvent(QMouseEvent* e) bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), - m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp index 34c8a76..9037abd 100644 --- a/noncore/graphics/drawpad/texttool.cpp +++ b/noncore/graphics/drawpad/texttool.cpp @@ -58,4 +58,6 @@ void TextTool::mousePressEvent(QMouseEvent* e) if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { + m_pDrawPadCanvas->backupPage(); + QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); painter.setPen(m_pDrawPad->pen()); @@ -65,4 +67,2 @@ void TextTool::mousePressEvent(QMouseEvent* e) m_pDrawPadCanvas->viewport()->update(); - - m_pDrawPadCanvas->backupPage(); } diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 14092bf..9b08ca2 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp @@ -37,3 +37,3 @@ PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) - QImage image = m_pPage->convertToImage(); + QImage image = m_pPage->pixmap()->convertToImage(); @@ -59,4 +59,4 @@ PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) m_titleText = QObject::tr("Title:") + " " + m_pPage->title(); - m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width()) - + "x" + QString::number(m_pPage->height()); + m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->pixmap()->width()) + + "x" + QString::number(m_pPage->pixmap()->height()); m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified()); |