KOffice – TDE office suite
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.

2550 lines
74KB

  1. /* -*- Mode: C++ -*-
  2. $Id: KDGanttViewItem.cpp 523435 2006-03-28 08:01:15Z mlaurent $
  3. KDGantt - a multi-platform charting engine
  4. */
  5. /****************************************************************************
  6. ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
  7. **
  8. ** This file is part of the KDGantt library.
  9. **
  10. ** This file may be distributed and/or modified under the terms of the
  11. ** GNU General Public License version 2 as published by the Free Software
  12. ** Foundation and appearing in the file LICENSE.GPL included in the
  13. ** packaging of this file.
  14. **
  15. ** Licensees holding valid commercial KDGantt licenses may use this file in
  16. ** accordance with the KDGantt Commercial License Agreement provided with
  17. ** the Software.
  18. **
  19. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. **
  22. ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
  23. ** information about KDGantt Commercial License Agreements.
  24. **
  25. ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
  26. ** licensing are not clear to you.
  27. **
  28. ** As a special exception, permission is given to link this program
  29. ** with any edition of TQt, and distribute the resulting executable,
  30. ** without including the source code for TQt in the source distribution.
  31. **
  32. **********************************************************************/
  33. #include "KDGanttViewSubwidgets.h"
  34. #include "KDGanttViewTaskItem.h"
  35. #include "KDGanttViewSummaryItem.h"
  36. #include "KDGanttViewEventItem.h"
  37. #include "itemAttributeDialog.h"
  38. #include "tqpainter.h"
  39. #include "KDGanttXMLTools.h"
  40. /*!
  41. \class KDGanttViewItem KDGanttViewItem.h
  42. This class represents an item in a Gantt chart.
  43. This class is an abstract base class, it cannot be instantiated
  44. directly. Instead, you should create items of one of the
  45. subclasses. This class provides methods common to all Gantt items.
  46. The initialization of the shapes/colors of the item works as follows:
  47. Shapes:
  48. When a new item is created, the shapes are set to the default values
  49. for items of the type of this item, defined in the KDGanttView class with
  50. void setShapes( KDGanttViewItem::Type type,
  51. KDGanttViewItem::Shape start,
  52. KDGanttViewItem::Shape middle,
  53. KDGanttViewItem::Shape end );
  54. If there is no default value defined for this type,
  55. the shapes are set as follows:
  56. For TaskViewItems all three shapes are set to Square.
  57. For SummaryViewItems all three shapes are set to TriangleDown.
  58. For EventViewItems all three shapes are set to Diamond.
  59. Colors:
  60. When a new item is created, the colors are set to the default values
  61. for items of the type of this item, defined in the KDGanttView class with
  62. void setColors( KDGanttViewItem::Type type,
  63. const TQColor& start,
  64. const TQColor& middle,
  65. const TQColor& end );
  66. If there is no default value defined for this type,
  67. the colors of the shapes are set to the default color for items of this type,
  68. defined in the KDGanttView class with:
  69. void setDefaultColor( KDGanttViewItem::Type type, const TQColor& );
  70. The initial default color in the KDGanttView class is set to
  71. blue for KDGanttViewItem::Event,
  72. green for KDGanttViewItem::Task,
  73. cyan for KDGanttViewItem::Summary.
  74. Highlight Colors:
  75. When a new item is created, the highlight colors are set to the default
  76. values for items of the type of this item,
  77. defined in the KDGanttView class with:
  78. void setHighlightColors( KDGanttViewItem::Type type,
  79. const TQColor& start,
  80. const TQColor& middle,
  81. const TQColor& end );
  82. If there is no default value defined for this type,
  83. the highlight colors of the shapes are set to the default color for
  84. items of this type, defined in the KDGanttView class with:
  85. void setDefaultHighlightColor( KDGanttViewItem::Type type, const TQColor& );
  86. The initial default highlight color in the KDGanttView class is set to red
  87. for all types.
  88. Start/End time:
  89. When a new item is created, the start time and the end time is set
  90. automatically. The time, which is currently displayed in the middle
  91. of the Gantt View, is set as start/end time. At startup of a newly
  92. created Gantt view, this is the current time.
  93. The Priority:
  94. The priority is set with \a setPriority().
  95. The priority determines which items are painted over which other items.
  96. The item with the highest priority is painted on top of all others.
  97. The priority for an item can be between 1 and 199.
  98. A priority less than 100 means that the item is painted below the
  99. grid in the Gantt chart.
  100. For Task items, the default priority is 50, for all other items it is 150.
  101. This feature only makes sense for an item which is a child of another item,
  102. for which \a displaySubitemsAsGroup() property is set to true.
  103. The Display Mode:
  104. The display mode is set with \a setDisplaySubitemsAsGroup().
  105. In the normal view mode (set with setDisplaySubitemsAsGroup( false ); ),
  106. an item is displayed in the same manner, when its child items are
  107. shown or not.
  108. In the other mode (set with setDisplaySubitemsAsGroup( true ); ),
  109. called "calendar mode", the item is displayed as follows:
  110. If the item has no children, it is displayed as usual.
  111. If the item is opened (i.e., its children are displayed), the
  112. start/end time of this item is computed automatically according to
  113. the earliest start time/latest end time of its children. The item
  114. and its children are displayed as usual.
  115. If the item is closed (i.e., its children are hidden in the left
  116. list view), the item itself is hidden, and its children are displayed
  117. on the timeline of this item instead. To control the painting of
  118. overlapping children, call \a setPriority() for the childs.
  119. Blocking of user interaction to open item:
  120. If you want to block users to open items used as parents of calendar items,
  121. call \a KDGanttView::setCalendarMode( true );
  122. Example 1, Color:
  123. If you create an instance of a KDGanttView class and add a SummaryViewItem
  124. without setting any color/shape values, you get an item with three shapes
  125. of the form TriangleDown in the color magenta. If the item is highlighted,
  126. the color will change to the highlight color red.
  127. Example 2, Calender View:
  128. To use a Gantt view as a calendar view, call
  129. \a KDGanttView::setCalendarMode( true );
  130. \a KDGanttView::setDisplaySubitemsAsGroup( true );
  131. Insert root items in the Gantt view.
  132. Insert items as children of these root item in the Gantt view.
  133. You may use any item type as parent and child; there are no limitations.
  134. It is, however, recommended to use KDGanttViewTaskItems
  135. Actually, you may add child items to the children themselves.
  136. Such a child behaves then like a parent.
  137. Now set the start/end time of the children to specify a time
  138. interval for these items.
  139. */
  140. TQDict<KDGanttViewItem> KDGanttViewItem::sItemDict;
  141. /*!
  142. Constructs an empty Gantt item.
  143. \param type the type of the item to insert
  144. \param view the Gantt view to insert this item into
  145. \param lvtext the text to show in the list view
  146. \param name the name by which the item can be identified. If no name
  147. is specified, a unique name will be generated
  148. */
  149. KDGanttViewItem::KDGanttViewItem( Type type, KDGanttView* view,
  150. const TQString& lvtext,
  151. const TQString& name ) :
  152. TQListViewItem(view->myListView,lvtext)
  153. {
  154. initColorAndShapes(type);
  155. generateAndInsertName( name );
  156. }
  157. /*!
  158. Constructs an empty Gantt item.
  159. \param type the type of the item to insert
  160. \param parentItem a parent item under which this one goes
  161. \param lvtext the text to show in the list view
  162. \param name the name by which the item can be identified. If no name
  163. is specified, a unique name will be generated
  164. */
  165. KDGanttViewItem::KDGanttViewItem( Type type, KDGanttViewItem* parentItem,
  166. const TQString& lvtext,
  167. const TQString& name ) :
  168. TQListViewItem(parentItem,lvtext)
  169. {
  170. initColorAndShapes(type);
  171. generateAndInsertName( name );
  172. }
  173. /*!
  174. Constructs an empty Gantt item.
  175. \param type the type of the item to insert
  176. \param view the Gantt view to insert this item into
  177. \param after another item at the same level behind which this one should go
  178. \param lvtext the text to show in the list view
  179. \param name the name by which the item can be identified. If no name
  180. is specified, a unique name will be generated
  181. */
  182. KDGanttViewItem::KDGanttViewItem( Type type, KDGanttView* view,
  183. KDGanttViewItem* after,
  184. const TQString& lvtext,
  185. const TQString& name ) :
  186. TQListViewItem(view->myListView,after, lvtext)
  187. {
  188. initColorAndShapes(type);
  189. generateAndInsertName( name );
  190. }
  191. /*!
  192. Constructs an empty Gantt item.
  193. \param type the type of the item to insert
  194. \param parentItem a parent item under which this one goes
  195. \param after another item at the same level behind which this one should go
  196. \param lvtext the text to show in the list view
  197. \param name the name by which the item can be identified. If no name
  198. is specified, a unique name will be generated
  199. */
  200. KDGanttViewItem::KDGanttViewItem( Type type, KDGanttViewItem* parentItem,
  201. KDGanttViewItem* after,
  202. const TQString& lvtext,
  203. const TQString& name ) :
  204. TQListViewItem( parentItem, after, lvtext )
  205. {
  206. initColorAndShapes(type);
  207. generateAndInsertName( name );
  208. }
  209. /*!
  210. Destroys the object and frees any allocated resources.
  211. */
  212. KDGanttViewItem::~KDGanttViewItem()
  213. {
  214. myGanttView->notifyEditdialog( this );
  215. if ( startLine ) delete startLine;
  216. if ( endLine ) delete endLine ;
  217. if ( startLineBack ) delete startLineBack ;
  218. if ( endLineBack ) delete endLineBack ;
  219. if ( actualEnd ) delete actualEnd ;
  220. if ( textCanvas ) delete textCanvas ;
  221. if ( startShape ) delete startShape ;
  222. if ( midShape ) delete midShape ;
  223. if ( endShape ) delete endShape ;
  224. if ( startShapeBack ) delete startShapeBack ;
  225. if ( midShapeBack ) delete midShapeBack ;
  226. if ( endShapeBack ) delete endShapeBack ;
  227. if ( progressShape ) delete progressShape ;
  228. if ( floatStartShape ) delete floatStartShape ;
  229. if ( floatEndShape ) delete floatEndShape ;
  230. myGanttView->myTimeTable->removeItemFromTasklinks( this );
  231. myGanttView->myCanvasView->resetCutPaste( this );
  232. if ( listView() ) {
  233. if ( isOpen() )
  234. setOpen( false );
  235. if ( parent() )
  236. parent()->takeItem( this );
  237. else
  238. myGanttView->myListView->takeItem( this );
  239. myGanttView->myTimeTable->updateMyContent();
  240. }
  241. // myGanttView->myTimeTable->removeItemFromTasklinks( this );
  242. // myGanttView->myCanvasView->resetCutPaste( this );
  243. }
  244. /*!
  245. Generates a unique name if necessary and inserts it into the item
  246. dictionary.
  247. */
  248. void KDGanttViewItem::generateAndInsertName( const TQString& name )
  249. {
  250. // First check if we already had a name. This can be the case if
  251. // the item was reconstructed from an XML file.
  252. if( !_name.isEmpty() )
  253. // We had a name, remove it
  254. sItemDict.remove( _name );
  255. TQString newName;
  256. if ( name.isEmpty() || sItemDict.find( name ) ) {
  257. // create unique name
  258. newName.sprintf( "%p", (void* )this );
  259. while( sItemDict.find( newName ) ) {
  260. newName += "_0";
  261. }
  262. } else {
  263. newName = name;
  264. }
  265. sItemDict.insert( newName, this );
  266. _name = newName;
  267. }
  268. /*!
  269. Returns the unique name that can identify the item.
  270. \return the unique item name
  271. */
  272. TQString KDGanttViewItem::name() const
  273. {
  274. return _name;
  275. }
  276. /*!
  277. Returns the item with the specified name.
  278. \param name the name to search for
  279. \return the item with the specified name; 0 if no group
  280. with that name exists
  281. */
  282. KDGanttViewItem* KDGanttViewItem::find( const TQString& name )
  283. {
  284. if (name.isEmpty()) // avoid error msg from TQDict
  285. return 0;
  286. return sItemDict.find( name );
  287. }
  288. /*!
  289. Returns the type of the item.
  290. This may be Event, Task, Summary.
  291. \return the type of the item
  292. */
  293. KDGanttViewItem::Type KDGanttViewItem::type() const
  294. {
  295. return myType;
  296. }
  297. /*!
  298. Specifies whether this item is enabled. If disabled, the item stays in the
  299. Gantt view and the item is shown in gray to show that the item is disabled.
  300. All signals of this item (like itemLeftClicked( this )) are blocked.
  301. If the item displays its subitems (childs) as a group,
  302. (displaySubitemsAsGroup() == true)
  303. all changes apply to all subitems as well.
  304. \param on pass true to make this item editable
  305. \sa enabled ()
  306. */
  307. void KDGanttViewItem::setEnabled( bool on )
  308. {
  309. _enabled = on;
  310. if ( displaySubitemsAsGroup() ) {
  311. myGanttView->myTimeTable->inc_blockUpdating();
  312. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  313. while (temp != 0) {
  314. temp->setEnabled( on );
  315. temp = temp->nextSibling();
  316. }
  317. TQListViewItem::setEnabled( on );
  318. myGanttView->myTimeTable->dec_blockUpdating();
  319. }
  320. updateCanvasItems();
  321. }
  322. /*!
  323. Returns whether this item is enabled.
  324. \return true if this item is enabled, false otherwise
  325. \sa setEnabled()
  326. */
  327. bool KDGanttViewItem::enabled () const
  328. {
  329. return _enabled;
  330. }
  331. // *********************************
  332. /*!
  333. Specifies whether this item is visible.
  334. \param on pass true to make this item visible
  335. \sa itemVisible ()
  336. */
  337. void KDGanttViewItem::setItemVisible( bool on )
  338. {
  339. if ( on ) {
  340. resetSubitemVisibility();
  341. } else
  342. setVisible( false );
  343. //updateCanvasItems();
  344. myGanttView->myTimeTable->updateMyContent();
  345. }
  346. /*!
  347. Returns whether this item is visible.
  348. \return true if this item is visible, false otherwise
  349. \sa setItemVisible()
  350. */
  351. bool KDGanttViewItem::itemVisible () const
  352. {
  353. return TQListViewItem::isVisible();
  354. }
  355. // *************************************
  356. /*!
  357. Specifies whether this item is editable. The whole Gantt view needs
  358. to be editable as well for this to have any effect.
  359. \param editable pass true to make this item editable
  360. \sa editable(), KDGanttView::setEditable(), KDGanttView::editable()
  361. */
  362. void KDGanttViewItem::setEditable( bool editable )
  363. {
  364. isEditable = editable;
  365. }
  366. /*!
  367. Returns whether this item is editable.
  368. \return true if this item is editable, false otherwise
  369. \sa setEditable(), KDGanttView::setEditable(), KDGanttView::editable()
  370. */
  371. bool KDGanttViewItem::editable() const
  372. {
  373. return isEditable;
  374. }
  375. /*!
  376. Specifies whether this item shows hidden subitems on its timeline.
  377. Useful to get a so called "calendar view" with many items in one row.
  378. When \a displaySubitemsAsGroup() is set to true, this item has a normal view,
  379. when it is expanded. If it is not expanded (and has at least one child),
  380. the item itself is hidden, and all children are displayed instead.
  381. To manage the painting priority of the childs (if overlapping),
  382. you may set \a priority() of these items.
  383. \param show pass true to make this item displaying hidden subitems
  384. \sa editable(), KDGanttView::setEditable(), KDGanttView::editable(), setPriority()
  385. */
  386. void KDGanttViewItem::setDisplaySubitemsAsGroup( bool show )
  387. {
  388. if ( !show && _displaySubitemsAsGroup)
  389. isVisibleInGanttView = true;
  390. _displaySubitemsAsGroup = show;
  391. if ( parent() )
  392. if ( parent()->isOpen() )
  393. parent()->setOpen( true );
  394. if ( isOpen() )
  395. setOpen( true );
  396. updateCanvasItems();
  397. }
  398. /*!
  399. Returns whether this item displays hidden subitems.
  400. Initial set to false.
  401. \return true if this item displays hidden subitems, false otherwise
  402. \sa setDisplaySubitemsAsGroup()
  403. */
  404. bool KDGanttViewItem::displaySubitemsAsGroup() const
  405. {
  406. return _displaySubitemsAsGroup;
  407. }
  408. /*!
  409. Specifies the priority of this item.
  410. Valid values are between 1 and 199.
  411. A priority less than 100 means that the item is painted in the
  412. Gantt chart below the grid. A priority more than 100 means
  413. that the item is painted in the Gantt chart over the grid.
  414. For a value of 100, the behavior is unspecified.
  415. An item with a higher priority is painted over an item with a lower
  416. priority in the Gantt chart. The painting order of items with the
  417. same priority is unspecified.
  418. For Calendar items, the default priority is 50, for all other items
  419. it is 150.
  420. This feature makes only sense for an item which is a child of
  421. another item, which \a displaySubitemsAsGroup() property is set to
  422. true.
  423. \param prio the new priority of this item.
  424. \sa priority(), displaySubitemsAsGroup()
  425. */
  426. void KDGanttViewItem::setPriority( int prio )
  427. {
  428. if ( prio < 1 )
  429. prio = 1;
  430. if (prio > 199 )
  431. prio = 199;
  432. _priority = prio;
  433. updateCanvasItems();
  434. }
  435. /*!
  436. Returns the priority of this item.
  437. \return the priority of this item
  438. \sa setDisplaySubitemsAsGroup()
  439. */
  440. int KDGanttViewItem::priority()
  441. {
  442. return _priority;
  443. }
  444. /*!
  445. Specifies the start time of this item. The parameter must be valid
  446. and non-null. If the parameter is invalid or null, no value is set.
  447. Reimplemented in the subclasses.
  448. \param start the start time
  449. \sa startTime(), setEndTime(), endTime()
  450. */
  451. void KDGanttViewItem::setStartTime( const TQDateTime& )
  452. {
  453. }
  454. /*!
  455. Returns the start time of this item.
  456. \return the start time of this item
  457. \sa setStartTime(), setEndTime(), endTime()
  458. */
  459. TQDateTime KDGanttViewItem::startTime() const
  460. {
  461. return myStartTime;
  462. }
  463. /*!
  464. Specifies the end time of this item. The parameter must be valid
  465. and non-null. If the parameter is invalid or null, no value is set.
  466. Reimplemented in the subclasses
  467. \param end the end time
  468. \sa endTime(), setStartTime(), startTime()
  469. */
  470. void KDGanttViewItem::setEndTime( const TQDateTime& end )
  471. {
  472. switch( type() ) {
  473. case Event:
  474. tqDebug( "KDGantt:Event Item has no end time" );
  475. break;
  476. case Summary:
  477. ((KDGanttViewSummaryItem*)this)->setEndTime( end );
  478. break;
  479. case Task:
  480. tqDebug( "KDGantt:Task Item has no end time" );
  481. break;
  482. default:
  483. tqDebug( "Unknown type in KDGanttViewItem::typeToString()" );
  484. }
  485. }
  486. /*!
  487. Returns the end time of this item.
  488. \return the end time of this item
  489. \sa setEndTime(), setStartTime(), startTime()
  490. */
  491. TQDateTime KDGanttViewItem::endTime() const
  492. {
  493. return myEndTime;
  494. }
  495. /*!
  496. Sets the text to be shown in this item in the Gantt view.
  497. For a KDGanttViewTaskItem witht displaySubitemsAsGroup() == true,
  498. the text is shown in the item itself and
  499. the text is truncated automatically, if it does not fit in the item.
  500. For all other item types, the text is shown to the right of the item.
  501. \param text the text to be shown
  502. \sa text(), setTextColor(), textColor(), setListViewText(),
  503. listViewText()
  504. */
  505. void KDGanttViewItem::setText( const TQString& text )
  506. {
  507. textCanvas->setText(text);
  508. textCanvasText = text;
  509. updateCanvasItems();
  510. }
  511. /*!
  512. Returns the text to be shown in this item in the Gantt view.
  513. \return the text to be shown in this item
  514. \sa setText(), setTextColor(), textColor(), setListViewText(),
  515. listViewText()
  516. */
  517. TQString KDGanttViewItem::text() const
  518. {
  519. return textCanvasText;
  520. }
  521. /*!
  522. \deprecated Use setListViewTest( int, const TQString& ) instead
  523. */
  524. void KDGanttViewItem::setListViewText( const TQString& text, int column )
  525. {
  526. TQListViewItem::setText( column, text );
  527. }
  528. /*!
  529. Sets the text to be shown in this item in the list view.
  530. \param column the column in which the text will be shown
  531. \param text the text to be shown
  532. \sa text(), setTextColor(), textColor(), setText(), listViewText()
  533. */
  534. void KDGanttViewItem::setListViewText( int column, const TQString& text )
  535. {
  536. TQListViewItem::setText( column, text );
  537. }
  538. /*!
  539. Returns the text to be shown in this item in the list view.
  540. \param column the column in which the text will be shown
  541. \return the text to be shown in this item
  542. \sa setText(), setTextColor(), textColor(), text(),
  543. setListViewText()
  544. */
  545. TQString KDGanttViewItem::listViewText( int column ) const
  546. {
  547. return TQListViewItem::text( column );
  548. }
  549. /*!
  550. Sets the font to be used for the text in this item.
  551. \param font the font to be shown
  552. \sa font()
  553. */
  554. void KDGanttViewItem::setFont( const TQFont& font )
  555. {
  556. textCanvas->setFont(font);
  557. updateCanvasItems();
  558. }
  559. /*!
  560. Returns the font used for the text in this item.
  561. \return the font used for the text in this item
  562. \sa setFont()
  563. */
  564. TQFont KDGanttViewItem::font() const
  565. {
  566. return textCanvas->font();
  567. }
  568. /*!
  569. Sets the text to show in a tooltip for this item.
  570. \param text the tooltip text
  571. \sa tooltipText()
  572. */
  573. void KDGanttViewItem::setTooltipText( const TQString& text )
  574. {
  575. myToolTipText = text;
  576. }
  577. /*!
  578. Returns the tooltip text of this item
  579. \return the tooltip text
  580. \sa setTooltipText()
  581. */
  582. TQString KDGanttViewItem::tooltipText() const
  583. {
  584. return myToolTipText;
  585. }
  586. /*!
  587. Sets the text to show in a What's This window for this item.
  588. \param text the what's this text
  589. \sa whatsThisText()
  590. */
  591. void KDGanttViewItem::setWhatsThisText( const TQString& text )
  592. {
  593. myWhatsThisText = text;
  594. }
  595. /*!
  596. Returns the what's this text of this item
  597. \return the what's this text
  598. \sa setWhatsThisText()
  599. */
  600. TQString KDGanttViewItem::whatsThisText() const
  601. {
  602. return myWhatsThisText;
  603. }
  604. /*!
  605. Specifies whether this item should be shown highlighted. The user
  606. can also highlight items with the mouse.
  607. If the item displays its subitems (children) as a group
  608. (displaySubitemsAsGroup() == true),
  609. all changes apply to all subitems as well.
  610. \param highlight true in order to highlight, false in order to turn
  611. highlighting off for this item
  612. \sa highlight()
  613. */
  614. void KDGanttViewItem::setHighlight( bool highlight )
  615. {
  616. isHighlighted = highlight;
  617. if ( displaySubitemsAsGroup() ) {
  618. myGanttView->myTimeTable->inc_blockUpdating();
  619. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  620. while (temp != 0) {
  621. temp->setHighlight( highlight );
  622. temp = temp->nextSibling();
  623. }
  624. myGanttView->myTimeTable->dec_blockUpdating();
  625. }
  626. updateCanvasItems();
  627. }
  628. /*!
  629. Returns whether this item is highlighted, either programmatically
  630. with setHighlight() or by the user with the mouse.
  631. \return true if the item is highlighted
  632. \sa setHighlight()
  633. */
  634. bool KDGanttViewItem::highlight() const
  635. {
  636. return isHighlighted;
  637. }
  638. /*!
  639. Specifies the shapes to be used for this item.
  640. It is advisable not to use this method, but rather set the shapes
  641. for all items of a type with KDGanttView::setShapes() in order to
  642. get a uniform Gantt view.
  643. \param start the start shape
  644. \param middle the middle shape
  645. \param end the end shape
  646. \sa shapes(), setColors(), colors()
  647. */
  648. void KDGanttViewItem::setShapes( Shape start, Shape middle, Shape end )
  649. {
  650. myStartShape = start;
  651. myMiddleShape= middle;
  652. myEndShape= end;
  653. createShape(startShape,startShapeBack,start);
  654. createShape(midShape,midShapeBack,middle);
  655. midShape->setZ( 4 );
  656. createShape(endShape,endShapeBack,end);
  657. updateCanvasItems();
  658. }
  659. /*!
  660. Creates shapes of the specified type \a shape.
  661. The background shape color is set to black and the background shape
  662. is slightly bit bigger than the foreground shape to have a black border
  663. around the foreground shape.
  664. \param itemShape the foreground shape
  665. \param middle itemShapeBack the background shape
  666. \param shape the type of the shape
  667. (may be TriangleDown, TriangleUp, Diamond, Square, Circle)
  668. \sa shapes(), setColors(), colors()
  669. */
  670. void KDGanttViewItem::createShape( KDCanvasPolygonItem* &itemShape,
  671. KDCanvasPolygonItem* &itemShapeBack,
  672. Shape shape )
  673. {
  674. if ( itemShape && type() == Task )
  675. return;
  676. if (itemShape) delete itemShape;
  677. if (itemShapeBack) delete itemShapeBack;
  678. TQCanvasPolygonalItem * item;
  679. TQCanvasPolygonalItem * itemBack;
  680. int size = myItemSize+2;
  681. int hei = (myItemSize/3)/2;
  682. switch (shape) {
  683. case TriangleDown:
  684. {
  685. item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  686. TQPointArray arr = TQPointArray(3);
  687. arr.setPoint(0,-size/2,-hei);
  688. arr.setPoint(1,size/2,-hei);
  689. arr.setPoint(2,0,((size/2)-hei));
  690. ((TQCanvasPolygon*)item)->setPoints(arr);
  691. size += 4;hei +=1;
  692. itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  693. arr.setPoint(0,-size/2,-hei);
  694. arr.setPoint(1,size/2,-hei);
  695. arr.setPoint(2,0,((size/2)-hei));
  696. ((TQCanvasPolygon*)itemBack)->setPoints(arr);
  697. break;
  698. }
  699. case TriangleUp:
  700. {
  701. // I really do not know why, but we get only an TriangleUp-icon
  702. // of the same size as a TriangleDown-icon, if we increment the size by 2
  703. size+=2;
  704. item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  705. TQPointArray arr = TQPointArray(3);
  706. arr.setPoint(0,-size/2,hei);
  707. arr.setPoint(1,size/2,hei);
  708. arr.setPoint(2,0,(-size/2)+hei);
  709. ((TQCanvasPolygon*)item)->setPoints(arr);
  710. size += 4;hei +=1;
  711. itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  712. arr.setPoint(0,-size/2,hei);
  713. arr.setPoint(1,size/2,hei);
  714. arr.setPoint(2,0,(-size/2)+hei);
  715. ((TQCanvasPolygon*)itemBack)->setPoints(arr);
  716. break;
  717. }
  718. case Diamond:
  719. {
  720. item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  721. TQPointArray arr = TQPointArray(4);
  722. arr.setPoint(0,0,-size/2);
  723. arr.setPoint(1,size/2,0);
  724. arr.setPoint(2,0,size/2);
  725. arr.setPoint(3,-size/2,0);
  726. ((TQCanvasPolygon*)item)->setPoints(arr);
  727. size += 2;hei +=1;
  728. itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  729. arr.setPoint(0,0,-size/2);
  730. arr.setPoint(1,size/2,0);
  731. arr.setPoint(2,0,size/2);
  732. arr.setPoint(3,-size/2,0);
  733. ((TQCanvasPolygon*)itemBack)->setPoints(arr);
  734. break;
  735. }
  736. case Square:
  737. {
  738. size -=2;
  739. item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  740. TQPointArray arr = TQPointArray(4);
  741. arr.setPoint(0,-size/2,-size/2);
  742. arr.setPoint(1,size/2,-size/2);
  743. arr.setPoint(2,size/2,size/2);
  744. arr.setPoint(3,-size/2,size/2);
  745. ((TQCanvasPolygon*)item)->setPoints(arr);
  746. size += 2;hei +=1;
  747. itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  748. arr.setPoint(0,-size/2,-size/2);
  749. arr.setPoint(1,size/2,-size/2);
  750. arr.setPoint(2,size/2,size/2);
  751. arr.setPoint(3,-size/2,size/2);
  752. ((TQCanvasPolygon*)itemBack)->setPoints(arr);
  753. break;
  754. }
  755. case Circle:
  756. {
  757. size -= 2;
  758. item = new KDCanvasEllipse(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  759. ((KDCanvasEllipse*)item)->setSize(size,size);
  760. size += 2;hei +=1;
  761. itemBack = new KDCanvasEllipse(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
  762. ((KDCanvasEllipse*)itemBack)->setSize(size,size);
  763. break;
  764. }
  765. default:
  766. // Uninitialized shape, can e.g. be the case with free-busy
  767. // items which don't have any shapes
  768. return;
  769. }
  770. item->setBrush(Qt::SolidPattern);
  771. item->setZ(5);
  772. itemShape = (KDCanvasPolygonItem*) item;
  773. itemBack->setBrush(Qt::SolidPattern);
  774. itemBack->setZ(3);
  775. itemShapeBack = (KDCanvasPolygonItem*) itemBack;
  776. }
  777. /*!
  778. Returns the shapes used for this item
  779. \param start returns the start shape
  780. \param middle returns the middle shape
  781. \param end returns the end shape
  782. \sa setShapes(), setColors(), colors()
  783. */
  784. void KDGanttViewItem::shapes( Shape& start, Shape& middle, Shape& end ) const
  785. {
  786. start = myStartShape;
  787. middle = myMiddleShape;
  788. end = myEndShape;
  789. }
  790. /*!
  791. Specifies the colors in which to draw the shapes of this item.
  792. It is advisable not to use this method, but rather set the colors
  793. for all items of a type with KDGanttView::setColors() in order to
  794. get a uniform Gantt view.
  795. \param start the color for the start shape
  796. \param middle the color for the middle shape
  797. \param end the color for the end shape
  798. \sa colors(), setShapes(), shapes(), setDefaultColor(), defaultColor()
  799. */
  800. void KDGanttViewItem::setColors( const TQColor& start, const TQColor& middle,
  801. const TQColor& end )
  802. {
  803. myStartColor=start ;
  804. myMiddleColor= middle;
  805. myEndColor= end;
  806. if ( displaySubitemsAsGroup() ) {
  807. myGanttView->myTimeTable->inc_blockUpdating();
  808. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  809. while (temp != 0) {
  810. temp->setColors( start, middle, end );
  811. temp = temp->nextSibling();
  812. }
  813. myGanttView->myTimeTable->dec_blockUpdating();
  814. }
  815. updateCanvasItems();
  816. }
  817. /*!
  818. Returns the colors used for this item
  819. \param start returns the start color
  820. \param middle returns the middle color
  821. \param end returns the end color
  822. \sa setColors(), setShapes(), shapes(), setDefaultColor(), defaultColor()
  823. */
  824. void KDGanttViewItem::colors( TQColor& start, TQColor& middle, TQColor& end ) const
  825. {
  826. start = myStartColor ;
  827. middle = myMiddleColor;
  828. end = myEndColor;
  829. }
  830. /*!
  831. Specifies the highlight colors in which to draw the shapes of this item.
  832. It is advisable not to use this method, but rather set the highlight
  833. colors for all items of a type with
  834. KDGanttView::setHighlightColors() in order to get a uniform Gantt
  835. view.
  836. If the item displays its subitems (children) as a group,
  837. (displaySubitemsAsGroup() == true)
  838. all changes apply to all subitems as well.
  839. \param start the highlight color for the start shape
  840. \param middle the highlight color for the middle shape
  841. \param end the highlight color for the end shape
  842. \sa highlightColors(), setShapes(), shapes()
  843. */
  844. void KDGanttViewItem::setHighlightColors( const TQColor& start, const TQColor& middle, const TQColor& end )
  845. {
  846. myStartColorHL=start ;
  847. myMiddleColorHL= middle;
  848. myEndColorHL= end;
  849. if ( displaySubitemsAsGroup() ) {
  850. myGanttView->myTimeTable->inc_blockUpdating();
  851. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  852. while (temp != 0) {
  853. temp->setHighlightColors( start, middle, end );
  854. temp = temp->nextSibling();
  855. }
  856. myGanttView->myTimeTable->dec_blockUpdating();
  857. }
  858. updateCanvasItems();
  859. }
  860. /*!
  861. Returns the highlight colors used for this item
  862. \param start returns the start highlight color
  863. \param middle returns the middle highlight color
  864. \param end returns the end highlight color
  865. \sa setHighlightColors(), setShapes(), shapes()
  866. */
  867. void KDGanttViewItem::highlightColors( TQColor& start, TQColor& middle, TQColor& end ) const
  868. {
  869. start = myStartColorHL ;
  870. middle = myMiddleColorHL;
  871. end = myEndColorHL;
  872. }
  873. /*!
  874. Specifies the color to be used for the text of this item.
  875. It is advisable not to use this method, but rather set the text color
  876. for all items with KDGanttView::setTextColor() in order to get a
  877. uniform Gantt view.
  878. If the item displays its subitems (children) as a group,
  879. (displaySubitemsAsGroup() == true)
  880. all changes apply to all subitems as well.
  881. \param color the text color
  882. \sa textColor(), setText(), text()
  883. */
  884. void KDGanttViewItem::setTextColor( const TQColor& color )
  885. {
  886. myTextColor = color;
  887. if ( displaySubitemsAsGroup() ) {
  888. myGanttView->myTimeTable->inc_blockUpdating();
  889. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  890. while (temp != 0) {
  891. temp->setTextColor(color);
  892. temp = temp->nextSibling();
  893. }
  894. myGanttView->myTimeTable->dec_blockUpdating();
  895. }
  896. updateCanvasItems();
  897. }
  898. /*!
  899. Returns the color used for the text of this item.
  900. \return the text color
  901. \sa setTextColor(), setText(), text()
  902. */
  903. TQColor KDGanttViewItem::textColor() const
  904. {
  905. return myTextColor;
  906. }
  907. /*!
  908. \enum KDGanttViewItem::Shape
  909. This enum is used in order to specify the shapes of a Gantt chart
  910. item.
  911. */
  912. /*!
  913. \enum KDGanttViewItem::Type
  914. This enum is used in order to return the type of a Gantt chart item.
  915. */
  916. /*!
  917. Sets the pixmap that is shown in the listview.
  918. \param column the column in which the pixmap is shown
  919. \param pixmap the pixmap to show
  920. \sa pixmap()
  921. */
  922. void KDGanttViewItem::setPixmap( int column, const TQPixmap& pixmap )
  923. {
  924. TQListViewItem::setPixmap( column, pixmap );
  925. }
  926. /*!
  927. \deprecated use setPixmap( int, const TQPixmap& ) instead
  928. */
  929. void KDGanttViewItem::setPixmap( const TQPixmap& pixmap )
  930. {
  931. TQListViewItem::setPixmap( 0, pixmap );
  932. }
  933. /*!
  934. Returns a pixmap that is shown in the listview.
  935. \param column the column for which to query the pixmap
  936. \return a pointer to the pixmap shown
  937. \sa setPixmap()
  938. */
  939. const TQPixmap* KDGanttViewItem::pixmap( int column ) const
  940. {
  941. return TQListViewItem::pixmap( column );
  942. }
  943. /*!
  944. Sets the default color that is used for the item if no specific
  945. start, middle, or end colors are set.
  946. It is advisable not to use this method, but rather set the colors
  947. for all items of a type with KDGanttView::setDefaultColor() in order to
  948. get a uniform Gantt view.
  949. If the item displays its subitems (children) as a group,
  950. (displaySubitemsAsGroup() == true)
  951. all changes apply to all subitems as well.
  952. \param color the default color to use
  953. \sa defaultColor(), setColors(), colors()
  954. */
  955. void KDGanttViewItem::setDefaultColor( const TQColor& color )
  956. {
  957. myDefaultColor = color;
  958. if ( displaySubitemsAsGroup() ) {
  959. myGanttView->myTimeTable->inc_blockUpdating();
  960. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  961. while (temp != 0) {
  962. temp->setDefaultColor( color );
  963. temp = temp->nextSibling();
  964. }
  965. myGanttView->myTimeTable->dec_blockUpdating();
  966. }
  967. updateCanvasItems();
  968. }
  969. /*!
  970. Returns the default color that is used for the item if no specific
  971. start, middle, or end colors are set.
  972. \return color the default color used
  973. \sa setDefaultColor(), setColors(), colors()
  974. */
  975. TQColor KDGanttViewItem::defaultColor() const
  976. {
  977. return myDefaultColor;
  978. }
  979. /*!
  980. Sets the default highlighting color that is used for the item if no
  981. specific start, middle, or end colors are set.
  982. It is advisable not to use this method, but rather set the colors
  983. for all items of a type with KDGanttView::setDefaultHighlightColor()
  984. in order to get a uniform Gantt view.
  985. If the item displays its subitems (children) as a group,
  986. (displaySubitemsAsGroup() == true)
  987. all changes apply to all subitems as well.
  988. \param color the default highlighting color to use
  989. \sa defaultHighlightColor(), setHighlightColors(), highlightColors()
  990. */
  991. void KDGanttViewItem::setDefaultHighlightColor( const TQColor& color )
  992. {
  993. myDefaultColorHL = color;
  994. if ( displaySubitemsAsGroup() ) {
  995. myGanttView->myTimeTable->inc_blockUpdating();
  996. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  997. while (temp != 0) {
  998. temp->setDefaultHighlightColor( color );
  999. temp = temp->nextSibling();
  1000. }
  1001. myGanttView->myTimeTable->dec_blockUpdating();
  1002. }
  1003. updateCanvasItems();
  1004. }
  1005. /*!
  1006. Returns the default highlighting color that is used for the item if
  1007. no specific start, middle, or end colors are set.
  1008. \return color the default highlighting color used
  1009. \sa setDefaultHighlightColor(), setHighlightColors(), highlightColors()
  1010. */
  1011. TQColor KDGanttViewItem::defaultHighlightColor() const
  1012. {
  1013. return myDefaultColorHL;
  1014. }
  1015. /*!
  1016. Returns the first child of this item.
  1017. \return the first child of this item, 0 if this item has no children
  1018. */
  1019. KDGanttViewItem* KDGanttViewItem::firstChild() const
  1020. {
  1021. return (KDGanttViewItem* )TQListViewItem::firstChild();
  1022. }
  1023. /*!
  1024. Returns the next sibling item of this item
  1025. \return the next sibling item of this item, 0 if this item has no
  1026. more siblings
  1027. */
  1028. KDGanttViewItem* KDGanttViewItem::nextSibling() const
  1029. {
  1030. return (KDGanttViewItem* )TQListViewItem::nextSibling();
  1031. }
  1032. /*!
  1033. Returns the parent item of this item
  1034. \return the parent item of this item, 0 if this item is a top-level
  1035. item
  1036. */
  1037. KDGanttViewItem* KDGanttViewItem::parent() const
  1038. {
  1039. return (KDGanttViewItem*)TQListViewItem::parent();
  1040. }
  1041. /*!
  1042. Returns the item above this item in the listview
  1043. \return the item above this item, 0 if this is the first item
  1044. */
  1045. KDGanttViewItem* KDGanttViewItem::itemAbove()
  1046. {
  1047. return (KDGanttViewItem* )TQListViewItem::itemAbove();
  1048. }
  1049. /*!
  1050. Returns the item below this item in the listview.
  1051. It can be specified whether the disabled items are taken
  1052. into account as well.
  1053. \param includeDisabled if true, disabled items are considered as well
  1054. \return the item below this item, 0 if this is the last item
  1055. */
  1056. KDGanttViewItem* KDGanttViewItem::itemBelow( bool includeDisabled )
  1057. {
  1058. KDGanttViewItem* retItem = (KDGanttViewItem* )TQListViewItem::itemBelow();
  1059. if ( !includeDisabled ) {
  1060. return retItem;
  1061. }
  1062. if ( retItem ) {
  1063. if (itemPos() + height() == retItem->itemPos() ) {
  1064. return retItem;
  1065. }
  1066. }
  1067. KDGanttViewItem* Item2 = (KDGanttViewItem* )TQListViewItem::listView()->itemAt(TQPoint (2, TQListViewItem::itemPos() + TQListViewItem::height() +2) );
  1068. if ( Item2 != 0 )
  1069. if (!Item2->enabled() )
  1070. return Item2;
  1071. return retItem;
  1072. }
  1073. /*!
  1074. Updates the colors of the item, but not the coordinates.
  1075. */
  1076. void KDGanttViewItem::updateCanvasItems()
  1077. {
  1078. if (blockUpdating) return;
  1079. TQPen p,pBack;
  1080. TQBrush b;
  1081. b.setStyle(Qt::SolidPattern);
  1082. if ( enabled() ) {
  1083. textCanvas->setColor(myTextColor);
  1084. if (isHighlighted) {
  1085. b.setStyle(Qt::SolidPattern);
  1086. b.setColor(myStartColorHL);
  1087. startShape->setBrush(b);
  1088. b.setColor(myMiddleColorHL);
  1089. midShape->setBrush(b);
  1090. b.setColor(myEndColorHL);
  1091. endShape->setBrush(b);
  1092. p.setWidth(myItemSize/3 -1);
  1093. p.setColor(myStartColorHL);
  1094. startLine->setPen(p);
  1095. p.setColor(myEndColorHL);
  1096. endLine->setPen(p);
  1097. } else {
  1098. b.setStyle(Qt::SolidPattern);
  1099. b.setColor(myStartColor);
  1100. // tqDebug("update color %s %s", listViewText().latin1(),myStartColor.name().latin1() );
  1101. startShape->setBrush(b);
  1102. b.setColor(myMiddleColor);
  1103. midShape->setBrush(b);
  1104. b.setColor(myEndColor);
  1105. endShape->setBrush(b);
  1106. p.setWidth(myItemSize/3-1);
  1107. p.setColor(myStartColor);
  1108. startLine->setPen(p);
  1109. p.setColor(myEndColor);
  1110. endLine->setPen(p);
  1111. }
  1112. } else {
  1113. //TQColor discol = TQt::lightGray;
  1114. TQColor discol = TQColor(232,232,232);
  1115. textCanvas->setColor( TQColor(150,150,150) );
  1116. b.setStyle(Qt::SolidPattern);
  1117. b.setColor(discol);
  1118. startShape->setBrush(b);
  1119. midShape->setBrush(b);
  1120. endShape->setBrush(b);
  1121. p.setWidth(myItemSize/3 -1);
  1122. p.setColor(discol);
  1123. startLine->setPen(p);
  1124. endLine->setPen(p);
  1125. }
  1126. pBack.setWidth((myItemSize/3-1)+2);
  1127. startLineBack->setPen(pBack);
  1128. endLineBack->setPen(pBack);
  1129. TQFont f = textCanvas->font();
  1130. f.setPixelSize(myItemSize);
  1131. textCanvas->setFont(f);
  1132. //if (isvisible) {
  1133. myGanttView->myTimeTable->updateMyContent();
  1134. //}
  1135. }
  1136. void KDGanttViewItem::initItem()
  1137. {
  1138. }
  1139. /*!
  1140. This method is reimplemented for internal purposes.
  1141. */
  1142. void KDGanttViewItem::setOpen( bool open )
  1143. {
  1144. if ( _callListViewOnSetOpen ) {
  1145. // notify the listview about a programatically called setOpen()
  1146. if ( listView () )
  1147. listView ()->setOpen( this, open );
  1148. } else {
  1149. TQListViewItem::setOpen( open );
  1150. }
  1151. }
  1152. void KDGanttViewItem::showItem( bool, int )
  1153. {
  1154. }
  1155. TQPoint KDGanttViewItem::getTaskLinkStartCoord(TQPoint p)
  1156. {
  1157. textCanvas->move(p.x()+myItemSize, itemPos() + height()/2-myItemSize/2);
  1158. return TQPoint (myGanttView->myTimeHeader->getCoordX(myEndTime) +myItemSize/2,itemPos()+height()/2);
  1159. }
  1160. TQPoint KDGanttViewItem::getTaskLinkEndCoord()
  1161. {
  1162. return TQPoint (myGanttView->myTimeHeader->getCoordX(myStartTime)-myItemSize/2 ,itemPos()-myItemSize/2+height()/2-2);
  1163. }
  1164. void KDGanttViewItem::hideSubtree()
  1165. {
  1166. if (firstChild())
  1167. firstChild()->hideSubtree();
  1168. if ( nextSibling () )
  1169. nextSibling ()->hideSubtree();
  1170. showItem(false);
  1171. }
  1172. void KDGanttViewItem::setCallListViewOnSetOpen( bool call )
  1173. {
  1174. _callListViewOnSetOpen = call;
  1175. }
  1176. void KDGanttViewItem::initColorAndShapes(Type t)
  1177. {
  1178. setTextOffset(TQPoint(0,0));
  1179. //_isCalendar = false;
  1180. _callListViewOnSetOpen = true;
  1181. myType = t;
  1182. myProgress = 0;
  1183. progressShape = 0;
  1184. floatStartShape = 0;
  1185. floatEndShape = 0;
  1186. blockUpdating = true;
  1187. isVisibleInGanttView = false;
  1188. startShape = 0;
  1189. midShape = 0;
  1190. endShape = 0;
  1191. startShapeBack = 0;
  1192. midShapeBack = 0;
  1193. endShapeBack = 0;
  1194. myItemSize = 10;
  1195. myGanttView = ((KDListView *)listView())->myGanttView;
  1196. myGanttView->myTimeHeader->saveCenterDateTime();
  1197. myStartTime = myGanttView->myTimeHeader->myCenterDateTime;
  1198. myEndTime = myStartTime;
  1199. myToolTipText =TQListViewItem::text(0);
  1200. myWhatsThisText = TQListViewItem::text(0);
  1201. isHighlighted = false;
  1202. isEditable = true;
  1203. _displaySubitemsAsGroup = myGanttView->displaySubitemsAsGroup();
  1204. startLine = new KDCanvasLine(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);//KDGanttViewItem );
  1205. endLine = new KDCanvasLine(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1206. startLine->setZ(2);endLine->setZ(2);
  1207. startLineBack = new KDCanvasLine(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);//KDGanttViewItem );
  1208. endLineBack = new KDCanvasLine(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1209. startLineBack->setZ(1);endLineBack->setZ(1);
  1210. actualEnd = new KDCanvasLine(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1211. actualEnd->setZ(5);
  1212. actualEnd->setPen( TQPen ( TQt::red, 3 ) );
  1213. textCanvas = new KDCanvasText(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1214. textCanvas->setText("");
  1215. textCanvas->setZ(10);
  1216. // set textcolor
  1217. setTextColor( myGanttView->textColor());
  1218. // set default color
  1219. setDefaultColor( myGanttView->defaultColor(myType));
  1220. // set default highlight color
  1221. setDefaultHighlightColor(myGanttView->defaultHighlightColor(myType));
  1222. // set shapes
  1223. if (!( shapeDefined = (myGanttView->shapes(myType,myStartShape,myMiddleShape,myEndShape)))) {
  1224. //tqDebug("KDGantt::KDGanttViewItem created with not user defined shapes");
  1225. };
  1226. setShapes(myStartShape,myMiddleShape,myEndShape);
  1227. if ( type() == Task ) {
  1228. //tqDebug("new task %s ", listViewText().latin1());
  1229. if ( startShape )
  1230. delete startShape;
  1231. startShape = (KDCanvasPolygonItem*)new KDCanvasRectangle(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1232. progressShape = (KDCanvasPolygonItem*)new KDCanvasRectangle(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1233. }
  1234. floatStartShape = (KDCanvasPolygonItem*)new KDCanvasRectangle(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1235. floatEndShape = (KDCanvasPolygonItem*)new KDCanvasRectangle(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
  1236. // set color of shapes
  1237. if (!( colorDefined = (myGanttView->colors(myType,myStartColor,myMiddleColor,myEndColor)))) {
  1238. };
  1239. setColors(defaultColor(),defaultColor(), defaultColor());
  1240. // set highlight color of shapes
  1241. if (!( colorHLDefined = (myGanttView->highlightColors(myType,myStartColorHL,myMiddleColorHL,myEndColorHL)))) {
  1242. };
  1243. setHighlightColors(defaultHighlightColor(),defaultHighlightColor(), defaultHighlightColor());
  1244. setFont(myGanttView->font());
  1245. // if (type() == Task)
  1246. //setText(TQListViewItem::text(0)); // testing only
  1247. //isvisible = true;
  1248. _priority = 150;
  1249. _showNoInformation = false;
  1250. _enabled = true;
  1251. blockUpdating = false;
  1252. updateCanvasItems();
  1253. }
  1254. TQString KDGanttViewItem::shapeToString( Shape shape )
  1255. {
  1256. switch( shape ) {
  1257. case TriangleDown:
  1258. return "TriangleDown";
  1259. case TriangleUp:
  1260. return "TriangleUp";
  1261. case Diamond:
  1262. return "Diamond";
  1263. case Square:
  1264. return "Square";
  1265. case Circle:
  1266. return "Circle";
  1267. }
  1268. return "";
  1269. }
  1270. KDGanttViewItem::Shape KDGanttViewItem::stringToShape( const TQString& string )
  1271. {
  1272. if( string == "TriangleDown" )
  1273. return TriangleDown;
  1274. else if( string == "TriangleUp" )
  1275. return TriangleUp;
  1276. else if( string == "Diamond" )
  1277. return Diamond;
  1278. else if( string == "Square" )
  1279. return Square;
  1280. else if( string == "Circle" )
  1281. return Circle;
  1282. else
  1283. return TriangleDown;
  1284. }
  1285. /*!
  1286. Creates a DOM node that describes this item.
  1287. \param doc the DOM document to which the node belongs
  1288. \param parentElement the element into which to insert this node
  1289. */
  1290. void KDGanttViewItem::createNode( TQDomDocument& doc,
  1291. TQDomElement& parentElement )
  1292. {
  1293. TQDomElement itemElement = doc.createElement( "Item" );
  1294. parentElement.appendChild( itemElement );
  1295. itemElement.setAttribute( "Type", typeToString( type() ) );
  1296. KDGanttXML::createDateTimeNode( doc, itemElement, "StartTime", startTime() );
  1297. KDGanttXML::createDateTimeNode( doc, itemElement, "EndTime", endTime() );
  1298. KDGanttXML::createFontNode( doc, itemElement, "Font", font() );
  1299. KDGanttXML::createStringNode( doc, itemElement, "Text", text() );
  1300. KDGanttXML::createStringNode( doc, itemElement, "TooltipText", tooltipText() );
  1301. KDGanttXML::createStringNode( doc, itemElement, "WhatsThisText",
  1302. whatsThisText() );
  1303. if( pixmap() )
  1304. KDGanttXML::createPixmapNode( doc, itemElement, "Pixmap", *pixmap() );
  1305. if( !listViewText().isNull() )
  1306. KDGanttXML::createStringNode( doc, itemElement, "ListViewText",
  1307. listViewText() );
  1308. KDGanttXML::createBoolNode( doc, itemElement, "Open", isOpen() );
  1309. KDGanttXML::createBoolNode( doc, itemElement, "Highlight", highlight() );
  1310. Shape startShape, middleShape, endShape;
  1311. shapes( startShape, middleShape, endShape );
  1312. KDGanttXML::createStringNode( doc, itemElement, "StartShape",
  1313. shapeToString( startShape ) );
  1314. KDGanttXML::createStringNode( doc, itemElement, "MiddleShape",
  1315. shapeToString( middleShape ) );
  1316. KDGanttXML::createStringNode( doc, itemElement, "EndShape",
  1317. shapeToString( endShape ) );
  1318. KDGanttXML::createColorNode( doc, itemElement, "DefaultColor", defaultColor() );
  1319. TQColor startColor, middleColor, endColor;
  1320. colors( startColor, middleColor, endColor );
  1321. KDGanttXML::createColorNode( doc, itemElement, "StartColor", startColor );
  1322. KDGanttXML::createColorNode( doc, itemElement, "MiddleColor", middleColor );
  1323. KDGanttXML::createColorNode( doc, itemElement, "EndColor", endColor );
  1324. KDGanttXML::createColorNode( doc, itemElement, "DefaultHighlightColor",
  1325. defaultHighlightColor() );
  1326. highlightColors( startColor, middleColor, endColor );
  1327. KDGanttXML::createColorNode( doc, itemElement, "StartHighlightColor",
  1328. startColor );
  1329. KDGanttXML::createColorNode( doc, itemElement, "MiddleHighlightColor",
  1330. middleColor );
  1331. KDGanttXML::createColorNode( doc, itemElement, "EndHighlightColor", endColor );
  1332. KDGanttXML::createColorNode( doc, itemElement, "TextColor", textColor() );
  1333. KDGanttXML::createStringNode( doc, itemElement, "Name", name() );
  1334. TQDomElement itemsElement = doc.createElement( "Items" );
  1335. itemElement.appendChild( itemsElement );
  1336. KDGanttViewItem* currentItem = firstChild();
  1337. while( currentItem ) {
  1338. currentItem->createNode( doc, itemsElement );
  1339. currentItem = currentItem->nextSibling();
  1340. }
  1341. }
  1342. /*!
  1343. Creates a KDGanttViewItem according to the specification in a DOM
  1344. element.
  1345. \param view the view in which the item will be inserted
  1346. \param element the DOM element from which to read the specification
  1347. \return the newly created item
  1348. */
  1349. KDGanttViewItem* KDGanttViewItem::createFromDomElement( KDGanttView* view,
  1350. TQDomElement& element )
  1351. {
  1352. TQString typeString = element.attribute( "Type" );
  1353. Q_ASSERT( !typeString.isEmpty() );
  1354. KDGanttViewItem* item;
  1355. if( typeString == "Task" )
  1356. item = new KDGanttViewTaskItem( view );
  1357. else if( typeString == "Summary" )
  1358. item = new KDGanttViewSummaryItem( view );
  1359. else if( typeString == "Event" )
  1360. item = new KDGanttViewEventItem( view );
  1361. else {
  1362. tqDebug( "Unknown item type %s in KDGanttViewItem::createFromDomElement()", typeString.latin1() );
  1363. return 0;
  1364. }
  1365. item->loadFromDomElement( element );
  1366. return item;
  1367. }
  1368. /*!
  1369. Creates a KDGanttViewItem according to the specification in a DOM
  1370. element.
  1371. \param view the view in which the item will be inserted
  1372. \param previous to item behind this one should appear
  1373. \param element the DOM element from which to read the specification
  1374. \return the newly created element
  1375. */
  1376. KDGanttViewItem* KDGanttViewItem::createFromDomElement( KDGanttView* view,
  1377. KDGanttViewItem* previous,
  1378. TQDomElement& element )
  1379. {
  1380. TQString typeString = element.attribute( "Type" );
  1381. Q_ASSERT( !typeString.isEmpty() );
  1382. KDGanttViewItem* item;
  1383. if( typeString == "Task" )
  1384. item = new KDGanttViewTaskItem( view, previous );
  1385. else if( typeString == "Summary" )
  1386. item = new KDGanttViewSummaryItem( view, previous );
  1387. else if( typeString == "Event" )
  1388. item = new KDGanttViewEventItem( view, previous );
  1389. else {
  1390. tqDebug( "Unknown item type in KDGanttViewItem::createFromDomElement()" );
  1391. return 0;
  1392. }
  1393. item->loadFromDomElement( element );
  1394. return item;
  1395. }
  1396. /*!
  1397. Creates a KDGanttViewItem according to the specification in a DOM
  1398. element.
  1399. \param parent the parent item under which the item will be inserted
  1400. \param element the DOM element from which to read the specification
  1401. \return the newly created element
  1402. */
  1403. KDGanttViewItem* KDGanttViewItem::createFromDomElement( KDGanttViewItem* parent,
  1404. TQDomElement& element )
  1405. {
  1406. TQString typeString = element.attribute( "Type" );
  1407. Q_ASSERT( !typeString.isEmpty() );
  1408. KDGanttViewItem* item;
  1409. if( typeString == "Task" )
  1410. item = new KDGanttViewTaskItem( parent );
  1411. else if( typeString == "Summary" )
  1412. item = new KDGanttViewSummaryItem( parent );
  1413. else if( typeString == "Event" )
  1414. item = new KDGanttViewEventItem( parent );
  1415. else {
  1416. tqDebug( "Unknown item type in KDGanttViewItem::createFromDomElement()" );
  1417. return 0;
  1418. }
  1419. item->loadFromDomElement( element );
  1420. return item;
  1421. }
  1422. /*!
  1423. Creates a KDGanttViewItem according to the specification in a DOM
  1424. element.
  1425. \param parent the parent item under which the item will be inserted
  1426. \param previous to item behind this one should appear
  1427. \param element the DOM element from which to read the specification
  1428. \return the newly created element
  1429. */
  1430. KDGanttViewItem* KDGanttViewItem::createFromDomElement( KDGanttViewItem* parent,
  1431. KDGanttViewItem* previous,
  1432. TQDomElement& element )
  1433. {
  1434. TQString typeString = element.attribute( "Type" );
  1435. Q_ASSERT( !typeString.isEmpty() );
  1436. KDGanttViewItem* item;
  1437. if( typeString == "Task" )
  1438. item = new KDGanttViewTaskItem( parent, previous );
  1439. else if( typeString == "Summary" )
  1440. item = new KDGanttViewSummaryItem( parent, previous );
  1441. else if( typeString == "Event" )
  1442. item = new KDGanttViewEventItem( parent, previous );
  1443. else {
  1444. tqDebug( "Unknown item type in KDGanttViewItem::createFromDomElement()" );
  1445. return 0;
  1446. }
  1447. item->loadFromDomElement( element );
  1448. return item;
  1449. }
  1450. /*
  1451. Fills in the values in the item by reading the DOM element.
  1452. */
  1453. void KDGanttViewItem::loadFromDomElement( TQDomElement& element )
  1454. {
  1455. TQDomNode node = element.firstChild();
  1456. Shape startShape = TriangleDown, middleShape = TriangleDown,
  1457. endShape = TriangleDown;
  1458. TQColor startColor, middleColor, endColor;
  1459. TQColor startHighlightColor, middleHighlightColor, endHighlightColor;
  1460. TQString tempName;
  1461. while( !node.isNull() ) {
  1462. TQDomElement element = node.toElement();
  1463. if( !element.isNull() ) { // was really an element
  1464. TQString tagName = element.tagName();
  1465. if( tagName == "StartTime" ) {
  1466. TQDateTime value;
  1467. if( KDGanttXML::readDateTimeNode( element, value ) )
  1468. setStartTime( value );
  1469. } else if( tagName == "EndTime" ) {
  1470. TQDateTime value;
  1471. if( KDGanttXML::readDateTimeNode( element, value ) )
  1472. setEndTime( value );
  1473. } else if( tagName == "Text" ) {
  1474. TQString value;
  1475. if( KDGanttXML::readStringNode( element, value ) )
  1476. setText( value );
  1477. } else if( tagName == "Font" ) {
  1478. TQFont value;
  1479. if( KDGanttXML::readFontNode( element, value ) )
  1480. setFont( value );
  1481. } else if( tagName == "TooltipText" ) {
  1482. TQString value;
  1483. if( KDGanttXML::readStringNode( element, value ) )
  1484. setTooltipText( value );
  1485. } else if( tagName == "WhatsThisText" ) {
  1486. TQString value;
  1487. if( KDGanttXML::readStringNode( element, value ) )
  1488. setWhatsThisText( value );
  1489. } else if( tagName == "Pixmap" ) {
  1490. TQPixmap value;
  1491. if( KDGanttXML::readPixmapNode( element, value ) )
  1492. setPixmap( value );
  1493. } else if( tagName == "ListViewText" ) {
  1494. TQString value;
  1495. if( KDGanttXML::readStringNode( element, value ) )
  1496. setListViewText( value );
  1497. } else if( tagName == "Open" ) {
  1498. bool value;
  1499. if( KDGanttXML::readBoolNode( element, value ) )
  1500. setOpen( value );
  1501. } else if( tagName == "Highlight" ) {
  1502. bool value;
  1503. if( KDGanttXML::readBoolNode( element, value ) )
  1504. setHighlight( value );
  1505. } else if( tagName == "StartShape" ) {
  1506. TQString value;
  1507. if( KDGanttXML::readStringNode( element, value ) )
  1508. startShape = stringToShape( value );
  1509. } else if( tagName == "MiddleShape" ) {
  1510. TQString value;
  1511. if( KDGanttXML::readStringNode( element, value ) )
  1512. middleShape = stringToShape( value );
  1513. } else if( tagName == "EndShape" ) {
  1514. TQString value;
  1515. if( KDGanttXML::readStringNode( element, value ) )
  1516. endShape = stringToShape( value );
  1517. } else if( tagName == "DefaultColor" ) {
  1518. TQColor value;
  1519. if( KDGanttXML::readColorNode( element, value ) )
  1520. setDefaultColor( value );
  1521. } else if( tagName == "StartColor" ) {
  1522. TQColor value;
  1523. if( KDGanttXML::readColorNode( element, value ) )
  1524. startColor = value;
  1525. } else if( tagName == "MiddleColor" ) {
  1526. TQColor value;
  1527. if( KDGanttXML::readColorNode( element, value ) )
  1528. middleColor = value;
  1529. } else if( tagName == "EndColor" ) {
  1530. TQColor value;
  1531. if( KDGanttXML::readColorNode( element, value ) )
  1532. endColor = value;
  1533. } else if( tagName == "DefaultHighlightColor" ) {
  1534. TQColor value;
  1535. if( KDGanttXML::readColorNode( element, value ) )
  1536. setDefaultHighlightColor( value );
  1537. } else if( tagName == "StartHighlightColor" ) {
  1538. TQColor value;
  1539. if( KDGanttXML::readColorNode( element, value ) )
  1540. startHighlightColor = value;
  1541. } else if( tagName == "MiddleHighlightColor" ) {
  1542. TQColor value;
  1543. if( KDGanttXML::readColorNode( element, value ) )
  1544. middleHighlightColor = value;
  1545. } else if( tagName == "EndHighlightColor" ) {
  1546. TQColor value;
  1547. if( KDGanttXML::readColorNode( element, value ) )
  1548. endHighlightColor = value;
  1549. } else if( tagName == "TextColor" ) {
  1550. TQColor value;
  1551. if( KDGanttXML::readColorNode( element, value ) )
  1552. setTextColor( value );
  1553. } else if( tagName == "Name" ) {
  1554. TQString value;
  1555. if( KDGanttXML::readStringNode( element, value ) )
  1556. tempName = value;
  1557. } else if( tagName == "Items" ) {
  1558. TQDomNode node = element.firstChild();
  1559. KDGanttViewItem* previous = 0;
  1560. while( !node.isNull() ) {
  1561. TQDomElement element = node.toElement();
  1562. if( !element.isNull() ) { // was really an element
  1563. TQString tagName = element.tagName();
  1564. if( tagName == "Item" ) {
  1565. KDGanttViewItem* newItem;
  1566. if( previous )
  1567. newItem =
  1568. KDGanttViewItem::createFromDomElement( this,
  1569. previous,
  1570. element );
  1571. else
  1572. newItem =
  1573. KDGanttViewItem::createFromDomElement( this,
  1574. element );
  1575. previous = newItem;
  1576. } else {
  1577. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  1578. Q_ASSERT( false );
  1579. }
  1580. }
  1581. node = node.nextSibling();
  1582. }
  1583. } else {
  1584. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  1585. Q_ASSERT( false );
  1586. }
  1587. }
  1588. node = node.nextSibling();
  1589. }
  1590. setColors( startColor, middleColor, endColor );
  1591. setHighlightColors( startHighlightColor, middleHighlightColor,
  1592. endHighlightColor );
  1593. setShapes( startShape, middleShape, endShape );
  1594. generateAndInsertName( tempName );
  1595. }
  1596. TQString KDGanttViewItem::typeToString( Type type )
  1597. {
  1598. switch( type ) {
  1599. case Event:
  1600. return "Event";
  1601. case Summary:
  1602. return "Summary";
  1603. case Task:
  1604. return "Task";
  1605. default:
  1606. tqDebug( "Unknown type in KDGanttViewItem::typeToString()" );
  1607. return "Summary";
  1608. }
  1609. return "";
  1610. }
  1611. /*!
  1612. Returns the y coordinate of this item.
  1613. \return the y coordinate of this item
  1614. */
  1615. int KDGanttViewItem::getCoordY()
  1616. {
  1617. return itemPos() + height()/2;
  1618. }
  1619. void KDGanttViewItem::showSubItems()
  1620. {
  1621. showSubitemTree( getCoordY() );
  1622. }
  1623. void KDGanttViewItem::showSubitemTree( int CoordY )
  1624. {
  1625. KDGanttViewItem* temp = firstChild();
  1626. if (temp) {
  1627. while (temp != 0) {
  1628. if (temp->isOpen() || !temp->displaySubitemsAsGroup() ) {
  1629. temp->showItem( true, CoordY );
  1630. if ( temp->firstChild() )
  1631. temp->firstChild()->hideSubtree();
  1632. } else {
  1633. if ( temp->displaySubitemsAsGroup() && temp->firstChild() )
  1634. temp->hideSubtree();
  1635. else {
  1636. temp->showSubitemTree( CoordY );
  1637. }
  1638. }
  1639. temp = temp->nextSibling();
  1640. }
  1641. showItem( false );
  1642. } else {
  1643. showItem( true, CoordY );
  1644. }
  1645. }
  1646. /*!
  1647. Returns the start time of the children of this item.
  1648. \return the start time of the children of this item
  1649. */
  1650. TQDateTime KDGanttViewItem::myChildStartTime()
  1651. {
  1652. TQDateTime ret, tempTime;
  1653. bool set = true;
  1654. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  1655. if (temp) {
  1656. while (temp != 0) {
  1657. if ( !temp->displaySubitemsAsGroup() ) {
  1658. tempTime = temp->startTime();
  1659. } else {
  1660. tempTime = temp->myChildStartTime();
  1661. }
  1662. if ( set ) {
  1663. set = false;
  1664. ret = tempTime;
  1665. } else {
  1666. if ( tempTime < ret ) {
  1667. ret = tempTime;
  1668. }
  1669. }
  1670. temp = temp->nextSibling();
  1671. }
  1672. } else {
  1673. ret = startTime();
  1674. }
  1675. return ret;
  1676. }
  1677. /*!
  1678. Returns the end time of the children of this item.
  1679. \return the end time of the children of this item
  1680. */
  1681. TQDateTime KDGanttViewItem::myChildEndTime()
  1682. {
  1683. TQDateTime ret, tempTime;
  1684. bool set = true;
  1685. KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
  1686. if (temp) {
  1687. while (temp != 0) {
  1688. if ( !temp->displaySubitemsAsGroup() ) {
  1689. tempTime = temp->endTime();
  1690. } else {
  1691. tempTime = temp->myChildEndTime();
  1692. }
  1693. if ( set ) {
  1694. set = false;
  1695. ret = tempTime;
  1696. } else {
  1697. if ( tempTime > ret ) {
  1698. ret = tempTime;
  1699. }
  1700. }
  1701. temp = temp->nextSibling();
  1702. }
  1703. } else {
  1704. ret = endTime();
  1705. }
  1706. return ret;
  1707. }
  1708. /*!
  1709. Returns whether the 'showNoInformation' line should be shown for this item
  1710. \return true if showNoInformation line should be shown
  1711. \sa setShowNoInformation(), KDGanttView::setNoInformationBrush(), KDGanttView::noInformationBrush()
  1712. */
  1713. bool KDGanttViewItem::showNoInformation()
  1714. {
  1715. return _showNoInformation;
  1716. }
  1717. /*!
  1718. Specifies whether the 'showNoInformation' line should be shown for
  1719. this item.
  1720. The 'showNoInformation' line is drawn over the whole timeline.
  1721. The height of the line is the height of the item.
  1722. The brush of the line is specified by KDGanttView::setNoInformationBrush().
  1723. (i.e. the same brush for all items of the Gantt view).
  1724. The default brush is TQBrush( TQColor ( 100,100,100 ), TQt::FDiagPattern );
  1725. \param show if true, the 'showNoInformation' line is shown for this item
  1726. \sa showNoInformation(), KDGanttView::setNoInformationBrush(), KDGanttView::noInformationBrush()
  1727. */
  1728. void KDGanttViewItem::setShowNoInformation( bool show )
  1729. {
  1730. _showNoInformation = show;
  1731. myGanttView->myTimeTable->updateMyContent();
  1732. }
  1733. /*!
  1734. If the name of this item is \a name (i.e., listViewText() == name),
  1735. the pointer to this item is returned. Otherwise, it looks for an
  1736. item with name \a name in the set of children and subchildren of
  1737. this item.
  1738. \param name the name of the item
  1739. \return the pointer to the item with name \a name
  1740. */
  1741. KDGanttViewItem* KDGanttViewItem::getChildByName( const TQString& name )
  1742. {
  1743. if ( listViewText() == name )
  1744. return this;
  1745. KDGanttViewItem* temp = firstChild(),* ret;
  1746. while (temp != 0) {
  1747. if ( (ret = temp->getChildByName( name )))
  1748. return ret;
  1749. temp = temp->nextSibling();
  1750. }
  1751. return 0;
  1752. }
  1753. /*
  1754. void KDGanttViewItem::printinfo( TQString s )
  1755. {
  1756. KDGanttViewItem* temp = firstChild();
  1757. while (temp != 0) {
  1758. temp->printinfo(" "+s );
  1759. temp = temp->nextSibling();
  1760. }
  1761. }
  1762. */
  1763. /*!
  1764. Returns whether this item has at least one subitem that is a calendar.
  1765. A subitem is a calendar, if that item has at least one subitem or
  1766. displaySubitemAsGroup() is true for that item.
  1767. \return true if the item has at least one subitem that is a calendar.
  1768. */
  1769. bool KDGanttViewItem::subitemIsCalendar() const
  1770. {
  1771. KDGanttViewItem* temp = firstChild();
  1772. bool ret = false;
  1773. while (temp) {
  1774. if (temp->firstChild() || temp->displaySubitemsAsGroup() ) {
  1775. ret = true;
  1776. break;
  1777. }
  1778. temp = temp->nextSibling();
  1779. }
  1780. return ret;
  1781. }
  1782. int KDGanttViewItem::computeHeight()
  1783. {
  1784. int hei = 0;
  1785. // if not visible, hide item and all subitems, return height = 0
  1786. if ( !isVisible() ) {
  1787. showItem( false );
  1788. if ( firstChild() )
  1789. firstChild()->hideSubtree();
  1790. // tqDebug("KDGanttViewItem::computeHeight() %s returns 0 ", TQListViewItem::text(0).latin1());
  1791. return 0;
  1792. }
  1793. KDGanttViewItem* temp;
  1794. bool show = true;
  1795. // explanation of terms:
  1796. // display opened item as usual:
  1797. // display this item opened, display Gantt part on the timeline of this item.
  1798. // the same for all subitems: display all subitems on its own timeline
  1799. // display closed item as usual:
  1800. // display this item closed, display Gantt part on the timeline of this item.
  1801. // do not display any subitem.
  1802. // desired behaviour:
  1803. // if not in calendar mode( GanttView is NOT in calendar mode ):
  1804. // opened:
  1805. // display opened item as usual
  1806. // closed:
  1807. // if not displaySubitemsAsGroup()
  1808. // display closed item as usual
  1809. // else ( displaySubitemsAsGroup() == true )
  1810. // display not this item, display subitems on the timeline of this item
  1811. // else ( GanttView is in calendar mode )
  1812. // 4 cases:
  1813. // opened && displaySubitemsAsGroup():
  1814. // display not this item, display subitems on the timeline of this item,
  1815. // which have the property displaySubitemsAsGroup() == false
  1816. // display the other items,
  1817. // which have the property displaySubitemsAsGroup() == true,
  1818. // as usual below this item on their own timeline
  1819. // opened && NOT displaySubitemsAsGroup():
  1820. // display opened item as usual
  1821. // closed && displaySubitemsAsGroup():
  1822. // display not this item, display subitems on the timeline of this item,
  1823. // which have the property displaySubitemsAsGroup() == false
  1824. // closed && NOT displaySubitemsAsGroup():
  1825. // display closed item as usual
  1826. //
  1827. if ( isOpen() ) {
  1828. //tqDebug("KDGanttViewItem::computeHeight() %s is open ", TQListViewItem::text(0).latin1());
  1829. temp = firstChild();
  1830. // if item opened, iterate over all subitems
  1831. int tempHeight;
  1832. // introduced special for performance reasons
  1833. bool special = displaySubitemsAsGroup() && myGanttView->calendarMode();
  1834. while (temp != 0) {
  1835. tempHeight = temp->computeHeight();
  1836. if ( special ) {
  1837. if ( temp->displaySubitemsAsGroup() ) {
  1838. hei += tempHeight;
  1839. //tqDebug(" hei added ");
  1840. } else {
  1841. temp->showSubitemTree( getCoordY() );
  1842. }
  1843. } else {
  1844. hei += tempHeight;
  1845. //tqDebug(" hei added ");
  1846. }
  1847. temp = temp->nextSibling();
  1848. }
  1849. } else { // closed!
  1850. //tqDebug("KDGanttViewItem::computeHeight() %s is closed ", TQListViewItem::text(0).latin1());
  1851. if ( !displaySubitemsAsGroup() ) {
  1852. if ( firstChild() ) {
  1853. firstChild()->hideSubtree();
  1854. }
  1855. } else {
  1856. if ( firstChild() ) {
  1857. showSubitemTree( getCoordY() );
  1858. show = false ;
  1859. }
  1860. }
  1861. }
  1862. if ( show )
  1863. showItem( true );
  1864. hei += height();
  1865. //tqDebug("KDGanttViewItem::computeHeight() %s returns: %d ", TQListViewItem::text(0).latin1(), hei);
  1866. return hei;
  1867. }
  1868. // if this item has at least one subitem which has the property displaySubitemsAsGroup(),
  1869. // a false is returned
  1870. bool KDGanttViewItem::showNoCross()
  1871. {
  1872. KDGanttViewItem * temp = firstChild();
  1873. if ( !temp )
  1874. return false;
  1875. while ( temp ) {
  1876. if ( temp->displaySubitemsAsGroup() ) {
  1877. return false;
  1878. }
  1879. temp = temp->nextSibling();
  1880. }
  1881. return true;
  1882. }
  1883. void KDGanttViewItem::paintBranches ( TQPainter* p, const TQColorGroup& cg,
  1884. int w, int y, int h )
  1885. {
  1886. TQListViewItem::paintBranches ( p, cg, w, y, h);
  1887. if ( !myGanttView->calendarMode() )
  1888. return;
  1889. else {
  1890. KDGanttViewItem * temp = firstChild();
  1891. while ( temp ) {
  1892. if ( temp->showNoCross() ) {
  1893. //tqDebug("paintNoCross %s ", temp->listViewText(0).latin1());
  1894. int y_coord = temp->itemPos() -height ()- itemPos();
  1895. int hei = temp->height();
  1896. //tqDebug(" y %d w %d h %d ", y,w,h);
  1897. //tqDebug("yc %d hei %d",y_coord,hei );
  1898. myGanttView->myListView->paintemptyarea( p, TQRect( 0,y+y_coord,w,hei));
  1899. int x_c = w/2;
  1900. int y_c = y+y_coord+ temp->height ()/2;
  1901. int y_ce ;
  1902. if ( temp->itemBelow() && temp->itemBelow()->parent() == this )
  1903. y_ce =y+y_coord+ temp->height ();
  1904. else
  1905. y_ce = y_c;
  1906. int i;
  1907. for (i = y+y_coord+1; i <= y_ce; i+=2 ) {
  1908. p->drawPoint( x_c, i );
  1909. }
  1910. for (i = x_c+2; i < w; i+=2 ) {
  1911. p->drawPoint( i, y_c );
  1912. }
  1913. }
  1914. temp = temp->nextSibling();
  1915. }
  1916. }
  1917. }
  1918. // resets the visibility os the subitems according to the setting of calendar mode
  1919. void KDGanttViewItem::resetSubitemVisibility()
  1920. {
  1921. KDGanttViewItem* temp;
  1922. temp = firstChild();
  1923. bool allow = false;
  1924. if ( myGanttView->calendarMode() ) {
  1925. // in calendarmode only items can be opened which have subitems which have subitems
  1926. if ( ! temp ) {
  1927. if ( !parent() )
  1928. // has no parent, has no child : show!
  1929. setVisible( true );
  1930. else
  1931. // has parent, has no child : hide!
  1932. setVisible( false );
  1933. return;
  1934. }
  1935. setVisible( true );
  1936. while (temp) {
  1937. if (temp->firstChild()) {
  1938. allow = true;
  1939. temp->resetSubitemVisibility();
  1940. }
  1941. else {
  1942. temp->setVisible(false);
  1943. }
  1944. temp = temp->nextSibling();
  1945. }
  1946. } else {
  1947. setVisible( true );
  1948. // all items can be opened
  1949. allow = true;
  1950. while (temp != 0) {
  1951. temp->resetSubitemVisibility();
  1952. temp = temp->nextSibling();
  1953. }
  1954. }
  1955. if ( !allow && isOpen() )
  1956. setOpen( false );
  1957. }
  1958. /*!
  1959. Specifies whether this item should behave like a calendar.
  1960. In calendar mode, only those items can be opened
  1961. which have subitems which have subitems.
  1962. An item which has subitems which have no subitems is called a calendar.
  1963. I.e., an item that contains
  1964. multiple calendars can be opened, while a calendar item itself cannot.
  1965. But if all calendars of an item do not have any subitem (e.g at startup),
  1966. the program cannot detect automatically that it should be possible to open
  1967. this item.
  1968. To enable this, call setIsCalendar( true ); for at least one calendar
  1969. \param cal true in order behave this item like a calendar
  1970. highlighting off for this item
  1971. \sa isCalendar()
  1972. */
  1973. /* removed
  1974. void KDGanttViewItem::setIsCalendar( bool cal )
  1975. {
  1976. _isCalendar = cal;
  1977. updateCanvasItems();
  1978. }
  1979. */
  1980. /*!
  1981. Returns whether this item behaves like a calendar,
  1982. even though it has no subitem which has subitems; when highlighting
  1983. with setHighlight() or by the user with the mouse.
  1984. \return true if the item behaves like a calendar
  1985. \sa setIsCalendar()
  1986. */
  1987. /* removed
  1988. bool KDGanttViewItem::isCalendar( ) const
  1989. {
  1990. return _isCalendar;
  1991. }
  1992. */
  1993. /*!
  1994. \var KDGanttViewItem::startLine
  1995. the line at the beginning of the item
  1996. */
  1997. /*!
  1998. \var KDGanttViewItem::endLine
  1999. the line at the end of the item
  2000. */
  2001. /*!
  2002. \var KDGanttViewItem::startLineBack
  2003. the background line at the beginning of the item
  2004. */
  2005. /*!
  2006. \var KDGanttViewItem::endLineBack
  2007. the background line at the end of the item
  2008. */
  2009. /*!
  2010. \var KDGanttViewItem::actualEnd
  2011. the line at the actual end of the item
  2012. */
  2013. /*!
  2014. \var KDGanttViewItem::startShape
  2015. the shape at the beginning of the item
  2016. */
  2017. /*!
  2018. \var KDGanttViewItem::midShape
  2019. the shape in the middle of the item
  2020. */
  2021. /*!
  2022. \var KDGanttViewItem::endShape
  2023. the shape at the end of the item
  2024. */
  2025. /*!
  2026. \var KDGanttViewItem::startShapeBack
  2027. the background shape at the beginning of the item
  2028. */
  2029. /*!
  2030. \var KDGanttViewItem::midShapeBack
  2031. the background shape in the middle of the item
  2032. */
  2033. /*!
  2034. \var KDGanttViewItem::endShapeBack
  2035. the background shape at the end of the item
  2036. */
  2037. /*!
  2038. \var KDGanttViewItem::myGanttView
  2039. a pointer to the KDGanttView object to which this item belongs
  2040. */
  2041. /*!
  2042. \var KDGanttViewItem::textCanvas
  2043. the text object that is used for this item
  2044. */
  2045. /*!
  2046. \var KDGanttViewItem::textCanvasText
  2047. the actual string that is displayed in the text object for this item
  2048. */
  2049. /*!
  2050. \var KDGanttViewItem::myStartTime
  2051. the starting time of this item
  2052. */
  2053. /*!
  2054. \var KDGanttViewItem::myEndTime
  2055. the ending time of this item
  2056. */
  2057. /*!
  2058. \var KDGanttViewItem::isHighlighted
  2059. whether this item is currently highlighted or not
  2060. */
  2061. /*!
  2062. \var KDGanttViewItem::isEditable
  2063. whether this item is currently editable or not
  2064. */
  2065. /*!
  2066. \var KDGanttViewItem::myItemSize
  2067. the current size of this item
  2068. */
  2069. /*!
  2070. \var KDGanttViewItem::blockUpdating
  2071. if true, updates to this item are currently blocked, to reduce
  2072. flicker or speed up redraws
  2073. */
  2074. /*!
  2075. \var KDGanttViewItem::isVisibleInGanttView
  2076. this instance variable is true if the item is visible in the Gantt
  2077. view
  2078. */
  2079. /*!
  2080. Returns the coordinate of this items middle left point
  2081. */
  2082. TQPoint KDGanttViewItem::middleLeft()
  2083. {
  2084. return TQPoint(myGanttView->myTimeHeader->getCoordX(myStartTime), itemPos()+height()/2);
  2085. }
  2086. /*!
  2087. Returns the coordinate of this items middle right point
  2088. */
  2089. TQPoint KDGanttViewItem::middleRight()
  2090. {
  2091. return TQPoint(myGanttView->myTimeHeader->getCoordX(myEndTime), itemPos()+height()/2);
  2092. }
  2093. /*!
  2094. Moves this items text.
  2095. */
  2096. void KDGanttViewItem::moveTextCanvas(int x, int y)
  2097. {
  2098. int mx = x + myTextOffset.x();
  2099. int my = y + myTextOffset.y();
  2100. if (myTextOffset.x() != 0)
  2101. mx -= 2*myItemSize; // keep old behaviour
  2102. textCanvas->move(mx+2*myItemSize,my-myItemSize/2);
  2103. //tqDebug("%s: moveTextCanvas(%d,%d) offset: %d,%d moved to %d,%d",listViewText(0).latin1(),x,y,myTextOffset.x(),myTextOffset.y(),mx+2*myItemSize,my-myItemSize/2);
  2104. }
  2105. /*!
  2106. Moves this items text relative to the middle right end of the item
  2107. Used to move text away from link.
  2108. */
  2109. void KDGanttViewItem::moveTextCanvas()
  2110. {
  2111. TQPoint m = myTextOffset+middleRight();
  2112. textCanvas->move(m.x(), m.y()-myItemSize/2);
  2113. }
  2114. /*!
  2115. Sets with how much the item text is offset.
  2116. */
  2117. void KDGanttViewItem::setTextOffset(TQPoint p)
  2118. {
  2119. //tqDebug("%s: setTextOffset() offset: %d,%d",listViewText(0).latin1(),p.x(),p.y());
  2120. myTextOffset.setX(p.x());
  2121. myTextOffset.setY(p.y());
  2122. }
  2123. bool KDGanttViewItem::isMyTextCanvas(TQCanvasItem *tc)
  2124. {
  2125. return tc == textCanvas;
  2126. }
  2127. /*!
  2128. Specifies the progress of this item in percent.
  2129. Progress is limited to minimum 0, maximum 100.
  2130. \param percent the progress in percent.
  2131. */
  2132. void KDGanttViewItem::setProgress(int percent)
  2133. {
  2134. myProgress = TQMAX(0, percent);
  2135. myProgress = TQMIN(100, myProgress);
  2136. }
  2137. /*!
  2138. Specifies the float start time of this item.
  2139. If the time is invalid, the start float is not shown.
  2140. \param start the float start time
  2141. */
  2142. void KDGanttViewItem::setFloatStartTime(const TQDateTime &start)
  2143. {
  2144. myFloatStartTime = start;
  2145. }
  2146. /*!
  2147. Specifies the float end time of this item.
  2148. If the time is invalid, the end float is not shown.
  2149. \param end the float end time
  2150. */
  2151. void KDGanttViewItem::setFloatEndTime(const TQDateTime &end)
  2152. {
  2153. myFloatEndTime = end;
  2154. }