-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 28 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 144 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasetool.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.h | 18 | ||||
-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, 146 insertions, 164 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 @@ -46,27 +46,25 @@ #include <qpainter.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qtooltip.h> DrawPad::DrawPad(QWidget* parent, const char* name) : QMainWindow(parent, name) { // init members m_pDrawPadCanvas = new DrawPadCanvas(this, this); - 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())); setCentralWidget(m_pDrawPadCanvas); // init menu setToolBarsMovable(false); QPEToolBar* menuToolBar = new QPEToolBar(this); QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); @@ -533,45 +531,39 @@ void DrawPad::changePenColor(const QColor& color) void DrawPad::changeBrushColor(const QColor& color) { m_brush = QBrush(color); QPainter painter; painter.begin(m_pBrushColorToolButton->pixmap()); painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); painter.end(); m_pBrushColorToolButton->popup()->hide(); } -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() { uint pagePosition = m_pDrawPadCanvas->pagePosition(); uint pageCount = m_pDrawPadCanvas->pageCount(); setCaption(tr("DrawPad") + " - " + tr("Page") + " " + 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()); } void DrawPad::deleteAll() { QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); messageBox.setButtonText(QMessageBox::No, tr("No")); 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 @@ -51,27 +51,25 @@ private slots: void setRectangleTool(); void setFilledRectangleTool(); void setEllipseTool(); void setFilledEllipseTool(); void setTextTool(); void setFillTool(); void setEraseTool(); void changePenWidth(int value); void changePenColor(const QColor& color); void changeBrushColor(const QColor& color); - void updateUndoRedoToolButtons(); - void updateNavigationToolButtons(); - void updateCaption(); + void updateView(); void deleteAll(); void importPage(); void exportPage(); void thumbnailView(); void pageInformation(); private: void loadConfig(); void saveConfig(); DrawPadCanvas* m_pDrawPadCanvas; 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 @@ -19,26 +19,24 @@ #include <qpe/applnk.h> #include <qpe/filemanager.h> #include <qpe/mimetype.h> #include <qbuffer.h> #include <qimage.h> #include <qpainter.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qxml.h> -const int PAGE_BACKUPS = 99; - class DrawPadCanvasXmlHandler: public QXmlDefaultHandler { public: DrawPadCanvasXmlHandler(); ~DrawPadCanvasXmlHandler(); QList<Page> pages(); bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName); @@ -140,107 +138,98 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) } else { r += l - 'a' + 10; } byteArray[i] = r; } QImage image; image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); Page* page = new Page(m_title, image.width(), image.height()); page->setLastModified(m_date); - page->convertFromImage(image); + page->pixmap()->convertFromImage(image); m_pages.append(page); } return true; } DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) : QScrollView(parent, name) { m_pDrawPad = drawPad; m_pages.setAutoDelete(true); - m_pageBackups.setAutoDelete(true); viewport()->setBackgroundMode(QWidget::NoBackground); } DrawPadCanvas::~DrawPadCanvas() { } void DrawPadCanvas::load(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); QXmlInputSource xmlInputSource(textStream); QXmlSimpleReader xmlSimpleReader; DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); xmlSimpleReader.parse(xmlInputSource); m_pages = drawPadCanvasXmlHandler.pages(); if (m_pages.isEmpty()) { 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(); emit pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::initialPage() { m_pages.append(new Page("", 236, 232)); - 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 pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::save(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); textStream << "<drawpad>" << endl; textStream << " <images>" << endl; QListIterator<Page> bufferIterator(m_pages); for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { textStream << " <image>" << endl; textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); textStream << " <date>" << intDate << "</date>" << endl; - QImage image = bufferIterator.current()->convertToImage(); + QImage image = bufferIterator.current()->pixmap()->convertToImage(); QByteArray byteArray; QBuffer buffer(byteArray); QImageIO imageIO(&buffer, "PNG"); buffer.open(IO_WriteOnly); imageIO.setImage(image); imageIO.write(); buffer.close(); textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; static const char hexchars[] = "0123456789abcdef"; @@ -254,67 +243,63 @@ void DrawPadCanvas::save(QIODevice* ioDevice) textStream << "</data>" << endl; textStream << " </image>" << endl; } textStream << " </images>" << endl; textStream << "</drawpad>"; } void DrawPadCanvas::importPage(const QString& fileName) { Page* importedPage = new Page(); - 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(); emit pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) { if (fromPage == toPage) { DocLnk docLnk; MimeType mimeType(format); docLnk.setName(name); docLnk.setType(mimeType.id()); FileManager fileManager; QIODevice* ioDevice = fileManager.saveFile(docLnk); QImageIO imageIO(ioDevice, format); - QImage image = m_pages.current()->convertToImage(); + QImage image = m_pages.current()->pixmap()->convertToImage(); imageIO.setImage(image); imageIO.write(); delete ioDevice; } else { for (uint i = fromPage; i <= toPage; i++) { DocLnk docLnk; MimeType mimeType(format); docLnk.setName(name + QString::number(i)); docLnk.setType(mimeType.id()); FileManager fileManager; QIODevice* ioDevice = fileManager.saveFile(docLnk); QImageIO imageIO(ioDevice, format); - QImage image = m_pages.at(i - 1)->convertToImage(); + QImage image = m_pages.at(i - 1)->pixmap()->convertToImage(); imageIO.setImage(image); imageIO.write(); delete ioDevice; } } } Page* DrawPadCanvas::currentPage() { return m_pages.current(); } @@ -327,256 +312,199 @@ uint DrawPadCanvas::pagePosition() { return (m_pages.at() + 1); } uint DrawPadCanvas::pageCount() { return m_pages.count(); } 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(); 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(); } void DrawPadCanvas::deleteAll() { m_pages.clear(); 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(); emit pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) { 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(); emit pagesChanged(); - emit pageBackupsChanged(); } 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(); } void DrawPadCanvas::deletePage() { m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { 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(); emit pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::movePageUp() { int index = m_pages.at(); Page* page = m_pages.take(); m_pages.insert(index - 1, page); emit pagesChanged(); } void DrawPadCanvas::movePageDown() { int index = m_pages.at(); Page* page = m_pages.take(); m_pages.insert(index + 1, page); emit pagesChanged(); } -bool DrawPadCanvas::undoEnabled() -{ - return (m_pageBackups.current() != m_pageBackups.getFirst()); -} - -bool DrawPadCanvas::redoEnabled() -{ - return (m_pageBackups.current() != m_pageBackups.getLast()); -} - bool DrawPadCanvas::goPreviousPageEnabled() { return (m_pages.current() != m_pages.getFirst()); } bool DrawPadCanvas::goNextPageEnabled() { return (m_pages.current() != m_pages.getLast()); } void DrawPadCanvas::undo() { - *(m_pages.current()) = *(m_pageBackups.prev()); + m_pages.current()->undo(); viewport()->update(); - emit pageBackupsChanged(); + emit pagesChanged(); } void DrawPadCanvas::redo() { - *(m_pages.current()) = *(m_pageBackups.next()); + m_pages.current()->redo(); viewport()->update(); - emit pageBackupsChanged(); + emit pagesChanged(); } 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(); emit pagesChanged(); - emit pageBackupsChanged(); } 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(); emit pagesChanged(); - emit pageBackupsChanged(); } 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(); emit pagesChanged(); - emit pageBackupsChanged(); } 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(); emit pagesChanged(); - emit pageBackupsChanged(); } void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) { m_pDrawPad->tool()->mousePressEvent(e); } void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) { m_pDrawPad->tool()->mouseReleaseEvent(e); } void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) { m_pDrawPad->tool()->mouseMoveEvent(e); } 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); if (drawRect.right() < clipRect.right()) { p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); } if (drawRect.bottom() < clipRect.bottom()) { p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); } } 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 @@ -28,26 +28,24 @@ class DrawPadCanvas : public QScrollView public: DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); ~DrawPadCanvas(); void load(QIODevice* ioDevice); void initialPage(); void save(QIODevice* ioDevice); void importPage(const QString& fileName); void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); - bool undoEnabled(); - bool redoEnabled(); bool goPreviousPageEnabled(); bool goNextPageEnabled(); Page* currentPage(); QList<Page> pages(); uint pagePosition(); uint pageCount(); void selectPage(Page* page); void selectPage(uint pagePosition); void backupPage(); @@ -60,27 +58,25 @@ public slots: void movePageDown(); void undo(); void redo(); void goFirstPage(); void goPreviousPage(); void goNextPage(); void goLastPage(); signals: void pagesChanged(); - void pageBackupsChanged(); protected: void contentsMousePressEvent(QMouseEvent* e); void contentsMouseReleaseEvent(QMouseEvent* e); void contentsMouseMoveEvent(QMouseEvent* e); void drawContents(QPainter* p, int cx, int cy, int cw, int ch); private: DrawPad* m_pDrawPad; QList<Page> m_pages; - QList<Page> m_pageBackups; }; #endif // DRAWPADCANVAS_H 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 @@ -23,54 +23,54 @@ EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) { m_mousePressed = false; m_polyline.resize(3); } EraseTool::~EraseTool() { } void EraseTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); } void EraseTool::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } void EraseTool::mouseMoveEvent(QMouseEvent* e) { if (m_mousePressed) { QPainter painter; QPen pen(Qt::white, m_pDrawPad->pen().width()); - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); painter.setPen(pen); m_polyline[2] = m_polyline[1]; m_polyline[1] = m_polyline[0]; m_polyline[0] = e->pos(); painter.drawPolyline(m_polyline); painter.end(); QRect r = m_polyline.boundingRect(); r = r.normalize(); r.setLeft(r.left() - m_pDrawPad->pen().width()); r.setTop(r.top() - m_pDrawPad->pen().width()); r.setRight(r.right() + m_pDrawPad->pen().width()); r.setBottom(r.bottom() + m_pDrawPad->pen().width()); QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 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()); m_pDrawPadCanvas->viewport()->update(viewportRect); } } 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 @@ -26,51 +26,51 @@ FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) { } FillTool::~FillTool() { } void FillTool::mousePressEvent(QMouseEvent* e) { int x = e->x(); int y = e->y(); - m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); + m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage(); m_fillRgb = m_pDrawPad->brush().color().rgb(); m_oldRgb = m_image.pixel(x, y); if (m_oldRgb != m_fillRgb) { + m_pDrawPadCanvas->backupPage(); + if (m_pDrawPad->antiAliasing()) { m_mask.create(m_image.width(), m_image.height(), 8, 2); m_mask.fill(0); fillMaskLine(x, y); for (int i = 0; i < m_image.width(); i++) { for (int j = 0; j < m_image.height(); j++) { if (m_mask.pixelIndex(i, j) == 1) { setInterpolatedPixel(i, j); } } } } else { fillLine(x, y); } - m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); + m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image); m_pDrawPadCanvas->viewport()->update(); - - m_pDrawPadCanvas->backupPage(); } } void FillTool::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) } void FillTool::mouseMoveEvent(QMouseEvent* e) { Q_UNUSED(e) } 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 @@ -4,56 +4,110 @@ * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "page.h" +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); } Page::Page(QString title, int w, int h) - : QPixmap(w, h) { m_title = title; m_lastModified = QDateTime::currentDateTime(); + m_pPixmap = new QPixmap(w, h); + + m_backHistory.setAutoDelete(true); + m_forwardHistory.setAutoDelete(true); } Page::Page(QString title, const QSize& size) - : QPixmap(size) { m_title = title; m_lastModified = QDateTime::currentDateTime(); + m_pPixmap = new QPixmap(size); + + m_backHistory.setAutoDelete(true); + m_forwardHistory.setAutoDelete(true); } Page::~Page() { + delete m_pPixmap; } QString Page::title() const { return m_title; } QDateTime Page::lastModified() const { return m_lastModified; } +QPixmap* Page::pixmap() const + +{ + return m_pPixmap; +} + void Page::setTitle(QString title) { m_title = title; } void Page::setLastModified(QDateTime lastModified) { m_lastModified = 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 @@ -5,37 +5,51 @@ * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PAGE_H #define PAGE_H -#include <qpixmap.h> +#include <qobject.h> #include <qdatetime.h> +#include <qlist.h> +#include <qpixmap.h> -class Page : public QPixmap +class Page : public QObject { public: Page(); Page(QString title, int w, int h); Page(QString title, const QSize& size); ~Page(); QString title() const; QDateTime lastModified() const; + QPixmap* pixmap() const; void setTitle(QString title); void setLastModified(QDateTime lastModified); + bool undoEnabled(); + bool redoEnabled(); + + void backup(); + void undo(); + void redo(); + private: QString m_title; QDateTime m_lastModified; + QPixmap* m_pPixmap; + + QList<QPixmap> m_backHistory; + QList<QPixmap> m_forwardHistory; }; #endif // PAGE_H 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 @@ -34,28 +34,28 @@ PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox); m_pTitleLineEdit = new QLineEdit(generalGroupBox); m_pTitleLineEdit->setText(page->title()); QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox); QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox); QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this); 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); QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); generalGroupBox->layout()->setSpacing(4); sizeGroupBox->layout()->setSpacing(4); QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2); QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); generalLayout->addWidget(titleLabel, 0, 0); generalLayout->addWidget(m_pTitleLineEdit, 0, 1); generalLayout->addWidget(dateLabel, 1, 0); generalLayout->addWidget(dateValueLabel, 1, 1); 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 @@ -24,53 +24,53 @@ PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) { m_mousePressed = false; m_polyline.resize(3); } PointTool::~PointTool() { } void PointTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); } void PointTool::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } void PointTool::mouseMoveEvent(QMouseEvent* e) { if (m_mousePressed) { m_polyline[2] = m_polyline[1]; m_polyline[1] = m_polyline[0]; m_polyline[0] = e->pos(); QRect r = m_polyline.boundingRect(); r = r.normalize(); r.setLeft(r.left() - m_pDrawPad->pen().width()); r.setTop(r.top() - m_pDrawPad->pen().width()); r.setRight(r.right() + m_pDrawPad->pen().width()); r.setBottom(r.bottom() + m_pDrawPad->pen().width()); QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); if (m_pDrawPad->antiAliasing()) { QPixmap areaPixmap(r.width(), r.height()); bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); QImage areaImage = areaPixmap.convertToImage(); QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); QPixmap bigAreaPixmap; bigAreaPixmap.convertFromImage(bigAreaImage); QPen bigAreaPen = m_pDrawPad->pen(); @@ -95,17 +95,17 @@ void PointTool::mouseMoveEvent(QMouseEvent* e) painter.drawPixmap(r.x(), r.y(), areaPixmap); } else { painter.setPen(m_pDrawPad->pen()); painter.drawPolyline(m_polyline); } painter.end(); QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 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()); m_pDrawPadCanvas->viewport()->update(viewportRect); } } 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 @@ -23,72 +23,72 @@ ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) { m_mousePressed = false; m_polyline.resize(3); } ShapeTool::~ShapeTool() { } void ShapeTool::mousePressEvent(QMouseEvent* e) { + m_pDrawPadCanvas->backupPage(); + m_mousePressed = true; m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); } void ShapeTool::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); drawFinalShape(painter); painter.end(); QRect r = m_polyline.boundingRect(); r = r.normalize(); r.setLeft(r.left() - m_pDrawPad->pen().width()); r.setTop(r.top() - m_pDrawPad->pen().width()); r.setRight(r.right() + m_pDrawPad->pen().width()); r.setBottom(r.bottom() + m_pDrawPad->pen().width()); QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 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()); m_pDrawPadCanvas->viewport()->update(viewportRect); m_mousePressed = false; - - m_pDrawPadCanvas->backupPage(); } void ShapeTool::mouseMoveEvent(QMouseEvent* e) { if (m_mousePressed) { m_polyline[0] = e->pos(); QPainter painter; - painter.begin(m_pDrawPadCanvas->currentPage()); + painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); drawTemporaryShape(painter); painter.end(); QRect r = m_polyline.boundingRect(); r = r.normalize(); r.setLeft(r.left() - m_pDrawPad->pen().width()); r.setTop(r.top() - m_pDrawPad->pen().width()); r.setRight(r.right() + m_pDrawPad->pen().width()); r.setBottom(r.bottom() + m_pDrawPad->pen().width()); QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 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()); m_pDrawPadCanvas->viewport()->update(viewportRect); m_polyline[1] = m_polyline[0]; } } 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 @@ -47,33 +47,33 @@ TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) { } TextTool::~TextTool() { } void TextTool::mousePressEvent(QMouseEvent* e) { TextToolDialog textToolDialog(m_pDrawPad); 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()); painter.drawText(e->x(), e->y(), textToolDialog.text()); painter.end(); m_pDrawPadCanvas->viewport()->update(); - - m_pDrawPadCanvas->backupPage(); } } void TextTool::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) } void TextTool::mouseMoveEvent(QMouseEvent* e) { Q_UNUSED(e) } 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 @@ -26,48 +26,48 @@ #include <qimage.h> #include <qlayout.h> #include <qmessagebox.h> #include <qtoolbutton.h> #define THUMBNAIL_SIZE 48 PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) : QListBoxItem(parent) { m_pPage = page; - QImage image = m_pPage->convertToImage(); + QImage image = m_pPage->pixmap()->convertToImage(); int previewWidth = THUMBNAIL_SIZE; int previewHeight = THUMBNAIL_SIZE; float widthScale = 1.0; float heightScale = 1.0; if (previewWidth < image.width()) { widthScale = (float)previewWidth / float(image.width()); } if (previewHeight < image.height()) { heightScale = (float)previewHeight / float(image.height()); } float scale = (widthScale < heightScale ? widthScale : heightScale); QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); m_thumbnail.convertFromImage(thumbnailImage); 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()); QColor baseColor = parent->colorGroup().base(); int h, s, v; baseColor.hsv(&h, &s, &v); if (v > 128) { m_alternateColor = baseColor.dark(115); } else if (baseColor != Qt::black) { m_alternateColor = baseColor.light(115); } else { m_alternateColor = QColor(32, 32, 32); |