author | leseb <leseb> | 2002-06-08 12:48:01 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-08 12:48:01 (UTC) |
commit | 571908b989a85d256767dc5b27bccdb717554bb5 (patch) (unidiff) | |
tree | 09149eb5ed82683020ebd9372635d4d0233982a3 | |
parent | 9dcd598f9b815511cae884d26b18e3c8913b9fcf (diff) | |
download | opie-571908b989a85d256767dc5b27bccdb717554bb5.zip opie-571908b989a85d256767dc5b27bccdb717554bb5.tar.gz opie-571908b989a85d256767dc5b27bccdb717554bb5.tar.bz2 |
Selection and delete now work in thumbnail view
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 13 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 1 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 27 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 2 |
4 files changed, 42 insertions, 1 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 252f4d5..0a1e9a5 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -234,192 +234,205 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
234 | imageIO.setImage(image); | 234 | imageIO.setImage(image); |
235 | imageIO.write(); | 235 | imageIO.write(); |
236 | buffer.close(); | 236 | buffer.close(); |
237 | 237 | ||
238 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; | 238 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; |
239 | 239 | ||
240 | static const char hexchars[] = "0123456789abcdef"; | 240 | static const char hexchars[] = "0123456789abcdef"; |
241 | 241 | ||
242 | for (int i = 0; i < (int)byteArray.size(); i++ ) { | 242 | for (int i = 0; i < (int)byteArray.size(); i++ ) { |
243 | uchar s = (uchar)byteArray[i]; | 243 | uchar s = (uchar)byteArray[i]; |
244 | textStream << hexchars[s >> 4]; | 244 | textStream << hexchars[s >> 4]; |
245 | textStream << hexchars[s & 0x0f]; | 245 | textStream << hexchars[s & 0x0f]; |
246 | } | 246 | } |
247 | 247 | ||
248 | textStream << "</data>" << endl; | 248 | textStream << "</data>" << endl; |
249 | textStream << " </image>" << endl; | 249 | textStream << " </image>" << endl; |
250 | } | 250 | } |
251 | 251 | ||
252 | textStream << " </images>" << endl; | 252 | textStream << " </images>" << endl; |
253 | textStream << "</drawpad>"; | 253 | textStream << "</drawpad>"; |
254 | } | 254 | } |
255 | 255 | ||
256 | void DrawPadCanvas::importPage(const QString& fileName) | 256 | void DrawPadCanvas::importPage(const QString& fileName) |
257 | { | 257 | { |
258 | Page* importedPage = new Page(); | 258 | Page* importedPage = new Page(); |
259 | 259 | ||
260 | importedPage->load(fileName); | 260 | importedPage->load(fileName); |
261 | m_pages.insert(m_pages.at() + 1, importedPage); | 261 | m_pages.insert(m_pages.at() + 1, importedPage); |
262 | 262 | ||
263 | m_pageBackups.clear(); | 263 | m_pageBackups.clear(); |
264 | m_pageBackups.append(new Page(*(m_pages.current()))); | 264 | m_pageBackups.append(new Page(*(m_pages.current()))); |
265 | 265 | ||
266 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 266 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
267 | viewport()->update(); | 267 | viewport()->update(); |
268 | 268 | ||
269 | emit pagesChanged(); | 269 | emit pagesChanged(); |
270 | emit pageBackupsChanged(); | 270 | emit pageBackupsChanged(); |
271 | } | 271 | } |
272 | 272 | ||
273 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 273 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
274 | { | 274 | { |
275 | if (fromPage == toPage) { | 275 | if (fromPage == toPage) { |
276 | DocLnk docLnk; | 276 | DocLnk docLnk; |
277 | MimeType mimeType(format); | 277 | MimeType mimeType(format); |
278 | 278 | ||
279 | docLnk.setName(name); | 279 | docLnk.setName(name); |
280 | docLnk.setType(mimeType.id()); | 280 | docLnk.setType(mimeType.id()); |
281 | 281 | ||
282 | FileManager fileManager; | 282 | FileManager fileManager; |
283 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 283 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
284 | QImageIO imageIO(ioDevice, format); | 284 | QImageIO imageIO(ioDevice, format); |
285 | 285 | ||
286 | QImage image = m_pages.current()->convertToImage(); | 286 | QImage image = m_pages.current()->convertToImage(); |
287 | imageIO.setImage(image); | 287 | imageIO.setImage(image); |
288 | imageIO.write(); | 288 | imageIO.write(); |
289 | delete ioDevice; | 289 | delete ioDevice; |
290 | } else { | 290 | } else { |
291 | for (uint i = fromPage; i <= toPage; i++) { | 291 | for (uint i = fromPage; i <= toPage; i++) { |
292 | DocLnk docLnk; | 292 | DocLnk docLnk; |
293 | MimeType mimeType(format); | 293 | MimeType mimeType(format); |
294 | 294 | ||
295 | docLnk.setName(name + QString::number(i)); | 295 | docLnk.setName(name + QString::number(i)); |
296 | docLnk.setType(mimeType.id()); | 296 | docLnk.setType(mimeType.id()); |
297 | 297 | ||
298 | FileManager fileManager; | 298 | FileManager fileManager; |
299 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 299 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
300 | QImageIO imageIO(ioDevice, format); | 300 | QImageIO imageIO(ioDevice, format); |
301 | 301 | ||
302 | QImage image = m_pages.at(i - 1)->convertToImage(); | 302 | QImage image = m_pages.at(i - 1)->convertToImage(); |
303 | imageIO.setImage(image); | 303 | imageIO.setImage(image); |
304 | imageIO.write(); | 304 | imageIO.write(); |
305 | delete ioDevice; | 305 | delete ioDevice; |
306 | } | 306 | } |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | Page* DrawPadCanvas::currentPage() | 310 | Page* DrawPadCanvas::currentPage() |
311 | { | 311 | { |
312 | return m_pages.current(); | 312 | return m_pages.current(); |
313 | } | 313 | } |
314 | 314 | ||
315 | QList<Page> DrawPadCanvas::pages() | 315 | QList<Page> DrawPadCanvas::pages() |
316 | { | 316 | { |
317 | return m_pages; | 317 | return m_pages; |
318 | } | 318 | } |
319 | 319 | ||
320 | uint DrawPadCanvas::pagePosition() | 320 | uint DrawPadCanvas::pagePosition() |
321 | { | 321 | { |
322 | return (m_pages.at() + 1); | 322 | return (m_pages.at() + 1); |
323 | } | 323 | } |
324 | 324 | ||
325 | uint DrawPadCanvas::pageCount() | 325 | uint DrawPadCanvas::pageCount() |
326 | { | 326 | { |
327 | return m_pages.count(); | 327 | return m_pages.count(); |
328 | } | 328 | } |
329 | 329 | ||
330 | void DrawPadCanvas::selectPage(Page* page) | ||
331 | { | ||
332 | m_pages.findRef(page); | ||
333 | m_pageBackups.clear(); | ||
334 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
335 | |||
336 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
337 | viewport()->update(); | ||
338 | |||
339 | emit pagesChanged(); | ||
340 | emit pageBackupsChanged(); | ||
341 | } | ||
342 | |||
330 | void DrawPadCanvas::backupPage() | 343 | void DrawPadCanvas::backupPage() |
331 | { | 344 | { |
332 | QPixmap* currentBackup = m_pageBackups.current(); | 345 | QPixmap* currentBackup = m_pageBackups.current(); |
333 | while (m_pageBackups.last() != currentBackup) { | 346 | while (m_pageBackups.last() != currentBackup) { |
334 | m_pageBackups.removeLast(); | 347 | m_pageBackups.removeLast(); |
335 | } | 348 | } |
336 | 349 | ||
337 | while (m_pageBackups.count() >= (5 + 1)) { | 350 | while (m_pageBackups.count() >= (5 + 1)) { |
338 | m_pageBackups.removeFirst(); | 351 | m_pageBackups.removeFirst(); |
339 | } | 352 | } |
340 | 353 | ||
341 | m_pageBackups.append(new Page(*(m_pages.current()))); | 354 | m_pageBackups.append(new Page(*(m_pages.current()))); |
342 | 355 | ||
343 | emit pageBackupsChanged(); | 356 | emit pageBackupsChanged(); |
344 | } | 357 | } |
345 | 358 | ||
346 | void DrawPadCanvas::deleteAll() | 359 | void DrawPadCanvas::deleteAll() |
347 | { | 360 | { |
348 | m_pages.clear(); | 361 | m_pages.clear(); |
349 | 362 | ||
350 | m_pages.append(new Page(contentsRect().size())); | 363 | m_pages.append(new Page(contentsRect().size())); |
351 | m_pages.current()->fill(Qt::white); | 364 | m_pages.current()->fill(Qt::white); |
352 | 365 | ||
353 | m_pageBackups.clear(); | 366 | m_pageBackups.clear(); |
354 | m_pageBackups.append(new Page(*(m_pages.current()))); | 367 | m_pageBackups.append(new Page(*(m_pages.current()))); |
355 | 368 | ||
356 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 369 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
357 | viewport()->update(); | 370 | viewport()->update(); |
358 | 371 | ||
359 | emit pagesChanged(); | 372 | emit pagesChanged(); |
360 | emit pageBackupsChanged(); | 373 | emit pageBackupsChanged(); |
361 | } | 374 | } |
362 | 375 | ||
363 | void DrawPadCanvas::newPage() | 376 | void DrawPadCanvas::newPage() |
364 | { | 377 | { |
365 | QRect rect = contentsRect(); | 378 | QRect rect = contentsRect(); |
366 | 379 | ||
367 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), | 380 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
368 | m_pDrawPad->brush().color(), this); | 381 | m_pDrawPad->brush().color(), this); |
369 | 382 | ||
370 | if (newPageDialog.exec() == QDialog::Accepted) { | 383 | if (newPageDialog.exec() == QDialog::Accepted) { |
371 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), | 384 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), |
372 | newPageDialog.selectedHeight())); | 385 | newPageDialog.selectedHeight())); |
373 | m_pages.current()->fill(newPageDialog.selectedColor()); | 386 | m_pages.current()->fill(newPageDialog.selectedColor()); |
374 | 387 | ||
375 | m_pageBackups.clear(); | 388 | m_pageBackups.clear(); |
376 | m_pageBackups.append(new Page(*(m_pages.current()))); | 389 | m_pageBackups.append(new Page(*(m_pages.current()))); |
377 | 390 | ||
378 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 391 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
379 | viewport()->update(); | 392 | viewport()->update(); |
380 | 393 | ||
381 | emit pagesChanged(); | 394 | emit pagesChanged(); |
382 | emit pageBackupsChanged(); | 395 | emit pageBackupsChanged(); |
383 | } | 396 | } |
384 | } | 397 | } |
385 | 398 | ||
386 | void DrawPadCanvas::clearPage() | 399 | void DrawPadCanvas::clearPage() |
387 | { | 400 | { |
388 | m_pages.current()->fill(Qt::white); | 401 | m_pages.current()->fill(Qt::white); |
389 | 402 | ||
390 | viewport()->update(); | 403 | viewport()->update(); |
391 | } | 404 | } |
392 | 405 | ||
393 | void DrawPadCanvas::deletePage() | 406 | void DrawPadCanvas::deletePage() |
394 | { | 407 | { |
395 | m_pages.remove(m_pages.current()); | 408 | m_pages.remove(m_pages.current()); |
396 | 409 | ||
397 | if (m_pages.isEmpty()) { | 410 | if (m_pages.isEmpty()) { |
398 | m_pages.append(new Page(contentsRect().size())); | 411 | m_pages.append(new Page(contentsRect().size())); |
399 | m_pages.current()->fill(Qt::white); | 412 | m_pages.current()->fill(Qt::white); |
400 | } | 413 | } |
401 | 414 | ||
402 | m_pageBackups.clear(); | 415 | m_pageBackups.clear(); |
403 | m_pageBackups.append(new Page(*(m_pages.current()))); | 416 | m_pageBackups.append(new Page(*(m_pages.current()))); |
404 | 417 | ||
405 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 418 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
406 | viewport()->update(); | 419 | viewport()->update(); |
407 | 420 | ||
408 | emit pagesChanged(); | 421 | emit pagesChanged(); |
409 | emit pageBackupsChanged(); | 422 | emit pageBackupsChanged(); |
410 | } | 423 | } |
411 | 424 | ||
412 | bool DrawPadCanvas::undoEnabled() | 425 | bool DrawPadCanvas::undoEnabled() |
413 | { | 426 | { |
414 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 427 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
415 | } | 428 | } |
416 | 429 | ||
417 | bool DrawPadCanvas::redoEnabled() | 430 | bool DrawPadCanvas::redoEnabled() |
418 | { | 431 | { |
419 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 432 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
420 | } | 433 | } |
421 | 434 | ||
422 | bool DrawPadCanvas::goPreviousPageEnabled() | 435 | bool DrawPadCanvas::goPreviousPageEnabled() |
423 | { | 436 | { |
424 | return (m_pages.current() != m_pages.getFirst()); | 437 | return (m_pages.current() != m_pages.getFirst()); |
425 | } | 438 | } |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 47763f9..cf2d904 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h | |||
@@ -1,82 +1,83 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
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 | #ifndef DRAWPADCANVAS_H | 14 | #ifndef DRAWPADCANVAS_H |
15 | #define DRAWPADCANVAS_H | 15 | #define DRAWPADCANVAS_H |
16 | 16 | ||
17 | #include <qscrollview.h> | 17 | #include <qscrollview.h> |
18 | 18 | ||
19 | #include <qlist.h> | 19 | #include <qlist.h> |
20 | #include <qpointarray.h> | 20 | #include <qpointarray.h> |
21 | 21 | ||
22 | class DrawPad; | 22 | class DrawPad; |
23 | class Page; | 23 | class Page; |
24 | 24 | ||
25 | class DrawPadCanvas : public QScrollView | 25 | class DrawPadCanvas : public QScrollView |
26 | { | 26 | { |
27 | Q_OBJECT | 27 | Q_OBJECT |
28 | 28 | ||
29 | public: | 29 | public: |
30 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); | 30 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); |
31 | ~DrawPadCanvas(); | 31 | ~DrawPadCanvas(); |
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(); | 40 | bool undoEnabled(); |
41 | bool redoEnabled(); | 41 | bool redoEnabled(); |
42 | bool goPreviousPageEnabled(); | 42 | bool goPreviousPageEnabled(); |
43 | bool goNextPageEnabled(); | 43 | bool goNextPageEnabled(); |
44 | 44 | ||
45 | Page* currentPage(); | 45 | Page* currentPage(); |
46 | QList<Page> pages(); | 46 | QList<Page> pages(); |
47 | uint pagePosition(); | 47 | uint pagePosition(); |
48 | uint pageCount(); | 48 | uint pageCount(); |
49 | 49 | ||
50 | void selectPage(Page* page); | ||
50 | void backupPage(); | 51 | void backupPage(); |
51 | 52 | ||
52 | public slots: | 53 | public slots: |
53 | void deleteAll(); | 54 | void deleteAll(); |
54 | void newPage(); | 55 | void newPage(); |
55 | void clearPage(); | 56 | void clearPage(); |
56 | void deletePage(); | 57 | void deletePage(); |
57 | 58 | ||
58 | void undo(); | 59 | void undo(); |
59 | void redo(); | 60 | void redo(); |
60 | 61 | ||
61 | void goFirstPage(); | 62 | void goFirstPage(); |
62 | void goPreviousPage(); | 63 | void goPreviousPage(); |
63 | void goNextPage(); | 64 | void goNextPage(); |
64 | void goLastPage(); | 65 | void goLastPage(); |
65 | 66 | ||
66 | signals: | 67 | signals: |
67 | void pagesChanged(); | 68 | void pagesChanged(); |
68 | void pageBackupsChanged(); | 69 | void pageBackupsChanged(); |
69 | 70 | ||
70 | protected: | 71 | protected: |
71 | void contentsMousePressEvent(QMouseEvent* e); | 72 | void contentsMousePressEvent(QMouseEvent* e); |
72 | void contentsMouseReleaseEvent(QMouseEvent* e); | 73 | void contentsMouseReleaseEvent(QMouseEvent* e); |
73 | void contentsMouseMoveEvent(QMouseEvent* e); | 74 | void contentsMouseMoveEvent(QMouseEvent* e); |
74 | 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); |
75 | 76 | ||
76 | private: | 77 | private: |
77 | DrawPad* m_pDrawPad; | 78 | DrawPad* m_pDrawPad; |
78 | QList<Page> m_pages; | 79 | QList<Page> m_pages; |
79 | QList<Page> m_pageBackups; | 80 | QList<Page> m_pageBackups; |
80 | }; | 81 | }; |
81 | 82 | ||
82 | #endif // DRAWPADCANVAS_H | 83 | #endif // DRAWPADCANVAS_H |
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 1754ce9..476b7b9 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -7,205 +7,230 @@ | |||
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 "thumbnailview.h" | 14 | #include "thumbnailview.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | 16 | #include "drawpadcanvas.h" |
17 | #include "page.h" | 17 | #include "page.h" |
18 | 18 | ||
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | 20 | ||
21 | #include <qapplication.h> | 21 | #include <qapplication.h> |
22 | #include <qheader.h> | 22 | #include <qheader.h> |
23 | #include <qimage.h> | 23 | #include <qimage.h> |
24 | #include <qlayout.h> | 24 | #include <qlayout.h> |
25 | #include <qmessagebox.h> | 25 | #include <qmessagebox.h> |
26 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
27 | 27 | ||
28 | PageListViewItem::PageListViewItem(Page* page, QListView* parent) | 28 | PageListViewItem::PageListViewItem(Page* page, QListView* parent) |
29 | : QListViewItem(parent) | 29 | : QListViewItem(parent) |
30 | { | 30 | { |
31 | m_pPage = page; | 31 | m_pPage = page; |
32 | 32 | ||
33 | QImage image = m_pPage->convertToImage(); | 33 | QImage image = m_pPage->convertToImage(); |
34 | 34 | ||
35 | int previewWidth = 64; | 35 | int previewWidth = 64; |
36 | int previewHeight = 64; | 36 | int previewHeight = 64; |
37 | 37 | ||
38 | float widthScale = 1.0; | 38 | float widthScale = 1.0; |
39 | float heightScale = 1.0; | 39 | float heightScale = 1.0; |
40 | 40 | ||
41 | if (previewWidth < image.width()) { | 41 | if (previewWidth < image.width()) { |
42 | widthScale = (float)previewWidth / float(image.width()); | 42 | widthScale = (float)previewWidth / float(image.width()); |
43 | } | 43 | } |
44 | 44 | ||
45 | if (previewHeight < image.height()) { | 45 | if (previewHeight < image.height()) { |
46 | heightScale = (float)previewHeight / float(image.height()); | 46 | heightScale = (float)previewHeight / float(image.height()); |
47 | } | 47 | } |
48 | 48 | ||
49 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 49 | float scale = (widthScale < heightScale ? widthScale : heightScale); |
50 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | 50 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); |
51 | 51 | ||
52 | QPixmap previewPixmap; | 52 | QPixmap previewPixmap; |
53 | previewPixmap.convertFromImage(previewImage); | 53 | previewPixmap.convertFromImage(previewImage); |
54 | 54 | ||
55 | QPixmap pixmap(64, 64); | 55 | QPixmap pixmap(64, 64); |
56 | 56 | ||
57 | pixmap.fill(listView()->colorGroup().mid()); | 57 | pixmap.fill(listView()->colorGroup().mid()); |
58 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | 58 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, |
59 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | 59 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); |
60 | 60 | ||
61 | setPixmap(0, pixmap); | 61 | setPixmap(0, pixmap); |
62 | } | 62 | } |
63 | 63 | ||
64 | PageListViewItem::~PageListViewItem() | 64 | PageListViewItem::~PageListViewItem() |
65 | { | 65 | { |
66 | } | 66 | } |
67 | 67 | ||
68 | Page* PageListViewItem::page() const | 68 | Page* PageListViewItem::page() const |
69 | { | 69 | { |
70 | return m_pPage; | 70 | return m_pPage; |
71 | } | 71 | } |
72 | 72 | ||
73 | PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | 73 | PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) |
74 | : QListView(parent, name) | 74 | : QListView(parent, name) |
75 | { | 75 | { |
76 | m_pDrawPadCanvas = drawPadCanvas; | 76 | m_pDrawPadCanvas = drawPadCanvas; |
77 | 77 | ||
78 | header()->hide(); | 78 | header()->hide(); |
79 | setVScrollBarMode(QScrollView::AlwaysOn); | 79 | setVScrollBarMode(QScrollView::AlwaysOn); |
80 | setAllColumnsShowFocus(true); | 80 | setAllColumnsShowFocus(true); |
81 | 81 | ||
82 | addColumn(tr("Thumbnail")); | 82 | addColumn(tr("Thumbnail")); |
83 | addColumn(tr("Information")); | 83 | addColumn(tr("Information")); |
84 | 84 | ||
85 | updateView(); | 85 | updateView(); |
86 | } | 86 | } |
87 | 87 | ||
88 | PageListView::~PageListView() | 88 | PageListView::~PageListView() |
89 | { | 89 | { |
90 | } | 90 | } |
91 | 91 | ||
92 | void PageListView::updateView() | 92 | void PageListView::updateView() |
93 | { | 93 | { |
94 | clear(); | 94 | clear(); |
95 | 95 | ||
96 | if (m_pDrawPadCanvas) { | 96 | if (m_pDrawPadCanvas) { |
97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); | 97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); |
98 | QListIterator<Page> it(pageList); | 98 | QListIterator<Page> it(pageList); |
99 | 99 | ||
100 | for (; it.current(); ++it) { | 100 | for (; it.current(); ++it) { |
101 | new PageListViewItem(it.current(), this); | 101 | new PageListViewItem(it.current(), this); |
102 | } | 102 | } |
103 | |||
104 | setSorting(0, false); | ||
105 | select(m_pDrawPadCanvas->currentPage()); | ||
103 | } | 106 | } |
104 | } | 107 | } |
105 | 108 | ||
106 | void PageListView::resizeEvent(QResizeEvent* e) | 109 | void PageListView::resizeEvent(QResizeEvent* e) |
107 | { | 110 | { |
108 | Q_UNUSED(e); | 111 | Q_UNUSED(e); |
109 | 112 | ||
110 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); | 113 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); |
111 | } | 114 | } |
112 | 115 | ||
116 | void PageListView::select(Page* page) | ||
117 | { | ||
118 | PageListViewItem* item = (PageListViewItem*)firstChild(); | ||
119 | |||
120 | while (item) { | ||
121 | if (item->page() == page) { | ||
122 | setSelected(item, true); | ||
123 | ensureItemVisible(item); | ||
124 | break; | ||
125 | } | ||
126 | |||
127 | item = (PageListViewItem*)(item->nextSibling()); | ||
128 | } | ||
129 | } | ||
130 | |||
113 | Page* PageListView::selected() const | 131 | Page* PageListView::selected() const |
114 | { | 132 | { |
115 | Page* page; | 133 | Page* page; |
116 | 134 | ||
117 | PageListViewItem* item = (PageListViewItem*)selectedItem(); | 135 | PageListViewItem* item = (PageListViewItem*)selectedItem(); |
118 | 136 | ||
119 | if (item) { | 137 | if (item) { |
120 | page = item->page(); | 138 | page = item->page(); |
121 | } else { | 139 | } else { |
122 | page = NULL; | 140 | page = NULL; |
123 | } | 141 | } |
124 | 142 | ||
125 | return page; | 143 | return page; |
126 | } | 144 | } |
127 | 145 | ||
128 | |||
129 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | 146 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) |
130 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) | 147 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) |
131 | { | 148 | { |
132 | inLoop = false; | 149 | inLoop = false; |
133 | m_pDrawPadCanvas = drawPadCanvas; | 150 | m_pDrawPadCanvas = drawPadCanvas; |
134 | 151 | ||
135 | setCaption(tr("Thumbnail")); | 152 | setCaption(tr("Thumbnail")); |
136 | 153 | ||
137 | QToolButton* newPageButton = new QToolButton(this); | 154 | QToolButton* newPageButton = new QToolButton(this); |
138 | newPageButton->setIconSet(Resource::loadIconSet("new")); | 155 | newPageButton->setIconSet(Resource::loadIconSet("new")); |
139 | newPageButton->setAutoRaise(true); | 156 | newPageButton->setAutoRaise(true); |
140 | 157 | ||
141 | QToolButton* clearPageButton = new QToolButton(this); | 158 | QToolButton* clearPageButton = new QToolButton(this); |
142 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | 159 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); |
143 | clearPageButton->setAutoRaise(true); | 160 | clearPageButton->setAutoRaise(true); |
144 | 161 | ||
145 | QToolButton* deletePageButton = new QToolButton(this); | 162 | QToolButton* deletePageButton = new QToolButton(this); |
146 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | 163 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); |
147 | deletePageButton->setAutoRaise(true); | 164 | deletePageButton->setAutoRaise(true); |
165 | connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); | ||
148 | 166 | ||
149 | QToolButton* movePageUpButton = new QToolButton(this); | 167 | QToolButton* movePageUpButton = new QToolButton(this); |
150 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | 168 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); |
151 | movePageUpButton->setAutoRaise(true); | 169 | movePageUpButton->setAutoRaise(true); |
152 | 170 | ||
153 | QToolButton* movePageDownButton = new QToolButton(this); | 171 | QToolButton* movePageDownButton = new QToolButton(this); |
154 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | 172 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); |
155 | movePageDownButton->setAutoRaise(true); | 173 | movePageDownButton->setAutoRaise(true); |
156 | 174 | ||
157 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); | 175 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); |
176 | connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage())); | ||
158 | 177 | ||
159 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 178 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
160 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | 179 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); |
161 | 180 | ||
162 | buttonLayout->addWidget(newPageButton); | 181 | buttonLayout->addWidget(newPageButton); |
163 | buttonLayout->addWidget(clearPageButton); | 182 | buttonLayout->addWidget(clearPageButton); |
164 | buttonLayout->addWidget(deletePageButton); | 183 | buttonLayout->addWidget(deletePageButton); |
165 | buttonLayout->addStretch(); | 184 | buttonLayout->addStretch(); |
166 | buttonLayout->addWidget(movePageUpButton); | 185 | buttonLayout->addWidget(movePageUpButton); |
167 | buttonLayout->addWidget(movePageDownButton); | 186 | buttonLayout->addWidget(movePageDownButton); |
168 | 187 | ||
169 | mainLayout->addLayout(buttonLayout); | 188 | mainLayout->addLayout(buttonLayout); |
170 | mainLayout->addWidget(m_pPageListView); | 189 | mainLayout->addWidget(m_pPageListView); |
171 | } | 190 | } |
172 | 191 | ||
173 | ThumbnailView::~ThumbnailView() | 192 | ThumbnailView::~ThumbnailView() |
174 | { | 193 | { |
175 | hide(); | 194 | hide(); |
176 | } | 195 | } |
177 | 196 | ||
178 | void ThumbnailView::hide() | 197 | void ThumbnailView::hide() |
179 | { | 198 | { |
180 | QWidget::hide(); | 199 | QWidget::hide(); |
181 | 200 | ||
182 | if (inLoop) { | 201 | if (inLoop) { |
183 | inLoop = false; | 202 | inLoop = false; |
184 | qApp->exit_loop(); | 203 | qApp->exit_loop(); |
185 | } | 204 | } |
186 | } | 205 | } |
187 | 206 | ||
188 | void ThumbnailView::exec() | 207 | void ThumbnailView::exec() |
189 | { | 208 | { |
190 | show(); | 209 | show(); |
191 | 210 | ||
192 | if (!inLoop) { | 211 | if (!inLoop) { |
193 | inLoop = true; | 212 | inLoop = true; |
194 | qApp->enter_loop(); | 213 | qApp->enter_loop(); |
195 | } | 214 | } |
196 | } | 215 | } |
197 | 216 | ||
198 | void ThumbnailView::deletePage() | 217 | void ThumbnailView::deletePage() |
199 | { | 218 | { |
200 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), | 219 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), |
201 | QMessageBox::Information, QMessageBox::Yes, | 220 | QMessageBox::Information, QMessageBox::Yes, |
202 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 221 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
203 | QMessageBox::NoButton, this); | 222 | QMessageBox::NoButton, this); |
204 | 223 | ||
205 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 224 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
206 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 225 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
207 | 226 | ||
208 | if (messageBox.exec() == QMessageBox::Yes) { | 227 | if (messageBox.exec() == QMessageBox::Yes) { |
209 | m_pDrawPadCanvas->deletePage(); | 228 | m_pDrawPadCanvas->deletePage(); |
229 | m_pPageListView->updateView(); | ||
210 | } | 230 | } |
211 | } | 231 | } |
232 | |||
233 | void ThumbnailView::changePage() | ||
234 | { | ||
235 | m_pDrawPadCanvas->selectPage(m_pPageListView->selected()); | ||
236 | } | ||
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h index ae97ff1..9417655 100644 --- a/noncore/graphics/drawpad/thumbnailview.h +++ b/noncore/graphics/drawpad/thumbnailview.h | |||
@@ -1,73 +1,75 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
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 | #ifndef THUMBNAILVIEW_H | 14 | #ifndef THUMBNAILVIEW_H |
15 | #define THUMBNAILVIEW_H | 15 | #define THUMBNAILVIEW_H |
16 | 16 | ||
17 | #include <qwidget.h> | 17 | #include <qwidget.h> |
18 | #include <qlistview.h> | 18 | #include <qlistview.h> |
19 | 19 | ||
20 | class DrawPadCanvas; | 20 | class DrawPadCanvas; |
21 | class Page; | 21 | class Page; |
22 | 22 | ||
23 | class PageListViewItem : public QListViewItem | 23 | class PageListViewItem : public QListViewItem |
24 | { | 24 | { |
25 | public: | 25 | public: |
26 | PageListViewItem(Page* page, QListView* parent); | 26 | PageListViewItem(Page* page, QListView* parent); |
27 | ~PageListViewItem(); | 27 | ~PageListViewItem(); |
28 | 28 | ||
29 | Page* page() const; | 29 | Page* page() const; |
30 | 30 | ||
31 | private: | 31 | private: |
32 | Page* m_pPage; | 32 | Page* m_pPage; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | class PageListView : public QListView | 35 | class PageListView : public QListView |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | 38 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
39 | ~PageListView(); | 39 | ~PageListView(); |
40 | 40 | ||
41 | void updateView(); | 41 | void updateView(); |
42 | 42 | ||
43 | void select(Page* page); | ||
43 | Page* selected() const; | 44 | Page* selected() const; |
44 | 45 | ||
45 | protected: | 46 | protected: |
46 | void resizeEvent(QResizeEvent* e); | 47 | void resizeEvent(QResizeEvent* e); |
47 | 48 | ||
48 | private: | 49 | private: |
49 | DrawPadCanvas* m_pDrawPadCanvas; | 50 | DrawPadCanvas* m_pDrawPadCanvas; |
50 | }; | 51 | }; |
51 | 52 | ||
52 | class ThumbnailView : public QWidget | 53 | class ThumbnailView : public QWidget |
53 | { | 54 | { |
54 | Q_OBJECT | 55 | Q_OBJECT |
55 | 56 | ||
56 | public: | 57 | public: |
57 | ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | 58 | ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
58 | ~ThumbnailView(); | 59 | ~ThumbnailView(); |
59 | 60 | ||
60 | void hide(); | 61 | void hide(); |
61 | void exec(); | 62 | void exec(); |
62 | 63 | ||
63 | public slots: | 64 | public slots: |
64 | void deletePage(); | 65 | void deletePage(); |
66 | void changePage(); | ||
65 | 67 | ||
66 | private: | 68 | private: |
67 | bool inLoop; | 69 | bool inLoop; |
68 | DrawPadCanvas* m_pDrawPadCanvas; | 70 | DrawPadCanvas* m_pDrawPadCanvas; |
69 | 71 | ||
70 | PageListView* m_pPageListView; | 72 | PageListView* m_pPageListView; |
71 | }; | 73 | }; |
72 | 74 | ||
73 | #endif // THUMBNAILVIEW_H | 75 | #endif // THUMBNAILVIEW_H |