Eneboo - Documentación para desarrolladores
|
00001 /********************************************************************** 00002 ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved. 00003 ** 00004 ** This file is part of Qt Designer. 00005 ** 00006 ** This file may be distributed and/or modified under the terms of the 00007 ** GNU General Public License version 2 as published by the Free Software 00008 ** Foundation and appearing in the file LICENSE.GPL included in the 00009 ** packaging of this file. 00010 ** 00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00012 ** licenses may use this file in accordance with the Qt Commercial License 00013 ** Agreement provided with the Software. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00020 ** information about Qt Commercial License Agreements. 00021 ** 00022 ** Contact info@trolltech.com if any conditions of this licensing are 00023 ** not clear to you. 00024 ** 00025 **********************************************************************/ 00026 00027 #ifndef UIB_H 00028 #define UIB_H 00029 00030 #include <qdatastream.h> 00031 00032 const Q_UINT32 UibMagic = 0xb77c61d8; 00033 00034 enum BlockTag { Block_End = '$', Block_Actions = 'A', Block_Buddies = 'B', 00035 Block_Connections = 'C', Block_Functions = 'F', 00036 Block_Images = 'G', Block_Intro = 'I', Block_Menubar = 'M', 00037 Block_Slots = 'S', Block_Strings = 'Z', Block_Tabstops = 'T', 00038 Block_Toolbars = 'O', Block_Variables = 'V', 00039 Block_Widget = 'W' }; 00040 00041 enum ObjectTag { Object_End = '$', Object_ActionRef = 'X', 00042 Object_Attribute = 'B', Object_Column = 'C', 00043 Object_Event = 'E', Object_FontProperty = 'F', 00044 Object_GridCell = 'G', Object_Item = 'I', 00045 Object_MenuItem = 'M', Object_PaletteProperty = 'P', 00046 Object_Row = 'R', Object_Separator = 'S', Object_Spacer = 'Y', 00047 Object_SubAction = 'A', Object_SubLayout = 'L', 00048 Object_SubWidget = 'W', Object_TextProperty = 'T', 00049 Object_VariantProperty = 'V' }; 00050 00051 enum PaletteTag { Palette_End = '$', Palette_Active = 'A', 00052 Palette_Inactive = 'I', Palette_Disabled = 'D', 00053 Palette_Color = 'C', Palette_Pixmap = 'P' }; 00054 00055 enum IntroFlag { Intro_Pixmapinproject = 0x1 }; 00056 00057 enum FontFlag { Font_Family = 0x1, Font_PointSize = 0x2, Font_Bold = 0x4, 00058 Font_Italic = 0x8, Font_Underline = 0x10, 00059 Font_StrikeOut = 0x20 }; 00060 00061 enum ConnectionFlag { Connection_Language = 0x1, Connection_Sender = 0x2, 00062 Connection_Signal = 0x4, Connection_Receiver = 0x8, 00063 Connection_Slot = 0x10 }; 00064 00065 class UibStrTable 00066 { 00067 public: 00068 UibStrTable(); 00069 00070 inline int insertCString( const char *cstr ); 00071 inline int insertString( const QString& str ); 00072 inline void readBlock( QDataStream& in, int size ); 00073 00074 inline const char *asCString( int offset ) const; 00075 inline QString asString( int offset ) const; 00076 inline QByteArray block() const; 00077 00078 private: 00079 QCString table; 00080 QDataStream out; 00081 int start; 00082 }; 00083 00084 /* 00085 uic uses insertCString(), insertString(), and block(); 00086 QWidgetFactory uses readBlock(), asCString(), and asString(). By 00087 implementing these functions inline, we ensure that the binaries 00088 don't contain needless code. 00089 */ 00090 00091 inline int UibStrTable::insertCString( const char *cstr ) 00092 { 00093 if ( cstr == 0 || cstr[0] == 0 ) { 00094 return 0; 00095 } else { 00096 int nextPos = table.size(); 00097 int len = (int)strlen( cstr ); 00098 int i; 00099 for ( i = 0; i < nextPos - len; i++ ) { 00100 if ( memcmp(table.data() + i, cstr, len + 1) == 0 ) 00101 return i; 00102 } 00103 for ( i = 0; i < len + 1; i++ ) 00104 out << (Q_UINT8) cstr[i]; 00105 return nextPos; 00106 } 00107 } 00108 00109 inline int UibStrTable::insertString( const QString& str ) 00110 { 00111 if ( str.contains('\0') || str[0] == QChar(0x7f) ) { 00112 int nextPos = table.size(); 00113 out << (Q_UINT8) 0x7f; 00114 out << str; 00115 return nextPos; 00116 } else { 00117 return insertCString( str.utf8() ); 00118 } 00119 } 00120 00121 inline void UibStrTable::readBlock( QDataStream& in, int size ) 00122 { 00123 table.resize( start + size ); 00124 in.readRawBytes( table.data() + start, size ); 00125 } 00126 00127 inline QString UibStrTable::asString( int offset ) const 00128 { 00129 if ( table[offset] == 0x7f ) { 00130 QDataStream in( table, IO_ReadOnly ); 00131 in.device()->at( offset + 1 ); 00132 QString str; 00133 in >> str; 00134 return str; 00135 } else { 00136 return QString::fromUtf8( asCString(offset) ); 00137 } 00138 } 00139 00140 inline const char *UibStrTable::asCString( int offset ) const 00141 { 00142 return table.data() + offset; 00143 } 00144 00145 inline QByteArray UibStrTable::block() const 00146 { 00147 QByteArray block; 00148 block.duplicate( table.data() + start, table.size() - start ); 00149 return block; 00150 } 00151 00152 #endif