1 | /**********************************************************************
|
---|
2 | **
|
---|
3 | ** Converts a Glade .glade file into a .ui file.
|
---|
4 | **
|
---|
5 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
6 | **
|
---|
7 | ** This file is part of Qt Designer.
|
---|
8 | **
|
---|
9 | ** This file may be distributed and/or modified under the terms of the
|
---|
10 | ** GNU General Public License version 2 as published by the Free Software
|
---|
11 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
12 | ** packaging of this file.
|
---|
13 | **
|
---|
14 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
15 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
16 | ** Agreement provided with the Software.
|
---|
17 | **
|
---|
18 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
19 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
20 | **
|
---|
21 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
22 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
23 | ** information about Qt Commercial License Agreements.
|
---|
24 | **
|
---|
25 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
26 | ** not clear to you.
|
---|
27 | **
|
---|
28 | **********************************************************************/
|
---|
29 |
|
---|
30 | #include "glade2ui.h"
|
---|
31 |
|
---|
32 | #include <qapplication.h>
|
---|
33 | #include <qfile.h>
|
---|
34 | #include <qimage.h>
|
---|
35 | #include <qprogressdialog.h>
|
---|
36 | #include <qmessagebox.h>
|
---|
37 | #include <qrect.h>
|
---|
38 | #include <qregexp.h>
|
---|
39 | #include <qsizepolicy.h>
|
---|
40 |
|
---|
41 | #include <ctype.h>
|
---|
42 |
|
---|
43 | static const struct {
|
---|
44 | const char *gtkName;
|
---|
45 | const char *qtName;
|
---|
46 | } classNames[] = {
|
---|
47 | { "Custom", "Custom" },
|
---|
48 | { "GnomeAbout", "QDialog" },
|
---|
49 | { "GnomeApp", "QMainWindow" },
|
---|
50 | { "GnomeCanvas", "QLabel" },
|
---|
51 | { "GnomeColorPicker", "QComboBox" },
|
---|
52 | { "GnomeDateEdit", "QDateTimeEdit" },
|
---|
53 | { "GnomeDialog", "QDialog" },
|
---|
54 | { "GnomeFontPicker", "QComboBox" },
|
---|
55 | { "GnomeIconSelection", "QIconView" },
|
---|
56 | { "GnomePixmap", "QLabel" },
|
---|
57 | { "GnomePropertyBox", "QDialog" },
|
---|
58 | { "GtkAccelLabel", "QLabel" },
|
---|
59 | { "GtkAspectFrame", "QFrame" },
|
---|
60 | { "GtkButton", "QPushButton" },
|
---|
61 | { "GtkCList", "QListView" },
|
---|
62 | { "GtkCTree", "QListView" },
|
---|
63 | { "GtkCheckButton", "QCheckBox" },
|
---|
64 | { "GtkCombo", "QComboBox" },
|
---|
65 | { "GtkDial", "QDial" },
|
---|
66 | { "GtkDialog", "QDialog" },
|
---|
67 | { "GtkEntry", "QLineEdit" },
|
---|
68 | { "GtkFixed", "QLayoutWidget" },
|
---|
69 | { "GtkFrame", "QFrame" },
|
---|
70 | { "GtkHPaned", "QSplitter" },
|
---|
71 | { "GtkHScale", "QSlider" },
|
---|
72 | { "GtkHScrollbar", "QScrollBar" },
|
---|
73 | { "GtkHSeparator", "Line" },
|
---|
74 | { "GtkHandleBox", "QFrame" },
|
---|
75 | { "GtkImage", "QLabel" },
|
---|
76 | { "GtkLabel", "QLabel" },
|
---|
77 | { "GtkList", "QListBox" },
|
---|
78 | { "GtkNotebook", "QTabWidget" },
|
---|
79 | { "GtkOptionMenu", "QComboBox" },
|
---|
80 | { "GtkPixmap", "QLabel" },
|
---|
81 | { "GtkPreview", "QLabel" },
|
---|
82 | { "GtkProgressBar", "QProgressBar" },
|
---|
83 | { "GtkRadioButton", "QRadioButton" },
|
---|
84 | { "GtkSpinButton", "QSpinBox" },
|
---|
85 | { "GtkStatusbar", "QStatusBar" },
|
---|
86 | { "GtkText", "QTextEdit" },
|
---|
87 | { "GtkToggleButton", "QPushButton" },
|
---|
88 | { "GtkTree", "QListView" },
|
---|
89 | { "GtkVPaned", "QSplitter" },
|
---|
90 | { "GtkVScale", "QSlider" },
|
---|
91 | { "GtkVScrollbar", "QScrollBar" },
|
---|
92 | { "GtkVSeparator", "Line" },
|
---|
93 | { "Placeholder", "QLabel" },
|
---|
94 | { 0, 0 }
|
---|
95 | };
|
---|
96 |
|
---|
97 | static const struct {
|
---|
98 | const char *name;
|
---|
99 | const char *menuText;
|
---|
100 | } stockMenuItems[] = {
|
---|
101 | { "ABOUT", "&About" },
|
---|
102 | { "CLEAR", "C&lear" },
|
---|
103 | { "CLOSE", "&Close" },
|
---|
104 | { "CLOSE_WINDOW", "&Close This Window" },
|
---|
105 | { "COPY", "&Copy" },
|
---|
106 | { "CUT", "C&ut" },
|
---|
107 | { "END_GAME", "&End Game" },
|
---|
108 | { "EXIT", "E&xit" },
|
---|
109 | { "FIND", "&Find..." },
|
---|
110 | { "FIND_AGAIN", "Find &Again" },
|
---|
111 | { "HINT", "&Hint" },
|
---|
112 | { "NEW", "&New" },
|
---|
113 | { "NEW_GAME", "&New Game" },
|
---|
114 | { "NEW_WINDOW", "Create New &Window" },
|
---|
115 | { "OPEN", "&Open..." },
|
---|
116 | { "PASTE", "&Paste" },
|
---|
117 | { "PAUSE_GAME", "&Pause Game" },
|
---|
118 | { "PREFERENCES", "&Preferences..." },
|
---|
119 | { "PRINT", "&Print" },
|
---|
120 | { "PRINT_SETUP", "Print S&etup..." },
|
---|
121 | { "PROPERTIES", "&Properties..." },
|
---|
122 | { "REDO", "&Redo" },
|
---|
123 | { "REDO_MOVE", "&Redo Move" },
|
---|
124 | { "REPLACE", "&Replace..." },
|
---|
125 | { "RESTART_GAME", "&Restart Game" },
|
---|
126 | { "REVERT", "&Revert" },
|
---|
127 | { "SAVE", "&Save" },
|
---|
128 | { "SAVE_AS", "Save &As..." },
|
---|
129 | { "SCORES", "&Scores..." },
|
---|
130 | { "SELECT_ALL", "&Select All" },
|
---|
131 | { "UNDO", "&Undo" },
|
---|
132 | { "UNDO_MOVE", "&Undo Move" },
|
---|
133 | { 0, 0 }
|
---|
134 | };
|
---|
135 |
|
---|
136 | static const struct {
|
---|
137 | const char *gtkName;
|
---|
138 | int qtValue;
|
---|
139 | } keys[] = {
|
---|
140 | { "BackSpace", Qt::Key_BackSpace },
|
---|
141 | { "Delete", Qt::Key_Delete },
|
---|
142 | { "Down", Qt::Key_Down },
|
---|
143 | { "End", Qt::Key_End },
|
---|
144 | { "Escape", Qt::Key_Escape },
|
---|
145 | { "F1", Qt::Key_F1 },
|
---|
146 | { "F10", Qt::Key_F10 },
|
---|
147 | { "F11", Qt::Key_F11 },
|
---|
148 | { "F12", Qt::Key_F12 },
|
---|
149 | { "F2", Qt::Key_F2 },
|
---|
150 | { "F3", Qt::Key_F3 },
|
---|
151 | { "F4", Qt::Key_F4 },
|
---|
152 | { "F5", Qt::Key_F5 },
|
---|
153 | { "F6", Qt::Key_F6 },
|
---|
154 | { "F7", Qt::Key_F7 },
|
---|
155 | { "F8", Qt::Key_F8 },
|
---|
156 | { "F9", Qt::Key_F9 },
|
---|
157 | { "Home", Qt::Key_Home },
|
---|
158 | { "Insert", Qt::Key_Insert },
|
---|
159 | { "KP_Enter", Qt::Key_Enter },
|
---|
160 | { "Left", Qt::Key_Left },
|
---|
161 | { "Page_Down", Qt::Key_PageDown },
|
---|
162 | { "Page_Up", Qt::Key_PageUp },
|
---|
163 | { "Return", Qt::Key_Return },
|
---|
164 | { "Right", Qt::Key_Right },
|
---|
165 | { "Tab", Qt::Key_Tab },
|
---|
166 | { "Up", Qt::Key_Up },
|
---|
167 | { "space", Qt::Key_Space },
|
---|
168 | { 0, 0 }
|
---|
169 | };
|
---|
170 |
|
---|
171 | static QString nonMenuText( const QString& menuText )
|
---|
172 | {
|
---|
173 | QString t;
|
---|
174 | int len = (int) menuText.length();
|
---|
175 | if ( menuText.endsWith(QString("...")) )
|
---|
176 | len -= 3;
|
---|
177 | for ( int i = 0; i < len; i++ ) {
|
---|
178 | if ( menuText[i] != QChar('&') )
|
---|
179 | t += menuText[i];
|
---|
180 | }
|
---|
181 | return t;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /*
|
---|
185 | Some GTK dialog use hyphens in variable names. Let's take no chance.
|
---|
186 | */
|
---|
187 | static QString fixedName( const QString& name )
|
---|
188 | {
|
---|
189 | const char *latin1 = name.latin1();
|
---|
190 | QString fixed;
|
---|
191 |
|
---|
192 | int i = 0;
|
---|
193 | while ( latin1 != 0 && latin1[i] != '\0' ) {
|
---|
194 | if ( isalnum(latin1[i]) )
|
---|
195 | fixed += name[i];
|
---|
196 | else
|
---|
197 | fixed += QChar( '_' );
|
---|
198 | i++;
|
---|
199 | }
|
---|
200 | return fixed;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /*
|
---|
204 | Returns an hexadecimal rendering of a block of memory.
|
---|
205 | */
|
---|
206 | static QString hexed( const char *data, int length )
|
---|
207 | {
|
---|
208 | QString t;
|
---|
209 | for ( int i = 0; i < length; i++ ) {
|
---|
210 | QString x;
|
---|
211 | x.sprintf( "%.2x", (uchar) data[i] );
|
---|
212 | t += x;
|
---|
213 | }
|
---|
214 | return t;
|
---|
215 | }
|
---|
216 |
|
---|
217 | static bool isTrue( const QString& val )
|
---|
218 | {
|
---|
219 | return val.lower() == QString( "true" );
|
---|
220 | }
|
---|
221 |
|
---|
222 | static AttributeMap attribute( const QString& name, const QString& val )
|
---|
223 | {
|
---|
224 | AttributeMap attr;
|
---|
225 | attr.insert( name, val );
|
---|
226 | return attr;
|
---|
227 | }
|
---|
228 |
|
---|
229 | static QString entitize( const QString& str )
|
---|
230 | {
|
---|
231 | QString t = str;
|
---|
232 | t.replace( '&', QString("&") );
|
---|
233 | t.replace( '>', QString(">") );
|
---|
234 | t.replace( '<', QString("<") );
|
---|
235 | t.replace( '"', QString(""") );
|
---|
236 | t.replace( '\'', QString("'") );
|
---|
237 | return t;
|
---|
238 | }
|
---|
239 |
|
---|
240 | Glade2Ui::Glade2Ui()
|
---|
241 | {
|
---|
242 | int i = 0;
|
---|
243 | while ( classNames[i].gtkName != 0 ) {
|
---|
244 | yyClassNameMap.insert( QString(classNames[i].gtkName),
|
---|
245 | QString(classNames[i].qtName) );
|
---|
246 | i++;
|
---|
247 | }
|
---|
248 |
|
---|
249 | i = 0;
|
---|
250 | while ( stockMenuItems[i].name != 0 ) {
|
---|
251 | yyStockMap.insert( QString(stockMenuItems[i].name),
|
---|
252 | QString(stockMenuItems[i].menuText) );
|
---|
253 | i++;
|
---|
254 | }
|
---|
255 |
|
---|
256 | i = 0;
|
---|
257 | while ( keys[i].gtkName != 0 ) {
|
---|
258 | yyKeyMap.insert( QString(keys[i].gtkName), keys[i].qtValue );
|
---|
259 | i++;
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | QString Glade2Ui::imageName( const QString& fileName )
|
---|
264 | {
|
---|
265 | return *yyImages.insert( fileName, QString("image%1").arg(yyImages.count()),
|
---|
266 | FALSE );
|
---|
267 | }
|
---|
268 |
|
---|
269 | QString Glade2Ui::opening( const QString& tag, const AttributeMap& attr )
|
---|
270 | {
|
---|
271 | QString t = QChar( '<' ) + tag;
|
---|
272 | AttributeMap::ConstIterator a = attr.begin();
|
---|
273 | while ( a != attr.end() ) {
|
---|
274 | t += QChar( ' ' ) + a.key() + QString( "=\"" ) + entitize( *a ) +
|
---|
275 | QChar( '"' );
|
---|
276 | ++a;
|
---|
277 | }
|
---|
278 | t += QChar( '>' );
|
---|
279 | return t;
|
---|
280 | }
|
---|
281 |
|
---|
282 | QString Glade2Ui::closing( const QString& tag )
|
---|
283 | {
|
---|
284 | return opening( QChar('/') + tag );
|
---|
285 | }
|
---|
286 |
|
---|
287 | QString Glade2Ui::atom( const QString& tag, const AttributeMap& attr )
|
---|
288 | {
|
---|
289 | QString t = opening( tag, attr );
|
---|
290 | t.insert( t.length() - 1, QChar('/') );
|
---|
291 | return t;
|
---|
292 | }
|
---|
293 |
|
---|
294 | void Glade2Ui::error( const QString& message )
|
---|
295 | {
|
---|
296 | if ( numErrors++ == 0 )
|
---|
297 | QMessageBox::warning( 0, yyFileName, message );
|
---|
298 | }
|
---|
299 |
|
---|
300 | void Glade2Ui::syntaxError()
|
---|
301 | {
|
---|
302 | error( QString("Sorry, I met a random syntax error. I did what I could, but"
|
---|
303 | " that was not enough."
|
---|
304 | "<p>You might want to write to"
|
---|
305 | " <tt>qt-bugs@trolltech.com</tt> about this incident.") );
|
---|
306 | }
|
---|
307 |
|
---|
308 | QString Glade2Ui::getTextValue( const QDomNode& node )
|
---|
309 | {
|
---|
310 | if ( node.childNodes().count() > 1 ) {
|
---|
311 | syntaxError();
|
---|
312 | return QString::null;
|
---|
313 | }
|
---|
314 |
|
---|
315 | if ( node.childNodes().count() == 0 )
|
---|
316 | return QString::null;
|
---|
317 |
|
---|
318 | QDomText t = node.firstChild().toText();
|
---|
319 | if ( t.isNull() ) {
|
---|
320 | syntaxError();
|
---|
321 | return QString::null;
|
---|
322 | }
|
---|
323 | return t.data().stripWhiteSpace();
|
---|
324 | }
|
---|
325 |
|
---|
326 | void Glade2Ui::emitHeader()
|
---|
327 | {
|
---|
328 | yyOut += QString( "<!DOCTYPE UI><UI version=\"3.0\" stdsetdef=\"1\">\n" );
|
---|
329 | }
|
---|
330 |
|
---|
331 | void Glade2Ui::emitFooter()
|
---|
332 | {
|
---|
333 | yyOut += QString( "</UI>\n" );
|
---|
334 | }
|
---|
335 |
|
---|
336 | void Glade2Ui::emitSimpleValue( const QString& tag, const QString& value,
|
---|
337 | const AttributeMap& attr )
|
---|
338 | {
|
---|
339 | yyOut += yyIndentStr + opening( tag, attr ) + entitize( value ) +
|
---|
340 | closing( tag ) + QChar( '\n' );
|
---|
341 | }
|
---|
342 |
|
---|
343 | void Glade2Ui::emitOpening( const QString& tag, const AttributeMap& attr )
|
---|
344 | {
|
---|
345 | yyOut += yyIndentStr + opening( tag, attr ) + QChar( '\n' );
|
---|
346 | yyIndentStr += QString( " " );
|
---|
347 | }
|
---|
348 |
|
---|
349 | void Glade2Ui::emitClosing( const QString& tag )
|
---|
350 | {
|
---|
351 | yyIndentStr.truncate( yyIndentStr.length() - 4 );
|
---|
352 | yyOut += yyIndentStr + closing( tag ) + QChar( '\n' );
|
---|
353 | }
|
---|
354 |
|
---|
355 | void Glade2Ui::emitAtom( const QString& tag, const AttributeMap& attr )
|
---|
356 | {
|
---|
357 | yyOut += yyIndentStr + atom( tag, attr ) + QChar( '\n' );
|
---|
358 | }
|
---|
359 |
|
---|
360 | void Glade2Ui::emitVariant( const QVariant& val, const QString& stringType )
|
---|
361 | {
|
---|
362 | if ( val.isValid() ) {
|
---|
363 | switch ( val.type() ) {
|
---|
364 | case QVariant::String:
|
---|
365 | emitSimpleValue( stringType, val.toString() );
|
---|
366 | break;
|
---|
367 | case QVariant::CString:
|
---|
368 | emitSimpleValue( QString("cstring"), val.toString() );
|
---|
369 | break;
|
---|
370 | case QVariant::Bool:
|
---|
371 | emitSimpleValue( QString("bool"),
|
---|
372 | QString(val.toBool() ? "true" : "false") );
|
---|
373 | break;
|
---|
374 | case QVariant::Int:
|
---|
375 | case QVariant::UInt:
|
---|
376 | emitSimpleValue( QString("number"), val.toString() );
|
---|
377 | break;
|
---|
378 | case QVariant::Rect:
|
---|
379 | emitOpening( QString("rect") );
|
---|
380 | emitSimpleValue( QString("x"), QString::number(val.toRect().x()) );
|
---|
381 | emitSimpleValue( QString("y"), QString::number(val.toRect().y()) );
|
---|
382 | emitSimpleValue( QString("width"),
|
---|
383 | QString::number(val.toRect().width()) );
|
---|
384 | emitSimpleValue( QString("height"),
|
---|
385 | QString::number(val.toRect().height()) );
|
---|
386 | emitClosing( QString("rect") );
|
---|
387 | break;
|
---|
388 | case QVariant::Size:
|
---|
389 | emitOpening( QString("size") );
|
---|
390 | emitSimpleValue( QString("width"),
|
---|
391 | QString::number(val.toSize().width()) );
|
---|
392 | emitSimpleValue( QString("height"),
|
---|
393 | QString::number(val.toSize().height()) );
|
---|
394 | emitClosing( QString("size") );
|
---|
395 | break;
|
---|
396 | case QVariant::SizePolicy:
|
---|
397 | emitOpening( QString("sizepolicy") );
|
---|
398 | emitSimpleValue( QString("hsizetype"),
|
---|
399 | QString::number((int) val.toSizePolicy()
|
---|
400 | .horData()) );
|
---|
401 | emitSimpleValue( QString("vsizetype"),
|
---|
402 | QString::number((int) val.toSizePolicy()
|
---|
403 | .verData()) );
|
---|
404 | emitClosing( QString("sizepolicy") );
|
---|
405 | break;
|
---|
406 | default:
|
---|
407 | emitSimpleValue( QString("fnord"), QString::null );
|
---|
408 | }
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | void Glade2Ui::emitProperty( const QString& prop, const QVariant& val,
|
---|
413 | const QString& stringType )
|
---|
414 | {
|
---|
415 | emitOpening( QString("property"), attribute(QString("name"), prop) );
|
---|
416 | emitVariant( val, stringType );
|
---|
417 | emitClosing( QString("property") );
|
---|
418 | }
|
---|
419 |
|
---|
420 | void Glade2Ui::emitFontProperty( const QString& prop, int pointSize, bool bold )
|
---|
421 | {
|
---|
422 | emitOpening( QString("property"), attribute(QString("name"), prop) );
|
---|
423 | emitOpening( QString("font") );
|
---|
424 | emitSimpleValue( QString("pointsize"), QString::number(pointSize) );
|
---|
425 | if ( bold )
|
---|
426 | emitSimpleValue( QString("bold"), QString("1") );
|
---|
427 | emitClosing( QString("font") );
|
---|
428 | emitClosing( QString("property") );
|
---|
429 | }
|
---|
430 |
|
---|
431 | void Glade2Ui::emitAttribute( const QString& prop, const QVariant& val,
|
---|
432 | const QString& stringType )
|
---|
433 | {
|
---|
434 | emitOpening( QString("attribute"), attribute(QString("name"), prop) );
|
---|
435 | emitVariant( val, stringType );
|
---|
436 | emitClosing( QString("attribute") );
|
---|
437 | }
|
---|
438 |
|
---|
439 | static QString accelerate( const QString& gtkLabel )
|
---|
440 | {
|
---|
441 | QString qtLabel = gtkLabel;
|
---|
442 | qtLabel.replace( '&', QString("&&") );
|
---|
443 | // close but not quite right
|
---|
444 | qtLabel.replace( QChar('_'), QChar('&') );
|
---|
445 | return qtLabel;
|
---|
446 | }
|
---|
447 |
|
---|
448 | static QString decelerate( const QString& gtkLabel )
|
---|
449 | {
|
---|
450 | QString qtLabel = gtkLabel;
|
---|
451 | // ditto
|
---|
452 | qtLabel.replace( '_', QString::null );
|
---|
453 | return qtLabel;
|
---|
454 | }
|
---|
455 |
|
---|
456 | /*
|
---|
457 | Converting a GTK widget to a corresponding Qt widget is sometimes
|
---|
458 | hard. For example, a GtkScrolledWindow should sometimes be converted
|
---|
459 | into a QTextView, a QTextEdit, a QListView or whatever. What we do
|
---|
460 | is pretty hackish, but it mostly works.
|
---|
461 | */
|
---|
462 | QString Glade2Ui::gtk2qtClass( const QString& gtkClass,
|
---|
463 | const QValueList<QDomElement>& childWidgets )
|
---|
464 | {
|
---|
465 | QRegExp gnomeXEntry( QString("Gnome(File|Number|Pixmap)?Entry") );
|
---|
466 |
|
---|
467 | QString qtClass;
|
---|
468 |
|
---|
469 | if ( gtkClass == QString("GtkScrolledWindow") ) {
|
---|
470 | if ( childWidgets.count() == 1 ) {
|
---|
471 | QString g;
|
---|
472 | bool editable = FALSE;
|
---|
473 | bool showTitles = TRUE;
|
---|
474 |
|
---|
475 | QDomNode n = childWidgets.first().firstChild();
|
---|
476 | while ( !n.isNull() ) {
|
---|
477 | QString tagName = n.toElement().tagName();
|
---|
478 | if ( tagName == QString("class") ) {
|
---|
479 | g = getTextValue( n );
|
---|
480 | } else if ( tagName == QString("editable") ) {
|
---|
481 | editable = isTrue( getTextValue(n) );
|
---|
482 | } else if ( tagName.startsWith(QString("show_tit")) ) {
|
---|
483 | showTitles = isTrue( getTextValue(n) );
|
---|
484 | }
|
---|
485 | n = n.nextSibling();
|
---|
486 | }
|
---|
487 |
|
---|
488 | if ( g == QString("GnomeCanvas") ||
|
---|
489 | g == QString("GtkDrawingArea") ) {
|
---|
490 | qtClass = QString( "QLabel" );
|
---|
491 | } else if ( g == QString("GnomeIconList") ) {
|
---|
492 | qtClass = QString( "QIconView" );
|
---|
493 | } else if ( g == QString("GtkCList") ) {
|
---|
494 | if ( showTitles )
|
---|
495 | qtClass = QString( "QListView" );
|
---|
496 | else
|
---|
497 | qtClass = QString( "QListBox" );
|
---|
498 | } else if ( g == QString("GtkCTree") ) {
|
---|
499 | qtClass = QString( "QListView" );
|
---|
500 | } else if ( g == QString("GtkList") ) {
|
---|
501 | qtClass = QString( "QListBox" );
|
---|
502 | } else if ( g == QString("GtkText") ) {
|
---|
503 | if ( editable )
|
---|
504 | qtClass = QString( "QTextEdit" );
|
---|
505 | else
|
---|
506 | qtClass = QString( "QTextView" );
|
---|
507 | } else if ( g == QString("GtkTree") ) {
|
---|
508 | qtClass = QString( "QListView" );
|
---|
509 | }
|
---|
510 | // else too bad (qtClass is empty)
|
---|
511 | }
|
---|
512 | } else if ( gtkClass == QString("GtkWindow") ) {
|
---|
513 | qtClass = QString( "QDialog" );
|
---|
514 | if ( childWidgets.count() == 1 ) {
|
---|
515 | QString g;
|
---|
516 |
|
---|
517 | QDomNode n = childWidgets.first().firstChild();
|
---|
518 | while ( !n.isNull() ) {
|
---|
519 | QString tagName = n.toElement().tagName();
|
---|
520 | if ( tagName == QString("class") )
|
---|
521 | g = getTextValue( n );
|
---|
522 | n = n.nextSibling();
|
---|
523 | }
|
---|
524 | if ( g == QString("GnomeDruid") )
|
---|
525 | qtClass = QString( "QWizard" );
|
---|
526 | }
|
---|
527 | /*
|
---|
528 | GnomeEntry and friends are a wrapper around a GtkEntry. We only
|
---|
529 | want the GtkEntry child.
|
---|
530 | */
|
---|
531 | } else if ( !gnomeXEntry.exactMatch(gtkClass) &&
|
---|
532 | gtkClass != QString("GtkAlignment") &&
|
---|
533 | gtkClass != QString("GtkEventBox") ) {
|
---|
534 | qtClass = yyClassNameMap[gtkClass];
|
---|
535 | if ( qtClass.isEmpty() )
|
---|
536 | qtClass = QString( "Unknown" );
|
---|
537 | }
|
---|
538 | return qtClass;
|
---|
539 | }
|
---|
540 |
|
---|
541 | static QString gtk2qtScrollBarMode( const QString& scrollbarPolicy )
|
---|
542 | {
|
---|
543 | if ( scrollbarPolicy.endsWith(QString("_NEVER")) ) {
|
---|
544 | return QString( "AlwaysOff" );
|
---|
545 | } else if ( scrollbarPolicy.endsWith(QString("_ALWAYS")) ) {
|
---|
546 | return QString( "AlwaysOn" );
|
---|
547 | } else {
|
---|
548 | return QString( "Auto" );
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 | static QString gtk2qtSelectionMode( const QString& selectionMode )
|
---|
553 | {
|
---|
554 | if ( selectionMode.endsWith(QString("_MULTIPLE")) )
|
---|
555 | return QString( "Multi" );
|
---|
556 | else if ( selectionMode.endsWith(QString("_EXTENDED")) )
|
---|
557 | return QString( "Extended" );
|
---|
558 | else
|
---|
559 | return QString( "Single" );
|
---|
560 | }
|
---|
561 |
|
---|
562 | int Glade2Ui::matchAccelOnActivate( const QDomElement& accel )
|
---|
563 | {
|
---|
564 | QString key;
|
---|
565 | QString modifiers;
|
---|
566 |
|
---|
567 | QDomNode n = accel.firstChild();
|
---|
568 | while ( !n.isNull() ) {
|
---|
569 | QString tagName = n.toElement().tagName();
|
---|
570 | if ( tagName == QString("key") ) {
|
---|
571 | key = getTextValue( n );
|
---|
572 | if ( !key.startsWith(QString("GDK_")) )
|
---|
573 | return 0;
|
---|
574 | } else if ( tagName == QString("modifiers") ) {
|
---|
575 | modifiers = getTextValue( n );
|
---|
576 | } else if ( tagName == QString("signal") ) {
|
---|
577 | if ( getTextValue(n) != QString("activate") )
|
---|
578 | return 0;
|
---|
579 | }
|
---|
580 | n = n.nextSibling();
|
---|
581 | }
|
---|
582 |
|
---|
583 | int flags = 0;
|
---|
584 |
|
---|
585 | if ( key.length() == 5 ) {
|
---|
586 | flags = key[4].upper().latin1();
|
---|
587 | } else if ( yyKeyMap.contains(key.mid(4)) ) {
|
---|
588 | flags = yyKeyMap[key.mid(4)];
|
---|
589 | } else {
|
---|
590 | return 0;
|
---|
591 | }
|
---|
592 |
|
---|
593 | if ( modifiers.contains(QString("_CONTROL_")) )
|
---|
594 | flags |= Qt::CTRL;
|
---|
595 | if ( modifiers.contains(QString("_SHIFT_")) )
|
---|
596 | flags |= Qt::SHIFT;
|
---|
597 | if ( modifiers.contains(QString("_MOD1_")) )
|
---|
598 | flags |= Qt::ALT;
|
---|
599 | return flags;
|
---|
600 | }
|
---|
601 |
|
---|
602 | void Glade2Ui::emitGtkMenu( const QDomElement& menu )
|
---|
603 | {
|
---|
604 | QRegExp gnomeuiinfoMenuXItem( QString("GNOMEUIINFO_MENU_(.+)_ITEM") );
|
---|
605 |
|
---|
606 | QDomNode n = menu.firstChild();
|
---|
607 | while ( !n.isNull() ) {
|
---|
608 | QString tagName = n.toElement().tagName();
|
---|
609 | if ( tagName == QString("widget") ) {
|
---|
610 | QString activateHandler;
|
---|
611 | QString gtkClass;
|
---|
612 | QString icon;
|
---|
613 | QString label;
|
---|
614 | QString name;
|
---|
615 | QString stockItem;
|
---|
616 | QString tooltip;
|
---|
617 | int qtAccel = 0;
|
---|
618 |
|
---|
619 | QDomNode child = n.firstChild();
|
---|
620 | while ( !child.isNull() ) {
|
---|
621 | QString childTagName = child.toElement().tagName();
|
---|
622 | if ( childTagName == QString("accelerator") ) {
|
---|
623 | qtAccel = matchAccelOnActivate( child.toElement() );
|
---|
624 | } else if ( childTagName == QString("class") ) {
|
---|
625 | gtkClass = getTextValue( child );
|
---|
626 | } else if ( childTagName == QString("icon") ) {
|
---|
627 | icon = getTextValue( child );
|
---|
628 | } else if ( childTagName == QString("label") ) {
|
---|
629 | label = getTextValue( child );
|
---|
630 | } else if ( childTagName == QString("name") ) {
|
---|
631 | name = getTextValue( child );
|
---|
632 | } else if ( childTagName == QString("signal") ) {
|
---|
633 | QString signalName;
|
---|
634 | QString signalHandler;
|
---|
635 |
|
---|
636 | QDomNode grandchild = child.firstChild();
|
---|
637 | while ( !grandchild.isNull() ) {
|
---|
638 | QString grandchildTagName =
|
---|
639 | grandchild.toElement().tagName();
|
---|
640 | if ( grandchildTagName == QString("handler") ) {
|
---|
641 | signalHandler = getTextValue( grandchild );
|
---|
642 | } else if ( grandchildTagName == QString("name") ) {
|
---|
643 | signalName = getTextValue( grandchild );
|
---|
644 | }
|
---|
645 | grandchild = grandchild.nextSibling();
|
---|
646 | }
|
---|
647 | if ( signalName == QString("activate") )
|
---|
648 | activateHandler = signalHandler;
|
---|
649 | } else if ( childTagName == QString("stock_item") ) {
|
---|
650 | stockItem = getTextValue( child );
|
---|
651 | } else if ( childTagName == QString("tooltip") ) {
|
---|
652 | tooltip = getTextValue( child );
|
---|
653 | }
|
---|
654 | child = child.nextSibling();
|
---|
655 | }
|
---|
656 |
|
---|
657 | if ( label.length() + stockItem.length() == 0 ) {
|
---|
658 | emitAtom( QString("separator") );
|
---|
659 | } else {
|
---|
660 | if ( name.isEmpty() )
|
---|
661 | name = QString( "action%1" ).arg( uniqueAction++ );
|
---|
662 | emitAtom( QString("action"), attribute(QString("name"), name) );
|
---|
663 |
|
---|
664 | if ( !activateHandler.isEmpty() ) {
|
---|
665 | QString slot = activateHandler + QString( "()" );
|
---|
666 | GladeConnection c;
|
---|
667 | c.sender = name;
|
---|
668 | c.signal = QString( "activated()" );
|
---|
669 | c.slot = slot;
|
---|
670 | yyConnections.push_back( c );
|
---|
671 | yySlots.insert( slot, QString("public") );
|
---|
672 | }
|
---|
673 |
|
---|
674 | QString x;
|
---|
675 | GladeAction a;
|
---|
676 |
|
---|
677 | if ( gnomeuiinfoMenuXItem.exactMatch(stockItem) ) {
|
---|
678 | x = gnomeuiinfoMenuXItem.cap( 1 );
|
---|
679 | a.menuText = yyStockMap[x];
|
---|
680 | if ( x == QString("EXIT") && qtAccel == 0 )
|
---|
681 | qtAccel = Qt::CTRL + Qt::Key_Q;
|
---|
682 | } else {
|
---|
683 | a.menuText = accelerate( label );
|
---|
684 | }
|
---|
685 | a.text = nonMenuText( a.menuText );
|
---|
686 | a.toolTip = tooltip;
|
---|
687 | a.accel = qtAccel;
|
---|
688 | a.iconSet = icon;
|
---|
689 | yyActions.insert( name, a );
|
---|
690 | if ( !x.isEmpty() )
|
---|
691 | yyStockItemActions.insert( x, name );
|
---|
692 | }
|
---|
693 | }
|
---|
694 | n = n.nextSibling();
|
---|
695 | }
|
---|
696 | }
|
---|
697 |
|
---|
698 | void Glade2Ui::emitGtkMenuBarChildWidgets(
|
---|
699 | const QValueList<QDomElement>& childWidgets )
|
---|
700 | {
|
---|
701 | QRegExp gnomeuiinfoMenuXTree( QString("GNOMEUIINFO_MENU_(.+)_TREE") );
|
---|
702 |
|
---|
703 | emitOpening( QString("menubar") );
|
---|
704 | emitProperty( QString("name"),
|
---|
705 | QString("MenuBar%1").arg(uniqueMenuBar++).latin1() );
|
---|
706 |
|
---|
707 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
708 | while ( c != childWidgets.end() ) {
|
---|
709 | QValueList<QDomElement> grandchildWidgets;
|
---|
710 | QString gtkClass;
|
---|
711 | QString label;
|
---|
712 | QString name;
|
---|
713 | QString stockItem;
|
---|
714 |
|
---|
715 | QDomNode n = (*c).firstChild();
|
---|
716 | while ( !n.isNull() ) {
|
---|
717 | QString tagName = n.toElement().tagName();
|
---|
718 | if ( tagName == QString("class") ) {
|
---|
719 | gtkClass = getTextValue( n );
|
---|
720 | } else if ( tagName == QString("label") ) {
|
---|
721 | label = getTextValue( n );
|
---|
722 | } else if ( tagName == QString("name") ) {
|
---|
723 | name = getTextValue( n );
|
---|
724 | } else if ( tagName == QString("stock_item") ) {
|
---|
725 | stockItem = getTextValue( n );
|
---|
726 | } else if ( tagName == QString("widget") ) {
|
---|
727 | grandchildWidgets.push_back( n.toElement() );
|
---|
728 | }
|
---|
729 | n = n.nextSibling();
|
---|
730 | }
|
---|
731 |
|
---|
732 | if ( gtkClass == QString("GtkMenuItem") &&
|
---|
733 | grandchildWidgets.count() == 1 ) {
|
---|
734 | QString text;
|
---|
735 | if ( gnomeuiinfoMenuXTree.exactMatch(stockItem) ) {
|
---|
736 | text = gnomeuiinfoMenuXTree.cap( 1 );
|
---|
737 | if ( text == QString("Files") )
|
---|
738 | text = QString( "Fi&les" );
|
---|
739 | else
|
---|
740 | text = QChar( '&' ) + text.left( 1 ) +
|
---|
741 | text.mid( 1 ).lower();
|
---|
742 | } else {
|
---|
743 | text = accelerate( label );
|
---|
744 | }
|
---|
745 |
|
---|
746 | AttributeMap attr;
|
---|
747 | attr.insert( QString("name"), name );
|
---|
748 | attr.insert( QString("text"), text );
|
---|
749 |
|
---|
750 | emitOpening( QString("item"), attr );
|
---|
751 | emitGtkMenu( grandchildWidgets.first() );
|
---|
752 | emitClosing( QString("item") );
|
---|
753 | }
|
---|
754 | ++c;
|
---|
755 | }
|
---|
756 | emitClosing( QString("menubar") );
|
---|
757 | }
|
---|
758 |
|
---|
759 | void Glade2Ui::emitGtkToolbarChildWidgets(
|
---|
760 | const QValueList<QDomElement>& childWidgets )
|
---|
761 | {
|
---|
762 | QRegExp gnomeStockPixmapX( QString("GNOME_STOCK_PIXMAP_(.+)") );
|
---|
763 |
|
---|
764 | emitOpening( QString("toolbar"), attribute(QString("dock"), QString("2")) );
|
---|
765 | emitProperty( QString("name"),
|
---|
766 | QString("ToolBar%1").arg(uniqueToolBar++).latin1() );
|
---|
767 |
|
---|
768 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
769 | while ( c != childWidgets.end() ) {
|
---|
770 | QString childName;
|
---|
771 | QString icon;
|
---|
772 | QString label;
|
---|
773 | QString name;
|
---|
774 | QString stockPixmap;
|
---|
775 | QString tooltip;
|
---|
776 |
|
---|
777 | QDomNode n = (*c).firstChild();
|
---|
778 | while ( !n.isNull() ) {
|
---|
779 | QString tagName = n.toElement().tagName();
|
---|
780 | if ( tagName == QString("child_name") ) {
|
---|
781 | childName = getTextValue( n );
|
---|
782 | } else if ( tagName == QString("icon") ) {
|
---|
783 | icon = getTextValue( n );
|
---|
784 | } else if ( tagName == QString("label") ) {
|
---|
785 | label = getTextValue( n );
|
---|
786 | } else if ( tagName == QString("name") ) {
|
---|
787 | name = getTextValue( n );
|
---|
788 | } else if ( tagName == QString("stock_pixmap") ) {
|
---|
789 | stockPixmap = getTextValue( n );
|
---|
790 | } else if ( tagName == QString("tooltip") ) {
|
---|
791 | tooltip = getTextValue( n );
|
---|
792 | }
|
---|
793 | n = n.nextSibling();
|
---|
794 | }
|
---|
795 |
|
---|
796 | if ( childName == QString("Toolbar:button") ) {
|
---|
797 | QString actionName;
|
---|
798 | GladeAction a;
|
---|
799 | a.menuText = label;
|
---|
800 | a.text = label;
|
---|
801 | a.accel = 0;
|
---|
802 | a.iconSet = icon;
|
---|
803 |
|
---|
804 | if ( gnomeStockPixmapX.exactMatch(stockPixmap) ) {
|
---|
805 | QString x = gnomeStockPixmapX.cap( 1 );
|
---|
806 | actionName = yyStockItemActions[x];
|
---|
807 | }
|
---|
808 | if ( actionName.isEmpty() ) {
|
---|
809 | if ( name.isEmpty() )
|
---|
810 | actionName = QString( "action%1" ).arg( uniqueAction++ );
|
---|
811 | else
|
---|
812 | actionName = QString( "action_%1" ).arg( name );
|
---|
813 | yyActions.insert( actionName, a );
|
---|
814 | }
|
---|
815 | if ( !tooltip.isEmpty() )
|
---|
816 | yyActions[actionName].toolTip = tooltip;
|
---|
817 |
|
---|
818 | emitAtom( QString("action"), attribute(QString("name"),
|
---|
819 | actionName) );
|
---|
820 | } else {
|
---|
821 | emitAtom( QString("separator") );
|
---|
822 | }
|
---|
823 | ++c;
|
---|
824 | }
|
---|
825 | emitClosing( QString("toolbar") );
|
---|
826 | }
|
---|
827 |
|
---|
828 | void Glade2Ui::emitPushButton( const QString& text, const QString& name )
|
---|
829 | {
|
---|
830 | emitOpening( QString("widget"),
|
---|
831 | attribute(QString("class"), QString("QPushButton")) );
|
---|
832 | emitProperty( QString("name"), name.latin1() );
|
---|
833 | emitProperty( QString("text"), text );
|
---|
834 | if ( name.contains(QString("ok")) > 0 ) {
|
---|
835 | emitProperty( QString("default"), QVariant(TRUE, 0) );
|
---|
836 | } else if ( name.contains(QString("help")) > 0 ) {
|
---|
837 | emitProperty( QString("accel"), (int) Qt::Key_F1 );
|
---|
838 | }
|
---|
839 | emitClosing( QString("widget") );
|
---|
840 | }
|
---|
841 |
|
---|
842 | void Glade2Ui::attach( AttributeMap *attr, int leftAttach, int rightAttach,
|
---|
843 | int topAttach, int bottomAttach )
|
---|
844 | {
|
---|
845 | if ( leftAttach >= 0 ) {
|
---|
846 | attr->insert( QString("row"), QString::number(topAttach) );
|
---|
847 | attr->insert( QString("column"), QString::number(leftAttach) );
|
---|
848 | if ( bottomAttach - topAttach != 1 )
|
---|
849 | attr->insert( QString("rowspan"),
|
---|
850 | QString::number(bottomAttach - topAttach) );
|
---|
851 | if ( rightAttach - leftAttach != 1 )
|
---|
852 | attr->insert( QString("colspan"),
|
---|
853 | QString::number(rightAttach - leftAttach) );
|
---|
854 | }
|
---|
855 | }
|
---|
856 |
|
---|
857 | void Glade2Ui::emitSpacer( const QString& orientation, int leftAttach,
|
---|
858 | int rightAttach, int topAttach, int bottomAttach )
|
---|
859 | {
|
---|
860 | AttributeMap attr;
|
---|
861 | attach( &attr, leftAttach, rightAttach, topAttach, bottomAttach );
|
---|
862 | emitOpening( QString("spacer"), attr );
|
---|
863 | emitProperty( QString("name"),
|
---|
864 | QString("Spacer%1").arg(uniqueSpacer++).latin1() );
|
---|
865 | emitProperty( QString("orientation"), orientation, QString("enum") );
|
---|
866 | emitProperty( QString("sizeType"), QString("Expanding"),
|
---|
867 | QString("enum") );
|
---|
868 | emitClosing( QString("spacer") );
|
---|
869 | }
|
---|
870 |
|
---|
871 | void Glade2Ui::emitPixmap( const QString& imageName, int leftAttach,
|
---|
872 | int rightAttach, int topAttach, int bottomAttach )
|
---|
873 | {
|
---|
874 | emitOpeningWidget( QString("QLabel"), leftAttach, rightAttach, topAttach,
|
---|
875 | bottomAttach );
|
---|
876 | emitProperty( QString("sizePolicy"),
|
---|
877 | QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
|
---|
878 | emitProperty( QString("pixmap"), imageName, QString("pixmap") );
|
---|
879 | emitClosing( QString("widget") );
|
---|
880 | }
|
---|
881 |
|
---|
882 | void Glade2Ui::emitGnomeAbout( QString copyright, QString authors,
|
---|
883 | QString comments )
|
---|
884 | {
|
---|
885 | QString prog = yyProgramName;
|
---|
886 | if ( prog.isEmpty() )
|
---|
887 | prog = QString( "Gnomovision 1.69" );
|
---|
888 | if ( copyright.isEmpty() )
|
---|
889 | copyright = QString( "(C) 2001 Jasmin Blanchette" );
|
---|
890 | if ( authors.isEmpty() )
|
---|
891 | authors = QString( "Jasmin Blanchette <jasmin@troll.no>" );
|
---|
892 | if ( comments.isEmpty() )
|
---|
893 | comments = QString( "Gnomovision is the official GNU application." );
|
---|
894 |
|
---|
895 | emitOpening( QString("hbox") );
|
---|
896 | emitSpacer( QString("Horizontal") );
|
---|
897 | emitOpeningWidget( QString("QLayoutWidget") );
|
---|
898 | emitOpening( QString("vbox") );
|
---|
899 | emitProperty( QString("spacing"), 17 );
|
---|
900 |
|
---|
901 | /*
|
---|
902 | Emit the application name.
|
---|
903 | */
|
---|
904 | emitOpeningWidget( QString("QLabel") );
|
---|
905 | emitFontProperty( QString("font"), 24, TRUE );
|
---|
906 | emitProperty( QString("text"), prog );
|
---|
907 | emitProperty( QString("alignment"), QString("AlignAuto|AlignCenter"),
|
---|
908 | QString("set") );
|
---|
909 | emitClosing( QString("widget") );
|
---|
910 |
|
---|
911 | /*
|
---|
912 | Emit the copyright notice.
|
---|
913 | */
|
---|
914 | emitOpeningWidget( QString("QLabel") );
|
---|
915 | emitFontProperty( QString("font"), 12, TRUE );
|
---|
916 | emitProperty( QString("text"), copyright );
|
---|
917 | emitClosing( QString("widget") );
|
---|
918 |
|
---|
919 | /*
|
---|
920 | Emit the authors' names.
|
---|
921 | */
|
---|
922 | emitOpeningWidget( QString("QLayoutWidget") );
|
---|
923 | emitOpening( QString("hbox") );
|
---|
924 |
|
---|
925 | emitOpeningWidget( QString("QLabel") );
|
---|
926 | emitFontProperty( QString("font"), 12, TRUE );
|
---|
927 | emitProperty( QString("text"), QString("Authors:") );
|
---|
928 | emitProperty( QString("alignment"), QString("AlignAuto|AlignTop"),
|
---|
929 | QString("set") );
|
---|
930 | emitClosing( QString("widget") );
|
---|
931 |
|
---|
932 | emitOpeningWidget( QString("QLabel") );
|
---|
933 | emitFontProperty( QString("font"), 12, FALSE );
|
---|
934 | emitProperty( QString("text"), authors );
|
---|
935 | emitProperty( QString("alignment"), QString("AlignAuto|AlignTop"),
|
---|
936 | QString("set") );
|
---|
937 | emitClosing( QString("widget") );
|
---|
938 |
|
---|
939 | emitSpacer( QString("Horizontal") );
|
---|
940 |
|
---|
941 | emitClosing( QString("hbox") );
|
---|
942 | emitClosing( QString("widget") );
|
---|
943 |
|
---|
944 | /*
|
---|
945 | Emit the comments.
|
---|
946 | */
|
---|
947 | emitOpeningWidget( QString("QLabel") );
|
---|
948 | emitFontProperty( QString("font"), 10, FALSE );
|
---|
949 | emitProperty( QString("text"), comments );
|
---|
950 | emitProperty( QString("alignment"), QString("AlignAuto|AlignTop"),
|
---|
951 | QString("set") );
|
---|
952 | emitClosing( QString("widget") );
|
---|
953 |
|
---|
954 | /*
|
---|
955 | Emit the spacer and the OK button.
|
---|
956 | */
|
---|
957 | emitSpacer( QString("Vertical") );
|
---|
958 |
|
---|
959 | emitOpeningWidget( QString("QLayoutWidget") );
|
---|
960 | emitOpening( QString("hbox") );
|
---|
961 | emitSpacer( QString("Horizontal") );
|
---|
962 |
|
---|
963 | emitPushButton( QString("&OK"), QString("okButton") );
|
---|
964 |
|
---|
965 | emitSpacer( QString("Horizontal") );
|
---|
966 | emitClosing( QString("hbox") );
|
---|
967 | emitClosing( QString("widget") );
|
---|
968 |
|
---|
969 | emitClosing( QString("vbox") );
|
---|
970 | emitClosing( QString("widget") );
|
---|
971 | emitSpacer( QString("Horizontal") );
|
---|
972 | emitClosing( QString("hbox") );
|
---|
973 | }
|
---|
974 |
|
---|
975 | /*
|
---|
976 | GnomeApps are emitted in two passes, because some information goes
|
---|
977 | into the <widget> section, whereas other information goes into the
|
---|
978 | <toolbars> section.
|
---|
979 | */
|
---|
980 | void Glade2Ui::emitGnomeAppChildWidgetsPass1(
|
---|
981 | const QValueList<QDomElement>& childWidgets )
|
---|
982 | {
|
---|
983 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
984 | while ( c != childWidgets.end() ) {
|
---|
985 | QValueList<QDomElement> grandchildWidgets;
|
---|
986 | QString childName;
|
---|
987 |
|
---|
988 | QDomNode n = (*c).firstChild();
|
---|
989 | while ( !n.isNull() ) {
|
---|
990 | QString tagName = n.toElement().tagName();
|
---|
991 | if ( tagName == QString("child_name") ) {
|
---|
992 | childName = getTextValue( n );
|
---|
993 | } else if ( tagName == QString("widget") ) {
|
---|
994 | grandchildWidgets.push_back( n.toElement() );
|
---|
995 | }
|
---|
996 | n = n.nextSibling();
|
---|
997 | }
|
---|
998 |
|
---|
999 | if ( childName == QString("GnomeDock:contents") ) {
|
---|
1000 | emitWidget( *c, FALSE );
|
---|
1001 | } else {
|
---|
1002 | emitGnomeAppChildWidgetsPass1( grandchildWidgets );
|
---|
1003 | }
|
---|
1004 | ++c;
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | void Glade2Ui::doPass2( const QValueList<QDomElement>& childWidgets,
|
---|
1009 | QValueList<QDomElement> *menuBar,
|
---|
1010 | QValueList<QValueList<QDomElement> > *toolBars )
|
---|
1011 | {
|
---|
1012 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
1013 | while ( c != childWidgets.end() ) {
|
---|
1014 | QValueList<QDomElement> grandchildWidgets;
|
---|
1015 | QString childName;
|
---|
1016 | QString gtkClass;
|
---|
1017 |
|
---|
1018 | QDomNode n = (*c).firstChild();
|
---|
1019 | while ( !n.isNull() ) {
|
---|
1020 | QString tagName = n.toElement().tagName();
|
---|
1021 | if ( tagName == QString("child_name") ) {
|
---|
1022 | childName = getTextValue( n );
|
---|
1023 | } else if ( tagName == QString("class") ) {
|
---|
1024 | gtkClass = getTextValue( n );
|
---|
1025 | } else if ( tagName == QString("widget") ) {
|
---|
1026 | grandchildWidgets.push_back( n.toElement() );
|
---|
1027 | }
|
---|
1028 | n = n.nextSibling();
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | if ( gtkClass == QString("GtkMenuBar") ) {
|
---|
1032 | *menuBar = grandchildWidgets;
|
---|
1033 | } else if ( gtkClass == QString("GtkToolbar") ) {
|
---|
1034 | toolBars->push_back( grandchildWidgets );
|
---|
1035 | } else if ( childName != QString("GnomeDock:contents") ) {
|
---|
1036 | doPass2( grandchildWidgets, menuBar, toolBars );
|
---|
1037 | }
|
---|
1038 | ++c;
|
---|
1039 | }
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | void Glade2Ui::emitGnomeAppChildWidgetsPass2(
|
---|
1043 | const QValueList<QDomElement>& childWidgets )
|
---|
1044 | {
|
---|
1045 | QValueList<QDomElement> menuBar;
|
---|
1046 | QValueList<QValueList<QDomElement> > toolBars;
|
---|
1047 |
|
---|
1048 | doPass2( childWidgets, &menuBar, &toolBars );
|
---|
1049 |
|
---|
1050 | emitGtkMenuBarChildWidgets( menuBar );
|
---|
1051 | if ( !toolBars.isEmpty() ) {
|
---|
1052 | emitOpening( QString("toolbars") );
|
---|
1053 | while ( !toolBars.isEmpty() ) {
|
---|
1054 | emitGtkToolbarChildWidgets( toolBars.first() );
|
---|
1055 | toolBars.remove( toolBars.begin() );
|
---|
1056 | }
|
---|
1057 | emitClosing( QString("toolbars") );
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | void Glade2Ui::emitGtkButtonChildWidgets( QValueList<QDomElement> childWidgets )
|
---|
1062 | {
|
---|
1063 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
1064 | while ( c != childWidgets.end() ) {
|
---|
1065 | QString label;
|
---|
1066 |
|
---|
1067 | QDomNode n = (*c).firstChild();
|
---|
1068 | while ( !n.isNull() ) {
|
---|
1069 | QString tagName = n.toElement().tagName();
|
---|
1070 | if ( tagName == QString("label") ) {
|
---|
1071 | label = getTextValue( n );
|
---|
1072 | } else if ( tagName == QString("widget") ) {
|
---|
1073 | childWidgets.push_back( n.toElement() );
|
---|
1074 | }
|
---|
1075 | n = n.nextSibling();
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | if ( !label.isEmpty() ) {
|
---|
1079 | emitProperty( QString("text"), accelerate(label) );
|
---|
1080 | break;
|
---|
1081 | }
|
---|
1082 | ++c;
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 |
|
---|
1086 | void Glade2Ui::emitGtkComboChildWidgets(
|
---|
1087 | const QValueList<QDomElement>& childWidgets, const QStringList& items )
|
---|
1088 | {
|
---|
1089 | QString text;
|
---|
1090 |
|
---|
1091 | // there should be exactly one child, of type GtkEntry
|
---|
1092 | if ( childWidgets.count() == 1 ) {
|
---|
1093 | QDomNode n = childWidgets.first().firstChild();
|
---|
1094 | while ( !n.isNull() ) {
|
---|
1095 | QString tagName = n.toElement().tagName();
|
---|
1096 | if ( tagName == QString("name") ) {
|
---|
1097 | // grep 'elsewhere'
|
---|
1098 | emitProperty( QString("name"),
|
---|
1099 | fixedName(getTextValue(n).latin1()) );
|
---|
1100 | } else if ( tagName == QString("text") ) {
|
---|
1101 | text = getTextValue( n );
|
---|
1102 | }
|
---|
1103 | n = n.nextSibling();
|
---|
1104 | }
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | int n = 0;
|
---|
1108 | QStringList::ConstIterator s = items.begin();
|
---|
1109 | while ( s != items.end() ) {
|
---|
1110 | if ( !text.isEmpty() && *s == text )
|
---|
1111 | emitProperty( QString("currentItem"), n );
|
---|
1112 | n++;
|
---|
1113 | ++s;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | void Glade2Ui::emitGtkNotebookChildWidgets(
|
---|
1119 | const QValueList<QDomElement>& childWidgets )
|
---|
1120 | {
|
---|
1121 | QStringList tabNames;
|
---|
1122 | QStringList tabLabels;
|
---|
1123 |
|
---|
1124 | for ( int i = 0; i < (int) childWidgets.count(); i++ ) {
|
---|
1125 | tabNames.push_back( QString("tab%1").arg(i + 1) );
|
---|
1126 | tabLabels.push_back( QString("Tab %1").arg(i + 1) );
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | QValueList<QDomElement>::ConstIterator c;
|
---|
1130 | c = childWidgets.begin();
|
---|
1131 |
|
---|
1132 | QStringList::Iterator nam = tabNames.begin();
|
---|
1133 | QStringList::Iterator lab = tabLabels.begin();
|
---|
1134 |
|
---|
1135 | while ( c != childWidgets.end() ) {
|
---|
1136 | QString childName;
|
---|
1137 | QString name;
|
---|
1138 | QString label;
|
---|
1139 |
|
---|
1140 | QDomNode n = (*c).firstChild();
|
---|
1141 | while ( !n.isNull() ) {
|
---|
1142 | QString tagName = n.toElement().tagName();
|
---|
1143 | if ( tagName == QString("child_name") ) {
|
---|
1144 | childName = getTextValue( n );
|
---|
1145 | } else if ( tagName == QString("name") ) {
|
---|
1146 | name = getTextValue( n );
|
---|
1147 | } else if ( tagName == QString("label") ) {
|
---|
1148 | label = getTextValue( n );
|
---|
1149 | }
|
---|
1150 | n = n.nextSibling();
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | if ( childName == QString("Notebook:tab") ) {
|
---|
1154 | if ( !name.isEmpty() )
|
---|
1155 | *nam = name;
|
---|
1156 | if ( !label.isEmpty() )
|
---|
1157 | *lab = label;
|
---|
1158 | ++nam;
|
---|
1159 | ++lab;
|
---|
1160 | }
|
---|
1161 | ++c;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | c = childWidgets.begin();
|
---|
1165 | while ( c != childWidgets.end() ) {
|
---|
1166 | QString childName;
|
---|
1167 | QString name;
|
---|
1168 | QString label;
|
---|
1169 |
|
---|
1170 | QDomNode n = (*c).firstChild();
|
---|
1171 | while ( !n.isNull() ) {
|
---|
1172 | QString tagName = n.toElement().tagName();
|
---|
1173 | if ( tagName == QString("child_name") )
|
---|
1174 | childName = getTextValue( n );
|
---|
1175 | n = n.nextSibling();
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | if ( childName != QString("Notebook:tab") ) {
|
---|
1179 | emitOpeningWidget( QString("QWidget") );
|
---|
1180 | emitProperty( QString("name"), tabNames.first().latin1() );
|
---|
1181 | tabNames.remove( tabNames.begin() );
|
---|
1182 | emitAttribute( QString("title"), accelerate(tabLabels.first()) );
|
---|
1183 | tabLabels.remove( tabLabels.begin() );
|
---|
1184 | emitWidget( *c, FALSE );
|
---|
1185 | emitClosing( QString("widget") );
|
---|
1186 | }
|
---|
1187 | ++c;
|
---|
1188 | }
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | void Glade2Ui::emitQListViewColumns( const QDomElement& qlistview )
|
---|
1192 | {
|
---|
1193 | QDomNode n = qlistview.firstChild();
|
---|
1194 | while ( !n.isNull() ) {
|
---|
1195 | QString tagName = n.toElement().tagName();
|
---|
1196 | if ( tagName == QString("widget") ) {
|
---|
1197 | QDomNode child = n.firstChild();
|
---|
1198 | while ( !child.isNull() ) {
|
---|
1199 | QString tagName = child.toElement().tagName();
|
---|
1200 | if ( tagName == QString("label") ) {
|
---|
1201 | emitOpening( QString("column") );
|
---|
1202 | emitProperty( QString("text"),
|
---|
1203 | decelerate(getTextValue(child)) );
|
---|
1204 | emitClosing( QString("column") );
|
---|
1205 | }
|
---|
1206 | child = child.nextSibling();
|
---|
1207 | }
|
---|
1208 | } else if ( tagName == QString("class") ) {
|
---|
1209 | QString gtkClass = getTextValue( n );
|
---|
1210 | if ( gtkClass.endsWith(QString("Tree")) )
|
---|
1211 | emitProperty( QString("rootIsDecorated"), QVariant(TRUE, 0) );
|
---|
1212 | } else if ( tagName == QString("selection_mode") ) {
|
---|
1213 | emitProperty( QString("selectionMode"),
|
---|
1214 | gtk2qtSelectionMode(getTextValue(n)) );
|
---|
1215 | }
|
---|
1216 | n = n.nextSibling();
|
---|
1217 | }
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | void Glade2Ui::emitGtkScrolledWindowChildWidgets(
|
---|
1221 | const QValueList<QDomElement>& childWidgets, const QString& qtClass )
|
---|
1222 | {
|
---|
1223 | if ( childWidgets.count() == 1 ) {
|
---|
1224 | if ( qtClass == QString("QIconView") ||
|
---|
1225 | qtClass == QString("QListBox") ||
|
---|
1226 | qtClass == QString("QListView") ) {
|
---|
1227 | QDomNode n = childWidgets.first().firstChild();
|
---|
1228 | while ( !n.isNull() ) {
|
---|
1229 | QString tagName = n.toElement().tagName();
|
---|
1230 | if ( tagName == QString("selection_mode") ) {
|
---|
1231 | emitProperty( QString("selectionMode"),
|
---|
1232 | gtk2qtSelectionMode(getTextValue(n)) );
|
---|
1233 | }
|
---|
1234 | n = n.nextSibling();
|
---|
1235 | }
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | if ( qtClass == QString("QListView") ) {
|
---|
1239 | emitQListViewColumns( childWidgets.first() );
|
---|
1240 | } else if ( qtClass == QString("QTextEdit") ||
|
---|
1241 | qtClass == QString("QTextView") ) {
|
---|
1242 | QDomNode n = childWidgets.first().firstChild();
|
---|
1243 | while ( !n.isNull() ) {
|
---|
1244 | QString tagName = n.toElement().tagName();
|
---|
1245 | if ( tagName == QString("text") )
|
---|
1246 | emitProperty( QString("text"), getTextValue(n) );
|
---|
1247 | n = n.nextSibling();
|
---|
1248 | }
|
---|
1249 | }
|
---|
1250 | }
|
---|
1251 | }
|
---|
1252 |
|
---|
1253 | void Glade2Ui::emitGnomeDruidPage( const QDomElement& druidPage )
|
---|
1254 | {
|
---|
1255 | QValueList<QDomElement> childWidgets;
|
---|
1256 | QString gtkClass;
|
---|
1257 | QString logoImage;
|
---|
1258 | QString name;
|
---|
1259 | QString text;
|
---|
1260 | QString title;
|
---|
1261 | QString watermarkImage;
|
---|
1262 |
|
---|
1263 | emitOpeningWidget( QString("QWidget") );
|
---|
1264 |
|
---|
1265 | QDomNode n = druidPage.firstChild();
|
---|
1266 | while ( !n.isNull() ) {
|
---|
1267 | QString tagName = n.toElement().tagName();
|
---|
1268 | if ( tagName == QString("class") ) {
|
---|
1269 | gtkClass = getTextValue( n );
|
---|
1270 | } else if ( tagName == QString("logo_image") ) {
|
---|
1271 | logoImage = getTextValue( n );
|
---|
1272 | } else if ( tagName == QString("name") ) {
|
---|
1273 | name = getTextValue( n );
|
---|
1274 | } else if ( tagName == QString("text") ) {
|
---|
1275 | text = getTextValue( n );
|
---|
1276 | } else if ( tagName == QString("title") ) {
|
---|
1277 | title = getTextValue( n );
|
---|
1278 | } else if ( tagName == QString("watermark_image") ) {
|
---|
1279 | watermarkImage = getTextValue( n );
|
---|
1280 | } else if ( tagName == QString("widget") ) {
|
---|
1281 | childWidgets.push_back( n.toElement() );
|
---|
1282 | }
|
---|
1283 | n = n.nextSibling();
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | if ( !name.isEmpty() )
|
---|
1287 | emitProperty( QString("name"), fixedName(name).latin1() );
|
---|
1288 | if ( title.isEmpty() )
|
---|
1289 | title = QString( "Page" );
|
---|
1290 | emitAttribute( QString("title"), title );
|
---|
1291 |
|
---|
1292 | /*
|
---|
1293 | We're striving to get the logoImage and/or the watermarkImage at
|
---|
1294 | the right places with a grid layout.
|
---|
1295 | */
|
---|
1296 | int leftAttach = 0;
|
---|
1297 | int rightAttach = 0;
|
---|
1298 | int topAttach = 0;
|
---|
1299 | int bottomAttach = 0;
|
---|
1300 |
|
---|
1301 | int numImages = 0;
|
---|
1302 | if ( !logoImage.isEmpty() ) {
|
---|
1303 | topAttach = 1;
|
---|
1304 | numImages++;
|
---|
1305 | }
|
---|
1306 | if ( !watermarkImage.isEmpty() ) {
|
---|
1307 | leftAttach = 1;
|
---|
1308 | numImages++;
|
---|
1309 | }
|
---|
1310 | rightAttach = leftAttach + numImages;
|
---|
1311 | bottomAttach = topAttach + numImages;
|
---|
1312 |
|
---|
1313 | bool layouted = ( numImages > 0 );
|
---|
1314 | if ( layouted ) {
|
---|
1315 | emitOpening( QString("grid") );
|
---|
1316 | if ( !logoImage.isEmpty() )
|
---|
1317 | emitPixmap( imageName(logoImage), numImages, numImages + 1, 0, 1 );
|
---|
1318 | if ( !watermarkImage.isEmpty() )
|
---|
1319 | emitPixmap( imageName(watermarkImage), 0, 1, numImages,
|
---|
1320 | numImages + 1 );
|
---|
1321 | } else {
|
---|
1322 | leftAttach = -1;
|
---|
1323 | rightAttach = -1;
|
---|
1324 | topAttach = -1;
|
---|
1325 | bottomAttach = -1;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | if ( gtkClass.endsWith(QString("Standard")) ) {
|
---|
1329 | emitChildWidgets( childWidgets, layouted, leftAttach, rightAttach,
|
---|
1330 | topAttach, bottomAttach );
|
---|
1331 | } else if ( !text.isEmpty() ) {
|
---|
1332 | if ( layouted )
|
---|
1333 | emitOpeningWidget( QString("QLayoutWidget"), leftAttach,
|
---|
1334 | rightAttach, topAttach, bottomAttach );
|
---|
1335 | emitOpening( QString("hbox") );
|
---|
1336 | emitSpacer( QString("Horizontal") );
|
---|
1337 | emitOpeningWidget( QString("QLabel") );
|
---|
1338 | emitProperty( QString("text"), text );
|
---|
1339 | emitClosing( QString("widget") );
|
---|
1340 | emitSpacer( QString("Horizontal") );
|
---|
1341 | emitClosing( QString("hbox") );
|
---|
1342 | if ( layouted )
|
---|
1343 | emitClosing( QString("widget") );
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | if ( layouted )
|
---|
1347 | emitClosing( QString("grid") );
|
---|
1348 | emitClosing( QString("widget") );
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | void Glade2Ui::emitGtkWindowChildWidgets(
|
---|
1352 | const QValueList<QDomElement>& childWidgets, const QString& qtClass )
|
---|
1353 | {
|
---|
1354 | if ( childWidgets.count() == 1 && qtClass == QString("QWizard") ) {
|
---|
1355 | emitFontProperty( QString("titleFont"), 18, FALSE );
|
---|
1356 |
|
---|
1357 | QDomNode n = childWidgets.first().firstChild();
|
---|
1358 | while ( !n.isNull() ) {
|
---|
1359 | if ( n.toElement().tagName() == QString("widget") )
|
---|
1360 | emitGnomeDruidPage( n.toElement() );
|
---|
1361 | n = n.nextSibling();
|
---|
1362 | }
|
---|
1363 | } else {
|
---|
1364 | emitChildWidgets( childWidgets, FALSE );
|
---|
1365 | }
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | bool Glade2Ui::packEnd( const QDomElement& widget )
|
---|
1369 | {
|
---|
1370 | QDomNode n = widget.firstChild();
|
---|
1371 | while ( !n.isNull() ) {
|
---|
1372 | if ( n.toElement().tagName() == QString("child") ) {
|
---|
1373 | QDomNode child = n.firstChild();
|
---|
1374 | while ( !child.isNull() ) {
|
---|
1375 | if ( child.toElement().tagName() == QString("pack") ) {
|
---|
1376 | QString pack = getTextValue( child );
|
---|
1377 | return pack.endsWith( QString("_END") );
|
---|
1378 | }
|
---|
1379 | child = child.nextSibling();
|
---|
1380 | }
|
---|
1381 | }
|
---|
1382 | n = n.nextSibling();
|
---|
1383 | }
|
---|
1384 | return FALSE;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | void Glade2Ui::emitChildWidgets( const QValueList<QDomElement>& childWidgets,
|
---|
1388 | bool layouted, int leftAttach, int rightAttach,
|
---|
1389 | int topAttach, int bottomAttach )
|
---|
1390 | {
|
---|
1391 | QValueList<QDomElement> start;
|
---|
1392 | QValueList<QDomElement> end;
|
---|
1393 | QValueList<QDomElement>::ConstIterator e;
|
---|
1394 |
|
---|
1395 | if ( layouted ) {
|
---|
1396 | e = childWidgets.begin();
|
---|
1397 | while ( e != childWidgets.end() ) {
|
---|
1398 | if ( packEnd(*e) )
|
---|
1399 | end.push_front( *e );
|
---|
1400 | else
|
---|
1401 | start.push_back( *e );
|
---|
1402 | ++e;
|
---|
1403 | }
|
---|
1404 | } else {
|
---|
1405 | start = childWidgets;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | e = start.begin();
|
---|
1409 | while ( e != start.end() ) {
|
---|
1410 | emitWidget( *e, layouted, leftAttach, rightAttach, topAttach,
|
---|
1411 | bottomAttach );
|
---|
1412 | ++e;
|
---|
1413 | }
|
---|
1414 | e = end.begin();
|
---|
1415 | while ( e != end.end() ) {
|
---|
1416 | emitWidget( *e, layouted, leftAttach, rightAttach, topAttach,
|
---|
1417 | bottomAttach );
|
---|
1418 | ++e;
|
---|
1419 | }
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | void Glade2Ui::emitOpeningWidget( const QString& qtClass, int leftAttach,
|
---|
1423 | int rightAttach, int topAttach,
|
---|
1424 | int bottomAttach )
|
---|
1425 | {
|
---|
1426 | AttributeMap attr = attribute( QString("class"), qtClass );
|
---|
1427 | attach( &attr, leftAttach, rightAttach, topAttach, bottomAttach );
|
---|
1428 | emitOpening( QString("widget"), attr );
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | /*
|
---|
1432 | Returns TRUE if the vbox containing childWidgets should have a
|
---|
1433 | spacer at the end to prevent it from looking bad, otherwise returns
|
---|
1434 | FALSE.
|
---|
1435 |
|
---|
1436 | The algorithm is very experimental.
|
---|
1437 | */
|
---|
1438 | bool Glade2Ui::shouldPullup( const QValueList<QDomElement>& childWidgets )
|
---|
1439 | {
|
---|
1440 | QRegExp gtkSmallWidget( QString(
|
---|
1441 | "G.*(?:Button|Combo|Dial|Entry|Label|OptionMenu|Picker|ProgressBar"
|
---|
1442 | "|Separator|Statusbar|Toolbar|VBox)") );
|
---|
1443 |
|
---|
1444 | QValueList<QDomElement>::ConstIterator c = childWidgets.begin();
|
---|
1445 | while ( c != childWidgets.end() ) {
|
---|
1446 | QValueList<QDomElement> grandchildWidgets;
|
---|
1447 | QString gtkClass;
|
---|
1448 |
|
---|
1449 | QDomNode n = (*c).firstChild();
|
---|
1450 | while ( !n.isNull() ) {
|
---|
1451 | QString tagName = n.toElement().tagName();
|
---|
1452 | if ( tagName == QString("class") ) {
|
---|
1453 | gtkClass = getTextValue( n );
|
---|
1454 | } else if ( tagName == QString("widget") ) {
|
---|
1455 | grandchildWidgets.push_back( n.toElement() );
|
---|
1456 | }
|
---|
1457 | n = n.nextSibling();
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | if ( !gtkSmallWidget.exactMatch(gtkClass) ||
|
---|
1461 | !shouldPullup(grandchildWidgets) )
|
---|
1462 | return FALSE;
|
---|
1463 | ++c;
|
---|
1464 | }
|
---|
1465 | return TRUE;
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | QString Glade2Ui::emitWidget( const QDomElement& widget, bool layouted,
|
---|
1469 | int leftAttach, int rightAttach, int topAttach,
|
---|
1470 | int bottomAttach )
|
---|
1471 | {
|
---|
1472 | QRegExp gtkLayoutWidget( QString(
|
---|
1473 | "Gtk(?:Packer|Table|Toolbar|[HV](?:(?:Button)?Box))") );
|
---|
1474 | QRegExp gtkOrientedWidget( QString(
|
---|
1475 | "Gtk([HV])(?:Paned|Scale|Scrollbar|Separator)") );
|
---|
1476 |
|
---|
1477 | QValueList<QDomElement> childWidgets;
|
---|
1478 | QString gtkClass;
|
---|
1479 | QString name;
|
---|
1480 | QString title;
|
---|
1481 | int x = 0;
|
---|
1482 | int y = 0;
|
---|
1483 | int width = 0;
|
---|
1484 | int height = 0;
|
---|
1485 | int numRows = 0;
|
---|
1486 | int numColumns = 0;
|
---|
1487 |
|
---|
1488 | bool active = FALSE;
|
---|
1489 | QString authors;
|
---|
1490 | QString childName;
|
---|
1491 | QString comments;
|
---|
1492 | QString copyright;
|
---|
1493 | QString creationFunction;
|
---|
1494 | bool editable = TRUE;
|
---|
1495 | QString filename;
|
---|
1496 | QString focusTarget;
|
---|
1497 | QString hscrollbarPolicy;
|
---|
1498 | QString icon;
|
---|
1499 | int initialChoice = 0;
|
---|
1500 | QStringList items;
|
---|
1501 | QString justify;
|
---|
1502 | QString label;
|
---|
1503 | QString logoImage;
|
---|
1504 | int lower = -123456789;
|
---|
1505 | int page = 10;
|
---|
1506 | int pageSize = 10;
|
---|
1507 | QString selectionMode;
|
---|
1508 | QString shadowType( "GTK_SHADOW_NONE" );
|
---|
1509 | bool showText = TRUE;
|
---|
1510 | bool showTitles = TRUE;
|
---|
1511 | int step = 1;
|
---|
1512 | QString tabPos;
|
---|
1513 | QString text;
|
---|
1514 | int textMaxLength = 0;
|
---|
1515 | bool textVisible = TRUE;
|
---|
1516 | QString tooltip;
|
---|
1517 | QString type;
|
---|
1518 | int upper = 123456789;
|
---|
1519 | int value = 123456789;
|
---|
1520 | bool valueInList = TRUE;
|
---|
1521 | QString vscrollbarPolicy;
|
---|
1522 | QString watermarkImage;
|
---|
1523 | bool wrap = FALSE;
|
---|
1524 |
|
---|
1525 | bool topLevel = yyFormName.isEmpty();
|
---|
1526 | if ( topLevel )
|
---|
1527 | name = QString( "Form%1" ).arg( uniqueForm++ );
|
---|
1528 |
|
---|
1529 | QDomNode n = widget.firstChild();
|
---|
1530 | while ( !n.isNull() ) {
|
---|
1531 | QString tagName = n.toElement().tagName();
|
---|
1532 | if ( !tagName.isEmpty() ) {
|
---|
1533 | /*
|
---|
1534 | Recognize the properties and stores them in variables.
|
---|
1535 | This step is a bit silly, and if this function were to
|
---|
1536 | be rewritten, almost everything would just be stored, as
|
---|
1537 | strings, in a giant map, and looked up for when emitting
|
---|
1538 | the properties.
|
---|
1539 | */
|
---|
1540 | switch ( (uchar) tagName[0].cell() ) {
|
---|
1541 | case 'a':
|
---|
1542 | if ( tagName == QString("active") ) {
|
---|
1543 | active = isTrue( getTextValue(n) );
|
---|
1544 | } else if ( tagName == QString("authors") ) {
|
---|
1545 | authors = getTextValue( n );
|
---|
1546 | }
|
---|
1547 | break;
|
---|
1548 | case 'c':
|
---|
1549 | if ( tagName == QString("child") ) {
|
---|
1550 | QDomNode child = n.firstChild();
|
---|
1551 | while ( !child.isNull() ) {
|
---|
1552 | QString childTagName = child.toElement().tagName();
|
---|
1553 | if ( childTagName == QString("left_attach") ) {
|
---|
1554 | leftAttach = getTextValue( child ).toInt();
|
---|
1555 | } else if ( childTagName == QString("right_attach") ) {
|
---|
1556 | rightAttach = getTextValue( child ).toInt();
|
---|
1557 | } else if ( childTagName == QString("top_attach") ) {
|
---|
1558 | topAttach = getTextValue( child ).toInt();
|
---|
1559 | } else if ( childTagName == QString("bottom_attach") ) {
|
---|
1560 | bottomAttach = getTextValue( child ).toInt();
|
---|
1561 | }
|
---|
1562 | child = child.nextSibling();
|
---|
1563 | }
|
---|
1564 | } else if ( tagName == QString("child_name") ) {
|
---|
1565 | childName = getTextValue( n );
|
---|
1566 | } else if ( tagName == QString("class") ) {
|
---|
1567 | gtkClass = getTextValue( n );
|
---|
1568 | } else if ( tagName == QString("climb_rate") ) {
|
---|
1569 | step = getTextValue( n ).toInt();
|
---|
1570 | } else if ( tagName == QString("columns") ) {
|
---|
1571 | numColumns = getTextValue( n ).toInt();
|
---|
1572 | } else if ( tagName == QString("comments") ) {
|
---|
1573 | comments = getTextValue( n );
|
---|
1574 | } else if ( tagName == QString("copyright") ) {
|
---|
1575 | copyright = getTextValue( n );
|
---|
1576 | } else if ( tagName == QString("creation_function") ) {
|
---|
1577 | creationFunction = getTextValue( n );
|
---|
1578 | }
|
---|
1579 | break;
|
---|
1580 | case 'd':
|
---|
1581 | if ( tagName == QString("default_focus_target") ) {
|
---|
1582 | if ( focusTarget.isEmpty() )
|
---|
1583 | focusTarget = getTextValue( n );
|
---|
1584 | }
|
---|
1585 | break;
|
---|
1586 | case 'e':
|
---|
1587 | if ( tagName == QString("editable") )
|
---|
1588 | editable = isTrue( getTextValue(n) );
|
---|
1589 | break;
|
---|
1590 | case 'f':
|
---|
1591 | if ( tagName == QString("filename") ) {
|
---|
1592 | filename = getTextValue( n );
|
---|
1593 | } else if ( tagName == QString("focus_target") ) {
|
---|
1594 | focusTarget = getTextValue( n );
|
---|
1595 | }
|
---|
1596 | break;
|
---|
1597 | case 'h':
|
---|
1598 | if ( tagName == QString("height") ) {
|
---|
1599 | height = getTextValue( n ).toInt();
|
---|
1600 | } else if ( tagName == QString("hscrollbar_policy") ) {
|
---|
1601 | hscrollbarPolicy = getTextValue( n );
|
---|
1602 | }
|
---|
1603 | break;
|
---|
1604 | case 'i':
|
---|
1605 | if ( tagName == QString("icon") ) {
|
---|
1606 | icon = getTextValue( n );
|
---|
1607 | } else if ( tagName == QString("initial_choice") ) {
|
---|
1608 | initialChoice = getTextValue( n ).toInt();
|
---|
1609 | } else if ( tagName == QString("items") ) {
|
---|
1610 | items = QStringList::split( QChar('\n'), getTextValue(n) );
|
---|
1611 | }
|
---|
1612 | break;
|
---|
1613 | case 'j':
|
---|
1614 | if ( tagName == QString("justify") )
|
---|
1615 | justify = getTextValue( n );
|
---|
1616 | break;
|
---|
1617 | case 'l':
|
---|
1618 | if ( tagName == QString("label") ) {
|
---|
1619 | label = getTextValue( n );
|
---|
1620 | } else if ( tagName == QString("logo_image") ) {
|
---|
1621 | logoImage = getTextValue( n );
|
---|
1622 | } else if ( tagName == QString("lower") ) {
|
---|
1623 | lower = getTextValue( n ).toInt();
|
---|
1624 | }
|
---|
1625 | break;
|
---|
1626 | case 'n':
|
---|
1627 | if ( tagName == QString("name") )
|
---|
1628 | name = getTextValue( n );
|
---|
1629 | break;
|
---|
1630 | case 'p':
|
---|
1631 | if ( tagName == QString("page") ) {
|
---|
1632 | page = getTextValue( n ).toInt();
|
---|
1633 | } else if ( tagName == QString("page_size") ) {
|
---|
1634 | pageSize = getTextValue( n ).toInt();
|
---|
1635 | }
|
---|
1636 | break;
|
---|
1637 | case 'r':
|
---|
1638 | if ( tagName == QString("rows") )
|
---|
1639 | numRows = getTextValue( n ).toInt();
|
---|
1640 | break;
|
---|
1641 | case 's':
|
---|
1642 | if ( tagName == QString("selection_mode") ) {
|
---|
1643 | selectionMode = getTextValue( n );
|
---|
1644 | } else if ( tagName == QString("shadow_type") ) {
|
---|
1645 | shadowType = getTextValue( n );
|
---|
1646 | } else if ( tagName == QString("show_text") ) {
|
---|
1647 | showText = isTrue( getTextValue(n) );
|
---|
1648 | } else if ( tagName == QString(QString("show_titles")) ) {
|
---|
1649 | showTitles = isTrue( getTextValue(n) );
|
---|
1650 | } else if ( tagName == QString("step") ) {
|
---|
1651 | step = getTextValue( n ).toInt();
|
---|
1652 | } else if ( tagName == QString("stock_button") ) {
|
---|
1653 | /*
|
---|
1654 | Let's cheat: We convert the symbolic name into a
|
---|
1655 | button label.
|
---|
1656 | */
|
---|
1657 | label = getTextValue( n );
|
---|
1658 | int k = label.findRev( QChar('_') );
|
---|
1659 | if ( k != -1 )
|
---|
1660 | label = label.mid( k + 1 );
|
---|
1661 | if ( !label.isEmpty() && label != QString("OK") )
|
---|
1662 | label = label.left( 1 ) + label.mid( 1 ).lower();
|
---|
1663 | }
|
---|
1664 | break;
|
---|
1665 | case 't':
|
---|
1666 | if ( tagName == QString("tab_pos") ) {
|
---|
1667 | tabPos = getTextValue( n );
|
---|
1668 | } else if ( tagName == QString("text") ) {
|
---|
1669 | text = getTextValue( n );
|
---|
1670 | } else if ( tagName == QString("textMaxLength") ) {
|
---|
1671 | textMaxLength = getTextValue( n ).toInt();
|
---|
1672 | } else if ( tagName == QString("textVisible") ) {
|
---|
1673 | textVisible = isTrue( getTextValue(n) );
|
---|
1674 | } else if ( tagName == QString("title") ) {
|
---|
1675 | title = getTextValue( n );
|
---|
1676 | } else if ( tagName == QString("tooltip") ) {
|
---|
1677 | tooltip = getTextValue( n );
|
---|
1678 | } else if ( tagName == QString("type") ) {
|
---|
1679 | type = getTextValue( n );
|
---|
1680 | }
|
---|
1681 | break;
|
---|
1682 | case 'u':
|
---|
1683 | if ( tagName == QString("upper") )
|
---|
1684 | upper = getTextValue( n ).toInt();
|
---|
1685 | break;
|
---|
1686 | case 'v':
|
---|
1687 | if ( tagName == QString("value") ) {
|
---|
1688 | value = getTextValue( n ).toInt();
|
---|
1689 | } else if ( tagName == QString("value_in_list") ) {
|
---|
1690 | valueInList = isTrue( getTextValue(n) );
|
---|
1691 | } else if ( tagName == QString("vscrollbar_policy") ) {
|
---|
1692 | vscrollbarPolicy = getTextValue( n );
|
---|
1693 | }
|
---|
1694 | break;
|
---|
1695 | case 'w':
|
---|
1696 | if ( tagName == QString("watermark_image") ) {
|
---|
1697 | watermarkImage = getTextValue( n );
|
---|
1698 | } else if ( tagName == QString("widget") )
|
---|
1699 | childWidgets.push_back( n.toElement() );
|
---|
1700 | else if ( tagName == QString("width") )
|
---|
1701 | width = getTextValue( n ).toInt();
|
---|
1702 | else if ( tagName == QString("wrap") )
|
---|
1703 | wrap = isTrue( getTextValue(n) );
|
---|
1704 | break;
|
---|
1705 | case 'x':
|
---|
1706 | if ( tagName == QString("x") )
|
---|
1707 | x = getTextValue( n ).toInt();
|
---|
1708 | break;
|
---|
1709 | case 'y':
|
---|
1710 | if ( tagName == QString("y") )
|
---|
1711 | y = getTextValue( n ).toInt();
|
---|
1712 | }
|
---|
1713 | }
|
---|
1714 | n = n.nextSibling();
|
---|
1715 | }
|
---|
1716 |
|
---|
1717 | if ( topLevel ) {
|
---|
1718 | yyFormName = name;
|
---|
1719 | emitSimpleValue( QString("class"), yyFormName );
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | if ( gtkLayoutWidget.exactMatch(gtkClass) ) {
|
---|
1723 | QString boxKind;
|
---|
1724 | QString orientation;
|
---|
1725 |
|
---|
1726 | if ( gtkClass.startsWith(QString("GtkH")) ||
|
---|
1727 | gtkClass == QString(QString("GtkToolbar")) ) {
|
---|
1728 | /*
|
---|
1729 | GtkToolbar, right. Toolbars may appear anywhere in a
|
---|
1730 | widget, but then they really are just a row of buttons.
|
---|
1731 | */
|
---|
1732 | boxKind = QString( "hbox" );
|
---|
1733 | orientation = QString( "Horizontal" );
|
---|
1734 | } else if ( gtkClass.startsWith(QString("GtkV")) ||
|
---|
1735 | gtkClass == QString("GtkPacker") ) {
|
---|
1736 | /*
|
---|
1737 | We don't support the GtkPacker, whose trails lead to
|
---|
1738 | destruction.
|
---|
1739 | */
|
---|
1740 | boxKind = QString( "vbox" );
|
---|
1741 | orientation = QString( "Vertical" );
|
---|
1742 | } else {
|
---|
1743 | boxKind = QString( "grid" );
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | if ( layouted )
|
---|
1747 | emitOpeningWidget( QString("QLayoutWidget"), leftAttach,
|
---|
1748 | rightAttach, topAttach, bottomAttach );
|
---|
1749 | emitOpening( boxKind );
|
---|
1750 | emitProperty( QString("name"), fixedName(name).latin1() );
|
---|
1751 | if ( gtkClass == QString("GtkHButtonBox") ||
|
---|
1752 | childName == QString("Dialog:action_area") )
|
---|
1753 | emitSpacer( orientation );
|
---|
1754 | emitChildWidgets( childWidgets, TRUE );
|
---|
1755 |
|
---|
1756 | if ( gtkClass == QString("GtkVButtonBox") ||
|
---|
1757 | childName == QString("Dialog:action_area") ||
|
---|
1758 | (boxKind == QString("vbox") && shouldPullup(childWidgets)) ) {
|
---|
1759 | emitSpacer( orientation );
|
---|
1760 | } else if ( boxKind == QString("grid") && shouldPullup(childWidgets) ) {
|
---|
1761 | emitSpacer( QString("Vertical"), 0, numColumns, numRows,
|
---|
1762 | numRows + 1 );
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | emitClosing( boxKind );
|
---|
1766 | if ( layouted )
|
---|
1767 | emitClosing( QString("widget") );
|
---|
1768 | } else if ( gtkClass == QString("GtkFixed") && !layouted ) {
|
---|
1769 | emitChildWidgets( childWidgets, FALSE );
|
---|
1770 | /*
|
---|
1771 | Placeholders in a grid are typically needless.
|
---|
1772 | */
|
---|
1773 | } else if ( !(leftAttach >= 0 && gtkClass == QString("Placeholder")) ) {
|
---|
1774 | bool needFakeLayout = ( !layouted && !topLevel && x == 0 && y == 0 &&
|
---|
1775 | width == 0 && height == 0 );
|
---|
1776 | QString qtClass = gtk2qtClass( gtkClass, childWidgets );
|
---|
1777 | bool unknown = FALSE;
|
---|
1778 |
|
---|
1779 | if ( qtClass == QString("QFrame") && !label.isEmpty() ) {
|
---|
1780 | qtClass = QString( "QButtonGroup" );
|
---|
1781 | } else if ( qtClass == QString("QListView") && !showTitles &&
|
---|
1782 | gtkClass.endsWith(QString("List")) ) {
|
---|
1783 | qtClass = QString( "QListBox" );
|
---|
1784 | } else if ( qtClass == QString("Custom") ) {
|
---|
1785 | qtClass = creationFunction;
|
---|
1786 | yyCustomWidgets.insert( qtClass, QString::null );
|
---|
1787 | } else if ( qtClass == QString("Unknown") ) {
|
---|
1788 | qtClass = QString( "QLabel" );
|
---|
1789 | unknown = TRUE;
|
---|
1790 | }
|
---|
1791 |
|
---|
1792 | if ( qtClass.isEmpty() ) {
|
---|
1793 | emitChildWidgets( childWidgets, layouted, leftAttach, rightAttach,
|
---|
1794 | topAttach, bottomAttach );
|
---|
1795 | } else {
|
---|
1796 | if ( needFakeLayout ) {
|
---|
1797 | emitOpening( QString("vbox") );
|
---|
1798 | emitProperty( QString("margin"), 11 );
|
---|
1799 | }
|
---|
1800 | emitOpeningWidget( qtClass, leftAttach, rightAttach, topAttach,
|
---|
1801 | bottomAttach );
|
---|
1802 |
|
---|
1803 | // grep 'elsewhere'
|
---|
1804 | if ( gtkClass != QString("GtkCombo") )
|
---|
1805 | emitProperty( QString("name"), fixedName(name).latin1() );
|
---|
1806 | if ( !title.isEmpty() )
|
---|
1807 | emitProperty( QString("caption"), title );
|
---|
1808 | if ( !layouted && (x != 0 || y != 0 || width != 0 || height != 0) )
|
---|
1809 | emitProperty( QString("geometry"), QRect(x, y, width, height) );
|
---|
1810 | if ( gtkClass == QString("GtkToggleButton") ) {
|
---|
1811 | emitProperty( QString("toggleButton"), QVariant(TRUE, 0) );
|
---|
1812 | if ( active )
|
---|
1813 | emitProperty( QString("on"), QVariant(TRUE, 0) );
|
---|
1814 | } else {
|
---|
1815 | if ( active )
|
---|
1816 | emitProperty( QString("checked"), QVariant(TRUE, 0) );
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 | if ( !editable )
|
---|
1820 | emitProperty( QString("readOnly"), QVariant(TRUE, 0) );
|
---|
1821 | if ( !focusTarget.isEmpty() )
|
---|
1822 | emitProperty( QString("buddy"),
|
---|
1823 | fixedName(focusTarget).latin1() );
|
---|
1824 | if ( !hscrollbarPolicy.isEmpty() )
|
---|
1825 | emitProperty( QString("hScrollBarMode"),
|
---|
1826 | gtk2qtScrollBarMode(hscrollbarPolicy),
|
---|
1827 | QString("enum") );
|
---|
1828 | if ( !vscrollbarPolicy.isEmpty() )
|
---|
1829 | emitProperty( QString("vScrollBarMode"),
|
---|
1830 | gtk2qtScrollBarMode(vscrollbarPolicy),
|
---|
1831 | QString("enum") );
|
---|
1832 | if ( !justify.isEmpty() ||
|
---|
1833 | (wrap && gtkClass != QString("GtkSpinButton")) ) {
|
---|
1834 | QStringList flags;
|
---|
1835 | if ( wrap )
|
---|
1836 | flags.push_back( QString("WordBreak") );
|
---|
1837 |
|
---|
1838 | if ( justify.endsWith(QString("_CENTER")) ) {
|
---|
1839 | flags.push_back( QString("AlignCenter") );
|
---|
1840 | } else {
|
---|
1841 | if ( justify.endsWith(QString("_RIGHT")) )
|
---|
1842 | flags.push_back( QString("AlignRight") );
|
---|
1843 | flags.push_back( QString("AlignVCenter") );
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | if ( !flags.isEmpty() )
|
---|
1847 | emitProperty( QString("alignment"), flags.join(QChar('|')),
|
---|
1848 | QString("set") );
|
---|
1849 | }
|
---|
1850 | if ( !label.isEmpty() ) {
|
---|
1851 | if ( gtkClass.endsWith(QString("Frame")) ) {
|
---|
1852 | emitProperty( QString("title"), label );
|
---|
1853 | } else {
|
---|
1854 | emitProperty( QString("text"), accelerate(label) );
|
---|
1855 | }
|
---|
1856 | }
|
---|
1857 | if ( lower != -123456789 )
|
---|
1858 | emitProperty( QString("minValue"), lower );
|
---|
1859 | if ( upper != 123456789 )
|
---|
1860 | emitProperty( QString("maxValue"), upper );
|
---|
1861 | if ( value != 123456789 ) {
|
---|
1862 | if ( gtkClass == QString("GtkProgressBar") ) {
|
---|
1863 | emitProperty( QString("progress"), value );
|
---|
1864 | } else {
|
---|
1865 | emitProperty( QString("value"), value );
|
---|
1866 | }
|
---|
1867 | }
|
---|
1868 | if ( QMAX(page, pageSize) != 10 &&
|
---|
1869 | gtkClass.endsWith(QString("Scrollbar")) )
|
---|
1870 | emitProperty( QString("pageStep"), QMAX(page, pageSize) );
|
---|
1871 | if ( !selectionMode.isEmpty() )
|
---|
1872 | emitProperty( QString("selectionMode"),
|
---|
1873 | gtk2qtSelectionMode(selectionMode),
|
---|
1874 | QString("enum") );
|
---|
1875 | if ( !shadowType.endsWith(QString("_NONE")) ) {
|
---|
1876 | QString shape = shadowType.contains( QString("_ETCHED_") ) > 0 ?
|
---|
1877 | QString( "Box" ) : QString( "WinPanel" );
|
---|
1878 | QString shadow = shadowType.endsWith( QString("_IN") ) ?
|
---|
1879 | QString( "Sunken" ) : QString( "Raised" );
|
---|
1880 | emitProperty( QString("frameShape"), shape, QString("enum") );
|
---|
1881 | emitProperty( QString("frameShadow"), shadow, QString("enum") );
|
---|
1882 | }
|
---|
1883 | if ( !showText )
|
---|
1884 | emitProperty( QString("percentageVisible"),
|
---|
1885 | QVariant(FALSE, 0) );
|
---|
1886 | if ( step != 1 )
|
---|
1887 | emitProperty( QString("lineStep"), step );
|
---|
1888 | if ( tabPos.endsWith(QString("_BOTTOM")) ||
|
---|
1889 | tabPos.endsWith(QString("_RIGHT")) )
|
---|
1890 | emitProperty( QString("tabPosition"), QString("Bottom") );
|
---|
1891 | if ( !text.isEmpty() )
|
---|
1892 | emitProperty( QString("text"), text );
|
---|
1893 | if ( textMaxLength != 0 )
|
---|
1894 | emitProperty( QString("maxLength"), textMaxLength );
|
---|
1895 | if ( !textVisible )
|
---|
1896 | emitProperty( QString("echoMode"), QString("Password"),
|
---|
1897 | QString("enum") );
|
---|
1898 | if ( !tooltip.isEmpty() )
|
---|
1899 | emitProperty( QString("toolTip"), tooltip );
|
---|
1900 | if ( !valueInList )
|
---|
1901 | emitProperty( QString("editable"), QVariant(TRUE, 0) );
|
---|
1902 | if ( wrap && gtkClass == QString("GtkSpinButton") )
|
---|
1903 | emitProperty( QString("wrapping"), QVariant(TRUE, 0) );
|
---|
1904 |
|
---|
1905 | if ( gtkClass.endsWith(QString("Tree")) ) {
|
---|
1906 | emitProperty( QString("rootIsDecorated"), QVariant(TRUE, 0) );
|
---|
1907 | } else if ( gtkOrientedWidget.exactMatch(gtkClass) ) {
|
---|
1908 | QString s = ( gtkOrientedWidget.cap(1) == QChar('H') ) ?
|
---|
1909 | QString( "Horizontal" ) : QString( "Vertical" );
|
---|
1910 | emitProperty( QString("orientation"), s, QString("enum") );
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | if ( qtClass == QString("QListView") )
|
---|
1914 | emitProperty( QString("resizeMode"), QString("AllColumns"),
|
---|
1915 | QString("enum") );
|
---|
1916 |
|
---|
1917 | while ( !items.isEmpty() ) {
|
---|
1918 | emitOpening( QString("item") );
|
---|
1919 | emitProperty( QString("text"), items.first() );
|
---|
1920 | emitClosing( QString("item") );
|
---|
1921 | items.remove( items.begin() );
|
---|
1922 | }
|
---|
1923 | if ( initialChoice != 0 )
|
---|
1924 | emitProperty( QString("currentItem"), initialChoice );
|
---|
1925 |
|
---|
1926 | if ( !icon.isEmpty() )
|
---|
1927 | emitProperty( QString("pixmap"), imageName(icon),
|
---|
1928 | QString("pixmap") );
|
---|
1929 |
|
---|
1930 | if ( gtkClass == QString("GnomeAbout") ) {
|
---|
1931 | emitGnomeAbout( copyright, authors, comments );
|
---|
1932 | } else if ( gtkClass == QString("GnomeApp") ) {
|
---|
1933 | emitGnomeAppChildWidgetsPass1( childWidgets );
|
---|
1934 | } else if ( gtkClass == QString("GnomePropertyBox") ) {
|
---|
1935 | emitOpening( QString("vbox") );
|
---|
1936 | emitChildWidgets( childWidgets, TRUE );
|
---|
1937 | emitOpeningWidget( QString("QLayoutWidget") );
|
---|
1938 | emitOpening( QString("hbox") );
|
---|
1939 | emitPushButton( QString("&Help"), QString("helpButton") );
|
---|
1940 | emitSpacer( QString("Horizontal") );
|
---|
1941 | emitPushButton( QString("&OK"), QString("okButton") );
|
---|
1942 | emitPushButton( QString("&Apply"), QString("applyButton") );
|
---|
1943 | emitPushButton( QString("&Close"), QString("closeButton") );
|
---|
1944 | emitClosing( QString("hbox") );
|
---|
1945 | emitClosing( QString("widget") );
|
---|
1946 | emitClosing( QString("vbox") );
|
---|
1947 | } else if ( gtkClass.endsWith(QString("Button")) ) {
|
---|
1948 | if ( label.isEmpty() )
|
---|
1949 | emitGtkButtonChildWidgets( childWidgets );
|
---|
1950 | } else if ( gtkClass == QString("GtkCombo") ) {
|
---|
1951 | emitGtkComboChildWidgets( childWidgets, items );
|
---|
1952 | } else if ( gtkClass == QString("GtkNotebook") ) {
|
---|
1953 | emitGtkNotebookChildWidgets( childWidgets );
|
---|
1954 | } else if ( gtkClass == QString("GtkWindow") ) {
|
---|
1955 | emitGtkWindowChildWidgets( childWidgets, qtClass );
|
---|
1956 | } else if ( gtkClass == QString("GtkScrolledWindow") ) {
|
---|
1957 | emitGtkScrolledWindowChildWidgets( childWidgets, qtClass );
|
---|
1958 | } else if ( qtClass == QString("QListView") ) {
|
---|
1959 | emitQListViewColumns( widget );
|
---|
1960 | } else if ( unknown || gtkClass == QString("Placeholder") ) {
|
---|
1961 | QString prefix;
|
---|
1962 | if ( unknown )
|
---|
1963 | prefix = gtkClass;
|
---|
1964 | emitProperty( QString("text"),
|
---|
1965 | QString("<font color=\"red\">%1<b>?</b></font>")
|
---|
1966 | .arg(prefix) );
|
---|
1967 | emitProperty( QString("alignment"),
|
---|
1968 | QString("AlignAuto|AlignCenter"),
|
---|
1969 | QString("set") );
|
---|
1970 | } else if ( qtClass != QString("QListBox") ) {
|
---|
1971 | emitChildWidgets( childWidgets, FALSE );
|
---|
1972 | }
|
---|
1973 |
|
---|
1974 | emitClosing( QString("widget") );
|
---|
1975 | if ( needFakeLayout )
|
---|
1976 | emitClosing( QString("vbox") );
|
---|
1977 | if ( gtkClass == QString("GnomeApp") )
|
---|
1978 | emitGnomeAppChildWidgetsPass2( childWidgets );
|
---|
1979 | }
|
---|
1980 | }
|
---|
1981 | return name;
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | QStringList Glade2Ui::convertGladeFile( const QString& fileName )
|
---|
1985 | {
|
---|
1986 | QStringList outFileNames;
|
---|
1987 |
|
---|
1988 | yyFileName = fileName;
|
---|
1989 |
|
---|
1990 | QDomDocument doc( QString("GTK-Interface") );
|
---|
1991 | QFile f( fileName );
|
---|
1992 | if ( !f.open(IO_ReadOnly) ) {
|
---|
1993 | error( QString("Cannot open file for reading.") );
|
---|
1994 | return QStringList();
|
---|
1995 | }
|
---|
1996 | if ( !doc.setContent(&f) ) {
|
---|
1997 | error( QString("File is not an XML file.") );
|
---|
1998 | f.close();
|
---|
1999 | return QStringList();
|
---|
2000 | }
|
---|
2001 | f.close();
|
---|
2002 |
|
---|
2003 | QDomElement root = doc.documentElement();
|
---|
2004 | if ( root.tagName() != QString("GTK-Interface") ) {
|
---|
2005 | error( QString("File is not a Glade XML file.") );
|
---|
2006 | return QStringList();
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | int widgetNo = 0;
|
---|
2010 | int numWidgets = 0;
|
---|
2011 | QDomNode n = root.firstChild();
|
---|
2012 | while ( !n.isNull() ) {
|
---|
2013 | if ( n.toElement().tagName() == QString("widget") )
|
---|
2014 | numWidgets++;
|
---|
2015 | n = n.nextSibling();
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | QProgressDialog fremskritt( QString("Converting Glade files..."),
|
---|
2019 | QString("Abort Conversion"), numWidgets, 0,
|
---|
2020 | "fremskritt", TRUE );
|
---|
2021 |
|
---|
2022 | n = root.firstChild();
|
---|
2023 | while ( !n.isNull() ) {
|
---|
2024 | QString tagName = n.toElement().tagName();
|
---|
2025 |
|
---|
2026 | if ( tagName == QString("project") ) {
|
---|
2027 | QDomNode child = n.firstChild();
|
---|
2028 | while ( !child.isNull() ) {
|
---|
2029 | QString childTagName = child.toElement().tagName();
|
---|
2030 | if ( childTagName == QString("pixmaps_directory") ) {
|
---|
2031 | yyPixmapDirectory = getTextValue( child );
|
---|
2032 | } else if ( childTagName == QString("program_name") ) {
|
---|
2033 | yyProgramName = getTextValue( child );
|
---|
2034 | }
|
---|
2035 | child = child.nextSibling();
|
---|
2036 | }
|
---|
2037 | } else if ( tagName == QString("widget") ) {
|
---|
2038 | yyOut = QString::null;
|
---|
2039 | yyCustomWidgets.clear();
|
---|
2040 | yyStockItemActions.clear();
|
---|
2041 | yyActions.clear();
|
---|
2042 | yyConnections.clear();
|
---|
2043 | yySlots.clear();
|
---|
2044 | yyFormName = QString::null;
|
---|
2045 | yyImages.clear();
|
---|
2046 |
|
---|
2047 | uniqueAction = 1;
|
---|
2048 | uniqueForm = 1;
|
---|
2049 | uniqueMenuBar = 1;
|
---|
2050 | uniqueSpacer = 1;
|
---|
2051 | uniqueToolBar = 1;
|
---|
2052 |
|
---|
2053 | emitHeader();
|
---|
2054 | QString name = emitWidget( n.toElement(), FALSE );
|
---|
2055 |
|
---|
2056 | if ( !yyCustomWidgets.isEmpty() ) {
|
---|
2057 | emitOpening( QString("customwidgets") );
|
---|
2058 |
|
---|
2059 | QMap<QString, QString>::Iterator c = yyCustomWidgets.begin();
|
---|
2060 | while ( c != yyCustomWidgets.end() ) {
|
---|
2061 | emitOpening( QString("customwidget") );
|
---|
2062 | emitSimpleValue( QString("class"), c.key() );
|
---|
2063 | if ( !(*c).isEmpty() )
|
---|
2064 | emitSimpleValue( QString("header"), *c,
|
---|
2065 | attribute(QString("location"),
|
---|
2066 | QString("local")) );
|
---|
2067 | emitClosing( QString("customwidget") );
|
---|
2068 | ++c;
|
---|
2069 | }
|
---|
2070 | emitClosing( QString("customwidgets") );
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 | if ( !yyActions.isEmpty() ) {
|
---|
2074 | emitOpening( QString("actions") );
|
---|
2075 |
|
---|
2076 | QMap<QString, GladeAction>::Iterator a = yyActions.begin();
|
---|
2077 | while ( a != yyActions.end() ) {
|
---|
2078 | emitOpening( QString("action") );
|
---|
2079 | emitProperty( QString("name"),
|
---|
2080 | fixedName(a.key()).latin1() );
|
---|
2081 | emitProperty( QString("text"), (*a).text );
|
---|
2082 | emitProperty( QString("menuText"), (*a).menuText );
|
---|
2083 | if ( (*a).toolTip )
|
---|
2084 | emitProperty( QString("toolTip"), (*a).toolTip );
|
---|
2085 | if ( (*a).accel != 0 )
|
---|
2086 | emitProperty( QString("accel"), (*a).accel );
|
---|
2087 | if ( !(*a).iconSet.isEmpty() )
|
---|
2088 | emitProperty( QString("iconSet"),
|
---|
2089 | imageName((*a).iconSet),
|
---|
2090 | QString("iconset") );
|
---|
2091 | emitClosing( QString("action") );
|
---|
2092 | ++a;
|
---|
2093 | }
|
---|
2094 | emitClosing( QString("actions") );
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | if ( !yyImages.isEmpty() ) {
|
---|
2098 | uint maxLength = 524288;
|
---|
2099 | char *data = new char[maxLength];
|
---|
2100 |
|
---|
2101 | QString dir = yyFileName;
|
---|
2102 | dir.truncate( dir.findRev(QChar('/')) + 1 );
|
---|
2103 | dir += yyPixmapDirectory;
|
---|
2104 |
|
---|
2105 | emitOpening( QString("images") );
|
---|
2106 |
|
---|
2107 | QMap<QString, QString>::ConstIterator im = yyImages.begin();
|
---|
2108 | while ( im != yyImages.end() ) {
|
---|
2109 | uint length = 0;
|
---|
2110 | const char *format = 0;
|
---|
2111 |
|
---|
2112 | QString fn = dir + QChar( '/' ) + im.key();
|
---|
2113 | QFile f( fn );
|
---|
2114 | if ( !f.open(IO_ReadOnly) ) {
|
---|
2115 | error( QString("Cannot open image '%1' for reading.")
|
---|
2116 | .arg(fn) );
|
---|
2117 | } else {
|
---|
2118 | length = f.readBlock( data, maxLength );
|
---|
2119 | f.at( 0 );
|
---|
2120 | format = QImageIO::imageFormat( &f );
|
---|
2121 | f.close();
|
---|
2122 | }
|
---|
2123 | if ( format == 0 )
|
---|
2124 | format = "XPM";
|
---|
2125 |
|
---|
2126 | AttributeMap attr;
|
---|
2127 | attr.insert( QString("format"), QString(format) );
|
---|
2128 | attr.insert( QString("length"), QString::number(length) );
|
---|
2129 |
|
---|
2130 | emitOpening( QString("image"),
|
---|
2131 | attribute(QString("name"), *im) );
|
---|
2132 | emitSimpleValue( QString("data"), hexed(data, length),
|
---|
2133 | attr );
|
---|
2134 | emitClosing( QString("image") );
|
---|
2135 | ++im;
|
---|
2136 | }
|
---|
2137 | emitClosing( QString("images") );
|
---|
2138 | delete[] data;
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | if ( yyConnections.count() + yySlots.count() > 0 ) {
|
---|
2142 | emitOpening( QString("connections") );
|
---|
2143 |
|
---|
2144 | QValueList<GladeConnection>::Iterator c = yyConnections.begin();
|
---|
2145 | while ( c != yyConnections.end() ) {
|
---|
2146 | emitOpening( QString("connection") );
|
---|
2147 | emitSimpleValue( QString("sender"), (*c).sender );
|
---|
2148 | emitSimpleValue( QString("signal"), (*c).signal );
|
---|
2149 | emitSimpleValue( QString("receiver"), yyFormName );
|
---|
2150 | emitSimpleValue( QString("slot"), (*c).slot );
|
---|
2151 | emitClosing( QString("connection") );
|
---|
2152 | ++c;
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | QMap<QString, QString>::Iterator s = yySlots.begin();
|
---|
2156 | while ( s != yySlots.end() ) {
|
---|
2157 | AttributeMap attr;
|
---|
2158 | attr.insert( QString("access"), *s );
|
---|
2159 | attr.insert( QString("language"), QString("C++") );
|
---|
2160 | attr.insert( QString("returntype"), QString("void") );
|
---|
2161 | emitSimpleValue( QString("slot"), s.key(), attr );
|
---|
2162 | ++s;
|
---|
2163 | }
|
---|
2164 | emitClosing( QString("connections") );
|
---|
2165 | }
|
---|
2166 | emitFooter();
|
---|
2167 |
|
---|
2168 | QString outFileName = fileName;
|
---|
2169 | int k = outFileName.findRev( "." );
|
---|
2170 | if ( k != -1 )
|
---|
2171 | outFileName.truncate( k );
|
---|
2172 | if ( widgetNo != 0 )
|
---|
2173 | outFileName += QString::number( widgetNo + 1 );
|
---|
2174 | outFileName += QString( ".ui" );
|
---|
2175 | FILE *out = fopen( outFileName.latin1(), "w" );
|
---|
2176 | if ( out == 0 ) {
|
---|
2177 | qWarning( "glade2ui: Could not open file '%s'",
|
---|
2178 | outFileName.latin1() );
|
---|
2179 | } else {
|
---|
2180 | if ( !yyOut.isEmpty() )
|
---|
2181 | fprintf( out, "%s", yyOut.latin1() );
|
---|
2182 | fclose( out );
|
---|
2183 | outFileNames.push_back( outFileName );
|
---|
2184 | }
|
---|
2185 | yyOut = QString::null;
|
---|
2186 | widgetNo++;
|
---|
2187 |
|
---|
2188 | qApp->processEvents();
|
---|
2189 | if ( fremskritt.wasCancelled() )
|
---|
2190 | break;
|
---|
2191 | fremskritt.setProgress( widgetNo );
|
---|
2192 | }
|
---|
2193 | n = n.nextSibling();
|
---|
2194 | }
|
---|
2195 | return outFileNames;
|
---|
2196 | }
|
---|