1 | /**********************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
|
---|
4 | **
|
---|
5 | ** This file is part of Qt Designer.
|
---|
6 | **
|
---|
7 | ** This file may be distributed and/or modified under the terms of the
|
---|
8 | ** GNU General Public License version 2 as published by the Free Software
|
---|
9 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
10 | ** packaging of this file.
|
---|
11 | **
|
---|
12 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
13 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
14 | ** Agreement provided with the Software.
|
---|
15 | **
|
---|
16 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
17 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
18 | **
|
---|
19 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
20 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
21 | ** information about Qt Commercial License Agreements.
|
---|
22 | **
|
---|
23 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
24 | ** not clear to you.
|
---|
25 | **
|
---|
26 | **********************************************************************/
|
---|
27 |
|
---|
28 | #include "rc2ui.h"
|
---|
29 | #include <qdir.h>
|
---|
30 |
|
---|
31 | /// some little helpers ///
|
---|
32 |
|
---|
33 | void RC2UI::wi()
|
---|
34 | {
|
---|
35 | for ( int i = 0; i < indentation; i++ )
|
---|
36 | *out << " ";
|
---|
37 | }
|
---|
38 |
|
---|
39 | void RC2UI::indent()
|
---|
40 | {
|
---|
41 | indentation++;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void RC2UI::undent()
|
---|
45 | {
|
---|
46 | indentation--;
|
---|
47 | }
|
---|
48 |
|
---|
49 | QString RC2UI::stripQM( const QString& string )
|
---|
50 | {
|
---|
51 | return string.mid( 1, string.length()-2 );
|
---|
52 | }
|
---|
53 |
|
---|
54 | QStringList RC2UI::splitStyles( const QString& styles, char sep )
|
---|
55 | {
|
---|
56 | QString s = styles;
|
---|
57 | QString style;
|
---|
58 | QStringList l;
|
---|
59 | while ( s.find( sep ) > -1 ) {
|
---|
60 | style = s.left( s.find( sep ) );
|
---|
61 | l << style.stripWhiteSpace();
|
---|
62 | s = s.right( s.length() - style.length() -1 );
|
---|
63 | }
|
---|
64 | if ( !s.isEmpty() )
|
---|
65 | l << s.stripWhiteSpace();
|
---|
66 | return l;
|
---|
67 | }
|
---|
68 |
|
---|
69 | QString RC2UI::parseNext( QString& arg, char sep )
|
---|
70 | {
|
---|
71 | QString next = arg.left( arg.find(sep) );
|
---|
72 | arg = arg.right( arg.length() - next.length() - 1 );
|
---|
73 | return next;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void RC2UI::writeClass( const QString& name )
|
---|
77 | {
|
---|
78 | wi(); *out << "<class>" << name << "</class>" << endl;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void RC2UI::writeCString( const QString& name, const QString& value )
|
---|
82 | {
|
---|
83 | wi(); *out << "<property>" << endl; indent();
|
---|
84 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
85 | wi(); *out << "<cstring>" << value << "</cstring>" << endl; undent();
|
---|
86 | wi(); *out << "</property>" << endl;
|
---|
87 | }
|
---|
88 |
|
---|
89 | void RC2UI::writeString( const QString& name, const QString& value )
|
---|
90 | {
|
---|
91 | wi(); *out << "<property>" << endl; indent();
|
---|
92 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
93 | wi(); *out << "<string>" << value << "</string>" << endl; undent();
|
---|
94 | wi(); *out << "</property>" << endl;
|
---|
95 | }
|
---|
96 |
|
---|
97 | void RC2UI::writeRect( const QString& name, int x, int y, int w, int h )
|
---|
98 | {
|
---|
99 | wi(); *out << "<property>" << endl; indent();
|
---|
100 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
101 | wi(); *out << "<rect>" << endl; indent();
|
---|
102 | wi(); *out << "<x>" << int(double(x)*1.5) << "</x>" << endl;
|
---|
103 | wi(); *out << "<y>" << int(double(y)*1.65) << "</y>" << endl;
|
---|
104 | wi(); *out << "<width>" << int(double(w)*1.5) << "</width>" << endl;
|
---|
105 | wi(); *out << "<height>" << int(double(h)*1.65) << "</height>" << endl; undent();
|
---|
106 | wi(); *out << "</rect>" << endl; undent();
|
---|
107 | wi(); *out << "</property>" << endl;
|
---|
108 | }
|
---|
109 |
|
---|
110 | void RC2UI::writeFont( const QString& family, int pointsize )
|
---|
111 | {
|
---|
112 | wi(); *out << "<property>" << endl; indent();
|
---|
113 | wi(); *out << "<name>font</name>" << endl;
|
---|
114 | wi(); *out << "<font>" << endl; indent();
|
---|
115 | wi(); *out << "<family>" << family << "</family>" << endl;
|
---|
116 | wi(); *out << "<pointsize>" << pointsize << "</pointsize>" << endl; undent();
|
---|
117 | wi(); *out << "</font>" << endl; undent();
|
---|
118 | wi(); *out << "</property>" << endl;
|
---|
119 | }
|
---|
120 |
|
---|
121 | void RC2UI::writeBool( const QString& name, bool value )
|
---|
122 | {
|
---|
123 | wi(); *out << "<property>" << endl; indent();
|
---|
124 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
125 | wi(); *out << "<bool>" << (value ? "true" : "false") << "</bool>" << endl; undent();
|
---|
126 | wi(); *out << "</property>" << endl;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void RC2UI::writeNumber( const QString& name, int value )
|
---|
130 | {
|
---|
131 | wi(); *out << "<property>" << endl; indent();
|
---|
132 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
133 | wi(); *out << "<number>" << value << "</number>" << endl; undent();
|
---|
134 | wi(); *out << "</property>" << endl;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void RC2UI::writeEnum( const QString& name, const QString& value )
|
---|
138 | {
|
---|
139 | wi(); *out << "<property>" << endl; indent();
|
---|
140 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
141 | wi(); *out << "<enum>" << value << "</enum>" << endl; undent();
|
---|
142 | wi(); *out << "</property>" << endl;
|
---|
143 | }
|
---|
144 |
|
---|
145 | void RC2UI::writeSet( const QString& name, const QString& value )
|
---|
146 | {
|
---|
147 | wi(); *out << "<property>" << endl; indent();
|
---|
148 | wi(); *out << "<name>" << name << "</name>" << endl;
|
---|
149 | wi(); *out << "<set>" << value << "</set>" << endl; undent();
|
---|
150 | wi(); *out << "</property>" << endl;
|
---|
151 | }
|
---|
152 |
|
---|
153 | void RC2UI::writeStyles( const QStringList styles, bool isFrame )
|
---|
154 | {
|
---|
155 | if ( isFrame ) {
|
---|
156 | bool defineFrame = FALSE;
|
---|
157 | QString shadow = "NoFrame";
|
---|
158 | QString shape = "StyledPanel";
|
---|
159 | int width = 2;
|
---|
160 | if ( styles.contains( "WS_EX_STATICEDGE" ) ) {
|
---|
161 | shadow = "Plain";
|
---|
162 | width = 1;
|
---|
163 | defineFrame = TRUE;
|
---|
164 | }
|
---|
165 | if ( styles.contains( "WS_EX_CLIENTEDGE" ) ) {
|
---|
166 | shadow = "Sunken";
|
---|
167 | defineFrame = TRUE;
|
---|
168 | }
|
---|
169 | if ( styles.contains( "WS_EX_DLGMODALFRAME" ) ) {
|
---|
170 | shadow = "Raised";
|
---|
171 | defineFrame = TRUE;
|
---|
172 | }
|
---|
173 | if ( !styles.contains( "WS_BORDER" ) ) {
|
---|
174 | shape = "NoFrame";
|
---|
175 | defineFrame = TRUE;
|
---|
176 | }
|
---|
177 |
|
---|
178 | if ( defineFrame ) {
|
---|
179 | writeEnum( "frameShape", "StyledPanel" );
|
---|
180 | writeEnum( "frameShadow", shadow );
|
---|
181 | writeNumber( "lineWidth", width );
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | if ( styles.contains("WS_DISABLED") )
|
---|
186 | writeBool("enabled", FALSE );
|
---|
187 | if ( styles.contains("WS_EX_ACCEPTFILES") )
|
---|
188 | writeBool("acceptDrops", TRUE );
|
---|
189 | if ( styles.contains("WS_EX_TRANSPARENT") )
|
---|
190 | writeBool("autoMask", TRUE );
|
---|
191 | if ( !styles.contains("WS_TABSTOP") )
|
---|
192 | writeEnum("focusPolicy", "NoFocus");
|
---|
193 | }
|
---|
194 |
|
---|
195 | /*!
|
---|
196 | Constructs a RC2UI object
|
---|
197 | */
|
---|
198 |
|
---|
199 | RC2UI::RC2UI( QTextStream* input )
|
---|
200 | : blockStart1( "/////////////////////////////////////////////////////////////////////////////" ),
|
---|
201 | blockStart2( "//" )
|
---|
202 | {
|
---|
203 | writeToFile = TRUE;
|
---|
204 | in = input;
|
---|
205 | indentation = 0;
|
---|
206 | out = 0;
|
---|
207 | }
|
---|
208 |
|
---|
209 | /*!
|
---|
210 | Destructs the RC2UI object
|
---|
211 | */
|
---|
212 |
|
---|
213 | RC2UI::~RC2UI()
|
---|
214 | {
|
---|
215 | }
|
---|
216 |
|
---|
217 | /*!
|
---|
218 | Parses the input stream and writes the output to files.
|
---|
219 | */
|
---|
220 |
|
---|
221 | bool RC2UI::parse()
|
---|
222 | {
|
---|
223 | while ( !in->eof() ) {
|
---|
224 | while ( line != blockStart1 && !in->eof() )
|
---|
225 | line = in->readLine();
|
---|
226 | if ( in->eof() )
|
---|
227 | return FALSE;
|
---|
228 | while ( line != blockStart2 && !in->eof() )
|
---|
229 | line = in->readLine();
|
---|
230 | if ( in->eof() )
|
---|
231 | return FALSE;
|
---|
232 |
|
---|
233 | line = in->readLine();
|
---|
234 |
|
---|
235 | if ( line.left(3) == "// " && !in->eof() ) {
|
---|
236 | QString type = line.right( line.length() - 3 );
|
---|
237 | if ( in->readLine() == "//" && in->readLine().isEmpty() && !in->eof() ) {
|
---|
238 | if ( type == "Dialog" ) {
|
---|
239 | if ( !makeDialog() )
|
---|
240 | return FALSE;
|
---|
241 | }
|
---|
242 | /*
|
---|
243 | else if ( type == "Bitmap" ) {
|
---|
244 | if ( !makeBitmap() )
|
---|
245 | return FALSE;
|
---|
246 | } else if ( type == "String Table" ) {
|
---|
247 | if ( !makeStringTable() )
|
---|
248 | return FALSE;
|
---|
249 | } else if ( type == "Accelerator" ) {
|
---|
250 | if ( !makeAccelerator() )
|
---|
251 | return FALSE;
|
---|
252 | } else if ( type == "Cursor" ) {
|
---|
253 | if ( !makeCursor() )
|
---|
254 | return FALSE;
|
---|
255 | } else if ( type == "HTML" ) {
|
---|
256 | if ( !makeHTML() )
|
---|
257 | return FALSE;
|
---|
258 | } else if ( type == "Icon" ) {
|
---|
259 | if ( !makeIcon() )
|
---|
260 | return FALSE;
|
---|
261 | } else if ( type == "Version" ) {
|
---|
262 | if ( !makeVersion() )
|
---|
263 | return FALSE;
|
---|
264 | }
|
---|
265 | */
|
---|
266 | }
|
---|
267 | } else
|
---|
268 | return FALSE;
|
---|
269 | }
|
---|
270 | return TRUE;
|
---|
271 | }
|
---|
272 |
|
---|
273 | /*!
|
---|
274 | Parses the input stream and writes the output in \a get.
|
---|
275 | */
|
---|
276 |
|
---|
277 | bool RC2UI::parse( QStringList& get )
|
---|
278 | {
|
---|
279 | writeToFile = FALSE;
|
---|
280 | bool result = parse();
|
---|
281 | get = target;
|
---|
282 | return result;
|
---|
283 | }
|
---|
284 |
|
---|
285 | /*!
|
---|
286 | Retrieves a unique name starting with \a start
|
---|
287 | */
|
---|
288 | QString RC2UI::useName( const QString& start )
|
---|
289 | {
|
---|
290 | QString name = start;
|
---|
291 | int id = 1;
|
---|
292 |
|
---|
293 | while ( usedNames.contains( name ) ) {
|
---|
294 | name = start + QString( "%1" ).arg( id );
|
---|
295 | id++;
|
---|
296 | }
|
---|
297 |
|
---|
298 | usedNames.append(name);
|
---|
299 |
|
---|
300 | return name;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | /*!
|
---|
305 | Builds a number of UI dialog out of the current input stream
|
---|
306 | */
|
---|
307 |
|
---|
308 | bool RC2UI::makeDialog()
|
---|
309 | {
|
---|
310 | line = in->readLine();
|
---|
311 | do {
|
---|
312 | QFile fileOut;
|
---|
313 | QString buffer;
|
---|
314 | int count;
|
---|
315 | QCString className;
|
---|
316 | uint x, y, w, h;
|
---|
317 | uint endDesc;
|
---|
318 | bool space = FALSE;
|
---|
319 | for ( endDesc = 0; endDesc < line.length() ; endDesc++ ) {
|
---|
320 | char c = (QChar)line.at(endDesc);
|
---|
321 | if ( space && (c >= '0') && (c <= '9') )
|
---|
322 | break;
|
---|
323 | space = c==' ';
|
---|
324 | }
|
---|
325 |
|
---|
326 | QString desc = line.left(endDesc-1);
|
---|
327 | line = line.right( line.length() - endDesc );
|
---|
328 |
|
---|
329 | className = parseNext( desc, ' ' );
|
---|
330 |
|
---|
331 | count = sscanf( line, "%u, %u, %u, %u", &x, &y, &w, &h );
|
---|
332 |
|
---|
333 | if ( !count && count == EOF )
|
---|
334 | return FALSE;
|
---|
335 |
|
---|
336 | char property[256];
|
---|
337 | QStringList styles;
|
---|
338 | QStringList extendedStyles;
|
---|
339 | QString caption = "";
|
---|
340 | QString baseClass = "";
|
---|
341 | QString widgetType;
|
---|
342 | QString widgetName;
|
---|
343 | QString arguments;
|
---|
344 | int pointsize = 10;
|
---|
345 | QString fontname;
|
---|
346 | do {
|
---|
347 | line = "";
|
---|
348 | do {
|
---|
349 | if ( in->eof() )
|
---|
350 | return TRUE;
|
---|
351 | line += in->readLine();
|
---|
352 | } while ( line[(int)line.length()-1] == '|' ||
|
---|
353 | line[(int)line.length()-1] == ',' );
|
---|
354 | count = sscanf( line, "%s", property );
|
---|
355 | line = line.right( line.length() - line.find(" ") -1 );
|
---|
356 | if ( QString(property) == "STYLE" ) {
|
---|
357 | styles = splitStyles(line);
|
---|
358 | if ( styles.contains( "WS_CAPTION" ) )
|
---|
359 | baseClass = "QDialog";
|
---|
360 | else
|
---|
361 | baseClass = "QWidget";
|
---|
362 | } else if ( QString(property) == "CAPTION" ) {
|
---|
363 | caption = stripQM( line );
|
---|
364 | } else if ( QString(property) == "FONT" ) {
|
---|
365 | QString pt = line.left( line.find(",") );
|
---|
366 | pointsize = pt.toInt();
|
---|
367 | fontname = stripQM(line.right( line.length() - line.find(",") - 2 ));
|
---|
368 | }
|
---|
369 | } while ( line != "BEGIN" );
|
---|
370 |
|
---|
371 | if ( writeToFile ) {
|
---|
372 |
|
---|
373 | QString outputFile = QString(className) + ".ui";
|
---|
374 | fileOut.setName( outputFile );
|
---|
375 | if (!fileOut.open( IO_WriteOnly ) )
|
---|
376 | qFatal( "rc2ui: Could not open output file '%s'", outputFile.latin1() );
|
---|
377 | out = new QTextStream( &fileOut );
|
---|
378 | targetFiles.append( outputFile );
|
---|
379 | } else {
|
---|
380 | out = new QTextStream( &buffer, IO_WriteOnly );
|
---|
381 | }
|
---|
382 |
|
---|
383 | *out << "<!DOCTYPE UI><UI>" << endl;
|
---|
384 | writeClass( className );
|
---|
385 | wi(); *out << "<widget>"<< endl; indent();
|
---|
386 | writeClass( baseClass );
|
---|
387 | writeCString( "name", className );
|
---|
388 | writeRect( "geometry", x, y, w, h );
|
---|
389 | writeString( "caption", caption );
|
---|
390 | writeFont( fontname, pointsize );
|
---|
391 |
|
---|
392 | do {
|
---|
393 | if ( in->eof() )
|
---|
394 | return TRUE;
|
---|
395 |
|
---|
396 | line = in->readLine().stripWhiteSpace();
|
---|
397 | if ( line == "END" )
|
---|
398 | continue;
|
---|
399 |
|
---|
400 | widgetType = parseNext(line, ' ');
|
---|
401 | arguments = line.stripWhiteSpace();
|
---|
402 | while ( arguments[(int)arguments.length()-1] == ',' ||
|
---|
403 | arguments[(int)arguments.length()-1] == '|' )
|
---|
404 | arguments += " "+in->readLine().stripWhiteSpace();
|
---|
405 |
|
---|
406 | wi(); *out << "<widget>" << endl; indent();
|
---|
407 |
|
---|
408 | WidgetType ID = IDUnknown;
|
---|
409 | QString controlType;
|
---|
410 | QString widgetID;
|
---|
411 | QString widgetText;
|
---|
412 | bool hasText = FALSE;
|
---|
413 | bool isControl = FALSE;
|
---|
414 | bool isFrame = FALSE;
|
---|
415 |
|
---|
416 | if ( widgetType == "PUSHBUTTON" ) {
|
---|
417 | ID = IDPushButton;
|
---|
418 | hasText = TRUE;
|
---|
419 | } else if ( widgetType == "DEFPUSHBUTTON" ) {
|
---|
420 | ID = IDPushButton;
|
---|
421 | hasText = TRUE;
|
---|
422 | } else if ( widgetType == "LTEXT" ) {
|
---|
423 | ID = IDLabel;
|
---|
424 | hasText = TRUE;
|
---|
425 | } else if ( widgetType == "CTEXT" ) {
|
---|
426 | ID = IDLabel;
|
---|
427 | hasText = TRUE;
|
---|
428 | } else if ( widgetType == "RTEXT" ) {
|
---|
429 | ID = IDLabel;
|
---|
430 | hasText = TRUE;
|
---|
431 | } else if ( widgetType == "EDITTEXT" ) {
|
---|
432 | ID = IDLineEdit;
|
---|
433 | } else if ( widgetType == "GROUPBOX" ) {
|
---|
434 | ID = IDGroupBox;
|
---|
435 | hasText = TRUE;
|
---|
436 | } else if ( widgetType == "COMBOBOX" ) {
|
---|
437 | ID = IDComboBox;
|
---|
438 | } else if ( widgetType == "LISTBOX" ) {
|
---|
439 | ID = IDListBox;
|
---|
440 | } else if ( widgetType == "SCROLLBAR" ) {
|
---|
441 | ID = IDScrollBar;
|
---|
442 | } else if ( widgetType == "CHECKBOX" ) {
|
---|
443 | ID = IDCheckBox;
|
---|
444 | hasText = TRUE;
|
---|
445 | } else if ( widgetType == "RADIOBUTTON" ) {
|
---|
446 | ID = IDRadioButton;
|
---|
447 | hasText = TRUE;
|
---|
448 | } else if ( widgetType == "CONTROL" ) {
|
---|
449 | isControl = TRUE;
|
---|
450 | widgetText = stripQM(parseNext( arguments ));
|
---|
451 | widgetID = parseNext( arguments );
|
---|
452 | controlType = stripQM(parseNext( arguments ));
|
---|
453 | styles = splitStyles(parseNext( arguments ));
|
---|
454 |
|
---|
455 | if ( controlType == "Static" ) {
|
---|
456 | ID = IDLabel;
|
---|
457 | } else if ( controlType == "Button" ) {
|
---|
458 | if ( styles.contains("BS_AUTOCHECKBOX") ||
|
---|
459 | styles.contains("BS_3STATE") )
|
---|
460 | ID = IDCheckBox;
|
---|
461 | else if ( styles.contains("BS_AUTORADIOBUTTON") )
|
---|
462 | ID = IDRadioButton;
|
---|
463 | } else if ( controlType == "msctls_updown32" ) {
|
---|
464 | ID = IDSpinBox;
|
---|
465 | } else if ( controlType == "msctls_progress32" ) {
|
---|
466 | ID = IDProgressBar;
|
---|
467 | } else if ( controlType == "msctls_trackbar32" ) {
|
---|
468 | ID = IDSlider;
|
---|
469 | } else if ( controlType == "SysListView32" ) {
|
---|
470 | ID = IDIconView;
|
---|
471 | } else if ( controlType == "SysTreeView32" ) {
|
---|
472 | ID = IDListView;
|
---|
473 | } else if ( controlType == "SysTabControl32" ) {
|
---|
474 | ID = IDTabWidget;
|
---|
475 | } else if ( controlType == "SysAnimate32" ) {
|
---|
476 | ID = IDLabel;
|
---|
477 | } else if ( controlType == "RICHEDIT" ) {
|
---|
478 | ID = IDMultiLineEdit;
|
---|
479 | } else if ( controlType == "ComboBoxEx32" ) {
|
---|
480 | ID = IDComboBox;
|
---|
481 | } else if ( controlType == "" ) {
|
---|
482 | ID = IDCustom;
|
---|
483 | } else {
|
---|
484 | ID = IDUnknown;
|
---|
485 | }
|
---|
486 | } else
|
---|
487 | ID = IDUnknown;
|
---|
488 |
|
---|
489 | if ( hasText )
|
---|
490 | widgetText = stripQM(parseNext( arguments ));
|
---|
491 |
|
---|
492 | if ( isControl ) {
|
---|
493 | x = parseNext( arguments ).toInt();
|
---|
494 | y = parseNext( arguments ).toInt();
|
---|
495 | w = parseNext( arguments ).toInt();
|
---|
496 | h = parseNext( arguments ).toInt();
|
---|
497 | } else {
|
---|
498 | widgetID = parseNext( arguments );
|
---|
499 | x = parseNext( arguments ).toInt();
|
---|
500 | y = parseNext( arguments ).toInt();
|
---|
501 | w = parseNext( arguments ).toInt();
|
---|
502 | h = parseNext( arguments ).toInt();
|
---|
503 | styles.clear();
|
---|
504 | }
|
---|
505 |
|
---|
506 | do {
|
---|
507 | extendedStyles = splitStyles(parseNext( arguments ));
|
---|
508 | for ( uint i = 0; i < extendedStyles.count(); i++ )
|
---|
509 | styles << (*extendedStyles.at(i));
|
---|
510 | } while ( arguments.find(',') > -1 );
|
---|
511 |
|
---|
512 | switch ( ID ) {
|
---|
513 | case IDWidget:
|
---|
514 | break;
|
---|
515 | case IDPushButton:
|
---|
516 | {
|
---|
517 | writeClass("QPushButton");
|
---|
518 | writeCString( "name", useName("PushButton_"+widgetID) );
|
---|
519 | writeRect( "geometry", x, y, w, h );
|
---|
520 | writeString( "text", widgetText );
|
---|
521 | if ( widgetType == "DEFPUSHBUTTON" )
|
---|
522 | writeBool( "default", TRUE );
|
---|
523 | }
|
---|
524 | break;
|
---|
525 | case IDLabel:
|
---|
526 | {
|
---|
527 | isFrame = TRUE,
|
---|
528 | writeClass("QLabel");
|
---|
529 | writeCString( "name", useName("Label_"+widgetID) );
|
---|
530 | writeRect( "geometry", x,y,w,h );
|
---|
531 | writeString( "text", widgetText );
|
---|
532 | QString align;
|
---|
533 | if ( !styles.contains("SS_CENTERIMAGE") )
|
---|
534 | align += "|AlignTop";
|
---|
535 | else
|
---|
536 | align += "|AlignVCenter";
|
---|
537 | if ( widgetType == "LTEXT" ) {
|
---|
538 | align += "|AlignLeft";
|
---|
539 | } else if ( widgetType == "CTEXT") {
|
---|
540 | align += "|AlignHCenter";
|
---|
541 | } else if ( widgetType == "RTEXT") {
|
---|
542 | align += "|AlignRight";
|
---|
543 | }
|
---|
544 | writeSet("alignment", align );
|
---|
545 | }
|
---|
546 | break;
|
---|
547 | case IDCheckBox:
|
---|
548 | {
|
---|
549 | writeClass("QCheckBox");
|
---|
550 | writeCString("name", useName("CheckBox_"+widgetID) );
|
---|
551 | writeRect("geometry", x,y,w,h);
|
---|
552 | writeString("text", widgetText );
|
---|
553 | if ( styles.contains( "BS_3STATE" ) )
|
---|
554 | writeBool( "tristate", TRUE );
|
---|
555 | }
|
---|
556 | break;
|
---|
557 | case IDRadioButton:
|
---|
558 | {
|
---|
559 | writeClass("QRadioButton");
|
---|
560 | writeCString("name", useName("RadioButton_"+widgetID) );
|
---|
561 | writeRect("geometry", x,y,w,h);
|
---|
562 | writeString("text", widgetText );
|
---|
563 | }
|
---|
564 | break;
|
---|
565 | case IDGroupBox:
|
---|
566 | {
|
---|
567 | isFrame = TRUE;
|
---|
568 | writeClass("QGroupBox");
|
---|
569 | writeCString( "name", useName("GroupBox_"+widgetID) );
|
---|
570 | writeRect( "geometry", x,y,w,h );
|
---|
571 | writeString( "title", widgetText );
|
---|
572 | if ( !styles.contains( "WS_BORDER" ) )
|
---|
573 | styles.append( "WS_BORDER" );
|
---|
574 | }
|
---|
575 | break;
|
---|
576 | case IDLineEdit:
|
---|
577 | {
|
---|
578 | if ( !styles.contains("ES_MULTILINE") ) {
|
---|
579 | writeClass("QLineEdit");
|
---|
580 | writeCString( "name", useName("LineEdit_"+widgetID) );
|
---|
581 | } else {
|
---|
582 | writeClass("QMultiLineEdit");
|
---|
583 | writeCString( "name", useName("MultiLineEdit_"+widgetID) );
|
---|
584 | }
|
---|
585 | writeRect( "geometry", x,y,w,h );
|
---|
586 | QString align = "AlignTop";
|
---|
587 | if ( styles.contains("ES_CENTER") )
|
---|
588 | align+="|AlignHCenter";
|
---|
589 | else if ( styles.contains("ES_RIGHT") )
|
---|
590 | align+="|AlignRight";
|
---|
591 | else
|
---|
592 | align+="|AlignLeft";
|
---|
593 | writeSet("alignment", align);
|
---|
594 | }
|
---|
595 | break;
|
---|
596 | case IDMultiLineEdit:
|
---|
597 | {
|
---|
598 | writeClass("QMultiLineEdit");
|
---|
599 | writeCString("name", useName("MultiLineEdit_"+widgetID) );
|
---|
600 | writeRect("geometry", x,y,w,h );
|
---|
601 | }
|
---|
602 | break;
|
---|
603 | case IDIconView:
|
---|
604 | {
|
---|
605 | isFrame = TRUE;
|
---|
606 | writeClass("QIconView");
|
---|
607 | writeCString("name", useName("IconView_"+widgetID) );
|
---|
608 | writeRect("geometry", x,y,w,h );
|
---|
609 | if ( !styles.contains( "LVS_SINGLESEL" ) )
|
---|
610 | writeEnum( "selectionMode", "Extended" );
|
---|
611 | if ( styles.contains( "LVS_NOLABELWRAP" ) )
|
---|
612 | writeBool("wordWrapIconText", FALSE );
|
---|
613 | }
|
---|
614 | break;
|
---|
615 | case IDListView:
|
---|
616 | {
|
---|
617 | isFrame = TRUE;
|
---|
618 | writeClass("QListView");
|
---|
619 | writeCString("name", useName("ListView_"+widgetID) );
|
---|
620 | writeRect("geometry", x,y,w,h );
|
---|
621 | if ( styles.contains( "TVS_LINESATROOT" ) )
|
---|
622 | writeBool( "rootIsDecorated", TRUE );
|
---|
623 | if ( styles.contains( "TVS_FULLROWSELECT" ) )
|
---|
624 | writeBool( "allColumnsShowFocus", TRUE );
|
---|
625 | }
|
---|
626 | break;
|
---|
627 | case IDProgressBar:
|
---|
628 | {
|
---|
629 | isFrame = TRUE;
|
---|
630 | writeClass("QProgressBar");
|
---|
631 | writeCString("name", useName("ProgressBar_"+widgetID) );
|
---|
632 | writeRect("geometry", x,y,w,h );
|
---|
633 | if ( styles.contains("TBS_VERT") )
|
---|
634 | writeEnum("orientation", "Vertical");
|
---|
635 | else
|
---|
636 | writeEnum("orientation", "Horizontal");
|
---|
637 | }
|
---|
638 | break;
|
---|
639 | case IDTabWidget:
|
---|
640 | {
|
---|
641 | writeClass("QTabWidget");
|
---|
642 | writeCString("name", useName("TabWidget_"+widgetID) );
|
---|
643 | writeRect("geometry", x,y,w,h );
|
---|
644 | wi(); *out << "<widget>" << endl; indent();
|
---|
645 | writeClass("QWidget");
|
---|
646 | wi(); *out << "<attribute>" << endl; indent();
|
---|
647 | wi(); *out << "<name>title</name>" << endl;
|
---|
648 | wi(); *out << "<string>Tab1</string>" << endl; undent();
|
---|
649 | wi(); *out << "</attribute>" << endl; undent();
|
---|
650 | wi(); *out << "</widget>" << endl;
|
---|
651 | }
|
---|
652 | break;
|
---|
653 | case IDSpinBox:
|
---|
654 | {
|
---|
655 | isFrame = TRUE;
|
---|
656 | writeClass("QSpinBox");
|
---|
657 | writeCString("name", useName("SpinBox_"+widgetID) );
|
---|
658 | writeRect("geometry", x,y,w,h);
|
---|
659 | }
|
---|
660 | break;
|
---|
661 | case IDSlider:
|
---|
662 | {
|
---|
663 | writeClass("QSlider");
|
---|
664 | writeCString("name", useName("Slider_"+widgetID) );
|
---|
665 | writeRect("geometry", x,y,w,h );
|
---|
666 | if ( styles.contains("TBS_VERT") )
|
---|
667 | writeEnum("orientation", "Vertical");
|
---|
668 | else
|
---|
669 | writeEnum("orientation", "Horizontal");
|
---|
670 | if ( !styles.contains("TBS_NOTICKS") )
|
---|
671 | writeEnum("tickmarks", "Left" );
|
---|
672 | }
|
---|
673 | break;
|
---|
674 | case IDComboBox:
|
---|
675 | {
|
---|
676 | writeClass("QComboBox");
|
---|
677 | writeCString("name", useName("ComboBox_"+widgetID) );
|
---|
678 | if ( isControl )
|
---|
679 | writeRect( "geometry", x,y,w,14 );
|
---|
680 | else
|
---|
681 | writeRect( "geometry", x,y,w,h );
|
---|
682 | }
|
---|
683 | break;
|
---|
684 | case IDListBox:
|
---|
685 | {
|
---|
686 | isFrame = TRUE;
|
---|
687 | writeClass("QListBox");
|
---|
688 | writeCString("name", useName("ListBox_"+widgetID) );
|
---|
689 | writeRect( "geometry", x,y,w,h );
|
---|
690 | if ( styles.contains("WS_HSCROLL") )
|
---|
691 | writeEnum("hScrollBarMode", "Auto");
|
---|
692 | else
|
---|
693 | writeEnum("hScrollBarMode", "AlwaysOff");
|
---|
694 | if ( styles.contains("WS_VSCROLL") )
|
---|
695 | writeEnum("vScrollBarMode", "Auto");
|
---|
696 | else
|
---|
697 | writeEnum("vScrollBarMode", "AlwaysOff");
|
---|
698 | if ( styles.contains("LBS_EXTENDEDSEL") )
|
---|
699 | writeEnum("selectionMode", "Extended");
|
---|
700 | else if ( styles.contains("LBS_MULTIPLESEL") )
|
---|
701 | writeEnum("selectionMode", "Multi");
|
---|
702 | else if ( styles.contains("LBS_NOSEL") )
|
---|
703 | writeEnum("selectionMode", "NoSelection");
|
---|
704 | else
|
---|
705 | writeEnum("selectionMode", "Single");
|
---|
706 | if ( !styles.contains( "NO WS_BORDER" ) )
|
---|
707 | styles.append( "WS_BORDER" );
|
---|
708 | }
|
---|
709 | break;
|
---|
710 | case IDScrollBar:
|
---|
711 | {
|
---|
712 | writeClass("QScrollBar");
|
---|
713 | writeCString("name", useName("ScrollBar_"+widgetID) );
|
---|
714 | writeRect("geometry", x,y,w,h );
|
---|
715 | if ( styles.contains("SBS_VERT") )
|
---|
716 | writeEnum("orientation", "Vertical");
|
---|
717 | else
|
---|
718 | writeEnum("orientation", "Horizontal");
|
---|
719 | }
|
---|
720 | break;
|
---|
721 | case IDCustom:
|
---|
722 | {
|
---|
723 | writeClass("QLabel");
|
---|
724 | writeCString("name", useName("Custom_"+widgetID) );
|
---|
725 | writeRect("geometry", x,y,w,h );
|
---|
726 | writeString("text", "Create a custom widget and place it here." );
|
---|
727 | }
|
---|
728 | default:
|
---|
729 | {
|
---|
730 | writeClass("QLabel");
|
---|
731 | writeCString("name", useName("Unknown_"+widgetID) );
|
---|
732 | writeRect("geometry", x,y,w,h );
|
---|
733 | writeString("text", QString("No support for %1.").arg(controlType) );
|
---|
734 | }
|
---|
735 | break;
|
---|
736 | }
|
---|
737 |
|
---|
738 | writeStyles( styles, isFrame );
|
---|
739 |
|
---|
740 | styles.clear();
|
---|
741 |
|
---|
742 | undent();
|
---|
743 | wi(); *out << "</widget>" << endl;
|
---|
744 | } while ( line != "END" );
|
---|
745 |
|
---|
746 | undent();
|
---|
747 | wi(); *out << "</widget>" << endl;
|
---|
748 | *out << "</UI>" << endl;
|
---|
749 |
|
---|
750 | do {
|
---|
751 | line = in->readLine();
|
---|
752 | } while ( line.isEmpty() );
|
---|
753 |
|
---|
754 | if ( !writeToFile )
|
---|
755 | target.append( buffer.copy() );
|
---|
756 |
|
---|
757 | if (out) {
|
---|
758 | delete out;
|
---|
759 | out = 0;
|
---|
760 | }
|
---|
761 | fileOut.close();
|
---|
762 |
|
---|
763 | } while ( line != blockStart1 );
|
---|
764 |
|
---|
765 | return TRUE;
|
---|
766 | }
|
---|
767 |
|
---|
768 | /*! Not yet implemented
|
---|
769 | */
|
---|
770 |
|
---|
771 | bool RC2UI::makeBitmap()
|
---|
772 | {
|
---|
773 | return TRUE;
|
---|
774 | }
|
---|
775 |
|
---|
776 | /*! Not yet implemented
|
---|
777 | */
|
---|
778 |
|
---|
779 | bool RC2UI::makeAccelerator()
|
---|
780 | {
|
---|
781 | return TRUE;
|
---|
782 | }
|
---|
783 |
|
---|
784 | /*! Not yet implemented
|
---|
785 | */
|
---|
786 |
|
---|
787 | bool RC2UI::makeCursor()
|
---|
788 | {
|
---|
789 | return TRUE;
|
---|
790 | }
|
---|
791 |
|
---|
792 | /*! Not yet implemented
|
---|
793 | */
|
---|
794 |
|
---|
795 | bool RC2UI::makeHTML()
|
---|
796 | {
|
---|
797 | return TRUE;
|
---|
798 | }
|
---|
799 |
|
---|
800 | /*! Not yet implemented
|
---|
801 | */
|
---|
802 |
|
---|
803 | bool RC2UI::makeIcon()
|
---|
804 | {
|
---|
805 | return TRUE;
|
---|
806 | }
|
---|
807 |
|
---|
808 | /*!
|
---|
809 | Writes a stringtable from the input stream to a c++ header file.
|
---|
810 | All strings are assigned using QT_TR_NOOP to enable easy translation.
|
---|
811 | */
|
---|
812 |
|
---|
813 | bool RC2UI::makeStringTable()
|
---|
814 | {
|
---|
815 | if ( !writeToFile )
|
---|
816 | return TRUE;
|
---|
817 |
|
---|
818 | QFile fileOut;
|
---|
819 | line = in->readLine();
|
---|
820 | do {
|
---|
821 | char stringtable[256];
|
---|
822 | char discard[12];
|
---|
823 | sscanf( line, "%s %s", stringtable, discard );
|
---|
824 | if ( QString(stringtable) != "STRINGTABLE" )
|
---|
825 | return TRUE;
|
---|
826 | do {
|
---|
827 | line = in->readLine();
|
---|
828 | } while ( line != "BEGIN" );
|
---|
829 |
|
---|
830 | QString outputFile = QString(stringtable).lower() + ".h";
|
---|
831 | if (outputFile ) {
|
---|
832 | fileOut.setName( outputFile );
|
---|
833 | if (!fileOut.open( IO_WriteOnly ) )
|
---|
834 | qFatal( "rc2ui: Could not open output file '%s'", outputFile.latin1() );
|
---|
835 | out = new QTextStream( &fileOut );
|
---|
836 | }
|
---|
837 |
|
---|
838 | *out << "#ifndef STRINGTABLE_H" << endl;
|
---|
839 | *out << "#define STRINGTABLE_H" << endl;
|
---|
840 | *out << endl;
|
---|
841 | *out << "#include <qstring.h>" << endl;
|
---|
842 | *out << "#include <qobject.h>" << endl;
|
---|
843 | *out << endl;
|
---|
844 |
|
---|
845 | QString ID;
|
---|
846 | QString value;
|
---|
847 | do {
|
---|
848 | line = in->readLine().stripWhiteSpace();
|
---|
849 | if ( line == "END" )
|
---|
850 | continue;
|
---|
851 |
|
---|
852 | ID = parseNext(line, ' ');
|
---|
853 | value = parseNext(line).stripWhiteSpace();
|
---|
854 |
|
---|
855 | *out << "static const QString " << ID << "= QT_TR_NOOP(" << value << ");" << endl;
|
---|
856 |
|
---|
857 | } while ( line != "END" );
|
---|
858 |
|
---|
859 | *out << endl;
|
---|
860 | *out << "#endif // STRINGTABLE_H" << endl;
|
---|
861 |
|
---|
862 | do {
|
---|
863 | line = in->readLine();
|
---|
864 | } while ( line.isEmpty() );
|
---|
865 |
|
---|
866 | if ( out ) {
|
---|
867 | delete out;
|
---|
868 | out = 0;
|
---|
869 | }
|
---|
870 | } while ( line != blockStart1 );
|
---|
871 |
|
---|
872 | return TRUE;
|
---|
873 | }
|
---|
874 |
|
---|
875 | /*! Not yet implemented
|
---|
876 | */
|
---|
877 |
|
---|
878 | bool RC2UI::makeVersion()
|
---|
879 | {
|
---|
880 | return TRUE;
|
---|
881 | }
|
---|