1 | /**********************************************************************
|
---|
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
---|
3 | **
|
---|
4 | ** This file is part of Qt Designer.
|
---|
5 | **
|
---|
6 | ** This file may be distributed and/or modified under the terms of the
|
---|
7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
9 | ** packaging of this file.
|
---|
10 | **
|
---|
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
13 | ** Agreement provided with the Software.
|
---|
14 | **
|
---|
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | **
|
---|
18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
20 | ** information about Qt Commercial License Agreements.
|
---|
21 | **
|
---|
22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
23 | ** not clear to you.
|
---|
24 | **
|
---|
25 | **********************************************************************/
|
---|
26 |
|
---|
27 | #include "uic.h"
|
---|
28 | #include "parser.h"
|
---|
29 | #include "domtool.h"
|
---|
30 | #include <qregexp.h>
|
---|
31 | #include <qsizepolicy.h>
|
---|
32 | #include <qstringlist.h>
|
---|
33 | #define NO_STATIC_COLORS
|
---|
34 | #include <globaldefs.h>
|
---|
35 | #include "../interfaces/widgetinterface.h"
|
---|
36 | #include "../shared/widgetdatabase.h"
|
---|
37 |
|
---|
38 | /*!
|
---|
39 | Creates a declaration for the object given in \a e.
|
---|
40 |
|
---|
41 | Children are not traversed recursively.
|
---|
42 |
|
---|
43 | \sa createObjectImpl()
|
---|
44 | */
|
---|
45 | void Uic::createObjectDecl( const QDomElement& e )
|
---|
46 | {
|
---|
47 | if ( e.tagName() == "vbox" ) {
|
---|
48 | out << " QVBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;
|
---|
49 | } else if ( e.tagName() == "hbox" ) {
|
---|
50 | out << " QHBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;
|
---|
51 | } else if ( e.tagName() == "grid" ) {
|
---|
52 | out << " QGridLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;
|
---|
53 | } else {
|
---|
54 | QString objClass = getClassName( e );
|
---|
55 | if ( objClass.isEmpty() )
|
---|
56 | return;
|
---|
57 | QString objName = getObjectName( e );
|
---|
58 | if ( objName.isEmpty() )
|
---|
59 | return;
|
---|
60 | // ignore QLayoutWidgets
|
---|
61 | if ( objClass == "QLayoutWidget" )
|
---|
62 | return;
|
---|
63 | // register the object and unify its name
|
---|
64 | objName = registerObject( objName );
|
---|
65 | if ( objClass == "Line" )
|
---|
66 | objClass = "QFrame";
|
---|
67 | else if (objClass == "Spacer")
|
---|
68 | objClass = "QSpacerItem";
|
---|
69 | out << " " << objClass << "* " << objName << ";" << endl;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | /*!
|
---|
75 | Creates an implementation for the object given in \a e.
|
---|
76 |
|
---|
77 | Traverses recursively over all children.
|
---|
78 |
|
---|
79 | Returns the name of the generated child object.
|
---|
80 |
|
---|
81 | \sa createObjectDecl()
|
---|
82 | */
|
---|
83 |
|
---|
84 | static bool createdCentralWidget = FALSE;
|
---|
85 |
|
---|
86 | QString Uic::createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& par, const QString& layout )
|
---|
87 | {
|
---|
88 | QString parent( par );
|
---|
89 | if ( parent == "this" && isMainWindow ) {
|
---|
90 | if ( !createdCentralWidget )
|
---|
91 | out << indent << "setCentralWidget( new QWidget( this, \"qt_central_widget\" ) );" << endl;
|
---|
92 | createdCentralWidget = TRUE;
|
---|
93 | parent = "centralWidget()";
|
---|
94 | }
|
---|
95 | QDomElement n;
|
---|
96 | QString objClass, objName;
|
---|
97 | int numItems = 0;
|
---|
98 | int numColumns = 0;
|
---|
99 | int numRows = 0;
|
---|
100 |
|
---|
101 | if ( layouts.contains( e.tagName() ) )
|
---|
102 | return createLayoutImpl( e, parentClass, parent, layout );
|
---|
103 |
|
---|
104 | objClass = getClassName( e );
|
---|
105 | if ( objClass.isEmpty() )
|
---|
106 | return objName;
|
---|
107 | objName = getObjectName( e );
|
---|
108 |
|
---|
109 | QString definedName = objName;
|
---|
110 | bool isTmpObject = objName.isEmpty() || objClass == "QLayoutWidget";
|
---|
111 | if ( isTmpObject ) {
|
---|
112 | if ( objClass[0] == 'Q' )
|
---|
113 | objName = objClass.mid(1);
|
---|
114 | else
|
---|
115 | objName = objClass.lower();
|
---|
116 | objName.prepend( "private" );
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool isLine = objClass == "Line";
|
---|
120 | if ( isLine )
|
---|
121 | objClass = "QFrame";
|
---|
122 |
|
---|
123 | out << endl;
|
---|
124 | if ( objClass == "QLayoutWidget" ) {
|
---|
125 | if ( layout.isEmpty() ) {
|
---|
126 | // register the object and unify its name
|
---|
127 | objName = registerObject( objName );
|
---|
128 | out << " QWidget* " << objName << " = new QWidget( " << parent << ", \"" << definedName << "\" );" << endl;
|
---|
129 | } else {
|
---|
130 | // the layout widget is not necessary, hide it by creating its child in the parent
|
---|
131 | QString result;
|
---|
132 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
133 | if (tags.contains( n.tagName() ) )
|
---|
134 | result = createObjectImpl( n, parentClass, parent, layout );
|
---|
135 | }
|
---|
136 | return result;
|
---|
137 | }
|
---|
138 | } else if ( objClass != "QToolBar" && objClass != "QMenuBar" ) {
|
---|
139 | // register the object and unify its name
|
---|
140 | objName = registerObject( objName );
|
---|
141 | out << " ";
|
---|
142 | if ( isTmpObject )
|
---|
143 | out << objClass << "* ";
|
---|
144 | out << objName << " = new " << createObjectInstance( objClass, parent, objName ) << ";" << endl;
|
---|
145 | }
|
---|
146 |
|
---|
147 | if ( objClass == "QAxWidget" ) {
|
---|
148 | QString controlId;
|
---|
149 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
150 | if ( n.tagName() == "property" && n.attribute( "name" ) == "control" ) {
|
---|
151 | controlId = n.firstChild().toElement().text();
|
---|
152 | }
|
---|
153 | }
|
---|
154 | out << " ";
|
---|
155 | out << objName << "->setControl(\"" << controlId << "\");" << endl;
|
---|
156 | }
|
---|
157 |
|
---|
158 | lastItem = "0";
|
---|
159 | // set the properties and insert items
|
---|
160 | bool hadFrameShadow = FALSE;
|
---|
161 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
162 | if ( n.tagName() == "property" ) {
|
---|
163 | bool stdset = stdsetdef;
|
---|
164 | if ( n.hasAttribute( "stdset" ) )
|
---|
165 | stdset = toBool( n.attribute( "stdset" ) );
|
---|
166 | QString prop = n.attribute( "name" );
|
---|
167 | if ( prop == "database" )
|
---|
168 | continue;
|
---|
169 | QString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
|
---|
170 | if ( value.isEmpty() )
|
---|
171 | continue;
|
---|
172 | if ( prop == "name" )
|
---|
173 | continue;
|
---|
174 | if ( isLine && prop == "frameShadow" )
|
---|
175 | hadFrameShadow = TRUE;
|
---|
176 | if ( prop == "buddy" && value.startsWith("\"") && value.endsWith("\"") ) {
|
---|
177 | buddies << Buddy( objName, value.mid(1, value.length() - 2 ) );
|
---|
178 | continue;
|
---|
179 | }
|
---|
180 | if ( isLine && prop == "orientation" ) {
|
---|
181 | prop = "frameShape";
|
---|
182 | if ( value.right(10) == "Horizontal" )
|
---|
183 | value = "QFrame::HLine";
|
---|
184 | else
|
---|
185 | value = "QFrame::VLine";
|
---|
186 | if ( !hadFrameShadow ) {
|
---|
187 | prop = "frameStyle";
|
---|
188 | value += " | QFrame::Sunken";
|
---|
189 | }
|
---|
190 | }
|
---|
191 | if ( prop == "buttonGroupId" ) {
|
---|
192 | if ( parentClass == "QButtonGroup" )
|
---|
193 | out << indent << parent << "->insert( " << objName << ", " << value << " );" << endl;
|
---|
194 | continue;
|
---|
195 | }
|
---|
196 | if ( prop == "frameworkCode" )
|
---|
197 | continue;
|
---|
198 | if ( objClass == "QMultiLineEdit" &&
|
---|
199 | QRegExp("echoMode|hMargin|maxLength|maxLines|undoEnabled").exactMatch(prop) )
|
---|
200 | continue;
|
---|
201 |
|
---|
202 | QString call = objName + "->";
|
---|
203 | if ( stdset ) {
|
---|
204 | call += mkStdSet( prop ) + "( ";
|
---|
205 | } else {
|
---|
206 | call += "setProperty( \"" + prop + "\", ";
|
---|
207 | }
|
---|
208 | if ( prop == "accel" )
|
---|
209 | call += "QKeySequence( " + value + " ) );";
|
---|
210 | else
|
---|
211 | call += value + " );";
|
---|
212 |
|
---|
213 | if ( n.firstChild().toElement().tagName() == "string" ||
|
---|
214 | prop == "currentItem" ) {
|
---|
215 | trout << indent << call << endl;
|
---|
216 | } else {
|
---|
217 | out << indent << call << endl;
|
---|
218 | }
|
---|
219 | } else if ( n.tagName() == "item" ) {
|
---|
220 | QString call;
|
---|
221 | QString value;
|
---|
222 |
|
---|
223 | if ( objClass.contains( "ListBox" ) ) {
|
---|
224 | call = createListBoxItemImpl( n, objName );
|
---|
225 | if ( !call.isEmpty() ) {
|
---|
226 | if ( numItems == 0 )
|
---|
227 | trout << indent << objName << "->clear();" << endl;
|
---|
228 | trout << indent << call << endl;
|
---|
229 | }
|
---|
230 | } else if ( objClass.contains( "ComboBox" ) ) {
|
---|
231 | call = createListBoxItemImpl( n, objName, &value );
|
---|
232 | if ( !call.isEmpty() ) {
|
---|
233 | if ( numItems == 0 )
|
---|
234 | trout << indent << objName << "->clear();" << endl;
|
---|
235 | trout << indent << call << endl;
|
---|
236 | }
|
---|
237 | } else if ( objClass.contains( "IconView" ) ) {
|
---|
238 | call = createIconViewItemImpl( n, objName );
|
---|
239 | if ( !call.isEmpty() ) {
|
---|
240 | if ( numItems == 0 )
|
---|
241 | trout << indent << objName << "->clear();" << endl;
|
---|
242 | trout << indent << call << endl;
|
---|
243 | }
|
---|
244 | } else if ( objClass.contains( "ListView" ) ) {
|
---|
245 | call = createListViewItemImpl( n, objName, QString::null );
|
---|
246 | if ( !call.isEmpty() ) {
|
---|
247 | if ( numItems == 0 )
|
---|
248 | trout << indent << objName << "->clear();" << endl;
|
---|
249 | trout << call << endl;
|
---|
250 | }
|
---|
251 | }
|
---|
252 | if ( !call.isEmpty() )
|
---|
253 | numItems++;
|
---|
254 | } else if ( n.tagName() == "column" || n.tagName() == "row" ) {
|
---|
255 | QString call;
|
---|
256 | QString value;
|
---|
257 |
|
---|
258 | if ( objClass.contains( "ListView" ) ) {
|
---|
259 | call = createListViewColumnImpl( n, objName, &value );
|
---|
260 | if ( !call.isEmpty() ) {
|
---|
261 | out << call;
|
---|
262 | trout << indent << objName << "->header()->setLabel( "
|
---|
263 | << numColumns++ << ", " << value << " );\n";
|
---|
264 | }
|
---|
265 | } else if ( objClass == "QTable" || objClass == "QDataTable" ) {
|
---|
266 | bool isCols = ( n.tagName() == "column" );
|
---|
267 | call = createTableRowColumnImpl( n, objName, &value );
|
---|
268 | if ( !call.isEmpty() ) {
|
---|
269 | out << call;
|
---|
270 | trout << indent << objName << "->"
|
---|
271 | << ( isCols ? "horizontalHeader" : "verticalHeader" )
|
---|
272 | << "()->setLabel( "
|
---|
273 | << ( isCols ? numColumns++ : numRows++ )
|
---|
274 | << ", " << value << " );\n";
|
---|
275 | }
|
---|
276 | }
|
---|
277 | }
|
---|
278 | }
|
---|
279 |
|
---|
280 | // create all children, some widgets have special requirements
|
---|
281 |
|
---|
282 | if ( objClass == "QTabWidget" ) {
|
---|
283 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
284 | if ( tags.contains( n.tagName() ) ) {
|
---|
285 | QString page = createObjectImpl( n, objClass, objName );
|
---|
286 | QString comment;
|
---|
287 | QString label = DomTool::readAttribute( n, "title", "", comment ).toString();
|
---|
288 | out << indent << objName << "->insertTab( " << page << ", QString(\"\") );" << endl;
|
---|
289 | trout << indent << objName << "->changeTab( " << page << ", "
|
---|
290 | << trcall( label, comment ) << " );" << endl;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | } else if ( objClass == "QWidgetStack" ) {
|
---|
294 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
295 | if ( tags.contains( n.tagName() ) ) {
|
---|
296 | QString page = createObjectImpl( n, objClass, objName );
|
---|
297 | int id = DomTool::readAttribute( n, "id", "" ).toInt();
|
---|
298 | out << indent << objName << "->addWidget( " << page << ", " << id << " );" << endl;
|
---|
299 | }
|
---|
300 | }
|
---|
301 | } else if ( objClass == "QToolBox" ) {
|
---|
302 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
303 | if ( tags.contains( n.tagName() ) ) {
|
---|
304 | QString page = createObjectImpl( n, objClass, objName );
|
---|
305 | QString label = DomTool::readAttribute( n, "label", "" ).toString();
|
---|
306 | out << indent << objName << "->addItem( " << page << ", \"" << label << "\" );" << endl;
|
---|
307 | }
|
---|
308 | }
|
---|
309 | } else if ( objClass != "QToolBar" && objClass != "QMenuBar" ) { // standard widgets
|
---|
310 | WidgetInterface *iface = 0;
|
---|
311 | widgetManager()->queryInterface( objClass, &iface );
|
---|
312 | #ifdef QT_CONTAINER_CUSTOM_WIDGETS
|
---|
313 | int id = WidgetDatabase::idFromClassName( objClass );
|
---|
314 | if ( WidgetDatabase::isContainer( id ) && WidgetDatabase::isCustomPluginWidget( id ) && iface ) {
|
---|
315 | QWidgetContainerInterfacePrivate *iface2 = 0;
|
---|
316 | iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );
|
---|
317 | if ( iface2 ) {
|
---|
318 | bool supportsPages = iface2->supportsPages( objClass );
|
---|
319 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
320 | if ( tags.contains( n.tagName() ) ) {
|
---|
321 | if ( supportsPages ) {
|
---|
322 | QString page = createObjectImpl( n, objClass, objName );
|
---|
323 | QString comment;
|
---|
324 | QString label = DomTool::readAttribute( n, "label", "", comment ).toString();
|
---|
325 | out << indent << iface2->createCode( objClass, objName, page, label ) << endl;
|
---|
326 | } else {
|
---|
327 | createObjectImpl( n, objClass, objName );
|
---|
328 | }
|
---|
329 | }
|
---|
330 | }
|
---|
331 | iface2->release();
|
---|
332 | }
|
---|
333 | iface->release();
|
---|
334 | } else {
|
---|
335 | #endif
|
---|
336 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
337 | if ( tags.contains( n.tagName() ) )
|
---|
338 | createObjectImpl( n, objClass, objName );
|
---|
339 | }
|
---|
340 | #ifdef QT_CONTAINER_CUSTOM_WIDGETS
|
---|
341 | }
|
---|
342 | #endif
|
---|
343 | }
|
---|
344 |
|
---|
345 | return objName;
|
---|
346 | }
|
---|
347 |
|
---|
348 | /*!
|
---|
349 | Creates declarations for spacer items that are children of \a e.
|
---|
350 |
|
---|
351 | \sa createObjectDecl()
|
---|
352 | */
|
---|
353 |
|
---|
354 | void Uic::createSpacerDecl( const QDomElement &e )
|
---|
355 | {
|
---|
356 | for ( QDomElement n = e.firstChild().toElement();
|
---|
357 | !n.isNull(); n = n.nextSibling().toElement() )
|
---|
358 | if ( n.tagName() == "spacer" )
|
---|
359 | out << " QSpacerItem* " << registerObject(getObjectName(n)) << ";" << endl;
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*!
|
---|
363 | Creates a set-call for property \a exclusiveProp of the object
|
---|
364 | given in \a e.
|
---|
365 |
|
---|
366 | If the object does not have this property, the function does nothing.
|
---|
367 |
|
---|
368 | Exclusive properties are used to generate the implementation of
|
---|
369 | application font or palette change handlers in createFormImpl().
|
---|
370 |
|
---|
371 | */
|
---|
372 | void Uic::createExclusiveProperty( const QDomElement & e, const QString& exclusiveProp )
|
---|
373 | {
|
---|
374 | QDomElement n;
|
---|
375 | QString objClass = getClassName( e );
|
---|
376 | if ( objClass.isEmpty() )
|
---|
377 | return;
|
---|
378 | QString objName = getObjectName( e );
|
---|
379 | #if 0 // it's not clear whether this check should be here or not
|
---|
380 | if ( objName.isEmpty() )
|
---|
381 | return;
|
---|
382 | #endif
|
---|
383 | for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
---|
384 | if ( n.tagName() == "property" ) {
|
---|
385 | bool stdset = stdsetdef;
|
---|
386 | if ( n.hasAttribute( "stdset" ) )
|
---|
387 | stdset = toBool( n.attribute( "stdset" ) );
|
---|
388 | QString prop = n.attribute( "name" );
|
---|
389 | if ( prop != exclusiveProp )
|
---|
390 | continue;
|
---|
391 | QString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
|
---|
392 | if ( value.isEmpty() )
|
---|
393 | continue;
|
---|
394 | // we assume the property isn't of type 'string'
|
---|
395 | out << '\t' << objName << "->setProperty( \"" << prop << "\", " << value << " );" << endl;
|
---|
396 | }
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 |
|
---|
401 | /*! Attention: this function has to be in sync with
|
---|
402 | Resource::saveProperty() and DomTool::elementToVariant. If you
|
---|
403 | change one, change all.
|
---|
404 | */
|
---|
405 | QString Uic::setObjectProperty( const QString& objClass, const QString& obj, const QString &prop, const QDomElement &e, bool stdset )
|
---|
406 | {
|
---|
407 | QString v;
|
---|
408 | if ( e.tagName() == "rect" ) {
|
---|
409 | QDomElement n3 = e.firstChild().toElement();
|
---|
410 | int x = 0, y = 0, w = 0, h = 0;
|
---|
411 | while ( !n3.isNull() ) {
|
---|
412 | if ( n3.tagName() == "x" )
|
---|
413 | x = n3.firstChild().toText().data().toInt();
|
---|
414 | else if ( n3.tagName() == "y" )
|
---|
415 | y = n3.firstChild().toText().data().toInt();
|
---|
416 | else if ( n3.tagName() == "width" )
|
---|
417 | w = n3.firstChild().toText().data().toInt();
|
---|
418 | else if ( n3.tagName() == "height" )
|
---|
419 | h = n3.firstChild().toText().data().toInt();
|
---|
420 | n3 = n3.nextSibling().toElement();
|
---|
421 | }
|
---|
422 | v = "QRect( %1, %2, %3, %4 )";
|
---|
423 | v = v.arg(x).arg(y).arg(w).arg(h);
|
---|
424 |
|
---|
425 | } else if ( e.tagName() == "point" ) {
|
---|
426 | QDomElement n3 = e.firstChild().toElement();
|
---|
427 | int x = 0, y = 0;
|
---|
428 | while ( !n3.isNull() ) {
|
---|
429 | if ( n3.tagName() == "x" )
|
---|
430 | x = n3.firstChild().toText().data().toInt();
|
---|
431 | else if ( n3.tagName() == "y" )
|
---|
432 | y = n3.firstChild().toText().data().toInt();
|
---|
433 | n3 = n3.nextSibling().toElement();
|
---|
434 | }
|
---|
435 | v = "QPoint( %1, %2 )";
|
---|
436 | v = v.arg(x).arg(y);
|
---|
437 | } else if ( e.tagName() == "size" ) {
|
---|
438 | QDomElement n3 = e.firstChild().toElement();
|
---|
439 | int w = 0, h = 0;
|
---|
440 | while ( !n3.isNull() ) {
|
---|
441 | if ( n3.tagName() == "width" )
|
---|
442 | w = n3.firstChild().toText().data().toInt();
|
---|
443 | else if ( n3.tagName() == "height" )
|
---|
444 | h = n3.firstChild().toText().data().toInt();
|
---|
445 | n3 = n3.nextSibling().toElement();
|
---|
446 | }
|
---|
447 | v = "QSize( %1, %2 )";
|
---|
448 | v = v.arg(w).arg(h);
|
---|
449 | } else if ( e.tagName() == "color" ) {
|
---|
450 | QDomElement n3 = e.firstChild().toElement();
|
---|
451 | int r = 0, g = 0, b = 0;
|
---|
452 | while ( !n3.isNull() ) {
|
---|
453 | if ( n3.tagName() == "red" )
|
---|
454 | r = n3.firstChild().toText().data().toInt();
|
---|
455 | else if ( n3.tagName() == "green" )
|
---|
456 | g = n3.firstChild().toText().data().toInt();
|
---|
457 | else if ( n3.tagName() == "blue" )
|
---|
458 | b = n3.firstChild().toText().data().toInt();
|
---|
459 | n3 = n3.nextSibling().toElement();
|
---|
460 | }
|
---|
461 | v = "QColor( %1, %2, %3 )";
|
---|
462 | v = v.arg(r).arg(g).arg(b);
|
---|
463 | } else if ( e.tagName() == "font" ) {
|
---|
464 | QDomElement n3 = e.firstChild().toElement();
|
---|
465 | QString attrname = e.parentNode().toElement().attribute( "name", "font" );
|
---|
466 | QString fontname;
|
---|
467 | if ( !obj.isEmpty() ) {
|
---|
468 | fontname = registerObject( obj + "_" + attrname );
|
---|
469 | out << indent << "QFont " << fontname << "( " << obj << "->font() );" << endl;
|
---|
470 | } else {
|
---|
471 | fontname = registerObject( "f" );
|
---|
472 | out << indent << "QFont " << fontname << "( font() );" << endl;
|
---|
473 | }
|
---|
474 | while ( !n3.isNull() ) {
|
---|
475 | if ( n3.tagName() == "family" )
|
---|
476 | out << indent << fontname << ".setFamily( \"" << n3.firstChild().toText().data() << "\" );" << endl;
|
---|
477 | else if ( n3.tagName() == "pointsize" )
|
---|
478 | out << indent << fontname << ".setPointSize( " << n3.firstChild().toText().data() << " );" << endl;
|
---|
479 | else if ( n3.tagName() == "bold" )
|
---|
480 | out << indent << fontname << ".setBold( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;
|
---|
481 | else if ( n3.tagName() == "italic" )
|
---|
482 | out << indent << fontname << ".setItalic( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;
|
---|
483 | else if ( n3.tagName() == "underline" )
|
---|
484 | out << indent << fontname << ".setUnderline( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;
|
---|
485 | else if ( n3.tagName() == "strikeout" )
|
---|
486 | out << indent << fontname << ".setStrikeOut( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;
|
---|
487 | n3 = n3.nextSibling().toElement();
|
---|
488 | }
|
---|
489 |
|
---|
490 | if ( prop == "font" ) {
|
---|
491 | if ( !obj.isEmpty() )
|
---|
492 | out << indent << obj << "->setFont( " << fontname << " ); " << endl;
|
---|
493 | else
|
---|
494 | out << indent << "setFont( " << fontname << " ); " << endl;
|
---|
495 | } else {
|
---|
496 | v = fontname;
|
---|
497 | }
|
---|
498 | } else if ( e.tagName() == "string" ) {
|
---|
499 | QString txt = e.firstChild().toText().data();
|
---|
500 | QString com = getComment( e.parentNode() );
|
---|
501 |
|
---|
502 | if ( prop == "toolTip" && objClass != "QAction" && objClass != "QActionGroup" ) {
|
---|
503 | if ( !obj.isEmpty() )
|
---|
504 | trout << indent << "QToolTip::add( " << obj << ", "
|
---|
505 | << trcall( txt, com ) << " );" << endl;
|
---|
506 | else
|
---|
507 | trout << indent << "QToolTip::add( this, "
|
---|
508 | << trcall( txt, com ) << " );" << endl;
|
---|
509 | } else if ( prop == "whatsThis" && objClass != "QAction" && objClass != "QActionGroup" ) {
|
---|
510 | if ( !obj.isEmpty() )
|
---|
511 | trout << indent << "QWhatsThis::add( " << obj << ", "
|
---|
512 | << trcall( txt, com ) << " );" << endl;
|
---|
513 | else
|
---|
514 | trout << indent << "QWhatsThis::add( this, "
|
---|
515 | << trcall( txt, com ) << " );" << endl;
|
---|
516 | } else {
|
---|
517 | v = trcall( txt, com );
|
---|
518 | }
|
---|
519 | } else if ( e.tagName() == "cstring" ) {
|
---|
520 | v = "\"%1\"";
|
---|
521 | v = v.arg( e.firstChild().toText().data() );
|
---|
522 | } else if ( e.tagName() == "number" ) {
|
---|
523 | v = "%1";
|
---|
524 | v = v.arg( e.firstChild().toText().data() );
|
---|
525 | } else if ( e.tagName() == "bool" ) {
|
---|
526 | if ( stdset )
|
---|
527 | v = "%1";
|
---|
528 | else
|
---|
529 | v = "QVariant( %1, 0 )";
|
---|
530 | v = v.arg( mkBool( e.firstChild().toText().data() ) );
|
---|
531 | } else if ( e.tagName() == "pixmap" ) {
|
---|
532 | v = e.firstChild().toText().data();
|
---|
533 | if ( !pixmapLoaderFunction.isEmpty() ) {
|
---|
534 | v.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) );
|
---|
535 | v.append( QString( externPixmaps ? "\"" : "" ) + " )" );
|
---|
536 | }
|
---|
537 | } else if ( e.tagName() == "iconset" ) {
|
---|
538 | v = "QIconSet( %1 )";
|
---|
539 | QString s = e.firstChild().toText().data();
|
---|
540 | if ( !pixmapLoaderFunction.isEmpty() ) {
|
---|
541 | s.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) );
|
---|
542 | s.append( QString( externPixmaps ? "\"" : "" ) + " )" );
|
---|
543 | }
|
---|
544 | v = v.arg( s );
|
---|
545 | } else if ( e.tagName() == "image" ) {
|
---|
546 | v = e.firstChild().toText().data() + ".convertToImage()";
|
---|
547 | } else if ( e.tagName() == "enum" ) {
|
---|
548 | if ( stdset )
|
---|
549 | v = "%1::%2";
|
---|
550 | else
|
---|
551 | v = "\"%1\"";
|
---|
552 | QString oc = objClass;
|
---|
553 | QString ev = e.firstChild().toText().data();
|
---|
554 | if ( oc == "QListView" && ev == "Manual" ) // #### workaround, rename QListView::Manual in 4.0
|
---|
555 | oc = "QScrollView";
|
---|
556 | if ( stdset )
|
---|
557 | v = v.arg( oc ).arg( ev );
|
---|
558 | else
|
---|
559 | v = v.arg( ev );
|
---|
560 | } else if ( e.tagName() == "set" ) {
|
---|
561 | QString keys( e.firstChild().toText().data() );
|
---|
562 | QStringList lst = QStringList::split( '|', keys );
|
---|
563 | v = "int( ";
|
---|
564 | QStringList::Iterator it = lst.begin();
|
---|
565 | while ( it != lst.end() ) {
|
---|
566 | v += objClass + "::" + *it;
|
---|
567 | if ( it != lst.fromLast() )
|
---|
568 | v += " | ";
|
---|
569 | ++it;
|
---|
570 | }
|
---|
571 | v += " )";
|
---|
572 | } else if ( e.tagName() == "sizepolicy" ) {
|
---|
573 | QDomElement n3 = e.firstChild().toElement();
|
---|
574 | QSizePolicy sp;
|
---|
575 | while ( !n3.isNull() ) {
|
---|
576 | if ( n3.tagName() == "hsizetype" )
|
---|
577 | sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
|
---|
578 | else if ( n3.tagName() == "vsizetype" )
|
---|
579 | sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
|
---|
580 | else if ( n3.tagName() == "horstretch" )
|
---|
581 | sp.setHorStretch( n3.firstChild().toText().data().toInt() );
|
---|
582 | else if ( n3.tagName() == "verstretch" )
|
---|
583 | sp.setVerStretch( n3.firstChild().toText().data().toInt() );
|
---|
584 | n3 = n3.nextSibling().toElement();
|
---|
585 | }
|
---|
586 | QString tmp;
|
---|
587 | if ( !obj.isEmpty() )
|
---|
588 | tmp = obj + "->";
|
---|
589 | v = "QSizePolicy( (QSizePolicy::SizeType)%1, (QSizePolicy::SizeType)%2, %3, %4, " + tmp + "sizePolicy().hasHeightForWidth() )";
|
---|
590 | v = v.arg( (int)sp.horData() ).arg( (int)sp.verData() ).arg( sp.horStretch() ).arg( sp.verStretch() );
|
---|
591 | } else if ( e.tagName() == "palette" ) {
|
---|
592 | QPalette pal;
|
---|
593 | bool no_pixmaps = e.elementsByTagName( "pixmap" ).count() == 0;
|
---|
594 | QDomElement n;
|
---|
595 | if ( no_pixmaps ) {
|
---|
596 | n = e.firstChild().toElement();
|
---|
597 | while ( !n.isNull() ) {
|
---|
598 | QColorGroup cg;
|
---|
599 | if ( n.tagName() == "active" ) {
|
---|
600 | cg = loadColorGroup( n );
|
---|
601 | pal.setActive( cg );
|
---|
602 | } else if ( n.tagName() == "inactive" ) {
|
---|
603 | cg = loadColorGroup( n );
|
---|
604 | pal.setInactive( cg );
|
---|
605 | } else if ( n.tagName() == "disabled" ) {
|
---|
606 | cg = loadColorGroup( n );
|
---|
607 | pal.setDisabled( cg );
|
---|
608 | }
|
---|
609 | n = n.nextSibling().toElement();
|
---|
610 | }
|
---|
611 | }
|
---|
612 | if ( no_pixmaps && pal == QPalette( pal.active().button(), pal.active().background() ) ) {
|
---|
613 | v = "QPalette( QColor( %1, %2, %3 ), QColor( %1, %2, %3 ) )";
|
---|
614 | v = v.arg( pal.active().button().red() ).arg( pal.active().button().green() ).arg( pal.active().button().blue() );
|
---|
615 | v = v.arg( pal.active().background().red() ).arg( pal.active().background().green() ).arg( pal.active().background().blue() );
|
---|
616 | } else {
|
---|
617 | QString palette = "pal";
|
---|
618 | if ( !pal_used ) {
|
---|
619 | out << indent << "QPalette " << palette << ";" << endl;
|
---|
620 | pal_used = TRUE;
|
---|
621 | }
|
---|
622 | QString cg = "cg";
|
---|
623 | if ( !cg_used ) {
|
---|
624 | out << indent << "QColorGroup " << cg << ";" << endl;
|
---|
625 | cg_used = TRUE;
|
---|
626 | }
|
---|
627 | n = e.firstChild().toElement();
|
---|
628 | while ( !n.isNull() && n.tagName() != "active" )
|
---|
629 | n = n.nextSibling().toElement();
|
---|
630 | createColorGroupImpl( cg, n );
|
---|
631 | out << indent << palette << ".setActive( " << cg << " );" << endl;
|
---|
632 |
|
---|
633 | n = e.firstChild().toElement();
|
---|
634 | while ( !n.isNull() && n.tagName() != "inactive" )
|
---|
635 | n = n.nextSibling().toElement();
|
---|
636 | createColorGroupImpl( cg, n );
|
---|
637 | out << indent << palette << ".setInactive( " << cg << " );" << endl;
|
---|
638 |
|
---|
639 | n = e.firstChild().toElement();
|
---|
640 | while ( !n.isNull() && n.tagName() != "disabled" )
|
---|
641 | n = n.nextSibling().toElement();
|
---|
642 | createColorGroupImpl( cg, n );
|
---|
643 | out << indent << palette << ".setDisabled( " << cg << " );" << endl;
|
---|
644 | v = palette;
|
---|
645 | }
|
---|
646 | } else if ( e.tagName() == "cursor" ) {
|
---|
647 | v = "QCursor( %1 )";
|
---|
648 | v = v.arg( e.firstChild().toText().data() );
|
---|
649 | } else if ( e.tagName() == "date" ) {
|
---|
650 | QDomElement n3 = e.firstChild().toElement();
|
---|
651 | int y, m, d;
|
---|
652 | y = m = d = 0;
|
---|
653 | while ( !n3.isNull() ) {
|
---|
654 | if ( n3.tagName() == "year" )
|
---|
655 | y = n3.firstChild().toText().data().toInt();
|
---|
656 | else if ( n3.tagName() == "month" )
|
---|
657 | m = n3.firstChild().toText().data().toInt();
|
---|
658 | else if ( n3.tagName() == "day" )
|
---|
659 | d = n3.firstChild().toText().data().toInt();
|
---|
660 | n3 = n3.nextSibling().toElement();
|
---|
661 | }
|
---|
662 | v = "QDate( %1, %2, %3 )";
|
---|
663 | v = v.arg(y).arg(m).arg(d);
|
---|
664 | } else if ( e.tagName() == "time" ) {
|
---|
665 | QDomElement n3 = e.firstChild().toElement();
|
---|
666 | int h, m, s;
|
---|
667 | h = m = s = 0;
|
---|
668 | while ( !n3.isNull() ) {
|
---|
669 | if ( n3.tagName() == "hour" )
|
---|
670 | h = n3.firstChild().toText().data().toInt();
|
---|
671 | else if ( n3.tagName() == "minute" )
|
---|
672 | m = n3.firstChild().toText().data().toInt();
|
---|
673 | else if ( n3.tagName() == "second" )
|
---|
674 | s = n3.firstChild().toText().data().toInt();
|
---|
675 | n3 = n3.nextSibling().toElement();
|
---|
676 | }
|
---|
677 | v = "QTime( %1, %2, %3 )";
|
---|
678 | v = v.arg(h).arg(m).arg(s);
|
---|
679 | } else if ( e.tagName() == "datetime" ) {
|
---|
680 | QDomElement n3 = e.firstChild().toElement();
|
---|
681 | int h, mi, s, y, mo, d;
|
---|
682 | h = mi = s = y = mo = d = 0;
|
---|
683 | while ( !n3.isNull() ) {
|
---|
684 | if ( n3.tagName() == "hour" )
|
---|
685 | h = n3.firstChild().toText().data().toInt();
|
---|
686 | else if ( n3.tagName() == "minute" )
|
---|
687 | mi = n3.firstChild().toText().data().toInt();
|
---|
688 | else if ( n3.tagName() == "second" )
|
---|
689 | s = n3.firstChild().toText().data().toInt();
|
---|
690 | else if ( n3.tagName() == "year" )
|
---|
691 | y = n3.firstChild().toText().data().toInt();
|
---|
692 | else if ( n3.tagName() == "month" )
|
---|
693 | mo = n3.firstChild().toText().data().toInt();
|
---|
694 | else if ( n3.tagName() == "day" )
|
---|
695 | d = n3.firstChild().toText().data().toInt();
|
---|
696 | n3 = n3.nextSibling().toElement();
|
---|
697 | }
|
---|
698 | v = "QDateTime( QDate( %1, %2, %3 ), QTime( %4, %5, %6 ) )";
|
---|
699 | v = v.arg(y).arg(mo).arg(d).arg(h).arg(mi).arg(s);
|
---|
700 | } else if ( e.tagName() == "stringlist" ) {
|
---|
701 | QStringList l;
|
---|
702 | QDomElement n3 = e.firstChild().toElement();
|
---|
703 | QString listname = "l";
|
---|
704 | if ( !obj.isEmpty() ) {
|
---|
705 | listname = obj + "_stringlist";
|
---|
706 | listname = registerObject( listname );
|
---|
707 | out << indent << "QStringList " << listname << ";" << endl;
|
---|
708 | } else {
|
---|
709 | listname = registerObject( listname );
|
---|
710 | out << indent << "QStringList " << listname << ";" << endl;
|
---|
711 | }
|
---|
712 | while ( !n3.isNull() ) {
|
---|
713 | if ( n3.tagName() == "string" )
|
---|
714 | out << indent << listname << " << \"" << n3.firstChild().toText().data().simplifyWhiteSpace() << "\";" << endl;
|
---|
715 | n3 = n3.nextSibling().toElement();
|
---|
716 | }
|
---|
717 | v = listname;
|
---|
718 | }
|
---|
719 | return v;
|
---|
720 | }
|
---|
721 |
|
---|
722 | /*! Extracts a named object property from \a e.
|
---|
723 | */
|
---|
724 | QDomElement Uic::getObjectProperty( const QDomElement& e, const QString& name )
|
---|
725 | {
|
---|
726 | QDomElement n;
|
---|
727 | for ( n = e.firstChild().toElement();
|
---|
728 | !n.isNull();
|
---|
729 | n = n.nextSibling().toElement() ) {
|
---|
730 | if ( n.tagName() == "property" && n.toElement().attribute("name") == name )
|
---|
731 | return n;
|
---|
732 | }
|
---|
733 | return n;
|
---|
734 | }
|
---|