-rw-r--r-- | noncore/graphics/drawpad/drawmode.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 81 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 17 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 135 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 12 |
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; | |||
21 | 21 | ||
22 | class DrawMode : QObject | 22 | class DrawMode : QObject |
23 | { | 23 | { |
24 | public: | 24 | protected: |
25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
26 | ~DrawMode(); | 26 | |
27 | public: | ||
28 | virtual ~DrawMode(); | ||
27 | 29 | ||
28 | virtual void mousePressEvent(QMouseEvent* e) = 0; | 30 | virtual void mousePressEvent(QMouseEvent* e) = 0; |
29 | virtual void mouseReleaseEvent(QMouseEvent* e) = 0; | 31 | 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) | |||
41 | // init members | 41 | // init members |
42 | 42 | ||
43 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 43 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
44 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | ||
45 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | ||
44 | 46 | ||
45 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 47 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
46 | 48 | ||
@@ -71,7 +73,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
71 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 73 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
72 | 74 | ||
73 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); | 75 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); |
74 | connect(clearAllAction, SIGNAL(activated()), this, SLOT(clearAll())); | 76 | connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); |
75 | clearAllAction->addTo(toolsPopupMenu); | 77 | clearAllAction->addTo(toolsPopupMenu); |
76 | 78 | ||
77 | toolsPopupMenu->insertSeparator(); | 79 | toolsPopupMenu->insertSeparator(); |
@@ -86,7 +88,7 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
86 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 88 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
87 | 89 | ||
88 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 90 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
89 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); | 91 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
90 | newPageAction->addTo(pageToolBar); | 92 | newPageAction->addTo(pageToolBar); |
91 | 93 | ||
92 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 94 | 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) | |||
94 | clearPageAction->addTo(pageToolBar); | 96 | clearPageAction->addTo(pageToolBar); |
95 | 97 | ||
96 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 98 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
97 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); | 99 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); |
98 | deletePageAction->addTo(pageToolBar); | 100 | deletePageAction->addTo(pageToolBar); |
99 | 101 | ||
100 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 102 | QPEToolBar* emptyToolBar = new QPEToolBar(this); |
@@ -104,23 +106,33 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
104 | 106 | ||
105 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 107 | QPEToolBar* navigationToolBar = new QPEToolBar(this); |
106 | 108 | ||
109 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); | ||
110 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | ||
111 | m_pUndoAction->addTo(navigationToolBar); | ||
112 | |||
113 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); | ||
114 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); | ||
115 | m_pRedoAction->addTo(navigationToolBar); | ||
116 | |||
117 | updateUndoRedoToolButtons(); | ||
118 | |||
107 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); | 119 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); |
108 | connect(m_pFirstPageAction, SIGNAL(activated()), this, SLOT(goFirstPage())); | 120 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); |
109 | m_pFirstPageAction->addTo(navigationToolBar); | 121 | m_pFirstPageAction->addTo(navigationToolBar); |
110 | 122 | ||
111 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); | 123 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); |
112 | connect(m_pPreviousPageAction, SIGNAL(activated()), this, SLOT(goPreviousPage())); | 124 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); |
113 | m_pPreviousPageAction->addTo(navigationToolBar); | 125 | m_pPreviousPageAction->addTo(navigationToolBar); |
114 | 126 | ||
115 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); | 127 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); |
116 | connect(m_pNextPageAction, SIGNAL(activated()), this, SLOT(goNextPage())); | 128 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); |
117 | m_pNextPageAction->addTo(navigationToolBar); | 129 | m_pNextPageAction->addTo(navigationToolBar); |
118 | 130 | ||
119 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); | 131 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); |
120 | connect(m_pLastPageAction, SIGNAL(activated()), this, SLOT(goLastPage())); | 132 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); |
121 | m_pLastPageAction->addTo(navigationToolBar); | 133 | m_pLastPageAction->addTo(navigationToolBar); |
122 | 134 | ||
123 | updateNavigationToolBar(); | 135 | updateNavigationToolButtons(); |
124 | 136 | ||
125 | // init draw mode toolbar | 137 | // init draw mode toolbar |
126 | 138 | ||
@@ -161,6 +173,9 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
161 | 173 | ||
162 | emptyToolBar = new QPEToolBar(this); | 174 | emptyToolBar = new QPEToolBar(this); |
163 | emptyToolBar->setHorizontalStretchable(true); | 175 | emptyToolBar->setHorizontalStretchable(true); |
176 | emptyToolBar->addSeparator(); | ||
177 | |||
178 | // init draw parameters toolbar | ||
164 | 179 | ||
165 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 180 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
166 | 181 | ||
@@ -218,48 +233,6 @@ DrawPad::~DrawPad() | |||
218 | } | 233 | } |
219 | } | 234 | } |
220 | 235 | ||
221 | void DrawPad::clearAll() | ||
222 | { | ||
223 | m_pDrawPadCanvas->clearAll(); | ||
224 | updateNavigationToolBar(); | ||
225 | } | ||
226 | |||
227 | void DrawPad::newPage() | ||
228 | { | ||
229 | m_pDrawPadCanvas->newPage(); | ||
230 | updateNavigationToolBar(); | ||
231 | } | ||
232 | |||
233 | void DrawPad::deletePage() | ||
234 | { | ||
235 | m_pDrawPadCanvas->deletePage(); | ||
236 | updateNavigationToolBar(); | ||
237 | } | ||
238 | |||
239 | void DrawPad::goFirstPage() | ||
240 | { | ||
241 | m_pDrawPadCanvas->goFirstPage(); | ||
242 | updateNavigationToolBar(); | ||
243 | } | ||
244 | |||
245 | void DrawPad::goPreviousPage() | ||
246 | { | ||
247 | m_pDrawPadCanvas->goPreviousPage(); | ||
248 | updateNavigationToolBar(); | ||
249 | } | ||
250 | |||
251 | void DrawPad::goNextPage() | ||
252 | { | ||
253 | m_pDrawPadCanvas->goNextPage(); | ||
254 | updateNavigationToolBar(); | ||
255 | } | ||
256 | |||
257 | void DrawPad::goLastPage() | ||
258 | { | ||
259 | m_pDrawPadCanvas->goLastPage(); | ||
260 | updateNavigationToolBar(); | ||
261 | } | ||
262 | |||
263 | void DrawPad::setPointDrawMode() | 236 | void DrawPad::setPointDrawMode() |
264 | { | 237 | { |
265 | if (m_pDrawMode) { | 238 | if (m_pDrawMode) { |
@@ -381,7 +354,13 @@ void DrawPad::changeBrushColor(int index) | |||
381 | painter.end(); | 354 | painter.end(); |
382 | } | 355 | } |
383 | 356 | ||
384 | void DrawPad::updateNavigationToolBar() | 357 | void DrawPad::updateUndoRedoToolButtons() |
358 | { | ||
359 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); | ||
360 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); | ||
361 | } | ||
362 | |||
363 | void DrawPad::updateNavigationToolButtons() | ||
385 | { | 364 | { |
386 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 365 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
387 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 366 | 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: | |||
39 | QBrush brush() { return m_brush; } | 39 | QBrush brush() { return m_brush; } |
40 | 40 | ||
41 | private slots: | 41 | private slots: |
42 | void clearAll(); | ||
43 | void newPage(); | ||
44 | void deletePage(); | ||
45 | |||
46 | void goFirstPage(); | ||
47 | void goPreviousPage(); | ||
48 | void goNextPage(); | ||
49 | void goLastPage(); | ||
50 | |||
51 | void setPointDrawMode(); | 42 | void setPointDrawMode(); |
52 | void setLineDrawMode(); | 43 | void setLineDrawMode(); |
53 | void setRectangleDrawMode(); | 44 | void setRectangleDrawMode(); |
@@ -59,9 +50,10 @@ private slots: | |||
59 | void changePenColor(int index); | 50 | void changePenColor(int index); |
60 | void changeBrushColor(int index); | 51 | void changeBrushColor(int index); |
61 | 52 | ||
62 | private: | 53 | void updateUndoRedoToolButtons(); |
63 | void updateNavigationToolBar(); | 54 | void updateNavigationToolButtons(); |
64 | 55 | ||
56 | private: | ||
65 | DrawPadCanvas* m_pDrawPadCanvas; | 57 | DrawPadCanvas* m_pDrawPadCanvas; |
66 | QArray<QColor> m_colors; | 58 | QArray<QColor> m_colors; |
67 | 59 | ||
@@ -69,6 +61,9 @@ private: | |||
69 | QPen m_pen; | 61 | QPen m_pen; |
70 | QBrush m_brush; | 62 | QBrush m_brush; |
71 | 63 | ||
64 | QAction* m_pUndoAction; | ||
65 | QAction* m_pRedoAction; | ||
66 | |||
72 | QAction* m_pFirstPageAction; | 67 | QAction* m_pFirstPageAction; |
73 | QAction* m_pPreviousPageAction; | 68 | QAction* m_pPreviousPageAction; |
74 | QAction* m_pNextPageAction; | 69 | 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 | |||
143 | setBackgroundMode(QWidget::PaletteBase); | 143 | setBackgroundMode(QWidget::PaletteBase); |
144 | 144 | ||
145 | m_pDrawPad = drawPad; | 145 | m_pDrawPad = drawPad; |
146 | m_buffers.setAutoDelete(true); | 146 | m_pages.setAutoDelete(true); |
147 | m_buffers.append(new QPixmap(width(), height())); | 147 | m_pages.append(new QPixmap(width(), height())); |
148 | m_buffers.current()->fill(Qt::white); | 148 | m_pages.current()->fill(Qt::white); |
149 | m_pageBackups.setAutoDelete(true); | ||
150 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
149 | } | 151 | } |
150 | 152 | ||
151 | DrawPadCanvas::~DrawPadCanvas() | 153 | DrawPadCanvas::~DrawPadCanvas() |
@@ -164,13 +166,16 @@ void DrawPadCanvas::load(QIODevice* ioDevice) | |||
164 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 166 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
165 | xmlSimpleReader.parse(xmlInputSource); | 167 | xmlSimpleReader.parse(xmlInputSource); |
166 | 168 | ||
167 | m_buffers = drawPadCanvasXmlHandler.pixmaps(); | 169 | m_pages = drawPadCanvasXmlHandler.pixmaps(); |
168 | 170 | ||
169 | if (m_buffers.isEmpty()) { | 171 | if (m_pages.isEmpty()) { |
170 | m_buffers.append(new QPixmap(width(), height())); | 172 | m_pages.append(new QPixmap(width(), height())); |
171 | m_buffers.current()->fill(Qt::white); | 173 | m_pages.current()->fill(Qt::white); |
172 | } | 174 | } |
173 | 175 | ||
176 | m_pageBackups.clear(); | ||
177 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
178 | |||
174 | repaint(); | 179 | repaint(); |
175 | } | 180 | } |
176 | 181 | ||
@@ -182,7 +187,7 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
182 | textStream << "<drawpad>" << endl; | 187 | textStream << "<drawpad>" << endl; |
183 | textStream << " <images>" << endl; | 188 | textStream << " <images>" << endl; |
184 | 189 | ||
185 | QListIterator<QPixmap> bufferIterator(m_buffers); | 190 | QListIterator<QPixmap> bufferIterator(m_pages); |
186 | 191 | ||
187 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 192 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
188 | textStream << " <image>" << endl; | 193 | textStream << " <image>" << endl; |
@@ -221,76 +226,139 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
221 | 226 | ||
222 | QPixmap* DrawPadCanvas::currentPage() | 227 | QPixmap* DrawPadCanvas::currentPage() |
223 | { | 228 | { |
224 | return m_buffers.current(); | 229 | return m_pages.current(); |
225 | } | 230 | } |
226 | 231 | ||
227 | void DrawPadCanvas::clearAll() | 232 | void DrawPadCanvas::clearAll() |
228 | { | 233 | { |
229 | m_buffers.clear(); | 234 | m_pages.clear(); |
235 | |||
236 | m_pages.append(new QPixmap(width(), height())); | ||
237 | m_pages.current()->fill(Qt::white); | ||
230 | 238 | ||
231 | m_buffers.append(new QPixmap(width(), height())); | 239 | m_pageBackups.clear(); |
232 | m_buffers.current()->fill(Qt::white); | 240 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
233 | 241 | ||
234 | repaint(); | 242 | repaint(); |
243 | |||
244 | emit pagesChanged(); | ||
245 | emit pageBackupsChanged(); | ||
235 | } | 246 | } |
236 | 247 | ||
237 | void DrawPadCanvas::newPage() | 248 | void DrawPadCanvas::newPage() |
238 | { | 249 | { |
239 | m_buffers.insert(m_buffers.at() + 1, new QPixmap(width(), height())); | 250 | m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height())); |
240 | m_buffers.current()->fill(Qt::white); | 251 | m_pages.current()->fill(Qt::white); |
252 | m_pageBackups.clear(); | ||
253 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
241 | repaint(); | 254 | repaint(); |
255 | |||
256 | emit pagesChanged(); | ||
257 | emit pageBackupsChanged(); | ||
242 | } | 258 | } |
243 | 259 | ||
244 | void DrawPadCanvas::clearPage() | 260 | void DrawPadCanvas::clearPage() |
245 | { | 261 | { |
246 | m_buffers.current()->fill(Qt::white); | 262 | m_pages.current()->fill(Qt::white); |
247 | repaint(); | 263 | repaint(); |
248 | } | 264 | } |
249 | 265 | ||
250 | void DrawPadCanvas::deletePage() | 266 | void DrawPadCanvas::deletePage() |
251 | { | 267 | { |
252 | m_buffers.remove(m_buffers.current()); | 268 | m_pages.remove(m_pages.current()); |
253 | 269 | ||
254 | if (m_buffers.isEmpty()) { | 270 | if (m_pages.isEmpty()) { |
255 | m_buffers.append(new QPixmap(width(), height())); | 271 | m_pages.append(new QPixmap(width(), height())); |
256 | m_buffers.current()->fill(Qt::white); | 272 | m_pages.current()->fill(Qt::white); |
257 | } | 273 | } |
258 | 274 | ||
275 | m_pageBackups.clear(); | ||
276 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
277 | |||
259 | repaint(); | 278 | repaint(); |
279 | |||
280 | emit pagesChanged(); | ||
281 | emit pageBackupsChanged(); | ||
282 | } | ||
283 | |||
284 | bool DrawPadCanvas::undoEnabled() | ||
285 | { | ||
286 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | ||
287 | } | ||
288 | |||
289 | bool DrawPadCanvas::redoEnabled() | ||
290 | { | ||
291 | return (m_pageBackups.current() != m_pageBackups.getLast()); | ||
260 | } | 292 | } |
261 | 293 | ||
262 | bool DrawPadCanvas::goPreviousPageEnabled() | 294 | bool DrawPadCanvas::goPreviousPageEnabled() |
263 | { | 295 | { |
264 | return (m_buffers.current() != m_buffers.getFirst()); | 296 | return (m_pages.current() != m_pages.getFirst()); |
265 | } | 297 | } |
266 | 298 | ||
267 | bool DrawPadCanvas::goNextPageEnabled() | 299 | bool DrawPadCanvas::goNextPageEnabled() |
268 | { | 300 | { |
269 | return (m_buffers.current() != m_buffers.getLast()); | 301 | return (m_pages.current() != m_pages.getLast()); |
302 | } | ||
303 | |||
304 | void DrawPadCanvas::undo() | ||
305 | { | ||
306 | *(m_pages.current()) = *(m_pageBackups.prev()); | ||
307 | repaint(); | ||
308 | |||
309 | emit pageBackupsChanged(); | ||
310 | } | ||
311 | |||
312 | void DrawPadCanvas::redo() | ||
313 | { | ||
314 | *(m_pages.current()) = *(m_pageBackups.next()); | ||
315 | repaint(); | ||
316 | |||
317 | emit pageBackupsChanged(); | ||
270 | } | 318 | } |
271 | 319 | ||
272 | void DrawPadCanvas::goFirstPage() | 320 | void DrawPadCanvas::goFirstPage() |
273 | { | 321 | { |
274 | m_buffers.first(); | 322 | m_pages.first(); |
323 | m_pageBackups.clear(); | ||
324 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
275 | repaint(); | 325 | repaint(); |
326 | |||
327 | emit pagesChanged(); | ||
328 | emit pageBackupsChanged(); | ||
276 | } | 329 | } |
277 | 330 | ||
278 | void DrawPadCanvas::goPreviousPage() | 331 | void DrawPadCanvas::goPreviousPage() |
279 | { | 332 | { |
280 | m_buffers.prev(); | 333 | m_pages.prev(); |
334 | m_pageBackups.clear(); | ||
335 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
281 | repaint(); | 336 | repaint(); |
337 | |||
338 | emit pagesChanged(); | ||
339 | emit pageBackupsChanged(); | ||
282 | } | 340 | } |
283 | 341 | ||
284 | void DrawPadCanvas::goNextPage() | 342 | void DrawPadCanvas::goNextPage() |
285 | { | 343 | { |
286 | m_buffers.next(); | 344 | m_pages.next(); |
345 | m_pageBackups.clear(); | ||
346 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
287 | repaint(); | 347 | repaint(); |
348 | |||
349 | emit pagesChanged(); | ||
350 | emit pageBackupsChanged(); | ||
288 | } | 351 | } |
289 | 352 | ||
290 | void DrawPadCanvas::goLastPage() | 353 | void DrawPadCanvas::goLastPage() |
291 | { | 354 | { |
292 | m_buffers.last(); | 355 | m_pages.last(); |
356 | m_pageBackups.clear(); | ||
357 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
293 | repaint(); | 358 | repaint(); |
359 | |||
360 | emit pagesChanged(); | ||
361 | emit pageBackupsChanged(); | ||
294 | } | 362 | } |
295 | 363 | ||
296 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) | 364 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) |
@@ -301,6 +369,19 @@ void DrawPadCanvas::mousePressEvent(QMouseEvent* e) | |||
301 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | 369 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) |
302 | { | 370 | { |
303 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); | 371 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); |
372 | |||
373 | QPixmap* currentBackup = m_pageBackups.current(); | ||
374 | while (m_pageBackups.last() != currentBackup) { | ||
375 | m_pageBackups.removeLast(); | ||
376 | } | ||
377 | |||
378 | while (m_pageBackups.count() >= (5 + 1)) { | ||
379 | m_pageBackups.removeFirst(); | ||
380 | } | ||
381 | |||
382 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
383 | |||
384 | emit pageBackupsChanged(); | ||
304 | } | 385 | } |
305 | 386 | ||
306 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) | 387 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) |
@@ -312,7 +393,7 @@ void DrawPadCanvas::resizeEvent(QResizeEvent* e) | |||
312 | { | 393 | { |
313 | QWidget::resizeEvent(e); | 394 | QWidget::resizeEvent(e); |
314 | 395 | ||
315 | QListIterator<QPixmap> bufferIterator(m_buffers); | 396 | QListIterator<QPixmap> bufferIterator(m_pages); |
316 | 397 | ||
317 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 398 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
318 | int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width(); | 399 | int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width(); |
@@ -334,6 +415,6 @@ void DrawPadCanvas::paintEvent(QPaintEvent* e) | |||
334 | 415 | ||
335 | for (uint i = 0; i < rects.count(); i++) { | 416 | for (uint i = 0; i < rects.count(); i++) { |
336 | QRect r = rects[i]; | 417 | QRect r = rects[i]; |
337 | bitBlt(this, r.x(), r.y(), m_buffers.current(), r.x(), r.y(), r.width(), r.height()); | 418 | bitBlt(this, r.x(), r.y(), m_pages.current(), r.x(), r.y(), r.width(), r.height()); |
338 | } | 419 | } |
339 | } | 420 | } |
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: | |||
34 | void load(QIODevice* ioDevice); | 34 | void load(QIODevice* ioDevice); |
35 | void save(QIODevice* ioDevice); | 35 | void save(QIODevice* ioDevice); |
36 | 36 | ||
37 | bool undoEnabled(); | ||
38 | bool redoEnabled(); | ||
37 | bool goPreviousPageEnabled(); | 39 | bool goPreviousPageEnabled(); |
38 | bool goNextPageEnabled(); | 40 | bool goNextPageEnabled(); |
39 | 41 | ||
@@ -45,11 +47,18 @@ public slots: | |||
45 | void clearPage(); | 47 | void clearPage(); |
46 | void deletePage(); | 48 | void deletePage(); |
47 | 49 | ||
50 | void undo(); | ||
51 | void redo(); | ||
52 | |||
48 | void goFirstPage(); | 53 | void goFirstPage(); |
49 | void goPreviousPage(); | 54 | void goPreviousPage(); |
50 | void goNextPage(); | 55 | void goNextPage(); |
51 | void goLastPage(); | 56 | void goLastPage(); |
52 | 57 | ||
58 | signals: | ||
59 | void pagesChanged(); | ||
60 | void pageBackupsChanged(); | ||
61 | |||
53 | protected: | 62 | protected: |
54 | void mousePressEvent(QMouseEvent* e); | 63 | void mousePressEvent(QMouseEvent* e); |
55 | void mouseReleaseEvent(QMouseEvent* e); | 64 | void mouseReleaseEvent(QMouseEvent* e); |
@@ -59,7 +68,8 @@ protected: | |||
59 | 68 | ||
60 | private: | 69 | private: |
61 | DrawPad* m_pDrawPad; | 70 | DrawPad* m_pDrawPad; |
62 | QList<QPixmap> m_buffers; | 71 | QList<QPixmap> m_pages; |
72 | QList<QPixmap> m_pageBackups; | ||
63 | }; | 73 | }; |
64 | 74 | ||
65 | #endif // DRAWPADCANVAS_H | 75 | #endif // DRAWPADCANVAS_H |