summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp17
-rw-r--r--noncore/graphics/drawpad/drawpad.h1
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp33
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h2
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp38
-rw-r--r--noncore/graphics/drawpad/thumbnailview.h7
6 files changed, 75 insertions, 23 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index 58c0d09..ef55268 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -1,48 +1,49 @@
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#include "drawpad.h" 14#include "drawpad.h"
15 15
16#include "drawpadcanvas.h" 16#include "drawpadcanvas.h"
17#include "ellipsetool.h" 17#include "ellipsetool.h"
18#include "erasetool.h" 18#include "erasetool.h"
19#include "exportdialog.h" 19#include "exportdialog.h"
20#include "filledellipsetool.h" 20#include "filledellipsetool.h"
21#include "filledrectangletool.h" 21#include "filledrectangletool.h"
22#include "filltool.h" 22#include "filltool.h"
23#include "importdialog.h" 23#include "importdialog.h"
24#include "linetool.h" 24#include "linetool.h"
25#include "newpagedialog.h"
25#include "pointtool.h" 26#include "pointtool.h"
26#include "rectangletool.h" 27#include "rectangletool.h"
27#include "texttool.h" 28#include "texttool.h"
28#include "thumbnailview.h" 29#include "thumbnailview.h"
29 30
30#include <opie/colordialog.h> 31#include <opie/colordialog.h>
31#include <opie/colorpopupmenu.h> 32#include <opie/colorpopupmenu.h>
32 33
33#include <qpe/applnk.h> 34#include <qpe/applnk.h>
34#include <qpe/global.h> 35#include <qpe/global.h>
35#include <qpe/qpemenubar.h> 36#include <qpe/qpemenubar.h>
36#include <qpe/qpetoolbar.h> 37#include <qpe/qpetoolbar.h>
37#include <qpe/resource.h> 38#include <qpe/resource.h>
38 39
39#include <qaction.h> 40#include <qaction.h>
40#include <qfile.h> 41#include <qfile.h>
41#include <qmessagebox.h> 42#include <qmessagebox.h>
42#include <qpainter.h> 43#include <qpainter.h>
43#include <qspinbox.h> 44#include <qspinbox.h>
44#include <qtoolbutton.h> 45#include <qtoolbutton.h>
45#include <qtooltip.h> 46#include <qtooltip.h>
46 47
47DrawPad::DrawPad(QWidget* parent, const char* name) 48DrawPad::DrawPad(QWidget* parent, const char* name)
48 : QMainWindow(parent, name) 49 : QMainWindow(parent, name)
@@ -72,49 +73,49 @@ DrawPad::DrawPad(QWidget* parent, const char* name)
72 73
73 toolsPopupMenu->insertSeparator(); 74 toolsPopupMenu->insertSeparator();
74 75
75 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); 76 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this);
76 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); 77 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage()));
77 importPageAction->addTo(toolsPopupMenu); 78 importPageAction->addTo(toolsPopupMenu);
78 79
79 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); 80 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this);
80 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); 81 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage()));
81 exportPageAction->addTo(toolsPopupMenu); 82 exportPageAction->addTo(toolsPopupMenu);
82 83
83 toolsPopupMenu->insertSeparator(); 84 toolsPopupMenu->insertSeparator();
84 85
85 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); 86 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this);
86 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); 87 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView()));
87 thumbnailViewAction->addTo(toolsPopupMenu); 88 thumbnailViewAction->addTo(toolsPopupMenu);
88 89
89 menuBar->insertItem(tr("Tools"), toolsPopupMenu); 90 menuBar->insertItem(tr("Tools"), toolsPopupMenu);
90 91
91 // init page toolbar 92 // init page toolbar
92 93
93 QPEToolBar* pageToolBar = new QPEToolBar(this); 94 QPEToolBar* pageToolBar = new QPEToolBar(this);
94 95
95 QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); 96 QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
96 connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); 97 connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
97 newPageAction->addTo(pageToolBar); 98 newPageAction->addTo(pageToolBar);
98 99
99 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); 100 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
100 connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); 101 connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage()));
101 clearPageAction->addTo(pageToolBar); 102 clearPageAction->addTo(pageToolBar);
102 103
103 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); 104 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
104 connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); 105 connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
105 deletePageAction->addTo(pageToolBar); 106 deletePageAction->addTo(pageToolBar);
106 107
107 QPEToolBar* emptyToolBar = new QPEToolBar(this); 108 QPEToolBar* emptyToolBar = new QPEToolBar(this);
108 emptyToolBar->setHorizontalStretchable(true); 109 emptyToolBar->setHorizontalStretchable(true);
109 110
110 // init navigation toolbar 111 // init navigation toolbar
111 112
112 QPEToolBar* navigationToolBar = new QPEToolBar(this); 113 QPEToolBar* navigationToolBar = new QPEToolBar(this);
113 114
114 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); 115 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
115 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); 116 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
116 m_pUndoAction->addTo(navigationToolBar); 117 m_pUndoAction->addTo(navigationToolBar);
117 118
118 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); 119 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
119 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); 120 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
120 m_pRedoAction->addTo(navigationToolBar); 121 m_pRedoAction->addTo(navigationToolBar);
@@ -247,48 +248,60 @@ DrawPad::DrawPad(QWidget* parent, const char* name)
247 changeBrushColor(Qt::white); 248 changeBrushColor(Qt::white);
248 249
249 // init pages 250 // init pages
250 251
251 QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); 252 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
252 253
253 if (file.open(IO_ReadOnly)) { 254 if (file.open(IO_ReadOnly)) {
254 m_pDrawPadCanvas->load(&file); 255 m_pDrawPadCanvas->load(&file);
255 file.close(); 256 file.close();
256 } else { 257 } else {
257 m_pDrawPadCanvas->initialPage(); 258 m_pDrawPadCanvas->initialPage();
258 } 259 }
259} 260}
260 261
261DrawPad::~DrawPad() 262DrawPad::~DrawPad()
262{ 263{
263 QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); 264 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
264 265
265 if (file.open(IO_WriteOnly)) { 266 if (file.open(IO_WriteOnly)) {
266 m_pDrawPadCanvas->save(&file); 267 m_pDrawPadCanvas->save(&file);
267 file.close(); 268 file.close();
268 } 269 }
269} 270}
270 271
272void DrawPad::newPage()
273{
274 QRect rect = m_pDrawPadCanvas->contentsRect();
275
276 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this);
277
278 if (newPageDialog.exec() == QDialog::Accepted) {
279 m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(),
280 newPageDialog.selectedColor());
281 }
282}
283
271void DrawPad::clearPage() 284void DrawPad::clearPage()
272{ 285{
273 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), 286 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"),
274 QMessageBox::Information, QMessageBox::Yes, 287 QMessageBox::Information, QMessageBox::Yes,
275 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 288 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
276 QMessageBox::NoButton, this); 289 QMessageBox::NoButton, this);
277 290
278 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 291 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
279 messageBox.setButtonText(QMessageBox::No, tr("No")); 292 messageBox.setButtonText(QMessageBox::No, tr("No"));
280 293
281 if (messageBox.exec() == QMessageBox::Yes) { 294 if (messageBox.exec() == QMessageBox::Yes) {
282 m_pDrawPadCanvas->clearPage(); 295 m_pDrawPadCanvas->clearPage();
283 } 296 }
284} 297}
285 298
286void DrawPad::deletePage() 299void DrawPad::deletePage()
287{ 300{
288 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), 301 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"),
289 QMessageBox::Information, QMessageBox::Yes, 302 QMessageBox::Information, QMessageBox::Yes,
290 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 303 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
291 QMessageBox::NoButton, this); 304 QMessageBox::NoButton, this);
292 305
293 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 306 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
294 messageBox.setButtonText(QMessageBox::No, tr("No")); 307 messageBox.setButtonText(QMessageBox::No, tr("No"));
@@ -554,29 +567,29 @@ void DrawPad::importPage()
554 if (importDialog.exec() == QDialog::Accepted) { 567 if (importDialog.exec() == QDialog::Accepted) {
555 const DocLnk* docLnk = importDialog.selected(); 568 const DocLnk* docLnk = importDialog.selected();
556 569
557 if (docLnk) { 570 if (docLnk) {
558 m_pDrawPadCanvas->importPage(docLnk->file()); 571 m_pDrawPadCanvas->importPage(docLnk->file());
559 delete docLnk; 572 delete docLnk;
560 } 573 }
561 } 574 }
562} 575}
563 576
564void DrawPad::exportPage() 577void DrawPad::exportPage()
565{ 578{
566 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); 579 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this);
567 580
568 exportDialog.showMaximized(); 581 exportDialog.showMaximized();
569 582
570 if (exportDialog.exec() == QDialog::Accepted) { 583 if (exportDialog.exec() == QDialog::Accepted) {
571 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), 584 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(),
572 exportDialog.selectedName(), exportDialog.selectedFormat()); 585 exportDialog.selectedName(), exportDialog.selectedFormat());
573 } 586 }
574} 587}
575 588
576void DrawPad::thumbnailView() 589void DrawPad::thumbnailView()
577{ 590{
578 ThumbnailView thumbnailView(m_pDrawPadCanvas, this); 591 ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this);
579 592
580 thumbnailView.showMaximized(); 593 thumbnailView.showMaximized();
581 thumbnailView.exec(); 594 thumbnailView.exec();
582} 595}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 01061b4..9a821f6 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -18,48 +18,49 @@
18 18
19#include <qpen.h> 19#include <qpen.h>
20 20
21class DrawPadCanvas; 21class DrawPadCanvas;
22class Tool; 22class Tool;
23 23
24class QAction; 24class QAction;
25class QColor; 25class QColor;
26class QToolButton; 26class QToolButton;
27class QWidgetStack; 27class QWidgetStack;
28 28
29class DrawPad : public QMainWindow 29class DrawPad : public QMainWindow
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
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
41private slots: 41private slots:
42 void newPage();
42 void clearPage(); 43 void clearPage();
43 void deletePage(); 44 void deletePage();
44 45
45 void setPointTool(); 46 void setPointTool();
46 void setLineTool(); 47 void setLineTool();
47 void setRectangleTool(); 48 void setRectangleTool();
48 void setFilledRectangleTool(); 49 void setFilledRectangleTool();
49 void setEllipseTool(); 50 void setEllipseTool();
50 void setFilledEllipseTool(); 51 void setFilledEllipseTool();
51 void setTextTool(); 52 void setTextTool();
52 void setFillTool(); 53 void setFillTool();
53 void setEraseTool(); 54 void setEraseTool();
54 55
55 void changePenWidth(int value); 56 void changePenWidth(int value);
56 void changePenColor(const QColor& color); 57 void changePenColor(const QColor& color);
57 void changeBrushColor(const QColor& color); 58 void changeBrushColor(const QColor& color);
58 59
59 void updateUndoRedoToolButtons(); 60 void updateUndoRedoToolButtons();
60 void updateNavigationToolButtons(); 61 void updateNavigationToolButtons();
61 void updateCaption(); 62 void updateCaption();
62 63
63 void deleteAll(); 64 void deleteAll();
64 void importPage(); 65 void importPage();
65 void exportPage(); 66 void exportPage();
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 0a1e9a5..c23ee34 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,41 +1,40 @@
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#include "drawpadcanvas.h" 14#include "drawpadcanvas.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "newpagedialog.h"
18#include "page.h" 17#include "page.h"
19#include "tool.h" 18#include "tool.h"
20 19
21#include <qpe/applnk.h> 20#include <qpe/applnk.h>
22#include <qpe/filemanager.h> 21#include <qpe/filemanager.h>
23#include <qpe/mimetype.h> 22#include <qpe/mimetype.h>
24 23
25#include <qbuffer.h> 24#include <qbuffer.h>
26#include <qimage.h> 25#include <qimage.h>
27#include <qpainter.h> 26#include <qpainter.h>
28#include <qtextcodec.h> 27#include <qtextcodec.h>
29#include <qtextstream.h> 28#include <qtextstream.h>
30#include <qxml.h> 29#include <qxml.h>
31 30
32#include <zlib.h> 31#include <zlib.h>
33 32
34class DrawPadCanvasXmlHandler: public QXmlDefaultHandler 33class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
35{ 34{
36public: 35public:
37 DrawPadCanvasXmlHandler(); 36 DrawPadCanvasXmlHandler();
38 ~DrawPadCanvasXmlHandler(); 37 ~DrawPadCanvasXmlHandler();
39 38
40 QList<Page> pages(); 39 QList<Page> pages();
41 40
@@ -352,76 +351,74 @@ void DrawPadCanvas::backupPage()
352 } 351 }
353 352
354 m_pageBackups.append(new Page(*(m_pages.current()))); 353 m_pageBackups.append(new Page(*(m_pages.current())));
355 354
356 emit pageBackupsChanged(); 355 emit pageBackupsChanged();
357} 356}
358 357
359void DrawPadCanvas::deleteAll() 358void DrawPadCanvas::deleteAll()
360{ 359{
361 m_pages.clear(); 360 m_pages.clear();
362 361
363 m_pages.append(new Page(contentsRect().size())); 362 m_pages.append(new Page(contentsRect().size()));
364 m_pages.current()->fill(Qt::white); 363 m_pages.current()->fill(Qt::white);
365 364
366 m_pageBackups.clear(); 365 m_pageBackups.clear();
367 m_pageBackups.append(new Page(*(m_pages.current()))); 366 m_pageBackups.append(new Page(*(m_pages.current())));
368 367
369 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 368 resizeContents(m_pages.current()->width(), m_pages.current()->height());
370 viewport()->update(); 369 viewport()->update();
371 370
372 emit pagesChanged(); 371 emit pagesChanged();
373 emit pageBackupsChanged(); 372 emit pageBackupsChanged();
374} 373}
375 374
376void DrawPadCanvas::newPage() 375void DrawPadCanvas::newPage(uint width, uint height, const QColor& color)
377{ 376{
378 QRect rect = contentsRect(); 377 m_pages.insert(m_pages.at() + 1, new Page(width, height));
378 m_pages.current()->fill(color);
379 379
380 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), 380 m_pageBackups.clear();
381 m_pDrawPad->brush().color(), this); 381 m_pageBackups.append(new Page(*(m_pages.current())));
382
383 if (newPageDialog.exec() == QDialog::Accepted) {
384 m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(),
385 newPageDialog.selectedHeight()));
386 m_pages.current()->fill(newPageDialog.selectedColor());
387
388 m_pageBackups.clear();
389 m_pageBackups.append(new Page(*(m_pages.current())));
390 382
391 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 383 resizeContents(m_pages.current()->width(), m_pages.current()->height());
392 viewport()->update(); 384 viewport()->update();
393 385
394 emit pagesChanged(); 386 emit pagesChanged();
395 emit pageBackupsChanged(); 387 emit pageBackupsChanged();
396 }
397} 388}
398 389
399void DrawPadCanvas::clearPage() 390void DrawPadCanvas::clearPage()
400{ 391{
401 m_pages.current()->fill(Qt::white); 392 m_pages.current()->fill(Qt::white);
402 393
394 m_pageBackups.clear();
395 m_pageBackups.append(new Page(*(m_pages.current())));
396
397 resizeContents(m_pages.current()->width(), m_pages.current()->height());
403 viewport()->update(); 398 viewport()->update();
399
400 emit pageBackupsChanged();
404} 401}
405 402
406void DrawPadCanvas::deletePage() 403void DrawPadCanvas::deletePage()
407{ 404{
408 m_pages.remove(m_pages.current()); 405 m_pages.remove(m_pages.current());
409 406
410 if (m_pages.isEmpty()) { 407 if (m_pages.isEmpty()) {
411 m_pages.append(new Page(contentsRect().size())); 408 m_pages.append(new Page(contentsRect().size()));
412 m_pages.current()->fill(Qt::white); 409 m_pages.current()->fill(Qt::white);
413 } 410 }
414 411
415 m_pageBackups.clear(); 412 m_pageBackups.clear();
416 m_pageBackups.append(new Page(*(m_pages.current()))); 413 m_pageBackups.append(new Page(*(m_pages.current())));
417 414
418 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 415 resizeContents(m_pages.current()->width(), m_pages.current()->height());
419 viewport()->update(); 416 viewport()->update();
420 417
421 emit pagesChanged(); 418 emit pagesChanged();
422 emit pageBackupsChanged(); 419 emit pageBackupsChanged();
423} 420}
424 421
425bool DrawPadCanvas::undoEnabled() 422bool DrawPadCanvas::undoEnabled()
426{ 423{
427 return (m_pageBackups.current() != m_pageBackups.getFirst()); 424 return (m_pageBackups.current() != m_pageBackups.getFirst());
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index cf2d904..d74d425 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -31,49 +31,49 @@ public:
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 selectPage(Page* page);
51 void backupPage(); 51 void backupPage();
52 52
53public slots: 53public slots:
54 void deleteAll(); 54 void deleteAll();
55 void newPage(); 55 void newPage(uint width, uint height, const QColor& color);
56 void clearPage(); 56 void clearPage();
57 void deletePage(); 57 void deletePage();
58 58
59 void undo(); 59 void undo();
60 void redo(); 60 void redo();
61 61
62 void goFirstPage(); 62 void goFirstPage();
63 void goPreviousPage(); 63 void goPreviousPage();
64 void goNextPage(); 64 void goNextPage();
65 void goLastPage(); 65 void goLastPage();
66 66
67signals: 67signals:
68 void pagesChanged(); 68 void pagesChanged();
69 void pageBackupsChanged(); 69 void pageBackupsChanged();
70 70
71protected: 71protected:
72 void contentsMousePressEvent(QMouseEvent* e); 72 void contentsMousePressEvent(QMouseEvent* e);
73 void contentsMouseReleaseEvent(QMouseEvent* e); 73 void contentsMouseReleaseEvent(QMouseEvent* e);
74 void contentsMouseMoveEvent(QMouseEvent* e); 74 void contentsMouseMoveEvent(QMouseEvent* e);
75 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);
76 76
77private: 77private:
78 DrawPad* m_pDrawPad; 78 DrawPad* m_pDrawPad;
79 QList<Page> m_pages; 79 QList<Page> m_pages;
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 476b7b9..08e106d 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,40 +1,42 @@
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#include "thumbnailview.h" 14#include "thumbnailview.h"
15 15
16#include "drawpad.h"
16#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "newpagedialog.h"
17#include "page.h" 19#include "page.h"
18 20
19#include <qpe/resource.h> 21#include <qpe/resource.h>
20 22
21#include <qapplication.h> 23#include <qapplication.h>
22#include <qheader.h> 24#include <qheader.h>
23#include <qimage.h> 25#include <qimage.h>
24#include <qlayout.h> 26#include <qlayout.h>
25#include <qmessagebox.h> 27#include <qmessagebox.h>
26#include <qtoolbutton.h> 28#include <qtoolbutton.h>
27 29
28PageListViewItem::PageListViewItem(Page* page, QListView* parent) 30PageListViewItem::PageListViewItem(Page* page, QListView* parent)
29 : QListViewItem(parent) 31 : QListViewItem(parent)
30{ 32{
31 m_pPage = page; 33 m_pPage = page;
32 34
33 QImage image = m_pPage->convertToImage(); 35 QImage image = m_pPage->convertToImage();
34 36
35 int previewWidth = 64; 37 int previewWidth = 64;
36 int previewHeight = 64; 38 int previewHeight = 64;
37 39
38 float widthScale = 1.0; 40 float widthScale = 1.0;
39 float heightScale = 1.0; 41 float heightScale = 1.0;
40 42
@@ -122,63 +124,67 @@ void PageListView::select(Page* page)
122 setSelected(item, true); 124 setSelected(item, true);
123 ensureItemVisible(item); 125 ensureItemVisible(item);
124 break; 126 break;
125 } 127 }
126 128
127 item = (PageListViewItem*)(item->nextSibling()); 129 item = (PageListViewItem*)(item->nextSibling());
128 } 130 }
129} 131}
130 132
131Page* PageListView::selected() const 133Page* PageListView::selected() const
132{ 134{
133 Page* page; 135 Page* page;
134 136
135 PageListViewItem* item = (PageListViewItem*)selectedItem(); 137 PageListViewItem* item = (PageListViewItem*)selectedItem();
136 138
137 if (item) { 139 if (item) {
138 page = item->page(); 140 page = item->page();
139 } else { 141 } else {
140 page = NULL; 142 page = NULL;
141 } 143 }
142 144
143 return page; 145 return page;
144} 146}
145 147
146ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) 148ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
147 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) 149 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel)
148{ 150{
149 inLoop = false; 151 inLoop = false;
152
153 m_pDrawPad = drawPad;
150 m_pDrawPadCanvas = drawPadCanvas; 154 m_pDrawPadCanvas = drawPadCanvas;
151 155
152 setCaption(tr("Thumbnail")); 156 setCaption(tr("Thumbnail"));
153 157
154 QToolButton* newPageButton = new QToolButton(this); 158 QToolButton* newPageButton = new QToolButton(this);
155 newPageButton->setIconSet(Resource::loadIconSet("new")); 159 newPageButton->setIconSet(Resource::loadIconSet("new"));
156 newPageButton->setAutoRaise(true); 160 newPageButton->setAutoRaise(true);
161 connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage()));
157 162
158 QToolButton* clearPageButton = new QToolButton(this); 163 QToolButton* clearPageButton = new QToolButton(this);
159 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); 164 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear"));
160 clearPageButton->setAutoRaise(true); 165 clearPageButton->setAutoRaise(true);
166 connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage()));
161 167
162 QToolButton* deletePageButton = new QToolButton(this); 168 QToolButton* deletePageButton = new QToolButton(this);
163 deletePageButton->setIconSet(Resource::loadIconSet("trash")); 169 deletePageButton->setIconSet(Resource::loadIconSet("trash"));
164 deletePageButton->setAutoRaise(true); 170 deletePageButton->setAutoRaise(true);
165 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); 171 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage()));
166 172
167 QToolButton* movePageUpButton = new QToolButton(this); 173 QToolButton* movePageUpButton = new QToolButton(this);
168 movePageUpButton->setIconSet(Resource::loadIconSet("up")); 174 movePageUpButton->setIconSet(Resource::loadIconSet("up"));
169 movePageUpButton->setAutoRaise(true); 175 movePageUpButton->setAutoRaise(true);
170 176
171 QToolButton* movePageDownButton = new QToolButton(this); 177 QToolButton* movePageDownButton = new QToolButton(this);
172 movePageDownButton->setIconSet(Resource::loadIconSet("down")); 178 movePageDownButton->setIconSet(Resource::loadIconSet("down"));
173 movePageDownButton->setAutoRaise(true); 179 movePageDownButton->setAutoRaise(true);
174 180
175 m_pPageListView = new PageListView(m_pDrawPadCanvas, this); 181 m_pPageListView = new PageListView(m_pDrawPadCanvas, this);
176 connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage())); 182 connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage()));
177 183
178 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); 184 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
179 QHBoxLayout* buttonLayout = new QHBoxLayout(0); 185 QHBoxLayout* buttonLayout = new QHBoxLayout(0);
180 186
181 buttonLayout->addWidget(newPageButton); 187 buttonLayout->addWidget(newPageButton);
182 buttonLayout->addWidget(clearPageButton); 188 buttonLayout->addWidget(clearPageButton);
183 buttonLayout->addWidget(deletePageButton); 189 buttonLayout->addWidget(deletePageButton);
184 buttonLayout->addStretch(); 190 buttonLayout->addStretch();
@@ -193,44 +199,74 @@ ThumbnailView::~ThumbnailView()
193{ 199{
194 hide(); 200 hide();
195} 201}
196 202
197void ThumbnailView::hide() 203void ThumbnailView::hide()
198{ 204{
199 QWidget::hide(); 205 QWidget::hide();
200 206
201 if (inLoop) { 207 if (inLoop) {
202 inLoop = false; 208 inLoop = false;
203 qApp->exit_loop(); 209 qApp->exit_loop();
204 } 210 }
205} 211}
206 212
207void ThumbnailView::exec() 213void ThumbnailView::exec()
208{ 214{
209 show(); 215 show();
210 216
211 if (!inLoop) { 217 if (!inLoop) {
212 inLoop = true; 218 inLoop = true;
213 qApp->enter_loop(); 219 qApp->enter_loop();
214 } 220 }
215} 221}
216 222
223void ThumbnailView::newPage()
224{
225 QRect rect = m_pDrawPadCanvas->contentsRect();
226
227 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(),
228 m_pDrawPad->brush().color(), this);
229
230 if (newPageDialog.exec() == QDialog::Accepted) {
231 m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(),
232 newPageDialog.selectedColor());
233 m_pPageListView->updateView();
234 }
235}
236
237void ThumbnailView::clearPage()
238{
239 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe selected page?"),
240 QMessageBox::Information, QMessageBox::Yes,
241 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
242 QMessageBox::NoButton, this);
243
244 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
245 messageBox.setButtonText(QMessageBox::No, tr("No"));
246
247 if (messageBox.exec() == QMessageBox::Yes) {
248 m_pDrawPadCanvas->clearPage();
249 m_pPageListView->updateView();
250 }
251}
252
217void ThumbnailView::deletePage() 253void ThumbnailView::deletePage()
218{ 254{
219 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), 255 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"),
220 QMessageBox::Information, QMessageBox::Yes, 256 QMessageBox::Information, QMessageBox::Yes,
221 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 257 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
222 QMessageBox::NoButton, this); 258 QMessageBox::NoButton, this);
223 259
224 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 260 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
225 messageBox.setButtonText(QMessageBox::No, tr("No")); 261 messageBox.setButtonText(QMessageBox::No, tr("No"));
226 262
227 if (messageBox.exec() == QMessageBox::Yes) { 263 if (messageBox.exec() == QMessageBox::Yes) {
228 m_pDrawPadCanvas->deletePage(); 264 m_pDrawPadCanvas->deletePage();
229 m_pPageListView->updateView(); 265 m_pPageListView->updateView();
230 } 266 }
231} 267}
232 268
233void ThumbnailView::changePage() 269void ThumbnailView::changePage()
234{ 270{
235 m_pDrawPadCanvas->selectPage(m_pPageListView->selected()); 271 m_pDrawPadCanvas->selectPage(m_pPageListView->selected());
236} 272}
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h
index 9417655..1fdb168 100644
--- a/noncore/graphics/drawpad/thumbnailview.h
+++ b/noncore/graphics/drawpad/thumbnailview.h
@@ -1,75 +1,80 @@
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
20class DrawPad;
20class DrawPadCanvas; 21class DrawPadCanvas;
21class Page; 22class Page;
22 23
23class PageListViewItem : public QListViewItem 24class PageListViewItem : public QListViewItem
24{ 25{
25public: 26public:
26 PageListViewItem(Page* page, QListView* parent); 27 PageListViewItem(Page* page, QListView* parent);
27 ~PageListViewItem(); 28 ~PageListViewItem();
28 29
29 Page* page() const; 30 Page* page() const;
30 31
31private: 32private:
32 Page* m_pPage; 33 Page* m_pPage;
33}; 34};
34 35
35class PageListView : public QListView 36class PageListView : public QListView
36{ 37{
37public: 38public:
38 PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); 39 PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
39 ~PageListView(); 40 ~PageListView();
40 41
41 void updateView(); 42 void updateView();
42 43
43 void select(Page* page); 44 void select(Page* page);
44 Page* selected() const; 45 Page* selected() const;
45 46
46protected: 47protected:
47 void resizeEvent(QResizeEvent* e); 48 void resizeEvent(QResizeEvent* e);
48 49
49private: 50private:
50 DrawPadCanvas* m_pDrawPadCanvas; 51 DrawPadCanvas* m_pDrawPadCanvas;
51}; 52};
52 53
53class ThumbnailView : public QWidget 54class ThumbnailView : public QWidget
54{ 55{
55 Q_OBJECT 56 Q_OBJECT
56 57
57public: 58public:
58 ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); 59 ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
59 ~ThumbnailView(); 60 ~ThumbnailView();
60 61
61 void hide(); 62 void hide();
62 void exec(); 63 void exec();
63 64
64public slots: 65public slots:
66 void newPage();
67 void clearPage();
65 void deletePage(); 68 void deletePage();
66 void changePage(); 69 void changePage();
67 70
68private: 71private:
69 bool inLoop; 72 bool inLoop;
73
74 DrawPad* m_pDrawPad;
70 DrawPadCanvas* m_pDrawPadCanvas; 75 DrawPadCanvas* m_pDrawPadCanvas;
71 76
72 PageListView* m_pPageListView; 77 PageListView* m_pPageListView;
73}; 78};
74 79
75#endif // THUMBNAILVIEW_H 80#endif // THUMBNAILVIEW_H