示例#1
0
static ulong embedData( QTextStream& out, const uchar* input, int nbytes )
{
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
    QByteArray bazip( qCompress( input, nbytes ) );
    ulong len = bazip.size();
#else
    ulong len = nbytes;
#endif
    static const char hexdigits[] = "0123456789abcdef";
    QString s;
    for ( int i=0; i<(int)len; i++ ) {
	if ( (i%14) == 0 ) {
	    s += "\n    ";
	    out << (const char*)s;
	    s.truncate( 0 );
	}
	uint v = (uchar)
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
		 bazip
#else
		 input
#endif
		 [i];
	s += "0x";
	s += hexdigits[(v >> 4) & 15];
	s += hexdigits[v & 15];
	if ( i < (int)len-1 )
	    s += ',';
    }
    if ( s.length() )
	out << (const char*)s;
    return len;
}
示例#2
0
void createPixmapNode( QDomDocument& doc, QDomNode& parent,
                       const QString& elementName, const QPixmap& pixmap )
{
    QDomElement pixmapElement = doc.createElement( elementName );
    parent.appendChild( pixmapElement );

    // Convert the pixmap to an image, save that image to an in-memory
    // XPM representation and compress this representation. This
    // conforms to the file format Qt Designer uses.
    QByteArray ba;
    QBuffer buffer( ba );
    buffer.open( IO_WriteOnly );
    QImageIO imgio( &buffer, "XPM" );
    QImage image = pixmap.convertToImage();
    imgio.setImage( image );
    imgio.write();
    buffer.close();
    ulong len = ba.size() * 2;
    QByteArray bazip( len );
    ::compress(  (uchar*) bazip.data(), &len, (uchar*) ba.data(), ba.size() );
    QString dataString;
    static const char hexchars[] = "0123456789abcdef";
    for ( int i = 0; i < (int)len; ++i ) {
        uchar c = (uchar) bazip[i];
        dataString += hexchars[c >> 4];
        dataString += hexchars[c & 0x0f];
    }

    createStringNode( doc, pixmapElement, "Format", "XPM.GZ" );
    createIntNode( doc, pixmapElement, "Length", ba.size() );
    createStringNode( doc, pixmapElement, "Data", dataString );
}