SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

object.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /**********************************************************************
  2. ** Copyright (C) 2000 Trolltech AS. All rights reserved.
  3. **
  4. ** This file is part of TQt 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. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  15. **
  16. ** Contact info@trolltech.com if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. **********************************************************************/
  20. #include "uic.h"
  21. #include "parser.h"
  22. #include "domtool.h"
  23. #include <qregexp.h>
  24. #include <qsizepolicy.h>
  25. #include <qstringlist.h>
  26. #define NO_STATIC_COLORS
  27. #include <globaldefs.h>
  28. /*!
  29. Creates an implementation for the object given in \a e.
  30. Traverses recursively over all children.
  31. Returns the name of the generated child object.
  32. */
  33. static bool createdCentralWidget = FALSE;
  34. TQString Uic::createObjectImpl( const TQDomElement &e, const TQString& parentClass, const TQString& par, const TQString& layout )
  35. {
  36. TQString parent( par );
  37. if ( parent == "self" && isMainWindow ) {
  38. if ( !createdCentralWidget )
  39. out << indent << "self.setCentralWidget(TQWidget(self,\"qt_central_widget\"))" << endl;
  40. createdCentralWidget = TRUE;
  41. parent = "self.centralWidget()";
  42. }
  43. TQDomElement n;
  44. TQString objClass, objName, fullObjName;
  45. int numItems = 0;
  46. int numColumns = 0;
  47. int numRows = 0;
  48. if ( layouts.contains( e.tagName() ) )
  49. return createLayoutImpl( e, parentClass, parent, layout );
  50. objClass = getClassName( e );
  51. if ( objClass.isEmpty() )
  52. return objName;
  53. objName = getObjectName( e );
  54. TQString definedName = objName;
  55. bool isTmpObject = objName.isEmpty() || objClass == "TQLayoutWidget";
  56. if ( isTmpObject ) {
  57. if ( objClass[0] == 'Q' )
  58. objName = objClass.mid(1);
  59. else
  60. objName = objClass.lower();
  61. }
  62. bool isLine = objClass == "Line";
  63. if ( isLine )
  64. objClass = "TQFrame";
  65. out << endl;
  66. if ( objClass == "TQLayoutWidget" ) {
  67. if ( layout.isEmpty() ) {
  68. // register the object and unify its name
  69. objName = registerObject( objName );
  70. out << indent << objName << " = TQWidget(" << parent << ",\"" << definedName << "\")" << endl;
  71. } else {
  72. // the layout widget is not necessary, hide it by creating its child in the parent
  73. TQString result;
  74. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  75. if (tags.contains( n.tagName() ) )
  76. result = createObjectImpl( n, parentClass, parent, layout );
  77. }
  78. return result;
  79. }
  80. // Layouts don't go into the class instance dictionary.
  81. fullObjName = objName;
  82. } else if ( objClass != "TQToolBar" && objClass != "TQMenuBar" ) {
  83. // register the object and unify its name
  84. objName = registerObject( objName );
  85. // Temporary objects don't go into the class instance dictionary.
  86. fullObjName = isTmpObject ? objName : "self." + objName;
  87. out << indent << fullObjName << " = " << createObjectInstance( objClass, parent, objName ) << endl;
  88. }
  89. else
  90. fullObjName = "self." + objName;
  91. if ( objClass == "TQAxWidget" ) {
  92. TQString controlId;
  93. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  94. if ( n.tagName() == "property" && n.attribute( "name" ) == "control" ) {
  95. controlId = n.firstChild().toElement().text();
  96. }
  97. }
  98. out << indent << fullObjName << ".setControl(\"" << controlId << "\")" << endl;
  99. }
  100. lastItem = "None";
  101. // set the properties and insert items
  102. bool hadFrameShadow = FALSE;
  103. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  104. if ( n.tagName() == "property" ) {
  105. bool stdset = stdsetdef;
  106. if ( n.hasAttribute( "stdset" ) )
  107. stdset = toBool( n.attribute( "stdset" ) );
  108. TQString prop = n.attribute( "name" );
  109. if ( prop == "database" )
  110. continue;
  111. TQString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
  112. if ( value.isEmpty() )
  113. continue;
  114. if ( prop == "name" )
  115. continue;
  116. if ( isLine && prop == "frameShadow" )
  117. hadFrameShadow = TRUE;
  118. if ( prop == "buddy" && value.startsWith("\"") && value.endsWith("\"") ) {
  119. buddies << Buddy( objName, value.mid(1, value.length() - 2 ) );
  120. continue;
  121. }
  122. if ( isLine && prop == "orientation" ) {
  123. prop = "frameShape";
  124. if ( value.right(10) == "Horizontal" )
  125. value = "TQFrame.HLine";
  126. else
  127. value = "TQFrame.VLine";
  128. if ( !hadFrameShadow ) {
  129. prop = "frameStyle";
  130. value += " | TQFrame.Sunken";
  131. }
  132. }
  133. if ( prop == "buttonGroupId" ) {
  134. if ( parentClass == "TQButtonGroup" )
  135. out << indent << parent << ".insert( " << fullObjName << "," << value << ")" << endl;
  136. continue;
  137. }
  138. if ( prop == "frameworkCode" )
  139. continue;
  140. if ( objClass == "TQMultiLineEdit" &&
  141. TQRegExp("echoMode|hMargin|maxLength|maxLines|undoEnabled").exactMatch(prop) )
  142. continue;
  143. TQString call = fullObjName + ".";
  144. TQString tail;
  145. if ( stdset ) {
  146. call += mkStdSet( prop ) + "(";
  147. tail = ")";
  148. } else {
  149. call += "setProperty(\"" + prop + "\",TQVariant(";
  150. tail = "))";
  151. }
  152. if ( prop == "accel" ) {
  153. call += "TQKeySequence(";
  154. tail += ")";
  155. }
  156. call += value + tail;
  157. if ( n.firstChild().toElement().tagName() == "string" ||
  158. prop == "currentItem" ) {
  159. trout << trindent << call << endl;
  160. } else {
  161. out << indent << call << endl;
  162. }
  163. } else if ( n.tagName() == "item" ) {
  164. TQString call;
  165. TQString value;
  166. if ( objClass.contains( "ListBox" ) ) {
  167. call = createListBoxItemImpl( n, fullObjName );
  168. if ( !call.isEmpty() ) {
  169. if ( numItems == 0 )
  170. trout << trindent << fullObjName << ".clear()" << endl;
  171. trout << trindent << call << endl;
  172. }
  173. } else if ( objClass.contains( "ComboBox" ) ) {
  174. call = createListBoxItemImpl( n, fullObjName, &value );
  175. if ( !call.isEmpty() ) {
  176. if ( numItems == 0 )
  177. trout << trindent << fullObjName << ".clear()" << endl;
  178. trout << trindent << call << endl;
  179. }
  180. } else if ( objClass.contains( "IconView" ) ) {
  181. call = createIconViewItemImpl( n, fullObjName );
  182. if ( !call.isEmpty() ) {
  183. if ( numItems == 0 )
  184. trout << trindent << fullObjName << ".clear()" << endl;
  185. trout << trindent << call << endl;
  186. }
  187. } else if ( objClass.contains( "ListView" ) ) {
  188. call = createListViewItemImpl( n, fullObjName, TQString::null );
  189. if ( !call.isEmpty() ) {
  190. if ( numItems == 0 )
  191. trout << trindent << fullObjName << ".clear()" << endl;
  192. trout << call << endl;
  193. }
  194. }
  195. if ( !call.isEmpty() )
  196. numItems++;
  197. } else if ( n.tagName() == "column" || n.tagName() == "row" ) {
  198. TQString call;
  199. TQString value;
  200. if ( objClass.contains( "ListView" ) ) {
  201. call = createListViewColumnImpl( n, fullObjName, &value );
  202. if ( !call.isEmpty() ) {
  203. out << call;
  204. trout << trindent << fullObjName << ".header().setLabel("
  205. << numColumns++ << "," << value << ")\n";
  206. }
  207. } else if ( objClass == "TQTable" || objClass == "TQDataTable" ) {
  208. bool isCols = ( n.tagName() == "column" );
  209. call = createTableRowColumnImpl( n, fullObjName, &value );
  210. if ( !call.isEmpty() ) {
  211. out << call;
  212. trout << trindent << fullObjName << "."
  213. << ( isCols ? "horizontalHeader" : "verticalHeader" )
  214. << "().setLabel("
  215. << ( isCols ? numColumns++ : numRows++ )
  216. << "," << value << ")\n";
  217. }
  218. }
  219. }
  220. }
  221. // create all children, some widgets have special requirements
  222. if ( objClass == "TQTabWidget" ) {
  223. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  224. if ( tags.contains( n.tagName() ) ) {
  225. TQString page = createObjectImpl( n, objClass, fullObjName );
  226. TQString comment;
  227. TQString label = DomTool::readAttribute( n, "title", "", comment ).toString();
  228. out << indent << fullObjName << ".insertTab(" << page << ",TQString.fromLatin1(\"\"))" << endl;
  229. trout << trindent << fullObjName << ".changeTab(" << page << "," << trcall( label, comment ) << ")" << endl;
  230. }
  231. }
  232. } else if ( objClass == "TQWidgetStack" ) {
  233. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  234. if ( tags.contains( n.tagName() ) ) {
  235. TQString page = createObjectImpl( n, objClass, fullObjName );
  236. int id = DomTool::readAttribute( n, "id", "" ).toInt();
  237. out << indent << fullObjName << ".addWidget(" << page << "," << id << ")" << endl;
  238. }
  239. }
  240. } else if ( objClass == "TQToolBox" ) {
  241. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  242. if ( tags.contains( n.tagName() ) ) {
  243. TQString page = createObjectImpl( n, objClass, fullObjName );
  244. TQString comment;
  245. TQString label = DomTool::readAttribute( n, "label", "", comment ).toString();
  246. out << indent << fullObjName << ".addItem(" << page << ",TQString.fromLatin1(\"\"))" << endl;
  247. trout << trindent << fullObjName << ".setItemLabel(" << fullObjName
  248. << ".indexOf(" << page << ")," << trcall( label, comment )
  249. << ")" << endl;
  250. }
  251. }
  252. } else if ( objClass != "TQToolBar" && objClass != "TQMenuBar" ) { // standard widgets
  253. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  254. if ( tags.contains( n.tagName() ) )
  255. createObjectImpl( n, objClass, fullObjName );
  256. }
  257. }
  258. return fullObjName;
  259. }
  260. /*!
  261. Creates a set-call for property \a exclusiveProp of the object
  262. given in \a e.
  263. If the object does not have this property, the function does nothing.
  264. Exclusive properties are used to generate the implementation of
  265. application font or palette change handlers in createFormImpl().
  266. */
  267. void Uic::createExclusiveProperty( const TQDomElement & e, const TQString& exclusiveProp )
  268. {
  269. TQDomElement n;
  270. TQString objClass = getClassName( e );
  271. if ( objClass.isEmpty() )
  272. return;
  273. TQString objName = getObjectName( e );
  274. #if 0 // it's not clear whether this check should be here or not
  275. if ( objName.isEmpty() )
  276. return;
  277. #endif
  278. for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
  279. if ( n.tagName() == "property" ) {
  280. bool stdset = stdsetdef;
  281. if ( n.hasAttribute( "stdset" ) )
  282. stdset = toBool( n.attribute( "stdset" ) );
  283. TQString prop = n.attribute( "name" );
  284. if ( prop != exclusiveProp )
  285. continue;
  286. TQString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
  287. if ( value.isEmpty() )
  288. continue;
  289. out << indent << indent << objName << ".setProperty(\"" << prop << "\",TQVariant(" << value << "))" << endl;
  290. }
  291. }
  292. }
  293. /* Convert a TQSizePolicy::SizeType to text. */
  294. static TQString mapSizeType(TQSizePolicy::SizeType st)
  295. {
  296. const char *txt;
  297. switch (st)
  298. {
  299. case TQSizePolicy::Fixed:
  300. txt = "TQSizePolicy.Fixed";
  301. break;
  302. case TQSizePolicy::Minimum:
  303. txt = "TQSizePolicy.Minimum";
  304. break;
  305. case TQSizePolicy::Maximum:
  306. txt = "TQSizePolicy.Maximum";
  307. break;
  308. case TQSizePolicy::Preferred:
  309. txt = "TQSizePolicy.Preferred";
  310. break;
  311. case TQSizePolicy::MinimumExpanding:
  312. txt = "TQSizePolicy.MinimumExpanding";
  313. break;
  314. case TQSizePolicy::Expanding:
  315. txt = "TQSizePolicy.Expanding";
  316. break;
  317. case TQSizePolicy::Ignored:
  318. txt = "TQSizePolicy.Ignored";
  319. break;
  320. default:
  321. txt = "Invalid TQSizePolicy::SizeType";
  322. }
  323. return txt;
  324. }
  325. /*! Attention: this function has to be in sync with
  326. Resource::saveProperty() and DomTool::elementToVariant. If you
  327. change one, change all.
  328. */
  329. TQString Uic::setObjectProperty( const TQString& objClass, const TQString& obj, const TQString &prop, const TQDomElement &e, bool stdset )
  330. {
  331. TQString v;
  332. if ( e.tagName() == "rect" ) {
  333. TQDomElement n3 = e.firstChild().toElement();
  334. int x = 0, y = 0, w = 0, h = 0;
  335. while ( !n3.isNull() ) {
  336. if ( n3.tagName() == "x" )
  337. x = n3.firstChild().toText().data().toInt();
  338. else if ( n3.tagName() == "y" )
  339. y = n3.firstChild().toText().data().toInt();
  340. else if ( n3.tagName() == "width" )
  341. w = n3.firstChild().toText().data().toInt();
  342. else if ( n3.tagName() == "height" )
  343. h = n3.firstChild().toText().data().toInt();
  344. n3 = n3.nextSibling().toElement();
  345. }
  346. v = "TQRect(%1,%2,%3,%4)";
  347. v = v.arg(x).arg(y).arg(w).arg(h);
  348. } else if ( e.tagName() == "point" ) {
  349. TQDomElement n3 = e.firstChild().toElement();
  350. int x = 0, y = 0;
  351. while ( !n3.isNull() ) {
  352. if ( n3.tagName() == "x" )
  353. x = n3.firstChild().toText().data().toInt();
  354. else if ( n3.tagName() == "y" )
  355. y = n3.firstChild().toText().data().toInt();
  356. n3 = n3.nextSibling().toElement();
  357. }
  358. v = "TQPoint(%1,%2)";
  359. v = v.arg(x).arg(y);
  360. } else if ( e.tagName() == "size" ) {
  361. TQDomElement n3 = e.firstChild().toElement();
  362. int w = 0, h = 0;
  363. while ( !n3.isNull() ) {
  364. if ( n3.tagName() == "width" )
  365. w = n3.firstChild().toText().data().toInt();
  366. else if ( n3.tagName() == "height" )
  367. h = n3.firstChild().toText().data().toInt();
  368. n3 = n3.nextSibling().toElement();
  369. }
  370. v = "TQSize(%1,%2)";
  371. v = v.arg(w).arg(h);
  372. } else if ( e.tagName() == "color" ) {
  373. TQDomElement n3 = e.firstChild().toElement();
  374. int r = 0, g = 0, b = 0;
  375. while ( !n3.isNull() ) {
  376. if ( n3.tagName() == "red" )
  377. r = n3.firstChild().toText().data().toInt();
  378. else if ( n3.tagName() == "green" )
  379. g = n3.firstChild().toText().data().toInt();
  380. else if ( n3.tagName() == "blue" )
  381. b = n3.firstChild().toText().data().toInt();
  382. n3 = n3.nextSibling().toElement();
  383. }
  384. v = "TQColor(%1,%2,%3)";
  385. v = v.arg(r).arg(g).arg(b);
  386. } else if ( e.tagName() == "font" ) {
  387. TQDomElement n3 = e.firstChild().toElement();
  388. TQString attrname = e.parentNode().toElement().attribute( "name", "font" );
  389. TQString fontname;
  390. if ( !obj.isEmpty() ) {
  391. fontname = registerObject( obj + "_" + attrname );
  392. out << indent << fontname << " = TQFont(self." << obj << ".font())" << endl;
  393. } else {
  394. fontname = registerObject( "f" );
  395. out << indent << fontname << " = TQFont(self.font())" << endl;
  396. }
  397. while ( !n3.isNull() ) {
  398. if ( n3.tagName() == "family" )
  399. out << indent << fontname << ".setFamily(\"" << n3.firstChild().toText().data() << "\")" << endl;
  400. else if ( n3.tagName() == "pointsize" )
  401. out << indent << fontname << ".setPointSize(" << n3.firstChild().toText().data() << ")" << endl;
  402. else if ( n3.tagName() == "bold" )
  403. out << indent << fontname << ".setBold(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
  404. else if ( n3.tagName() == "italic" )
  405. out << indent << fontname << ".setItalic(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
  406. else if ( n3.tagName() == "underline" )
  407. out << indent << fontname << ".setUnderline(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
  408. else if ( n3.tagName() == "strikeout" )
  409. out << indent << fontname << ".setStrikeOut(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
  410. n3 = n3.nextSibling().toElement();
  411. }
  412. if ( prop == "font" ) {
  413. if ( !obj.isEmpty() )
  414. out << indent << "self." << obj << ".setFont(" << fontname << ")" << endl;
  415. else
  416. out << indent << "self.setFont(" << fontname << ")" << endl;
  417. } else {
  418. v = fontname;
  419. }
  420. } else if ( e.tagName() == "string" ) {
  421. TQString txt = e.firstChild().toText().data();
  422. TQString com = getComment( e.parentNode() );
  423. if ( prop == "toolTip" && objClass != "TQAction" && objClass != "TQActionGroup" ) {
  424. if ( !obj.isEmpty() )
  425. trout << trindent << "TQToolTip.add(self." << obj << ","
  426. << trcall( txt, com ) << ")" << endl;
  427. else
  428. trout << trindent << "TQToolTip.add(self,"
  429. << trcall( txt, com ) << ")" << endl;
  430. } else if ( prop == "whatsThis" && objClass != "TQAction" && objClass != "TQActionGroup" ) {
  431. if ( !obj.isEmpty() )
  432. trout << trindent << "TQWhatsThis.add(self." << obj << ","
  433. << trcall( txt, com ) << ")" << endl;
  434. else
  435. trout << trindent << "TQWhatsThis.add(self,"
  436. << trcall( txt, com ) << ")" << endl;
  437. } else {
  438. v = trcall( txt, com );
  439. }
  440. } else if ( e.tagName() == "cstring" ) {
  441. v = "\"%1\"";
  442. v = v.arg( e.firstChild().toText().data() );
  443. } else if ( e.tagName() == "number" ) {
  444. v = "%1";
  445. v = v.arg( e.firstChild().toText().data() );
  446. } else if ( e.tagName() == "bool" ) {
  447. if ( stdset )
  448. v = "%1";
  449. else
  450. v = "TQVariant(%1,0)";
  451. v = v.arg( mkBool( e.firstChild().toText().data() ) );
  452. } else if ( e.tagName() == "pixmap" ) {
  453. v = e.firstChild().toText().data();
  454. if ( !v.isEmpty() ) {
  455. if ( pixmapLoaderFunction.isEmpty() ) {
  456. v.prepend( "self." );
  457. } else {
  458. v.prepend( pixmapLoaderFunction + "(" + TQString( externPixmaps ? "\"" : "" ) );
  459. v.append( TQString( externPixmaps ? "\"" : "" ) + ")" );
  460. }
  461. }
  462. } else if ( e.tagName() == "iconset" ) {
  463. v = "TQIconSet(%1)";
  464. TQString s = e.firstChild().toText().data();
  465. if ( !s.isEmpty() ) {
  466. if ( pixmapLoaderFunction.isEmpty() ) {
  467. s.prepend( "self." );
  468. } else {
  469. s.prepend( pixmapLoaderFunction + "(" + TQString( externPixmaps ? "\"" : "" ) );
  470. s.append( TQString( externPixmaps ? "\"" : "" ) + ")" );
  471. }
  472. }
  473. v = v.arg( s );
  474. } else if ( e.tagName() == "image" ) {
  475. v = e.firstChild().toText().data() + ".convertToImage()";
  476. } else if ( e.tagName() == "enum" ) {
  477. v = "%1.%2";
  478. TQString oc = objClass;
  479. TQString ev = e.firstChild().toText().data();
  480. if ( oc == "TQListView" && ev == "Manual" ) // #### workaround, rename TQListView::Manual in 4.0
  481. oc = "TQScrollView";
  482. v = v.arg( oc ).arg( ev );
  483. } else if ( e.tagName() == "set" ) {
  484. TQString keys( e.firstChild().toText().data() );
  485. TQStringList lst = TQStringList::split( '|', keys );
  486. v = "";
  487. TQStringList::Iterator it = lst.begin();
  488. while ( it != lst.end() ) {
  489. v += objClass + "." + *it;
  490. if ( it != lst.fromLast() )
  491. v += " | ";
  492. ++it;
  493. }
  494. } else if ( e.tagName() == "sizepolicy" ) {
  495. TQDomElement n3 = e.firstChild().toElement();
  496. TQSizePolicy sp;
  497. while ( !n3.isNull() ) {
  498. if ( n3.tagName() == "hsizetype" )
  499. sp.setHorData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
  500. else if ( n3.tagName() == "vsizetype" )
  501. sp.setVerData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
  502. else if ( n3.tagName() == "horstretch" )
  503. sp.setHorStretch( n3.firstChild().toText().data().toInt() );
  504. else if ( n3.tagName() == "verstretch" )
  505. sp.setVerStretch( n3.firstChild().toText().data().toInt() );
  506. n3 = n3.nextSibling().toElement();
  507. }
  508. TQString tmp = "self.";
  509. if ( !obj.isEmpty() )
  510. tmp += obj + ".";
  511. v = "TQSizePolicy(%1,%2,%3,%4," + tmp + "sizePolicy().hasHeightForWidth())";
  512. v = v.arg( mapSizeType(sp.horData()) ).arg( mapSizeType(sp.verData()) ).arg( sp.horStretch() ).arg( sp.verStretch() );
  513. } else if ( e.tagName() == "palette" ) {
  514. TQPalette pal;
  515. bool no_pixmaps = e.elementsByTagName( "pixmap" ).count() == 0;
  516. TQDomElement n;
  517. if ( no_pixmaps ) {
  518. n = e.firstChild().toElement();
  519. while ( !n.isNull() ) {
  520. TQColorGroup cg;
  521. if ( n.tagName() == "active" ) {
  522. cg = loadColorGroup( n );
  523. pal.setActive( cg );
  524. } else if ( n.tagName() == "inactive" ) {
  525. cg = loadColorGroup( n );
  526. pal.setInactive( cg );
  527. } else if ( n.tagName() == "disabled" ) {
  528. cg = loadColorGroup( n );
  529. pal.setDisabled( cg );
  530. }
  531. n = n.nextSibling().toElement();
  532. }
  533. }
  534. if ( no_pixmaps && pal == TQPalette( pal.active().button(), pal.active().background() ) ) {
  535. v = "TQPalette(TQColor(%1,%2,%3),TQColor(%1,%2,%3))";
  536. v = v.arg( pal.active().button().red() ).arg( pal.active().button().green() ).arg( pal.active().button().blue() );
  537. v = v.arg( pal.active().background().red() ).arg( pal.active().background().green() ).arg( pal.active().background().blue() );
  538. } else {
  539. TQString palette = "pal";
  540. if ( !pal_used ) {
  541. out << indent << palette << " = TQPalette()" << endl;
  542. pal_used = TRUE;
  543. }
  544. TQString cg = "cg";
  545. if ( !cg_used ) {
  546. out << indent << cg << " = TQColorGroup()" << endl;
  547. cg_used = TRUE;
  548. }
  549. n = e.firstChild().toElement();
  550. while ( !n.isNull() && n.tagName() != "active" )
  551. n = n.nextSibling().toElement();
  552. createColorGroupImpl( cg, n );
  553. out << indent << palette << ".setActive(" << cg << ")" << endl;
  554. n = e.firstChild().toElement();
  555. while ( !n.isNull() && n.tagName() != "inactive" )
  556. n = n.nextSibling().toElement();
  557. createColorGroupImpl( cg, n );
  558. out << indent << palette << ".setInactive(" << cg << ")" << endl;
  559. n = e.firstChild().toElement();
  560. while ( !n.isNull() && n.tagName() != "disabled" )
  561. n = n.nextSibling().toElement();
  562. createColorGroupImpl( cg, n );
  563. out << indent << palette << ".setDisabled(" << cg << ")" << endl;
  564. v = palette;
  565. }
  566. } else if ( e.tagName() == "cursor" ) {
  567. v = "TQCursor(%1)";
  568. v = v.arg( e.firstChild().toText().data() );
  569. } else if ( e.tagName() == "date" ) {
  570. TQDomElement n3 = e.firstChild().toElement();
  571. int y, m, d;
  572. y = m = d = 0;
  573. while ( !n3.isNull() ) {
  574. if ( n3.tagName() == "year" )
  575. y = n3.firstChild().toText().data().toInt();
  576. else if ( n3.tagName() == "month" )
  577. m = n3.firstChild().toText().data().toInt();
  578. else if ( n3.tagName() == "day" )
  579. d = n3.firstChild().toText().data().toInt();
  580. n3 = n3.nextSibling().toElement();
  581. }
  582. v = "TQDate(%1,%2,%3)";
  583. v = v.arg(y).arg(m).arg(d);
  584. } else if ( e.tagName() == "time" ) {
  585. TQDomElement n3 = e.firstChild().toElement();
  586. int h, m, s;
  587. h = m = s = 0;
  588. while ( !n3.isNull() ) {
  589. if ( n3.tagName() == "hour" )
  590. h = n3.firstChild().toText().data().toInt();
  591. else if ( n3.tagName() == "minute" )
  592. m = n3.firstChild().toText().data().toInt();
  593. else if ( n3.tagName() == "second" )
  594. s = n3.firstChild().toText().data().toInt();
  595. n3 = n3.nextSibling().toElement();
  596. }
  597. v = "TQTime(%1,%2,%3)";
  598. v = v.arg(h).arg(m).arg(s);
  599. } else if ( e.tagName() == "datetime" ) {
  600. TQDomElement n3 = e.firstChild().toElement();
  601. int h, mi, s, y, mo, d;
  602. h = mi = s = y = mo = d = 0;
  603. while ( !n3.isNull() ) {
  604. if ( n3.tagName() == "hour" )
  605. h = n3.firstChild().toText().data().toInt();
  606. else if ( n3.tagName() == "minute" )
  607. mi = n3.firstChild().toText().data().toInt();
  608. else if ( n3.tagName() == "second" )
  609. s = n3.firstChild().toText().data().toInt();
  610. else if ( n3.tagName() == "year" )
  611. y = n3.firstChild().toText().data().toInt();
  612. else if ( n3.tagName() == "month" )
  613. mo = n3.firstChild().toText().data().toInt();
  614. else if ( n3.tagName() == "day" )
  615. d = n3.firstChild().toText().data().toInt();
  616. n3 = n3.nextSibling().toElement();
  617. }
  618. v = "TQDateTime(TQDate(%1,%2,%3),TQTime(%4,%5,%6))";
  619. v = v.arg(y).arg(mo).arg(d).arg(h).arg(mi).arg(s);
  620. } else if ( e.tagName() == "stringlist" ) {
  621. TQStringList l;
  622. TQDomElement n3 = e.firstChild().toElement();
  623. TQString listname = "l";
  624. if ( !obj.isEmpty() ) {
  625. listname = obj + "_stringlist";
  626. listname = registerObject( listname );
  627. out << indent << listname << " = TQStringList()" << endl;
  628. } else {
  629. out << indent << listname << " = TQStringList()" << endl;
  630. }
  631. while ( !n3.isNull() ) {
  632. if ( n3.tagName() == "string" )
  633. out << indent << listname << ".append(\"" << n3.firstChild().toText().data().simplifyWhiteSpace() << "\")" << endl;
  634. n3 = n3.nextSibling().toElement();
  635. }
  636. v = listname;
  637. }
  638. return v;
  639. }
  640. /*! Extracts a named object property from \a e.
  641. */
  642. TQDomElement Uic::getObjectProperty( const TQDomElement& e, const TQString& name )
  643. {
  644. TQDomElement n;
  645. for ( n = e.firstChild().toElement();
  646. !n.isNull();
  647. n = n.nextSibling().toElement() ) {
  648. if ( n.tagName() == "property" && n.toElement().attribute("name") == name )
  649. return n;
  650. }
  651. return n;
  652. }