summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawmode.h6
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp81
-rw-r--r--noncore/graphics/drawpad/drawpad.h17
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp135
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h12
5 files changed, 159 insertions, 92 deletions
diff --git a/noncore/graphics/drawpad/drawmode.h b/noncore/graphics/drawpad/drawmode.h
index d4ecadd..4e80fe2 100644
--- a/noncore/graphics/drawpad/drawmode.h
+++ b/noncore/graphics/drawpad/drawmode.h
@@ -21,9 +21,11 @@ class DrawPadCanvas;
class DrawMode : QObject
{
-public:
+protected:
DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
- ~DrawMode();
+
+public:
+ virtual ~DrawMode();
virtual void mousePressEvent(QMouseEvent* e) = 0;
virtual void mouseReleaseEvent(QMouseEvent* e) = 0;
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index 3c593b6..5cc2197 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -41,6 +41,8 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
// init members
m_pDrawPadCanvas = new DrawPadCanvas(this, this);
+ connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
+ connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
@@ -71,7 +73,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar);
QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this);
- connect(clearAllAction, SIGNAL(activated()), this, SLOT(clearAll()));
+ connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll()));
clearAllAction->addTo(toolsPopupMenu);
toolsPopupMenu->insertSeparator();
@@ -86,7 +88,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
QPEToolBar* pageToolBar = new QPEToolBar(this);
QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
- connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
+ connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage()));
newPageAction->addTo(pageToolBar);
QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
@@ -94,7 +96,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
clearPageAction->addTo(pageToolBar);
QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
- connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
+ connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage()));
deletePageAction->addTo(pageToolBar);
QPEToolBar* emptyToolBar = new QPEToolBar(this);
@@ -104,23 +106,33 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
QPEToolBar* navigationToolBar = new QPEToolBar(this);
+ m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
+ connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
+ m_pUndoAction->addTo(navigationToolBar);
+
+ m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
+ connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
+ m_pRedoAction->addTo(navigationToolBar);
+
+ updateUndoRedoToolButtons();
+
m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
- connect(m_pFirstPageAction, SIGNAL(activated()), this, SLOT(goFirstPage()));
+ connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
m_pFirstPageAction->addTo(navigationToolBar);
m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
- connect(m_pPreviousPageAction, SIGNAL(activated()), this, SLOT(goPreviousPage()));
+ connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage()));
m_pPreviousPageAction->addTo(navigationToolBar);
m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
- connect(m_pNextPageAction, SIGNAL(activated()), this, SLOT(goNextPage()));
+ connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage()));
m_pNextPageAction->addTo(navigationToolBar);
m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
- connect(m_pLastPageAction, SIGNAL(activated()), this, SLOT(goLastPage()));
+ connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
m_pLastPageAction->addTo(navigationToolBar);
- updateNavigationToolBar();
+ updateNavigationToolButtons();
// init draw mode toolbar
@@ -161,6 +173,9 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
emptyToolBar = new QPEToolBar(this);
emptyToolBar->setHorizontalStretchable(true);
+ emptyToolBar->addSeparator();
+
+ // init draw parameters toolbar
QPEToolBar* drawParametersToolBar = new QPEToolBar(this);
@@ -218,48 +233,6 @@ DrawPad::~DrawPad()
}
}
-void DrawPad::clearAll()
-{
- m_pDrawPadCanvas->clearAll();
- updateNavigationToolBar();
-}
-
-void DrawPad::newPage()
-{
- m_pDrawPadCanvas->newPage();
- updateNavigationToolBar();
-}
-
-void DrawPad::deletePage()
-{
- m_pDrawPadCanvas->deletePage();
- updateNavigationToolBar();
-}
-
-void DrawPad::goFirstPage()
-{
- m_pDrawPadCanvas->goFirstPage();
- updateNavigationToolBar();
-}
-
-void DrawPad::goPreviousPage()
-{
- m_pDrawPadCanvas->goPreviousPage();
- updateNavigationToolBar();
-}
-
-void DrawPad::goNextPage()
-{
- m_pDrawPadCanvas->goNextPage();
- updateNavigationToolBar();
-}
-
-void DrawPad::goLastPage()
-{
- m_pDrawPadCanvas->goLastPage();
- updateNavigationToolBar();
-}
-
void DrawPad::setPointDrawMode()
{
if (m_pDrawMode) {
@@ -381,7 +354,13 @@ void DrawPad::changeBrushColor(int index)
painter.end();
}
-void DrawPad::updateNavigationToolBar()
+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());
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 0ece408..ee81ddf 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -39,15 +39,6 @@ public:
QBrush brush() { return m_brush; }
private slots:
- void clearAll();
- void newPage();
- void deletePage();
-
- void goFirstPage();
- void goPreviousPage();
- void goNextPage();
- void goLastPage();
-
void setPointDrawMode();
void setLineDrawMode();
void setRectangleDrawMode();
@@ -59,9 +50,10 @@ private slots:
void changePenColor(int index);
void changeBrushColor(int index);
-private:
- void updateNavigationToolBar();
+ void updateUndoRedoToolButtons();
+ void updateNavigationToolButtons();
+private:
DrawPadCanvas* m_pDrawPadCanvas;
QArray<QColor> m_colors;
@@ -69,6 +61,9 @@ private:
QPen m_pen;
QBrush m_brush;
+ QAction* m_pUndoAction;
+ QAction* m_pRedoAction;
+
QAction* m_pFirstPageAction;
QAction* m_pPreviousPageAction;
QAction* m_pNextPageAction;
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
@@ -143,9 +143,11 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name
setBackgroundMode(QWidget::PaletteBase);
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())));
}
DrawPadCanvas::~DrawPadCanvas()
@@ -164,13 +166,16 @@ void DrawPadCanvas::load(QIODevice* ioDevice)
xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
xmlSimpleReader.parse(xmlInputSource);
- 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();
}
@@ -182,7 +187,7 @@ void DrawPadCanvas::save(QIODevice* ioDevice)
textStream << "<drawpad>" << endl;
textStream << " <images>" << endl;
- QListIterator<QPixmap> bufferIterator(m_buffers);
+ QListIterator<QPixmap> bufferIterator(m_pages);
for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
textStream << " <image>" << endl;
@@ -221,76 +226,139 @@ void DrawPadCanvas::save(QIODevice* ioDevice)
QPixmap* DrawPadCanvas::currentPage()
{
- return m_buffers.current();
+ return m_pages.current();
}
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();
}
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();
}
void DrawPadCanvas::clearPage()
{
- m_buffers.current()->fill(Qt::white);
+ m_pages.current()->fill(Qt::white);
repaint();
}
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());
}
bool DrawPadCanvas::goPreviousPageEnabled()
{
- return (m_buffers.current() != m_buffers.getFirst());
+ return (m_pages.current() != m_pages.getFirst());
}
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();
}
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();
}
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();
}
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();
}
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();
}
void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
@@ -301,6 +369,19 @@ void DrawPadCanvas::mousePressEvent(QMouseEvent* e)
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();
}
void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e)
@@ -312,7 +393,7 @@ void DrawPadCanvas::resizeEvent(QResizeEvent* e)
{
QWidget::resizeEvent(e);
- QListIterator<QPixmap> bufferIterator(m_buffers);
+ QListIterator<QPixmap> bufferIterator(m_pages);
for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width();
@@ -334,6 +415,6 @@ void DrawPadCanvas::paintEvent(QPaintEvent* e)
for (uint i = 0; i < rects.count(); i++) {
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());
}
}
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index 2ec9298..eddcb43 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -34,6 +34,8 @@ public:
void load(QIODevice* ioDevice);
void save(QIODevice* ioDevice);
+ bool undoEnabled();
+ bool redoEnabled();
bool goPreviousPageEnabled();
bool goNextPageEnabled();
@@ -45,11 +47,18 @@ public slots:
void clearPage();
void deletePage();
+ void undo();
+ void redo();
+
void goFirstPage();
void goPreviousPage();
void goNextPage();
void goLastPage();
+signals:
+ void pagesChanged();
+ void pageBackupsChanged();
+
protected:
void mousePressEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
@@ -59,7 +68,8 @@ protected:
private:
DrawPad* m_pDrawPad;
- QList<QPixmap> m_buffers;
+ QList<QPixmap> m_pages;
+ QList<QPixmap> m_pageBackups;
};
#endif // DRAWPADCANVAS_H