author | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
commit | 9dcd598f9b815511cae884d26b18e3c8913b9fcf (patch) (unidiff) | |
tree | 4b18e7fa7c864b2dca4da76bc89c2a975e80a73c /noncore/graphics/drawpad | |
parent | 640d964cfdc7467f6cacb513087cd3acda2c04f0 (diff) | |
download | opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.zip opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.gz opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.bz2 |
Make progress in thumbnail view
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 54 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 31 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 184 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 51 |
5 files changed, 233 insertions, 91 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index b325323..58c0d09 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -29,24 +29,25 @@ | |||
29 | 29 | ||
30 | #include <opie/colordialog.h> | 30 | #include <opie/colordialog.h> |
31 | #include <opie/colorpopupmenu.h> | 31 | #include <opie/colorpopupmenu.h> |
32 | 32 | ||
33 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
34 | #include <qpe/global.h> | 34 | #include <qpe/global.h> |
35 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
36 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | 38 | ||
39 | #include <qaction.h> | 39 | #include <qaction.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qmessagebox.h> | ||
41 | #include <qpainter.h> | 42 | #include <qpainter.h> |
42 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
43 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
44 | #include <qtooltip.h> | 45 | #include <qtooltip.h> |
45 | 46 | ||
46 | DrawPad::DrawPad(QWidget* parent, const char* name) | 47 | DrawPad::DrawPad(QWidget* parent, const char* name) |
47 | : QMainWindow(parent, name) | 48 | : QMainWindow(parent, name) |
48 | { | 49 | { |
49 | // init members | 50 | // init members |
50 | 51 | ||
51 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 52 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
52 | 53 | ||
@@ -57,25 +58,25 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
57 | setCentralWidget(m_pDrawPadCanvas); | 58 | setCentralWidget(m_pDrawPadCanvas); |
58 | 59 | ||
59 | // init menu | 60 | // init menu |
60 | 61 | ||
61 | setToolBarsMovable(false); | 62 | setToolBarsMovable(false); |
62 | 63 | ||
63 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 64 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
64 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 65 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
65 | 66 | ||
66 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 67 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
67 | 68 | ||
68 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); | 69 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); |
69 | connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll())); | 70 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); |
70 | deleteAllAction->addTo(toolsPopupMenu); | 71 | deleteAllAction->addTo(toolsPopupMenu); |
71 | 72 | ||
72 | toolsPopupMenu->insertSeparator(); | 73 | toolsPopupMenu->insertSeparator(); |
73 | 74 | ||
74 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); | 75 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); |
75 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); | 76 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); |
76 | importPageAction->addTo(toolsPopupMenu); | 77 | importPageAction->addTo(toolsPopupMenu); |
77 | 78 | ||
78 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); | 79 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); |
79 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); | 80 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); |
80 | exportPageAction->addTo(toolsPopupMenu); | 81 | exportPageAction->addTo(toolsPopupMenu); |
81 | 82 | ||
@@ -87,29 +88,29 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
87 | 88 | ||
88 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 89 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
89 | 90 | ||
90 | // init page toolbar | 91 | // init page toolbar |
91 | 92 | ||
92 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 93 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
93 | 94 | ||
94 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 95 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
95 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); | 96 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
96 | newPageAction->addTo(pageToolBar); | 97 | newPageAction->addTo(pageToolBar); |
97 | 98 | ||
98 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 99 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); |
99 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); | 100 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); |
100 | clearPageAction->addTo(pageToolBar); | 101 | clearPageAction->addTo(pageToolBar); |
101 | 102 | ||
102 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 103 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
103 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); | 104 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); |
104 | deletePageAction->addTo(pageToolBar); | 105 | deletePageAction->addTo(pageToolBar); |
105 | 106 | ||
106 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 107 | QPEToolBar* emptyToolBar = new QPEToolBar(this); |
107 | emptyToolBar->setHorizontalStretchable(true); | 108 | emptyToolBar->setHorizontalStretchable(true); |
108 | 109 | ||
109 | // init navigation toolbar | 110 | // init navigation toolbar |
110 | 111 | ||
111 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 112 | QPEToolBar* navigationToolBar = new QPEToolBar(this); |
112 | 113 | ||
113 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); | 114 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); |
114 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | 115 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); |
115 | m_pUndoAction->addTo(navigationToolBar); | 116 | m_pUndoAction->addTo(navigationToolBar); |
@@ -258,24 +259,54 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
258 | } | 259 | } |
259 | 260 | ||
260 | DrawPad::~DrawPad() | 261 | DrawPad::~DrawPad() |
261 | { | 262 | { |
262 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 263 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
263 | 264 | ||
264 | if (file.open(IO_WriteOnly)) { | 265 | if (file.open(IO_WriteOnly)) { |
265 | m_pDrawPadCanvas->save(&file); | 266 | m_pDrawPadCanvas->save(&file); |
266 | file.close(); | 267 | file.close(); |
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
271 | void DrawPad::clearPage() | ||
272 | { | ||
273 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | ||
274 | QMessageBox::Information, QMessageBox::Yes, | ||
275 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
276 | QMessageBox::NoButton, this); | ||
277 | |||
278 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
279 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
280 | |||
281 | if (messageBox.exec() == QMessageBox::Yes) { | ||
282 | m_pDrawPadCanvas->clearPage(); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | void DrawPad::deletePage() | ||
287 | { | ||
288 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | ||
289 | QMessageBox::Information, QMessageBox::Yes, | ||
290 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
291 | QMessageBox::NoButton, this); | ||
292 | |||
293 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
294 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
295 | |||
296 | if (messageBox.exec() == QMessageBox::Yes) { | ||
297 | m_pDrawPadCanvas->deletePage(); | ||
298 | } | ||
299 | } | ||
300 | |||
270 | void DrawPad::setPointTool() | 301 | void DrawPad::setPointTool() |
271 | { | 302 | { |
272 | if (m_pTool) { | 303 | if (m_pTool) { |
273 | delete m_pTool; | 304 | delete m_pTool; |
274 | } | 305 | } |
275 | 306 | ||
276 | m_pTool = new PointTool(this, m_pDrawPadCanvas); | 307 | m_pTool = new PointTool(this, m_pDrawPadCanvas); |
277 | 308 | ||
278 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); | 309 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); |
279 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); | 310 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); |
280 | 311 | ||
281 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 312 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
@@ -490,24 +521,39 @@ void DrawPad::updateNavigationToolButtons() | |||
490 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 521 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
491 | } | 522 | } |
492 | 523 | ||
493 | void DrawPad::updateCaption() | 524 | void DrawPad::updateCaption() |
494 | { | 525 | { |
495 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); | 526 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); |
496 | uint pageCount = m_pDrawPadCanvas->pageCount(); | 527 | uint pageCount = m_pDrawPadCanvas->pageCount(); |
497 | 528 | ||
498 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " | 529 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " |
499 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); | 530 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); |
500 | } | 531 | } |
501 | 532 | ||
533 | void DrawPad::deleteAll() | ||
534 | { | ||
535 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | ||
536 | QMessageBox::Information, QMessageBox::Yes, | ||
537 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
538 | QMessageBox::NoButton, this); | ||
539 | |||
540 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
541 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
542 | |||
543 | if (messageBox.exec() == QMessageBox::Yes) { | ||
544 | m_pDrawPadCanvas->deleteAll(); | ||
545 | } | ||
546 | } | ||
547 | |||
502 | void DrawPad::importPage() | 548 | void DrawPad::importPage() |
503 | { | 549 | { |
504 | ImportDialog importDialog(this); | 550 | ImportDialog importDialog(this); |
505 | 551 | ||
506 | importDialog.showMaximized(); | 552 | importDialog.showMaximized(); |
507 | 553 | ||
508 | if (importDialog.exec() == QDialog::Accepted) { | 554 | if (importDialog.exec() == QDialog::Accepted) { |
509 | const DocLnk* docLnk = importDialog.selected(); | 555 | const DocLnk* docLnk = importDialog.selected(); |
510 | 556 | ||
511 | if (docLnk) { | 557 | if (docLnk) { |
512 | m_pDrawPadCanvas->importPage(docLnk->file()); | 558 | m_pDrawPadCanvas->importPage(docLnk->file()); |
513 | delete docLnk; | 559 | delete docLnk; |
@@ -520,17 +566,17 @@ void DrawPad::exportPage() | |||
520 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); | 566 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); |
521 | 567 | ||
522 | exportDialog.showMaximized(); | 568 | exportDialog.showMaximized(); |
523 | 569 | ||
524 | if (exportDialog.exec() == QDialog::Accepted) { | 570 | if (exportDialog.exec() == QDialog::Accepted) { |
525 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), | 571 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), |
526 | exportDialog.selectedName(), exportDialog.selectedFormat()); | 572 | exportDialog.selectedName(), exportDialog.selectedFormat()); |
527 | } | 573 | } |
528 | } | 574 | } |
529 | 575 | ||
530 | void DrawPad::thumbnailView() | 576 | void DrawPad::thumbnailView() |
531 | { | 577 | { |
532 | ThumbnailView thumbnailView(m_pDrawPadCanvas->pages(), this); | 578 | ThumbnailView thumbnailView(m_pDrawPadCanvas, this); |
533 | 579 | ||
534 | thumbnailView.showMaximized(); | 580 | thumbnailView.showMaximized(); |
535 | thumbnailView.exec(); | 581 | thumbnailView.exec(); |
536 | } | 582 | } |
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index b0b3666..01061b4 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h | |||
@@ -30,42 +30,46 @@ class DrawPad : public QMainWindow | |||
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | DrawPad(QWidget* parent = 0, const char* name = 0); | 34 | DrawPad(QWidget* parent = 0, const char* name = 0); |
35 | ~DrawPad(); | 35 | ~DrawPad(); |
36 | 36 | ||
37 | Tool* tool() { return m_pTool; } | 37 | Tool* tool() { return m_pTool; } |
38 | QPen pen() { return m_pen; } | 38 | QPen pen() { return m_pen; } |
39 | QBrush brush() { return m_brush; } | 39 | QBrush brush() { return m_brush; } |
40 | 40 | ||
41 | private slots: | 41 | private slots: |
42 | void clearPage(); | ||
43 | void deletePage(); | ||
44 | |||
42 | void setPointTool(); | 45 | void setPointTool(); |
43 | void setLineTool(); | 46 | void setLineTool(); |
44 | void setRectangleTool(); | 47 | void setRectangleTool(); |
45 | void setFilledRectangleTool(); | 48 | void setFilledRectangleTool(); |
46 | void setEllipseTool(); | 49 | void setEllipseTool(); |
47 | void setFilledEllipseTool(); | 50 | void setFilledEllipseTool(); |
48 | void setTextTool(); | 51 | void setTextTool(); |
49 | void setFillTool(); | 52 | void setFillTool(); |
50 | void setEraseTool(); | 53 | void setEraseTool(); |
51 | 54 | ||
52 | void changePenWidth(int value); | 55 | void changePenWidth(int value); |
53 | void changePenColor(const QColor& color); | 56 | void changePenColor(const QColor& color); |
54 | void changeBrushColor(const QColor& color); | 57 | void changeBrushColor(const QColor& color); |
55 | 58 | ||
56 | void updateUndoRedoToolButtons(); | 59 | void updateUndoRedoToolButtons(); |
57 | void updateNavigationToolButtons(); | 60 | void updateNavigationToolButtons(); |
58 | void updateCaption(); | 61 | void updateCaption(); |
59 | 62 | ||
63 | void deleteAll(); | ||
60 | void importPage(); | 64 | void importPage(); |
61 | void exportPage(); | 65 | void exportPage(); |
62 | void thumbnailView(); | 66 | void thumbnailView(); |
63 | 67 | ||
64 | private: | 68 | private: |
65 | DrawPadCanvas* m_pDrawPadCanvas; | 69 | DrawPadCanvas* m_pDrawPadCanvas; |
66 | 70 | ||
67 | Tool* m_pTool; | 71 | Tool* m_pTool; |
68 | QPen m_pen; | 72 | QPen m_pen; |
69 | QBrush m_brush; | 73 | QBrush m_brush; |
70 | 74 | ||
71 | QAction* m_pUndoAction; | 75 | QAction* m_pUndoAction; |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 79bef35..252f4d5 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -15,25 +15,24 @@ | |||
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "newpagedialog.h" | 17 | #include "newpagedialog.h" |
18 | #include "page.h" | 18 | #include "page.h" |
19 | #include "tool.h" | 19 | #include "tool.h" |
20 | 20 | ||
21 | #include <qpe/applnk.h> | 21 | #include <qpe/applnk.h> |
22 | #include <qpe/filemanager.h> | 22 | #include <qpe/filemanager.h> |
23 | #include <qpe/mimetype.h> | 23 | #include <qpe/mimetype.h> |
24 | 24 | ||
25 | #include <qbuffer.h> | 25 | #include <qbuffer.h> |
26 | #include <qimage.h> | 26 | #include <qimage.h> |
27 | #include <qmessagebox.h> | ||
28 | #include <qpainter.h> | 27 | #include <qpainter.h> |
29 | #include <qtextcodec.h> | 28 | #include <qtextcodec.h> |
30 | #include <qtextstream.h> | 29 | #include <qtextstream.h> |
31 | #include <qxml.h> | 30 | #include <qxml.h> |
32 | 31 | ||
33 | #include <zlib.h> | 32 | #include <zlib.h> |
34 | 33 | ||
35 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 34 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
36 | { | 35 | { |
37 | public: | 36 | public: |
38 | DrawPadCanvasXmlHandler(); | 37 | DrawPadCanvasXmlHandler(); |
39 | ~DrawPadCanvasXmlHandler(); | 38 | ~DrawPadCanvasXmlHandler(); |
@@ -337,48 +336,38 @@ void DrawPadCanvas::backupPage() | |||
337 | 336 | ||
338 | while (m_pageBackups.count() >= (5 + 1)) { | 337 | while (m_pageBackups.count() >= (5 + 1)) { |
339 | m_pageBackups.removeFirst(); | 338 | m_pageBackups.removeFirst(); |
340 | } | 339 | } |
341 | 340 | ||
342 | m_pageBackups.append(new Page(*(m_pages.current()))); | 341 | m_pageBackups.append(new Page(*(m_pages.current()))); |
343 | 342 | ||
344 | emit pageBackupsChanged(); | 343 | emit pageBackupsChanged(); |
345 | } | 344 | } |
346 | 345 | ||
347 | void DrawPadCanvas::deleteAll() | 346 | void DrawPadCanvas::deleteAll() |
348 | { | 347 | { |
349 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | ||
350 | QMessageBox::Information, QMessageBox::Yes, | ||
351 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
352 | QMessageBox::NoButton, this); | ||
353 | |||
354 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
355 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
356 | |||
357 | if (messageBox.exec() == QMessageBox::Yes) { | ||
358 | m_pages.clear(); | 348 | m_pages.clear(); |
359 | 349 | ||
360 | m_pages.append(new Page(contentsRect().size())); | 350 | m_pages.append(new Page(contentsRect().size())); |
361 | m_pages.current()->fill(Qt::white); | 351 | m_pages.current()->fill(Qt::white); |
362 | 352 | ||
363 | m_pageBackups.clear(); | 353 | m_pageBackups.clear(); |
364 | m_pageBackups.append(new Page(*(m_pages.current()))); | 354 | m_pageBackups.append(new Page(*(m_pages.current()))); |
365 | 355 | ||
366 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 356 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
367 | viewport()->update(); | 357 | viewport()->update(); |
368 | 358 | ||
369 | emit pagesChanged(); | 359 | emit pagesChanged(); |
370 | emit pageBackupsChanged(); | 360 | emit pageBackupsChanged(); |
371 | } | 361 | } |
372 | } | ||
373 | 362 | ||
374 | void DrawPadCanvas::newPage() | 363 | void DrawPadCanvas::newPage() |
375 | { | 364 | { |
376 | QRect rect = contentsRect(); | 365 | QRect rect = contentsRect(); |
377 | 366 | ||
378 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), | 367 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
379 | m_pDrawPad->brush().color(), this); | 368 | m_pDrawPad->brush().color(), this); |
380 | 369 | ||
381 | if (newPageDialog.exec() == QDialog::Accepted) { | 370 | if (newPageDialog.exec() == QDialog::Accepted) { |
382 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), | 371 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), |
383 | newPageDialog.selectedHeight())); | 372 | newPageDialog.selectedHeight())); |
384 | m_pages.current()->fill(newPageDialog.selectedColor()); | 373 | m_pages.current()->fill(newPageDialog.selectedColor()); |
@@ -387,67 +376,47 @@ void DrawPadCanvas::newPage() | |||
387 | m_pageBackups.append(new Page(*(m_pages.current()))); | 376 | m_pageBackups.append(new Page(*(m_pages.current()))); |
388 | 377 | ||
389 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 378 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
390 | viewport()->update(); | 379 | viewport()->update(); |
391 | 380 | ||
392 | emit pagesChanged(); | 381 | emit pagesChanged(); |
393 | emit pageBackupsChanged(); | 382 | emit pageBackupsChanged(); |
394 | } | 383 | } |
395 | } | 384 | } |
396 | 385 | ||
397 | void DrawPadCanvas::clearPage() | 386 | void DrawPadCanvas::clearPage() |
398 | { | 387 | { |
399 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | ||
400 | QMessageBox::Information, QMessageBox::Yes, | ||
401 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
402 | QMessageBox::NoButton, this); | ||
403 | |||
404 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
405 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
406 | |||
407 | if (messageBox.exec() == QMessageBox::Yes) { | ||
408 | m_pages.current()->fill(Qt::white); | 388 | m_pages.current()->fill(Qt::white); |
409 | 389 | ||
410 | viewport()->update(); | 390 | viewport()->update(); |
411 | } | 391 | } |
412 | } | ||
413 | 392 | ||
414 | void DrawPadCanvas::deletePage() | 393 | void DrawPadCanvas::deletePage() |
415 | { | 394 | { |
416 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | ||
417 | QMessageBox::Information, QMessageBox::Yes, | ||
418 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
419 | QMessageBox::NoButton, this); | ||
420 | |||
421 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
422 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
423 | |||
424 | if (messageBox.exec() == QMessageBox::Yes) { | ||
425 | m_pages.remove(m_pages.current()); | 395 | m_pages.remove(m_pages.current()); |
426 | 396 | ||
427 | if (m_pages.isEmpty()) { | 397 | if (m_pages.isEmpty()) { |
428 | m_pages.append(new Page(contentsRect().size())); | 398 | m_pages.append(new Page(contentsRect().size())); |
429 | m_pages.current()->fill(Qt::white); | 399 | m_pages.current()->fill(Qt::white); |
430 | } | 400 | } |
431 | 401 | ||
432 | m_pageBackups.clear(); | 402 | m_pageBackups.clear(); |
433 | m_pageBackups.append(new Page(*(m_pages.current()))); | 403 | m_pageBackups.append(new Page(*(m_pages.current()))); |
434 | 404 | ||
435 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 405 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
436 | viewport()->update(); | 406 | viewport()->update(); |
437 | 407 | ||
438 | emit pagesChanged(); | 408 | emit pagesChanged(); |
439 | emit pageBackupsChanged(); | 409 | emit pageBackupsChanged(); |
440 | } | 410 | } |
441 | } | ||
442 | 411 | ||
443 | bool DrawPadCanvas::undoEnabled() | 412 | bool DrawPadCanvas::undoEnabled() |
444 | { | 413 | { |
445 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 414 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
446 | } | 415 | } |
447 | 416 | ||
448 | bool DrawPadCanvas::redoEnabled() | 417 | bool DrawPadCanvas::redoEnabled() |
449 | { | 418 | { |
450 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 419 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
451 | } | 420 | } |
452 | 421 | ||
453 | bool DrawPadCanvas::goPreviousPageEnabled() | 422 | bool DrawPadCanvas::goPreviousPageEnabled() |
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 10ade90..1754ce9 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -4,118 +4,208 @@ | |||
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 | #include "thumbnailview.h" | 14 | #include "thumbnailview.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | ||
16 | #include "page.h" | 17 | #include "page.h" |
17 | 18 | ||
18 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
19 | 20 | ||
21 | #include <qapplication.h> | ||
20 | #include <qheader.h> | 22 | #include <qheader.h> |
21 | #include <qimage.h> | 23 | #include <qimage.h> |
22 | #include <qlayout.h> | 24 | #include <qlayout.h> |
23 | #include <qlistview.h> | 25 | #include <qmessagebox.h> |
24 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
25 | 27 | ||
26 | ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name) | 28 | PageListViewItem::PageListViewItem(Page* page, QListView* parent) |
27 | : QDialog(parent, name, true) | 29 | : QListViewItem(parent) |
28 | { | 30 | { |
29 | setCaption(tr("Thumbnail")); | 31 | m_pPage = page; |
30 | |||
31 | QToolButton* newPageButton = new QToolButton(this); | ||
32 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
33 | newPageButton->setAutoRaise(true); | ||
34 | |||
35 | QToolButton* clearPageButton = new QToolButton(this); | ||
36 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | ||
37 | clearPageButton->setAutoRaise(true); | ||
38 | |||
39 | QToolButton* deletePageButton = new QToolButton(this); | ||
40 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | ||
41 | deletePageButton->setAutoRaise(true); | ||
42 | |||
43 | QToolButton* movePageUpButton = new QToolButton(this); | ||
44 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | ||
45 | movePageUpButton->setAutoRaise(true); | ||
46 | |||
47 | QToolButton* movePageDownButton = new QToolButton(this); | ||
48 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | ||
49 | movePageDownButton->setAutoRaise(true); | ||
50 | |||
51 | m_pListView = new QListView(this); | ||
52 | |||
53 | m_pListView->header()->hide(); | ||
54 | m_pListView->setAllColumnsShowFocus(true); | ||
55 | |||
56 | m_pListView->addColumn(tr("Thumbnail")); | ||
57 | m_pListView->addColumn(tr("Information")); | ||
58 | |||
59 | m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); | ||
60 | m_pListView->setColumnAlignment(1, Qt::AlignTop); | ||
61 | 32 | ||
62 | QListIterator<Page> iterator(pages); | 33 | QImage image = m_pPage->convertToImage(); |
63 | |||
64 | for (; iterator.current(); ++iterator) { | ||
65 | QImage image = iterator.current()->convertToImage(); | ||
66 | 34 | ||
67 | int previewWidth = 64; | 35 | int previewWidth = 64; |
68 | int previewHeight = 64; | 36 | int previewHeight = 64; |
69 | 37 | ||
70 | float widthScale = 1.0; | 38 | float widthScale = 1.0; |
71 | float heightScale = 1.0; | 39 | float heightScale = 1.0; |
72 | 40 | ||
73 | if (previewWidth < image.width()) { | 41 | if (previewWidth < image.width()) { |
74 | widthScale = (float)previewWidth / float(image.width()); | 42 | widthScale = (float)previewWidth / float(image.width()); |
75 | } | 43 | } |
76 | 44 | ||
77 | if (previewHeight < image.height()) { | 45 | if (previewHeight < image.height()) { |
78 | heightScale = (float)previewHeight / float(image.height()); | 46 | heightScale = (float)previewHeight / float(image.height()); |
79 | } | 47 | } |
80 | 48 | ||
81 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 49 | float scale = (widthScale < heightScale ? widthScale : heightScale); |
82 | 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)); |
83 | 51 | ||
84 | QPixmap previewPixmap; | 52 | QPixmap previewPixmap; |
85 | previewPixmap.convertFromImage(previewImage); | 53 | previewPixmap.convertFromImage(previewImage); |
86 | 54 | ||
87 | QPixmap pixmap(64, 64); | 55 | QPixmap pixmap(64, 64); |
88 | 56 | ||
89 | pixmap.fill(colorGroup().mid()); | 57 | pixmap.fill(listView()->colorGroup().mid()); |
90 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | 58 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, |
91 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | 59 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); |
92 | 60 | ||
93 | QListViewItem* item = new QListViewItem(m_pListView); | 61 | setPixmap(0, pixmap); |
94 | item->setPixmap(0, pixmap); | 62 | } |
63 | |||
64 | PageListViewItem::~PageListViewItem() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | Page* PageListViewItem::page() const | ||
69 | { | ||
70 | return m_pPage; | ||
71 | } | ||
72 | |||
73 | PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | ||
74 | : QListView(parent, name) | ||
75 | { | ||
76 | m_pDrawPadCanvas = drawPadCanvas; | ||
77 | |||
78 | header()->hide(); | ||
79 | setVScrollBarMode(QScrollView::AlwaysOn); | ||
80 | setAllColumnsShowFocus(true); | ||
81 | |||
82 | addColumn(tr("Thumbnail")); | ||
83 | addColumn(tr("Information")); | ||
84 | |||
85 | updateView(); | ||
86 | } | ||
87 | |||
88 | PageListView::~PageListView() | ||
89 | { | ||
90 | } | ||
91 | |||
92 | void PageListView::updateView() | ||
93 | { | ||
94 | clear(); | ||
95 | |||
96 | if (m_pDrawPadCanvas) { | ||
97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); | ||
98 | QListIterator<Page> it(pageList); | ||
99 | |||
100 | for (; it.current(); ++it) { | ||
101 | new PageListViewItem(it.current(), this); | ||
102 | } | ||
103 | } | ||
95 | } | 104 | } |
96 | 105 | ||
106 | void PageListView::resizeEvent(QResizeEvent* e) | ||
107 | { | ||
108 | Q_UNUSED(e); | ||
109 | |||
110 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); | ||
111 | } | ||
112 | |||
113 | Page* PageListView::selected() const | ||
114 | { | ||
115 | Page* page; | ||
116 | |||
117 | PageListViewItem* item = (PageListViewItem*)selectedItem(); | ||
118 | |||
119 | if (item) { | ||
120 | page = item->page(); | ||
121 | } else { | ||
122 | page = NULL; | ||
123 | } | ||
124 | |||
125 | return page; | ||
126 | } | ||
127 | |||
128 | |||
129 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | ||
130 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) | ||
131 | { | ||
132 | inLoop = false; | ||
133 | m_pDrawPadCanvas = drawPadCanvas; | ||
134 | |||
135 | setCaption(tr("Thumbnail")); | ||
136 | |||
137 | QToolButton* newPageButton = new QToolButton(this); | ||
138 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
139 | newPageButton->setAutoRaise(true); | ||
140 | |||
141 | QToolButton* clearPageButton = new QToolButton(this); | ||
142 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | ||
143 | clearPageButton->setAutoRaise(true); | ||
144 | |||
145 | QToolButton* deletePageButton = new QToolButton(this); | ||
146 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | ||
147 | deletePageButton->setAutoRaise(true); | ||
148 | |||
149 | QToolButton* movePageUpButton = new QToolButton(this); | ||
150 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | ||
151 | movePageUpButton->setAutoRaise(true); | ||
152 | |||
153 | QToolButton* movePageDownButton = new QToolButton(this); | ||
154 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | ||
155 | movePageDownButton->setAutoRaise(true); | ||
156 | |||
157 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); | ||
158 | |||
97 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 159 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
98 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | 160 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); |
99 | 161 | ||
100 | buttonLayout->addWidget(newPageButton); | 162 | buttonLayout->addWidget(newPageButton); |
101 | buttonLayout->addWidget(clearPageButton); | 163 | buttonLayout->addWidget(clearPageButton); |
102 | buttonLayout->addWidget(deletePageButton); | 164 | buttonLayout->addWidget(deletePageButton); |
103 | buttonLayout->addStretch(); | 165 | buttonLayout->addStretch(); |
104 | buttonLayout->addWidget(movePageUpButton); | 166 | buttonLayout->addWidget(movePageUpButton); |
105 | buttonLayout->addWidget(movePageDownButton); | 167 | buttonLayout->addWidget(movePageDownButton); |
106 | 168 | ||
107 | mainLayout->addLayout(buttonLayout); | 169 | mainLayout->addLayout(buttonLayout); |
108 | mainLayout->addWidget(m_pListView); | 170 | mainLayout->addWidget(m_pPageListView); |
109 | } | 171 | } |
110 | 172 | ||
111 | ThumbnailView::~ThumbnailView() | 173 | ThumbnailView::~ThumbnailView() |
112 | { | 174 | { |
175 | hide(); | ||
113 | } | 176 | } |
114 | 177 | ||
115 | void ThumbnailView::resizeEvent(QResizeEvent* e) | 178 | void ThumbnailView::hide() |
116 | { | 179 | { |
117 | QDialog::resizeEvent(e); | 180 | QWidget::hide(); |
118 | 181 | ||
119 | m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) | 182 | if (inLoop) { |
120 | - m_pListView->verticalScrollBar()->width()); | 183 | inLoop = false; |
184 | qApp->exit_loop(); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | void ThumbnailView::exec() | ||
189 | { | ||
190 | show(); | ||
191 | |||
192 | if (!inLoop) { | ||
193 | inLoop = true; | ||
194 | qApp->enter_loop(); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | void ThumbnailView::deletePage() | ||
199 | { | ||
200 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), | ||
201 | QMessageBox::Information, QMessageBox::Yes, | ||
202 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
203 | QMessageBox::NoButton, this); | ||
204 | |||
205 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
206 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
207 | |||
208 | if (messageBox.exec() == QMessageBox::Yes) { | ||
209 | m_pDrawPadCanvas->deletePage(); | ||
210 | } | ||
121 | } | 211 | } |
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h index c74730d..ae97ff1 100644 --- a/noncore/graphics/drawpad/thumbnailview.h +++ b/noncore/graphics/drawpad/thumbnailview.h | |||
@@ -5,36 +5,69 @@ | |||
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 <qdialog.h> | 17 | #include <qwidget.h> |
18 | #include <qlistview.h> | ||
18 | 19 | ||
19 | #include <qlist.h> | 20 | class DrawPadCanvas; |
21 | class Page; | ||
22 | |||
23 | class PageListViewItem : public QListViewItem | ||
24 | { | ||
25 | public: | ||
26 | PageListViewItem(Page* page, QListView* parent); | ||
27 | ~PageListViewItem(); | ||
20 | 28 | ||
21 | class QListView; | 29 | Page* page() const; |
22 | 30 | ||
23 | class Page; | 31 | private: |
32 | Page* m_pPage; | ||
33 | }; | ||
34 | |||
35 | class PageListView : public QListView | ||
36 | { | ||
37 | public: | ||
38 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | ||
39 | ~PageListView(); | ||
40 | |||
41 | void updateView(); | ||
24 | 42 | ||
25 | class ThumbnailView : public QDialog | 43 | Page* selected() const; |
44 | |||
45 | protected: | ||
46 | void resizeEvent(QResizeEvent* e); | ||
47 | |||
48 | private: | ||
49 | DrawPadCanvas* m_pDrawPadCanvas; | ||
50 | }; | ||
51 | |||
52 | class ThumbnailView : public QWidget | ||
26 | { | 53 | { |
27 | Q_OBJECT | 54 | Q_OBJECT |
28 | 55 | ||
29 | public: | 56 | public: |
30 | ThumbnailView(QList<Page> pages, QWidget* parent = 0, const char* name = 0); | 57 | ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
31 | ~ThumbnailView(); | 58 | ~ThumbnailView(); |
32 | 59 | ||
33 | protected: | 60 | void hide(); |
34 | void resizeEvent(QResizeEvent* e); | 61 | void exec(); |
62 | |||
63 | public slots: | ||
64 | void deletePage(); | ||
35 | 65 | ||
36 | private: | 66 | private: |
37 | QListView* m_pListView; | 67 | bool inLoop; |
68 | DrawPadCanvas* m_pDrawPadCanvas; | ||
69 | |||
70 | PageListView* m_pPageListView; | ||
38 | }; | 71 | }; |
39 | 72 | ||
40 | #endif // THUMBNAILVIEW_H | 73 | #endif // THUMBNAILVIEW_H |