summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-26 14:17:12 (UTC)
committer leseb <leseb>2002-06-26 14:17:12 (UTC)
commit531bb3c03f5576523a3c7ccecc714362507f69e1 (patch) (unidiff)
tree8bdda021e3ddd110ca75df06a1f6a5fbf0429a6c
parent527c3a7240bee3fe1d7c000aecc8ff0a01219fdd (diff)
downloadopie-531bb3c03f5576523a3c7ccecc714362507f69e1.zip
opie-531bb3c03f5576523a3c7ccecc714362507f69e1.tar.gz
opie-531bb3c03f5576523a3c7ccecc714362507f69e1.tar.bz2
Add application config
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp39
-rw-r--r--noncore/graphics/drawpad/drawpad.h6
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp13
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h1
4 files changed, 54 insertions, 5 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index b29f5ba..4eb47a5 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -1,621 +1,650 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * DrawPad - a drawing program for Opie Environment * 3 * DrawPad - a drawing program for Opie Environment *
4 * * 4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * 5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * * 6 * *
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 * * 11 * *
12 ***************************************************************************/ 12 ***************************************************************************/
13 13
14#include "drawpad.h" 14#include "drawpad.h"
15 15
16#include "drawpadcanvas.h" 16#include "drawpadcanvas.h"
17#include "ellipsetool.h" 17#include "ellipsetool.h"
18#include "erasetool.h" 18#include "erasetool.h"
19#include "exportdialog.h" 19#include "exportdialog.h"
20#include "filledellipsetool.h" 20#include "filledellipsetool.h"
21#include "filledrectangletool.h" 21#include "filledrectangletool.h"
22#include "filltool.h" 22#include "filltool.h"
23#include "importdialog.h" 23#include "importdialog.h"
24#include "linetool.h" 24#include "linetool.h"
25#include "newpagedialog.h" 25#include "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/global.h> 38#include <qpe/global.h>
38#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
39#include <qpe/qpetoolbar.h> 40#include <qpe/qpetoolbar.h>
40#include <qpe/resource.h> 41#include <qpe/resource.h>
41 42
42#include <qaction.h> 43#include <qaction.h>
43#include <qfile.h> 44#include <qfile.h>
44#include <qmessagebox.h> 45#include <qmessagebox.h>
45#include <qpainter.h> 46#include <qpainter.h>
46#include <qspinbox.h> 47#include <qspinbox.h>
47#include <qtoolbutton.h> 48#include <qtoolbutton.h>
48#include <qtooltip.h> 49#include <qtooltip.h>
49 50
50DrawPad::DrawPad(QWidget* parent, const char* name) 51DrawPad::DrawPad(QWidget* parent, const char* name)
51 : QMainWindow(parent, name) 52 : QMainWindow(parent, name)
52{ 53{
53 // init members 54 // init members
54 55
55 m_pDrawPadCanvas = new DrawPadCanvas(this, this); 56 m_pDrawPadCanvas = new DrawPadCanvas(this, this);
56 57
57 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); 58 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
58 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); 59 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
59 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); 60 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
60 61
61 setCentralWidget(m_pDrawPadCanvas); 62 setCentralWidget(m_pDrawPadCanvas);
62 63
63 // init menu 64 // init menu
64 65
65 setToolBarsMovable(false); 66 setToolBarsMovable(false);
66 67
67 QPEToolBar* menuToolBar = new QPEToolBar(this); 68 QPEToolBar* menuToolBar = new QPEToolBar(this);
68 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); 69 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
69 70
70 QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); 71 QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar);
71 72
72 QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); 73 QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this);
73 connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); 74 connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll()));
74 deleteAllAction->addTo(toolsPopupMenu); 75 deleteAllAction->addTo(toolsPopupMenu);
75 76
76 toolsPopupMenu->insertSeparator(); 77 toolsPopupMenu->insertSeparator();
77 78
78 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); 79 QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this);
79 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); 80 connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage()));
80 importPageAction->addTo(toolsPopupMenu); 81 importPageAction->addTo(toolsPopupMenu);
81 82
82 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); 83 QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this);
83 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); 84 connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage()));
84 exportPageAction->addTo(toolsPopupMenu); 85 exportPageAction->addTo(toolsPopupMenu);
85 86
86 toolsPopupMenu->insertSeparator(); 87 toolsPopupMenu->insertSeparator();
87 88
88 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); 89 QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this);
89 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); 90 connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView()));
90 thumbnailViewAction->addTo(toolsPopupMenu); 91 thumbnailViewAction->addTo(toolsPopupMenu);
91 92
92 QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); 93 QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this);
93 connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); 94 connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation()));
94 pageInformationAction->addTo(toolsPopupMenu); 95 pageInformationAction->addTo(toolsPopupMenu);
95 96
96 toolsPopupMenu->insertSeparator(); 97 toolsPopupMenu->insertSeparator();
97 98
98 m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); 99 m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this);
99 m_pAntiAliasingAction->setToggleAction(true); 100 m_pAntiAliasingAction->setToggleAction(true);
100 m_pAntiAliasingAction->addTo(toolsPopupMenu); 101 m_pAntiAliasingAction->addTo(toolsPopupMenu);
101 102
102 menuBar->insertItem(tr("Tools"), toolsPopupMenu); 103 menuBar->insertItem(tr("Tools"), toolsPopupMenu);
103 104
104 // init page toolbar 105 // init page toolbar
105 106
106 QPEToolBar* pageToolBar = new QPEToolBar(this); 107 QPEToolBar* pageToolBar = new QPEToolBar(this);
107 108
108 QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); 109 QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
109 connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); 110 connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
110 newPageAction->addTo(pageToolBar); 111 newPageAction->addTo(pageToolBar);
111 112
112 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); 113 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
113 connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); 114 connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage()));
114 clearPageAction->addTo(pageToolBar); 115 clearPageAction->addTo(pageToolBar);
115 116
116 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); 117 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
117 connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); 118 connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
118 deletePageAction->addTo(pageToolBar); 119 deletePageAction->addTo(pageToolBar);
119 120
120 QPEToolBar* emptyToolBar = new QPEToolBar(this); 121 QPEToolBar* emptyToolBar = new QPEToolBar(this);
121 emptyToolBar->setHorizontalStretchable(true); 122 emptyToolBar->setHorizontalStretchable(true);
122 123
123 // init navigation toolbar 124 // init navigation toolbar
124 125
125 QPEToolBar* navigationToolBar = new QPEToolBar(this); 126 QPEToolBar* navigationToolBar = new QPEToolBar(this);
126 127
127 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); 128 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
128 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); 129 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
129 m_pUndoAction->addTo(navigationToolBar); 130 m_pUndoAction->addTo(navigationToolBar);
130 131
131 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); 132 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
132 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); 133 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
133 m_pRedoAction->addTo(navigationToolBar); 134 m_pRedoAction->addTo(navigationToolBar);
134 135
135 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); 136 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
136 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); 137 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
137 m_pFirstPageAction->addTo(navigationToolBar); 138 m_pFirstPageAction->addTo(navigationToolBar);
138 139
139 m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); 140 m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
140 connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); 141 connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage()));
141 m_pPreviousPageAction->addTo(navigationToolBar); 142 m_pPreviousPageAction->addTo(navigationToolBar);
142 143
143 m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); 144 m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
144 connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); 145 connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage()));
145 m_pNextPageAction->addTo(navigationToolBar); 146 m_pNextPageAction->addTo(navigationToolBar);
146 147
147 m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); 148 m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
148 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); 149 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
149 m_pLastPageAction->addTo(navigationToolBar); 150 m_pLastPageAction->addTo(navigationToolBar);
150 151
151 // init draw mode toolbar 152 // init draw mode toolbar
152 153
153 QPEToolBar* drawModeToolBar = new QPEToolBar(this); 154 QPEToolBar* drawModeToolBar = new QPEToolBar(this);
154 155
155 m_pLineToolButton = new QToolButton(drawModeToolBar); 156 m_pLineToolButton = new QToolButton(drawModeToolBar);
156 m_pLineToolButton->setToggleButton(true); 157 m_pLineToolButton->setToggleButton(true);
157 158
158 QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); 159 QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton);
159 160
160 m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this); 161 m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this);
161 connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); 162 connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool()));
162 m_pPointToolAction->addTo(linePopupMenu); 163 m_pPointToolAction->addTo(linePopupMenu);
163 164
164 m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this); 165 m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this);
165 connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); 166 connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool()));
166 m_pLineToolAction->addTo(linePopupMenu); 167 m_pLineToolAction->addTo(linePopupMenu);
167 168
168 m_pLineToolButton->setPopup(linePopupMenu); 169 m_pLineToolButton->setPopup(linePopupMenu);
169 m_pLineToolButton->setPopupDelay(0); 170 m_pLineToolButton->setPopupDelay(0);
170 171
171 m_pRectangleToolButton = new QToolButton(drawModeToolBar); 172 m_pRectangleToolButton = new QToolButton(drawModeToolBar);
172 m_pRectangleToolButton->setToggleButton(true); 173 m_pRectangleToolButton->setToggleButton(true);
173 174
174 QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); 175 QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton);
175 176
176 m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this); 177 m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this);
177 connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); 178 connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool()));
178 m_pRectangleToolAction->addTo(rectanglePopupMenu); 179 m_pRectangleToolAction->addTo(rectanglePopupMenu);
179 180
180 m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this); 181 m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this);
181 connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); 182 connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool()));
182 m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); 183 m_pFilledRectangleToolAction->addTo(rectanglePopupMenu);
183 184
184 m_pRectangleToolButton->setPopup(rectanglePopupMenu); 185 m_pRectangleToolButton->setPopup(rectanglePopupMenu);
185 m_pRectangleToolButton->setPopupDelay(0); 186 m_pRectangleToolButton->setPopupDelay(0);
186 187
187 m_pEllipseToolButton = new QToolButton(drawModeToolBar); 188 m_pEllipseToolButton = new QToolButton(drawModeToolBar);
188 m_pEllipseToolButton->setToggleButton(true); 189 m_pEllipseToolButton->setToggleButton(true);
189 190
190 QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); 191 QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton);
191 192
192 m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this); 193 m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this);
193 connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); 194 connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool()));
194 m_pEllipseToolAction->addTo(ellipsePopupMenu); 195 m_pEllipseToolAction->addTo(ellipsePopupMenu);
195 196
196 m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this); 197 m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this);
197 connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); 198 connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool()));
198 m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); 199 m_pFilledEllipseToolAction->addTo(ellipsePopupMenu);
199 200
200 m_pEllipseToolButton->setPopup(ellipsePopupMenu); 201 m_pEllipseToolButton->setPopup(ellipsePopupMenu);
201 m_pEllipseToolButton->setPopupDelay(0); 202 m_pEllipseToolButton->setPopupDelay(0);
202 203
203 m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this); 204 m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this);
204 m_pTextToolAction->setToggleAction(true); 205 m_pTextToolAction->setToggleAction(true);
205 connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); 206 connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool()));
206 m_pTextToolAction->addTo(drawModeToolBar); 207 m_pTextToolAction->addTo(drawModeToolBar);
207 208
208 m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); 209 m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this);
209 m_pFillToolAction->setToggleAction(true); 210 m_pFillToolAction->setToggleAction(true);
210 connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); 211 connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool()));
211 m_pFillToolAction->addTo(drawModeToolBar); 212 m_pFillToolAction->addTo(drawModeToolBar);
212 213
213 m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); 214 m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this);
214 m_pEraseToolAction->setToggleAction(true); 215 m_pEraseToolAction->setToggleAction(true);
215 connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); 216 connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool()));
216 m_pEraseToolAction->addTo(drawModeToolBar); 217 m_pEraseToolAction->addTo(drawModeToolBar);
217 218
218 m_pTool = 0; 219 m_pTool = 0;
219 setRectangleTool(); 220 setRectangleTool();
220 setEllipseTool(); 221 setEllipseTool();
221 setPointTool(); 222 setPointTool();
222 223
223 emptyToolBar = new QPEToolBar(this); 224 emptyToolBar = new QPEToolBar(this);
224 emptyToolBar->setHorizontalStretchable(true); 225 emptyToolBar->setHorizontalStretchable(true);
225 emptyToolBar->addSeparator(); 226 emptyToolBar->addSeparator();
226 227
227 // init draw parameters toolbar 228 // init draw parameters toolbar
228 229
229 QPEToolBar* drawParametersToolBar = new QPEToolBar(this); 230 QPEToolBar* drawParametersToolBar = new QPEToolBar(this);
230 231
231 QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); 232 m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
232 connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); 233 connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
233 234
234 QToolTip::add(penWidthSpinBox, tr("Pen Width")); 235 QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width"));
235 penWidthSpinBox->setValue(1); 236 m_pPenWidthSpinBox->setValue(1);
236 penWidthSpinBox->setFocusPolicy(QWidget::NoFocus); 237 m_pPenWidthSpinBox->setFocusPolicy(QWidget::NoFocus);
237 238
238 m_pPenColorToolButton = new QToolButton(drawParametersToolBar); 239 m_pPenColorToolButton = new QToolButton(drawParametersToolBar);
239 m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); 240 m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png"));
240 241
241 ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton); 242 ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton);
242 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); 243 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&)));
243 244
244 QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); 245 QToolTip::add(m_pPenColorToolButton, tr("Pen Color"));
245 m_pPenColorToolButton->setPopup(penColorPopupMenu); 246 m_pPenColorToolButton->setPopup(penColorPopupMenu);
246 m_pPenColorToolButton->setPopupDelay(0); 247 m_pPenColorToolButton->setPopupDelay(0);
247 248
248 changePenColor(Qt::black); 249 changePenColor(Qt::black);
249 250
250 m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); 251 m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
251 m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); 252 m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png"));
252 253
253 ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton); 254 ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton);
254 connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); 255 connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&)));
255 256
256 QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); 257 QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
257 m_pBrushColorToolButton->setPopup(brushColorPopupMenu); 258 m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
258 m_pBrushColorToolButton->setPopupDelay(0); 259 m_pBrushColorToolButton->setPopupDelay(0);
259 260
260 changeBrushColor(Qt::white); 261 changeBrushColor(Qt::white);
261 262
262 // init pages 263 // init pages
263 264
264 QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); 265 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
265 266
266 if (file.open(IO_ReadOnly)) { 267 if (file.open(IO_ReadOnly)) {
267 m_pDrawPadCanvas->load(&file); 268 m_pDrawPadCanvas->load(&file);
268 file.close(); 269 file.close();
269 } else { 270 } else {
270 m_pDrawPadCanvas->initialPage(); 271 m_pDrawPadCanvas->initialPage();
271 } 272 }
273
274 loadConfig();
272} 275}
273 276
274DrawPad::~DrawPad() 277DrawPad::~DrawPad()
275{ 278{
279 saveConfig();
280
276 QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); 281 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
277 282
278 if (file.open(IO_WriteOnly)) { 283 if (file.open(IO_WriteOnly)) {
279 m_pDrawPadCanvas->save(&file); 284 m_pDrawPadCanvas->save(&file);
280 file.close(); 285 file.close();
281 } 286 }
282} 287}
283 288
284bool DrawPad::antiAliasing() 289bool DrawPad::antiAliasing()
285{ 290{
286 return (m_pAntiAliasingAction->isOn()); 291 return (m_pAntiAliasingAction->isOn());
287} 292}
288 293
289void DrawPad::newPage() 294void DrawPad::newPage()
290{ 295{
291 QRect rect = m_pDrawPadCanvas->contentsRect(); 296 QRect rect = m_pDrawPadCanvas->contentsRect();
292 297
293 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); 298 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this);
294 299
295 if (newPageDialog.exec() == QDialog::Accepted) { 300 if (newPageDialog.exec() == QDialog::Accepted) {
296 m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), 301 m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(),
297 newPageDialog.selectedHeight(), newPageDialog.selectedColor()); 302 newPageDialog.selectedHeight(), newPageDialog.selectedColor());
298 } 303 }
299} 304}
300 305
301void DrawPad::clearPage() 306void DrawPad::clearPage()
302{ 307{
303 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), 308 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"),
304 QMessageBox::Information, QMessageBox::Yes, 309 QMessageBox::Information, QMessageBox::Yes,
305 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 310 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
306 QMessageBox::NoButton, this); 311 QMessageBox::NoButton, this);
307 312
308 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 313 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
309 messageBox.setButtonText(QMessageBox::No, tr("No")); 314 messageBox.setButtonText(QMessageBox::No, tr("No"));
310 315
311 if (messageBox.exec() == QMessageBox::Yes) { 316 if (messageBox.exec() == QMessageBox::Yes) {
312 m_pDrawPadCanvas->clearPage(); 317 m_pDrawPadCanvas->clearPage();
313 } 318 }
314} 319}
315 320
316void DrawPad::deletePage() 321void DrawPad::deletePage()
317{ 322{
318 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), 323 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"),
319 QMessageBox::Information, QMessageBox::Yes, 324 QMessageBox::Information, QMessageBox::Yes,
320 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 325 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
321 QMessageBox::NoButton, this); 326 QMessageBox::NoButton, this);
322 327
323 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 328 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
324 messageBox.setButtonText(QMessageBox::No, tr("No")); 329 messageBox.setButtonText(QMessageBox::No, tr("No"));
325 330
326 if (messageBox.exec() == QMessageBox::Yes) { 331 if (messageBox.exec() == QMessageBox::Yes) {
327 m_pDrawPadCanvas->deletePage(); 332 m_pDrawPadCanvas->deletePage();
328 } 333 }
329} 334}
330 335
331void DrawPad::setPointTool() 336void DrawPad::setPointTool()
332{ 337{
333 if (m_pTool) { 338 if (m_pTool) {
334 delete m_pTool; 339 delete m_pTool;
335 } 340 }
336 341
337 m_pTool = new PointTool(this, m_pDrawPadCanvas); 342 m_pTool = new PointTool(this, m_pDrawPadCanvas);
338 343
339 m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); 344 m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet());
340 QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); 345 QToolTip::add(m_pLineToolButton, m_pPointToolAction->text());
341 346
342 disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); 347 disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
343 connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); 348 connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated()));
344 349
345 m_pLineToolButton->setOn(true); 350 m_pLineToolButton->setOn(true);
346 m_pRectangleToolButton->setOn(false); 351 m_pRectangleToolButton->setOn(false);
347 m_pEllipseToolButton->setOn(false); 352 m_pEllipseToolButton->setOn(false);
348 m_pTextToolAction->setOn(false); 353 m_pTextToolAction->setOn(false);
349 m_pFillToolAction->setOn(false); 354 m_pFillToolAction->setOn(false);
350 m_pEraseToolAction->setOn(false); 355 m_pEraseToolAction->setOn(false);
351} 356}
352 357
353void DrawPad::setLineTool() 358void DrawPad::setLineTool()
354{ 359{
355 if (m_pTool) { 360 if (m_pTool) {
356 delete m_pTool; 361 delete m_pTool;
357 } 362 }
358 363
359 m_pTool = new LineTool(this, m_pDrawPadCanvas); 364 m_pTool = new LineTool(this, m_pDrawPadCanvas);
360 365
361 m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); 366 m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet());
362 QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); 367 QToolTip::add(m_pLineToolButton, m_pLineToolAction->text());
363 368
364 disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); 369 disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
365 connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); 370 connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated()));
366 371
367 m_pLineToolButton->setOn(true); 372 m_pLineToolButton->setOn(true);
368 m_pRectangleToolButton->setOn(false); 373 m_pRectangleToolButton->setOn(false);
369 m_pEllipseToolButton->setOn(false); 374 m_pEllipseToolButton->setOn(false);
370 m_pTextToolAction->setOn(false); 375 m_pTextToolAction->setOn(false);
371 m_pFillToolAction->setOn(false); 376 m_pFillToolAction->setOn(false);
372 m_pEraseToolAction->setOn(false); 377 m_pEraseToolAction->setOn(false);
373} 378}
374 379
375void DrawPad::setRectangleTool() 380void DrawPad::setRectangleTool()
376{ 381{
377 if (m_pTool) { 382 if (m_pTool) {
378 delete m_pTool; 383 delete m_pTool;
379 } 384 }
380 385
381 m_pTool = new RectangleTool(this, m_pDrawPadCanvas); 386 m_pTool = new RectangleTool(this, m_pDrawPadCanvas);
382 387
383 m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); 388 m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet());
384 QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); 389 QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text());
385 390
386 disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); 391 disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
387 connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); 392 connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated()));
388 393
389 m_pLineToolButton->setOn(false); 394 m_pLineToolButton->setOn(false);
390 m_pRectangleToolButton->setOn(true); 395 m_pRectangleToolButton->setOn(true);
391 m_pEllipseToolButton->setOn(false); 396 m_pEllipseToolButton->setOn(false);
392 m_pTextToolAction->setOn(false); 397 m_pTextToolAction->setOn(false);
393 m_pFillToolAction->setOn(false); 398 m_pFillToolAction->setOn(false);
394 m_pEraseToolAction->setOn(false); 399 m_pEraseToolAction->setOn(false);
395} 400}
396 401
397void DrawPad::setFilledRectangleTool() 402void DrawPad::setFilledRectangleTool()
398{ 403{
399 if (m_pTool) { 404 if (m_pTool) {
400 delete m_pTool; 405 delete m_pTool;
401 } 406 }
402 407
403 m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); 408 m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas);
404 409
405 m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); 410 m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet());
406 QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); 411 QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text());
407 412
408 disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); 413 disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
409 connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); 414 connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated()));
410 415
411 m_pLineToolButton->setOn(false); 416 m_pLineToolButton->setOn(false);
412 m_pRectangleToolButton->setOn(true); 417 m_pRectangleToolButton->setOn(true);
413 m_pEllipseToolButton->setOn(false); 418 m_pEllipseToolButton->setOn(false);
414 m_pTextToolAction->setOn(false); 419 m_pTextToolAction->setOn(false);
415 m_pFillToolAction->setOn(false); 420 m_pFillToolAction->setOn(false);
416 m_pEraseToolAction->setOn(false); 421 m_pEraseToolAction->setOn(false);
417} 422}
418 423
419void DrawPad::setEllipseTool() 424void DrawPad::setEllipseTool()
420{ 425{
421 if (m_pTool) { 426 if (m_pTool) {
422 delete m_pTool; 427 delete m_pTool;
423 } 428 }
424 429
425 m_pTool = new EllipseTool(this, m_pDrawPadCanvas); 430 m_pTool = new EllipseTool(this, m_pDrawPadCanvas);
426 431
427 m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); 432 m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet());
428 QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); 433 QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text());
429 434
430 disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); 435 disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
431 connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); 436 connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated()));
432 437
433 m_pLineToolButton->setOn(false); 438 m_pLineToolButton->setOn(false);
434 m_pRectangleToolButton->setOn(false); 439 m_pRectangleToolButton->setOn(false);
435 m_pEllipseToolButton->setOn(true); 440 m_pEllipseToolButton->setOn(true);
436 m_pTextToolAction->setOn(false); 441 m_pTextToolAction->setOn(false);
437 m_pFillToolAction->setOn(false); 442 m_pFillToolAction->setOn(false);
438 m_pEraseToolAction->setOn(false); 443 m_pEraseToolAction->setOn(false);
439} 444}
440 445
441void DrawPad::setFilledEllipseTool() 446void DrawPad::setFilledEllipseTool()
442{ 447{
443 if (m_pTool) { 448 if (m_pTool) {
444 delete m_pTool; 449 delete m_pTool;
445 } 450 }
446 451
447 m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); 452 m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas);
448 453
449 m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); 454 m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet());
450 QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); 455 QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text());
451 456
452 disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); 457 disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
453 connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); 458 connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated()));
454 459
455 m_pLineToolButton->setOn(false); 460 m_pLineToolButton->setOn(false);
456 m_pRectangleToolButton->setOn(false); 461 m_pRectangleToolButton->setOn(false);
457 m_pEllipseToolButton->setOn(true); 462 m_pEllipseToolButton->setOn(true);
458 m_pTextToolAction->setOn(false); 463 m_pTextToolAction->setOn(false);
459 m_pFillToolAction->setOn(false); 464 m_pFillToolAction->setOn(false);
460 m_pEraseToolAction->setOn(false); 465 m_pEraseToolAction->setOn(false);
461} 466}
462 467
463void DrawPad::setTextTool() 468void DrawPad::setTextTool()
464{ 469{
465 if (m_pTool) { 470 if (m_pTool) {
466 delete m_pTool; 471 delete m_pTool;
467 } 472 }
468 473
469 m_pTool = new TextTool(this, m_pDrawPadCanvas); 474 m_pTool = new TextTool(this, m_pDrawPadCanvas);
470 475
471 m_pLineToolButton->setOn(false); 476 m_pLineToolButton->setOn(false);
472 m_pRectangleToolButton->setOn(false); 477 m_pRectangleToolButton->setOn(false);
473 m_pEllipseToolButton->setOn(false); 478 m_pEllipseToolButton->setOn(false);
474 m_pTextToolAction->setOn(true); 479 m_pTextToolAction->setOn(true);
475 m_pFillToolAction->setOn(false); 480 m_pFillToolAction->setOn(false);
476 m_pEraseToolAction->setOn(false); 481 m_pEraseToolAction->setOn(false);
477} 482}
478 483
479void DrawPad::setFillTool() 484void DrawPad::setFillTool()
480{ 485{
481 if (m_pTool) { 486 if (m_pTool) {
482 delete m_pTool; 487 delete m_pTool;
483 } 488 }
484 489
485 m_pTool = new FillTool(this, m_pDrawPadCanvas); 490 m_pTool = new FillTool(this, m_pDrawPadCanvas);
486 491
487 m_pLineToolButton->setOn(false); 492 m_pLineToolButton->setOn(false);
488 m_pRectangleToolButton->setOn(false); 493 m_pRectangleToolButton->setOn(false);
489 m_pEllipseToolButton->setOn(false); 494 m_pEllipseToolButton->setOn(false);
490 m_pTextToolAction->setOn(false); 495 m_pTextToolAction->setOn(false);
491 m_pFillToolAction->setOn(true); 496 m_pFillToolAction->setOn(true);
492 m_pEraseToolAction->setOn(false); 497 m_pEraseToolAction->setOn(false);
493} 498}
494 499
495void DrawPad::setEraseTool() 500void DrawPad::setEraseTool()
496{ 501{
497 if (m_pTool) { 502 if (m_pTool) {
498 delete m_pTool; 503 delete m_pTool;
499 } 504 }
500 505
501 m_pTool = new EraseTool(this, m_pDrawPadCanvas); 506 m_pTool = new EraseTool(this, m_pDrawPadCanvas);
502 507
503 m_pLineToolButton->setOn(false); 508 m_pLineToolButton->setOn(false);
504 m_pRectangleToolButton->setOn(false); 509 m_pRectangleToolButton->setOn(false);
505 m_pEllipseToolButton->setOn(false); 510 m_pEllipseToolButton->setOn(false);
506 m_pTextToolAction->setOn(false); 511 m_pTextToolAction->setOn(false);
507 m_pFillToolAction->setOn(false); 512 m_pFillToolAction->setOn(false);
508 m_pEraseToolAction->setOn(true); 513 m_pEraseToolAction->setOn(true);
509} 514}
510 515
511void DrawPad::changePenWidth(int value) 516void DrawPad::changePenWidth(int value)
512{ 517{
513 m_pen.setWidth(value); 518 m_pen.setWidth(value);
514} 519}
515 520
516void DrawPad::changePenColor(const QColor& color) 521void DrawPad::changePenColor(const QColor& color)
517{ 522{
518 m_pen.setColor(color); 523 m_pen.setColor(color);
519 524
520 QPainter painter; 525 QPainter painter;
521 painter.begin(m_pPenColorToolButton->pixmap()); 526 painter.begin(m_pPenColorToolButton->pixmap());
522 painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); 527 painter.fillRect(QRect(0, 12, 14, 2), m_pen.color());
523 painter.end(); 528 painter.end();
524 529
525 m_pPenColorToolButton->popup()->hide(); 530 m_pPenColorToolButton->popup()->hide();
526} 531}
527 532
528void DrawPad::changeBrushColor(const QColor& color) 533void DrawPad::changeBrushColor(const QColor& color)
529{ 534{
530 m_brush = QBrush(color); 535 m_brush = QBrush(color);
531 536
532 QPainter painter; 537 QPainter painter;
533 painter.begin(m_pBrushColorToolButton->pixmap()); 538 painter.begin(m_pBrushColorToolButton->pixmap());
534 painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); 539 painter.fillRect(QRect(0, 12, 14, 2), m_brush.color());
535 painter.end(); 540 painter.end();
536 541
537 m_pBrushColorToolButton->popup()->hide(); 542 m_pBrushColorToolButton->popup()->hide();
538} 543}
539 544
540void DrawPad::updateUndoRedoToolButtons() 545void DrawPad::updateUndoRedoToolButtons()
541{ 546{
542 m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); 547 m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled());
543 m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); 548 m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled());
544} 549}
545 550
546void DrawPad::updateNavigationToolButtons() 551void DrawPad::updateNavigationToolButtons()
547{ 552{
548 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); 553 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
549 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); 554 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
550 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 555 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
551 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 556 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
552} 557}
553 558
554void DrawPad::updateCaption() 559void DrawPad::updateCaption()
555{ 560{
556 uint pagePosition = m_pDrawPadCanvas->pagePosition(); 561 uint pagePosition = m_pDrawPadCanvas->pagePosition();
557 uint pageCount = m_pDrawPadCanvas->pageCount(); 562 uint pageCount = m_pDrawPadCanvas->pageCount();
558 563
559 setCaption(tr("DrawPad") + " - " + tr("Page") + " " 564 setCaption(tr("DrawPad") + " - " + tr("Page") + " "
560 + QString::number(pagePosition) + "/" + QString::number(pageCount)); 565 + QString::number(pagePosition) + "/" + QString::number(pageCount));
561} 566}
562 567
563void DrawPad::deleteAll() 568void DrawPad::deleteAll()
564{ 569{
565 QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), 570 QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"),
566 QMessageBox::Information, QMessageBox::Yes, 571 QMessageBox::Information, QMessageBox::Yes,
567 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 572 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
568 QMessageBox::NoButton, this); 573 QMessageBox::NoButton, this);
569 574
570 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 575 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
571 messageBox.setButtonText(QMessageBox::No, tr("No")); 576 messageBox.setButtonText(QMessageBox::No, tr("No"));
572 577
573 if (messageBox.exec() == QMessageBox::Yes) { 578 if (messageBox.exec() == QMessageBox::Yes) {
574 m_pDrawPadCanvas->deleteAll(); 579 m_pDrawPadCanvas->deleteAll();
575 } 580 }
576} 581}
577 582
578void DrawPad::importPage() 583void DrawPad::importPage()
579{ 584{
580 ImportDialog importDialog(this); 585 ImportDialog importDialog(this);
581 586
582 importDialog.showMaximized(); 587 importDialog.showMaximized();
583 588
584 if (importDialog.exec() == QDialog::Accepted) { 589 if (importDialog.exec() == QDialog::Accepted) {
585 const DocLnk* docLnk = importDialog.selected(); 590 const DocLnk* docLnk = importDialog.selected();
586 591
587 if (docLnk) { 592 if (docLnk) {
588 m_pDrawPadCanvas->importPage(docLnk->file()); 593 m_pDrawPadCanvas->importPage(docLnk->file());
589 delete docLnk; 594 delete docLnk;
590 } 595 }
591 } 596 }
592} 597}
593 598
594void DrawPad::exportPage() 599void DrawPad::exportPage()
595{ 600{
596 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); 601 ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this);
597 602
598 exportDialog.showMaximized(); 603 exportDialog.showMaximized();
599 604
600 if (exportDialog.exec() == QDialog::Accepted) { 605 if (exportDialog.exec() == QDialog::Accepted) {
601 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), 606 m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(),
602 exportDialog.selectedName(), exportDialog.selectedFormat()); 607 exportDialog.selectedName(), exportDialog.selectedFormat());
603 } 608 }
604} 609}
605 610
606void DrawPad::thumbnailView() 611void DrawPad::thumbnailView()
607{ 612{
608 ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); 613 ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this);
609 614
610 thumbnailView.showMaximized(); 615 thumbnailView.showMaximized();
611 thumbnailView.exec(); 616 thumbnailView.exec();
612} 617}
613 618
614void DrawPad::pageInformation() 619void DrawPad::pageInformation()
615{ 620{
616 PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); 621 PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage());
617 622
618 if (pageInformationDialog.exec() == QDialog::Accepted) { 623 if (pageInformationDialog.exec() == QDialog::Accepted) {
619 m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); 624 m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle());
620 } 625 }
621} 626}
627
628void DrawPad::loadConfig()
629{
630 Config config("drawpad");
631 config.setGroup("General");
632
633 m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false));
634 m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1));
635 changePenColor(QColor(config.readEntry("PenColor", Qt::black.name())));
636 changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name())));
637 m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1));
638}
639
640void DrawPad::saveConfig()
641{
642 Config config("drawpad");
643 config.setGroup("General");
644
645 config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition());
646 config.writeEntry("AntiAliasing", antiAliasing());
647 config.writeEntry("PenWidth", (int)m_pen.width());
648 config.writeEntry("PenColor", m_pen.color().name());
649 config.writeEntry("BrushColor", m_brush.color().name());
650}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 8e29c61..c57606c 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -1,106 +1,112 @@
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 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 QToolButton; 27class QToolButton;
27class QWidgetStack; 28class QWidgetStack;
28 29
29class DrawPad : public QMainWindow 30class DrawPad : public QMainWindow
30{ 31{
31 Q_OBJECT 32 Q_OBJECT
32 33
33public: 34public:
34 DrawPad(QWidget* parent = 0, const char* name = 0); 35 DrawPad(QWidget* parent = 0, const char* name = 0);
35 ~DrawPad(); 36 ~DrawPad();
36 37
37 Tool* tool() { return m_pTool; } 38 Tool* tool() { return m_pTool; }
38 QPen pen() { return m_pen; } 39 QPen pen() { return m_pen; }
39 QBrush brush() { return m_brush; } 40 QBrush brush() { return m_brush; }
40 41
41 bool antiAliasing(); 42 bool antiAliasing();
42 43
43private slots: 44private slots:
44 void newPage(); 45 void newPage();
45 void clearPage(); 46 void clearPage();
46 void deletePage(); 47 void deletePage();
47 48
48 void setPointTool(); 49 void setPointTool();
49 void setLineTool(); 50 void setLineTool();
50 void setRectangleTool(); 51 void setRectangleTool();
51 void setFilledRectangleTool(); 52 void setFilledRectangleTool();
52 void setEllipseTool(); 53 void setEllipseTool();
53 void setFilledEllipseTool(); 54 void setFilledEllipseTool();
54 void setTextTool(); 55 void setTextTool();
55 void setFillTool(); 56 void setFillTool();
56 void setEraseTool(); 57 void setEraseTool();
57 58
58 void changePenWidth(int value); 59 void changePenWidth(int value);
59 void changePenColor(const QColor& color); 60 void changePenColor(const QColor& color);
60 void changeBrushColor(const QColor& color); 61 void changeBrushColor(const QColor& color);
61 62
62 void updateUndoRedoToolButtons(); 63 void updateUndoRedoToolButtons();
63 void updateNavigationToolButtons(); 64 void updateNavigationToolButtons();
64 void updateCaption(); 65 void updateCaption();
65 66
66 void deleteAll(); 67 void deleteAll();
67 void importPage(); 68 void importPage();
68 void exportPage(); 69 void exportPage();
69 void thumbnailView(); 70 void thumbnailView();
70 void pageInformation(); 71 void pageInformation();
71 72
72private: 73private:
74 void loadConfig();
75 void saveConfig();
76
73 DrawPadCanvas* m_pDrawPadCanvas; 77 DrawPadCanvas* m_pDrawPadCanvas;
74 78
75 Tool* m_pTool; 79 Tool* m_pTool;
76 QPen m_pen; 80 QPen m_pen;
77 QBrush m_brush; 81 QBrush m_brush;
78 82
79 QAction* m_pAntiAliasingAction; 83 QAction* m_pAntiAliasingAction;
80 84
81 QAction* m_pUndoAction; 85 QAction* m_pUndoAction;
82 QAction* m_pRedoAction; 86 QAction* m_pRedoAction;
83 87
84 QAction* m_pFirstPageAction; 88 QAction* m_pFirstPageAction;
85 QAction* m_pPreviousPageAction; 89 QAction* m_pPreviousPageAction;
86 QAction* m_pNextPageAction; 90 QAction* m_pNextPageAction;
87 QAction* m_pLastPageAction; 91 QAction* m_pLastPageAction;
88 92
89 QAction* m_pPointToolAction; 93 QAction* m_pPointToolAction;
90 QAction* m_pLineToolAction; 94 QAction* m_pLineToolAction;
91 QAction* m_pRectangleToolAction; 95 QAction* m_pRectangleToolAction;
92 QAction* m_pFilledRectangleToolAction; 96 QAction* m_pFilledRectangleToolAction;
93 QAction* m_pEllipseToolAction; 97 QAction* m_pEllipseToolAction;
94 QAction* m_pFilledEllipseToolAction; 98 QAction* m_pFilledEllipseToolAction;
95 QAction* m_pTextToolAction; 99 QAction* m_pTextToolAction;
96 QAction* m_pFillToolAction; 100 QAction* m_pFillToolAction;
97 QAction* m_pEraseToolAction; 101 QAction* m_pEraseToolAction;
98 102
99 QToolButton* m_pLineToolButton; 103 QToolButton* m_pLineToolButton;
100 QToolButton* m_pRectangleToolButton; 104 QToolButton* m_pRectangleToolButton;
101 QToolButton* m_pEllipseToolButton; 105 QToolButton* m_pEllipseToolButton;
102 QToolButton* m_pPenColorToolButton; 106 QToolButton* m_pPenColorToolButton;
103 QToolButton* m_pBrushColorToolButton; 107 QToolButton* m_pBrushColorToolButton;
108
109 QSpinBox* m_pPenWidthSpinBox;
104}; 110};
105 111
106#endif // DRAWPAD_H 112#endif // DRAWPAD_H
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 5437068..05dd408 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -157,384 +157,397 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch)
157} 157}
158 158
159DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) 159DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
160 : QScrollView(parent, name) 160 : QScrollView(parent, name)
161{ 161{
162 m_pDrawPad = drawPad; 162 m_pDrawPad = drawPad;
163 m_pages.setAutoDelete(true); 163 m_pages.setAutoDelete(true);
164 m_pageBackups.setAutoDelete(true); 164 m_pageBackups.setAutoDelete(true);
165 165
166 viewport()->setBackgroundMode(QWidget::NoBackground); 166 viewport()->setBackgroundMode(QWidget::NoBackground);
167} 167}
168 168
169DrawPadCanvas::~DrawPadCanvas() 169DrawPadCanvas::~DrawPadCanvas()
170{ 170{
171} 171}
172 172
173void DrawPadCanvas::load(QIODevice* ioDevice) 173void DrawPadCanvas::load(QIODevice* ioDevice)
174{ 174{
175 QTextStream textStream(ioDevice); 175 QTextStream textStream(ioDevice);
176 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 176 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
177 177
178 QXmlInputSource xmlInputSource(textStream); 178 QXmlInputSource xmlInputSource(textStream);
179 QXmlSimpleReader xmlSimpleReader; 179 QXmlSimpleReader xmlSimpleReader;
180 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; 180 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
181 181
182 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); 182 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
183 xmlSimpleReader.parse(xmlInputSource); 183 xmlSimpleReader.parse(xmlInputSource);
184 184
185 m_pages = drawPadCanvasXmlHandler.pages(); 185 m_pages = drawPadCanvasXmlHandler.pages();
186 186
187 if (m_pages.isEmpty()) { 187 if (m_pages.isEmpty()) {
188 m_pages.append(new Page("", contentsRect().size())); 188 m_pages.append(new Page("", contentsRect().size()));
189 m_pages.current()->fill(Qt::white); 189 m_pages.current()->fill(Qt::white);
190 } 190 }
191 191
192 m_pageBackups.clear(); 192 m_pageBackups.clear();
193 m_pageBackups.append(new Page(*(m_pages.current()))); 193 m_pageBackups.append(new Page(*(m_pages.current())));
194 194
195 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 195 resizeContents(m_pages.current()->width(), m_pages.current()->height());
196 viewport()->update(); 196 viewport()->update();
197 197
198 emit pagesChanged(); 198 emit pagesChanged();
199 emit pageBackupsChanged(); 199 emit pageBackupsChanged();
200} 200}
201 201
202void DrawPadCanvas::initialPage() 202void DrawPadCanvas::initialPage()
203{ 203{
204 m_pages.append(new Page("", 236, 232)); 204 m_pages.append(new Page("", 236, 232));
205 m_pages.current()->fill(Qt::white); 205 m_pages.current()->fill(Qt::white);
206 206
207 m_pageBackups.clear(); 207 m_pageBackups.clear();
208 m_pageBackups.append(new Page(*(m_pages.current()))); 208 m_pageBackups.append(new Page(*(m_pages.current())));
209 209
210 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 210 resizeContents(m_pages.current()->width(), m_pages.current()->height());
211 viewport()->update(); 211 viewport()->update();
212 212
213 emit pagesChanged(); 213 emit pagesChanged();
214 emit pageBackupsChanged(); 214 emit pageBackupsChanged();
215} 215}
216 216
217void DrawPadCanvas::save(QIODevice* ioDevice) 217void DrawPadCanvas::save(QIODevice* ioDevice)
218{ 218{
219 QTextStream textStream(ioDevice); 219 QTextStream textStream(ioDevice);
220 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 220 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
221 221
222 textStream << "<drawpad>" << endl; 222 textStream << "<drawpad>" << endl;
223 textStream << " <images>" << endl; 223 textStream << " <images>" << endl;
224 224
225 QListIterator<Page> bufferIterator(m_pages); 225 QListIterator<Page> bufferIterator(m_pages);
226 226
227 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 227 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
228 textStream << " <image>" << endl; 228 textStream << " <image>" << endl;
229 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; 229 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl;
230 230
231 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); 231 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified());
232 textStream << " <date>" << intDate << "</date>" << endl; 232 textStream << " <date>" << intDate << "</date>" << endl;
233 233
234 QImage image = bufferIterator.current()->convertToImage(); 234 QImage image = bufferIterator.current()->convertToImage();
235 QByteArray byteArray; 235 QByteArray byteArray;
236 QBuffer buffer(byteArray); 236 QBuffer buffer(byteArray);
237 QImageIO imageIO(&buffer, "PNG"); 237 QImageIO imageIO(&buffer, "PNG");
238 238
239 buffer.open(IO_WriteOnly); 239 buffer.open(IO_WriteOnly);
240 imageIO.setImage(image); 240 imageIO.setImage(image);
241 imageIO.write(); 241 imageIO.write();
242 buffer.close(); 242 buffer.close();
243 243
244 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; 244 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">";
245 245
246 static const char hexchars[] = "0123456789abcdef"; 246 static const char hexchars[] = "0123456789abcdef";
247 247
248 for (int i = 0; i < (int)byteArray.size(); i++ ) { 248 for (int i = 0; i < (int)byteArray.size(); i++ ) {
249 uchar s = (uchar)byteArray[i]; 249 uchar s = (uchar)byteArray[i];
250 textStream << hexchars[s >> 4]; 250 textStream << hexchars[s >> 4];
251 textStream << hexchars[s & 0x0f]; 251 textStream << hexchars[s & 0x0f];
252 } 252 }
253 253
254 textStream << "</data>" << endl; 254 textStream << "</data>" << endl;
255 textStream << " </image>" << endl; 255 textStream << " </image>" << endl;
256 } 256 }
257 257
258 textStream << " </images>" << endl; 258 textStream << " </images>" << endl;
259 textStream << "</drawpad>"; 259 textStream << "</drawpad>";
260} 260}
261 261
262void DrawPadCanvas::importPage(const QString& fileName) 262void DrawPadCanvas::importPage(const QString& fileName)
263{ 263{
264 Page* importedPage = new Page(); 264 Page* importedPage = new Page();
265 265
266 importedPage->load(fileName); 266 importedPage->load(fileName);
267 m_pages.insert(m_pages.at() + 1, importedPage); 267 m_pages.insert(m_pages.at() + 1, importedPage);
268 268
269 m_pageBackups.clear(); 269 m_pageBackups.clear();
270 m_pageBackups.append(new Page(*(m_pages.current()))); 270 m_pageBackups.append(new Page(*(m_pages.current())));
271 271
272 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 272 resizeContents(m_pages.current()->width(), m_pages.current()->height());
273 viewport()->update(); 273 viewport()->update();
274 274
275 emit pagesChanged(); 275 emit pagesChanged();
276 emit pageBackupsChanged(); 276 emit pageBackupsChanged();
277} 277}
278 278
279void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) 279void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format)
280{ 280{
281 if (fromPage == toPage) { 281 if (fromPage == toPage) {
282 DocLnk docLnk; 282 DocLnk docLnk;
283 MimeType mimeType(format); 283 MimeType mimeType(format);
284 284
285 docLnk.setName(name); 285 docLnk.setName(name);
286 docLnk.setType(mimeType.id()); 286 docLnk.setType(mimeType.id());
287 287
288 FileManager fileManager; 288 FileManager fileManager;
289 QIODevice* ioDevice = fileManager.saveFile(docLnk); 289 QIODevice* ioDevice = fileManager.saveFile(docLnk);
290 QImageIO imageIO(ioDevice, format); 290 QImageIO imageIO(ioDevice, format);
291 291
292 QImage image = m_pages.current()->convertToImage(); 292 QImage image = m_pages.current()->convertToImage();
293 imageIO.setImage(image); 293 imageIO.setImage(image);
294 imageIO.write(); 294 imageIO.write();
295 delete ioDevice; 295 delete ioDevice;
296 } else { 296 } else {
297 for (uint i = fromPage; i <= toPage; i++) { 297 for (uint i = fromPage; i <= toPage; i++) {
298 DocLnk docLnk; 298 DocLnk docLnk;
299 MimeType mimeType(format); 299 MimeType mimeType(format);
300 300
301 docLnk.setName(name + QString::number(i)); 301 docLnk.setName(name + QString::number(i));
302 docLnk.setType(mimeType.id()); 302 docLnk.setType(mimeType.id());
303 303
304 FileManager fileManager; 304 FileManager fileManager;
305 QIODevice* ioDevice = fileManager.saveFile(docLnk); 305 QIODevice* ioDevice = fileManager.saveFile(docLnk);
306 QImageIO imageIO(ioDevice, format); 306 QImageIO imageIO(ioDevice, format);
307 307
308 QImage image = m_pages.at(i - 1)->convertToImage(); 308 QImage image = m_pages.at(i - 1)->convertToImage();
309 imageIO.setImage(image); 309 imageIO.setImage(image);
310 imageIO.write(); 310 imageIO.write();
311 delete ioDevice; 311 delete ioDevice;
312 } 312 }
313 } 313 }
314} 314}
315 315
316Page* DrawPadCanvas::currentPage() 316Page* DrawPadCanvas::currentPage()
317{ 317{
318 return m_pages.current(); 318 return m_pages.current();
319} 319}
320 320
321QList<Page> DrawPadCanvas::pages() 321QList<Page> DrawPadCanvas::pages()
322{ 322{
323 return m_pages; 323 return m_pages;
324} 324}
325 325
326uint DrawPadCanvas::pagePosition() 326uint DrawPadCanvas::pagePosition()
327{ 327{
328 return (m_pages.at() + 1); 328 return (m_pages.at() + 1);
329} 329}
330 330
331uint DrawPadCanvas::pageCount() 331uint DrawPadCanvas::pageCount()
332{ 332{
333 return m_pages.count(); 333 return m_pages.count();
334} 334}
335 335
336void DrawPadCanvas::selectPage(Page* page) 336void DrawPadCanvas::selectPage(Page* page)
337{ 337{
338 m_pages.findRef(page); 338 m_pages.findRef(page);
339 m_pageBackups.clear(); 339 m_pageBackups.clear();
340 m_pageBackups.append(new Page(*(m_pages.current()))); 340 m_pageBackups.append(new Page(*(m_pages.current())));
341 341
342 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 342 resizeContents(m_pages.current()->width(), m_pages.current()->height());
343 viewport()->update(); 343 viewport()->update();
344 344
345 emit pagesChanged(); 345 emit pagesChanged();
346 emit pageBackupsChanged(); 346 emit pageBackupsChanged();
347} 347}
348 348
349void DrawPadCanvas::selectPage(uint pagePosition)
350{
351 m_pages.at(pagePosition - 1);
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
358 emit pagesChanged();
359 emit pageBackupsChanged();
360}
361
349void DrawPadCanvas::backupPage() 362void DrawPadCanvas::backupPage()
350{ 363{
351 m_pages.current()->setLastModified(QDateTime::currentDateTime()); 364 m_pages.current()->setLastModified(QDateTime::currentDateTime());
352 365
353 Page* currentBackup = m_pageBackups.current(); 366 Page* currentBackup = m_pageBackups.current();
354 while (m_pageBackups.last() != currentBackup) { 367 while (m_pageBackups.last() != currentBackup) {
355 m_pageBackups.removeLast(); 368 m_pageBackups.removeLast();
356 } 369 }
357 370
358 while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) { 371 while (m_pageBackups.count() >= (PAGE_BACKUPS + 1)) {
359 m_pageBackups.removeFirst(); 372 m_pageBackups.removeFirst();
360 } 373 }
361 374
362 m_pageBackups.append(new Page(*(m_pages.current()))); 375 m_pageBackups.append(new Page(*(m_pages.current())));
363 376
364 emit pageBackupsChanged(); 377 emit pageBackupsChanged();
365} 378}
366 379
367void DrawPadCanvas::deleteAll() 380void DrawPadCanvas::deleteAll()
368{ 381{
369 m_pages.clear(); 382 m_pages.clear();
370 383
371 m_pages.append(new Page("", contentsRect().size())); 384 m_pages.append(new Page("", contentsRect().size()));
372 m_pages.current()->fill(Qt::white); 385 m_pages.current()->fill(Qt::white);
373 386
374 m_pageBackups.clear(); 387 m_pageBackups.clear();
375 m_pageBackups.append(new Page(*(m_pages.current()))); 388 m_pageBackups.append(new Page(*(m_pages.current())));
376 389
377 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 390 resizeContents(m_pages.current()->width(), m_pages.current()->height());
378 viewport()->update(); 391 viewport()->update();
379 392
380 emit pagesChanged(); 393 emit pagesChanged();
381 emit pageBackupsChanged(); 394 emit pageBackupsChanged();
382} 395}
383 396
384void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) 397void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color)
385{ 398{
386 m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); 399 m_pages.insert(m_pages.at() + 1, new Page(title, width, height));
387 m_pages.current()->fill(color); 400 m_pages.current()->fill(color);
388 401
389 m_pageBackups.clear(); 402 m_pageBackups.clear();
390 m_pageBackups.append(new Page(*(m_pages.current()))); 403 m_pageBackups.append(new Page(*(m_pages.current())));
391 404
392 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 405 resizeContents(m_pages.current()->width(), m_pages.current()->height());
393 viewport()->update(); 406 viewport()->update();
394 407
395 emit pagesChanged(); 408 emit pagesChanged();
396 emit pageBackupsChanged(); 409 emit pageBackupsChanged();
397} 410}
398 411
399void DrawPadCanvas::clearPage() 412void DrawPadCanvas::clearPage()
400{ 413{
401 m_pages.current()->fill(Qt::white); 414 m_pages.current()->fill(Qt::white);
402 415
403 m_pageBackups.clear(); 416 m_pageBackups.clear();
404 m_pageBackups.append(new Page(*(m_pages.current()))); 417 m_pageBackups.append(new Page(*(m_pages.current())));
405 418
406 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 419 resizeContents(m_pages.current()->width(), m_pages.current()->height());
407 viewport()->update(); 420 viewport()->update();
408 421
409 emit pageBackupsChanged(); 422 emit pageBackupsChanged();
410} 423}
411 424
412void DrawPadCanvas::deletePage() 425void DrawPadCanvas::deletePage()
413{ 426{
414 m_pages.remove(m_pages.current()); 427 m_pages.remove(m_pages.current());
415 428
416 if (m_pages.isEmpty()) { 429 if (m_pages.isEmpty()) {
417 m_pages.append(new Page("", contentsRect().size())); 430 m_pages.append(new Page("", contentsRect().size()));
418 m_pages.current()->fill(Qt::white); 431 m_pages.current()->fill(Qt::white);
419 } 432 }
420 433
421 m_pageBackups.clear(); 434 m_pageBackups.clear();
422 m_pageBackups.append(new Page(*(m_pages.current()))); 435 m_pageBackups.append(new Page(*(m_pages.current())));
423 436
424 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 437 resizeContents(m_pages.current()->width(), m_pages.current()->height());
425 viewport()->update(); 438 viewport()->update();
426 439
427 emit pagesChanged(); 440 emit pagesChanged();
428 emit pageBackupsChanged(); 441 emit pageBackupsChanged();
429} 442}
430 443
431void DrawPadCanvas::movePageUp() 444void DrawPadCanvas::movePageUp()
432{ 445{
433 int index = m_pages.at(); 446 int index = m_pages.at();
434 Page* page = m_pages.take(); 447 Page* page = m_pages.take();
435 m_pages.insert(index - 1, page); 448 m_pages.insert(index - 1, page);
436 449
437 emit pagesChanged(); 450 emit pagesChanged();
438} 451}
439 452
440void DrawPadCanvas::movePageDown() 453void DrawPadCanvas::movePageDown()
441{ 454{
442 int index = m_pages.at(); 455 int index = m_pages.at();
443 Page* page = m_pages.take(); 456 Page* page = m_pages.take();
444 m_pages.insert(index + 1, page); 457 m_pages.insert(index + 1, page);
445 458
446 emit pagesChanged(); 459 emit pagesChanged();
447} 460}
448 461
449bool DrawPadCanvas::undoEnabled() 462bool DrawPadCanvas::undoEnabled()
450{ 463{
451 return (m_pageBackups.current() != m_pageBackups.getFirst()); 464 return (m_pageBackups.current() != m_pageBackups.getFirst());
452} 465}
453 466
454bool DrawPadCanvas::redoEnabled() 467bool DrawPadCanvas::redoEnabled()
455{ 468{
456 return (m_pageBackups.current() != m_pageBackups.getLast()); 469 return (m_pageBackups.current() != m_pageBackups.getLast());
457} 470}
458 471
459bool DrawPadCanvas::goPreviousPageEnabled() 472bool DrawPadCanvas::goPreviousPageEnabled()
460{ 473{
461 return (m_pages.current() != m_pages.getFirst()); 474 return (m_pages.current() != m_pages.getFirst());
462} 475}
463 476
464bool DrawPadCanvas::goNextPageEnabled() 477bool DrawPadCanvas::goNextPageEnabled()
465{ 478{
466 return (m_pages.current() != m_pages.getLast()); 479 return (m_pages.current() != m_pages.getLast());
467} 480}
468 481
469void DrawPadCanvas::undo() 482void DrawPadCanvas::undo()
470{ 483{
471 *(m_pages.current()) = *(m_pageBackups.prev()); 484 *(m_pages.current()) = *(m_pageBackups.prev());
472 485
473 viewport()->update(); 486 viewport()->update();
474 487
475 emit pageBackupsChanged(); 488 emit pageBackupsChanged();
476} 489}
477 490
478void DrawPadCanvas::redo() 491void DrawPadCanvas::redo()
479{ 492{
480 *(m_pages.current()) = *(m_pageBackups.next()); 493 *(m_pages.current()) = *(m_pageBackups.next());
481 494
482 viewport()->update(); 495 viewport()->update();
483 496
484 emit pageBackupsChanged(); 497 emit pageBackupsChanged();
485} 498}
486 499
487void DrawPadCanvas::goFirstPage() 500void DrawPadCanvas::goFirstPage()
488{ 501{
489 m_pages.first(); 502 m_pages.first();
490 m_pageBackups.clear(); 503 m_pageBackups.clear();
491 m_pageBackups.append(new Page(*(m_pages.current()))); 504 m_pageBackups.append(new Page(*(m_pages.current())));
492 505
493 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 506 resizeContents(m_pages.current()->width(), m_pages.current()->height());
494 viewport()->update(); 507 viewport()->update();
495 508
496 emit pagesChanged(); 509 emit pagesChanged();
497 emit pageBackupsChanged(); 510 emit pageBackupsChanged();
498} 511}
499 512
500void DrawPadCanvas::goPreviousPage() 513void DrawPadCanvas::goPreviousPage()
501{ 514{
502 m_pages.prev(); 515 m_pages.prev();
503 m_pageBackups.clear(); 516 m_pageBackups.clear();
504 m_pageBackups.append(new Page(*(m_pages.current()))); 517 m_pageBackups.append(new Page(*(m_pages.current())));
505 518
506 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 519 resizeContents(m_pages.current()->width(), m_pages.current()->height());
507 viewport()->update(); 520 viewport()->update();
508 521
509 emit pagesChanged(); 522 emit pagesChanged();
510 emit pageBackupsChanged(); 523 emit pageBackupsChanged();
511} 524}
512 525
513void DrawPadCanvas::goNextPage() 526void DrawPadCanvas::goNextPage()
514{ 527{
515 m_pages.next(); 528 m_pages.next();
516 m_pageBackups.clear(); 529 m_pageBackups.clear();
517 m_pageBackups.append(new Page(*(m_pages.current()))); 530 m_pageBackups.append(new Page(*(m_pages.current())));
518 531
519 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 532 resizeContents(m_pages.current()->width(), m_pages.current()->height());
520 viewport()->update(); 533 viewport()->update();
521 534
522 emit pagesChanged(); 535 emit pagesChanged();
523 emit pageBackupsChanged(); 536 emit pageBackupsChanged();
524} 537}
525 538
526void DrawPadCanvas::goLastPage() 539void DrawPadCanvas::goLastPage()
527{ 540{
528 m_pages.last(); 541 m_pages.last();
529 m_pageBackups.clear(); 542 m_pageBackups.clear();
530 m_pageBackups.append(new Page(*(m_pages.current()))); 543 m_pageBackups.append(new Page(*(m_pages.current())));
531 544
532 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 545 resizeContents(m_pages.current()->width(), m_pages.current()->height());
533 viewport()->update(); 546 viewport()->update();
534 547
535 emit pagesChanged(); 548 emit pagesChanged();
536 emit pageBackupsChanged(); 549 emit pageBackupsChanged();
537} 550}
538 551
539void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) 552void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
540{ 553{
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index dcaff5c..2283e5e 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -1,85 +1,86 @@
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(); 40 bool undoEnabled();
41 bool redoEnabled(); 41 bool redoEnabled();
42 bool goPreviousPageEnabled(); 42 bool goPreviousPageEnabled();
43 bool goNextPageEnabled(); 43 bool goNextPageEnabled();
44 44
45 Page* currentPage(); 45 Page* currentPage();
46 QList<Page> pages(); 46 QList<Page> pages();
47 uint pagePosition(); 47 uint pagePosition();
48 uint pageCount(); 48 uint pageCount();
49 49
50 void selectPage(Page* page); 50 void selectPage(Page* page);
51 void selectPage(uint pagePosition);
51 void backupPage(); 52 void backupPage();
52 53
53public slots: 54public slots:
54 void deleteAll(); 55 void deleteAll();
55 void newPage(QString title, uint width, uint height, const QColor& color); 56 void newPage(QString title, uint width, uint height, const QColor& color);
56 void clearPage(); 57 void clearPage();
57 void deletePage(); 58 void deletePage();
58 void movePageUp(); 59 void movePageUp();
59 void movePageDown(); 60 void movePageDown();
60 61
61 void undo(); 62 void undo();
62 void redo(); 63 void redo();
63 64
64 void goFirstPage(); 65 void goFirstPage();
65 void goPreviousPage(); 66 void goPreviousPage();
66 void goNextPage(); 67 void goNextPage();
67 void goLastPage(); 68 void goLastPage();
68 69
69signals: 70signals:
70 void pagesChanged(); 71 void pagesChanged();
71 void pageBackupsChanged(); 72 void pageBackupsChanged();
72 73
73protected: 74protected:
74 void contentsMousePressEvent(QMouseEvent* e); 75 void contentsMousePressEvent(QMouseEvent* e);
75 void contentsMouseReleaseEvent(QMouseEvent* e); 76 void contentsMouseReleaseEvent(QMouseEvent* e);
76 void contentsMouseMoveEvent(QMouseEvent* e); 77 void contentsMouseMoveEvent(QMouseEvent* e);
77 void drawContents(QPainter* p, int cx, int cy, int cw, int ch); 78 void drawContents(QPainter* p, int cx, int cy, int cw, int ch);
78 79
79private: 80private:
80 DrawPad* m_pDrawPad; 81 DrawPad* m_pDrawPad;
81 QList<Page> m_pages; 82 QList<Page> m_pages;
82 QList<Page> m_pageBackups; 83 QList<Page> m_pageBackups;
83}; 84};
84 85
85#endif // DRAWPADCANVAS_H 86#endif // DRAWPADCANVAS_H