Diffstat (limited to 'noncore/graphics/drawpad/drawpadcanvas.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 9f1e50b..79bef35 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -6,79 +6,79 @@ | |||
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "drawpadcanvas.h" | 14 | #include "drawpadcanvas.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "newpagedialog.h" | 17 | #include "newpagedialog.h" |
18 | #include "page.h" | ||
18 | #include "tool.h" | 19 | #include "tool.h" |
19 | 20 | ||
20 | #include <qpe/applnk.h> | 21 | #include <qpe/applnk.h> |
21 | #include <qpe/filemanager.h> | 22 | #include <qpe/filemanager.h> |
22 | #include <qpe/mimetype.h> | 23 | #include <qpe/mimetype.h> |
23 | 24 | ||
24 | #include <qbuffer.h> | 25 | #include <qbuffer.h> |
25 | #include <qimage.h> | 26 | #include <qimage.h> |
26 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
27 | #include <qpainter.h> | 28 | #include <qpainter.h> |
28 | #include <qpixmap.h> | ||
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qxml.h> | 31 | #include <qxml.h> |
32 | 32 | ||
33 | #include <zlib.h> | 33 | #include <zlib.h> |
34 | 34 | ||
35 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 35 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | DrawPadCanvasXmlHandler(); | 38 | DrawPadCanvasXmlHandler(); |
39 | ~DrawPadCanvasXmlHandler(); | 39 | ~DrawPadCanvasXmlHandler(); |
40 | 40 | ||
41 | QList<QPixmap> pixmaps(); | 41 | QList<Page> pages(); |
42 | 42 | ||
43 | bool startElement(const QString& namespaceURI, const QString& localName, | 43 | bool startElement(const QString& namespaceURI, const QString& localName, |
44 | const QString& qName, const QXmlAttributes& atts); | 44 | const QString& qName, const QXmlAttributes& atts); |
45 | bool endElement(const QString& namespaceURI, const QString& localName, | 45 | bool endElement(const QString& namespaceURI, const QString& localName, |
46 | const QString& qName); | 46 | const QString& qName); |
47 | bool characters(const QString& ch); | 47 | bool characters(const QString& ch); |
48 | 48 | ||
49 | private: | 49 | private: |
50 | enum State { | 50 | enum State { |
51 | Unknown, | 51 | Unknown, |
52 | InData | 52 | InData |
53 | }; | 53 | }; |
54 | 54 | ||
55 | State m_state; | 55 | State m_state; |
56 | ulong m_dataLenght; | 56 | ulong m_dataLenght; |
57 | QString m_dataFormat; | 57 | QString m_dataFormat; |
58 | QList<QPixmap> m_pixmaps; | 58 | QList<Page> m_pages; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
62 | { | 62 | { |
63 | m_state = Unknown; | 63 | m_state = Unknown; |
64 | } | 64 | } |
65 | 65 | ||
66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 70 | QList<Page> DrawPadCanvasXmlHandler::pages() |
71 | { | 71 | { |
72 | return m_pixmaps; | 72 | return m_pages; |
73 | } | 73 | } |
74 | 74 | ||
75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
76 | const QString& qName, const QXmlAttributes& atts) | 76 | const QString& qName, const QXmlAttributes& atts) |
77 | { | 77 | { |
78 | Q_CONST_UNUSED(namespaceURI) | 78 | Q_CONST_UNUSED(namespaceURI) |
79 | Q_CONST_UNUSED(localName) | 79 | Q_CONST_UNUSED(localName) |
80 | 80 | ||
81 | if (qName.compare("data") == 0) { | 81 | if (qName.compare("data") == 0) { |
82 | m_state = InData; | 82 | m_state = InData; |
83 | m_dataLenght = atts.value("length").toULong(); | 83 | m_dataLenght = atts.value("length").toULong(); |
84 | m_dataFormat = atts.value("format"); | 84 | m_dataFormat = atts.value("format"); |
@@ -138,27 +138,27 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) | |||
138 | if (m_dataLenght < ch.length() * 5) { | 138 | if (m_dataLenght < ch.length() * 5) { |
139 | m_dataLenght = ch.length() * 5; | 139 | m_dataLenght = ch.length() * 5; |
140 | } | 140 | } |
141 | 141 | ||
142 | QByteArray byteArrayUnzipped(m_dataLenght); | 142 | QByteArray byteArrayUnzipped(m_dataLenght); |
143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
144 | 144 | ||
145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); | 145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); |
146 | } else { | 146 | } else { |
147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); | 147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); |
148 | } | 148 | } |
149 | 149 | ||
150 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 150 | Page* page = new Page(image.width(), image.height()); |
151 | pixmap->convertFromImage(image); | 151 | page->convertFromImage(image); |
152 | m_pixmaps.append(pixmap); | 152 | m_pages.append(page); |
153 | } | 153 | } |
154 | 154 | ||
155 | return true; | 155 | return true; |
156 | } | 156 | } |
157 | 157 | ||
158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
159 | : QScrollView(parent, name) | 159 | : QScrollView(parent, name) |
160 | { | 160 | { |
161 | m_pDrawPad = drawPad; | 161 | m_pDrawPad = drawPad; |
162 | m_pages.setAutoDelete(true); | 162 | m_pages.setAutoDelete(true); |
163 | m_pageBackups.setAutoDelete(true); | 163 | m_pageBackups.setAutoDelete(true); |
164 | 164 | ||
@@ -172,65 +172,65 @@ DrawPadCanvas::~DrawPadCanvas() | |||
172 | void DrawPadCanvas::load(QIODevice* ioDevice) | 172 | void DrawPadCanvas::load(QIODevice* ioDevice) |
173 | { | 173 | { |
174 | QTextStream textStream(ioDevice); | 174 | QTextStream textStream(ioDevice); |
175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
176 | 176 | ||
177 | QXmlInputSource xmlInputSource(textStream); | 177 | QXmlInputSource xmlInputSource(textStream); |
178 | QXmlSimpleReader xmlSimpleReader; | 178 | QXmlSimpleReader xmlSimpleReader; |
179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; | 179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; |
180 | 180 | ||
181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
182 | xmlSimpleReader.parse(xmlInputSource); | 182 | xmlSimpleReader.parse(xmlInputSource); |
183 | 183 | ||
184 | m_pages = drawPadCanvasXmlHandler.pixmaps(); | 184 | m_pages = drawPadCanvasXmlHandler.pages(); |
185 | 185 | ||
186 | if (m_pages.isEmpty()) { | 186 | if (m_pages.isEmpty()) { |
187 | m_pages.append(new QPixmap(contentsRect().size())); | 187 | m_pages.append(new Page(contentsRect().size())); |
188 | m_pages.current()->fill(Qt::white); | 188 | m_pages.current()->fill(Qt::white); |
189 | } | 189 | } |
190 | 190 | ||
191 | m_pageBackups.clear(); | 191 | m_pageBackups.clear(); |
192 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 192 | m_pageBackups.append(new Page(*(m_pages.current()))); |
193 | 193 | ||
194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
195 | viewport()->update(); | 195 | viewport()->update(); |
196 | 196 | ||
197 | emit pagesChanged(); | 197 | emit pagesChanged(); |
198 | emit pageBackupsChanged(); | 198 | emit pageBackupsChanged(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void DrawPadCanvas::initialPage() | 201 | void DrawPadCanvas::initialPage() |
202 | { | 202 | { |
203 | m_pages.append(new QPixmap(236, 232)); | 203 | m_pages.append(new Page(236, 232)); |
204 | m_pages.current()->fill(Qt::white); | 204 | m_pages.current()->fill(Qt::white); |
205 | 205 | ||
206 | m_pageBackups.clear(); | 206 | m_pageBackups.clear(); |
207 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 207 | m_pageBackups.append(new Page(*(m_pages.current()))); |
208 | 208 | ||
209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
210 | viewport()->update(); | 210 | viewport()->update(); |
211 | 211 | ||
212 | emit pagesChanged(); | 212 | emit pagesChanged(); |
213 | emit pageBackupsChanged(); | 213 | emit pageBackupsChanged(); |
214 | } | 214 | } |
215 | 215 | ||
216 | void DrawPadCanvas::save(QIODevice* ioDevice) | 216 | void DrawPadCanvas::save(QIODevice* ioDevice) |
217 | { | 217 | { |
218 | QTextStream textStream(ioDevice); | 218 | QTextStream textStream(ioDevice); |
219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
220 | 220 | ||
221 | textStream << "<drawpad>" << endl; | 221 | textStream << "<drawpad>" << endl; |
222 | textStream << " <images>" << endl; | 222 | textStream << " <images>" << endl; |
223 | 223 | ||
224 | QListIterator<QPixmap> bufferIterator(m_pages); | 224 | QListIterator<Page> bufferIterator(m_pages); |
225 | 225 | ||
226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
227 | textStream << " <image>" << endl; | 227 | textStream << " <image>" << endl; |
228 | 228 | ||
229 | QImage image = bufferIterator.current()->convertToImage(); | 229 | QImage image = bufferIterator.current()->convertToImage(); |
230 | QByteArray byteArray; | 230 | QByteArray byteArray; |
231 | QBuffer buffer(byteArray); | 231 | QBuffer buffer(byteArray); |
232 | QImageIO imageIO(&buffer, "PNG"); | 232 | QImageIO imageIO(&buffer, "PNG"); |
233 | 233 | ||
234 | buffer.open(IO_WriteOnly); | 234 | buffer.open(IO_WriteOnly); |
235 | imageIO.setImage(image); | 235 | imageIO.setImage(image); |
236 | imageIO.write(); | 236 | imageIO.write(); |
@@ -247,31 +247,31 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
247 | } | 247 | } |
248 | 248 | ||
249 | textStream << "</data>" << endl; | 249 | textStream << "</data>" << endl; |
250 | textStream << " </image>" << endl; | 250 | textStream << " </image>" << endl; |
251 | } | 251 | } |
252 | 252 | ||
253 | textStream << " </images>" << endl; | 253 | textStream << " </images>" << endl; |
254 | textStream << "</drawpad>"; | 254 | textStream << "</drawpad>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | void DrawPadCanvas::importPage(const QString& fileName) | 257 | void DrawPadCanvas::importPage(const QString& fileName) |
258 | { | 258 | { |
259 | QPixmap* importedPixmap = new QPixmap(); | 259 | Page* importedPage = new Page(); |
260 | 260 | ||
261 | importedPixmap->load(fileName); | 261 | importedPage->load(fileName); |
262 | m_pages.insert(m_pages.at() + 1, importedPixmap); | 262 | m_pages.insert(m_pages.at() + 1, importedPage); |
263 | 263 | ||
264 | m_pageBackups.clear(); | 264 | m_pageBackups.clear(); |
265 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 265 | m_pageBackups.append(new Page(*(m_pages.current()))); |
266 | 266 | ||
267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
268 | viewport()->update(); | 268 | viewport()->update(); |
269 | 269 | ||
270 | emit pagesChanged(); | 270 | emit pagesChanged(); |
271 | emit pageBackupsChanged(); | 271 | emit pageBackupsChanged(); |
272 | } | 272 | } |
273 | 273 | ||
274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
275 | { | 275 | { |
276 | if (fromPage == toPage) { | 276 | if (fromPage == toPage) { |
277 | DocLnk docLnk; | 277 | DocLnk docLnk; |
@@ -299,30 +299,30 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c | |||
299 | FileManager fileManager; | 299 | FileManager fileManager; |
300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
301 | QImageIO imageIO(ioDevice, format); | 301 | QImageIO imageIO(ioDevice, format); |
302 | 302 | ||
303 | QImage image = m_pages.at(i - 1)->convertToImage(); | 303 | QImage image = m_pages.at(i - 1)->convertToImage(); |
304 | imageIO.setImage(image); | 304 | imageIO.setImage(image); |
305 | imageIO.write(); | 305 | imageIO.write(); |
306 | delete ioDevice; | 306 | delete ioDevice; |
307 | } | 307 | } |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | QPixmap* DrawPadCanvas::currentPage() | 311 | Page* DrawPadCanvas::currentPage() |
312 | { | 312 | { |
313 | return m_pages.current(); | 313 | return m_pages.current(); |
314 | } | 314 | } |
315 | 315 | ||
316 | QList<QPixmap> DrawPadCanvas::pages() | 316 | QList<Page> DrawPadCanvas::pages() |
317 | { | 317 | { |
318 | return m_pages; | 318 | return m_pages; |
319 | } | 319 | } |
320 | 320 | ||
321 | uint DrawPadCanvas::pagePosition() | 321 | uint DrawPadCanvas::pagePosition() |
322 | { | 322 | { |
323 | return (m_pages.at() + 1); | 323 | return (m_pages.at() + 1); |
324 | } | 324 | } |
325 | 325 | ||
326 | uint DrawPadCanvas::pageCount() | 326 | uint DrawPadCanvas::pageCount() |
327 | { | 327 | { |
328 | return m_pages.count(); | 328 | return m_pages.count(); |
@@ -330,70 +330,70 @@ uint DrawPadCanvas::pageCount() | |||
330 | 330 | ||
331 | void DrawPadCanvas::backupPage() | 331 | void DrawPadCanvas::backupPage() |
332 | { | 332 | { |
333 | QPixmap* currentBackup = m_pageBackups.current(); | 333 | QPixmap* currentBackup = m_pageBackups.current(); |
334 | while (m_pageBackups.last() != currentBackup) { | 334 | while (m_pageBackups.last() != currentBackup) { |
335 | m_pageBackups.removeLast(); | 335 | m_pageBackups.removeLast(); |
336 | } | 336 | } |
337 | 337 | ||
338 | while (m_pageBackups.count() >= (5 + 1)) { | 338 | while (m_pageBackups.count() >= (5 + 1)) { |
339 | m_pageBackups.removeFirst(); | 339 | m_pageBackups.removeFirst(); |
340 | } | 340 | } |
341 | 341 | ||
342 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 342 | m_pageBackups.append(new Page(*(m_pages.current()))); |
343 | 343 | ||
344 | emit pageBackupsChanged(); | 344 | emit pageBackupsChanged(); |
345 | } | 345 | } |
346 | 346 | ||
347 | void DrawPadCanvas::deleteAll() | 347 | void DrawPadCanvas::deleteAll() |
348 | { | 348 | { |
349 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | 349 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
350 | QMessageBox::Information, QMessageBox::Yes, | 350 | QMessageBox::Information, QMessageBox::Yes, |
351 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 351 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
352 | QMessageBox::NoButton, this); | 352 | QMessageBox::NoButton, this); |
353 | 353 | ||
354 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 354 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
355 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 355 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
356 | 356 | ||
357 | if (messageBox.exec() == QMessageBox::Yes) { | 357 | if (messageBox.exec() == QMessageBox::Yes) { |
358 | m_pages.clear(); | 358 | m_pages.clear(); |
359 | 359 | ||
360 | m_pages.append(new QPixmap(contentsRect().size())); | 360 | m_pages.append(new Page(contentsRect().size())); |
361 | m_pages.current()->fill(Qt::white); | 361 | m_pages.current()->fill(Qt::white); |
362 | 362 | ||
363 | m_pageBackups.clear(); | 363 | m_pageBackups.clear(); |
364 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 364 | m_pageBackups.append(new Page(*(m_pages.current()))); |
365 | 365 | ||
366 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 366 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
367 | viewport()->update(); | 367 | viewport()->update(); |
368 | 368 | ||
369 | emit pagesChanged(); | 369 | emit pagesChanged(); |
370 | emit pageBackupsChanged(); | 370 | emit pageBackupsChanged(); |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | void DrawPadCanvas::newPage() | 374 | void DrawPadCanvas::newPage() |
375 | { | 375 | { |
376 | QRect rect = contentsRect(); | 376 | QRect rect = contentsRect(); |
377 | 377 | ||
378 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), | 378 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
379 | m_pDrawPad->brush().color(), this); | 379 | m_pDrawPad->brush().color(), this); |
380 | 380 | ||
381 | if (newPageDialog.exec() == QDialog::Accepted) { | 381 | if (newPageDialog.exec() == QDialog::Accepted) { |
382 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), | 382 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), |
383 | newPageDialog.selectedHeight())); | 383 | newPageDialog.selectedHeight())); |
384 | m_pages.current()->fill(newPageDialog.selectedColor()); | 384 | m_pages.current()->fill(newPageDialog.selectedColor()); |
385 | 385 | ||
386 | m_pageBackups.clear(); | 386 | m_pageBackups.clear(); |
387 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 387 | m_pageBackups.append(new Page(*(m_pages.current()))); |
388 | 388 | ||
389 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 389 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
390 | viewport()->update(); | 390 | viewport()->update(); |
391 | 391 | ||
392 | emit pagesChanged(); | 392 | emit pagesChanged(); |
393 | emit pageBackupsChanged(); | 393 | emit pageBackupsChanged(); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | void DrawPadCanvas::clearPage() | 397 | void DrawPadCanvas::clearPage() |
398 | { | 398 | { |
399 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | 399 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
@@ -416,30 +416,30 @@ void DrawPadCanvas::deletePage() | |||
416 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | 416 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), |
417 | QMessageBox::Information, QMessageBox::Yes, | 417 | QMessageBox::Information, QMessageBox::Yes, |
418 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 418 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
419 | QMessageBox::NoButton, this); | 419 | QMessageBox::NoButton, this); |
420 | 420 | ||
421 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 421 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
422 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 422 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
423 | 423 | ||
424 | if (messageBox.exec() == QMessageBox::Yes) { | 424 | if (messageBox.exec() == QMessageBox::Yes) { |
425 | m_pages.remove(m_pages.current()); | 425 | m_pages.remove(m_pages.current()); |
426 | 426 | ||
427 | if (m_pages.isEmpty()) { | 427 | if (m_pages.isEmpty()) { |
428 | m_pages.append(new QPixmap(contentsRect().size())); | 428 | m_pages.append(new Page(contentsRect().size())); |
429 | m_pages.current()->fill(Qt::white); | 429 | m_pages.current()->fill(Qt::white); |
430 | } | 430 | } |
431 | 431 | ||
432 | m_pageBackups.clear(); | 432 | m_pageBackups.clear(); |
433 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 433 | m_pageBackups.append(new Page(*(m_pages.current()))); |
434 | 434 | ||
435 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 435 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
436 | viewport()->update(); | 436 | viewport()->update(); |
437 | 437 | ||
438 | emit pagesChanged(); | 438 | emit pagesChanged(); |
439 | emit pageBackupsChanged(); | 439 | emit pageBackupsChanged(); |
440 | } | 440 | } |
441 | } | 441 | } |
442 | 442 | ||
443 | bool DrawPadCanvas::undoEnabled() | 443 | bool DrawPadCanvas::undoEnabled() |
444 | { | 444 | { |
445 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 445 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
@@ -473,64 +473,64 @@ void DrawPadCanvas::redo() | |||
473 | { | 473 | { |
474 | *(m_pages.current()) = *(m_pageBackups.next()); | 474 | *(m_pages.current()) = *(m_pageBackups.next()); |
475 | 475 | ||
476 | viewport()->update(); | 476 | viewport()->update(); |
477 | 477 | ||
478 | emit pageBackupsChanged(); | 478 | emit pageBackupsChanged(); |
479 | } | 479 | } |
480 | 480 | ||
481 | void DrawPadCanvas::goFirstPage() | 481 | void DrawPadCanvas::goFirstPage() |
482 | { | 482 | { |
483 | m_pages.first(); | 483 | m_pages.first(); |
484 | m_pageBackups.clear(); | 484 | m_pageBackups.clear(); |
485 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 485 | m_pageBackups.append(new Page(*(m_pages.current()))); |
486 | 486 | ||
487 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 487 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
488 | viewport()->update(); | 488 | viewport()->update(); |
489 | 489 | ||
490 | emit pagesChanged(); | 490 | emit pagesChanged(); |
491 | emit pageBackupsChanged(); | 491 | emit pageBackupsChanged(); |
492 | } | 492 | } |
493 | 493 | ||
494 | void DrawPadCanvas::goPreviousPage() | 494 | void DrawPadCanvas::goPreviousPage() |
495 | { | 495 | { |
496 | m_pages.prev(); | 496 | m_pages.prev(); |
497 | m_pageBackups.clear(); | 497 | m_pageBackups.clear(); |
498 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 498 | m_pageBackups.append(new Page(*(m_pages.current()))); |
499 | 499 | ||
500 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 500 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
501 | viewport()->update(); | 501 | viewport()->update(); |
502 | 502 | ||
503 | emit pagesChanged(); | 503 | emit pagesChanged(); |
504 | emit pageBackupsChanged(); | 504 | emit pageBackupsChanged(); |
505 | } | 505 | } |
506 | 506 | ||
507 | void DrawPadCanvas::goNextPage() | 507 | void DrawPadCanvas::goNextPage() |
508 | { | 508 | { |
509 | m_pages.next(); | 509 | m_pages.next(); |
510 | m_pageBackups.clear(); | 510 | m_pageBackups.clear(); |
511 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 511 | m_pageBackups.append(new Page(*(m_pages.current()))); |
512 | 512 | ||
513 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 513 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
514 | viewport()->update(); | 514 | viewport()->update(); |
515 | 515 | ||
516 | emit pagesChanged(); | 516 | emit pagesChanged(); |
517 | emit pageBackupsChanged(); | 517 | emit pageBackupsChanged(); |
518 | } | 518 | } |
519 | 519 | ||
520 | void DrawPadCanvas::goLastPage() | 520 | void DrawPadCanvas::goLastPage() |
521 | { | 521 | { |
522 | m_pages.last(); | 522 | m_pages.last(); |
523 | m_pageBackups.clear(); | 523 | m_pageBackups.clear(); |
524 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 524 | m_pageBackups.append(new Page(*(m_pages.current()))); |
525 | 525 | ||
526 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 526 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
527 | viewport()->update(); | 527 | viewport()->update(); |
528 | 528 | ||
529 | emit pagesChanged(); | 529 | emit pagesChanged(); |
530 | emit pageBackupsChanged(); | 530 | emit pageBackupsChanged(); |
531 | } | 531 | } |
532 | 532 | ||
533 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 533 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
534 | { | 534 | { |
535 | m_pDrawPad->tool()->mousePressEvent(e); | 535 | m_pDrawPad->tool()->mousePressEvent(e); |
536 | } | 536 | } |