summaryrefslogtreecommitdiff
authorleseb <leseb>2002-07-10 21:59:27 (UTC)
committer leseb <leseb>2002-07-10 21:59:27 (UTC)
commitf568737c20bea96fb79d85681a72e142ec05d66f (patch) (unidiff)
tree80d08b351bbdeec5be93885a4c18ba0207ef990a
parent01b04adb73c8bc49938b71a4bebe6fb6a5477f75 (diff)
downloadopie-f568737c20bea96fb79d85681a72e142ec05d66f.zip
opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.gz
opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.bz2
Undo/redo reimplemented
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp28
-rw-r--r--noncore/graphics/drawpad/drawpad.h6
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp146
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h6
-rw-r--r--noncore/graphics/drawpad/erasetool.cpp8
-rw-r--r--noncore/graphics/drawpad/filltool.cpp46
-rw-r--r--noncore/graphics/drawpad/page.cpp60
-rw-r--r--noncore/graphics/drawpad/page.h20
-rw-r--r--noncore/graphics/drawpad/pageinformationdialog.cpp4
-rw-r--r--noncore/graphics/drawpad/pointtool.cpp8
-rw-r--r--noncore/graphics/drawpad/shapetool.cpp12
-rw-r--r--noncore/graphics/drawpad/texttool.cpp6
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp6
13 files changed, 169 insertions, 187 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index 4eb47a5..b0a414e 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -10,99 +10,97 @@
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 "newpagedialog.h"
26#include "page.h" 26#include "page.h"
27#include "pageinformationdialog.h" 27#include "pageinformationdialog.h"
28#include "pointtool.h" 28#include "pointtool.h"
29#include "rectangletool.h" 29#include "rectangletool.h"
30#include "texttool.h" 30#include "texttool.h"
31#include "thumbnailview.h" 31#include "thumbnailview.h"
32 32
33#include <opie/colordialog.h> 33#include <opie/colordialog.h>
34#include <opie/colorpopupmenu.h> 34#include <opie/colorpopupmenu.h>
35 35
36#include <qpe/applnk.h> 36#include <qpe/applnk.h>
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/global.h> 38#include <qpe/global.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qpe/qpetoolbar.h> 40#include <qpe/qpetoolbar.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42 42
43#include <qaction.h> 43#include <qaction.h>
44#include <qfile.h> 44#include <qfile.h>
45#include <qmessagebox.h> 45#include <qmessagebox.h>
46#include <qpainter.h> 46#include <qpainter.h>
47#include <qspinbox.h> 47#include <qspinbox.h>
48#include <qtoolbutton.h> 48#include <qtoolbutton.h>
49#include <qtooltip.h> 49#include <qtooltip.h>
50 50
51DrawPad::DrawPad(QWidget* parent, const char* name) 51DrawPad::DrawPad(QWidget* parent, const char* name)
52 : QMainWindow(parent, name) 52 : QMainWindow(parent, name)
53{ 53{
54 // init members 54 // init members
55 55
56 m_pDrawPadCanvas = new DrawPadCanvas(this, this); 56 m_pDrawPadCanvas = new DrawPadCanvas(this, this);
57 57
58 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); 58 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView()));
59 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
60 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
61 59
62 setCentralWidget(m_pDrawPadCanvas); 60 setCentralWidget(m_pDrawPadCanvas);
63 61
64 // init menu 62 // init menu
65 63
66 setToolBarsMovable(false); 64 setToolBarsMovable(false);
67 65
68 QPEToolBar* menuToolBar = new QPEToolBar(this); 66 QPEToolBar* menuToolBar = new QPEToolBar(this);
69 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); 67 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
70 68
71 QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); 69 QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar);
72 70
73 QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); 71 QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this);
74 connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); 72 connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll()));
75 deleteAllAction->addTo(toolsPopupMenu); 73 deleteAllAction->addTo(toolsPopupMenu);
76 74
77 toolsPopupMenu->insertSeparator(); 75 toolsPopupMenu->insertSeparator();
78 76
79 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); 77 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this);
80 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); 78 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage()));
81 importPageAction->addTo(toolsPopupMenu); 79 importPageAction->addTo(toolsPopupMenu);
82 80
83 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); 81 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this);
84 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); 82 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage()));
85 exportPageAction->addTo(toolsPopupMenu); 83 exportPageAction->addTo(toolsPopupMenu);
86 84
87 toolsPopupMenu->insertSeparator(); 85 toolsPopupMenu->insertSeparator();
88 86
89 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); 87 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this);
90 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); 88 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView()));
91 thumbnailViewAction->addTo(toolsPopupMenu); 89 thumbnailViewAction->addTo(toolsPopupMenu);
92 90
93 QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); 91 QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this);
94 connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); 92 connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation()));
95 pageInformationAction->addTo(toolsPopupMenu); 93 pageInformationAction->addTo(toolsPopupMenu);
96 94
97 toolsPopupMenu->insertSeparator(); 95 toolsPopupMenu->insertSeparator();
98 96
99 m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); 97 m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this);
100 m_pAntiAliasingAction->setToggleAction(true); 98 m_pAntiAliasingAction->setToggleAction(true);
101 m_pAntiAliasingAction->addTo(toolsPopupMenu); 99 m_pAntiAliasingAction->addTo(toolsPopupMenu);
102 100
103 menuBar->insertItem(tr("Tools"), toolsPopupMenu); 101 menuBar->insertItem(tr("Tools"), toolsPopupMenu);
104 102
105 // init page toolbar 103 // init page toolbar
106 104
107 QPEToolBar* pageToolBar = new QPEToolBar(this); 105 QPEToolBar* pageToolBar = new QPEToolBar(this);
108 106
@@ -497,117 +495,111 @@ void DrawPad::setFillTool()
497 m_pEraseToolAction->setOn(false); 495 m_pEraseToolAction->setOn(false);
498} 496}
499 497
500void DrawPad::setEraseTool() 498void DrawPad::setEraseTool()
501{ 499{
502 if (m_pTool) { 500 if (m_pTool) {
503 delete m_pTool; 501 delete m_pTool;
504 } 502 }
505 503
506 m_pTool = new EraseTool(this, m_pDrawPadCanvas); 504 m_pTool = new EraseTool(this, m_pDrawPadCanvas);
507 505
508 m_pLineToolButton->setOn(false); 506 m_pLineToolButton->setOn(false);
509 m_pRectangleToolButton->setOn(false); 507 m_pRectangleToolButton->setOn(false);
510 m_pEllipseToolButton->setOn(false); 508 m_pEllipseToolButton->setOn(false);
511 m_pTextToolAction->setOn(false); 509 m_pTextToolAction->setOn(false);
512 m_pFillToolAction->setOn(false); 510 m_pFillToolAction->setOn(false);
513 m_pEraseToolAction->setOn(true); 511 m_pEraseToolAction->setOn(true);
514} 512}
515 513
516void DrawPad::changePenWidth(int value) 514void DrawPad::changePenWidth(int value)
517{ 515{
518 m_pen.setWidth(value); 516 m_pen.setWidth(value);
519} 517}
520 518
521void DrawPad::changePenColor(const QColor& color) 519void DrawPad::changePenColor(const QColor& color)
522{ 520{
523 m_pen.setColor(color); 521 m_pen.setColor(color);
524 522
525 QPainter painter; 523 QPainter painter;
526 painter.begin(m_pPenColorToolButton->pixmap()); 524 painter.begin(m_pPenColorToolButton->pixmap());
527 painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); 525 painter.fillRect(QRect(0, 12, 14, 2), m_pen.color());
528 painter.end(); 526 painter.end();
529 527
530 m_pPenColorToolButton->popup()->hide(); 528 m_pPenColorToolButton->popup()->hide();
531} 529}
532 530
533void DrawPad::changeBrushColor(const QColor& color) 531void DrawPad::changeBrushColor(const QColor& color)
534{ 532{
535 m_brush = QBrush(color); 533 m_brush = QBrush(color);
536 534
537 QPainter painter; 535 QPainter painter;
538 painter.begin(m_pBrushColorToolButton->pixmap()); 536 painter.begin(m_pBrushColorToolButton->pixmap());
539 painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); 537 painter.fillRect(QRect(0, 12, 14, 2), m_brush.color());
540 painter.end(); 538 painter.end();
541 539
542 m_pBrushColorToolButton->popup()->hide(); 540 m_pBrushColorToolButton->popup()->hide();
543} 541}
544 542
545void DrawPad::updateUndoRedoToolButtons() 543void DrawPad::updateView()
546{
547 m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled());
548 m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled());
549}
550
551void DrawPad::updateNavigationToolButtons()
552{
553 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
554 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
555 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
556 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
557}
558
559void DrawPad::updateCaption()
560{ 544{
561 uint pagePosition = m_pDrawPadCanvas->pagePosition(); 545 uint pagePosition = m_pDrawPadCanvas->pagePosition();
562 uint pageCount = m_pDrawPadCanvas->pageCount(); 546 uint pageCount = m_pDrawPadCanvas->pageCount();
563 547
564 setCaption(tr("DrawPad") + " - " + tr("Page") + " " 548 setCaption(tr("DrawPad") + " - " + tr("Page") + " "
565 + QString::number(pagePosition) + "/" + QString::number(pageCount)); 549 + QString::number(pagePosition) + "/" + QString::number(pageCount));
550
551 m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled());
552 m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled());
553
554 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
555 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
556 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
557 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
566} 558}
567 559
568void DrawPad::deleteAll() 560void DrawPad::deleteAll()
569{ 561{
570 QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), 562 QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"),
571 QMessageBox::Information, QMessageBox::Yes, 563 QMessageBox::Information, QMessageBox::Yes,
572 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 564 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
573 QMessageBox::NoButton, this); 565 QMessageBox::NoButton, this);
574 566
575 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 567 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
576 messageBox.setButtonText(QMessageBox::No, tr("No")); 568 messageBox.setButtonText(QMessageBox::No, tr("No"));
577 569
578 if (messageBox.exec() == QMessageBox::Yes) { 570 if (messageBox.exec() == QMessageBox::Yes) {
579 m_pDrawPadCanvas->deleteAll(); 571 m_pDrawPadCanvas->deleteAll();
580 } 572 }
581} 573}
582 574
583void DrawPad::importPage() 575void DrawPad::importPage()
584{ 576{
585 ImportDialog importDialog(this); 577 ImportDialog importDialog(this);
586 578
587 importDialog.showMaximized(); 579 importDialog.showMaximized();
588 580
589 if (importDialog.exec() == QDialog::Accepted) { 581 if (importDialog.exec() == QDialog::Accepted) {
590 const DocLnk* docLnk = importDialog.selected(); 582 const DocLnk* docLnk = importDialog.selected();
591 583
592 if (docLnk) { 584 if (docLnk) {
593 m_pDrawPadCanvas->importPage(docLnk->file()); 585 m_pDrawPadCanvas->importPage(docLnk->file());
594 delete docLnk; 586 delete docLnk;
595 } 587 }
596 } 588 }
597} 589}
598 590
599void DrawPad::exportPage() 591void DrawPad::exportPage()
600{ 592{
601 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); 593 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this);
602 594
603 exportDialog.showMaximized(); 595 exportDialog.showMaximized();
604 596
605 if (exportDialog.exec() == QDialog::Accepted) { 597 if (exportDialog.exec() == QDialog::Accepted) {
606 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), 598 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(),
607 exportDialog.selectedName(), exportDialog.selectedFormat()); 599 exportDialog.selectedName(), exportDialog.selectedFormat());
608 } 600 }
609} 601}
610 602
611void DrawPad::thumbnailView() 603void DrawPad::thumbnailView()
612{ 604{
613 ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); 605 ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this);
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index c57606c..7306228 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -14,99 +14,97 @@
14#ifndef DRAWPAD_H 14#ifndef DRAWPAD_H
15#define DRAWPAD_H 15#define DRAWPAD_H
16 16
17#include <qmainwindow.h> 17#include <qmainwindow.h>
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 QSpinBox; 26class QSpinBox;
27class QToolButton; 27class QToolButton;
28class QWidgetStack; 28class QWidgetStack;
29 29
30class DrawPad : public QMainWindow 30class DrawPad : public QMainWindow
31{ 31{
32 Q_OBJECT 32 Q_OBJECT
33 33
34public: 34public:
35 DrawPad(QWidget* parent = 0, const char* name = 0); 35 DrawPad(QWidget* parent = 0, const char* name = 0);
36 ~DrawPad(); 36 ~DrawPad();
37 37
38 Tool* tool() { return m_pTool; } 38 Tool* tool() { return m_pTool; }
39 QPen pen() { return m_pen; } 39 QPen pen() { return m_pen; }
40 QBrush brush() { return m_brush; } 40 QBrush brush() { return m_brush; }
41 41
42 bool antiAliasing(); 42 bool antiAliasing();
43 43
44private slots: 44private slots:
45 void newPage(); 45 void newPage();
46 void clearPage(); 46 void clearPage();
47 void deletePage(); 47 void deletePage();
48 48
49 void setPointTool(); 49 void setPointTool();
50 void setLineTool(); 50 void setLineTool();
51 void setRectangleTool(); 51 void setRectangleTool();
52 void setFilledRectangleTool(); 52 void setFilledRectangleTool();
53 void setEllipseTool(); 53 void setEllipseTool();
54 void setFilledEllipseTool(); 54 void setFilledEllipseTool();
55 void setTextTool(); 55 void setTextTool();
56 void setFillTool(); 56 void setFillTool();
57 void setEraseTool(); 57 void setEraseTool();
58 58
59 void changePenWidth(int value); 59 void changePenWidth(int value);
60 void changePenColor(const QColor& color); 60 void changePenColor(const QColor& color);
61 void changeBrushColor(const QColor& color); 61 void changeBrushColor(const QColor& color);
62 62
63 void updateUndoRedoToolButtons(); 63 void updateView();
64 void updateNavigationToolButtons();
65 void updateCaption();
66 64
67 void deleteAll(); 65 void deleteAll();
68 void importPage(); 66 void importPage();
69 void exportPage(); 67 void exportPage();
70 void thumbnailView(); 68 void thumbnailView();
71 void pageInformation(); 69 void pageInformation();
72 70
73private: 71private:
74 void loadConfig(); 72 void loadConfig();
75 void saveConfig(); 73 void saveConfig();
76 74
77 DrawPadCanvas* m_pDrawPadCanvas; 75 DrawPadCanvas* m_pDrawPadCanvas;
78 76
79 Tool* m_pTool; 77 Tool* m_pTool;
80 QPen m_pen; 78 QPen m_pen;
81 QBrush m_brush; 79 QBrush m_brush;
82 80
83 QAction* m_pAntiAliasingAction; 81 QAction* m_pAntiAliasingAction;
84 82
85 QAction* m_pUndoAction; 83 QAction* m_pUndoAction;
86 QAction* m_pRedoAction; 84 QAction* m_pRedoAction;
87 85
88 QAction* m_pFirstPageAction; 86 QAction* m_pFirstPageAction;
89 QAction* m_pPreviousPageAction; 87 QAction* m_pPreviousPageAction;
90 QAction* m_pNextPageAction; 88 QAction* m_pNextPageAction;
91 QAction* m_pLastPageAction; 89 QAction* m_pLastPageAction;
92 90
93 QAction* m_pPointToolAction; 91 QAction* m_pPointToolAction;
94 QAction* m_pLineToolAction; 92 QAction* m_pLineToolAction;
95 QAction* m_pRectangleToolAction; 93 QAction* m_pRectangleToolAction;
96 QAction* m_pFilledRectangleToolAction; 94 QAction* m_pFilledRectangleToolAction;
97 QAction* m_pEllipseToolAction; 95 QAction* m_pEllipseToolAction;
98 QAction* m_pFilledEllipseToolAction; 96 QAction* m_pFilledEllipseToolAction;
99 QAction* m_pTextToolAction; 97 QAction* m_pTextToolAction;
100 QAction* m_pFillToolAction; 98 QAction* m_pFillToolAction;
101 QAction* m_pEraseToolAction; 99 QAction* m_pEraseToolAction;
102 100
103 QToolButton* m_pLineToolButton; 101 QToolButton* m_pLineToolButton;
104 QToolButton* m_pRectangleToolButton; 102 QToolButton* m_pRectangleToolButton;
105 QToolButton* m_pEllipseToolButton; 103 QToolButton* m_pEllipseToolButton;
106 QToolButton* m_pPenColorToolButton; 104 QToolButton* m_pPenColorToolButton;
107 QToolButton* m_pBrushColorToolButton; 105 QToolButton* m_pBrushColorToolButton;
108 106
109 QSpinBox* m_pPenWidthSpinBox; 107 QSpinBox* m_pPenWidthSpinBox;
110}; 108};
111 109
112#endif // DRAWPAD_H 110#endif // DRAWPAD_H
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 05dd408..025bebb 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,80 +1,78 @@
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 "page.h" 17#include "page.h"
18#include "tool.h" 18#include "tool.h"
19 19
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/filemanager.h> 21#include <qpe/filemanager.h>
22#include <qpe/mimetype.h> 22#include <qpe/mimetype.h>
23 23
24#include <qbuffer.h> 24#include <qbuffer.h>
25#include <qimage.h> 25#include <qimage.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qtextcodec.h> 27#include <qtextcodec.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qxml.h> 29#include <qxml.h>
30 30
31const int PAGE_BACKUPS = 99;
32
33class DrawPadCanvasXmlHandler: public QXmlDefaultHandler 31class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
34{ 32{
35public: 33public:
36 DrawPadCanvasXmlHandler(); 34 DrawPadCanvasXmlHandler();
37 ~DrawPadCanvasXmlHandler(); 35 ~DrawPadCanvasXmlHandler();
38 36
39 QList<Page> pages(); 37 QList<Page> pages();
40 38
41 bool startElement(const QString& namespaceURI, const QString& localName, 39 bool startElement(const QString& namespaceURI, const QString& localName,
42 const QString& qName, const QXmlAttributes& atts); 40 const QString& qName, const QXmlAttributes& atts);
43 bool endElement(const QString& namespaceURI, const QString& localName, 41 bool endElement(const QString& namespaceURI, const QString& localName,
44 const QString& qName); 42 const QString& qName);
45 bool characters(const QString& ch); 43 bool characters(const QString& ch);
46 44
47private: 45private:
48 enum State { 46 enum State {
49 Unknown, 47 Unknown,
50 InTitle, 48 InTitle,
51 InDate, 49 InDate,
52 InData 50 InData
53 }; 51 };
54 52
55 State m_state; 53 State m_state;
56 QString m_title; 54 QString m_title;
57 QDateTime m_date; 55 QDateTime m_date;
58 ulong m_dataLenght; 56 ulong m_dataLenght;
59 QString m_dataFormat; 57 QString m_dataFormat;
60 QList<Page> m_pages; 58 QList<Page> m_pages;
61}; 59};
62 60
63DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() 61DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler()
64{ 62{
65 m_state = Unknown; 63 m_state = Unknown;
66} 64}
67 65
68DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() 66DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler()
69{ 67{
70} 68}
71 69
72QList<Page> DrawPadCanvasXmlHandler::pages() 70QList<Page> DrawPadCanvasXmlHandler::pages()
73{ 71{
74 return m_pages; 72 return m_pages;
75} 73}
76 74
77bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, 75bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName,
78 const QString& qName, const QXmlAttributes& atts) 76 const QString& qName, const QXmlAttributes& atts)
79{ 77{
80 Q_CONST_UNUSED(namespaceURI) 78 Q_CONST_UNUSED(namespaceURI)
@@ -104,479 +102,409 @@ bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QStr
104 102
105 if (qName == "title") { 103 if (qName == "title") {
106 m_state = Unknown; 104 m_state = Unknown;
107 } else if (qName == "date") { 105 } else if (qName == "date") {
108 m_state = Unknown; 106 m_state = Unknown;
109 } else if (qName == "data") { 107 } else if (qName == "data") {
110 m_state = Unknown; 108 m_state = Unknown;
111 } 109 }
112 110
113 return true; 111 return true;
114} 112}
115 113
116bool DrawPadCanvasXmlHandler::characters(const QString& ch) 114bool DrawPadCanvasXmlHandler::characters(const QString& ch)
117{ 115{
118 if (m_state == InTitle) { 116 if (m_state == InTitle) {
119 m_title = ch; 117 m_title = ch;
120 } else if (m_state == InDate) { 118 } else if (m_state == InDate) {
121 m_date = QDateTime(QDate(1970, 1, 1)).addSecs(ch.toInt()); 119 m_date = QDateTime(QDate(1970, 1, 1)).addSecs(ch.toInt());
122 } else if (m_state == InData) { 120 } else if (m_state == InData) {
123 QByteArray byteArray(ch.length() / 2); 121 QByteArray byteArray(ch.length() / 2);
124 122
125 for (int i = 0; i < (int)ch.length() / 2; i++) { 123 for (int i = 0; i < (int)ch.length() / 2; i++) {
126 char h = ch[2 * i].latin1(); 124 char h = ch[2 * i].latin1();
127 char l = ch[2 * i + 1].latin1(); 125 char l = ch[2 * i + 1].latin1();
128 uchar r = 0; 126 uchar r = 0;
129 127
130 if (h <= '9') { 128 if (h <= '9') {
131 r += h - '0'; 129 r += h - '0';
132 } else { 130 } else {
133 r += h - 'a' + 10; 131 r += h - 'a' + 10;
134 } 132 }
135 133
136 r = r << 4; 134 r = r << 4;
137 135
138 if (l <= '9') { 136 if (l <= '9') {
139 r += l - '0'; 137 r += l - '0';
140 } else { 138 } else {
141 r += l - 'a' + 10; 139 r += l - 'a' + 10;
142 } 140 }
143 141
144 byteArray[i] = r; 142 byteArray[i] = r;
145 } 143 }
146 144
147 QImage image; 145 QImage image;
148 image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); 146 image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat);
149 147
150 Page* page = new Page(m_title, image.width(), image.height()); 148 Page* page = new Page(m_title, image.width(), image.height());
151 page->setLastModified(m_date); 149 page->setLastModified(m_date);
152 page->convertFromImage(image); 150 page->pixmap()->convertFromImage(image);
153 m_pages.append(page); 151 m_pages.append(page);
154 } 152 }
155 153
156 return true; 154 return true;
157} 155}
158 156
159DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) 157DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
160 : QScrollView(parent, name) 158 : QScrollView(parent, name)
161{ 159{
162 m_pDrawPad = drawPad; 160 m_pDrawPad = drawPad;
163 m_pages.setAutoDelete(true); 161 m_pages.setAutoDelete(true);
164 m_pageBackups.setAutoDelete(true);
165 162
166 viewport()->setBackgroundMode(QWidget::NoBackground); 163 viewport()->setBackgroundMode(QWidget::NoBackground);
167} 164}
168 165
169DrawPadCanvas::~DrawPadCanvas() 166DrawPadCanvas::~DrawPadCanvas()
170{ 167{
171} 168}
172 169
173void DrawPadCanvas::load(QIODevice* ioDevice) 170void DrawPadCanvas::load(QIODevice* ioDevice)
174{ 171{
175 QTextStream textStream(ioDevice); 172 QTextStream textStream(ioDevice);
176 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 173 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
177 174
178 QXmlInputSource xmlInputSource(textStream); 175 QXmlInputSource xmlInputSource(textStream);
179 QXmlSimpleReader xmlSimpleReader; 176 QXmlSimpleReader xmlSimpleReader;
180 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; 177 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
181 178
182 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); 179 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
183 xmlSimpleReader.parse(xmlInputSource); 180 xmlSimpleReader.parse(xmlInputSource);
184 181
185 m_pages = drawPadCanvasXmlHandler.pages(); 182 m_pages = drawPadCanvasXmlHandler.pages();
186 183
187 if (m_pages.isEmpty()) { 184 if (m_pages.isEmpty()) {
188 m_pages.append(new Page("", contentsRect().size())); 185 m_pages.append(new Page("", contentsRect().size()));
189 m_pages.current()->fill(Qt::white); 186 m_pages.current()->pixmap()->fill(Qt::white);
190 } 187 }
191 188
192 m_pageBackups.clear(); 189 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
193 m_pageBackups.append(new Page(*(m_pages.current())));
194
195 resizeContents(m_pages.current()->width(), m_pages.current()->height());
196 viewport()->update(); 190 viewport()->update();
197 191
198 emit pagesChanged(); 192 emit pagesChanged();
199 emit pageBackupsChanged();
200} 193}
201 194
202void DrawPadCanvas::initialPage() 195void DrawPadCanvas::initialPage()
203{ 196{
204 m_pages.append(new Page("", 236, 232)); 197 m_pages.append(new Page("", 236, 232));
205 m_pages.current()->fill(Qt::white); 198 m_pages.current()->pixmap()->fill(Qt::white);
206
207 m_pageBackups.clear();
208 m_pageBackups.append(new Page(*(m_pages.current())));
209 199
210 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 200 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
211 viewport()->update(); 201 viewport()->update();
212 202
213 emit pagesChanged(); 203 emit pagesChanged();
214 emit pageBackupsChanged();
215} 204}
216 205
217void DrawPadCanvas::save(QIODevice* ioDevice) 206void DrawPadCanvas::save(QIODevice* ioDevice)
218{ 207{
219 QTextStream textStream(ioDevice); 208 QTextStream textStream(ioDevice);
220 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 209 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
221 210
222 textStream << "<drawpad>" << endl; 211 textStream << "<drawpad>" << endl;
223 textStream << " <images>" << endl; 212 textStream << " <images>" << endl;
224 213
225 QListIterator<Page> bufferIterator(m_pages); 214 QListIterator<Page> bufferIterator(m_pages);
226 215
227 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 216 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
228 textStream << " <image>" << endl; 217 textStream << " <image>" << endl;
229 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; 218 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl;
230 219
231 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); 220 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified());
232 textStream << " <date>" << intDate << "</date>" << endl; 221 textStream << " <date>" << intDate << "</date>" << endl;
233 222
234 QImage image = bufferIterator.current()->convertToImage(); 223 QImage image = bufferIterator.current()->pixmap()->convertToImage();
235 QByteArray byteArray; 224 QByteArray byteArray;
236 QBuffer buffer(byteArray); 225 QBuffer buffer(byteArray);
237 QImageIO imageIO(&buffer, "PNG"); 226 QImageIO imageIO(&buffer, "PNG");
238 227
239 buffer.open(IO_WriteOnly); 228 buffer.open(IO_WriteOnly);
240 imageIO.setImage(image); 229 imageIO.setImage(image);
241 imageIO.write(); 230 imageIO.write();
242 buffer.close(); 231 buffer.close();
243 232
244 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; 233 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">";
245 234
246 static const char hexchars[] = "0123456789abcdef"; 235 static const char hexchars[] = "0123456789abcdef";
247 236
248 for (int i = 0; i < (int)byteArray.size(); i++ ) { 237 for (int i = 0; i < (int)byteArray.size(); i++ ) {
249 uchar s = (uchar)byteArray[i]; 238 uchar s = (uchar)byteArray[i];
250 textStream << hexchars[s >> 4]; 239 textStream << hexchars[s >> 4];
251 textStream << hexchars[s & 0x0f]; 240 textStream << hexchars[s & 0x0f];
252 } 241 }
253 242
254 textStream << "</data>" << endl; 243 textStream << "</data>" << endl;
255 textStream << " </image>" << endl; 244 textStream << " </image>" << endl;
256 } 245 }
257 246
258 textStream << " </images>" << endl; 247 textStream << " </images>" << endl;
259 textStream << "</drawpad>"; 248 textStream << "</drawpad>";
260} 249}
261 250
262void DrawPadCanvas::importPage(const QString& fileName) 251void DrawPadCanvas::importPage(const QString& fileName)
263{ 252{
264 Page* importedPage = new Page(); 253 Page* importedPage = new Page();
265 254
266 importedPage->load(fileName); 255 importedPage->pixmap()->load(fileName);
267 m_pages.insert(m_pages.at() + 1, importedPage); 256 m_pages.insert(m_pages.at() + 1, importedPage);
268 257
269 m_pageBackups.clear(); 258 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
270 m_pageBackups.append(new Page(*(m_pages.current())));
271
272 resizeContents(m_pages.current()->width(), m_pages.current()->height());
273 viewport()->update(); 259 viewport()->update();
274 260
275 emit pagesChanged(); 261 emit pagesChanged();
276 emit pageBackupsChanged();
277} 262}
278 263
279void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) 264void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format)
280{ 265{
281 if (fromPage == toPage) { 266 if (fromPage == toPage) {
282 DocLnk docLnk; 267 DocLnk docLnk;
283 MimeType mimeType(format); 268 MimeType mimeType(format);
284 269
285 docLnk.setName(name); 270 docLnk.setName(name);
286 docLnk.setType(mimeType.id()); 271 docLnk.setType(mimeType.id());
287 272
288 FileManager fileManager; 273 FileManager fileManager;
289 QIODevice* ioDevice = fileManager.saveFile(docLnk); 274 QIODevice* ioDevice = fileManager.saveFile(docLnk);
290 QImageIO imageIO(ioDevice, format); 275 QImageIO imageIO(ioDevice, format);
291 276
292 QImage image = m_pages.current()->convertToImage(); 277 QImage image = m_pages.current()->pixmap()->convertToImage();
293 imageIO.setImage(image); 278 imageIO.setImage(image);
294 imageIO.write(); 279 imageIO.write();
295 delete ioDevice; 280 delete ioDevice;
296 } else { 281 } else {
297 for (uint i = fromPage; i <= toPage; i++) { 282 for (uint i = fromPage; i <= toPage; i++) {
298 DocLnk docLnk; 283 DocLnk docLnk;
299 MimeType mimeType(format); 284 MimeType mimeType(format);
300 285
301 docLnk.setName(name + QString::number(i)); 286 docLnk.setName(name + QString::number(i));
302 docLnk.setType(mimeType.id()); 287 docLnk.setType(mimeType.id());
303 288
304 FileManager fileManager; 289 FileManager fileManager;
305 QIODevice* ioDevice = fileManager.saveFile(docLnk); 290 QIODevice* ioDevice = fileManager.saveFile(docLnk);
306 QImageIO imageIO(ioDevice, format); 291 QImageIO imageIO(ioDevice, format);
307 292
308 QImage image = m_pages.at(i - 1)->convertToImage(); 293 QImage image = m_pages.at(i - 1)->pixmap()->convertToImage();
309 imageIO.setImage(image); 294 imageIO.setImage(image);
310 imageIO.write(); 295 imageIO.write();
311 delete ioDevice; 296 delete ioDevice;
312 } 297 }
313 } 298 }
314} 299}
315 300
316Page* DrawPadCanvas::currentPage() 301Page* DrawPadCanvas::currentPage()
317{ 302{
318 return m_pages.current(); 303 return m_pages.current();
319} 304}
320 305
321QList<Page> DrawPadCanvas::pages() 306QList<Page> DrawPadCanvas::pages()
322{ 307{
323 return m_pages; 308 return m_pages;
324} 309}
325 310
326uint DrawPadCanvas::pagePosition() 311uint DrawPadCanvas::pagePosition()
327{ 312{
328 return (m_pages.at() + 1); 313 return (m_pages.at() + 1);
329} 314}
330 315
331uint DrawPadCanvas::pageCount() 316uint DrawPadCanvas::pageCount()
332{ 317{
333 return m_pages.count(); 318 return m_pages.count();
334} 319}
335 320
336void DrawPadCanvas::selectPage(Page* page) 321void DrawPadCanvas::selectPage(Page* page)
337{ 322{
338 m_pages.findRef(page); 323 m_pages.findRef(page);
339 m_pageBackups.clear();
340 m_pageBackups.append(new Page(*(m_pages.current())));
341 324
342 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 325 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
343 viewport()->update(); 326 viewport()->update();
344 327
345 emit pagesChanged(); 328 emit pagesChanged();
346 emit pageBackupsChanged();
347} 329}
348 330
349void DrawPadCanvas::selectPage(uint pagePosition) 331void DrawPadCanvas::backupPage()
350{ 332{
351 m_pages.at(pagePosition - 1); 333 m_pages.current()->backup();
352 m_pageBackups.clear();
353 m_pageBackups.append(new Page(*(m_pages.current())));
354
355 resizeContents(m_pages.current()->width(), m_pages.current()->height());
356 viewport()->update();
357 334
358 emit pagesChanged(); 335 emit pagesChanged();
359 emit pageBackupsChanged();
360} 336}
361 337
362void DrawPadCanvas::backupPage() 338void DrawPadCanvas::selectPage(uint pagePosition)
363{ 339{
364 m_pages.current()->setLastModified(QDateTime::currentDateTime()); 340 m_pages.at(pagePosition - 1);
365
366 Page* currentBackup = m_pageBackups.current();
367 while (m_pageBackups.last() != currentBackup) {
368 m_pageBackups.removeLast();
369 }
370
371 while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) {
372 m_pageBackups.removeFirst();
373 }
374 341
375 m_pageBackups.append(new Page(*(m_pages.current()))); 342 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
343 viewport()->update();
376 344
377 emit pageBackupsChanged(); 345 emit pagesChanged();
378} 346}
379 347
380void DrawPadCanvas::deleteAll() 348void DrawPadCanvas::deleteAll()
381{ 349{
382 m_pages.clear(); 350 m_pages.clear();
383 351
384 m_pages.append(new Page("", contentsRect().size())); 352 m_pages.append(new Page("", contentsRect().size()));
385 m_pages.current()->fill(Qt::white); 353 m_pages.current()->pixmap()->fill(Qt::white);
386 354
387 m_pageBackups.clear(); 355 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
388 m_pageBackups.append(new Page(*(m_pages.current())));
389
390 resizeContents(m_pages.current()->width(), m_pages.current()->height());
391 viewport()->update(); 356 viewport()->update();
392 357
393 emit pagesChanged(); 358 emit pagesChanged();
394 emit pageBackupsChanged();
395} 359}
396 360
397void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) 361void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color)
398{ 362{
399 m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); 363 m_pages.insert(m_pages.at() + 1, new Page(title, width, height));
400 m_pages.current()->fill(color); 364 m_pages.current()->pixmap()->fill(color);
401
402 m_pageBackups.clear();
403 m_pageBackups.append(new Page(*(m_pages.current())));
404 365
405 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 366 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
406 viewport()->update(); 367 viewport()->update();
407 368
408 emit pagesChanged(); 369 emit pagesChanged();
409 emit pageBackupsChanged();
410} 370}
411 371
412void DrawPadCanvas::clearPage() 372void DrawPadCanvas::clearPage()
413{ 373{
414 m_pages.current()->fill(Qt::white); 374 m_pages.current()->pixmap()->fill(Qt::white);
415 375
416 m_pageBackups.clear(); 376 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
417 m_pageBackups.append(new Page(*(m_pages.current())));
418
419 resizeContents(m_pages.current()->width(), m_pages.current()->height());
420 viewport()->update(); 377 viewport()->update();
421
422 emit pageBackupsChanged();
423} 378}
424 379
425void DrawPadCanvas::deletePage() 380void DrawPadCanvas::deletePage()
426{ 381{
427 m_pages.remove(m_pages.current()); 382 m_pages.remove(m_pages.current());
428 383
429 if (m_pages.isEmpty()) { 384 if (m_pages.isEmpty()) {
430 m_pages.append(new Page("", contentsRect().size())); 385 m_pages.append(new Page("", contentsRect().size()));
431 m_pages.current()->fill(Qt::white); 386 m_pages.current()->pixmap()->fill(Qt::white);
432 } 387 }
433 388
434 m_pageBackups.clear(); 389 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
435 m_pageBackups.append(new Page(*(m_pages.current())));
436
437 resizeContents(m_pages.current()->width(), m_pages.current()->height());
438 viewport()->update(); 390 viewport()->update();
439 391
440 emit pagesChanged(); 392 emit pagesChanged();
441 emit pageBackupsChanged();
442} 393}
443 394
444void DrawPadCanvas::movePageUp() 395void DrawPadCanvas::movePageUp()
445{ 396{
446 int index = m_pages.at(); 397 int index = m_pages.at();
447 Page* page = m_pages.take(); 398 Page* page = m_pages.take();
448 m_pages.insert(index - 1, page); 399 m_pages.insert(index - 1, page);
449 400
450 emit pagesChanged(); 401 emit pagesChanged();
451} 402}
452 403
453void DrawPadCanvas::movePageDown() 404void DrawPadCanvas::movePageDown()
454{ 405{
455 int index = m_pages.at(); 406 int index = m_pages.at();
456 Page* page = m_pages.take(); 407 Page* page = m_pages.take();
457 m_pages.insert(index + 1, page); 408 m_pages.insert(index + 1, page);
458 409
459 emit pagesChanged(); 410 emit pagesChanged();
460} 411}
461 412
462bool DrawPadCanvas::undoEnabled()
463{
464 return (m_pageBackups.current() != m_pageBackups.getFirst());
465}
466
467bool DrawPadCanvas::redoEnabled()
468{
469 return (m_pageBackups.current() != m_pageBackups.getLast());
470}
471
472bool DrawPadCanvas::goPreviousPageEnabled() 413bool DrawPadCanvas::goPreviousPageEnabled()
473{ 414{
474 return (m_pages.current() != m_pages.getFirst()); 415 return (m_pages.current() != m_pages.getFirst());
475} 416}
476 417
477bool DrawPadCanvas::goNextPageEnabled() 418bool DrawPadCanvas::goNextPageEnabled()
478{ 419{
479 return (m_pages.current() != m_pages.getLast()); 420 return (m_pages.current() != m_pages.getLast());
480} 421}
481 422
482void DrawPadCanvas::undo() 423void DrawPadCanvas::undo()
483{ 424{
484 *(m_pages.current()) = *(m_pageBackups.prev()); 425 m_pages.current()->undo();
485 426
486 viewport()->update(); 427 viewport()->update();
487 428
488 emit pageBackupsChanged(); 429 emit pagesChanged();
489} 430}
490 431
491void DrawPadCanvas::redo() 432void DrawPadCanvas::redo()
492{ 433{
493 *(m_pages.current()) = *(m_pageBackups.next()); 434 m_pages.current()->redo();
494 435
495 viewport()->update(); 436 viewport()->update();
496 437
497 emit pageBackupsChanged(); 438 emit pagesChanged();
498} 439}
499 440
500void DrawPadCanvas::goFirstPage() 441void DrawPadCanvas::goFirstPage()
501{ 442{
502 m_pages.first(); 443 m_pages.first();
503 m_pageBackups.clear();
504 m_pageBackups.append(new Page(*(m_pages.current())));
505 444
506 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 445 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
507 viewport()->update(); 446 viewport()->update();
508 447
509 emit pagesChanged(); 448 emit pagesChanged();
510 emit pageBackupsChanged();
511} 449}
512 450
513void DrawPadCanvas::goPreviousPage() 451void DrawPadCanvas::goPreviousPage()
514{ 452{
515 m_pages.prev(); 453 m_pages.prev();
516 m_pageBackups.clear();
517 m_pageBackups.append(new Page(*(m_pages.current())));
518 454
519 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 455 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
520 viewport()->update(); 456 viewport()->update();
521 457
522 emit pagesChanged(); 458 emit pagesChanged();
523 emit pageBackupsChanged();
524} 459}
525 460
526void DrawPadCanvas::goNextPage() 461void DrawPadCanvas::goNextPage()
527{ 462{
528 m_pages.next(); 463 m_pages.next();
529 m_pageBackups.clear(); 464 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
530 m_pageBackups.append(new Page(*(m_pages.current())));
531
532 resizeContents(m_pages.current()->width(), m_pages.current()->height());
533 viewport()->update(); 465 viewport()->update();
534 466
535 emit pagesChanged(); 467 emit pagesChanged();
536 emit pageBackupsChanged();
537} 468}
538 469
539void DrawPadCanvas::goLastPage() 470void DrawPadCanvas::goLastPage()
540{ 471{
541 m_pages.last(); 472 m_pages.last();
542 m_pageBackups.clear();
543 m_pageBackups.append(new Page(*(m_pages.current())));
544 473
545 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 474 resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
546 viewport()->update(); 475 viewport()->update();
547 476
548 emit pagesChanged(); 477 emit pagesChanged();
549 emit pageBackupsChanged();
550} 478}
551 479
552void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) 480void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
553{ 481{
554 m_pDrawPad->tool()->mousePressEvent(e); 482 m_pDrawPad->tool()->mousePressEvent(e);
555} 483}
556 484
557void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) 485void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
558{ 486{
559 m_pDrawPad->tool()->mouseReleaseEvent(e); 487 m_pDrawPad->tool()->mouseReleaseEvent(e);
560} 488}
561 489
562void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) 490void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
563{ 491{
564 m_pDrawPad->tool()->mouseMoveEvent(e); 492 m_pDrawPad->tool()->mouseMoveEvent(e);
565} 493}
566 494
567void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 495void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
568{ 496{
569 QRect clipRect(cx, cy, cw, ch); 497 QRect clipRect(cx, cy, cw, ch);
570 QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); 498 QRect pixmapRect(0, 0, m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
571 QRect drawRect = pixmapRect.intersect(clipRect); 499 QRect drawRect = pixmapRect.intersect(clipRect);
572 500
573 p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); 501 p->drawPixmap(drawRect.topLeft(), *(m_pages.current()->pixmap()), drawRect);
574 502
575 if (drawRect.right() < clipRect.right()) { 503 if (drawRect.right() < clipRect.right()) {
576 p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); 504 p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark());
577 } 505 }
578 506
579 if (drawRect.bottom() < clipRect.bottom()) { 507 if (drawRect.bottom() < clipRect.bottom()) {
580 p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); 508 p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark());
581 } 509 }
582} 510}
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index 2283e5e..80a2a7e 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -1,86 +1,82 @@
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
22class DrawPad; 22class DrawPad;
23class Page; 23class Page;
24 24
25class DrawPadCanvas : public QScrollView 25class DrawPadCanvas : public QScrollView
26{ 26{
27 Q_OBJECT 27 Q_OBJECT
28 28
29public: 29public:
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();
41 bool redoEnabled();
42 bool goPreviousPageEnabled(); 40 bool goPreviousPageEnabled();
43 bool goNextPageEnabled(); 41 bool goNextPageEnabled();
44 42
45 Page* currentPage(); 43 Page* currentPage();
46 QList<Page> pages(); 44 QList<Page> pages();
47 uint pagePosition(); 45 uint pagePosition();
48 uint pageCount(); 46 uint pageCount();
49 47
50 void selectPage(Page* page); 48 void selectPage(Page* page);
51 void selectPage(uint pagePosition); 49 void selectPage(uint pagePosition);
52 void backupPage(); 50 void backupPage();
53 51
54public slots: 52public slots:
55 void deleteAll(); 53 void deleteAll();
56 void newPage(QString title, uint width, uint height, const QColor& color); 54 void newPage(QString title, uint width, uint height, const QColor& color);
57 void clearPage(); 55 void clearPage();
58 void deletePage(); 56 void deletePage();
59 void movePageUp(); 57 void movePageUp();
60 void movePageDown(); 58 void movePageDown();
61 59
62 void undo(); 60 void undo();
63 void redo(); 61 void redo();
64 62
65 void goFirstPage(); 63 void goFirstPage();
66 void goPreviousPage(); 64 void goPreviousPage();
67 void goNextPage(); 65 void goNextPage();
68 void goLastPage(); 66 void goLastPage();
69 67
70signals: 68signals:
71 void pagesChanged(); 69 void pagesChanged();
72 void pageBackupsChanged();
73 70
74protected: 71protected:
75 void contentsMousePressEvent(QMouseEvent* e); 72 void contentsMousePressEvent(QMouseEvent* e);
76 void contentsMouseReleaseEvent(QMouseEvent* e); 73 void contentsMouseReleaseEvent(QMouseEvent* e);
77 void contentsMouseMoveEvent(QMouseEvent* e); 74 void contentsMouseMoveEvent(QMouseEvent* e);
78 void drawContents(QPainter* p, int cx, int cy, int cw, int ch); 75 void drawContents(QPainter* p, int cx, int cy, int cw, int ch);
79 76
80private: 77private:
81 DrawPad* m_pDrawPad; 78 DrawPad* m_pDrawPad;
82 QList<Page> m_pages; 79 QList<Page> m_pages;
83 QList<Page> m_pageBackups;
84}; 80};
85 81
86#endif // DRAWPADCANVAS_H 82#endif // DRAWPADCANVAS_H
diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp
index f77e038..2326da5 100644
--- a/noncore/graphics/drawpad/erasetool.cpp
+++ b/noncore/graphics/drawpad/erasetool.cpp
@@ -1,76 +1,76 @@
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 "erasetool.h" 14#include "erasetool.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "page.h" 18#include "page.h"
19 19
20#include <qpainter.h> 20#include <qpainter.h>
21 21
22EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 22EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : Tool(drawPad, drawPadCanvas) 23 : Tool(drawPad, drawPadCanvas)
24{ 24{
25 m_mousePressed = false; 25 m_mousePressed = false;
26 m_polyline.resize(3); 26 m_polyline.resize(3);
27} 27}
28 28
29EraseTool::~EraseTool() 29EraseTool::~EraseTool()
30{ 30{
31} 31}
32 32
33void EraseTool::mousePressEvent(QMouseEvent* e) 33void EraseTool::mousePressEvent(QMouseEvent* e)
34{ 34{
35 m_pDrawPadCanvas->backupPage();
36
35 m_mousePressed = true; 37 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 38 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37} 39}
38 40
39void EraseTool::mouseReleaseEvent(QMouseEvent* e) 41void EraseTool::mouseReleaseEvent(QMouseEvent* e)
40{ 42{
41 Q_UNUSED(e) 43 Q_UNUSED(e)
42 44
43 m_mousePressed = false; 45 m_mousePressed = false;
44
45 m_pDrawPadCanvas->backupPage();
46} 46}
47 47
48void EraseTool::mouseMoveEvent(QMouseEvent* e) 48void EraseTool::mouseMoveEvent(QMouseEvent* e)
49{ 49{
50 if (m_mousePressed) { 50 if (m_mousePressed) {
51 QPainter painter; 51 QPainter painter;
52 QPen pen(Qt::white, m_pDrawPad->pen().width()); 52 QPen pen(Qt::white, m_pDrawPad->pen().width());
53 painter.begin(m_pDrawPadCanvas->currentPage()); 53 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
54 painter.setPen(pen); 54 painter.setPen(pen);
55 m_polyline[2] = m_polyline[1]; 55 m_polyline[2] = m_polyline[1];
56 m_polyline[1] = m_polyline[0]; 56 m_polyline[1] = m_polyline[0];
57 m_polyline[0] = e->pos(); 57 m_polyline[0] = e->pos();
58 painter.drawPolyline(m_polyline); 58 painter.drawPolyline(m_polyline);
59 painter.end(); 59 painter.end();
60 60
61 QRect r = m_polyline.boundingRect(); 61 QRect r = m_polyline.boundingRect();
62 r = r.normalize(); 62 r = r.normalize();
63 r.setLeft(r.left() - m_pDrawPad->pen().width()); 63 r.setLeft(r.left() - m_pDrawPad->pen().width());
64 r.setTop(r.top() - m_pDrawPad->pen().width()); 64 r.setTop(r.top() - m_pDrawPad->pen().width());
65 r.setRight(r.right() + m_pDrawPad->pen().width()); 65 r.setRight(r.right() + m_pDrawPad->pen().width());
66 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 66 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
67 67
68 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), 68 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
69 m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 69 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
70 70
71 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), 71 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
72 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 72 m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
73 73
74 m_pDrawPadCanvas->viewport()->update(viewportRect); 74 m_pDrawPadCanvas->viewport()->update(viewportRect);
75 } 75 }
76} 76}
diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp
index 0177e1c..2a39d04 100644
--- a/noncore/graphics/drawpad/filltool.cpp
+++ b/noncore/graphics/drawpad/filltool.cpp
@@ -1,160 +1,160 @@
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 "filltool.h" 14#include "filltool.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "page.h" 18#include "page.h"
19 19
20#include <qimage.h> 20#include <qimage.h>
21 21
22const int FILL_THRESHOLD = 65536; 22const int FILL_THRESHOLD = 65536;
23 23
24FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 24FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
25 : Tool(drawPad, drawPadCanvas) 25 : Tool(drawPad, drawPadCanvas)
26{ 26{
27} 27}
28 28
29FillTool::~FillTool() 29FillTool::~FillTool()
30{ 30{
31} 31}
32 32
33void FillTool::mousePressEvent(QMouseEvent* e) 33void FillTool::mousePressEvent(QMouseEvent* e)
34{ 34{
35 int x = e->x(); 35 int x = e->x();
36 int y = e->y(); 36 int y = e->y();
37 37
38 m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); 38 m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage();
39 m_fillRgb = m_pDrawPad->brush().color().rgb(); 39 m_fillRgb = m_pDrawPad->brush().color().rgb();
40 m_oldRgb = m_image.pixel(x, y); 40 m_oldRgb = m_image.pixel(x, y);
41 41
42 if (m_oldRgb != m_fillRgb) { 42 if (m_oldRgb != m_fillRgb) {
43 m_pDrawPadCanvas->backupPage();
44
43 if (m_pDrawPad->antiAliasing()) { 45 if (m_pDrawPad->antiAliasing()) {
44 m_mask.create(m_image.width(), m_image.height(), 8, 2); 46 m_mask.create(m_image.width(), m_image.height(), 8, 2);
45 m_mask.fill(0); 47 m_mask.fill(0);
46 48
47 fillMaskLine(x, y); 49 fillMaskLine(x, y);
48 50
49 for (int i = 0; i < m_image.width(); i++) { 51 for (int i = 0; i < m_image.width(); i++) {
50 for (int j = 0; j < m_image.height(); j++) { 52 for (int j = 0; j < m_image.height(); j++) {
51 if (m_mask.pixelIndex(i, j) == 1) { 53 if (m_mask.pixelIndex(i, j) == 1) {
52 setInterpolatedPixel(i, j); 54 setInterpolatedPixel(i, j);
53 } 55 }
54 } 56 }
55 } 57 }
56 58
57 } else { 59 } else {
58 fillLine(x, y); 60 fillLine(x, y);
59 } 61 }
60 62
61 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); 63 m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image);
62 m_pDrawPadCanvas->viewport()->update(); 64 m_pDrawPadCanvas->viewport()->update();
63
64 m_pDrawPadCanvas->backupPage();
65 } 65 }
66} 66}
67 67
68void FillTool::mouseReleaseEvent(QMouseEvent* e) 68void FillTool::mouseReleaseEvent(QMouseEvent* e)
69{ 69{
70 Q_UNUSED(e) 70 Q_UNUSED(e)
71} 71}
72 72
73void FillTool::mouseMoveEvent(QMouseEvent* e) 73void FillTool::mouseMoveEvent(QMouseEvent* e)
74{ 74{
75 Q_UNUSED(e) 75 Q_UNUSED(e)
76} 76}
77 77
78void FillTool::fillLine(int x, int y) 78void FillTool::fillLine(int x, int y)
79{ 79{
80 if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { 80 if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) {
81 if (m_image.pixel(x, y) == m_oldRgb) { 81 if (m_image.pixel(x, y) == m_oldRgb) {
82 int x1, x2; 82 int x1, x2;
83 83
84 x1 = x - 1; 84 x1 = x - 1;
85 x2 = x + 1; 85 x2 = x + 1;
86 86
87 while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { 87 while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) {
88 x1--; 88 x1--;
89 } 89 }
90 90
91 while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { 91 while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) {
92 x2++; 92 x2++;
93 } 93 }
94 94
95 for (int i = x1 + 1; i < x2; i++) { 95 for (int i = x1 + 1; i < x2; i++) {
96 m_image.setPixel(i, y, m_fillRgb); 96 m_image.setPixel(i, y, m_fillRgb);
97 } 97 }
98 98
99 for (int i = x1 + 1; i < x2; i++) { 99 for (int i = x1 + 1; i < x2; i++) {
100 fillLine(i, y - 1); 100 fillLine(i, y - 1);
101 } 101 }
102 102
103 for (int i = x1 + 1; i < x2; i++) { 103 for (int i = x1 + 1; i < x2; i++) {
104 fillLine(i, y + 1); 104 fillLine(i, y + 1);
105 } 105 }
106 } 106 }
107 } 107 }
108} 108}
109 109
110void FillTool::fillMaskLine(int x, int y) 110void FillTool::fillMaskLine(int x, int y)
111{ 111{
112 if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { 112 if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) {
113 if (m_mask.pixelIndex(x, y) == 0) { 113 if (m_mask.pixelIndex(x, y) == 0) {
114 if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { 114 if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) {
115 int x1, x2; 115 int x1, x2;
116 116
117 x1 = x - 1; 117 x1 = x - 1;
118 x2 = x + 1; 118 x2 = x + 1;
119 119
120 while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { 120 while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) {
121 x1--; 121 x1--;
122 } 122 }
123 123
124 while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { 124 while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) {
125 x2++; 125 x2++;
126 } 126 }
127 127
128 for (int i = x1 + 1; i < x2; i++) { 128 for (int i = x1 + 1; i < x2; i++) {
129 m_mask.setPixel(i, y, 1); 129 m_mask.setPixel(i, y, 1);
130 } 130 }
131 131
132 for (int i = x1 + 1; i < x2; i++) { 132 for (int i = x1 + 1; i < x2; i++) {
133 fillMaskLine(i, y - 1); 133 fillMaskLine(i, y - 1);
134 } 134 }
135 135
136 for (int i = x1 + 1; i < x2; i++) { 136 for (int i = x1 + 1; i < x2; i++) {
137 fillMaskLine(i, y + 1); 137 fillMaskLine(i, y + 1);
138 } 138 }
139 } 139 }
140 } 140 }
141 } 141 }
142} 142}
143 143
144void FillTool::setInterpolatedPixel(int x, int y) 144void FillTool::setInterpolatedPixel(int x, int y)
145{ 145{
146 int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); 146 int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255);
147 int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255); 147 int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255);
148 int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255); 148 int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255);
149 149
150 m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue)); 150 m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue));
151} 151}
152 152
153int FillTool::rgbDistance(QRgb rgb1, QRgb rgb2) 153int FillTool::rgbDistance(QRgb rgb1, QRgb rgb2)
154{ 154{
155 int redDistance = qRed(rgb2) - qRed(rgb1); 155 int redDistance = qRed(rgb2) - qRed(rgb1);
156 int greenDistance = qGreen(rgb2) - qGreen(rgb1); 156 int greenDistance = qGreen(rgb2) - qGreen(rgb1);
157 int blueDistance = qBlue(rgb2) - qBlue(rgb1); 157 int blueDistance = qBlue(rgb2) - qBlue(rgb1);
158 158
159 return (redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance); 159 return (redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance);
160} 160}
diff --git a/noncore/graphics/drawpad/page.cpp b/noncore/graphics/drawpad/page.cpp
index 601d1c3..fbf3d01 100644
--- a/noncore/graphics/drawpad/page.cpp
+++ b/noncore/graphics/drawpad/page.cpp
@@ -1,59 +1,113 @@
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 "page.h" 14#include "page.h"
15 15
16const int PAGE_BACKUPS = 99;
17
16Page::Page() 18Page::Page()
17 : QPixmap()
18{ 19{
20 m_title = "";
19 m_lastModified = QDateTime::currentDateTime(); 21 m_lastModified = QDateTime::currentDateTime();
22 m_pPixmap = new QPixmap();
23
24 m_backHistory.setAutoDelete(true);
25 m_forwardHistory.setAutoDelete(true);
20} 26}
21 27
22Page::Page(QString title, int w, int h) 28Page::Page(QString title, int w, int h)
23 : QPixmap(w, h)
24{ 29{
25 m_title = title; 30 m_title = title;
26 m_lastModified = QDateTime::currentDateTime(); 31 m_lastModified = QDateTime::currentDateTime();
32 m_pPixmap = new QPixmap(w, h);
33
34 m_backHistory.setAutoDelete(true);
35 m_forwardHistory.setAutoDelete(true);
27} 36}
28 37
29Page::Page(QString title, const QSize& size) 38Page::Page(QString title, const QSize& size)
30 : QPixmap(size)
31{ 39{
32 m_title = title; 40 m_title = title;
33 m_lastModified = QDateTime::currentDateTime(); 41 m_lastModified = QDateTime::currentDateTime();
42 m_pPixmap = new QPixmap(size);
43
44 m_backHistory.setAutoDelete(true);
45 m_forwardHistory.setAutoDelete(true);
34} 46}
35 47
36Page::~Page() 48Page::~Page()
37{ 49{
50 delete m_pPixmap;
38} 51}
39 52
40QString Page::title() const 53QString Page::title() const
41{ 54{
42 return m_title; 55 return m_title;
43} 56}
44 57
45QDateTime Page::lastModified() const 58QDateTime Page::lastModified() const
46{ 59{
47 return m_lastModified; 60 return m_lastModified;
48} 61}
49 62
63QPixmap* Page::pixmap() const
64
65{
66 return m_pPixmap;
67}
68
50void Page::setTitle(QString title) 69void Page::setTitle(QString title)
51{ 70{
52 m_title = title; 71 m_title = title;
53} 72}
54 73
55void Page::setLastModified(QDateTime lastModified) 74void Page::setLastModified(QDateTime lastModified)
56{ 75{
57 m_lastModified = lastModified; 76 m_lastModified = lastModified;
58} 77}
59 78
79bool Page::undoEnabled()
80{
81 return (!m_backHistory.isEmpty());
82}
83
84bool Page::redoEnabled()
85{
86 return (!m_forwardHistory.isEmpty());
87}
88
89void Page::backup()
90{
91 setLastModified(QDateTime::currentDateTime());
92
93 while (m_backHistory.count() >= (PAGE_BACKUPS + 1)) {
94 m_backHistory.removeFirst();
95 }
96
97 m_backHistory.append(new QPixmap(*m_pPixmap));
98 m_forwardHistory.clear();
99}
100
101void Page::undo()
102{
103 m_forwardHistory.append(new QPixmap(*m_pPixmap));
104 m_pPixmap = new QPixmap(*(m_backHistory.last()));
105 m_backHistory.removeLast();
106}
107
108void Page::redo()
109{
110 m_backHistory.append(new QPixmap(*m_pPixmap));
111 m_pPixmap = new QPixmap(*(m_forwardHistory.last()));
112 m_forwardHistory.removeLast();
113}
diff --git a/noncore/graphics/drawpad/page.h b/noncore/graphics/drawpad/page.h
index 20a37b5..8ce7bc9 100644
--- a/noncore/graphics/drawpad/page.h
+++ b/noncore/graphics/drawpad/page.h
@@ -1,41 +1,55 @@
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 PAGE_H 14#ifndef PAGE_H
15#define PAGE_H 15#define PAGE_H
16 16
17#include <qpixmap.h> 17#include <qobject.h>
18 18
19#include <qdatetime.h> 19#include <qdatetime.h>
20#include <qlist.h>
21#include <qpixmap.h>
20 22
21class Page : public QPixmap 23class Page : public QObject
22{ 24{
23public: 25public:
24 Page(); 26 Page();
25 Page(QString title, int w, int h); 27 Page(QString title, int w, int h);
26 Page(QString title, const QSize& size); 28 Page(QString title, const QSize& size);
27 29
28 ~Page(); 30 ~Page();
29 31
30 QString title() const; 32 QString title() const;
31 QDateTime lastModified() const; 33 QDateTime lastModified() const;
34 QPixmap* pixmap() const;
32 35
33 void setTitle(QString title); 36 void setTitle(QString title);
34 void setLastModified(QDateTime lastModified); 37 void setLastModified(QDateTime lastModified);
35 38
39 bool undoEnabled();
40 bool redoEnabled();
41
42 void backup();
43 void undo();
44 void redo();
45
36private: 46private:
37 QString m_title; 47 QString m_title;
38 QDateTime m_lastModified; 48 QDateTime m_lastModified;
49 QPixmap* m_pPixmap;
50
51 QList<QPixmap> m_backHistory;
52 QList<QPixmap> m_forwardHistory;
39}; 53};
40 54
41#endif // PAGE_H 55#endif // PAGE_H
diff --git a/noncore/graphics/drawpad/pageinformationdialog.cpp b/noncore/graphics/drawpad/pageinformationdialog.cpp
index c0d055e..cb14d73 100644
--- a/noncore/graphics/drawpad/pageinformationdialog.cpp
+++ b/noncore/graphics/drawpad/pageinformationdialog.cpp
@@ -1,97 +1,97 @@
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 "pageinformationdialog.h" 14#include "pageinformationdialog.h"
15 15
16#include "page.h" 16#include "page.h"
17 17
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/timestring.h> 19#include <qpe/timestring.h>
20 20
21#include <qgroupbox.h> 21#include <qgroupbox.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qlayout.h> 23#include <qlayout.h>
24#include <qlineedit.h> 24#include <qlineedit.h>
25 25
26PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const char* name) 26PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const char* name)
27 : QDialog(parent, name, true) 27 : QDialog(parent, name, true)
28{ 28{
29 m_pPage = page; 29 m_pPage = page;
30 30
31 setCaption(tr("Page Information")); 31 setCaption(tr("Page Information"));
32 32
33 QGroupBox* generalGroupBox = new QGroupBox(0, Qt::Vertical, tr("General"), this); 33 QGroupBox* generalGroupBox = new QGroupBox(0, Qt::Vertical, tr("General"), this);
34 34
35 QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox); 35 QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox);
36 36
37 m_pTitleLineEdit = new QLineEdit(generalGroupBox); 37 m_pTitleLineEdit = new QLineEdit(generalGroupBox);
38 m_pTitleLineEdit->setText(page->title()); 38 m_pTitleLineEdit->setText(page->title());
39 39
40 QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox); 40 QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox);
41 QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox); 41 QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox);
42 42
43 QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this); 43 QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this);
44 44
45 QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox); 45 QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox);
46 QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->width()), sizeGroupBox); 46 QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->pixmap()->width()), sizeGroupBox);
47 47
48 QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox); 48 QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox);
49 QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->height()), sizeGroupBox); 49 QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->pixmap()->height()), sizeGroupBox);
50 50
51 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); 51 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
52 generalGroupBox->layout()->setSpacing(4); 52 generalGroupBox->layout()->setSpacing(4);
53 sizeGroupBox->layout()->setSpacing(4); 53 sizeGroupBox->layout()->setSpacing(4);
54 QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2); 54 QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2);
55 QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); 55 QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2);
56 56
57 generalLayout->addWidget(titleLabel, 0, 0); 57 generalLayout->addWidget(titleLabel, 0, 0);
58 generalLayout->addWidget(m_pTitleLineEdit, 0, 1); 58 generalLayout->addWidget(m_pTitleLineEdit, 0, 1);
59 generalLayout->addWidget(dateLabel, 1, 0); 59 generalLayout->addWidget(dateLabel, 1, 0);
60 generalLayout->addWidget(dateValueLabel, 1, 1); 60 generalLayout->addWidget(dateValueLabel, 1, 1);
61 61
62 generalLayout->setColStretch(1, 1); 62 generalLayout->setColStretch(1, 1);
63 63
64 sizeLayout->addWidget(widthLabel, 0, 0); 64 sizeLayout->addWidget(widthLabel, 0, 0);
65 sizeLayout->addWidget(widthValueLabel, 0, 1); 65 sizeLayout->addWidget(widthValueLabel, 0, 1);
66 sizeLayout->addWidget(heightLabel, 1, 0); 66 sizeLayout->addWidget(heightLabel, 1, 0);
67 sizeLayout->addWidget(heightValueLabel, 1, 1); 67 sizeLayout->addWidget(heightValueLabel, 1, 1);
68 68
69 sizeLayout->setColStretch(1, 1); 69 sizeLayout->setColStretch(1, 1);
70 70
71 mainLayout->addWidget(generalGroupBox); 71 mainLayout->addWidget(generalGroupBox);
72 mainLayout->addWidget(sizeGroupBox); 72 mainLayout->addWidget(sizeGroupBox);
73} 73}
74 74
75PageInformationDialog::~PageInformationDialog() 75PageInformationDialog::~PageInformationDialog()
76{ 76{
77} 77}
78 78
79QString PageInformationDialog::selectedTitle() 79QString PageInformationDialog::selectedTitle()
80{ 80{
81 return (m_pTitleLineEdit->text()); 81 return (m_pTitleLineEdit->text());
82} 82}
83 83
84QString PageInformationDialog::dateTimeString(QDateTime dateTime) 84QString PageInformationDialog::dateTimeString(QDateTime dateTime)
85{ 85{
86 QString result; 86 QString result;
87 87
88 Config config("qpe"); 88 Config config("qpe");
89 config.setGroup("Date"); 89 config.setGroup("Date");
90 90
91 QChar separator = config.readEntry("Separator", "/")[0]; 91 QChar separator = config.readEntry("Separator", "/")[0];
92 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear); 92 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear);
93 93
94 for (int i = 0; i < 3; i++) { 94 for (int i = 0; i < 3; i++) {
95 switch((shortOrder >> (i * 3)) & 0x0007) { 95 switch((shortOrder >> (i * 3)) & 0x0007) {
96 case 0x0001: 96 case 0x0001:
97 result += QString().sprintf("%02d", dateTime.date().day()); 97 result += QString().sprintf("%02d", dateTime.date().day());
diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp
index a4f846e..b9b52bc 100644
--- a/noncore/graphics/drawpad/pointtool.cpp
+++ b/noncore/graphics/drawpad/pointtool.cpp
@@ -1,111 +1,111 @@
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 "pointtool.h" 14#include "pointtool.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "page.h" 18#include "page.h"
19 19
20#include <qimage.h> 20#include <qimage.h>
21#include <qpainter.h> 21#include <qpainter.h>
22 22
23PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 23PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
24 : Tool(drawPad, drawPadCanvas) 24 : Tool(drawPad, drawPadCanvas)
25{ 25{
26 m_mousePressed = false; 26 m_mousePressed = false;
27 m_polyline.resize(3); 27 m_polyline.resize(3);
28} 28}
29 29
30PointTool::~PointTool() 30PointTool::~PointTool()
31{ 31{
32} 32}
33 33
34void PointTool::mousePressEvent(QMouseEvent* e) 34void PointTool::mousePressEvent(QMouseEvent* e)
35{ 35{
36 m_pDrawPadCanvas->backupPage();
37
36 m_mousePressed = true; 38 m_mousePressed = true;
37 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 39 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
38} 40}
39 41
40void PointTool::mouseReleaseEvent(QMouseEvent* e) 42void PointTool::mouseReleaseEvent(QMouseEvent* e)
41{ 43{
42 Q_UNUSED(e) 44 Q_UNUSED(e)
43 45
44 m_mousePressed = false; 46 m_mousePressed = false;
45
46 m_pDrawPadCanvas->backupPage();
47} 47}
48 48
49void PointTool::mouseMoveEvent(QMouseEvent* e) 49void PointTool::mouseMoveEvent(QMouseEvent* e)
50{ 50{
51 if (m_mousePressed) { 51 if (m_mousePressed) {
52 m_polyline[2] = m_polyline[1]; 52 m_polyline[2] = m_polyline[1];
53 m_polyline[1] = m_polyline[0]; 53 m_polyline[1] = m_polyline[0];
54 m_polyline[0] = e->pos(); 54 m_polyline[0] = e->pos();
55 55
56 QRect r = m_polyline.boundingRect(); 56 QRect r = m_polyline.boundingRect();
57 r = r.normalize(); 57 r = r.normalize();
58 r.setLeft(r.left() - m_pDrawPad->pen().width()); 58 r.setLeft(r.left() - m_pDrawPad->pen().width());
59 r.setTop(r.top() - m_pDrawPad->pen().width()); 59 r.setTop(r.top() - m_pDrawPad->pen().width());
60 r.setRight(r.right() + m_pDrawPad->pen().width()); 60 r.setRight(r.right() + m_pDrawPad->pen().width());
61 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 61 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
62 62
63 QPainter painter; 63 QPainter painter;
64 painter.begin(m_pDrawPadCanvas->currentPage()); 64 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
65 65
66 if (m_pDrawPad->antiAliasing()) { 66 if (m_pDrawPad->antiAliasing()) {
67 QPixmap areaPixmap(r.width(), r.height()); 67 QPixmap areaPixmap(r.width(), r.height());
68 bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); 68 bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r);
69 69
70 QImage areaImage = areaPixmap.convertToImage(); 70 QImage areaImage = areaPixmap.convertToImage();
71 QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); 71 QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
72 72
73 QPixmap bigAreaPixmap; 73 QPixmap bigAreaPixmap;
74 bigAreaPixmap.convertFromImage(bigAreaImage); 74 bigAreaPixmap.convertFromImage(bigAreaImage);
75 75
76 QPen bigAreaPen = m_pDrawPad->pen(); 76 QPen bigAreaPen = m_pDrawPad->pen();
77 bigAreaPen.setWidth(bigAreaPen.width() * 3); 77 bigAreaPen.setWidth(bigAreaPen.width() * 3);
78 78
79 QPainter bigAreaPainter; 79 QPainter bigAreaPainter;
80 bigAreaPainter.begin(&bigAreaPixmap); 80 bigAreaPainter.begin(&bigAreaPixmap);
81 bigAreaPainter.setPen(bigAreaPen); 81 bigAreaPainter.setPen(bigAreaPen);
82 82
83 QPointArray bigAreaPolyline(3); 83 QPointArray bigAreaPolyline(3);
84 bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1); 84 bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1);
85 bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1); 85 bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1);
86 bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1); 86 bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1);
87 87
88 bigAreaPainter.drawPolyline(bigAreaPolyline); 88 bigAreaPainter.drawPolyline(bigAreaPolyline);
89 bigAreaPainter.end(); 89 bigAreaPainter.end();
90 90
91 bigAreaImage = bigAreaPixmap.convertToImage(); 91 bigAreaImage = bigAreaPixmap.convertToImage();
92 areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); 92 areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
93 areaPixmap.convertFromImage(areaImage); 93 areaPixmap.convertFromImage(areaImage);
94 94
95 painter.drawPixmap(r.x(), r.y(), areaPixmap); 95 painter.drawPixmap(r.x(), r.y(), areaPixmap);
96 } else { 96 } else {
97 painter.setPen(m_pDrawPad->pen()); 97 painter.setPen(m_pDrawPad->pen());
98 painter.drawPolyline(m_polyline); 98 painter.drawPolyline(m_polyline);
99 } 99 }
100 100
101 painter.end(); 101 painter.end();
102 102
103 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), 103 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
104 m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 104 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
105 105
106 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), 106 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
107 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 107 m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
108 108
109 m_pDrawPadCanvas->viewport()->update(viewportRect); 109 m_pDrawPadCanvas->viewport()->update(viewportRect);
110 } 110 }
111} 111}
diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp
index 8870a78..22e3dd6 100644
--- a/noncore/graphics/drawpad/shapetool.cpp
+++ b/noncore/graphics/drawpad/shapetool.cpp
@@ -1,94 +1,94 @@
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 "shapetool.h" 14#include "shapetool.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "page.h" 18#include "page.h"
19 19
20#include <qpainter.h> 20#include <qpainter.h>
21 21
22ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 22ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : Tool(drawPad, drawPadCanvas) 23 : Tool(drawPad, drawPadCanvas)
24{ 24{
25 m_mousePressed = false; 25 m_mousePressed = false;
26 m_polyline.resize(3); 26 m_polyline.resize(3);
27} 27}
28 28
29ShapeTool::~ShapeTool() 29ShapeTool::~ShapeTool()
30{ 30{
31} 31}
32 32
33void ShapeTool::mousePressEvent(QMouseEvent* e) 33void ShapeTool::mousePressEvent(QMouseEvent* e)
34{ 34{
35 m_pDrawPadCanvas->backupPage();
36
35 m_mousePressed = true; 37 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 38 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37} 39}
38 40
39void ShapeTool::mouseReleaseEvent(QMouseEvent* e) 41void ShapeTool::mouseReleaseEvent(QMouseEvent* e)
40{ 42{
41 Q_UNUSED(e) 43 Q_UNUSED(e)
42 44
43 QPainter painter; 45 QPainter painter;
44 painter.begin(m_pDrawPadCanvas->currentPage()); 46 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
45 drawFinalShape(painter); 47 drawFinalShape(painter);
46 painter.end(); 48 painter.end();
47 49
48 QRect r = m_polyline.boundingRect(); 50 QRect r = m_polyline.boundingRect();
49 r = r.normalize(); 51 r = r.normalize();
50 r.setLeft(r.left() - m_pDrawPad->pen().width()); 52 r.setLeft(r.left() - m_pDrawPad->pen().width());
51 r.setTop(r.top() - m_pDrawPad->pen().width()); 53 r.setTop(r.top() - m_pDrawPad->pen().width());
52 r.setRight(r.right() + m_pDrawPad->pen().width()); 54 r.setRight(r.right() + m_pDrawPad->pen().width());
53 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 55 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
54 56
55 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), 57 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
56 m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 58 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
57 59
58 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), 60 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
59 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 61 m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
60 62
61 m_pDrawPadCanvas->viewport()->update(viewportRect); 63 m_pDrawPadCanvas->viewport()->update(viewportRect);
62 64
63 m_mousePressed = false; 65 m_mousePressed = false;
64
65 m_pDrawPadCanvas->backupPage();
66} 66}
67 67
68void ShapeTool::mouseMoveEvent(QMouseEvent* e) 68void ShapeTool::mouseMoveEvent(QMouseEvent* e)
69{ 69{
70 if (m_mousePressed) { 70 if (m_mousePressed) {
71 m_polyline[0] = e->pos(); 71 m_polyline[0] = e->pos();
72 QPainter painter; 72 QPainter painter;
73 painter.begin(m_pDrawPadCanvas->currentPage()); 73 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
74 drawTemporaryShape(painter); 74 drawTemporaryShape(painter);
75 painter.end(); 75 painter.end();
76 76
77 QRect r = m_polyline.boundingRect(); 77 QRect r = m_polyline.boundingRect();
78 r = r.normalize(); 78 r = r.normalize();
79 r.setLeft(r.left() - m_pDrawPad->pen().width()); 79 r.setLeft(r.left() - m_pDrawPad->pen().width());
80 r.setTop(r.top() - m_pDrawPad->pen().width()); 80 r.setTop(r.top() - m_pDrawPad->pen().width());
81 r.setRight(r.right() + m_pDrawPad->pen().width()); 81 r.setRight(r.right() + m_pDrawPad->pen().width());
82 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 82 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
83 83
84 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), 84 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
85 m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); 85 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
86 86
87 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), 87 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
88 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 88 m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
89 89
90 m_pDrawPadCanvas->viewport()->update(viewportRect); 90 m_pDrawPadCanvas->viewport()->update(viewportRect);
91 91
92 m_polyline[1] = m_polyline[0]; 92 m_polyline[1] = m_polyline[0];
93 } 93 }
94} 94}
diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp
index 34c8a76..9037abd 100644
--- a/noncore/graphics/drawpad/texttool.cpp
+++ b/noncore/graphics/drawpad/texttool.cpp
@@ -11,69 +11,69 @@
11 * * 11 * *
12 ***************************************************************************/ 12 ***************************************************************************/
13 13
14#include "texttool.h" 14#include "texttool.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "page.h" 18#include "page.h"
19 19
20#include <qlayout.h> 20#include <qlayout.h>
21#include <qlineedit.h> 21#include <qlineedit.h>
22#include <qpainter.h> 22#include <qpainter.h>
23 23
24TextToolDialog::TextToolDialog(QWidget* parent, const char* name) 24TextToolDialog::TextToolDialog(QWidget* parent, const char* name)
25 : QDialog(parent, name, true) 25 : QDialog(parent, name, true)
26{ 26{
27 setCaption(tr("Insert Text")); 27 setCaption(tr("Insert Text"));
28 28
29 m_pLineEdit = new QLineEdit(this); 29 m_pLineEdit = new QLineEdit(this);
30 30
31 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); 31 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
32 32
33 mainLayout->addWidget(m_pLineEdit); 33 mainLayout->addWidget(m_pLineEdit);
34} 34}
35 35
36TextToolDialog::~TextToolDialog() 36TextToolDialog::~TextToolDialog()
37{ 37{
38} 38}
39 39
40QString TextToolDialog::text() 40QString TextToolDialog::text()
41{ 41{
42 return m_pLineEdit->text(); 42 return m_pLineEdit->text();
43} 43}
44 44
45TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 45TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
46 : Tool(drawPad, drawPadCanvas) 46 : Tool(drawPad, drawPadCanvas)
47{ 47{
48} 48}
49 49
50TextTool::~TextTool() 50TextTool::~TextTool()
51{ 51{
52} 52}
53 53
54void TextTool::mousePressEvent(QMouseEvent* e) 54void TextTool::mousePressEvent(QMouseEvent* e)
55{ 55{
56 TextToolDialog textToolDialog(m_pDrawPad); 56 TextToolDialog textToolDialog(m_pDrawPad);
57 57
58 if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { 58 if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) {
59 m_pDrawPadCanvas->backupPage();
60
59 QPainter painter; 61 QPainter painter;
60 painter.begin(m_pDrawPadCanvas->currentPage()); 62 painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
61 painter.setPen(m_pDrawPad->pen()); 63 painter.setPen(m_pDrawPad->pen());
62 painter.drawText(e->x(), e->y(), textToolDialog.text()); 64 painter.drawText(e->x(), e->y(), textToolDialog.text());
63 painter.end(); 65 painter.end();
64 66
65 m_pDrawPadCanvas->viewport()->update(); 67 m_pDrawPadCanvas->viewport()->update();
66
67 m_pDrawPadCanvas->backupPage();
68 } 68 }
69} 69}
70 70
71void TextTool::mouseReleaseEvent(QMouseEvent* e) 71void TextTool::mouseReleaseEvent(QMouseEvent* e)
72{ 72{
73 Q_UNUSED(e) 73 Q_UNUSED(e)
74} 74}
75 75
76void TextTool::mouseMoveEvent(QMouseEvent* e) 76void TextTool::mouseMoveEvent(QMouseEvent* e)
77{ 77{
78 Q_UNUSED(e) 78 Q_UNUSED(e)
79} 79}
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 14092bf..9b08ca2 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,109 +1,109 @@
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 "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18#include "newpagedialog.h" 18#include "newpagedialog.h"
19#include "page.h" 19#include "page.h"
20 20
21#include <qpe/config.h> 21#include <qpe/config.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/timestring.h> 23#include <qpe/timestring.h>
24 24
25#include <qapplication.h> 25#include <qapplication.h>
26#include <qimage.h> 26#include <qimage.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30 30
31#define THUMBNAIL_SIZE 48 31#define THUMBNAIL_SIZE 48
32 32
33PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) 33PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
34 : QListBoxItem(parent) 34 : QListBoxItem(parent)
35{ 35{
36 m_pPage = page; 36 m_pPage = page;
37 37
38 QImage image = m_pPage->convertToImage(); 38 QImage image = m_pPage->pixmap()->convertToImage();
39 39
40 int previewWidth = THUMBNAIL_SIZE; 40 int previewWidth = THUMBNAIL_SIZE;
41 int previewHeight = THUMBNAIL_SIZE; 41 int previewHeight = THUMBNAIL_SIZE;
42 42
43 float widthScale = 1.0; 43 float widthScale = 1.0;
44 float heightScale = 1.0; 44 float heightScale = 1.0;
45 45
46 if (previewWidth < image.width()) { 46 if (previewWidth < image.width()) {
47 widthScale = (float)previewWidth / float(image.width()); 47 widthScale = (float)previewWidth / float(image.width());
48 } 48 }
49 49
50 if (previewHeight < image.height()) { 50 if (previewHeight < image.height()) {
51 heightScale = (float)previewHeight / float(image.height()); 51 heightScale = (float)previewHeight / float(image.height());
52 } 52 }
53 53
54 float scale = (widthScale < heightScale ? widthScale : heightScale); 54 float scale = (widthScale < heightScale ? widthScale : heightScale);
55 QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); 55 QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
56 56
57 m_thumbnail.convertFromImage(thumbnailImage); 57 m_thumbnail.convertFromImage(thumbnailImage);
58 58
59 m_titleText = QObject::tr("Title:") + " " + m_pPage->title(); 59 m_titleText = QObject::tr("Title:") + " " + m_pPage->title();
60 m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width()) 60 m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->pixmap()->width())
61 + "x" + QString::number(m_pPage->height()); 61 + "x" + QString::number(m_pPage->pixmap()->height());
62 m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified()); 62 m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified());
63 63
64 QColor baseColor = parent->colorGroup().base(); 64 QColor baseColor = parent->colorGroup().base();
65 int h, s, v; 65 int h, s, v;
66 baseColor.hsv(&h, &s, &v); 66 baseColor.hsv(&h, &s, &v);
67 67
68 if (v > 128) { 68 if (v > 128) {
69 m_alternateColor = baseColor.dark(115); 69 m_alternateColor = baseColor.dark(115);
70 } else if (baseColor != Qt::black) { 70 } else if (baseColor != Qt::black) {
71 m_alternateColor = baseColor.light(115); 71 m_alternateColor = baseColor.light(115);
72 } else { 72 } else {
73 m_alternateColor = QColor(32, 32, 32); 73 m_alternateColor = QColor(32, 32, 32);
74 } 74 }
75} 75}
76 76
77PageListBoxItem::~PageListBoxItem() 77PageListBoxItem::~PageListBoxItem()
78{ 78{
79} 79}
80 80
81int PageListBoxItem::height(const QListBox*) const 81int PageListBoxItem::height(const QListBox*) const
82{ 82{
83 return QMAX(THUMBNAIL_SIZE + 4, QApplication::globalStrut().height()); 83 return QMAX(THUMBNAIL_SIZE + 4, QApplication::globalStrut().height());
84} 84}
85 85
86int PageListBoxItem::width(const QListBox* lb) const 86int PageListBoxItem::width(const QListBox* lb) const
87{ 87{
88 QFontMetrics fontMetrics = lb->fontMetrics(); 88 QFontMetrics fontMetrics = lb->fontMetrics();
89 int maxtextLength = QMAX(fontMetrics.width(m_titleText), 89 int maxtextLength = QMAX(fontMetrics.width(m_titleText),
90 QMAX(fontMetrics.width(m_dimensionText), 90 QMAX(fontMetrics.width(m_dimensionText),
91 fontMetrics.width(m_dateText))); 91 fontMetrics.width(m_dateText)));
92 92
93 return QMAX(THUMBNAIL_SIZE + maxtextLength + 8, QApplication::globalStrut().width()); 93 return QMAX(THUMBNAIL_SIZE + maxtextLength + 8, QApplication::globalStrut().width());
94} 94}
95 95
96void PageListBoxItem::paint(QPainter *painter) 96void PageListBoxItem::paint(QPainter *painter)
97{ 97{
98 QRect itemRect = listBox()->itemRect(this); 98 QRect itemRect = listBox()->itemRect(this);
99 99
100 if (!selected() && (listBox()->index(this) % 2)) { 100 if (!selected() && (listBox()->index(this) % 2)) {
101 painter->fillRect(0, 0, itemRect.width(), itemRect.height(), m_alternateColor); 101 painter->fillRect(0, 0, itemRect.width(), itemRect.height(), m_alternateColor);
102 } 102 }
103 103
104 painter->drawPixmap(2 + (THUMBNAIL_SIZE - m_thumbnail.width()) / 2, 104 painter->drawPixmap(2 + (THUMBNAIL_SIZE - m_thumbnail.width()) / 2,
105 2 + (THUMBNAIL_SIZE - m_thumbnail.height()) / 2, 105 2 + (THUMBNAIL_SIZE - m_thumbnail.height()) / 2,
106 m_thumbnail); 106 m_thumbnail);
107 107
108 QFont standardFont = painter->font(); 108 QFont standardFont = painter->font();
109 QFont boldFont = painter->font(); 109 QFont boldFont = painter->font();