source: trunk/tools/designer/shared/uib.h@ 10

Last change on this file since 10 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#ifndef UIB_H
28#define UIB_H
29
30#include <qdatastream.h>
31
32const Q_UINT32 UibMagic = 0xb77c61d8;
33
34enum BlockTag { Block_End = '$', Block_Actions = 'A', Block_Buddies = 'B',
35 Block_Connections = 'C', Block_Functions = 'F',
36 Block_Images = 'G', Block_Intro = 'I', Block_Menubar = 'M',
37 Block_Slots = 'S', Block_Strings = 'Z', Block_Tabstops = 'T',
38 Block_Toolbars = 'O', Block_Variables = 'V',
39 Block_Widget = 'W' };
40
41enum ObjectTag { Object_End = '$', Object_ActionRef = 'X',
42 Object_Attribute = 'B', Object_Column = 'C',
43 Object_Event = 'E', Object_FontProperty = 'F',
44 Object_GridCell = 'G', Object_Item = 'I',
45 Object_MenuItem = 'M', Object_PaletteProperty = 'P',
46 Object_Row = 'R', Object_Separator = 'S', Object_Spacer = 'Y',
47 Object_SubAction = 'A', Object_SubLayout = 'L',
48 Object_SubWidget = 'W', Object_TextProperty = 'T',
49 Object_VariantProperty = 'V' };
50
51enum PaletteTag { Palette_End = '$', Palette_Active = 'A',
52 Palette_Inactive = 'I', Palette_Disabled = 'D',
53 Palette_Color = 'C', Palette_Pixmap = 'P' };
54
55enum IntroFlag { Intro_Pixmapinproject = 0x1 };
56
57enum FontFlag { Font_Family = 0x1, Font_PointSize = 0x2, Font_Bold = 0x4,
58 Font_Italic = 0x8, Font_Underline = 0x10,
59 Font_StrikeOut = 0x20 };
60
61enum ConnectionFlag { Connection_Language = 0x1, Connection_Sender = 0x2,
62 Connection_Signal = 0x4, Connection_Receiver = 0x8,
63 Connection_Slot = 0x10 };
64
65class UibStrTable
66{
67public:
68 UibStrTable();
69
70 inline int insertCString( const char *cstr );
71 inline int insertString( const QString& str );
72 inline void readBlock( QDataStream& in, int size );
73
74 inline const char *asCString( int offset ) const;
75 inline QString asString( int offset ) const;
76 inline QByteArray block() const;
77
78private:
79 QCString table;
80 QDataStream out;
81 int start;
82};
83
84/*
85 uic uses insertCString(), insertString(), and block();
86 QWidgetFactory uses readBlock(), asCString(), and asString(). By
87 implementing these functions inline, we ensure that the binaries
88 don't contain needless code.
89*/
90
91inline int UibStrTable::insertCString( const char *cstr )
92{
93 if ( cstr == 0 || cstr[0] == 0 ) {
94 return 0;
95 } else {
96 int nextPos = table.size();
97 int len = strlen( cstr );
98 int i;
99 for ( i = 0; i < nextPos - len; i++ ) {
100 if ( memcmp(table.data() + i, cstr, len + 1) == 0 )
101 return i;
102 }
103 for ( i = 0; i < len + 1; i++ )
104 out << (Q_UINT8) cstr[i];
105 return nextPos;
106 }
107}
108
109inline int UibStrTable::insertString( const QString& str )
110{
111 if ( str.contains('\0') || str[0] == QChar(0x7f) ) {
112 int nextPos = table.size();
113 out << (Q_UINT8) 0x7f;
114 out << str;
115 return nextPos;
116 } else {
117 return insertCString( str.utf8() );
118 }
119}
120
121inline void UibStrTable::readBlock( QDataStream& in, int size )
122{
123 table.resize( start + size );
124 in.readRawBytes( table.data() + start, size );
125}
126
127inline QString UibStrTable::asString( int offset ) const
128{
129 if ( table[offset] == 0x7f ) {
130 QDataStream in( table, IO_ReadOnly );
131 in.device()->at( offset + 1 );
132 QString str;
133 in >> str;
134 return str;
135 } else {
136 return QString::fromUtf8( asCString(offset) );
137 }
138}
139
140inline const char *UibStrTable::asCString( int offset ) const
141{
142 return table.data() + offset;
143}
144
145inline QByteArray UibStrTable::block() const
146{
147 QByteArray block;
148 block.duplicate( table.data() + start, table.size() - start );
149 return block;
150}
151
152#endif
Note: See TracBrowser for help on using the repository browser.