1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the tools applications of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include <qtextstream.h>
31
#include "writeicondata.h"
36
static QByteArray unzipXPM(QString data, ulong& length)
38
const int lengthOffset = 4;
39
int baSize = data.length() / 2 + lengthOffset;
40
uchar *ba = new uchar[baSize];
41
for (int i = lengthOffset; i < baSize; ++i) {
42
char h = data[2 * (i-lengthOffset)].toLatin1();
43
char l = data[2 * (i-lengthOffset) + 1].toLatin1();
56
// qUncompress() expects the first 4 bytes to be the expected length of the
58
ba[0] = (length & 0xff000000) >> 24;
59
ba[1] = (length & 0x00ff0000) >> 16;
60
ba[2] = (length & 0x0000ff00) >> 8;
61
ba[3] = (length & 0x000000ff);
62
QByteArray baunzip = qUncompress(ba, baSize);
67
WriteIconData::WriteIconData(Uic *uic)
68
: driver(uic->driver()), output(uic->output()), option(uic->option())
72
void WriteIconData::acceptUI(DomUI *node)
74
TreeWalker::acceptUI(node);
77
void WriteIconData::acceptImages(DomImages *images)
79
TreeWalker::acceptImages(images);
82
void WriteIconData::acceptImage(DomImage *image)
84
QString img = image->attributeName() + QLatin1String("_data");
85
QString data = image->elementData()->text();
86
QString fmt = image->elementData()->attributeFormat();
87
int size = image->elementData()->attributeLength();
89
if (fmt == QLatin1String("XPM.GZ")) {
91
QByteArray baunzip = unzipXPM(data, length);
92
length = baunzip.size();
93
// shouldn't we test the initial 'length' against the
94
// resulting 'length' to catch corrupt UIC files?
98
output << option.indent << "static const char* const " << img << "[] = { " << endl;
99
while (baunzip[a] != '\"')
101
for (; a < (int) length; a++) {
102
output << baunzip[a];
103
if (baunzip[a] == '\n') {
105
} else if (baunzip[a] == '"') {
109
if (column++ >= 511 && inQuote) {
110
output << "\"\n\""; // be nice with MSVC & Co.
116
output << option.indent << "static const unsigned char " << img << "[] = { \n";
117
output << option.indent;
119
for (a = 0; a < (int) (data.length()/2)-1; a++) {
120
output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << ",";
122
output << "\n" << option.indent;
126
output << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << "\n";