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.

1008 lines
33KB

  1. /* -*- Mode: C++ -*-
  2. $Id: KDGanttViewTaskLink.cpp 422535 2005-06-05 18:54:23Z adridg $
  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 "KDGanttViewTaskLink.h"
  34. #include "KDGanttViewTaskLinkGroup.h"
  35. #include "KDGanttViewSubwidgets.h"
  36. #include "KDGanttXMLTools.h"
  37. /*! \class KDGanttViewTaskLink KDGanttViewTaskLink.h
  38. This class represents a link between a number of Gantt chart items.
  39. It always connects source items with target items. Task links can
  40. be grouped into KDGanttViewTaskLinkGroup objects.
  41. If a Gantt view item is deleted, it is removed from the fromList or
  42. from the toList.
  43. If one of the lists becomes empty, the complete task link is deleted
  44. as well.
  45. The task link is deleted by KDGanttViews d'tor.
  46. You may delete the task link yourself, if you do it
  47. _before_ KDGanttViews d'tor is called.
  48. */
  49. /*!
  50. Creates a task link that connects all items in the source item list from
  51. to all items in the destination item list to.
  52. \param from the source items
  53. \param to the target items
  54. \param type the link type for the connection
  55. */
  56. KDGanttViewTaskLink::KDGanttViewTaskLink( TQPtrList<KDGanttViewItem> from,
  57. TQPtrList<KDGanttViewItem> to,
  58. LinkType type )
  59. {
  60. fromList= from;
  61. toList = to;
  62. myGroup = 0;
  63. setLinkType(type);
  64. initTaskLink();
  65. }
  66. /*!
  67. \overload
  68. Creates a task link that connects two items.
  69. Note, that the from() and to() functions are returning a list,
  70. in this case containing only one item.
  71. \param from the source item
  72. \param to the target item
  73. \param type the link type for the connection
  74. */
  75. KDGanttViewTaskLink::KDGanttViewTaskLink( KDGanttViewItem* from,
  76. KDGanttViewItem* to,
  77. LinkType type )
  78. {
  79. fromList.append(from);
  80. toList.append(to);
  81. myGroup = 0;
  82. setLinkType(type);
  83. initTaskLink();
  84. }
  85. /*!
  86. Creates a task link that connects all items in the source item list from
  87. to all items in the destination item list to.
  88. Inserts the link directly into a link group.
  89. \param group the link group to insert this link into
  90. \param from the source items
  91. \param to the target items
  92. \param type the link type for the connection
  93. */
  94. KDGanttViewTaskLink::KDGanttViewTaskLink( KDGanttViewTaskLinkGroup* group,
  95. TQPtrList<KDGanttViewItem> from,
  96. TQPtrList<KDGanttViewItem> to,
  97. LinkType type )
  98. {
  99. fromList = from;
  100. toList = to;
  101. myGroup = 0;
  102. setLinkType(type);
  103. initTaskLink();
  104. setGroup(group);
  105. }
  106. /*!
  107. \overload
  108. Creates a task link that connects two items and inserts the link
  109. directly into a link group.
  110. Note, that the from() and to() functions are returning a list,
  111. in this case containing only one item.
  112. \param group the link group to insert this link into
  113. \param from the source item
  114. \param to the target item
  115. \param type the link type for the connection
  116. */
  117. KDGanttViewTaskLink::KDGanttViewTaskLink( KDGanttViewTaskLinkGroup* group,
  118. KDGanttViewItem* from,
  119. KDGanttViewItem* to,
  120. LinkType type )
  121. {
  122. fromList.append(from);
  123. toList.append(to);
  124. myGroup = 0;
  125. setLinkType(type);
  126. initTaskLink();
  127. setGroup(group);
  128. }
  129. KDGanttViewTaskLink::~KDGanttViewTaskLink( )
  130. {
  131. setGroup(0);
  132. myTimeTable->myTaskLinkList.remove(this);
  133. delete horLineList;
  134. delete verLineList;
  135. delete horLineList2;
  136. delete verLineList2;
  137. delete horLineList3;
  138. delete topList;
  139. delete topLeftList;
  140. delete topRightList;
  141. }
  142. void KDGanttViewTaskLink::initTaskLink()
  143. {
  144. horLineList = new TQPtrList<KDCanvasLine>;
  145. verLineList = new TQPtrList<KDCanvasLine>;
  146. horLineList2 = new TQPtrList<KDCanvasLine>;
  147. verLineList2 = new TQPtrList<KDCanvasLine>;
  148. horLineList3 = new TQPtrList<KDCanvasLine>;
  149. topList = new TQPtrList<KDCanvasPolygon>;
  150. topLeftList = new TQPtrList<KDCanvasPolygon>;
  151. topRightList = new TQPtrList<KDCanvasPolygon>;
  152. horLineList->setAutoDelete( true );
  153. verLineList->setAutoDelete( true );
  154. horLineList2->setAutoDelete( true );
  155. verLineList2->setAutoDelete( true );
  156. horLineList3->setAutoDelete( true );
  157. topList->setAutoDelete( true );
  158. topLeftList->setAutoDelete( true );
  159. topRightList->setAutoDelete( true );
  160. myTimeTable = fromList.getFirst()->myGanttView->myTimeTable;
  161. KDCanvasLine* horLine,*verLine;
  162. KDCanvasLine* horLine2,*verLine2;
  163. KDCanvasLine* horLine3;
  164. KDCanvasPolygon* top;
  165. KDCanvasPolygon* topLeft;
  166. KDCanvasPolygon* topRight;
  167. unsigned int i, j;
  168. for ( i = 0;i < fromList.count();++i) {
  169. for ( j = 0;j < toList.count();++j) {
  170. horLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
  171. verLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
  172. horLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
  173. verLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
  174. horLine3 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
  175. top = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
  176. topLeft = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
  177. topRight = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
  178. TQPointArray arr = TQPointArray(3);
  179. arr.setPoint(0,-4,-5);
  180. arr.setPoint(1,4,-5);
  181. arr.setPoint(2,0,0);
  182. top->setPoints(arr);
  183. arr.setPoint(0,5,-5); // need an extra y pixel, canvas bug?
  184. arr.setPoint(1,5,5); // need an extra y pixel, canvas bug?
  185. arr.setPoint(2,0,0);
  186. topLeft->setPoints(arr);
  187. arr.setPoint(0,-5,-4);
  188. arr.setPoint(1,-5,4);
  189. arr.setPoint(2,0,0);
  190. topRight->setPoints(arr);
  191. horLineList->append(horLine);
  192. verLineList->append(verLine);
  193. horLineList2->append(horLine2);
  194. verLineList2->append(verLine2);
  195. horLineList3->append(horLine3);
  196. topList->append(top);
  197. topLeftList->append(topLeft);
  198. topRightList->append(topRight);
  199. horLine->setZ(1);
  200. verLine->setZ(1);
  201. horLine2->setZ(1);
  202. verLine2->setZ(1);
  203. horLine3->setZ(1);
  204. top->setZ(1);
  205. topLeft->setZ(1);
  206. topRight->setZ(1);
  207. }
  208. }
  209. setTooltipText( "Tasklink" );
  210. setWhatsThisText( "Tasklink" );
  211. myTimeTable->myTaskLinkList.append(this);
  212. setHighlight( false);
  213. setHighlightColor(TQt::red );
  214. setColor(TQt::black);
  215. setVisible(true);
  216. }
  217. /*!
  218. Specifies whether this task link should be visible or not.
  219. \param visible pass true to make this task link visible, and false
  220. to hide it
  221. \sa isVisible()
  222. */
  223. void KDGanttViewTaskLink::setVisible( bool visible )
  224. {
  225. showMe ( visible );
  226. myTimeTable->updateMyContent();
  227. }
  228. void KDGanttViewTaskLink::showMe( bool visible )
  229. {
  230. if (linkType() != None) {
  231. showMeType(visible);
  232. return;
  233. }
  234. hide();
  235. isvisible = visible;
  236. int wid = 1;
  237. TQPen p;
  238. TQBrush b;
  239. p.setWidth(wid);
  240. b.setStyle(Qt::SolidPattern);
  241. if (ishighlighted) {
  242. b.setColor(myColorHL);
  243. p.setColor(myColorHL);
  244. } else {
  245. b.setColor(myColor);
  246. p.setColor(myColor);
  247. }
  248. TQPoint start, end;
  249. TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
  250. TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
  251. TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
  252. TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
  253. TQPtrListIterator<KDGanttViewItem> toIt(toList);
  254. for ( ; fromIt.current(); ++fromIt ) {
  255. (*fromIt)->setTextOffset(TQPoint(0,0));
  256. toIt.toFirst();
  257. for ( ; toIt.current(); ++toIt ) {
  258. (*toIt)->setTextOffset(TQPoint(0,0));
  259. if (!isvisible || ! (*fromIt)->isVisibleInGanttView || !(*toIt)->isVisibleInGanttView || !myTimeTable->taskLinksVisible) {
  260. (*horIt)->hide();
  261. (*verIt)->hide();
  262. (*topIt)->hide();
  263. ++horIt;
  264. ++verIt;
  265. ++topIt;
  266. } else {
  267. (*horIt)->setPen(p);
  268. (*verIt)->setPen(p);
  269. (*topIt)->setBrush(b);
  270. end = (*toIt)->getTaskLinkEndCoord();
  271. start = (*fromIt)->getTaskLinkStartCoord(end);
  272. (*horIt)->setPoints(start.x(),start.y(),end.x()+wid,start.y());
  273. (*verIt)->setPoints(end.x()+wid/2,start.y(),end.x()+wid/2,end.y()-2);
  274. (*topIt)->move(end.x()+wid/2,end.y());
  275. (*horIt)->show();
  276. (*verIt)->show();
  277. (*topIt)->show();
  278. ++horIt;
  279. ++verIt;
  280. ++topIt;
  281. }
  282. }
  283. }
  284. while ( horIt.current() ) {
  285. (*horIt)->hide();
  286. (*verIt)->hide();
  287. (*topIt)->hide();
  288. ++horIt;
  289. ++verIt;
  290. ++topIt;
  291. }
  292. }
  293. void KDGanttViewTaskLink::showMeType( bool visible )
  294. {
  295. //tqDebug("KDGanttViewTaskLink::showMeType %d",linkType());
  296. hide();
  297. isvisible = visible;
  298. int wid = 1;
  299. TQPen p;
  300. TQBrush b;
  301. p.setWidth(wid);
  302. b.setStyle(Qt::SolidPattern);
  303. if (ishighlighted) {
  304. b.setColor(myColorHL);
  305. p.setColor(myColorHL);
  306. } else {
  307. b.setColor(myColor);
  308. p.setColor(myColor);
  309. }
  310. TQPoint start, end;
  311. TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
  312. TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
  313. TQPtrListIterator<KDCanvasLine> horIt2(*horLineList2);
  314. TQPtrListIterator<KDCanvasLine> verIt2(*verLineList2);
  315. TQPtrListIterator<KDCanvasLine> horIt3(*horLineList3);
  316. TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
  317. TQPtrListIterator<KDCanvasPolygon> topLeftIt(*topLeftList);
  318. TQPtrListIterator<KDCanvasPolygon> topRightIt(*topRightList);
  319. TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
  320. TQPtrListIterator<KDGanttViewItem> toIt(toList);
  321. for ( ; fromIt.current(); ++fromIt ) {
  322. (*fromIt)->setTextOffset(TQPoint(30,0));
  323. (*fromIt)->moveTextCanvas();
  324. toIt.toFirst();
  325. for ( ; toIt.current(); ++toIt ) {
  326. if (isvisible && (*fromIt)->isVisibleInGanttView &&
  327. (*toIt)->isVisibleInGanttView && myTimeTable->taskLinksVisible) {
  328. (*horIt)->setPen(p);
  329. (*verIt)->setPen(p);
  330. (*horIt2)->setPen(p);
  331. (*verIt2)->setPen(p);
  332. (*horIt3)->setPen(p);
  333. (*topIt)->setBrush(b);
  334. (*topLeftIt)->setBrush(b);
  335. (*topRightIt)->setBrush(b);
  336. (*toIt)->setTextOffset(TQPoint(30,0));
  337. (*toIt)->moveTextCanvas();
  338. switch (linkType()) {
  339. case StartStart: {
  340. start = (*fromIt)->middleLeft();
  341. end = (*toIt)->middleLeft()-TQPoint(12,0);
  342. bool down = start.y() < end.y();
  343. (*horIt)->setPoints(start.x()-xOffset(*fromIt),start.y(),
  344. start.x()-10, start.y());
  345. (*verIt)->setPoints(
  346. (*horIt)->endPoint().x(),
  347. (*horIt)->endPoint().y(),
  348. (*horIt)->endPoint().x(),
  349. (down ? (*toIt)->itemPos()+1
  350. : (*toIt)->itemPos()+(*toIt)->height()-1));
  351. (*horIt2)->setPoints((*verIt)->endPoint().x(),
  352. (*verIt)->endPoint().y(),
  353. end.x()-12,
  354. (*verIt)->endPoint().y());
  355. (*verIt2)->setPoints((*horIt2)->endPoint().x(),
  356. (*horIt2)->endPoint().y(),
  357. (*horIt2)->endPoint().x(),
  358. end.y());
  359. (*horIt3)->setPoints((*verIt2)->endPoint().x(),
  360. (*verIt2)->endPoint().y(),
  361. end.x(),
  362. end.y());
  363. (*topRightIt)->move(end.x(),end.y());
  364. (*topRightIt)->show();
  365. break;
  366. }
  367. case FinishFinish: {
  368. start = (*fromIt)->middleRight();
  369. end = (*toIt)->middleRight()+TQPoint(12,0);
  370. bool down = start.y() < end.y();
  371. (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
  372. start.x()+10, start.y());
  373. (*verIt)->setPoints(
  374. (*horIt)->endPoint().x(),
  375. (*horIt)->endPoint().y(),
  376. (*horIt)->endPoint().x(),
  377. (down ? (*toIt)->itemPos()+1
  378. : (*toIt)->itemPos()+(*toIt)->height()-1));
  379. (*horIt2)->setPoints((*verIt)->endPoint().x(),
  380. (*verIt)->endPoint().y(),
  381. end.x()+12,
  382. (*verIt)->endPoint().y());
  383. (*verIt2)->setPoints((*horIt2)->endPoint().x(),
  384. (*horIt2)->endPoint().y(),
  385. (*horIt2)->endPoint().x(),
  386. end.y());
  387. (*horIt3)->setPoints((*verIt2)->endPoint().x(),
  388. (*verIt2)->endPoint().y(),
  389. end.x(),
  390. end.y());
  391. (*topLeftIt)->move(end.x(),end.y());
  392. (*topLeftIt)->show();
  393. break;
  394. }
  395. case FinishStart: {
  396. start = (*fromIt)->middleRight();
  397. end = (*toIt)->middleLeft() - TQPoint(12,0);
  398. bool down = start.y() < end.y();
  399. (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
  400. start.x()+10,start.y());
  401. (*verIt)->setPoints(
  402. (*horIt)->endPoint().x(),
  403. (*horIt)->endPoint().y(),
  404. (*horIt)->endPoint().x(),
  405. (down ? (*toIt)->itemPos()+1
  406. : (*toIt)->itemPos()+(*toIt)->height()-1));
  407. (*horIt2)->setPoints((*verIt)->endPoint().x(),
  408. (*verIt)->endPoint().y(),
  409. end.x()-12,
  410. (*verIt)->endPoint().y());
  411. (*verIt2)->setPoints((*horIt2)->endPoint().x(),
  412. (*horIt2)->endPoint().y(),
  413. (*horIt2)->endPoint().x(),
  414. end.y());
  415. (*horIt3)->setPoints((*verIt2)->endPoint().x(),
  416. (*verIt2)->endPoint().y(),
  417. end.x(),
  418. end.y());
  419. (*topRightIt)->move(end.x(),end.y());
  420. (*topRightIt)->show();
  421. break;
  422. }
  423. case StartFinish: {
  424. start = (*fromIt)->middleRight();
  425. end = (*toIt)->middleRight()+TQPoint(12,0);
  426. bool down = start.y() < end.y();
  427. (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
  428. start.x()+10, start.y());
  429. (*verIt)->setPoints(
  430. (*horIt)->endPoint().x(),
  431. (*horIt)->endPoint().y(),
  432. (*horIt)->endPoint().x(),
  433. (down ? (*toIt)->itemPos()+1
  434. : (*toIt)->itemPos()+(*toIt)->height()-1));
  435. (*horIt2)->setPoints((*verIt)->endPoint().x(),
  436. (*verIt)->endPoint().y(),
  437. end.x()-12,
  438. (*verIt)->endPoint().y());
  439. (*verIt2)->setPoints((*horIt2)->endPoint().x(),
  440. (*horIt2)->endPoint().y(),
  441. (*horIt2)->endPoint().x(),
  442. end.y());
  443. (*horIt3)->setPoints((*verIt2)->endPoint().x(),
  444. (*verIt2)->endPoint().y(),
  445. end.x(),
  446. end.y());
  447. (*topRightIt)->move(end.x(),end.y());
  448. (*topRightIt)->show();
  449. break;
  450. }
  451. default:
  452. tqWarning("KDGanttViewTaskLink: Unknown link type");
  453. break;
  454. }
  455. (*horIt)->show();
  456. (*verIt)->show();
  457. (*horIt2)->show();
  458. (*verIt2)->show();
  459. (*horIt3)->show();
  460. }
  461. ++horIt;
  462. ++verIt;
  463. ++horIt2;
  464. ++verIt2;
  465. ++horIt3;
  466. ++topIt;
  467. ++topLeftIt;
  468. ++topRightIt;
  469. }
  470. }
  471. }
  472. /*!
  473. Returns whether this task link should be visible or not.
  474. \return true if the task link is visible
  475. \sa setVisible()
  476. */
  477. bool KDGanttViewTaskLink::isVisible() const
  478. {
  479. return isvisible;
  480. }
  481. /*!
  482. Returns the group (if any) to which this task link belongs.
  483. \return the group to which this task link belongs; 0 if it does not
  484. belong to any group.
  485. \sa KDGanttViewTaskLinkGroup
  486. */
  487. KDGanttViewTaskLinkGroup* KDGanttViewTaskLink::group()
  488. {
  489. return myGroup;
  490. }
  491. /*!
  492. Inserts this task link in a group.
  493. If the parameter is 0, the task link is removed from any group
  494. \param group the group, this task link has to be inserted
  495. \sa KDGanttViewTaskLinkGroup
  496. */
  497. void KDGanttViewTaskLink::setGroup(KDGanttViewTaskLinkGroup* group)
  498. {
  499. myTimeTable->myGanttView->addTaskLinkGroup(group);
  500. if(myGroup == group)
  501. return;
  502. if (myGroup != 0)
  503. myGroup->removeItem(this);
  504. myGroup = group;
  505. if (myGroup != 0)
  506. myGroup->insertItem(this);
  507. }
  508. /*!
  509. Specifies whether this task link should be shown highlighted. The
  510. user can also highlight a task link with the mouse.
  511. \param highlight pass true in order to highlight this task link
  512. \sa highlight()
  513. */
  514. void KDGanttViewTaskLink::setHighlight( bool highlight )
  515. {
  516. ishighlighted = highlight ;
  517. // if ( isvisible) setVisible(true );
  518. myTimeTable->updateMyContent();
  519. }
  520. /*!
  521. Returns whether this task link is highlighted, either
  522. programmatically by setHighlight() or by the user with the mouse.
  523. \return true if the task link is highlighted
  524. \sa setHighlight()
  525. */
  526. bool KDGanttViewTaskLink::highlight() const
  527. {
  528. return ishighlighted;
  529. }
  530. /*!
  531. Specifies the color to draw this task link in.
  532. \param color the color to draw this task link in
  533. \sa color()
  534. */
  535. void KDGanttViewTaskLink::setColor( const TQColor& color )
  536. {
  537. myColor = color;
  538. //if ( isvisible) setVisible(true );
  539. myTimeTable->updateMyContent();
  540. }
  541. /*!
  542. Returns the color in which this task link is drawn.
  543. \return the color in which this task link is drawn
  544. \sa setColor()
  545. */
  546. TQColor KDGanttViewTaskLink::color() const
  547. {
  548. return myColor;
  549. }
  550. /*!
  551. Specifies the highlight color to draw this task link in.
  552. \param color the highlight color to draw this task link in
  553. \sa highlightColor()
  554. */
  555. void KDGanttViewTaskLink::setHighlightColor( const TQColor& color )
  556. {
  557. myColorHL = color;
  558. //if ( isvisible) setVisible(true );
  559. myTimeTable->updateMyContent();
  560. }
  561. /*!
  562. Returns the highlight color in which this task link is drawn.
  563. \return the highlight color in which this task link is drawn
  564. \sa setHighlightColor()
  565. */
  566. TQColor KDGanttViewTaskLink::highlightColor() const
  567. {
  568. return myColorHL;
  569. }
  570. /*!
  571. Specifies the text to be shown as a tooltip for this task link.
  572. \param text the tooltip text
  573. \sa tooltipText()
  574. */
  575. void KDGanttViewTaskLink::setTooltipText( const TQString& text )
  576. {
  577. myToolTipText = text;
  578. }
  579. /*!
  580. Returns the tooltip text of this task link.
  581. \return the tooltip text of this task link
  582. \sa setTooltipText()
  583. */
  584. TQString KDGanttViewTaskLink::tooltipText() const
  585. {
  586. return myToolTipText;
  587. }
  588. /*!
  589. Specifies the text to be shown in a what's this window for this task link.
  590. \param text the what's this text
  591. \sa whatsThisText()
  592. */
  593. void KDGanttViewTaskLink::setWhatsThisText( const TQString& text )
  594. {
  595. myWhatsThisText = text;
  596. }
  597. /*!
  598. Returns the what's this text of this task link.
  599. \return the what's this text of this task link
  600. \sa setWhatsThisText()
  601. */
  602. TQString KDGanttViewTaskLink::whatsThisText() const
  603. {
  604. return myWhatsThisText;
  605. }
  606. /*!
  607. Returns the list of source item of this task link.
  608. \return the ist of source item of this task link
  609. \sa to()
  610. */
  611. TQPtrList<KDGanttViewItem> KDGanttViewTaskLink::from() const
  612. {
  613. return fromList;
  614. }
  615. /*!
  616. Removes a KDGanttViewItem from the lists.
  617. \sa to() from()
  618. */
  619. void KDGanttViewTaskLink::removeItemFromList( KDGanttViewItem* item )
  620. {
  621. bool itemremoved = false;
  622. if (fromList.remove( item )) {
  623. itemremoved = true;
  624. }
  625. if ( toList.remove( item )) {
  626. itemremoved = true;
  627. }
  628. if ( itemremoved ) {
  629. setVisible( isvisible );
  630. }
  631. }
  632. /*!
  633. Returns the list of target items of this task link.
  634. \return the list of target item of this task link
  635. \sa from()
  636. */
  637. TQPtrList<KDGanttViewItem> KDGanttViewTaskLink::to() const
  638. {
  639. return toList;
  640. }
  641. /*!
  642. Creates a DOM node that describes this task link.
  643. \param doc the DOM document to which the node belongs
  644. \param parentElement the element into which to insert this node
  645. */
  646. void KDGanttViewTaskLink::createNode( TQDomDocument& doc,
  647. TQDomElement& parentElement )
  648. {
  649. TQDomElement taskLinkElement = doc.createElement( "TaskLink" );
  650. parentElement.appendChild( taskLinkElement );
  651. TQDomElement fromItemsElement = doc.createElement( "FromItems" );
  652. taskLinkElement.appendChild( fromItemsElement );
  653. TQPtrList<KDGanttViewItem> fromList = from();
  654. KDGanttViewItem* item;
  655. for( item = fromList.first(); item;
  656. item = fromList.next() )
  657. KDGanttXML::createStringNode( doc, fromItemsElement, "Item", item->name() );
  658. TQDomElement toItemsElement = doc.createElement( "ToItems" );
  659. taskLinkElement.appendChild( toItemsElement );
  660. TQPtrList<KDGanttViewItem> toList = to();
  661. for( item = toList.first(); item;
  662. item = toList.next() )
  663. KDGanttXML::createStringNode( doc, toItemsElement, "Item", item->name() );
  664. KDGanttXML::createBoolNode( doc, taskLinkElement, "Highlight", highlight() );
  665. KDGanttXML::createColorNode( doc, taskLinkElement, "Color", color() );
  666. KDGanttXML::createColorNode( doc, taskLinkElement, "HighlightColor",
  667. highlightColor() );
  668. KDGanttXML::createStringNode( doc, taskLinkElement, "TooltipText",
  669. tooltipText() );
  670. KDGanttXML::createStringNode( doc, taskLinkElement, "WhatsThisText",
  671. whatsThisText() );
  672. if( group() )
  673. KDGanttXML::createStringNode( doc, taskLinkElement, "Group",
  674. group()->name() );
  675. KDGanttXML::createBoolNode( doc, taskLinkElement, "Visible",
  676. isVisible() );
  677. KDGanttXML::createStringNode( doc, taskLinkElement, "Linktype",
  678. linkTypeToString( myLinkType ) );
  679. }
  680. /*!
  681. Creates a KDGanttViewTaskLink according to the specification in a DOM
  682. element.
  683. \param element the DOM element from which to read the specification
  684. \return the newly created task link
  685. */
  686. KDGanttViewTaskLink* KDGanttViewTaskLink::createFromDomElement( TQDomElement& element )
  687. {
  688. TQDomNode node = element.firstChild();
  689. TQStringList fromList, toList;
  690. bool highlight = false, visible = false;
  691. TQColor color, highlightColor;
  692. TQString tooltipText, whatsThisText, group;
  693. LinkType linktype=None;
  694. while( !node.isNull() ) {
  695. TQDomElement element = node.toElement();
  696. if( !element.isNull() ) { // was really an element
  697. TQString tagName = element.tagName();
  698. if( tagName == "FromItems" ) {
  699. TQDomNode node = element.firstChild();
  700. while( !node.isNull() ) {
  701. TQDomElement element = node.toElement();
  702. if( !element.isNull() ) { // was really an element
  703. TQString tagName = element.tagName();
  704. if( tagName == "Item" ) {
  705. TQString value;
  706. if( KDGanttXML::readStringNode( element, value ) )
  707. fromList << value;
  708. } else {
  709. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  710. Q_ASSERT( false );
  711. }
  712. }
  713. node = node.nextSibling();
  714. }
  715. } else if( tagName == "ToItems" ) {
  716. TQDomNode node = element.firstChild();
  717. while( !node.isNull() ) {
  718. TQDomElement element = node.toElement();
  719. if( !element.isNull() ) { // was really an element
  720. TQString tagName = element.tagName();
  721. if( tagName == "Item" ) {
  722. TQString value;
  723. if( KDGanttXML::readStringNode( element, value ) )
  724. toList << value;
  725. } else {
  726. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  727. Q_ASSERT( false );
  728. }
  729. }
  730. node = node.nextSibling();
  731. }
  732. } else if( tagName == "Highlight" ) {
  733. bool value;
  734. if( KDGanttXML::readBoolNode( element, value ) )
  735. highlight = value;
  736. } else if( tagName == "Visible" ) {
  737. bool value;
  738. if( KDGanttXML::readBoolNode( element, value ) )
  739. visible = value;
  740. } else if( tagName == "Color" ) {
  741. TQColor value;
  742. if( KDGanttXML::readColorNode( element, value ) )
  743. color = value;
  744. } else if( tagName == "HighlightColor" ) {
  745. TQColor value;
  746. if( KDGanttXML::readColorNode( element, value ) )
  747. highlightColor = value;
  748. } else if( tagName == "TooltipText" ) {
  749. TQString value;
  750. if( KDGanttXML::readStringNode( element, value ) )
  751. tooltipText = value;
  752. } else if( tagName == "WhatsThisText" ) {
  753. TQString value;
  754. if( KDGanttXML::readStringNode( element, value ) )
  755. whatsThisText = value;
  756. } else if( tagName == "Group" ) {
  757. TQString value;
  758. if( KDGanttXML::readStringNode( element, value ) )
  759. group = value;
  760. } else if( tagName == "Linktype" ) {
  761. TQString value;
  762. if( KDGanttXML::readStringNode( element, value ) )
  763. linktype = stringToLinkType( value );
  764. } else {
  765. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  766. Q_ASSERT( false );
  767. }
  768. }
  769. node = node.nextSibling();
  770. }
  771. TQPtrList<KDGanttViewItem> fromItemList;
  772. TQPtrList<KDGanttViewItem> toItemList;
  773. for( TQStringList::const_iterator fromIt = fromList.begin();
  774. fromIt != fromList.end(); ++fromIt ) {
  775. KDGanttViewItem* item = KDGanttViewItem::find( *fromIt );
  776. if( item )
  777. fromItemList.append( item );
  778. }
  779. for( TQStringList::const_iterator toIt = toList.begin();
  780. toIt != toList.end(); ++toIt ) {
  781. KDGanttViewItem* item = KDGanttViewItem::find( *toIt );
  782. if( item )
  783. toItemList.append( item );
  784. }
  785. // safeguard aginst incorrect names
  786. if (fromItemList.isEmpty()) {
  787. tqDebug("Cannot create link: fromItemList is empty");
  788. return 0;
  789. }
  790. if (toItemList.isEmpty()) {
  791. tqDebug("Cannot create link: toItemList is empty");
  792. return 0;
  793. }
  794. KDGanttViewTaskLink* tl = new KDGanttViewTaskLink( fromItemList,
  795. toItemList );
  796. tl->setLinkType( linktype );
  797. tl->setVisible( visible );
  798. tl->setHighlight( highlight );
  799. tl->setColor( color );
  800. tl->setHighlightColor( highlightColor );
  801. tl->setTooltipText( tooltipText );
  802. tl->setWhatsThisText( whatsThisText );
  803. KDGanttViewTaskLinkGroup* gr = KDGanttViewTaskLinkGroup::find( group );
  804. if( gr )
  805. tl->setGroup( gr );
  806. return tl;
  807. }
  808. int KDGanttViewTaskLink::linkType()
  809. {
  810. return myLinkType;
  811. }
  812. void KDGanttViewTaskLink::setLinkType(int type)
  813. {
  814. myLinkType = static_cast<LinkType>(type);
  815. }
  816. int KDGanttViewTaskLink::xOffset(KDGanttViewItem *item)
  817. {
  818. switch (item->type()) {
  819. case KDGanttViewItem::Task:
  820. return 0;
  821. break;
  822. case KDGanttViewItem::Event:
  823. return 4;
  824. break;
  825. case KDGanttViewItem::Summary:
  826. return 4;
  827. break;
  828. default:
  829. break;
  830. }
  831. return 0;
  832. }
  833. void KDGanttViewTaskLink::hide()
  834. {
  835. TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
  836. TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
  837. TQPtrListIterator<KDCanvasLine> horIt2(*horLineList2);
  838. TQPtrListIterator<KDCanvasLine> verIt2(*verLineList2);
  839. TQPtrListIterator<KDCanvasLine> horIt3(*horLineList3);
  840. TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
  841. TQPtrListIterator<KDCanvasPolygon> topLeftIt(*topLeftList);
  842. TQPtrListIterator<KDCanvasPolygon> topRightIt(*topRightList);
  843. TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
  844. TQPtrListIterator<KDGanttViewItem> toIt(toList);
  845. for ( ; fromIt.current(); ++fromIt ) {
  846. toIt.toFirst();
  847. for ( ; toIt.current(); ++toIt ) {
  848. (*horIt)->hide();
  849. (*verIt)->hide();
  850. (*horIt2)->hide();
  851. (*verIt2)->hide();
  852. (*horIt3)->hide();
  853. (*topIt)->hide();
  854. (*topLeftIt)->hide();
  855. (*topRightIt)->hide();
  856. ++horIt;
  857. ++verIt;
  858. ++horIt2;
  859. ++verIt2;
  860. ++horIt3;
  861. ++topIt;
  862. ++topLeftIt;
  863. ++topRightIt;
  864. }
  865. }
  866. }
  867. TQString KDGanttViewTaskLink::linkTypeToString( LinkType type )
  868. {
  869. switch( type ) {
  870. case None:
  871. return "None";
  872. break;
  873. case FinishStart:
  874. return "FinishStart";
  875. break;
  876. case FinishFinish:
  877. return "FinishFinish";
  878. break;
  879. case StartStart:
  880. return "StartStart";
  881. break;
  882. case StartFinish:
  883. return "StartFinish";
  884. break;
  885. default:
  886. break;
  887. }
  888. return "";
  889. }
  890. KDGanttViewTaskLink::LinkType KDGanttViewTaskLink::stringToLinkType( const TQString type )
  891. {
  892. if (type == "FinishStart")
  893. return FinishStart;
  894. if (type == "FinishFinish")
  895. return FinishFinish;
  896. if (type == "StartStart")
  897. return StartStart;
  898. if (type == "StartFinish")
  899. return StartFinish;
  900. return None;
  901. }