Diffstat (limited to 'noncore/graphics/drawpad/drawpadcanvas.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 8818c03..b8a1c2e 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -45,24 +45,25 @@ public: | |||
45 | bool endElement(const QString& namespaceURI, const QString& localName, | 45 | bool endElement(const QString& namespaceURI, const QString& localName, |
46 | const QString& qName); | 46 | const QString& qName); |
47 | bool characters(const QString& ch); | 47 | bool characters(const QString& ch); |
48 | 48 | ||
49 | private: | 49 | private: |
50 | enum State { | 50 | enum State { |
51 | Unknown, | 51 | Unknown, |
52 | InData | 52 | InData |
53 | }; | 53 | }; |
54 | 54 | ||
55 | State m_state; | 55 | State m_state; |
56 | ulong m_dataLenght; | 56 | ulong m_dataLenght; |
57 | QString m_dataFormat; | ||
57 | QList<QPixmap> m_pixmaps; | 58 | QList<QPixmap> m_pixmaps; |
58 | }; | 59 | }; |
59 | 60 | ||
60 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
61 | { | 62 | { |
62 | m_state = Unknown; | 63 | m_state = Unknown; |
63 | } | 64 | } |
64 | 65 | ||
65 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
66 | { | 67 | { |
67 | } | 68 | } |
68 | 69 | ||
@@ -71,24 +72,29 @@ QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | |||
71 | return m_pixmaps; | 72 | return m_pixmaps; |
72 | } | 73 | } |
73 | 74 | ||
74 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
75 | const QString& qName, const QXmlAttributes& atts) | 76 | const QString& qName, const QXmlAttributes& atts) |
76 | { | 77 | { |
77 | Q_CONST_UNUSED(namespaceURI) | 78 | Q_CONST_UNUSED(namespaceURI) |
78 | Q_CONST_UNUSED(localName) | 79 | Q_CONST_UNUSED(localName) |
79 | 80 | ||
80 | if (qName.compare("data") == 0) { | 81 | if (qName.compare("data") == 0) { |
81 | m_state = InData; | 82 | m_state = InData; |
82 | m_dataLenght = atts.value("length").toULong(); | 83 | m_dataLenght = atts.value("length").toULong(); |
84 | m_dataFormat = atts.value("format"); | ||
85 | |||
86 | if (m_dataFormat.isEmpty()) { | ||
87 | m_dataFormat = "XPM"; | ||
88 | } | ||
83 | } | 89 | } |
84 | 90 | ||
85 | return true; | 91 | return true; |
86 | } | 92 | } |
87 | 93 | ||
88 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, | 94 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, |
89 | const QString& qName) | 95 | const QString& qName) |
90 | { | 96 | { |
91 | Q_CONST_UNUSED(namespaceURI) | 97 | Q_CONST_UNUSED(namespaceURI) |
92 | Q_CONST_UNUSED(localName) | 98 | Q_CONST_UNUSED(localName) |
93 | 99 | ||
94 | if (qName.compare("data") == 0) { | 100 | if (qName.compare("data") == 0) { |
@@ -124,25 +130,25 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) | |||
124 | 130 | ||
125 | byteArray[i] = r; | 131 | byteArray[i] = r; |
126 | } | 132 | } |
127 | 133 | ||
128 | if (m_dataLenght < ch.length() * 5) { | 134 | if (m_dataLenght < ch.length() * 5) { |
129 | m_dataLenght = ch.length() * 5; | 135 | m_dataLenght = ch.length() * 5; |
130 | } | 136 | } |
131 | 137 | ||
132 | QByteArray byteArrayUnzipped(m_dataLenght); | 138 | QByteArray byteArrayUnzipped(m_dataLenght); |
133 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 139 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
134 | 140 | ||
135 | QImage image; | 141 | QImage image; |
136 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); | 142 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); |
137 | 143 | ||
138 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 144 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); |
139 | pixmap->convertFromImage(image); | 145 | pixmap->convertFromImage(image); |
140 | m_pixmaps.append(pixmap); | 146 | m_pixmaps.append(pixmap); |
141 | } | 147 | } |
142 | 148 | ||
143 | return true; | 149 | return true; |
144 | } | 150 | } |
145 | 151 | ||
146 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 152 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
147 | : QScrollView(parent, name) | 153 | : QScrollView(parent, name) |
148 | { | 154 | { |
@@ -206,36 +212,36 @@ void DrawPadCanvas::save(QIODevice* ioDevice) | |||
206 | 212 | ||
207 | textStream << "<drawpad>" << endl; | 213 | textStream << "<drawpad>" << endl; |
208 | textStream << " <images>" << endl; | 214 | textStream << " <images>" << endl; |
209 | 215 | ||
210 | QListIterator<QPixmap> bufferIterator(m_pages); | 216 | QListIterator<QPixmap> bufferIterator(m_pages); |
211 | 217 | ||
212 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 218 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
213 | textStream << " <image>" << endl; | 219 | textStream << " <image>" << endl; |
214 | 220 | ||
215 | QImage image = bufferIterator.current()->convertToImage(); | 221 | QImage image = bufferIterator.current()->convertToImage(); |
216 | QByteArray byteArray; | 222 | QByteArray byteArray; |
217 | QBuffer buffer(byteArray); | 223 | QBuffer buffer(byteArray); |
218 | QImageIO imageIO(&buffer, "XPM"); | 224 | QImageIO imageIO(&buffer, "PNG"); |
219 | 225 | ||
220 | buffer.open(IO_WriteOnly); | 226 | buffer.open(IO_WriteOnly); |
221 | imageIO.setImage(image); | 227 | imageIO.setImage(image); |
222 | imageIO.write(); | 228 | imageIO.write(); |
223 | buffer.close(); | 229 | buffer.close(); |
224 | 230 | ||
225 | ulong size = byteArray.size() * 2; | 231 | ulong size = byteArray.size() * 2; |
226 | QByteArray byteArrayZipped(size); | 232 | QByteArray byteArrayZipped(size); |
227 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); | 233 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); |
228 | 234 | ||
229 | textStream << " <data length=\"" << byteArray.size() << "\">"; | 235 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; |
230 | 236 | ||
231 | static const char hexchars[] = "0123456789abcdef"; | 237 | static const char hexchars[] = "0123456789abcdef"; |
232 | 238 | ||
233 | for (int i = 0; i < (int)size; i++ ) { | 239 | for (int i = 0; i < (int)size; i++ ) { |
234 | uchar s = (uchar)byteArrayZipped[i]; | 240 | uchar s = (uchar)byteArrayZipped[i]; |
235 | textStream << hexchars[s >> 4]; | 241 | textStream << hexchars[s >> 4]; |
236 | textStream << hexchars[s & 0x0f]; | 242 | textStream << hexchars[s & 0x0f]; |
237 | } | 243 | } |
238 | 244 | ||
239 | textStream << "</data>" << endl; | 245 | textStream << "</data>" << endl; |
240 | textStream << " </image>" << endl; | 246 | textStream << " </image>" << endl; |
241 | } | 247 | } |