summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-14 19:15:16 (UTC)
committer leseb <leseb>2002-06-14 19:15:16 (UTC)
commit251404b1ad7c5712270233821699ab8492fe76ac (patch) (unidiff)
treeb78e72bd4d420e95951eca8b5f5015cf405f2f9c
parent0aa515c2f050a85dbaf7b20b7a3c3fc12a213ed1 (diff)
downloadopie-251404b1ad7c5712270233821699ab8492fe76ac.zip
opie-251404b1ad7c5712270233821699ab8492fe76ac.tar.gz
opie-251404b1ad7c5712270233821699ab8492fe76ac.tar.bz2
Minor fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp4
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp4
2 files changed, 4 insertions, 4 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index dcf0871..4547b41 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,586 +1,586 @@
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
31#include <zlib.h> 31#include <zlib.h>
32 32
33class DrawPadCanvasXmlHandler: public QXmlDefaultHandler 33class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
34{ 34{
35public: 35public:
36 DrawPadCanvasXmlHandler(); 36 DrawPadCanvasXmlHandler();
37 ~DrawPadCanvasXmlHandler(); 37 ~DrawPadCanvasXmlHandler();
38 38
39 QList<Page> pages(); 39 QList<Page> pages();
40 40
41 bool startElement(const QString& namespaceURI, const QString& localName, 41 bool startElement(const QString& namespaceURI, const QString& localName,
42 const QString& qName, const QXmlAttributes& atts); 42 const QString& qName, const QXmlAttributes& atts);
43 bool endElement(const QString& namespaceURI, const QString& localName, 43 bool endElement(const QString& namespaceURI, const QString& localName,
44 const QString& qName); 44 const QString& qName);
45 bool characters(const QString& ch); 45 bool characters(const QString& ch);
46 46
47private: 47private:
48 enum State { 48 enum State {
49 Unknown, 49 Unknown,
50 InTitle, 50 InTitle,
51 InDate, 51 InDate,
52 InData 52 InData
53 }; 53 };
54 54
55 State m_state; 55 State m_state;
56 QString m_title; 56 QString m_title;
57 QDateTime m_date; 57 QDateTime m_date;
58 ulong m_dataLenght; 58 ulong m_dataLenght;
59 QString m_dataFormat; 59 QString m_dataFormat;
60 QList<Page> m_pages; 60 QList<Page> m_pages;
61}; 61};
62 62
63DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() 63DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler()
64{ 64{
65 m_state = Unknown; 65 m_state = Unknown;
66} 66}
67 67
68DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() 68DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler()
69{ 69{
70} 70}
71 71
72QList<Page> DrawPadCanvasXmlHandler::pages() 72QList<Page> DrawPadCanvasXmlHandler::pages()
73{ 73{
74 return m_pages; 74 return m_pages;
75} 75}
76 76
77bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, 77bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName,
78 const QString& qName, const QXmlAttributes& atts) 78 const QString& qName, const QXmlAttributes& atts)
79{ 79{
80 Q_CONST_UNUSED(namespaceURI) 80 Q_CONST_UNUSED(namespaceURI)
81 Q_CONST_UNUSED(localName) 81 Q_CONST_UNUSED(localName)
82 82
83 if (qName == "image") { 83 if (qName == "image") {
84 m_title = QString(); 84 m_title = QString();
85 m_date = QDateTime(QDate(1970, 1, 1)); 85 m_date = QDateTime::currentDateTime();
86 } else if (qName == "title") { 86 } else if (qName == "title") {
87 m_state = InTitle; 87 m_state = InTitle;
88 } else if (qName == "date") { 88 } else if (qName == "date") {
89 m_state = InDate; 89 m_state = InDate;
90 } else if (qName == "data") { 90 } else if (qName == "data") {
91 m_state = InData; 91 m_state = InData;
92 m_dataLenght = atts.value("length").toULong(); 92 m_dataLenght = atts.value("length").toULong();
93 m_dataFormat = atts.value("format"); 93 m_dataFormat = atts.value("format");
94 94
95 if (m_dataFormat.isEmpty()) { 95 if (m_dataFormat.isEmpty()) {
96 m_dataFormat = "XPM"; 96 m_dataFormat = "XPM";
97 } 97 }
98 } 98 }
99 99
100 return true; 100 return true;
101} 101}
102 102
103bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, 103bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName,
104 const QString& qName) 104 const QString& qName)
105{ 105{
106 Q_CONST_UNUSED(namespaceURI) 106 Q_CONST_UNUSED(namespaceURI)
107 Q_CONST_UNUSED(localName) 107 Q_CONST_UNUSED(localName)
108 108
109 if (qName == "title") { 109 if (qName == "title") {
110 m_state = Unknown; 110 m_state = Unknown;
111 } else if (qName == "date") { 111 } else if (qName == "date") {
112 m_state = Unknown; 112 m_state = Unknown;
113 } else if (qName == "data") { 113 } else if (qName == "data") {
114 m_state = Unknown; 114 m_state = Unknown;
115 } 115 }
116 116
117 return true; 117 return true;
118} 118}
119 119
120bool DrawPadCanvasXmlHandler::characters(const QString& ch) 120bool DrawPadCanvasXmlHandler::characters(const QString& ch)
121{ 121{
122 if (m_state == InTitle) { 122 if (m_state == InTitle) {
123 m_title = ch; 123 m_title = ch;
124 } else if (m_state == InDate) { 124 } else if (m_state == InDate) {
125 m_date = m_date.addSecs(ch.toInt()); 125 m_date = QDateTime(QDate(1970, 1, 1)).addSecs(ch.toInt());
126 } else if (m_state == InData) { 126 } else if (m_state == InData) {
127 QByteArray byteArray(ch.length() / 2); 127 QByteArray byteArray(ch.length() / 2);
128 128
129 for (int i = 0; i < (int)ch.length() / 2; i++) { 129 for (int i = 0; i < (int)ch.length() / 2; i++) {
130 char h = ch[2 * i].latin1(); 130 char h = ch[2 * i].latin1();
131 char l = ch[2 * i + 1].latin1(); 131 char l = ch[2 * i + 1].latin1();
132 uchar r = 0; 132 uchar r = 0;
133 133
134 if (h <= '9') { 134 if (h <= '9') {
135 r += h - '0'; 135 r += h - '0';
136 } else { 136 } else {
137 r += h - 'a' + 10; 137 r += h - 'a' + 10;
138 } 138 }
139 139
140 r = r << 4; 140 r = r << 4;
141 141
142 if (l <= '9') { 142 if (l <= '9') {
143 r += l - '0'; 143 r += l - '0';
144 } else { 144 } else {
145 r += l - 'a' + 10; 145 r += l - 'a' + 10;
146 } 146 }
147 147
148 byteArray[i] = r; 148 byteArray[i] = r;
149 } 149 }
150 150
151 151
152 QImage image; 152 QImage image;
153 153
154 if (m_dataFormat == "XPM") { 154 if (m_dataFormat == "XPM") {
155 if (m_dataLenght < ch.length() * 5) { 155 if (m_dataLenght < ch.length() * 5) {
156 m_dataLenght = ch.length() * 5; 156 m_dataLenght = ch.length() * 5;
157 } 157 }
158 158
159 QByteArray byteArrayUnzipped(m_dataLenght); 159 QByteArray byteArrayUnzipped(m_dataLenght);
160 ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); 160 ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size());
161 161
162 image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); 162 image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat);
163 } else { 163 } else {
164 image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); 164 image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat);
165 } 165 }
166 166
167 Page* page = new Page(m_title, image.width(), image.height()); 167 Page* page = new Page(m_title, image.width(), image.height());
168 page->setLastModified(m_date); 168 page->setLastModified(m_date);
169 page->convertFromImage(image); 169 page->convertFromImage(image);
170 m_pages.append(page); 170 m_pages.append(page);
171 } 171 }
172 172
173 return true; 173 return true;
174} 174}
175 175
176DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) 176DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
177 : QScrollView(parent, name) 177 : QScrollView(parent, name)
178{ 178{
179 m_pDrawPad = drawPad; 179 m_pDrawPad = drawPad;
180 m_pages.setAutoDelete(true); 180 m_pages.setAutoDelete(true);
181 m_pageBackups.setAutoDelete(true); 181 m_pageBackups.setAutoDelete(true);
182 182
183 viewport()->setBackgroundMode(QWidget::NoBackground); 183 viewport()->setBackgroundMode(QWidget::NoBackground);
184} 184}
185 185
186DrawPadCanvas::~DrawPadCanvas() 186DrawPadCanvas::~DrawPadCanvas()
187{ 187{
188} 188}
189 189
190void DrawPadCanvas::load(QIODevice* ioDevice) 190void DrawPadCanvas::load(QIODevice* ioDevice)
191{ 191{
192 QTextStream textStream(ioDevice); 192 QTextStream textStream(ioDevice);
193 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 193 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
194 194
195 QXmlInputSource xmlInputSource(textStream); 195 QXmlInputSource xmlInputSource(textStream);
196 QXmlSimpleReader xmlSimpleReader; 196 QXmlSimpleReader xmlSimpleReader;
197 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; 197 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
198 198
199 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); 199 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
200 xmlSimpleReader.parse(xmlInputSource); 200 xmlSimpleReader.parse(xmlInputSource);
201 201
202 m_pages = drawPadCanvasXmlHandler.pages(); 202 m_pages = drawPadCanvasXmlHandler.pages();
203 203
204 if (m_pages.isEmpty()) { 204 if (m_pages.isEmpty()) {
205 m_pages.append(new Page("", contentsRect().size())); 205 m_pages.append(new Page("", contentsRect().size()));
206 m_pages.current()->fill(Qt::white); 206 m_pages.current()->fill(Qt::white);
207 } 207 }
208 208
209 m_pageBackups.clear(); 209 m_pageBackups.clear();
210 m_pageBackups.append(new Page(*(m_pages.current()))); 210 m_pageBackups.append(new Page(*(m_pages.current())));
211 211
212 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 212 resizeContents(m_pages.current()->width(), m_pages.current()->height());
213 viewport()->update(); 213 viewport()->update();
214 214
215 emit pagesChanged(); 215 emit pagesChanged();
216 emit pageBackupsChanged(); 216 emit pageBackupsChanged();
217} 217}
218 218
219void DrawPadCanvas::initialPage() 219void DrawPadCanvas::initialPage()
220{ 220{
221 m_pages.append(new Page("", 236, 232)); 221 m_pages.append(new Page("", 236, 232));
222 m_pages.current()->fill(Qt::white); 222 m_pages.current()->fill(Qt::white);
223 223
224 m_pageBackups.clear(); 224 m_pageBackups.clear();
225 m_pageBackups.append(new Page(*(m_pages.current()))); 225 m_pageBackups.append(new Page(*(m_pages.current())));
226 226
227 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 227 resizeContents(m_pages.current()->width(), m_pages.current()->height());
228 viewport()->update(); 228 viewport()->update();
229 229
230 emit pagesChanged(); 230 emit pagesChanged();
231 emit pageBackupsChanged(); 231 emit pageBackupsChanged();
232} 232}
233 233
234void DrawPadCanvas::save(QIODevice* ioDevice) 234void DrawPadCanvas::save(QIODevice* ioDevice)
235{ 235{
236 QTextStream textStream(ioDevice); 236 QTextStream textStream(ioDevice);
237 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 237 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
238 238
239 textStream << "<drawpad>" << endl; 239 textStream << "<drawpad>" << endl;
240 textStream << " <images>" << endl; 240 textStream << " <images>" << endl;
241 241
242 QListIterator<Page> bufferIterator(m_pages); 242 QListIterator<Page> bufferIterator(m_pages);
243 243
244 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 244 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
245 textStream << " <image>" << endl; 245 textStream << " <image>" << endl;
246 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; 246 textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl;
247 247
248 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); 248 int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified());
249 textStream << " <date>" << intDate << "</date>" << endl; 249 textStream << " <date>" << intDate << "</date>" << endl;
250 250
251 QImage image = bufferIterator.current()->convertToImage(); 251 QImage image = bufferIterator.current()->convertToImage();
252 QByteArray byteArray; 252 QByteArray byteArray;
253 QBuffer buffer(byteArray); 253 QBuffer buffer(byteArray);
254 QImageIO imageIO(&buffer, "PNG"); 254 QImageIO imageIO(&buffer, "PNG");
255 255
256 buffer.open(IO_WriteOnly); 256 buffer.open(IO_WriteOnly);
257 imageIO.setImage(image); 257 imageIO.setImage(image);
258 imageIO.write(); 258 imageIO.write();
259 buffer.close(); 259 buffer.close();
260 260
261 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; 261 textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">";
262 262
263 static const char hexchars[] = "0123456789abcdef"; 263 static const char hexchars[] = "0123456789abcdef";
264 264
265 for (int i = 0; i < (int)byteArray.size(); i++ ) { 265 for (int i = 0; i < (int)byteArray.size(); i++ ) {
266 uchar s = (uchar)byteArray[i]; 266 uchar s = (uchar)byteArray[i];
267 textStream << hexchars[s >> 4]; 267 textStream << hexchars[s >> 4];
268 textStream << hexchars[s & 0x0f]; 268 textStream << hexchars[s & 0x0f];
269 } 269 }
270 270
271 textStream << "</data>" << endl; 271 textStream << "</data>" << endl;
272 textStream << " </image>" << endl; 272 textStream << " </image>" << endl;
273 } 273 }
274 274
275 textStream << " </images>" << endl; 275 textStream << " </images>" << endl;
276 textStream << "</drawpad>"; 276 textStream << "</drawpad>";
277} 277}
278 278
279void DrawPadCanvas::importPage(const QString& fileName) 279void DrawPadCanvas::importPage(const QString& fileName)
280{ 280{
281 Page* importedPage = new Page(); 281 Page* importedPage = new Page();
282 282
283 importedPage->load(fileName); 283 importedPage->load(fileName);
284 m_pages.insert(m_pages.at() + 1, importedPage); 284 m_pages.insert(m_pages.at() + 1, importedPage);
285 285
286 m_pageBackups.clear(); 286 m_pageBackups.clear();
287 m_pageBackups.append(new Page(*(m_pages.current()))); 287 m_pageBackups.append(new Page(*(m_pages.current())));
288 288
289 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 289 resizeContents(m_pages.current()->width(), m_pages.current()->height());
290 viewport()->update(); 290 viewport()->update();
291 291
292 emit pagesChanged(); 292 emit pagesChanged();
293 emit pageBackupsChanged(); 293 emit pageBackupsChanged();
294} 294}
295 295
296void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) 296void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format)
297{ 297{
298 if (fromPage == toPage) { 298 if (fromPage == toPage) {
299 DocLnk docLnk; 299 DocLnk docLnk;
300 MimeType mimeType(format); 300 MimeType mimeType(format);
301 301
302 docLnk.setName(name); 302 docLnk.setName(name);
303 docLnk.setType(mimeType.id()); 303 docLnk.setType(mimeType.id());
304 304
305 FileManager fileManager; 305 FileManager fileManager;
306 QIODevice* ioDevice = fileManager.saveFile(docLnk); 306 QIODevice* ioDevice = fileManager.saveFile(docLnk);
307 QImageIO imageIO(ioDevice, format); 307 QImageIO imageIO(ioDevice, format);
308 308
309 QImage image = m_pages.current()->convertToImage(); 309 QImage image = m_pages.current()->convertToImage();
310 imageIO.setImage(image); 310 imageIO.setImage(image);
311 imageIO.write(); 311 imageIO.write();
312 delete ioDevice; 312 delete ioDevice;
313 } else { 313 } else {
314 for (uint i = fromPage; i <= toPage; i++) { 314 for (uint i = fromPage; i <= toPage; i++) {
315 DocLnk docLnk; 315 DocLnk docLnk;
316 MimeType mimeType(format); 316 MimeType mimeType(format);
317 317
318 docLnk.setName(name + QString::number(i)); 318 docLnk.setName(name + QString::number(i));
319 docLnk.setType(mimeType.id()); 319 docLnk.setType(mimeType.id());
320 320
321 FileManager fileManager; 321 FileManager fileManager;
322 QIODevice* ioDevice = fileManager.saveFile(docLnk); 322 QIODevice* ioDevice = fileManager.saveFile(docLnk);
323 QImageIO imageIO(ioDevice, format); 323 QImageIO imageIO(ioDevice, format);
324 324
325 QImage image = m_pages.at(i - 1)->convertToImage(); 325 QImage image = m_pages.at(i - 1)->convertToImage();
326 imageIO.setImage(image); 326 imageIO.setImage(image);
327 imageIO.write(); 327 imageIO.write();
328 delete ioDevice; 328 delete ioDevice;
329 } 329 }
330 } 330 }
331} 331}
332 332
333Page* DrawPadCanvas::currentPage() 333Page* DrawPadCanvas::currentPage()
334{ 334{
335 return m_pages.current(); 335 return m_pages.current();
336} 336}
337 337
338QList<Page> DrawPadCanvas::pages() 338QList<Page> DrawPadCanvas::pages()
339{ 339{
340 return m_pages; 340 return m_pages;
341} 341}
342 342
343uint DrawPadCanvas::pagePosition() 343uint DrawPadCanvas::pagePosition()
344{ 344{
345 return (m_pages.at() + 1); 345 return (m_pages.at() + 1);
346} 346}
347 347
348uint DrawPadCanvas::pageCount() 348uint DrawPadCanvas::pageCount()
349{ 349{
350 return m_pages.count(); 350 return m_pages.count();
351} 351}
352 352
353void DrawPadCanvas::selectPage(Page* page) 353void DrawPadCanvas::selectPage(Page* page)
354{ 354{
355 m_pages.findRef(page); 355 m_pages.findRef(page);
356 m_pageBackups.clear(); 356 m_pageBackups.clear();
357 m_pageBackups.append(new Page(*(m_pages.current()))); 357 m_pageBackups.append(new Page(*(m_pages.current())));
358 358
359 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 359 resizeContents(m_pages.current()->width(), m_pages.current()->height());
360 viewport()->update(); 360 viewport()->update();
361 361
362 emit pagesChanged(); 362 emit pagesChanged();
363 emit pageBackupsChanged(); 363 emit pageBackupsChanged();
364} 364}
365 365
366void DrawPadCanvas::backupPage() 366void DrawPadCanvas::backupPage()
367{ 367{
368 m_pages.current()->setLastModified(QDateTime::currentDateTime()); 368 m_pages.current()->setLastModified(QDateTime::currentDateTime());
369 369
370 Page* currentBackup = m_pageBackups.current(); 370 Page* currentBackup = m_pageBackups.current();
371 while (m_pageBackups.last() != currentBackup) { 371 while (m_pageBackups.last() != currentBackup) {
372 m_pageBackups.removeLast(); 372 m_pageBackups.removeLast();
373 } 373 }
374 374
375 while (m_pageBackups.count() >= (5 + 1)) { 375 while (m_pageBackups.count() >= (5 + 1)) {
376 m_pageBackups.removeFirst(); 376 m_pageBackups.removeFirst();
377 } 377 }
378 378
379 m_pageBackups.append(new Page(*(m_pages.current()))); 379 m_pageBackups.append(new Page(*(m_pages.current())));
380 380
381 emit pageBackupsChanged(); 381 emit pageBackupsChanged();
382} 382}
383 383
384void DrawPadCanvas::deleteAll() 384void DrawPadCanvas::deleteAll()
385{ 385{
386 m_pages.clear(); 386 m_pages.clear();
387 387
388 m_pages.append(new Page("", contentsRect().size())); 388 m_pages.append(new Page("", contentsRect().size()));
389 m_pages.current()->fill(Qt::white); 389 m_pages.current()->fill(Qt::white);
390 390
391 m_pageBackups.clear(); 391 m_pageBackups.clear();
392 m_pageBackups.append(new Page(*(m_pages.current()))); 392 m_pageBackups.append(new Page(*(m_pages.current())));
393 393
394 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 394 resizeContents(m_pages.current()->width(), m_pages.current()->height());
395 viewport()->update(); 395 viewport()->update();
396 396
397 emit pagesChanged(); 397 emit pagesChanged();
398 emit pageBackupsChanged(); 398 emit pageBackupsChanged();
399} 399}
400 400
401void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) 401void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color)
402{ 402{
403 m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); 403 m_pages.insert(m_pages.at() + 1, new Page(title, width, height));
404 m_pages.current()->fill(color); 404 m_pages.current()->fill(color);
405 405
406 m_pageBackups.clear(); 406 m_pageBackups.clear();
407 m_pageBackups.append(new Page(*(m_pages.current()))); 407 m_pageBackups.append(new Page(*(m_pages.current())));
408 408
409 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 409 resizeContents(m_pages.current()->width(), m_pages.current()->height());
410 viewport()->update(); 410 viewport()->update();
411 411
412 emit pagesChanged(); 412 emit pagesChanged();
413 emit pageBackupsChanged(); 413 emit pageBackupsChanged();
414} 414}
415 415
416void DrawPadCanvas::clearPage() 416void DrawPadCanvas::clearPage()
417{ 417{
418 m_pages.current()->fill(Qt::white); 418 m_pages.current()->fill(Qt::white);
419 419
420 m_pageBackups.clear(); 420 m_pageBackups.clear();
421 m_pageBackups.append(new Page(*(m_pages.current()))); 421 m_pageBackups.append(new Page(*(m_pages.current())));
422 422
423 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 423 resizeContents(m_pages.current()->width(), m_pages.current()->height());
424 viewport()->update(); 424 viewport()->update();
425 425
426 emit pageBackupsChanged(); 426 emit pageBackupsChanged();
427} 427}
428 428
429void DrawPadCanvas::deletePage() 429void DrawPadCanvas::deletePage()
430{ 430{
431 m_pages.remove(m_pages.current()); 431 m_pages.remove(m_pages.current());
432 432
433 if (m_pages.isEmpty()) { 433 if (m_pages.isEmpty()) {
434 m_pages.append(new Page("", contentsRect().size())); 434 m_pages.append(new Page("", contentsRect().size()));
435 m_pages.current()->fill(Qt::white); 435 m_pages.current()->fill(Qt::white);
436 } 436 }
437 437
438 m_pageBackups.clear(); 438 m_pageBackups.clear();
439 m_pageBackups.append(new Page(*(m_pages.current()))); 439 m_pageBackups.append(new Page(*(m_pages.current())));
440 440
441 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 441 resizeContents(m_pages.current()->width(), m_pages.current()->height());
442 viewport()->update(); 442 viewport()->update();
443 443
444 emit pagesChanged(); 444 emit pagesChanged();
445 emit pageBackupsChanged(); 445 emit pageBackupsChanged();
446} 446}
447 447
448void DrawPadCanvas::movePageUp() 448void DrawPadCanvas::movePageUp()
449{ 449{
450 int index = m_pages.at(); 450 int index = m_pages.at();
451 Page* page = m_pages.take(); 451 Page* page = m_pages.take();
452 m_pages.insert(index - 1, page); 452 m_pages.insert(index - 1, page);
453 453
454 emit pagesChanged(); 454 emit pagesChanged();
455} 455}
456 456
457void DrawPadCanvas::movePageDown() 457void DrawPadCanvas::movePageDown()
458{ 458{
459 int index = m_pages.at(); 459 int index = m_pages.at();
460 Page* page = m_pages.take(); 460 Page* page = m_pages.take();
461 m_pages.insert(index + 1, page); 461 m_pages.insert(index + 1, page);
462 462
463 emit pagesChanged(); 463 emit pagesChanged();
464} 464}
465 465
466bool DrawPadCanvas::undoEnabled() 466bool DrawPadCanvas::undoEnabled()
467{ 467{
468 return (m_pageBackups.current() != m_pageBackups.getFirst()); 468 return (m_pageBackups.current() != m_pageBackups.getFirst());
469} 469}
470 470
471bool DrawPadCanvas::redoEnabled() 471bool DrawPadCanvas::redoEnabled()
472{ 472{
473 return (m_pageBackups.current() != m_pageBackups.getLast()); 473 return (m_pageBackups.current() != m_pageBackups.getLast());
474} 474}
475 475
476bool DrawPadCanvas::goPreviousPageEnabled() 476bool DrawPadCanvas::goPreviousPageEnabled()
477{ 477{
478 return (m_pages.current() != m_pages.getFirst()); 478 return (m_pages.current() != m_pages.getFirst());
479} 479}
480 480
481bool DrawPadCanvas::goNextPageEnabled() 481bool DrawPadCanvas::goNextPageEnabled()
482{ 482{
483 return (m_pages.current() != m_pages.getLast()); 483 return (m_pages.current() != m_pages.getLast());
484} 484}
485 485
486void DrawPadCanvas::undo() 486void DrawPadCanvas::undo()
487{ 487{
488 *(m_pages.current()) = *(m_pageBackups.prev()); 488 *(m_pages.current()) = *(m_pageBackups.prev());
489 489
490 viewport()->update(); 490 viewport()->update();
491 491
492 emit pageBackupsChanged(); 492 emit pageBackupsChanged();
493} 493}
494 494
495void DrawPadCanvas::redo() 495void DrawPadCanvas::redo()
496{ 496{
497 *(m_pages.current()) = *(m_pageBackups.next()); 497 *(m_pages.current()) = *(m_pageBackups.next());
498 498
499 viewport()->update(); 499 viewport()->update();
500 500
501 emit pageBackupsChanged(); 501 emit pageBackupsChanged();
502} 502}
503 503
504void DrawPadCanvas::goFirstPage() 504void DrawPadCanvas::goFirstPage()
505{ 505{
506 m_pages.first(); 506 m_pages.first();
507 m_pageBackups.clear(); 507 m_pageBackups.clear();
508 m_pageBackups.append(new Page(*(m_pages.current()))); 508 m_pageBackups.append(new Page(*(m_pages.current())));
509 509
510 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 510 resizeContents(m_pages.current()->width(), m_pages.current()->height());
511 viewport()->update(); 511 viewport()->update();
512 512
513 emit pagesChanged(); 513 emit pagesChanged();
514 emit pageBackupsChanged(); 514 emit pageBackupsChanged();
515} 515}
516 516
517void DrawPadCanvas::goPreviousPage() 517void DrawPadCanvas::goPreviousPage()
518{ 518{
519 m_pages.prev(); 519 m_pages.prev();
520 m_pageBackups.clear(); 520 m_pageBackups.clear();
521 m_pageBackups.append(new Page(*(m_pages.current()))); 521 m_pageBackups.append(new Page(*(m_pages.current())));
522 522
523 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 523 resizeContents(m_pages.current()->width(), m_pages.current()->height());
524 viewport()->update(); 524 viewport()->update();
525 525
526 emit pagesChanged(); 526 emit pagesChanged();
527 emit pageBackupsChanged(); 527 emit pageBackupsChanged();
528} 528}
529 529
530void DrawPadCanvas::goNextPage() 530void DrawPadCanvas::goNextPage()
531{ 531{
532 m_pages.next(); 532 m_pages.next();
533 m_pageBackups.clear(); 533 m_pageBackups.clear();
534 m_pageBackups.append(new Page(*(m_pages.current()))); 534 m_pageBackups.append(new Page(*(m_pages.current())));
535 535
536 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 536 resizeContents(m_pages.current()->width(), m_pages.current()->height());
537 viewport()->update(); 537 viewport()->update();
538 538
539 emit pagesChanged(); 539 emit pagesChanged();
540 emit pageBackupsChanged(); 540 emit pageBackupsChanged();
541} 541}
542 542
543void DrawPadCanvas::goLastPage() 543void DrawPadCanvas::goLastPage()
544{ 544{
545 m_pages.last(); 545 m_pages.last();
546 m_pageBackups.clear(); 546 m_pageBackups.clear();
547 m_pageBackups.append(new Page(*(m_pages.current()))); 547 m_pageBackups.append(new Page(*(m_pages.current())));
548 548
549 resizeContents(m_pages.current()->width(), m_pages.current()->height()); 549 resizeContents(m_pages.current()->width(), m_pages.current()->height());
550 viewport()->update(); 550 viewport()->update();
551 551
552 emit pagesChanged(); 552 emit pagesChanged();
553 emit pageBackupsChanged(); 553 emit pageBackupsChanged();
554} 554}
555 555
556void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) 556void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
557{ 557{
558 m_pDrawPad->tool()->mousePressEvent(e); 558 m_pDrawPad->tool()->mousePressEvent(e);
559} 559}
560 560
561void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) 561void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
562{ 562{
563 m_pDrawPad->tool()->mouseReleaseEvent(e); 563 m_pDrawPad->tool()->mouseReleaseEvent(e);
564} 564}
565 565
566void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) 566void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
567{ 567{
568 m_pDrawPad->tool()->mouseMoveEvent(e); 568 m_pDrawPad->tool()->mouseMoveEvent(e);
569} 569}
570 570
571void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 571void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
572{ 572{
573 QRect clipRect(cx, cy, cw, ch); 573 QRect clipRect(cx, cy, cw, ch);
574 QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); 574 QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height());
575 QRect drawRect = pixmapRect.intersect(clipRect); 575 QRect drawRect = pixmapRect.intersect(clipRect);
576 576
577 p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); 577 p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect);
578 578
579 if (drawRect.right() < clipRect.right()) { 579 if (drawRect.right() < clipRect.right()) {
580 p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); 580 p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark());
581 } 581 }
582 582
583 if (drawRect.bottom() < clipRect.bottom()) { 583 if (drawRect.bottom() < clipRect.bottom()) {
584 p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); 584 p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark());
585 } 585 }
586} 586}
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 81ec79f..14092bf 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,382 +1,382 @@
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->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->width())
61 + "x" + QString::number(m_pPage->height()); 61 + "x" + QString::number(m_pPage->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(106); 69 m_alternateColor = baseColor.dark(115);
70 } else if (baseColor != Qt::black) { 70 } else if (baseColor != Qt::black) {
71 m_alternateColor = baseColor.light(110); 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();
110 boldFont.setBold(TRUE); 110 boldFont.setBold(TRUE);
111 111
112 QFontMetrics fontMetrics = painter->fontMetrics(); 112 QFontMetrics fontMetrics = painter->fontMetrics();
113 QRect textRect(THUMBNAIL_SIZE + 6, 2, 113 QRect textRect(THUMBNAIL_SIZE + 6, 2,
114 itemRect.width() - THUMBNAIL_SIZE - 8, 114 itemRect.width() - THUMBNAIL_SIZE - 8,
115 itemRect.height() - 4); 115 itemRect.height() - 4);
116 116
117 painter->setFont(boldFont); 117 painter->setFont(boldFont);
118 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, m_titleText); 118 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, m_titleText);
119 119
120 painter->setFont(standardFont); 120 painter->setFont(standardFont);
121 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_dimensionText); 121 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_dimensionText);
122 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, m_dateText); 122 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, m_dateText);
123 123
124 if (!selected() && !(listBox()->hasFocus() && listBox()->item(listBox()->currentItem()) == this)) { 124 if (!selected() && !(listBox()->hasFocus() && listBox()->item(listBox()->currentItem()) == this)) {
125 painter->drawLine(0, itemRect.height() - 1, itemRect.width() - 1, itemRect.height() - 1); 125 painter->drawLine(0, itemRect.height() - 1, itemRect.width() - 1, itemRect.height() - 1);
126 } 126 }
127} 127}
128 128
129Page* PageListBoxItem::page() const 129Page* PageListBoxItem::page() const
130{ 130{
131 return m_pPage; 131 return m_pPage;
132} 132}
133 133
134QString PageListBoxItem::dateTimeString(QDateTime dateTime) 134QString PageListBoxItem::dateTimeString(QDateTime dateTime)
135{ 135{
136 QString result; 136 QString result;
137 137
138 Config config("qpe"); 138 Config config("qpe");
139 config.setGroup("Date"); 139 config.setGroup("Date");
140 140
141 QChar separator = config.readEntry("Separator", "/")[0]; 141 QChar separator = config.readEntry("Separator", "/")[0];
142 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear); 142 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear);
143 143
144 for (int i = 0; i < 3; i++) { 144 for (int i = 0; i < 3; i++) {
145 switch((shortOrder >> (i * 3)) & 0x0007) { 145 switch((shortOrder >> (i * 3)) & 0x0007) {
146 case 0x0001: 146 case 0x0001:
147 result += QString().sprintf("%02d", dateTime.date().day()); 147 result += QString().sprintf("%02d", dateTime.date().day());
148 break; 148 break;
149 case 0x0002: 149 case 0x0002:
150 result += QString().sprintf("%02d", dateTime.date().month()); 150 result += QString().sprintf("%02d", dateTime.date().month());
151 break; 151 break;
152 case 0x0004: 152 case 0x0004:
153 result += QString().sprintf("%04d", dateTime.date().year()); 153 result += QString().sprintf("%04d", dateTime.date().year());
154 break; 154 break;
155 default: 155 default:
156 break; 156 break;
157 } 157 }
158 158
159 if (i < 2) { 159 if (i < 2) {
160 result += separator; 160 result += separator;
161 } 161 }
162 } 162 }
163 163
164 result += QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute()); 164 result += QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute());
165 165
166 return result; 166 return result;
167} 167}
168 168
169PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) 169PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
170 : QListBox(parent, name) 170 : QListBox(parent, name)
171{ 171{
172 m_pDrawPadCanvas = drawPadCanvas; 172 m_pDrawPadCanvas = drawPadCanvas;
173 173
174 setVScrollBarMode(QScrollView::AlwaysOn); 174 setVScrollBarMode(QScrollView::AlwaysOn);
175 175
176 updateView(); 176 updateView();
177} 177}
178 178
179PageListBox::~PageListBox() 179PageListBox::~PageListBox()
180{ 180{
181} 181}
182 182
183void PageListBox::updateView() 183void PageListBox::updateView()
184{ 184{
185 clear(); 185 clear();
186 186
187 if (m_pDrawPadCanvas) { 187 if (m_pDrawPadCanvas) {
188 QList<Page> pageList = m_pDrawPadCanvas->pages(); 188 QList<Page> pageList = m_pDrawPadCanvas->pages();
189 QListIterator<Page> it(pageList); 189 QListIterator<Page> it(pageList);
190 190
191 for (; it.current(); ++it) { 191 for (; it.current(); ++it) {
192 new PageListBoxItem(it.current(), this); 192 new PageListBoxItem(it.current(), this);
193 } 193 }
194 194
195 select(m_pDrawPadCanvas->currentPage()); 195 select(m_pDrawPadCanvas->currentPage());
196 } 196 }
197} 197}
198 198
199void PageListBox::select(Page* page) 199void PageListBox::select(Page* page)
200{ 200{
201 uint i = 0; 201 uint i = 0;
202 uint itemCount = count(); 202 uint itemCount = count();
203 203
204 while (i < itemCount) { 204 while (i < itemCount) {
205 PageListBoxItem* currentItem = (PageListBoxItem*)item(i); 205 PageListBoxItem* currentItem = (PageListBoxItem*)item(i);
206 206
207 if (currentItem->page() == page) { 207 if (currentItem->page() == page) {
208 setCurrentItem(currentItem); 208 setCurrentItem(currentItem);
209 break; 209 break;
210 } 210 }
211 211
212 i++; 212 i++;
213 } 213 }
214} 214}
215 215
216Page* PageListBox::selected() const 216Page* PageListBox::selected() const
217{ 217{
218 Page* page; 218 Page* page;
219 219
220 PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem()); 220 PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem());
221 221
222 if (selectedItem) { 222 if (selectedItem) {
223 page = selectedItem->page(); 223 page = selectedItem->page();
224 } else { 224 } else {
225 page = NULL; 225 page = NULL;
226 } 226 }
227 227
228 return page; 228 return page;
229} 229}
230 230
231ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) 231ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
232 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) 232 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel)
233{ 233{
234 inLoop = false; 234 inLoop = false;
235 235
236 m_pDrawPad = drawPad; 236 m_pDrawPad = drawPad;
237 m_pDrawPadCanvas = drawPadCanvas; 237 m_pDrawPadCanvas = drawPadCanvas;
238 238
239 setCaption(tr("DrawPad - Thumbnail View")); 239 setCaption(tr("DrawPad - Thumbnail View"));
240 240
241 QToolButton* newPageButton = new QToolButton(this); 241 QToolButton* newPageButton = new QToolButton(this);
242 newPageButton->setIconSet(Resource::loadIconSet("new")); 242 newPageButton->setIconSet(Resource::loadIconSet("new"));
243 newPageButton->setAutoRaise(true); 243 newPageButton->setAutoRaise(true);
244 connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage())); 244 connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage()));
245 245
246 QToolButton* clearPageButton = new QToolButton(this); 246 QToolButton* clearPageButton = new QToolButton(this);
247 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); 247 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear"));
248 clearPageButton->setAutoRaise(true); 248 clearPageButton->setAutoRaise(true);
249 connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage())); 249 connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage()));
250 250
251 QToolButton* deletePageButton = new QToolButton(this); 251 QToolButton* deletePageButton = new QToolButton(this);
252 deletePageButton->setIconSet(Resource::loadIconSet("trash")); 252 deletePageButton->setIconSet(Resource::loadIconSet("trash"));
253 deletePageButton->setAutoRaise(true); 253 deletePageButton->setAutoRaise(true);
254 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); 254 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage()));
255 255
256 m_pMovePageUpButton = new QToolButton(this); 256 m_pMovePageUpButton = new QToolButton(this);
257 m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up")); 257 m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up"));
258 m_pMovePageUpButton->setAutoRaise(true); 258 m_pMovePageUpButton->setAutoRaise(true);
259 connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp())); 259 connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp()));
260 260
261 m_pMovePageDownButton = new QToolButton(this); 261 m_pMovePageDownButton = new QToolButton(this);
262 m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down")); 262 m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down"));
263 m_pMovePageDownButton->setAutoRaise(true); 263 m_pMovePageDownButton->setAutoRaise(true);
264 connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown())); 264 connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown()));
265 265
266 m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this); 266 m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this);
267 connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage())); 267 connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage()));
268 268
269 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); 269 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
270 QHBoxLayout* buttonLayout = new QHBoxLayout(0); 270 QHBoxLayout* buttonLayout = new QHBoxLayout(0);
271 271
272 buttonLayout->addWidget(newPageButton); 272 buttonLayout->addWidget(newPageButton);
273 buttonLayout->addWidget(clearPageButton); 273 buttonLayout->addWidget(clearPageButton);
274 buttonLayout->addWidget(deletePageButton); 274 buttonLayout->addWidget(deletePageButton);
275 buttonLayout->addStretch(); 275 buttonLayout->addStretch();
276 buttonLayout->addWidget(m_pMovePageUpButton); 276 buttonLayout->addWidget(m_pMovePageUpButton);
277 buttonLayout->addWidget(m_pMovePageDownButton); 277 buttonLayout->addWidget(m_pMovePageDownButton);
278 278
279 mainLayout->addLayout(buttonLayout); 279 mainLayout->addLayout(buttonLayout);
280 mainLayout->addWidget(m_pPageListBox); 280 mainLayout->addWidget(m_pPageListBox);
281 281
282 updateView(); 282 updateView();
283} 283}
284 284
285ThumbnailView::~ThumbnailView() 285ThumbnailView::~ThumbnailView()
286{ 286{
287 hide(); 287 hide();
288} 288}
289 289
290void ThumbnailView::updateView() 290void ThumbnailView::updateView()
291{ 291{
292 m_pMovePageUpButton->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); 292 m_pMovePageUpButton->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
293 m_pMovePageDownButton->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 293 m_pMovePageDownButton->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
294} 294}
295 295
296void ThumbnailView::hide() 296void ThumbnailView::hide()
297{ 297{
298 QWidget::hide(); 298 QWidget::hide();
299 299
300 if (inLoop) { 300 if (inLoop) {
301 inLoop = false; 301 inLoop = false;
302 qApp->exit_loop(); 302 qApp->exit_loop();
303 } 303 }
304} 304}
305 305
306void ThumbnailView::exec() 306void ThumbnailView::exec()
307{ 307{
308 show(); 308 show();
309 309
310 if (!inLoop) { 310 if (!inLoop) {
311 inLoop = true; 311 inLoop = true;
312 qApp->enter_loop(); 312 qApp->enter_loop();
313 } 313 }
314} 314}
315 315
316void ThumbnailView::newPage() 316void ThumbnailView::newPage()
317{ 317{
318 QRect rect = m_pDrawPadCanvas->contentsRect(); 318 QRect rect = m_pDrawPadCanvas->contentsRect();
319 319
320 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), 320 NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(),
321 m_pDrawPad->brush().color(), this); 321 m_pDrawPad->brush().color(), this);
322 322
323 if (newPageDialog.exec() == QDialog::Accepted) { 323 if (newPageDialog.exec() == QDialog::Accepted) {
324 m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), 324 m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(),
325 newPageDialog.selectedHeight(), newPageDialog.selectedColor()); 325 newPageDialog.selectedHeight(), newPageDialog.selectedColor());
326 m_pPageListBox->updateView(); 326 m_pPageListBox->updateView();
327 updateView(); 327 updateView();
328 } 328 }
329} 329}
330 330
331void ThumbnailView::clearPage() 331void ThumbnailView::clearPage()
332{ 332{
333 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe selected page?"), 333 QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe selected page?"),
334 QMessageBox::Information, QMessageBox::Yes, 334 QMessageBox::Information, QMessageBox::Yes,
335 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 335 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
336 QMessageBox::NoButton, this); 336 QMessageBox::NoButton, this);
337 337
338 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 338 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
339 messageBox.setButtonText(QMessageBox::No, tr("No")); 339 messageBox.setButtonText(QMessageBox::No, tr("No"));
340 340
341 if (messageBox.exec() == QMessageBox::Yes) { 341 if (messageBox.exec() == QMessageBox::Yes) {
342 m_pDrawPadCanvas->clearPage(); 342 m_pDrawPadCanvas->clearPage();
343 m_pPageListBox->updateView(); 343 m_pPageListBox->updateView();
344 } 344 }
345} 345}
346 346
347void ThumbnailView::deletePage() 347void ThumbnailView::deletePage()
348{ 348{
349 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), 349 QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"),
350 QMessageBox::Information, QMessageBox::Yes, 350 QMessageBox::Information, QMessageBox::Yes,
351 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, 351 QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
352 QMessageBox::NoButton, this); 352 QMessageBox::NoButton, this);
353 353
354 messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); 354 messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
355 messageBox.setButtonText(QMessageBox::No, tr("No")); 355 messageBox.setButtonText(QMessageBox::No, tr("No"));
356 356
357 if (messageBox.exec() == QMessageBox::Yes) { 357 if (messageBox.exec() == QMessageBox::Yes) {
358 m_pDrawPadCanvas->deletePage(); 358 m_pDrawPadCanvas->deletePage();
359 m_pPageListBox->updateView(); 359 m_pPageListBox->updateView();
360 updateView(); 360 updateView();
361 } 361 }
362} 362}
363 363
364void ThumbnailView::movePageUp() 364void ThumbnailView::movePageUp()
365{ 365{
366 m_pDrawPadCanvas->movePageUp(); 366 m_pDrawPadCanvas->movePageUp();
367 m_pPageListBox->updateView(); 367 m_pPageListBox->updateView();
368 updateView(); 368 updateView();
369} 369}
370 370
371void ThumbnailView::movePageDown() 371void ThumbnailView::movePageDown()
372{ 372{
373 m_pDrawPadCanvas->movePageDown(); 373 m_pDrawPadCanvas->movePageDown();
374 m_pPageListBox->updateView(); 374 m_pPageListBox->updateView();
375 updateView(); 375 updateView();
376} 376}
377 377
378void ThumbnailView::changePage() 378void ThumbnailView::changePage()
379{ 379{
380 m_pDrawPadCanvas->selectPage(m_pPageListBox->selected()); 380 m_pDrawPadCanvas->selectPage(m_pPageListBox->selected());
381 updateView(); 381 updateView();
382} 382}