author | leseb <leseb> | 2002-04-15 09:02:41 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-04-15 09:02:41 (UTC) |
commit | 6fe76c38a8c38e491bc292475bb2b27c4e63218c (patch) (unidiff) | |
tree | 83fd51845ebfa698a13f126d9e733d9a50e98cc1 | |
parent | d126d607fe18c9253330692f9da53bb932941af5 (diff) | |
download | opie-6fe76c38a8c38e491bc292475bb2b27c4e63218c.zip opie-6fe76c38a8c38e491bc292475bb2b27c4e63218c.tar.gz opie-6fe76c38a8c38e491bc292475bb2b27c4e63218c.tar.bz2 |
Add pages get method
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 5 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 58192d3..db6288f 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -60,477 +60,482 @@ private: | |||
60 | 60 | ||
61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
62 | { | 62 | { |
63 | m_state = Unknown; | 63 | m_state = Unknown; |
64 | } | 64 | } |
65 | 65 | ||
66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 70 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() |
71 | { | 71 | { |
72 | return m_pixmaps; | 72 | return m_pixmaps; |
73 | } | 73 | } |
74 | 74 | ||
75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
76 | const QString& qName, const QXmlAttributes& atts) | 76 | const QString& qName, const QXmlAttributes& atts) |
77 | { | 77 | { |
78 | Q_CONST_UNUSED(namespaceURI) | 78 | Q_CONST_UNUSED(namespaceURI) |
79 | Q_CONST_UNUSED(localName) | 79 | Q_CONST_UNUSED(localName) |
80 | 80 | ||
81 | if (qName.compare("data") == 0) { | 81 | if (qName.compare("data") == 0) { |
82 | m_state = InData; | 82 | m_state = InData; |
83 | m_dataLenght = atts.value("length").toULong(); | 83 | m_dataLenght = atts.value("length").toULong(); |
84 | m_dataFormat = atts.value("format"); | 84 | m_dataFormat = atts.value("format"); |
85 | 85 | ||
86 | if (m_dataFormat.isEmpty()) { | 86 | if (m_dataFormat.isEmpty()) { |
87 | m_dataFormat = "XPM"; | 87 | m_dataFormat = "XPM"; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | return true; | 91 | return true; |
92 | } | 92 | } |
93 | 93 | ||
94 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, | 94 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, |
95 | const QString& qName) | 95 | const QString& qName) |
96 | { | 96 | { |
97 | Q_CONST_UNUSED(namespaceURI) | 97 | Q_CONST_UNUSED(namespaceURI) |
98 | Q_CONST_UNUSED(localName) | 98 | Q_CONST_UNUSED(localName) |
99 | 99 | ||
100 | if (qName.compare("data") == 0) { | 100 | if (qName.compare("data") == 0) { |
101 | m_state = Unknown; | 101 | m_state = Unknown; |
102 | } | 102 | } |
103 | 103 | ||
104 | return true; | 104 | return true; |
105 | } | 105 | } |
106 | 106 | ||
107 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) | 107 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) |
108 | { | 108 | { |
109 | if (m_state == InData) { | 109 | if (m_state == InData) { |
110 | QByteArray byteArray(ch.length() / 2); | 110 | QByteArray byteArray(ch.length() / 2); |
111 | 111 | ||
112 | for (int i = 0; i < (int)ch.length() / 2; i++) { | 112 | for (int i = 0; i < (int)ch.length() / 2; i++) { |
113 | char h = ch[2 * i].latin1(); | 113 | char h = ch[2 * i].latin1(); |
114 | char l = ch[2 * i + 1].latin1(); | 114 | char l = ch[2 * i + 1].latin1(); |
115 | uchar r = 0; | 115 | uchar r = 0; |
116 | 116 | ||
117 | if (h <= '9') { | 117 | if (h <= '9') { |
118 | r += h - '0'; | 118 | r += h - '0'; |
119 | } else { | 119 | } else { |
120 | r += h - 'a' + 10; | 120 | r += h - 'a' + 10; |
121 | } | 121 | } |
122 | 122 | ||
123 | r = r << 4; | 123 | r = r << 4; |
124 | 124 | ||
125 | if (l <= '9') { | 125 | if (l <= '9') { |
126 | r += l - '0'; | 126 | r += l - '0'; |
127 | } else { | 127 | } else { |
128 | r += l - 'a' + 10; | 128 | r += l - 'a' + 10; |
129 | } | 129 | } |
130 | 130 | ||
131 | byteArray[i] = r; | 131 | byteArray[i] = r; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | QImage image; | 135 | QImage image; |
136 | 136 | ||
137 | if (m_dataFormat == "XPM") { | 137 | if (m_dataFormat == "XPM") { |
138 | if (m_dataLenght < ch.length() * 5) { | 138 | if (m_dataLenght < ch.length() * 5) { |
139 | m_dataLenght = ch.length() * 5; | 139 | m_dataLenght = ch.length() * 5; |
140 | } | 140 | } |
141 | 141 | ||
142 | QByteArray byteArrayUnzipped(m_dataLenght); | 142 | QByteArray byteArrayUnzipped(m_dataLenght); |
143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
144 | 144 | ||
145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); | 145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); |
146 | } else { | 146 | } else { |
147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); | 147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); |
148 | } | 148 | } |
149 | 149 | ||
150 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 150 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); |
151 | pixmap->convertFromImage(image); | 151 | pixmap->convertFromImage(image); |
152 | m_pixmaps.append(pixmap); | 152 | m_pixmaps.append(pixmap); |
153 | } | 153 | } |
154 | 154 | ||
155 | return true; | 155 | return true; |
156 | } | 156 | } |
157 | 157 | ||
158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
159 | : QScrollView(parent, name) | 159 | : QScrollView(parent, name) |
160 | { | 160 | { |
161 | m_pDrawPad = drawPad; | 161 | m_pDrawPad = drawPad; |
162 | m_pages.setAutoDelete(true); | 162 | m_pages.setAutoDelete(true); |
163 | m_pageBackups.setAutoDelete(true); | 163 | m_pageBackups.setAutoDelete(true); |
164 | 164 | ||
165 | viewport()->setBackgroundMode(QWidget::NoBackground); | 165 | viewport()->setBackgroundMode(QWidget::NoBackground); |
166 | } | 166 | } |
167 | 167 | ||
168 | DrawPadCanvas::~DrawPadCanvas() | 168 | DrawPadCanvas::~DrawPadCanvas() |
169 | { | 169 | { |
170 | } | 170 | } |
171 | 171 | ||
172 | void DrawPadCanvas::load(QIODevice* ioDevice) | 172 | void DrawPadCanvas::load(QIODevice* ioDevice) |
173 | { | 173 | { |
174 | QTextStream textStream(ioDevice); | 174 | QTextStream textStream(ioDevice); |
175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
176 | 176 | ||
177 | QXmlInputSource xmlInputSource(textStream); | 177 | QXmlInputSource xmlInputSource(textStream); |
178 | QXmlSimpleReader xmlSimpleReader; | 178 | QXmlSimpleReader xmlSimpleReader; |
179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; | 179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; |
180 | 180 | ||
181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
182 | xmlSimpleReader.parse(xmlInputSource); | 182 | xmlSimpleReader.parse(xmlInputSource); |
183 | 183 | ||
184 | m_pages = drawPadCanvasXmlHandler.pixmaps(); | 184 | m_pages = drawPadCanvasXmlHandler.pixmaps(); |
185 | 185 | ||
186 | if (m_pages.isEmpty()) { | 186 | if (m_pages.isEmpty()) { |
187 | m_pages.append(new QPixmap(contentsRect().size())); | 187 | m_pages.append(new QPixmap(contentsRect().size())); |
188 | m_pages.current()->fill(Qt::white); | 188 | m_pages.current()->fill(Qt::white); |
189 | } | 189 | } |
190 | 190 | ||
191 | m_pageBackups.clear(); | 191 | m_pageBackups.clear(); |
192 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 192 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
193 | 193 | ||
194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
195 | viewport()->update(); | 195 | viewport()->update(); |
196 | 196 | ||
197 | emit pagesChanged(); | 197 | emit pagesChanged(); |
198 | emit pageBackupsChanged(); | 198 | emit pageBackupsChanged(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void DrawPadCanvas::initialPage() | 201 | void DrawPadCanvas::initialPage() |
202 | { | 202 | { |
203 | m_pages.append(new QPixmap(236, 232)); | 203 | m_pages.append(new QPixmap(236, 232)); |
204 | m_pages.current()->fill(Qt::white); | 204 | m_pages.current()->fill(Qt::white); |
205 | 205 | ||
206 | m_pageBackups.clear(); | 206 | m_pageBackups.clear(); |
207 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 207 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
208 | 208 | ||
209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
210 | viewport()->update(); | 210 | viewport()->update(); |
211 | 211 | ||
212 | emit pagesChanged(); | 212 | emit pagesChanged(); |
213 | emit pageBackupsChanged(); | 213 | emit pageBackupsChanged(); |
214 | } | 214 | } |
215 | 215 | ||
216 | void DrawPadCanvas::save(QIODevice* ioDevice) | 216 | void DrawPadCanvas::save(QIODevice* ioDevice) |
217 | { | 217 | { |
218 | QTextStream textStream(ioDevice); | 218 | QTextStream textStream(ioDevice); |
219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
220 | 220 | ||
221 | textStream << "<drawpad>" << endl; | 221 | textStream << "<drawpad>" << endl; |
222 | textStream << " <images>" << endl; | 222 | textStream << " <images>" << endl; |
223 | 223 | ||
224 | QListIterator<QPixmap> bufferIterator(m_pages); | 224 | QListIterator<QPixmap> bufferIterator(m_pages); |
225 | 225 | ||
226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
227 | textStream << " <image>" << endl; | 227 | textStream << " <image>" << endl; |
228 | 228 | ||
229 | QImage image = bufferIterator.current()->convertToImage(); | 229 | QImage image = bufferIterator.current()->convertToImage(); |
230 | QByteArray byteArray; | 230 | QByteArray byteArray; |
231 | QBuffer buffer(byteArray); | 231 | QBuffer buffer(byteArray); |
232 | QImageIO imageIO(&buffer, "PNG"); | 232 | QImageIO imageIO(&buffer, "PNG"); |
233 | 233 | ||
234 | buffer.open(IO_WriteOnly); | 234 | buffer.open(IO_WriteOnly); |
235 | imageIO.setImage(image); | 235 | imageIO.setImage(image); |
236 | imageIO.write(); | 236 | imageIO.write(); |
237 | buffer.close(); | 237 | buffer.close(); |
238 | 238 | ||
239 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; | 239 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; |
240 | 240 | ||
241 | static const char hexchars[] = "0123456789abcdef"; | 241 | static const char hexchars[] = "0123456789abcdef"; |
242 | 242 | ||
243 | for (int i = 0; i < (int)byteArray.size(); i++ ) { | 243 | for (int i = 0; i < (int)byteArray.size(); i++ ) { |
244 | uchar s = (uchar)byteArray[i]; | 244 | uchar s = (uchar)byteArray[i]; |
245 | textStream << hexchars[s >> 4]; | 245 | textStream << hexchars[s >> 4]; |
246 | textStream << hexchars[s & 0x0f]; | 246 | textStream << hexchars[s & 0x0f]; |
247 | } | 247 | } |
248 | 248 | ||
249 | textStream << "</data>" << endl; | 249 | textStream << "</data>" << endl; |
250 | textStream << " </image>" << endl; | 250 | textStream << " </image>" << endl; |
251 | } | 251 | } |
252 | 252 | ||
253 | textStream << " </images>" << endl; | 253 | textStream << " </images>" << endl; |
254 | textStream << "</drawpad>"; | 254 | textStream << "</drawpad>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | void DrawPadCanvas::importPage(const QString& fileName) | 257 | void DrawPadCanvas::importPage(const QString& fileName) |
258 | { | 258 | { |
259 | QPixmap* importedPixmap = new QPixmap(); | 259 | QPixmap* importedPixmap = new QPixmap(); |
260 | 260 | ||
261 | importedPixmap->load(fileName); | 261 | importedPixmap->load(fileName); |
262 | m_pages.insert(m_pages.at() + 1, importedPixmap); | 262 | m_pages.insert(m_pages.at() + 1, importedPixmap); |
263 | 263 | ||
264 | m_pageBackups.clear(); | 264 | m_pageBackups.clear(); |
265 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 265 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
266 | 266 | ||
267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
268 | viewport()->update(); | 268 | viewport()->update(); |
269 | 269 | ||
270 | emit pagesChanged(); | 270 | emit pagesChanged(); |
271 | emit pageBackupsChanged(); | 271 | emit pageBackupsChanged(); |
272 | } | 272 | } |
273 | 273 | ||
274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
275 | { | 275 | { |
276 | if (fromPage == toPage) { | 276 | if (fromPage == toPage) { |
277 | DocLnk docLnk; | 277 | DocLnk docLnk; |
278 | MimeType mimeType(format); | 278 | MimeType mimeType(format); |
279 | 279 | ||
280 | docLnk.setName(name); | 280 | docLnk.setName(name); |
281 | docLnk.setType(mimeType.id()); | 281 | docLnk.setType(mimeType.id()); |
282 | 282 | ||
283 | FileManager fileManager; | 283 | FileManager fileManager; |
284 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 284 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
285 | QImageIO imageIO(ioDevice, format); | 285 | QImageIO imageIO(ioDevice, format); |
286 | 286 | ||
287 | QImage image = m_pages.current()->convertToImage(); | 287 | QImage image = m_pages.current()->convertToImage(); |
288 | imageIO.setImage(image); | 288 | imageIO.setImage(image); |
289 | imageIO.write(); | 289 | imageIO.write(); |
290 | delete ioDevice; | 290 | delete ioDevice; |
291 | } else { | 291 | } else { |
292 | for (uint i = fromPage; i <= toPage; i++) { | 292 | for (uint i = fromPage; i <= toPage; i++) { |
293 | DocLnk docLnk; | 293 | DocLnk docLnk; |
294 | MimeType mimeType(format); | 294 | MimeType mimeType(format); |
295 | 295 | ||
296 | docLnk.setName(name + QString::number(i)); | 296 | docLnk.setName(name + QString::number(i)); |
297 | docLnk.setType(mimeType.id()); | 297 | docLnk.setType(mimeType.id()); |
298 | 298 | ||
299 | FileManager fileManager; | 299 | FileManager fileManager; |
300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
301 | QImageIO imageIO(ioDevice, format); | 301 | QImageIO imageIO(ioDevice, format); |
302 | 302 | ||
303 | QImage image = m_pages.at(i - 1)->convertToImage(); | 303 | QImage image = m_pages.at(i - 1)->convertToImage(); |
304 | imageIO.setImage(image); | 304 | imageIO.setImage(image); |
305 | imageIO.write(); | 305 | imageIO.write(); |
306 | delete ioDevice; | 306 | delete ioDevice; |
307 | } | 307 | } |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | QPixmap* DrawPadCanvas::currentPage() | 311 | QPixmap* DrawPadCanvas::currentPage() |
312 | { | 312 | { |
313 | return m_pages.current(); | 313 | return m_pages.current(); |
314 | } | 314 | } |
315 | 315 | ||
316 | QList<QPixmap> DrawPadCanvas::pages() | ||
317 | { | ||
318 | return m_pages; | ||
319 | } | ||
320 | |||
316 | uint DrawPadCanvas::pagePosition() | 321 | uint DrawPadCanvas::pagePosition() |
317 | { | 322 | { |
318 | return (m_pages.at() + 1); | 323 | return (m_pages.at() + 1); |
319 | } | 324 | } |
320 | 325 | ||
321 | uint DrawPadCanvas::pageCount() | 326 | uint DrawPadCanvas::pageCount() |
322 | { | 327 | { |
323 | return m_pages.count(); | 328 | return m_pages.count(); |
324 | } | 329 | } |
325 | 330 | ||
326 | void DrawPadCanvas::deleteAll() | 331 | void DrawPadCanvas::deleteAll() |
327 | { | 332 | { |
328 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | 333 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
329 | QMessageBox::Information, QMessageBox::Yes, | 334 | QMessageBox::Information, QMessageBox::Yes, |
330 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 335 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
331 | QMessageBox::NoButton, this); | 336 | QMessageBox::NoButton, this); |
332 | 337 | ||
333 | if (messageBox.exec() == QMessageBox::Yes) { | 338 | if (messageBox.exec() == QMessageBox::Yes) { |
334 | m_pages.clear(); | 339 | m_pages.clear(); |
335 | 340 | ||
336 | m_pages.append(new QPixmap(contentsRect().size())); | 341 | m_pages.append(new QPixmap(contentsRect().size())); |
337 | m_pages.current()->fill(Qt::white); | 342 | m_pages.current()->fill(Qt::white); |
338 | 343 | ||
339 | m_pageBackups.clear(); | 344 | m_pageBackups.clear(); |
340 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 345 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
341 | 346 | ||
342 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 347 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
343 | viewport()->update(); | 348 | viewport()->update(); |
344 | 349 | ||
345 | emit pagesChanged(); | 350 | emit pagesChanged(); |
346 | emit pageBackupsChanged(); | 351 | emit pageBackupsChanged(); |
347 | } | 352 | } |
348 | } | 353 | } |
349 | 354 | ||
350 | void DrawPadCanvas::newPage() | 355 | void DrawPadCanvas::newPage() |
351 | { | 356 | { |
352 | QRect rect = contentsRect(); | 357 | QRect rect = contentsRect(); |
353 | 358 | ||
354 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), | 359 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
355 | m_pDrawPad->brush().color(), this); | 360 | m_pDrawPad->brush().color(), this); |
356 | 361 | ||
357 | if (newPageDialog.exec() == QDialog::Accepted) { | 362 | if (newPageDialog.exec() == QDialog::Accepted) { |
358 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), | 363 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), |
359 | newPageDialog.selectedHeight())); | 364 | newPageDialog.selectedHeight())); |
360 | m_pages.current()->fill(newPageDialog.selectedColor()); | 365 | m_pages.current()->fill(newPageDialog.selectedColor()); |
361 | 366 | ||
362 | m_pageBackups.clear(); | 367 | m_pageBackups.clear(); |
363 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 368 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
364 | 369 | ||
365 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 370 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
366 | viewport()->update(); | 371 | viewport()->update(); |
367 | 372 | ||
368 | emit pagesChanged(); | 373 | emit pagesChanged(); |
369 | emit pageBackupsChanged(); | 374 | emit pageBackupsChanged(); |
370 | } | 375 | } |
371 | } | 376 | } |
372 | 377 | ||
373 | void DrawPadCanvas::clearPage() | 378 | void DrawPadCanvas::clearPage() |
374 | { | 379 | { |
375 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | 380 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
376 | QMessageBox::Information, QMessageBox::Yes, | 381 | QMessageBox::Information, QMessageBox::Yes, |
377 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 382 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
378 | QMessageBox::NoButton, this); | 383 | QMessageBox::NoButton, this); |
379 | 384 | ||
380 | if (messageBox.exec() == QMessageBox::Yes) { | 385 | if (messageBox.exec() == QMessageBox::Yes) { |
381 | m_pages.current()->fill(Qt::white); | 386 | m_pages.current()->fill(Qt::white); |
382 | 387 | ||
383 | viewport()->update(); | 388 | viewport()->update(); |
384 | } | 389 | } |
385 | } | 390 | } |
386 | 391 | ||
387 | void DrawPadCanvas::deletePage() | 392 | void DrawPadCanvas::deletePage() |
388 | { | 393 | { |
389 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | 394 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), |
390 | QMessageBox::Information, QMessageBox::Yes, | 395 | QMessageBox::Information, QMessageBox::Yes, |
391 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 396 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
392 | QMessageBox::NoButton, this); | 397 | QMessageBox::NoButton, this); |
393 | 398 | ||
394 | if (messageBox.exec() == QMessageBox::Yes) { | 399 | if (messageBox.exec() == QMessageBox::Yes) { |
395 | m_pages.remove(m_pages.current()); | 400 | m_pages.remove(m_pages.current()); |
396 | 401 | ||
397 | if (m_pages.isEmpty()) { | 402 | if (m_pages.isEmpty()) { |
398 | m_pages.append(new QPixmap(contentsRect().size())); | 403 | m_pages.append(new QPixmap(contentsRect().size())); |
399 | m_pages.current()->fill(Qt::white); | 404 | m_pages.current()->fill(Qt::white); |
400 | } | 405 | } |
401 | 406 | ||
402 | m_pageBackups.clear(); | 407 | m_pageBackups.clear(); |
403 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 408 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
404 | 409 | ||
405 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 410 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
406 | viewport()->update(); | 411 | viewport()->update(); |
407 | 412 | ||
408 | emit pagesChanged(); | 413 | emit pagesChanged(); |
409 | emit pageBackupsChanged(); | 414 | emit pageBackupsChanged(); |
410 | } | 415 | } |
411 | } | 416 | } |
412 | 417 | ||
413 | bool DrawPadCanvas::undoEnabled() | 418 | bool DrawPadCanvas::undoEnabled() |
414 | { | 419 | { |
415 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 420 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
416 | } | 421 | } |
417 | 422 | ||
418 | bool DrawPadCanvas::redoEnabled() | 423 | bool DrawPadCanvas::redoEnabled() |
419 | { | 424 | { |
420 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 425 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
421 | } | 426 | } |
422 | 427 | ||
423 | bool DrawPadCanvas::goPreviousPageEnabled() | 428 | bool DrawPadCanvas::goPreviousPageEnabled() |
424 | { | 429 | { |
425 | return (m_pages.current() != m_pages.getFirst()); | 430 | return (m_pages.current() != m_pages.getFirst()); |
426 | } | 431 | } |
427 | 432 | ||
428 | bool DrawPadCanvas::goNextPageEnabled() | 433 | bool DrawPadCanvas::goNextPageEnabled() |
429 | { | 434 | { |
430 | return (m_pages.current() != m_pages.getLast()); | 435 | return (m_pages.current() != m_pages.getLast()); |
431 | } | 436 | } |
432 | 437 | ||
433 | void DrawPadCanvas::undo() | 438 | void DrawPadCanvas::undo() |
434 | { | 439 | { |
435 | *(m_pages.current()) = *(m_pageBackups.prev()); | 440 | *(m_pages.current()) = *(m_pageBackups.prev()); |
436 | 441 | ||
437 | viewport()->update(); | 442 | viewport()->update(); |
438 | 443 | ||
439 | emit pageBackupsChanged(); | 444 | emit pageBackupsChanged(); |
440 | } | 445 | } |
441 | 446 | ||
442 | void DrawPadCanvas::redo() | 447 | void DrawPadCanvas::redo() |
443 | { | 448 | { |
444 | *(m_pages.current()) = *(m_pageBackups.next()); | 449 | *(m_pages.current()) = *(m_pageBackups.next()); |
445 | 450 | ||
446 | viewport()->update(); | 451 | viewport()->update(); |
447 | 452 | ||
448 | emit pageBackupsChanged(); | 453 | emit pageBackupsChanged(); |
449 | } | 454 | } |
450 | 455 | ||
451 | void DrawPadCanvas::goFirstPage() | 456 | void DrawPadCanvas::goFirstPage() |
452 | { | 457 | { |
453 | m_pages.first(); | 458 | m_pages.first(); |
454 | m_pageBackups.clear(); | 459 | m_pageBackups.clear(); |
455 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 460 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
456 | 461 | ||
457 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 462 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
458 | viewport()->update(); | 463 | viewport()->update(); |
459 | 464 | ||
460 | emit pagesChanged(); | 465 | emit pagesChanged(); |
461 | emit pageBackupsChanged(); | 466 | emit pageBackupsChanged(); |
462 | } | 467 | } |
463 | 468 | ||
464 | void DrawPadCanvas::goPreviousPage() | 469 | void DrawPadCanvas::goPreviousPage() |
465 | { | 470 | { |
466 | m_pages.prev(); | 471 | m_pages.prev(); |
467 | m_pageBackups.clear(); | 472 | m_pageBackups.clear(); |
468 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 473 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
469 | 474 | ||
470 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 475 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
471 | viewport()->update(); | 476 | viewport()->update(); |
472 | 477 | ||
473 | emit pagesChanged(); | 478 | emit pagesChanged(); |
474 | emit pageBackupsChanged(); | 479 | emit pageBackupsChanged(); |
475 | } | 480 | } |
476 | 481 | ||
477 | void DrawPadCanvas::goNextPage() | 482 | void DrawPadCanvas::goNextPage() |
478 | { | 483 | { |
479 | m_pages.next(); | 484 | m_pages.next(); |
480 | m_pageBackups.clear(); | 485 | m_pageBackups.clear(); |
481 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 486 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
482 | 487 | ||
483 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 488 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
484 | viewport()->update(); | 489 | viewport()->update(); |
485 | 490 | ||
486 | emit pagesChanged(); | 491 | emit pagesChanged(); |
487 | emit pageBackupsChanged(); | 492 | emit pageBackupsChanged(); |
488 | } | 493 | } |
489 | 494 | ||
490 | void DrawPadCanvas::goLastPage() | 495 | void DrawPadCanvas::goLastPage() |
491 | { | 496 | { |
492 | m_pages.last(); | 497 | m_pages.last(); |
493 | m_pageBackups.clear(); | 498 | m_pageBackups.clear(); |
494 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 499 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
495 | 500 | ||
496 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 501 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
497 | viewport()->update(); | 502 | viewport()->update(); |
498 | 503 | ||
499 | emit pagesChanged(); | 504 | emit pagesChanged(); |
500 | emit pageBackupsChanged(); | 505 | emit pageBackupsChanged(); |
501 | } | 506 | } |
502 | 507 | ||
503 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 508 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
504 | { | 509 | { |
505 | m_pDrawPad->tool()->mousePressEvent(e); | 510 | m_pDrawPad->tool()->mousePressEvent(e); |
506 | } | 511 | } |
507 | 512 | ||
508 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | 513 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
509 | { | 514 | { |
510 | m_pDrawPad->tool()->mouseReleaseEvent(e); | 515 | m_pDrawPad->tool()->mouseReleaseEvent(e); |
511 | 516 | ||
512 | QPixmap* currentBackup = m_pageBackups.current(); | 517 | QPixmap* currentBackup = m_pageBackups.current(); |
513 | while (m_pageBackups.last() != currentBackup) { | 518 | while (m_pageBackups.last() != currentBackup) { |
514 | m_pageBackups.removeLast(); | 519 | m_pageBackups.removeLast(); |
515 | } | 520 | } |
516 | 521 | ||
517 | while (m_pageBackups.count() >= (5 + 1)) { | 522 | while (m_pageBackups.count() >= (5 + 1)) { |
518 | m_pageBackups.removeFirst(); | 523 | m_pageBackups.removeFirst(); |
519 | } | 524 | } |
520 | 525 | ||
521 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 526 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
522 | 527 | ||
523 | emit pageBackupsChanged(); | 528 | emit pageBackupsChanged(); |
524 | } | 529 | } |
525 | 530 | ||
526 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | 531 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
527 | { | 532 | { |
528 | m_pDrawPad->tool()->mouseMoveEvent(e); | 533 | m_pDrawPad->tool()->mouseMoveEvent(e); |
529 | } | 534 | } |
530 | 535 | ||
531 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 536 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
532 | { | 537 | { |
533 | QRect clipRect(cx, cy, cw, ch); | 538 | QRect clipRect(cx, cy, cw, ch); |
534 | 539 | ||
535 | p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect); | 540 | p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect); |
536 | } | 541 | } |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 90dd951..a1a9466 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h | |||
@@ -1,80 +1,81 @@ | |||
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 | ||
22 | class DrawPad; | 22 | class DrawPad; |
23 | 23 | ||
24 | class QPixmap; | 24 | class QPixmap; |
25 | 25 | ||
26 | class DrawPadCanvas : public QScrollView | 26 | class DrawPadCanvas : public QScrollView |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | 29 | ||
30 | public: | 30 | public: |
31 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); | 31 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); |
32 | ~DrawPadCanvas(); | 32 | ~DrawPadCanvas(); |
33 | 33 | ||
34 | void load(QIODevice* ioDevice); | 34 | void load(QIODevice* ioDevice); |
35 | void initialPage(); | 35 | void initialPage(); |
36 | void save(QIODevice* ioDevice); | 36 | void save(QIODevice* ioDevice); |
37 | 37 | ||
38 | void importPage(const QString& fileName); | 38 | void importPage(const QString& fileName); |
39 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); | 39 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); |
40 | 40 | ||
41 | bool undoEnabled(); | 41 | bool undoEnabled(); |
42 | bool redoEnabled(); | 42 | bool redoEnabled(); |
43 | bool goPreviousPageEnabled(); | 43 | bool goPreviousPageEnabled(); |
44 | bool goNextPageEnabled(); | 44 | bool goNextPageEnabled(); |
45 | 45 | ||
46 | QPixmap* currentPage(); | 46 | QPixmap* currentPage(); |
47 | QList<QPixmap> pages(); | ||
47 | uint pagePosition(); | 48 | uint pagePosition(); |
48 | uint pageCount(); | 49 | uint pageCount(); |
49 | 50 | ||
50 | public slots: | 51 | public slots: |
51 | void deleteAll(); | 52 | void deleteAll(); |
52 | void newPage(); | 53 | void newPage(); |
53 | void clearPage(); | 54 | void clearPage(); |
54 | void deletePage(); | 55 | void deletePage(); |
55 | 56 | ||
56 | void undo(); | 57 | void undo(); |
57 | void redo(); | 58 | void redo(); |
58 | 59 | ||
59 | void goFirstPage(); | 60 | void goFirstPage(); |
60 | void goPreviousPage(); | 61 | void goPreviousPage(); |
61 | void goNextPage(); | 62 | void goNextPage(); |
62 | void goLastPage(); | 63 | void goLastPage(); |
63 | 64 | ||
64 | signals: | 65 | signals: |
65 | void pagesChanged(); | 66 | void pagesChanged(); |
66 | void pageBackupsChanged(); | 67 | void pageBackupsChanged(); |
67 | 68 | ||
68 | protected: | 69 | protected: |
69 | void contentsMousePressEvent(QMouseEvent* e); | 70 | void contentsMousePressEvent(QMouseEvent* e); |
70 | void contentsMouseReleaseEvent(QMouseEvent* e); | 71 | void contentsMouseReleaseEvent(QMouseEvent* e); |
71 | void contentsMouseMoveEvent(QMouseEvent* e); | 72 | void contentsMouseMoveEvent(QMouseEvent* e); |
72 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); | 73 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); |
73 | 74 | ||
74 | private: | 75 | private: |
75 | DrawPad* m_pDrawPad; | 76 | DrawPad* m_pDrawPad; |
76 | QList<QPixmap> m_pages; | 77 | QList<QPixmap> m_pages; |
77 | QList<QPixmap> m_pageBackups; | 78 | QList<QPixmap> m_pageBackups; |
78 | }; | 79 | }; |
79 | 80 | ||
80 | #endif // DRAWPADCANVAS_H | 81 | #endif // DRAWPADCANVAS_H |