author | leseb <leseb> | 2002-03-21 19:43:29 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-21 19:43:29 (UTC) |
commit | fb34e5636c9bd56019f7f365ee75ab3da495e1f4 (patch) (unidiff) | |
tree | 4ff5c177d79beedc7de481f1a0a6d9090a15c3a0 | |
parent | 17b43caf4ffafff3a91bd144722d408d1c0dfacd (diff) | |
download | opie-fb34e5636c9bd56019f7f365ee75ab3da495e1f4.zip opie-fb34e5636c9bd56019f7f365ee75ab3da495e1f4.tar.gz opie-fb34e5636c9bd56019f7f365ee75ab3da495e1f4.tar.bz2 |
Fix initial page size
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 49a8cf0..40c27b5 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -1,446 +1,446 @@ | |||
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 "drawmode.h" | 16 | #include "drawmode.h" |
17 | #include "drawpad.h" | 17 | #include "drawpad.h" |
18 | #include "newpagedialog.h" | 18 | #include "newpagedialog.h" |
19 | 19 | ||
20 | #include <qbuffer.h> | 20 | #include <qbuffer.h> |
21 | #include <qimage.h> | 21 | #include <qimage.h> |
22 | #include <qpainter.h> | 22 | #include <qpainter.h> |
23 | #include <qpixmap.h> | 23 | #include <qpixmap.h> |
24 | #include <qtextcodec.h> | 24 | #include <qtextcodec.h> |
25 | #include <qtextstream.h> | 25 | #include <qtextstream.h> |
26 | #include <qxml.h> | 26 | #include <qxml.h> |
27 | 27 | ||
28 | #include <zlib.h> | 28 | #include <zlib.h> |
29 | 29 | ||
30 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 30 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | DrawPadCanvasXmlHandler(); | 33 | DrawPadCanvasXmlHandler(); |
34 | ~DrawPadCanvasXmlHandler(); | 34 | ~DrawPadCanvasXmlHandler(); |
35 | 35 | ||
36 | QList<QPixmap> pixmaps(); | 36 | QList<QPixmap> pixmaps(); |
37 | 37 | ||
38 | bool startElement(const QString& namespaceURI, const QString& localName, | 38 | bool startElement(const QString& namespaceURI, const QString& localName, |
39 | const QString& qName, const QXmlAttributes& atts); | 39 | const QString& qName, const QXmlAttributes& atts); |
40 | bool endElement(const QString& namespaceURI, const QString& localName, | 40 | bool endElement(const QString& namespaceURI, const QString& localName, |
41 | const QString& qName); | 41 | const QString& qName); |
42 | bool characters(const QString& ch); | 42 | bool characters(const QString& ch); |
43 | 43 | ||
44 | private: | 44 | private: |
45 | enum State { | 45 | enum State { |
46 | Unknown, | 46 | Unknown, |
47 | InData | 47 | InData |
48 | }; | 48 | }; |
49 | 49 | ||
50 | State m_state; | 50 | State m_state; |
51 | ulong m_dataLenght; | 51 | ulong m_dataLenght; |
52 | QList<QPixmap> m_pixmaps; | 52 | QList<QPixmap> m_pixmaps; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 55 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
56 | { | 56 | { |
57 | m_state = Unknown; | 57 | m_state = Unknown; |
58 | } | 58 | } |
59 | 59 | ||
60 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 60 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
61 | { | 61 | { |
62 | } | 62 | } |
63 | 63 | ||
64 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 64 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() |
65 | { | 65 | { |
66 | return m_pixmaps; | 66 | return m_pixmaps; |
67 | } | 67 | } |
68 | 68 | ||
69 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 69 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
70 | const QString& qName, const QXmlAttributes& atts) | 70 | const QString& qName, const QXmlAttributes& atts) |
71 | { | 71 | { |
72 | Q_CONST_UNUSED(namespaceURI) | 72 | Q_CONST_UNUSED(namespaceURI) |
73 | Q_CONST_UNUSED(localName) | 73 | Q_CONST_UNUSED(localName) |
74 | 74 | ||
75 | if (qName.compare("data") == 0) { | 75 | if (qName.compare("data") == 0) { |
76 | m_state = InData; | 76 | m_state = InData; |
77 | m_dataLenght = atts.value("length").toULong(); | 77 | m_dataLenght = atts.value("length").toULong(); |
78 | } | 78 | } |
79 | 79 | ||
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | 82 | ||
83 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, | 83 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, |
84 | const QString& qName) | 84 | const QString& qName) |
85 | { | 85 | { |
86 | Q_CONST_UNUSED(namespaceURI) | 86 | Q_CONST_UNUSED(namespaceURI) |
87 | Q_CONST_UNUSED(localName) | 87 | Q_CONST_UNUSED(localName) |
88 | 88 | ||
89 | if (qName.compare("data") == 0) { | 89 | if (qName.compare("data") == 0) { |
90 | m_state = Unknown; | 90 | m_state = Unknown; |
91 | } | 91 | } |
92 | 92 | ||
93 | return true; | 93 | return true; |
94 | } | 94 | } |
95 | 95 | ||
96 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) | 96 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) |
97 | { | 97 | { |
98 | if (m_state == InData) { | 98 | if (m_state == InData) { |
99 | QByteArray byteArray(ch.length() / 2); | 99 | QByteArray byteArray(ch.length() / 2); |
100 | 100 | ||
101 | for (int i = 0; i < (int)ch.length() / 2; i++) { | 101 | for (int i = 0; i < (int)ch.length() / 2; i++) { |
102 | char h = ch[2 * i].latin1(); | 102 | char h = ch[2 * i].latin1(); |
103 | char l = ch[2 * i + 1].latin1(); | 103 | char l = ch[2 * i + 1].latin1(); |
104 | uchar r = 0; | 104 | uchar r = 0; |
105 | 105 | ||
106 | if (h <= '9') { | 106 | if (h <= '9') { |
107 | r += h - '0'; | 107 | r += h - '0'; |
108 | } else { | 108 | } else { |
109 | r += h - 'a' + 10; | 109 | r += h - 'a' + 10; |
110 | } | 110 | } |
111 | 111 | ||
112 | r = r << 4; | 112 | r = r << 4; |
113 | 113 | ||
114 | if (l <= '9') { | 114 | if (l <= '9') { |
115 | r += l - '0'; | 115 | r += l - '0'; |
116 | } else { | 116 | } else { |
117 | r += l - 'a' + 10; | 117 | r += l - 'a' + 10; |
118 | } | 118 | } |
119 | 119 | ||
120 | byteArray[i] = r; | 120 | byteArray[i] = r; |
121 | } | 121 | } |
122 | 122 | ||
123 | if (m_dataLenght < ch.length() * 5) { | 123 | if (m_dataLenght < ch.length() * 5) { |
124 | m_dataLenght = ch.length() * 5; | 124 | m_dataLenght = ch.length() * 5; |
125 | } | 125 | } |
126 | 126 | ||
127 | QByteArray byteArrayUnzipped(m_dataLenght); | 127 | QByteArray byteArrayUnzipped(m_dataLenght); |
128 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 128 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
129 | 129 | ||
130 | QImage image; | 130 | QImage image; |
131 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); | 131 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); |
132 | 132 | ||
133 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 133 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); |
134 | pixmap->convertFromImage(image); | 134 | pixmap->convertFromImage(image); |
135 | m_pixmaps.append(pixmap); | 135 | m_pixmaps.append(pixmap); |
136 | } | 136 | } |
137 | 137 | ||
138 | return true; | 138 | return true; |
139 | } | 139 | } |
140 | 140 | ||
141 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 141 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
142 | : QScrollView(parent, name) | 142 | : QScrollView(parent, name) |
143 | { | 143 | { |
144 | m_pDrawPad = drawPad; | 144 | m_pDrawPad = drawPad; |
145 | m_pages.setAutoDelete(true); | 145 | m_pages.setAutoDelete(true); |
146 | m_pageBackups.setAutoDelete(true); | 146 | m_pageBackups.setAutoDelete(true); |
147 | } | 147 | } |
148 | 148 | ||
149 | DrawPadCanvas::~DrawPadCanvas() | 149 | DrawPadCanvas::~DrawPadCanvas() |
150 | { | 150 | { |
151 | } | 151 | } |
152 | 152 | ||
153 | void DrawPadCanvas::load(QIODevice* ioDevice) | 153 | void DrawPadCanvas::load(QIODevice* ioDevice) |
154 | { | 154 | { |
155 | QTextStream textStream(ioDevice); | 155 | QTextStream textStream(ioDevice); |
156 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 156 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
157 | 157 | ||
158 | QXmlInputSource xmlInputSource(textStream); | 158 | QXmlInputSource xmlInputSource(textStream); |
159 | QXmlSimpleReader xmlSimpleReader; | 159 | QXmlSimpleReader xmlSimpleReader; |
160 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; | 160 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; |
161 | 161 | ||
162 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 162 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
163 | xmlSimpleReader.parse(xmlInputSource); | 163 | xmlSimpleReader.parse(xmlInputSource); |
164 | 164 | ||
165 | m_pages = drawPadCanvasXmlHandler.pixmaps(); | 165 | m_pages = drawPadCanvasXmlHandler.pixmaps(); |
166 | 166 | ||
167 | if (m_pages.isEmpty()) { | 167 | if (m_pages.isEmpty()) { |
168 | m_pages.append(new QPixmap(contentsRect().size())); | 168 | m_pages.append(new QPixmap(contentsRect().size())); |
169 | m_pages.current()->fill(Qt::white); | 169 | m_pages.current()->fill(Qt::white); |
170 | } | 170 | } |
171 | 171 | ||
172 | m_pageBackups.clear(); | 172 | m_pageBackups.clear(); |
173 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 173 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
174 | 174 | ||
175 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 175 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
176 | viewport()->update(); | 176 | viewport()->update(); |
177 | 177 | ||
178 | emit pagesChanged(); | 178 | emit pagesChanged(); |
179 | emit pageBackupsChanged(); | 179 | emit pageBackupsChanged(); |
180 | } | 180 | } |
181 | 181 | ||
182 | void DrawPadCanvas::initialPage() | 182 | void DrawPadCanvas::initialPage() |
183 | { | 183 | { |
184 | m_pages.append(new QPixmap(234, 252)); | 184 | m_pages.append(new QPixmap(234, 233)); |
185 | m_pages.current()->fill(Qt::white); | 185 | m_pages.current()->fill(Qt::white); |
186 | 186 | ||
187 | m_pageBackups.clear(); | 187 | m_pageBackups.clear(); |
188 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 188 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
189 | 189 | ||
190 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 190 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
191 | viewport()->update(); | 191 | viewport()->update(); |
192 | 192 | ||
193 | emit pagesChanged(); | 193 | emit pagesChanged(); |
194 | emit pageBackupsChanged(); | 194 | emit pageBackupsChanged(); |
195 | } | 195 | } |
196 | 196 | ||
197 | void DrawPadCanvas::save(QIODevice* ioDevice) | 197 | void DrawPadCanvas::save(QIODevice* ioDevice) |
198 | { | 198 | { |
199 | QTextStream textStream(ioDevice); | 199 | QTextStream textStream(ioDevice); |
200 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 200 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
201 | 201 | ||
202 | textStream << "<drawpad>" << endl; | 202 | textStream << "<drawpad>" << endl; |
203 | textStream << " <images>" << endl; | 203 | textStream << " <images>" << endl; |
204 | 204 | ||
205 | QListIterator<QPixmap> bufferIterator(m_pages); | 205 | QListIterator<QPixmap> bufferIterator(m_pages); |
206 | 206 | ||
207 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 207 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
208 | textStream << " <image>" << endl; | 208 | textStream << " <image>" << endl; |
209 | 209 | ||
210 | QImage image = bufferIterator.current()->convertToImage(); | 210 | QImage image = bufferIterator.current()->convertToImage(); |
211 | QByteArray byteArray; | 211 | QByteArray byteArray; |
212 | QBuffer buffer(byteArray); | 212 | QBuffer buffer(byteArray); |
213 | QImageIO imageIO(&buffer, "XPM"); | 213 | QImageIO imageIO(&buffer, "XPM"); |
214 | 214 | ||
215 | buffer.open(IO_WriteOnly); | 215 | buffer.open(IO_WriteOnly); |
216 | imageIO.setImage(image); | 216 | imageIO.setImage(image); |
217 | imageIO.write(); | 217 | imageIO.write(); |
218 | buffer.close(); | 218 | buffer.close(); |
219 | 219 | ||
220 | ulong size = byteArray.size() * 2; | 220 | ulong size = byteArray.size() * 2; |
221 | QByteArray byteArrayZipped(size); | 221 | QByteArray byteArrayZipped(size); |
222 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); | 222 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); |
223 | 223 | ||
224 | textStream << " <data length=\"" << byteArray.size() << "\">"; | 224 | textStream << " <data length=\"" << byteArray.size() << "\">"; |
225 | 225 | ||
226 | static const char hexchars[] = "0123456789abcdef"; | 226 | static const char hexchars[] = "0123456789abcdef"; |
227 | 227 | ||
228 | for (int i = 0; i < (int)size; i++ ) { | 228 | for (int i = 0; i < (int)size; i++ ) { |
229 | uchar s = (uchar)byteArrayZipped[i]; | 229 | uchar s = (uchar)byteArrayZipped[i]; |
230 | textStream << hexchars[s >> 4]; | 230 | textStream << hexchars[s >> 4]; |
231 | textStream << hexchars[s & 0x0f]; | 231 | textStream << hexchars[s & 0x0f]; |
232 | } | 232 | } |
233 | 233 | ||
234 | textStream << "</data>" << endl; | 234 | textStream << "</data>" << endl; |
235 | textStream << " </image>" << endl; | 235 | textStream << " </image>" << endl; |
236 | } | 236 | } |
237 | 237 | ||
238 | textStream << " </images>" << endl; | 238 | textStream << " </images>" << endl; |
239 | textStream << "</drawpad>"; | 239 | textStream << "</drawpad>"; |
240 | } | 240 | } |
241 | 241 | ||
242 | QPixmap* DrawPadCanvas::currentPage() | 242 | QPixmap* DrawPadCanvas::currentPage() |
243 | { | 243 | { |
244 | return m_pages.current(); | 244 | return m_pages.current(); |
245 | } | 245 | } |
246 | 246 | ||
247 | uint DrawPadCanvas::pagePosition() | 247 | uint DrawPadCanvas::pagePosition() |
248 | { | 248 | { |
249 | return (m_pages.at() + 1); | 249 | return (m_pages.at() + 1); |
250 | } | 250 | } |
251 | 251 | ||
252 | uint DrawPadCanvas::pageCount() | 252 | uint DrawPadCanvas::pageCount() |
253 | { | 253 | { |
254 | return m_pages.count(); | 254 | return m_pages.count(); |
255 | } | 255 | } |
256 | 256 | ||
257 | void DrawPadCanvas::clearAll() | 257 | void DrawPadCanvas::clearAll() |
258 | { | 258 | { |
259 | m_pages.clear(); | 259 | m_pages.clear(); |
260 | 260 | ||
261 | m_pages.append(new QPixmap(contentsRect().size())); | 261 | m_pages.append(new QPixmap(contentsRect().size())); |
262 | m_pages.current()->fill(Qt::white); | 262 | m_pages.current()->fill(Qt::white); |
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::newPage() | 274 | void DrawPadCanvas::newPage() |
275 | { | 275 | { |
276 | QRect rect = contentsRect(); | 276 | QRect rect = contentsRect(); |
277 | 277 | ||
278 | NewPageDialog newPageDialog(this); | 278 | NewPageDialog newPageDialog(this); |
279 | newPageDialog.setWidth(rect.width()); | 279 | newPageDialog.setWidth(rect.width()); |
280 | newPageDialog.setHeight(rect.height()); | 280 | newPageDialog.setHeight(rect.height()); |
281 | 281 | ||
282 | if (newPageDialog.exec() == QDialog::Accepted) { | 282 | if (newPageDialog.exec() == QDialog::Accepted) { |
283 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height())); | 283 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height())); |
284 | m_pages.current()->fill(Qt::white); | 284 | m_pages.current()->fill(Qt::white); |
285 | 285 | ||
286 | m_pageBackups.clear(); | 286 | m_pageBackups.clear(); |
287 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 287 | m_pageBackups.append(new QPixmap(*(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 | } |
296 | 296 | ||
297 | void DrawPadCanvas::clearPage() | 297 | void DrawPadCanvas::clearPage() |
298 | { | 298 | { |
299 | m_pages.current()->fill(Qt::white); | 299 | m_pages.current()->fill(Qt::white); |
300 | 300 | ||
301 | viewport()->update(); | 301 | viewport()->update(); |
302 | } | 302 | } |
303 | 303 | ||
304 | void DrawPadCanvas::deletePage() | 304 | void DrawPadCanvas::deletePage() |
305 | { | 305 | { |
306 | m_pages.remove(m_pages.current()); | 306 | m_pages.remove(m_pages.current()); |
307 | 307 | ||
308 | if (m_pages.isEmpty()) { | 308 | if (m_pages.isEmpty()) { |
309 | m_pages.append(new QPixmap(contentsRect().size())); | 309 | m_pages.append(new QPixmap(contentsRect().size())); |
310 | m_pages.current()->fill(Qt::white); | 310 | m_pages.current()->fill(Qt::white); |
311 | } | 311 | } |
312 | 312 | ||
313 | m_pageBackups.clear(); | 313 | m_pageBackups.clear(); |
314 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 314 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
315 | 315 | ||
316 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 316 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
317 | viewport()->update(); | 317 | viewport()->update(); |
318 | 318 | ||
319 | emit pagesChanged(); | 319 | emit pagesChanged(); |
320 | emit pageBackupsChanged(); | 320 | emit pageBackupsChanged(); |
321 | } | 321 | } |
322 | 322 | ||
323 | bool DrawPadCanvas::undoEnabled() | 323 | bool DrawPadCanvas::undoEnabled() |
324 | { | 324 | { |
325 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 325 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
326 | } | 326 | } |
327 | 327 | ||
328 | bool DrawPadCanvas::redoEnabled() | 328 | bool DrawPadCanvas::redoEnabled() |
329 | { | 329 | { |
330 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 330 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
331 | } | 331 | } |
332 | 332 | ||
333 | bool DrawPadCanvas::goPreviousPageEnabled() | 333 | bool DrawPadCanvas::goPreviousPageEnabled() |
334 | { | 334 | { |
335 | return (m_pages.current() != m_pages.getFirst()); | 335 | return (m_pages.current() != m_pages.getFirst()); |
336 | } | 336 | } |
337 | 337 | ||
338 | bool DrawPadCanvas::goNextPageEnabled() | 338 | bool DrawPadCanvas::goNextPageEnabled() |
339 | { | 339 | { |
340 | return (m_pages.current() != m_pages.getLast()); | 340 | return (m_pages.current() != m_pages.getLast()); |
341 | } | 341 | } |
342 | 342 | ||
343 | void DrawPadCanvas::undo() | 343 | void DrawPadCanvas::undo() |
344 | { | 344 | { |
345 | *(m_pages.current()) = *(m_pageBackups.prev()); | 345 | *(m_pages.current()) = *(m_pageBackups.prev()); |
346 | 346 | ||
347 | viewport()->update(); | 347 | viewport()->update(); |
348 | 348 | ||
349 | emit pageBackupsChanged(); | 349 | emit pageBackupsChanged(); |
350 | } | 350 | } |
351 | 351 | ||
352 | void DrawPadCanvas::redo() | 352 | void DrawPadCanvas::redo() |
353 | { | 353 | { |
354 | *(m_pages.current()) = *(m_pageBackups.next()); | 354 | *(m_pages.current()) = *(m_pageBackups.next()); |
355 | 355 | ||
356 | viewport()->update(); | 356 | viewport()->update(); |
357 | 357 | ||
358 | emit pageBackupsChanged(); | 358 | emit pageBackupsChanged(); |
359 | } | 359 | } |
360 | 360 | ||
361 | void DrawPadCanvas::goFirstPage() | 361 | void DrawPadCanvas::goFirstPage() |
362 | { | 362 | { |
363 | m_pages.first(); | 363 | m_pages.first(); |
364 | m_pageBackups.clear(); | 364 | m_pageBackups.clear(); |
365 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 365 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
366 | 366 | ||
367 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 367 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
368 | viewport()->update(); | 368 | viewport()->update(); |
369 | 369 | ||
370 | emit pagesChanged(); | 370 | emit pagesChanged(); |
371 | emit pageBackupsChanged(); | 371 | emit pageBackupsChanged(); |
372 | } | 372 | } |
373 | 373 | ||
374 | void DrawPadCanvas::goPreviousPage() | 374 | void DrawPadCanvas::goPreviousPage() |
375 | { | 375 | { |
376 | m_pages.prev(); | 376 | m_pages.prev(); |
377 | m_pageBackups.clear(); | 377 | m_pageBackups.clear(); |
378 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 378 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
379 | 379 | ||
380 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 380 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
381 | viewport()->update(); | 381 | viewport()->update(); |
382 | 382 | ||
383 | emit pagesChanged(); | 383 | emit pagesChanged(); |
384 | emit pageBackupsChanged(); | 384 | emit pageBackupsChanged(); |
385 | } | 385 | } |
386 | 386 | ||
387 | void DrawPadCanvas::goNextPage() | 387 | void DrawPadCanvas::goNextPage() |
388 | { | 388 | { |
389 | m_pages.next(); | 389 | m_pages.next(); |
390 | m_pageBackups.clear(); | 390 | m_pageBackups.clear(); |
391 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 391 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
392 | 392 | ||
393 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 393 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
394 | viewport()->update(); | 394 | viewport()->update(); |
395 | 395 | ||
396 | emit pagesChanged(); | 396 | emit pagesChanged(); |
397 | emit pageBackupsChanged(); | 397 | emit pageBackupsChanged(); |
398 | } | 398 | } |
399 | 399 | ||
400 | void DrawPadCanvas::goLastPage() | 400 | void DrawPadCanvas::goLastPage() |
401 | { | 401 | { |
402 | m_pages.last(); | 402 | m_pages.last(); |
403 | m_pageBackups.clear(); | 403 | m_pageBackups.clear(); |
404 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 404 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
405 | 405 | ||
406 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 406 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
407 | viewport()->update(); | 407 | viewport()->update(); |
408 | 408 | ||
409 | emit pagesChanged(); | 409 | emit pagesChanged(); |
410 | emit pageBackupsChanged(); | 410 | emit pageBackupsChanged(); |
411 | } | 411 | } |
412 | 412 | ||
413 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 413 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
414 | { | 414 | { |
415 | m_pDrawPad->drawMode()->mousePressEvent(e); | 415 | m_pDrawPad->drawMode()->mousePressEvent(e); |
416 | } | 416 | } |
417 | 417 | ||
418 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | 418 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
419 | { | 419 | { |
420 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); | 420 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); |
421 | 421 | ||
422 | QPixmap* currentBackup = m_pageBackups.current(); | 422 | QPixmap* currentBackup = m_pageBackups.current(); |
423 | while (m_pageBackups.last() != currentBackup) { | 423 | while (m_pageBackups.last() != currentBackup) { |
424 | m_pageBackups.removeLast(); | 424 | m_pageBackups.removeLast(); |
425 | } | 425 | } |
426 | 426 | ||
427 | while (m_pageBackups.count() >= (5 + 1)) { | 427 | while (m_pageBackups.count() >= (5 + 1)) { |
428 | m_pageBackups.removeFirst(); | 428 | m_pageBackups.removeFirst(); |
429 | } | 429 | } |
430 | 430 | ||
431 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 431 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
432 | 432 | ||
433 | emit pageBackupsChanged(); | 433 | emit pageBackupsChanged(); |
434 | } | 434 | } |
435 | 435 | ||
436 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | 436 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
437 | { | 437 | { |
438 | m_pDrawPad->drawMode()->mouseMoveEvent(e); | 438 | m_pDrawPad->drawMode()->mouseMoveEvent(e); |
439 | } | 439 | } |
440 | 440 | ||
441 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 441 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
442 | { | 442 | { |
443 | QRect clipRect(cx, cy, cw, ch); | 443 | QRect clipRect(cx, cy, cw, ch); |
444 | 444 | ||
445 | p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect); | 445 | p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect); |
446 | } | 446 | } |