-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 | |||
@@ -23,5 +23,7 @@ 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 | ||
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 | |||
@@ -43,2 +43,4 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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 | ||
@@ -73,3 +75,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -88,3 +90,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -96,3 +98,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -106,4 +108,14 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -111,3 +123,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -115,3 +127,3 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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); |
@@ -119,6 +131,6 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
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 | ||
@@ -163,2 +175,5 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
163 | emptyToolBar->setHorizontalStretchable(true); | 175 | emptyToolBar->setHorizontalStretchable(true); |
176 | emptyToolBar->addSeparator(); | ||
177 | |||
178 | // init draw parameters toolbar | ||
164 | 179 | ||
@@ -220,44 +235,2 @@ DrawPad::~DrawPad() | |||
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() |
@@ -383,3 +356,9 @@ void DrawPad::changeBrushColor(int index) | |||
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 | { |
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 | |||
@@ -41,11 +41,2 @@ public: | |||
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(); |
@@ -61,5 +52,6 @@ private slots: | |||
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; |
@@ -71,2 +63,5 @@ private: | |||
71 | 63 | ||
64 | QAction* m_pUndoAction; | ||
65 | QAction* m_pRedoAction; | ||
66 | |||
72 | QAction* m_pFirstPageAction; | 67 | QAction* m_pFirstPageAction; |
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 | |||
@@ -145,5 +145,7 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name | |||
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 | } |
@@ -166,9 +168,12 @@ void DrawPadCanvas::load(QIODevice* ioDevice) | |||
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(); |
@@ -184,3 +189,3 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
184 | 189 | ||
185 | QListIterator<QPixmap> bufferIterator(m_buffers); | 190 | QListIterator<QPixmap> bufferIterator(m_pages); |
186 | 191 | ||
@@ -223,3 +228,3 @@ QPixmap* DrawPadCanvas::currentPage() | |||
223 | { | 228 | { |
224 | return m_buffers.current(); | 229 | return m_pages.current(); |
225 | } | 230 | } |
@@ -228,8 +233,14 @@ 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 | } |
@@ -238,5 +249,10 @@ 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 | } |
@@ -245,3 +261,3 @@ void DrawPadCanvas::clearPage() | |||
245 | { | 261 | { |
246 | m_buffers.current()->fill(Qt::white); | 262 | m_pages.current()->fill(Qt::white); |
247 | repaint(); | 263 | repaint(); |
@@ -251,10 +267,26 @@ 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 | } |
@@ -263,3 +295,3 @@ bool DrawPadCanvas::goPreviousPageEnabled() | |||
263 | { | 295 | { |
264 | return (m_buffers.current() != m_buffers.getFirst()); | 296 | return (m_pages.current() != m_pages.getFirst()); |
265 | } | 297 | } |
@@ -268,3 +300,19 @@ 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 | } |
@@ -273,4 +321,9 @@ 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 | } |
@@ -279,4 +332,9 @@ 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 | } |
@@ -285,4 +343,9 @@ 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 | } |
@@ -291,4 +354,9 @@ 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 | } |
@@ -303,2 +371,15 @@ void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | |||
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 | } |
@@ -314,3 +395,3 @@ void DrawPadCanvas::resizeEvent(QResizeEvent* e) | |||
314 | 395 | ||
315 | QListIterator<QPixmap> bufferIterator(m_buffers); | 396 | QListIterator<QPixmap> bufferIterator(m_pages); |
316 | 397 | ||
@@ -336,3 +417,3 @@ void DrawPadCanvas::paintEvent(QPaintEvent* e) | |||
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 | } |
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 | |||
@@ -36,2 +36,4 @@ public: | |||
36 | 36 | ||
37 | bool undoEnabled(); | ||
38 | bool redoEnabled(); | ||
37 | bool goPreviousPageEnabled(); | 39 | bool goPreviousPageEnabled(); |
@@ -47,2 +49,5 @@ public slots: | |||
47 | 49 | ||
50 | void undo(); | ||
51 | void redo(); | ||
52 | |||
48 | void goFirstPage(); | 53 | void goFirstPage(); |
@@ -52,2 +57,6 @@ public slots: | |||
52 | 57 | ||
58 | signals: | ||
59 | void pagesChanged(); | ||
60 | void pageBackupsChanged(); | ||
61 | |||
53 | protected: | 62 | protected: |
@@ -61,3 +70,4 @@ 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 | }; |