1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the tools applications of the Qt Toolkit.
|
|
7 **
|
|
8 ** Commercial Usage
|
|
9 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 ** accordance with the Qt Commercial License Agreement provided with the
|
|
11 ** Software or, alternatively, in accordance with the terms contained in
|
|
12 ** a written agreement between you and Nokia.
|
|
13 **
|
|
14 **
|
|
15 ** GNU General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU
|
|
17 ** General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 ** Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 ** the packaging of this file. Please review the following information
|
|
20 ** to ensure GNU General Public Licensing requirements will be met:
|
|
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 ** exception, Nokia gives you certain additional rights. These rights
|
|
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in
|
|
25 ** the file GPL_EXCEPTION.txt in this package.
|
|
26 **
|
|
27 ** Qt for Windows(R) Licensees
|
|
28 ** As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 ** right for the Qt/Eclipse Integration to link to functionality
|
|
31 ** provided by Qt Designer and its related libraries.
|
|
32 **
|
|
33 ** If you are unsure which license is appropriate for your use, please
|
|
34 ** contact the sales department at qt-sales@nokia.com.
|
|
35 **
|
|
36 ****************************************************************************/
|
|
37
|
|
38 #include "dwriteicondata.h"
|
|
39 #include "driver.h"
|
|
40 #include "ui4.h"
|
|
41 #include "uic.h"
|
|
42
|
|
43 #include <QtCore/QTextStream>
|
|
44
|
|
45 QT_BEGIN_NAMESPACE
|
|
46
|
|
47 namespace D {
|
|
48
|
|
49 static QByteArray transformImageData(QString data)
|
|
50 {
|
|
51 int baSize = data.length() / 2;
|
|
52 uchar *ba = new uchar[baSize];
|
|
53 for (int i = 0; i < baSize; ++i) {
|
|
54 char h = data[2 * (i)].toLatin1();
|
|
55 char l = data[2 * (i) + 1].toLatin1();
|
|
56 uchar r = 0;
|
|
57 if (h <= '9')
|
|
58 r += h - '0';
|
|
59 else
|
|
60 r += h - 'a' + 10;
|
|
61 r = r << 4;
|
|
62 if (l <= '9')
|
|
63 r += l - '0';
|
|
64 else
|
|
65 r += l - 'a' + 10;
|
|
66 ba[i] = r;
|
|
67 }
|
|
68 QByteArray ret(reinterpret_cast<const char *>(ba), baSize);
|
|
69 delete [] ba;
|
|
70 return ret;
|
|
71 }
|
|
72
|
|
73 static QByteArray unzipXPM(QString data, ulong& length)
|
|
74 {
|
|
75 #ifndef QT_NO_COMPRESS
|
|
76 const int lengthOffset = 4;
|
|
77 QByteArray ba(lengthOffset, ' ');
|
|
78
|
|
79 // qUncompress() expects the first 4 bytes to be the expected length of the
|
|
80 // uncompressed data
|
|
81 ba[0] = (length & 0xff000000) >> 24;
|
|
82 ba[1] = (length & 0x00ff0000) >> 16;
|
|
83 ba[2] = (length & 0x0000ff00) >> 8;
|
|
84 ba[3] = (length & 0x000000ff);
|
|
85 ba.append(transformImageData(data));
|
|
86 QByteArray baunzip = qUncompress(ba);
|
|
87 return baunzip;
|
|
88 #else
|
|
89 Q_UNUSED(data);
|
|
90 Q_UNUSED(length);
|
|
91 return QByteArray();
|
|
92 #endif
|
|
93 }
|
|
94
|
|
95
|
|
96 WriteIconData::WriteIconData(Uic *uic)
|
|
97 : driver(uic->driver()), output(uic->output()), option(uic->option())
|
|
98 {
|
|
99 }
|
|
100
|
|
101 void WriteIconData::acceptUI(DomUI *node)
|
|
102 {
|
|
103 TreeWalker::acceptUI(node);
|
|
104 }
|
|
105
|
|
106 void WriteIconData::acceptImages(DomImages *images)
|
|
107 {
|
|
108 TreeWalker::acceptImages(images);
|
|
109 }
|
|
110
|
|
111 void WriteIconData::acceptImage(DomImage *image)
|
|
112 {
|
|
113 writeImage(output, option.indent, image);
|
|
114 }
|
|
115
|
|
116 void WriteIconData::writeImage(QTextStream &output, const QString &indent, DomImage *image)
|
|
117 {
|
|
118 QString img = image->attributeName() + QLatin1String("_data");
|
|
119 QString data = image->elementData()->text();
|
|
120 QString fmt = image->elementData()->attributeFormat();
|
|
121 int size = image->elementData()->attributeLength();
|
|
122
|
|
123 if (fmt == QLatin1String("XPM.GZ")) {
|
|
124 ulong length = size;
|
|
125 QByteArray baunzip = unzipXPM(data, length);
|
|
126 length = baunzip.size();
|
|
127 // shouldn't we test the initial 'length' against the
|
|
128 // resulting 'length' to catch corrupt UIC files?
|
|
129 int a = 0;
|
|
130 int column = 0;
|
|
131 bool inQuote = false;
|
|
132 output << indent << "static const char* const " << img << "[] = { \n";
|
|
133 while (baunzip[a] != '\"')
|
|
134 a++;
|
|
135 for (; a < (int) length; a++) {
|
|
136 output << baunzip[a];
|
|
137 if (baunzip[a] == '\n') {
|
|
138 column = 0;
|
|
139 } else if (baunzip[a] == '"') {
|
|
140 inQuote = !inQuote;
|
|
141 }
|
|
142
|
|
143 if (column++ >= 511 && inQuote) {
|
|
144 output << "\"\n\""; // be nice with MSVC & Co.
|
|
145 column = 1;
|
|
146 }
|
|
147 }
|
|
148
|
|
149 if (! baunzip.trimmed ().endsWith ("};"))
|
|
150 output << "};";
|
|
151
|
|
152 output << "\n\n";
|
|
153 } else {
|
|
154 output << indent << "static const unsigned char " << img << "[] = { \n";
|
|
155 output << indent;
|
|
156 int a ;
|
|
157 for (a = 0; a < (int) (data.length()/2)-1; a++) {
|
|
158 output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << ',';
|
|
159 if (a % 12 == 11)
|
|
160 output << "\n" << indent;
|
|
161 else
|
|
162 output << " ";
|
|
163 }
|
|
164 output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << '\n';
|
|
165 output << "};\n\n";
|
|
166 }
|
|
167 }
|
|
168
|
|
169 void WriteIconData::writeImage(QIODevice &output, DomImage *image)
|
|
170 {
|
|
171 QByteArray array = transformImageData(image->elementData()->text());
|
|
172 output.write(array, array.size());
|
|
173 }
|
|
174
|
|
175 } // namespace D
|
|
176
|
|
177 QT_END_NAMESPACE
|