-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 28 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 146 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasetool.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 46 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.h | 20 | ||||
-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, 169 insertions, 187 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 | |||
@@ -50,19 +50,17 @@ | |||
50 | 50 | ||
51 | DrawPad::DrawPad(QWidget* parent, const char* name) | 51 | DrawPad::DrawPad(QWidget* parent, const char* name) |
52 | : QMainWindow(parent, name) | 52 | : QMainWindow(parent, name) |
53 | { | 53 | { |
54 | // init members | 54 | // init members |
55 | 55 | ||
56 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 56 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
57 | 57 | ||
58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | 58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView())); |
59 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); | ||
60 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | ||
61 | 59 | ||
62 | setCentralWidget(m_pDrawPadCanvas); | 60 | setCentralWidget(m_pDrawPadCanvas); |
63 | 61 | ||
64 | // init menu | 62 | // init menu |
65 | 63 | ||
66 | setToolBarsMovable(false); | 64 | setToolBarsMovable(false); |
67 | 65 | ||
68 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 66 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
@@ -537,37 +535,31 @@ void DrawPad::changeBrushColor(const QColor& color) | |||
537 | QPainter painter; | 535 | QPainter painter; |
538 | painter.begin(m_pBrushColorToolButton->pixmap()); | 536 | painter.begin(m_pBrushColorToolButton->pixmap()); |
539 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 537 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
540 | painter.end(); | 538 | painter.end(); |
541 | 539 | ||
542 | m_pBrushColorToolButton->popup()->hide(); | 540 | m_pBrushColorToolButton->popup()->hide(); |
543 | } | 541 | } |
544 | 542 | ||
545 | void DrawPad::updateUndoRedoToolButtons() | 543 | void DrawPad::updateView() |
546 | { | ||
547 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); | ||
548 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); | ||
549 | } | ||
550 | |||
551 | void DrawPad::updateNavigationToolButtons() | ||
552 | { | ||
553 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | ||
554 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | ||
555 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | ||
556 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | ||
557 | } | ||
558 | |||
559 | void DrawPad::updateCaption() | ||
560 | { | 544 | { |
561 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); | 545 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); |
562 | uint pageCount = m_pDrawPadCanvas->pageCount(); | 546 | uint pageCount = m_pDrawPadCanvas->pageCount(); |
563 | 547 | ||
564 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " | 548 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " |
565 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); | 549 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); |
550 | |||
551 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled()); | ||
552 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled()); | ||
553 | |||
554 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | ||
555 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | ||
556 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | ||
557 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | ||
566 | } | 558 | } |
567 | 559 | ||
568 | void DrawPad::deleteAll() | 560 | void DrawPad::deleteAll() |
569 | { | 561 | { |
570 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | 562 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
571 | QMessageBox::Information, QMessageBox::Yes, | 563 | QMessageBox::Information, QMessageBox::Yes, |
572 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 564 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
573 | QMessageBox::NoButton, this); | 565 | QMessageBox::NoButton, this); |
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 | |||
@@ -54,20 +54,18 @@ private slots: | |||
54 | void setFilledEllipseTool(); | 54 | void setFilledEllipseTool(); |
55 | void setTextTool(); | 55 | void setTextTool(); |
56 | void setFillTool(); | 56 | void setFillTool(); |
57 | void setEraseTool(); | 57 | void setEraseTool(); |
58 | 58 | ||
59 | void changePenWidth(int value); | 59 | void changePenWidth(int value); |
60 | void changePenColor(const QColor& color); | 60 | void changePenColor(const QColor& color); |
61 | void changeBrushColor(const QColor& color); | 61 | void changeBrushColor(const QColor& color); |
62 | 62 | ||
63 | void updateUndoRedoToolButtons(); | 63 | void updateView(); |
64 | void updateNavigationToolButtons(); | ||
65 | void updateCaption(); | ||
66 | 64 | ||
67 | void deleteAll(); | 65 | void deleteAll(); |
68 | void importPage(); | 66 | void importPage(); |
69 | void exportPage(); | 67 | void exportPage(); |
70 | void thumbnailView(); | 68 | void thumbnailView(); |
71 | void pageInformation(); | 69 | void pageInformation(); |
72 | 70 | ||
73 | private: | 71 | private: |
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 | |||
@@ -23,18 +23,16 @@ | |||
23 | 23 | ||
24 | #include <qbuffer.h> | 24 | #include <qbuffer.h> |
25 | #include <qimage.h> | 25 | #include <qimage.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qtextcodec.h> | 27 | #include <qtextcodec.h> |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qxml.h> | 29 | #include <qxml.h> |
30 | 30 | ||
31 | const int PAGE_BACKUPS = 99; | ||
32 | |||
33 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 31 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
34 | { | 32 | { |
35 | public: | 33 | public: |
36 | DrawPadCanvasXmlHandler(); | 34 | DrawPadCanvasXmlHandler(); |
37 | ~DrawPadCanvasXmlHandler(); | 35 | ~DrawPadCanvasXmlHandler(); |
38 | 36 | ||
39 | QList<Page> pages(); | 37 | QList<Page> pages(); |
40 | 38 | ||
@@ -144,29 +142,28 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) | |||
144 | byteArray[i] = r; | 142 | byteArray[i] = r; |
145 | } | 143 | } |
146 | 144 | ||
147 | QImage image; | 145 | QImage image; |
148 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); | 146 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); |
149 | 147 | ||
150 | Page* page = new Page(m_title, image.width(), image.height()); | 148 | Page* page = new Page(m_title, image.width(), image.height()); |
151 | page->setLastModified(m_date); | 149 | page->setLastModified(m_date); |
152 | page->convertFromImage(image); | 150 | page->pixmap()->convertFromImage(image); |
153 | m_pages.append(page); | 151 | m_pages.append(page); |
154 | } | 152 | } |
155 | 153 | ||
156 | return true; | 154 | return true; |
157 | } | 155 | } |
158 | 156 | ||
159 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 157 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
160 | : QScrollView(parent, name) | 158 | : QScrollView(parent, name) |
161 | { | 159 | { |
162 | m_pDrawPad = drawPad; | 160 | m_pDrawPad = drawPad; |
163 | m_pages.setAutoDelete(true); | 161 | m_pages.setAutoDelete(true); |
164 | m_pageBackups.setAutoDelete(true); | ||
165 | 162 | ||
166 | viewport()->setBackgroundMode(QWidget::NoBackground); | 163 | viewport()->setBackgroundMode(QWidget::NoBackground); |
167 | } | 164 | } |
168 | 165 | ||
169 | DrawPadCanvas::~DrawPadCanvas() | 166 | DrawPadCanvas::~DrawPadCanvas() |
170 | { | 167 | { |
171 | } | 168 | } |
172 | 169 | ||
@@ -181,62 +178,54 @@ void DrawPadCanvas::load(QIODevice* ioDevice) | |||
181 | 178 | ||
182 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 179 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
183 | xmlSimpleReader.parse(xmlInputSource); | 180 | xmlSimpleReader.parse(xmlInputSource); |
184 | 181 | ||
185 | m_pages = drawPadCanvasXmlHandler.pages(); | 182 | m_pages = drawPadCanvasXmlHandler.pages(); |
186 | 183 | ||
187 | if (m_pages.isEmpty()) { | 184 | if (m_pages.isEmpty()) { |
188 | m_pages.append(new Page("", contentsRect().size())); | 185 | m_pages.append(new Page("", contentsRect().size())); |
189 | m_pages.current()->fill(Qt::white); | 186 | m_pages.current()->pixmap()->fill(Qt::white); |
190 | } | 187 | } |
191 | 188 | ||
192 | m_pageBackups.clear(); | 189 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
193 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
194 | |||
195 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
196 | viewport()->update(); | 190 | viewport()->update(); |
197 | 191 | ||
198 | emit pagesChanged(); | 192 | emit pagesChanged(); |
199 | emit pageBackupsChanged(); | ||
200 | } | 193 | } |
201 | 194 | ||
202 | void DrawPadCanvas::initialPage() | 195 | void DrawPadCanvas::initialPage() |
203 | { | 196 | { |
204 | m_pages.append(new Page("", 236, 232)); | 197 | m_pages.append(new Page("", 236, 232)); |
205 | m_pages.current()->fill(Qt::white); | 198 | m_pages.current()->pixmap()->fill(Qt::white); |
206 | |||
207 | m_pageBackups.clear(); | ||
208 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
209 | 199 | ||
210 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 200 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
211 | viewport()->update(); | 201 | viewport()->update(); |
212 | 202 | ||
213 | emit pagesChanged(); | 203 | emit pagesChanged(); |
214 | emit pageBackupsChanged(); | ||
215 | } | 204 | } |
216 | 205 | ||
217 | void DrawPadCanvas::save(QIODevice* ioDevice) | 206 | void DrawPadCanvas::save(QIODevice* ioDevice) |
218 | { | 207 | { |
219 | QTextStream textStream(ioDevice); | 208 | QTextStream textStream(ioDevice); |
220 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 209 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
221 | 210 | ||
222 | textStream << "<drawpad>" << endl; | 211 | textStream << "<drawpad>" << endl; |
223 | textStream << " <images>" << endl; | 212 | textStream << " <images>" << endl; |
224 | 213 | ||
225 | QListIterator<Page> bufferIterator(m_pages); | 214 | QListIterator<Page> bufferIterator(m_pages); |
226 | 215 | ||
227 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 216 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
228 | textStream << " <image>" << endl; | 217 | textStream << " <image>" << endl; |
229 | textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; | 218 | textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; |
230 | 219 | ||
231 | int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); | 220 | int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); |
232 | textStream << " <date>" << intDate << "</date>" << endl; | 221 | textStream << " <date>" << intDate << "</date>" << endl; |
233 | 222 | ||
234 | QImage image = bufferIterator.current()->convertToImage(); | 223 | QImage image = bufferIterator.current()->pixmap()->convertToImage(); |
235 | QByteArray byteArray; | 224 | QByteArray byteArray; |
236 | QBuffer buffer(byteArray); | 225 | QBuffer buffer(byteArray); |
237 | QImageIO imageIO(&buffer, "PNG"); | 226 | QImageIO imageIO(&buffer, "PNG"); |
238 | 227 | ||
239 | buffer.open(IO_WriteOnly); | 228 | buffer.open(IO_WriteOnly); |
240 | imageIO.setImage(image); | 229 | imageIO.setImage(image); |
241 | imageIO.write(); | 230 | imageIO.write(); |
242 | buffer.close(); | 231 | buffer.close(); |
@@ -258,59 +247,55 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
258 | textStream << " </images>" << endl; | 247 | textStream << " </images>" << endl; |
259 | textStream << "</drawpad>"; | 248 | textStream << "</drawpad>"; |
260 | } | 249 | } |
261 | 250 | ||
262 | void DrawPadCanvas::importPage(const QString& fileName) | 251 | void DrawPadCanvas::importPage(const QString& fileName) |
263 | { | 252 | { |
264 | Page* importedPage = new Page(); | 253 | Page* importedPage = new Page(); |
265 | 254 | ||
266 | importedPage->load(fileName); | 255 | importedPage->pixmap()->load(fileName); |
267 | m_pages.insert(m_pages.at() + 1, importedPage); | 256 | m_pages.insert(m_pages.at() + 1, importedPage); |
268 | 257 | ||
269 | m_pageBackups.clear(); | 258 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
270 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
271 | |||
272 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
273 | viewport()->update(); | 259 | viewport()->update(); |
274 | 260 | ||
275 | emit pagesChanged(); | 261 | emit pagesChanged(); |
276 | emit pageBackupsChanged(); | ||
277 | } | 262 | } |
278 | 263 | ||
279 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 264 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
280 | { | 265 | { |
281 | if (fromPage == toPage) { | 266 | if (fromPage == toPage) { |
282 | DocLnk docLnk; | 267 | DocLnk docLnk; |
283 | MimeType mimeType(format); | 268 | MimeType mimeType(format); |
284 | 269 | ||
285 | docLnk.setName(name); | 270 | docLnk.setName(name); |
286 | docLnk.setType(mimeType.id()); | 271 | docLnk.setType(mimeType.id()); |
287 | 272 | ||
288 | FileManager fileManager; | 273 | FileManager fileManager; |
289 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 274 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
290 | QImageIO imageIO(ioDevice, format); | 275 | QImageIO imageIO(ioDevice, format); |
291 | 276 | ||
292 | QImage image = m_pages.current()->convertToImage(); | 277 | QImage image = m_pages.current()->pixmap()->convertToImage(); |
293 | imageIO.setImage(image); | 278 | imageIO.setImage(image); |
294 | imageIO.write(); | 279 | imageIO.write(); |
295 | delete ioDevice; | 280 | delete ioDevice; |
296 | } else { | 281 | } else { |
297 | for (uint i = fromPage; i <= toPage; i++) { | 282 | for (uint i = fromPage; i <= toPage; i++) { |
298 | DocLnk docLnk; | 283 | DocLnk docLnk; |
299 | MimeType mimeType(format); | 284 | MimeType mimeType(format); |
300 | 285 | ||
301 | docLnk.setName(name + QString::number(i)); | 286 | docLnk.setName(name + QString::number(i)); |
302 | docLnk.setType(mimeType.id()); | 287 | docLnk.setType(mimeType.id()); |
303 | 288 | ||
304 | FileManager fileManager; | 289 | FileManager fileManager; |
305 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 290 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
306 | QImageIO imageIO(ioDevice, format); | 291 | QImageIO imageIO(ioDevice, format); |
307 | 292 | ||
308 | QImage image = m_pages.at(i - 1)->convertToImage(); | 293 | QImage image = m_pages.at(i - 1)->pixmap()->convertToImage(); |
309 | imageIO.setImage(image); | 294 | imageIO.setImage(image); |
310 | imageIO.write(); | 295 | imageIO.write(); |
311 | delete ioDevice; | 296 | delete ioDevice; |
312 | } | 297 | } |
313 | } | 298 | } |
314 | } | 299 | } |
315 | 300 | ||
316 | Page* DrawPadCanvas::currentPage() | 301 | Page* DrawPadCanvas::currentPage() |
@@ -331,119 +316,85 @@ uint DrawPadCanvas::pagePosition() | |||
331 | uint DrawPadCanvas::pageCount() | 316 | uint DrawPadCanvas::pageCount() |
332 | { | 317 | { |
333 | return m_pages.count(); | 318 | return m_pages.count(); |
334 | } | 319 | } |
335 | 320 | ||
336 | void DrawPadCanvas::selectPage(Page* page) | 321 | void DrawPadCanvas::selectPage(Page* page) |
337 | { | 322 | { |
338 | m_pages.findRef(page); | 323 | m_pages.findRef(page); |
339 | m_pageBackups.clear(); | ||
340 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
341 | 324 | ||
342 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 325 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
343 | viewport()->update(); | 326 | viewport()->update(); |
344 | 327 | ||
345 | emit pagesChanged(); | 328 | emit pagesChanged(); |
346 | emit pageBackupsChanged(); | ||
347 | } | 329 | } |
348 | 330 | ||
349 | void DrawPadCanvas::selectPage(uint pagePosition) | 331 | void DrawPadCanvas::backupPage() |
350 | { | 332 | { |
351 | m_pages.at(pagePosition - 1); | 333 | m_pages.current()->backup(); |
352 | m_pageBackups.clear(); | ||
353 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
354 | |||
355 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
356 | viewport()->update(); | ||
357 | 334 | ||
358 | emit pagesChanged(); | 335 | emit pagesChanged(); |
359 | emit pageBackupsChanged(); | ||
360 | } | 336 | } |
361 | 337 | ||
362 | void DrawPadCanvas::backupPage() | 338 | void DrawPadCanvas::selectPage(uint pagePosition) |
363 | { | 339 | { |
364 | m_pages.current()->setLastModified(QDateTime::currentDateTime()); | 340 | m_pages.at(pagePosition - 1); |
365 | |||
366 | Page* currentBackup = m_pageBackups.current(); | ||
367 | while (m_pageBackups.last() != currentBackup) { | ||
368 | m_pageBackups.removeLast(); | ||
369 | } | ||
370 | |||
371 | while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) { | ||
372 | m_pageBackups.removeFirst(); | ||
373 | } | ||
374 | 341 | ||
375 | m_pageBackups.append(new Page(*(m_pages.current()))); | 342 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
343 | viewport()->update(); | ||
376 | 344 | ||
377 | emit pageBackupsChanged(); | 345 | emit pagesChanged(); |
378 | } | 346 | } |
379 | 347 | ||
380 | void DrawPadCanvas::deleteAll() | 348 | void DrawPadCanvas::deleteAll() |
381 | { | 349 | { |
382 | m_pages.clear(); | 350 | m_pages.clear(); |
383 | 351 | ||
384 | m_pages.append(new Page("", contentsRect().size())); | 352 | m_pages.append(new Page("", contentsRect().size())); |
385 | m_pages.current()->fill(Qt::white); | 353 | m_pages.current()->pixmap()->fill(Qt::white); |
386 | 354 | ||
387 | m_pageBackups.clear(); | 355 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
388 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
389 | |||
390 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
391 | viewport()->update(); | 356 | viewport()->update(); |
392 | 357 | ||
393 | emit pagesChanged(); | 358 | emit pagesChanged(); |
394 | emit pageBackupsChanged(); | ||
395 | } | 359 | } |
396 | 360 | ||
397 | void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) | 361 | void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) |
398 | { | 362 | { |
399 | m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); | 363 | m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); |
400 | m_pages.current()->fill(color); | 364 | m_pages.current()->pixmap()->fill(color); |
401 | |||
402 | m_pageBackups.clear(); | ||
403 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
404 | 365 | ||
405 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 366 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
406 | viewport()->update(); | 367 | viewport()->update(); |
407 | 368 | ||
408 | emit pagesChanged(); | 369 | emit pagesChanged(); |
409 | emit pageBackupsChanged(); | ||
410 | } | 370 | } |
411 | 371 | ||
412 | void DrawPadCanvas::clearPage() | 372 | void DrawPadCanvas::clearPage() |
413 | { | 373 | { |
414 | m_pages.current()->fill(Qt::white); | 374 | m_pages.current()->pixmap()->fill(Qt::white); |
415 | 375 | ||
416 | m_pageBackups.clear(); | 376 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
417 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
418 | |||
419 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
420 | viewport()->update(); | 377 | viewport()->update(); |
421 | |||
422 | emit pageBackupsChanged(); | ||
423 | } | 378 | } |
424 | 379 | ||
425 | void DrawPadCanvas::deletePage() | 380 | void DrawPadCanvas::deletePage() |
426 | { | 381 | { |
427 | m_pages.remove(m_pages.current()); | 382 | m_pages.remove(m_pages.current()); |
428 | 383 | ||
429 | if (m_pages.isEmpty()) { | 384 | if (m_pages.isEmpty()) { |
430 | m_pages.append(new Page("", contentsRect().size())); | 385 | m_pages.append(new Page("", contentsRect().size())); |
431 | m_pages.current()->fill(Qt::white); | 386 | m_pages.current()->pixmap()->fill(Qt::white); |
432 | } | 387 | } |
433 | 388 | ||
434 | m_pageBackups.clear(); | 389 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
435 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
436 | |||
437 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
438 | viewport()->update(); | 390 | viewport()->update(); |
439 | 391 | ||
440 | emit pagesChanged(); | 392 | emit pagesChanged(); |
441 | emit pageBackupsChanged(); | ||
442 | } | 393 | } |
443 | 394 | ||
444 | void DrawPadCanvas::movePageUp() | 395 | void DrawPadCanvas::movePageUp() |
445 | { | 396 | { |
446 | int index = m_pages.at(); | 397 | int index = m_pages.at(); |
447 | Page* page = m_pages.take(); | 398 | Page* page = m_pages.take(); |
448 | m_pages.insert(index - 1, page); | 399 | m_pages.insert(index - 1, page); |
449 | 400 | ||
@@ -454,104 +405,81 @@ void DrawPadCanvas::movePageDown() | |||
454 | { | 405 | { |
455 | int index = m_pages.at(); | 406 | int index = m_pages.at(); |
456 | Page* page = m_pages.take(); | 407 | Page* page = m_pages.take(); |
457 | m_pages.insert(index + 1, page); | 408 | m_pages.insert(index + 1, page); |
458 | 409 | ||
459 | emit pagesChanged(); | 410 | emit pagesChanged(); |
460 | } | 411 | } |
461 | 412 | ||
462 | bool DrawPadCanvas::undoEnabled() | ||
463 | { | ||
464 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | ||
465 | } | ||
466 | |||
467 | bool DrawPadCanvas::redoEnabled() | ||
468 | { | ||
469 | return (m_pageBackups.current() != m_pageBackups.getLast()); | ||
470 | } | ||
471 | |||
472 | bool DrawPadCanvas::goPreviousPageEnabled() | 413 | bool DrawPadCanvas::goPreviousPageEnabled() |
473 | { | 414 | { |
474 | return (m_pages.current() != m_pages.getFirst()); | 415 | return (m_pages.current() != m_pages.getFirst()); |
475 | } | 416 | } |
476 | 417 | ||
477 | bool DrawPadCanvas::goNextPageEnabled() | 418 | bool DrawPadCanvas::goNextPageEnabled() |
478 | { | 419 | { |
479 | return (m_pages.current() != m_pages.getLast()); | 420 | return (m_pages.current() != m_pages.getLast()); |
480 | } | 421 | } |
481 | 422 | ||
482 | void DrawPadCanvas::undo() | 423 | void DrawPadCanvas::undo() |
483 | { | 424 | { |
484 | *(m_pages.current()) = *(m_pageBackups.prev()); | 425 | m_pages.current()->undo(); |
485 | 426 | ||
486 | viewport()->update(); | 427 | viewport()->update(); |
487 | 428 | ||
488 | emit pageBackupsChanged(); | 429 | emit pagesChanged(); |
489 | } | 430 | } |
490 | 431 | ||
491 | void DrawPadCanvas::redo() | 432 | void DrawPadCanvas::redo() |
492 | { | 433 | { |
493 | *(m_pages.current()) = *(m_pageBackups.next()); | 434 | m_pages.current()->redo(); |
494 | 435 | ||
495 | viewport()->update(); | 436 | viewport()->update(); |
496 | 437 | ||
497 | emit pageBackupsChanged(); | 438 | emit pagesChanged(); |
498 | } | 439 | } |
499 | 440 | ||
500 | void DrawPadCanvas::goFirstPage() | 441 | void DrawPadCanvas::goFirstPage() |
501 | { | 442 | { |
502 | m_pages.first(); | 443 | m_pages.first(); |
503 | m_pageBackups.clear(); | ||
504 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
505 | 444 | ||
506 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 445 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
507 | viewport()->update(); | 446 | viewport()->update(); |
508 | 447 | ||
509 | emit pagesChanged(); | 448 | emit pagesChanged(); |
510 | emit pageBackupsChanged(); | ||
511 | } | 449 | } |
512 | 450 | ||
513 | void DrawPadCanvas::goPreviousPage() | 451 | void DrawPadCanvas::goPreviousPage() |
514 | { | 452 | { |
515 | m_pages.prev(); | 453 | m_pages.prev(); |
516 | m_pageBackups.clear(); | ||
517 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
518 | 454 | ||
519 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 455 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
520 | viewport()->update(); | 456 | viewport()->update(); |
521 | 457 | ||
522 | emit pagesChanged(); | 458 | emit pagesChanged(); |
523 | emit pageBackupsChanged(); | ||
524 | } | 459 | } |
525 | 460 | ||
526 | void DrawPadCanvas::goNextPage() | 461 | void DrawPadCanvas::goNextPage() |
527 | { | 462 | { |
528 | m_pages.next(); | 463 | m_pages.next(); |
529 | m_pageBackups.clear(); | 464 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
530 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
531 | |||
532 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
533 | viewport()->update(); | 465 | viewport()->update(); |
534 | 466 | ||
535 | emit pagesChanged(); | 467 | emit pagesChanged(); |
536 | emit pageBackupsChanged(); | ||
537 | } | 468 | } |
538 | 469 | ||
539 | void DrawPadCanvas::goLastPage() | 470 | void DrawPadCanvas::goLastPage() |
540 | { | 471 | { |
541 | m_pages.last(); | 472 | m_pages.last(); |
542 | m_pageBackups.clear(); | ||
543 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
544 | 473 | ||
545 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 474 | resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
546 | viewport()->update(); | 475 | viewport()->update(); |
547 | 476 | ||
548 | emit pagesChanged(); | 477 | emit pagesChanged(); |
549 | emit pageBackupsChanged(); | ||
550 | } | 478 | } |
551 | 479 | ||
552 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 480 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
553 | { | 481 | { |
554 | m_pDrawPad->tool()->mousePressEvent(e); | 482 | m_pDrawPad->tool()->mousePressEvent(e); |
555 | } | 483 | } |
556 | 484 | ||
557 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | 485 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
@@ -562,20 +490,20 @@ void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | |||
562 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | 490 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
563 | { | 491 | { |
564 | m_pDrawPad->tool()->mouseMoveEvent(e); | 492 | m_pDrawPad->tool()->mouseMoveEvent(e); |
565 | } | 493 | } |
566 | 494 | ||
567 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 495 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
568 | { | 496 | { |
569 | QRect clipRect(cx, cy, cw, ch); | 497 | QRect clipRect(cx, cy, cw, ch); |
570 | QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); | 498 | QRect pixmapRect(0, 0, m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); |
571 | QRect drawRect = pixmapRect.intersect(clipRect); | 499 | QRect drawRect = pixmapRect.intersect(clipRect); |
572 | 500 | ||
573 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); | 501 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()->pixmap()), drawRect); |
574 | 502 | ||
575 | if (drawRect.right() < clipRect.right()) { | 503 | if (drawRect.right() < clipRect.right()) { |
576 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); | 504 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); |
577 | } | 505 | } |
578 | 506 | ||
579 | if (drawRect.bottom() < clipRect.bottom()) { | 507 | if (drawRect.bottom() < clipRect.bottom()) { |
580 | p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); | 508 | p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); |
581 | } | 509 | } |
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 | |||
@@ -32,18 +32,16 @@ public: | |||
32 | 32 | ||
33 | void load(QIODevice* ioDevice); | 33 | void load(QIODevice* ioDevice); |
34 | void initialPage(); | 34 | void initialPage(); |
35 | void save(QIODevice* ioDevice); | 35 | void save(QIODevice* ioDevice); |
36 | 36 | ||
37 | void importPage(const QString& fileName); | 37 | void importPage(const QString& fileName); |
38 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); | 38 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); |
39 | 39 | ||
40 | bool undoEnabled(); | ||
41 | bool redoEnabled(); | ||
42 | bool goPreviousPageEnabled(); | 40 | bool goPreviousPageEnabled(); |
43 | bool goNextPageEnabled(); | 41 | bool goNextPageEnabled(); |
44 | 42 | ||
45 | Page* currentPage(); | 43 | Page* currentPage(); |
46 | QList<Page> pages(); | 44 | QList<Page> pages(); |
47 | uint pagePosition(); | 45 | uint pagePosition(); |
48 | uint pageCount(); | 46 | uint pageCount(); |
49 | 47 | ||
@@ -53,34 +51,32 @@ public: | |||
53 | 51 | ||
54 | public slots: | 52 | public slots: |
55 | void deleteAll(); | 53 | void deleteAll(); |
56 | void newPage(QString title, uint width, uint height, const QColor& color); | 54 | void newPage(QString title, uint width, uint height, const QColor& color); |
57 | void clearPage(); | 55 | void clearPage(); |
58 | void deletePage(); | 56 | void deletePage(); |
59 | void movePageUp(); | 57 | void movePageUp(); |
60 | void movePageDown(); | 58 | void movePageDown(); |
61 | 59 | ||
62 | void undo(); | 60 | void undo(); |
63 | void redo(); | 61 | void redo(); |
64 | 62 | ||
65 | void goFirstPage(); | 63 | void goFirstPage(); |
66 | void goPreviousPage(); | 64 | void goPreviousPage(); |
67 | void goNextPage(); | 65 | void goNextPage(); |
68 | void goLastPage(); | 66 | void goLastPage(); |
69 | 67 | ||
70 | signals: | 68 | signals: |
71 | void pagesChanged(); | 69 | void pagesChanged(); |
72 | void pageBackupsChanged(); | ||
73 | 70 | ||
74 | protected: | 71 | protected: |
75 | void contentsMousePressEvent(QMouseEvent* e); | 72 | void contentsMousePressEvent(QMouseEvent* e); |
76 | void contentsMouseReleaseEvent(QMouseEvent* e); | 73 | void contentsMouseReleaseEvent(QMouseEvent* e); |
77 | void contentsMouseMoveEvent(QMouseEvent* e); | 74 | void contentsMouseMoveEvent(QMouseEvent* e); |
78 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); | 75 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); |
79 | 76 | ||
80 | private: | 77 | private: |
81 | DrawPad* m_pDrawPad; | 78 | DrawPad* m_pDrawPad; |
82 | QList<Page> m_pages; | 79 | QList<Page> m_pages; |
83 | QList<Page> m_pageBackups; | ||
84 | }; | 80 | }; |
85 | 81 | ||
86 | #endif // DRAWPADCANVAS_H | 82 | #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 | |||
@@ -27,35 +27,35 @@ EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | |||
27 | } | 27 | } |
28 | 28 | ||
29 | EraseTool::~EraseTool() | 29 | EraseTool::~EraseTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void EraseTool::mousePressEvent(QMouseEvent* e) | 33 | void EraseTool::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_pDrawPadCanvas->backupPage(); | ||
36 | |||
35 | m_mousePressed = true; | 37 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 38 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 39 | } |
38 | 40 | ||
39 | void EraseTool::mouseReleaseEvent(QMouseEvent* e) | 41 | void EraseTool::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 42 | { |
41 | Q_UNUSED(e) | 43 | Q_UNUSED(e) |
42 | 44 | ||
43 | m_mousePressed = false; | 45 | m_mousePressed = false; |
44 | |||
45 | m_pDrawPadCanvas->backupPage(); | ||
46 | } | 46 | } |
47 | 47 | ||
48 | void EraseTool::mouseMoveEvent(QMouseEvent* e) | 48 | void EraseTool::mouseMoveEvent(QMouseEvent* e) |
49 | { | 49 | { |
50 | if (m_mousePressed) { | 50 | if (m_mousePressed) { |
51 | QPainter painter; | 51 | QPainter painter; |
52 | QPen pen(Qt::white, m_pDrawPad->pen().width()); | 52 | QPen pen(Qt::white, m_pDrawPad->pen().width()); |
53 | painter.begin(m_pDrawPadCanvas->currentPage()); | 53 | painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); |
54 | painter.setPen(pen); | 54 | painter.setPen(pen); |
55 | m_polyline[2] = m_polyline[1]; | 55 | m_polyline[2] = m_polyline[1]; |
56 | m_polyline[1] = m_polyline[0]; | 56 | m_polyline[1] = m_polyline[0]; |
57 | m_polyline[0] = e->pos(); | 57 | m_polyline[0] = e->pos(); |
58 | painter.drawPolyline(m_polyline); | 58 | painter.drawPolyline(m_polyline); |
59 | painter.end(); | 59 | painter.end(); |
60 | 60 | ||
61 | QRect r = m_polyline.boundingRect(); | 61 | QRect r = m_polyline.boundingRect(); |
@@ -64,13 +64,13 @@ void EraseTool::mouseMoveEvent(QMouseEvent* e) | |||
64 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 64 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
65 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 65 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
66 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 66 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
67 | 67 | ||
68 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 68 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
69 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 69 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
70 | 70 | ||
71 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 71 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
72 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 72 | m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); |
73 | 73 | ||
74 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 74 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
75 | } | 75 | } |
76 | } | 76 | } |
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 | |||
@@ -30,21 +30,23 @@ FillTool::~FillTool() | |||
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void FillTool::mousePressEvent(QMouseEvent* e) | 33 | void FillTool::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | int x = e->x(); | 35 | int x = e->x(); |
36 | int y = e->y(); | 36 | int y = e->y(); |
37 | 37 | ||
38 | m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); | 38 | m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage(); |
39 | m_fillRgb = m_pDrawPad->brush().color().rgb(); | 39 | m_fillRgb = m_pDrawPad->brush().color().rgb(); |
40 | m_oldRgb = m_image.pixel(x, y); | 40 | m_oldRgb = m_image.pixel(x, y); |
41 | 41 | ||
42 | if (m_oldRgb != m_fillRgb) { | 42 | if (m_oldRgb != m_fillRgb) { |
43 | m_pDrawPadCanvas->backupPage(); | ||
44 | |||
43 | if (m_pDrawPad->antiAliasing()) { | 45 | if (m_pDrawPad->antiAliasing()) { |
44 | m_mask.create(m_image.width(), m_image.height(), 8, 2); | 46 | m_mask.create(m_image.width(), m_image.height(), 8, 2); |
45 | m_mask.fill(0); | 47 | m_mask.fill(0); |
46 | 48 | ||
47 | fillMaskLine(x, y); | 49 | fillMaskLine(x, y); |
48 | 50 | ||
49 | for (int i = 0; i < m_image.width(); i++) { | 51 | for (int i = 0; i < m_image.width(); i++) { |
50 | for (int j = 0; j < m_image.height(); j++) { | 52 | for (int j = 0; j < m_image.height(); j++) { |
@@ -53,20 +55,18 @@ void FillTool::mousePressEvent(QMouseEvent* e) | |||
53 | } | 55 | } |
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | } else { | 59 | } else { |
58 | fillLine(x, y); | 60 | fillLine(x, y); |
59 | } | 61 | } |
60 | 62 | ||
61 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); | 63 | m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image); |
62 | m_pDrawPadCanvas->viewport()->update(); | 64 | m_pDrawPadCanvas->viewport()->update(); |
63 | |||
64 | m_pDrawPadCanvas->backupPage(); | ||
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | void FillTool::mouseReleaseEvent(QMouseEvent* e) | 68 | void FillTool::mouseReleaseEvent(QMouseEvent* e) |
69 | { | 69 | { |
70 | Q_UNUSED(e) | 70 | Q_UNUSED(e) |
71 | } | 71 | } |
72 | 72 | ||
@@ -106,41 +106,41 @@ void FillTool::fillLine(int x, int y) | |||
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | void FillTool::fillMaskLine(int x, int y) | 110 | void FillTool::fillMaskLine(int x, int y) |
111 | { | 111 | { |
112 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { | 112 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { |
113 | if (m_mask.pixelIndex(x, y) == 0) { | 113 | if (m_mask.pixelIndex(x, y) == 0) { |
114 | if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { | 114 | if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { |
115 | int x1, x2; | 115 | int x1, x2; |
116 | 116 | ||
117 | x1 = x - 1; | 117 | x1 = x - 1; |
118 | x2 = x + 1; | 118 | x2 = x + 1; |
119 | 119 | ||
120 | while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { | 120 | while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { |
121 | x1--; | 121 | x1--; |
122 | } | 122 | } |
123 | 123 | ||
124 | while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { | 124 | while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { |
125 | x2++; | 125 | x2++; |
126 | } | 126 | } |
127 | 127 | ||
128 | for (int i = x1 + 1; i < x2; i++) { | 128 | for (int i = x1 + 1; i < x2; i++) { |
129 | m_mask.setPixel(i, y, 1); | 129 | m_mask.setPixel(i, y, 1); |
130 | } | 130 | } |
131 | 131 | ||
132 | for (int i = x1 + 1; i < x2; i++) { | 132 | for (int i = x1 + 1; i < x2; i++) { |
133 | fillMaskLine(i, y - 1); | 133 | fillMaskLine(i, y - 1); |
134 | } | 134 | } |
135 | 135 | ||
136 | for (int i = x1 + 1; i < x2; i++) { | 136 | for (int i = x1 + 1; i < x2; i++) { |
137 | fillMaskLine(i, y + 1); | 137 | fillMaskLine(i, y + 1); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | void FillTool::setInterpolatedPixel(int x, int y) | 144 | void FillTool::setInterpolatedPixel(int x, int y) |
145 | { | 145 | { |
146 | int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); | 146 | int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); |
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 | |||
@@ -8,52 +8,106 @@ | |||
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 "page.h" | 14 | #include "page.h" |
15 | 15 | ||
16 | const int PAGE_BACKUPS = 99; | ||
17 | |||
16 | Page::Page() | 18 | Page::Page() |
17 | : QPixmap() | ||
18 | { | 19 | { |
20 | m_title = ""; | ||
19 | m_lastModified = QDateTime::currentDateTime(); | 21 | m_lastModified = QDateTime::currentDateTime(); |
22 | m_pPixmap = new QPixmap(); | ||
23 | |||
24 | m_backHistory.setAutoDelete(true); | ||
25 | m_forwardHistory.setAutoDelete(true); | ||
20 | } | 26 | } |
21 | 27 | ||
22 | Page::Page(QString title, int w, int h) | 28 | Page::Page(QString title, int w, int h) |
23 | : QPixmap(w, h) | ||
24 | { | 29 | { |
25 | m_title = title; | 30 | m_title = title; |
26 | m_lastModified = QDateTime::currentDateTime(); | 31 | m_lastModified = QDateTime::currentDateTime(); |
32 | m_pPixmap = new QPixmap(w, h); | ||
33 | |||
34 | m_backHistory.setAutoDelete(true); | ||
35 | m_forwardHistory.setAutoDelete(true); | ||
27 | } | 36 | } |
28 | 37 | ||
29 | Page::Page(QString title, const QSize& size) | 38 | Page::Page(QString title, const QSize& size) |
30 | : QPixmap(size) | ||
31 | { | 39 | { |
32 | m_title = title; | 40 | m_title = title; |
33 | m_lastModified = QDateTime::currentDateTime(); | 41 | m_lastModified = QDateTime::currentDateTime(); |
42 | m_pPixmap = new QPixmap(size); | ||
43 | |||
44 | m_backHistory.setAutoDelete(true); | ||
45 | m_forwardHistory.setAutoDelete(true); | ||
34 | } | 46 | } |
35 | 47 | ||
36 | Page::~Page() | 48 | Page::~Page() |
37 | { | 49 | { |
50 | delete m_pPixmap; | ||
38 | } | 51 | } |
39 | 52 | ||
40 | QString Page::title() const | 53 | QString Page::title() const |
41 | { | 54 | { |
42 | return m_title; | 55 | return m_title; |
43 | } | 56 | } |
44 | 57 | ||
45 | QDateTime Page::lastModified() const | 58 | QDateTime Page::lastModified() const |
46 | { | 59 | { |
47 | return m_lastModified; | 60 | return m_lastModified; |
48 | } | 61 | } |
49 | 62 | ||
63 | QPixmap* Page::pixmap() const | ||
64 | |||
65 | { | ||
66 | return m_pPixmap; | ||
67 | } | ||
68 | |||
50 | void Page::setTitle(QString title) | 69 | void Page::setTitle(QString title) |
51 | { | 70 | { |
52 | m_title = title; | 71 | m_title = title; |
53 | } | 72 | } |
54 | 73 | ||
55 | void Page::setLastModified(QDateTime lastModified) | 74 | void Page::setLastModified(QDateTime lastModified) |
56 | { | 75 | { |
57 | m_lastModified = lastModified; | 76 | m_lastModified = lastModified; |
58 | } | 77 | } |
59 | 78 | ||
79 | bool Page::undoEnabled() | ||
80 | { | ||
81 | return (!m_backHistory.isEmpty()); | ||
82 | } | ||
83 | |||
84 | bool Page::redoEnabled() | ||
85 | { | ||
86 | return (!m_forwardHistory.isEmpty()); | ||
87 | } | ||
88 | |||
89 | void Page::backup() | ||
90 | { | ||
91 | setLastModified(QDateTime::currentDateTime()); | ||
92 | |||
93 | while (m_backHistory.count() >= (PAGE_BACKUPS + 1)) { | ||
94 | m_backHistory.removeFirst(); | ||
95 | } | ||
96 | |||
97 | m_backHistory.append(new QPixmap(*m_pPixmap)); | ||
98 | m_forwardHistory.clear(); | ||
99 | } | ||
100 | |||
101 | void Page::undo() | ||
102 | { | ||
103 | m_forwardHistory.append(new QPixmap(*m_pPixmap)); | ||
104 | m_pPixmap = new QPixmap(*(m_backHistory.last())); | ||
105 | m_backHistory.removeLast(); | ||
106 | } | ||
107 | |||
108 | void Page::redo() | ||
109 | { | ||
110 | m_backHistory.append(new QPixmap(*m_pPixmap)); | ||
111 | m_pPixmap = new QPixmap(*(m_forwardHistory.last())); | ||
112 | m_forwardHistory.removeLast(); | ||
113 | } | ||
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 | |||
@@ -9,33 +9,47 @@ | |||
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 | #ifndef PAGE_H | 14 | #ifndef PAGE_H |
15 | #define PAGE_H | 15 | #define PAGE_H |
16 | 16 | ||
17 | #include <qpixmap.h> | 17 | #include <qobject.h> |
18 | 18 | ||
19 | #include <qdatetime.h> | 19 | #include <qdatetime.h> |
20 | #include <qlist.h> | ||
21 | #include <qpixmap.h> | ||
20 | 22 | ||
21 | class Page : public QPixmap | 23 | class Page : public QObject |
22 | { | 24 | { |
23 | public: | 25 | public: |
24 | Page(); | 26 | Page(); |
25 | Page(QString title, int w, int h); | 27 | Page(QString title, int w, int h); |
26 | Page(QString title, const QSize& size); | 28 | Page(QString title, const QSize& size); |
27 | 29 | ||
28 | ~Page(); | 30 | ~Page(); |
29 | 31 | ||
30 | QString title() const; | 32 | QString title() const; |
31 | QDateTime lastModified() const; | 33 | QDateTime lastModified() const; |
34 | QPixmap* pixmap() const; | ||
32 | 35 | ||
33 | void setTitle(QString title); | 36 | void setTitle(QString title); |
34 | void setLastModified(QDateTime lastModified); | 37 | void setLastModified(QDateTime lastModified); |
35 | 38 | ||
39 | bool undoEnabled(); | ||
40 | bool redoEnabled(); | ||
41 | |||
42 | void backup(); | ||
43 | void undo(); | ||
44 | void redo(); | ||
45 | |||
36 | private: | 46 | private: |
37 | QString m_title; | 47 | QString m_title; |
38 | QDateTime m_lastModified; | 48 | QDateTime m_lastModified; |
49 | QPixmap* m_pPixmap; | ||
50 | |||
51 | QList<QPixmap> m_backHistory; | ||
52 | QList<QPixmap> m_forwardHistory; | ||
39 | }; | 53 | }; |
40 | 54 | ||
41 | #endif // PAGE_H | 55 | #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 | |||
@@ -38,20 +38,20 @@ PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const | |||
38 | m_pTitleLineEdit->setText(page->title()); | 38 | m_pTitleLineEdit->setText(page->title()); |
39 | 39 | ||
40 | QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox); | 40 | QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox); |
41 | QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox); | 41 | QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox); |
42 | 42 | ||
43 | QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this); | 43 | QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this); |
44 | 44 | ||
45 | QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox); | 45 | QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox); |
46 | QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->width()), sizeGroupBox); | 46 | QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->pixmap()->width()), sizeGroupBox); |
47 | 47 | ||
48 | QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox); | 48 | QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox); |
49 | QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->height()), sizeGroupBox); | 49 | QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->pixmap()->height()), sizeGroupBox); |
50 | 50 | ||
51 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 51 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
52 | generalGroupBox->layout()->setSpacing(4); | 52 | generalGroupBox->layout()->setSpacing(4); |
53 | sizeGroupBox->layout()->setSpacing(4); | 53 | sizeGroupBox->layout()->setSpacing(4); |
54 | QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2); | 54 | QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2); |
55 | QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); | 55 | QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); |
56 | 56 | ||
57 | generalLayout->addWidget(titleLabel, 0, 0); | 57 | generalLayout->addWidget(titleLabel, 0, 0); |
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 | |||
@@ -28,27 +28,27 @@ PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | |||
28 | } | 28 | } |
29 | 29 | ||
30 | PointTool::~PointTool() | 30 | PointTool::~PointTool() |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | void PointTool::mousePressEvent(QMouseEvent* e) | 34 | void PointTool::mousePressEvent(QMouseEvent* e) |
35 | { | 35 | { |
36 | m_pDrawPadCanvas->backupPage(); | ||
37 | |||
36 | m_mousePressed = true; | 38 | m_mousePressed = true; |
37 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 39 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
38 | } | 40 | } |
39 | 41 | ||
40 | void PointTool::mouseReleaseEvent(QMouseEvent* e) | 42 | void PointTool::mouseReleaseEvent(QMouseEvent* e) |
41 | { | 43 | { |
42 | Q_UNUSED(e) | 44 | Q_UNUSED(e) |
43 | 45 | ||
44 | m_mousePressed = false; | 46 | m_mousePressed = false; |
45 | |||
46 | m_pDrawPadCanvas->backupPage(); | ||
47 | } | 47 | } |
48 | 48 | ||
49 | void PointTool::mouseMoveEvent(QMouseEvent* e) | 49 | void PointTool::mouseMoveEvent(QMouseEvent* e) |
50 | { | 50 | { |
51 | if (m_mousePressed) { | 51 | if (m_mousePressed) { |
52 | m_polyline[2] = m_polyline[1]; | 52 | m_polyline[2] = m_polyline[1]; |
53 | m_polyline[1] = m_polyline[0]; | 53 | m_polyline[1] = m_polyline[0]; |
54 | m_polyline[0] = e->pos(); | 54 | m_polyline[0] = e->pos(); |
@@ -56,17 +56,17 @@ void PointTool::mouseMoveEvent(QMouseEvent* e) | |||
56 | QRect r = m_polyline.boundingRect(); | 56 | QRect r = m_polyline.boundingRect(); |
57 | r = r.normalize(); | 57 | r = r.normalize(); |
58 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 58 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
59 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 59 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
60 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 60 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
61 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 61 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
62 | 62 | ||
63 | QPainter painter; | 63 | QPainter painter; |
64 | painter.begin(m_pDrawPadCanvas->currentPage()); | 64 | painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); |
65 | 65 | ||
66 | if (m_pDrawPad->antiAliasing()) { | 66 | if (m_pDrawPad->antiAliasing()) { |
67 | QPixmap areaPixmap(r.width(), r.height()); | 67 | QPixmap areaPixmap(r.width(), r.height()); |
68 | bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); | 68 | bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); |
69 | 69 | ||
70 | QImage areaImage = areaPixmap.convertToImage(); | 70 | QImage areaImage = areaPixmap.convertToImage(); |
71 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | 71 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); |
72 | 72 | ||
@@ -99,13 +99,13 @@ void PointTool::mouseMoveEvent(QMouseEvent* e) | |||
99 | } | 99 | } |
100 | 100 | ||
101 | painter.end(); | 101 | painter.end(); |
102 | 102 | ||
103 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 103 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
104 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 104 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
105 | 105 | ||
106 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 106 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
107 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 107 | m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); |
108 | 108 | ||
109 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 109 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
110 | } | 110 | } |
111 | } | 111 | } |
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 | |||
@@ -27,68 +27,68 @@ ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | |||
27 | } | 27 | } |
28 | 28 | ||
29 | ShapeTool::~ShapeTool() | 29 | ShapeTool::~ShapeTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void ShapeTool::mousePressEvent(QMouseEvent* e) | 33 | void ShapeTool::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_pDrawPadCanvas->backupPage(); | ||
36 | |||
35 | m_mousePressed = true; | 37 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 38 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 39 | } |
38 | 40 | ||
39 | void ShapeTool::mouseReleaseEvent(QMouseEvent* e) | 41 | void ShapeTool::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 42 | { |
41 | Q_UNUSED(e) | 43 | Q_UNUSED(e) |
42 | 44 | ||
43 | QPainter painter; | 45 | QPainter painter; |
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | 46 | painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); |
45 | drawFinalShape(painter); | 47 | drawFinalShape(painter); |
46 | painter.end(); | 48 | painter.end(); |
47 | 49 | ||
48 | QRect r = m_polyline.boundingRect(); | 50 | QRect r = m_polyline.boundingRect(); |
49 | r = r.normalize(); | 51 | r = r.normalize(); |
50 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 52 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
51 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 53 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
52 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 54 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
53 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 55 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
54 | 56 | ||
55 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 57 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
56 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 58 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
57 | 59 | ||
58 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 60 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
59 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 61 | m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); |
60 | 62 | ||
61 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 63 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
62 | 64 | ||
63 | m_mousePressed = false; | 65 | m_mousePressed = false; |
64 | |||
65 | m_pDrawPadCanvas->backupPage(); | ||
66 | } | 66 | } |
67 | 67 | ||
68 | void ShapeTool::mouseMoveEvent(QMouseEvent* e) | 68 | void ShapeTool::mouseMoveEvent(QMouseEvent* e) |
69 | { | 69 | { |
70 | if (m_mousePressed) { | 70 | if (m_mousePressed) { |
71 | m_polyline[0] = e->pos(); | 71 | m_polyline[0] = e->pos(); |
72 | QPainter painter; | 72 | QPainter painter; |
73 | painter.begin(m_pDrawPadCanvas->currentPage()); | 73 | painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); |
74 | drawTemporaryShape(painter); | 74 | drawTemporaryShape(painter); |
75 | painter.end(); | 75 | painter.end(); |
76 | 76 | ||
77 | QRect r = m_polyline.boundingRect(); | 77 | QRect r = m_polyline.boundingRect(); |
78 | r = r.normalize(); | 78 | r = r.normalize(); |
79 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 79 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
80 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 80 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
81 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 81 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
82 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 82 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
83 | 83 | ||
84 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 84 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
85 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 85 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
86 | 86 | ||
87 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 87 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
88 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 88 | m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height()); |
89 | 89 | ||
90 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 90 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
91 | 91 | ||
92 | m_polyline[1] = m_polyline[0]; | 92 | m_polyline[1] = m_polyline[0]; |
93 | } | 93 | } |
94 | } | 94 | } |
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 | |||
@@ -51,25 +51,25 @@ TextTool::~TextTool() | |||
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void TextTool::mousePressEvent(QMouseEvent* e) | 54 | void TextTool::mousePressEvent(QMouseEvent* e) |
55 | { | 55 | { |
56 | TextToolDialog textToolDialog(m_pDrawPad); | 56 | TextToolDialog textToolDialog(m_pDrawPad); |
57 | 57 | ||
58 | if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { | 58 | if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { |
59 | m_pDrawPadCanvas->backupPage(); | ||
60 | |||
59 | QPainter painter; | 61 | QPainter painter; |
60 | painter.begin(m_pDrawPadCanvas->currentPage()); | 62 | painter.begin(m_pDrawPadCanvas->currentPage()->pixmap()); |
61 | painter.setPen(m_pDrawPad->pen()); | 63 | painter.setPen(m_pDrawPad->pen()); |
62 | painter.drawText(e->x(), e->y(), textToolDialog.text()); | 64 | painter.drawText(e->x(), e->y(), textToolDialog.text()); |
63 | painter.end(); | 65 | painter.end(); |
64 | 66 | ||
65 | m_pDrawPadCanvas->viewport()->update(); | 67 | m_pDrawPadCanvas->viewport()->update(); |
66 | |||
67 | m_pDrawPadCanvas->backupPage(); | ||
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | void TextTool::mouseReleaseEvent(QMouseEvent* e) | 71 | void TextTool::mouseReleaseEvent(QMouseEvent* e) |
72 | { | 72 | { |
73 | Q_UNUSED(e) | 73 | Q_UNUSED(e) |
74 | } | 74 | } |
75 | 75 | ||
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 | |||
@@ -30,17 +30,17 @@ | |||
30 | 30 | ||
31 | #define THUMBNAIL_SIZE 48 | 31 | #define THUMBNAIL_SIZE 48 |
32 | 32 | ||
33 | PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) | 33 | PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) |
34 | : QListBoxItem(parent) | 34 | : QListBoxItem(parent) |
35 | { | 35 | { |
36 | m_pPage = page; | 36 | m_pPage = page; |
37 | 37 | ||
38 | QImage image = m_pPage->convertToImage(); | 38 | QImage image = m_pPage->pixmap()->convertToImage(); |
39 | 39 | ||
40 | int previewWidth = THUMBNAIL_SIZE; | 40 | int previewWidth = THUMBNAIL_SIZE; |
41 | int previewHeight = THUMBNAIL_SIZE; | 41 | int previewHeight = THUMBNAIL_SIZE; |
42 | 42 | ||
43 | float widthScale = 1.0; | 43 | float widthScale = 1.0; |
44 | float heightScale = 1.0; | 44 | float heightScale = 1.0; |
45 | 45 | ||
46 | if (previewWidth < image.width()) { | 46 | if (previewWidth < image.width()) { |
@@ -52,18 +52,18 @@ PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) | |||
52 | } | 52 | } |
53 | 53 | ||
54 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 54 | float scale = (widthScale < heightScale ? widthScale : heightScale); |
55 | QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | 55 | QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); |
56 | 56 | ||
57 | m_thumbnail.convertFromImage(thumbnailImage); | 57 | m_thumbnail.convertFromImage(thumbnailImage); |
58 | 58 | ||
59 | m_titleText = QObject::tr("Title:") + " " + m_pPage->title(); | 59 | m_titleText = QObject::tr("Title:") + " " + m_pPage->title(); |
60 | m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width()) | 60 | m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->pixmap()->width()) |
61 | + "x" + QString::number(m_pPage->height()); | 61 | + "x" + QString::number(m_pPage->pixmap()->height()); |
62 | m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified()); | 62 | m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified()); |
63 | 63 | ||
64 | QColor baseColor = parent->colorGroup().base(); | 64 | QColor baseColor = parent->colorGroup().base(); |
65 | int h, s, v; | 65 | int h, s, v; |
66 | baseColor.hsv(&h, &s, &v); | 66 | baseColor.hsv(&h, &s, &v); |
67 | 67 | ||
68 | if (v > 128) { | 68 | if (v > 128) { |
69 | m_alternateColor = baseColor.dark(115); | 69 | m_alternateColor = baseColor.dark(115); |