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.

3866 lines
127KB

  1. /* -*- Mode: C++ -*-
  2. $Id: KDGanttViewSubwidgets.cpp 669475 2007-05-29 13:44:48Z mueller $
  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 "KDGanttViewEventItem.h"
  35. #include "KDGanttViewSummaryItem.h"
  36. #include "KDGanttViewTaskItem.h"
  37. #ifndef KDGANTT_MASTER_CVS
  38. #include "KDGanttViewSubwidgets.moc"
  39. #endif
  40. #include <tqlabel.h>
  41. #include <tqheader.h>
  42. #include <tqpainter.h>
  43. #include <tqrect.h>
  44. #include <tqtooltip.h>
  45. #include <tqapplication.h>
  46. #include <tqdrawutil.h>
  47. #include <tqpalette.h>
  48. #include <tqdragobject.h>
  49. #include <tqptrlist.h>
  50. #include <tqpen.h>
  51. #include <tdeglobal.h>
  52. #include <tdelocale.h>
  53. #include <kcalendarsystem.h>
  54. #include <kdebug.h>
  55. KDTimeTableWidget:: KDTimeTableWidget( TQWidget* parent,KDGanttView* myGantt)
  56. : TQCanvas (TQT_TQOBJECT(parent))
  57. {
  58. myGanttView = myGantt;
  59. taskLinksVisible = true;
  60. flag_blockUpdating = false;
  61. int_blockUpdating = 0;
  62. gridPen.setStyle(Qt::DotLine);
  63. gridPen.setColor(TQColor(100,100,100));
  64. maximumComputedGridHeight = 0;
  65. denseLineCount = 0;
  66. denseLineBrush = TQBrush( TQColor ( 240,240,240 ));
  67. noInfoLineBrush = TQBrush( TQColor ( 100,100,100 ), TQt::FDiagPattern );
  68. pendingHeight = 0;
  69. pendingWidth = 0;
  70. retune(256);
  71. resize(1,1);
  72. }
  73. TQPtrList<KDGanttViewTaskLink> KDTimeTableWidget::taskLinks()
  74. {
  75. return myTaskLinkList;
  76. }
  77. void KDTimeTableWidget::clearTaskLinks()
  78. {
  79. // cannot use clear() here, as tasklinks will remove themselves from my list when deleted!
  80. TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
  81. while (it.current()) {
  82. delete it.current();
  83. }
  84. }
  85. void KDTimeTableWidget::resetWidth( int wid )
  86. {
  87. if ( wid == width() ) {
  88. if (pendingHeight)
  89. pendingWidth = wid;
  90. else
  91. pendingWidth = 0;
  92. return;
  93. }
  94. if ( ! pendingHeight )
  95. pendingHeight = height();
  96. pendingWidth = wid;
  97. updateMyContent();
  98. }
  99. void KDTimeTableWidget::checkHeight( int hei )
  100. {
  101. if( hei < height() )
  102. return;
  103. if ( pendingHeight < hei+100)
  104. pendingHeight = hei+100;
  105. if ( ! pendingWidth )
  106. pendingWidth = width();
  107. maximumComputedGridHeight = 0; //force recomputing all
  108. updateMyContent();
  109. }
  110. void KDTimeTableWidget::setNoInformationBrush( const TQBrush& brush )
  111. {
  112. noInfoLineBrush = brush;
  113. updateMyContent();
  114. }
  115. TQBrush KDTimeTableWidget::noInformationBrush() const
  116. {
  117. return noInfoLineBrush;
  118. }
  119. void KDTimeTableWidget::removeItemFromTasklinks( KDGanttViewItem* item)
  120. {
  121. TQPtrListIterator<KDGanttViewTaskLink> it((myTaskLinkList));
  122. for ( ; it.current(); ++it ) {
  123. it.current()->removeItemFromList( item );
  124. }
  125. }
  126. void KDTimeTableWidget::expandItem( TQListViewItem * item)
  127. {
  128. item->invalidateHeight () ;
  129. //tqApp->processEvents();
  130. updateMyContent();
  131. }
  132. void KDTimeTableWidget::collapseItem( TQListViewItem * item)
  133. {
  134. item->invalidateHeight () ;
  135. //tqApp->processEvents();
  136. updateMyContent();
  137. }
  138. void KDTimeTableWidget::highlightItem( TQListViewItem * item )
  139. {
  140. static bool itemwashighlighted;
  141. static KDGanttViewItem* highlightedItem = 0;
  142. if (highlightedItem)
  143. highlightedItem->setHighlight(itemwashighlighted);
  144. highlightedItem = ( KDGanttViewItem*)item;
  145. itemwashighlighted = highlightedItem->highlight();
  146. highlightedItem->setHighlight(true);
  147. item->invalidateHeight () ;
  148. myGanttView->myListView->contentsY();
  149. updateMyContent();
  150. }
  151. int KDTimeTableWidget::computeHeight()
  152. {
  153. // compute height of ListView
  154. // show only items shown in ListView
  155. int hei = 0;
  156. KDGanttViewItem* temp;
  157. temp = myGanttView->firstChild();
  158. while (temp) {
  159. hei += temp->computeHeight();
  160. temp = temp->nextSibling();
  161. }
  162. // set hei to 1 to avoid canavs to be a null pixmap
  163. if (hei == 0) {
  164. hei = 1;
  165. }
  166. //tqDebug("COMPUTED HEI %d ", hei);
  167. emit heightComputed( hei );
  168. return hei;
  169. }
  170. void KDTimeTableWidget::computeVerticalGrid()
  171. {
  172. // recompute the vertical grid
  173. // compute the vertical grid
  174. // if we have too much lines, hide them
  175. //tqDebug("computeVerticalGrid() ");
  176. int cw = myGanttView->myTimeHeader->myGridMinorWidth;
  177. int i = 0;
  178. int h ;
  179. if (pendingHeight > height() )
  180. h = pendingHeight;
  181. else
  182. h = height();
  183. int wid;
  184. if ( pendingWidth )
  185. wid = pendingWidth;
  186. else
  187. wid = width();
  188. KDCanvasLine* templine;
  189. KDCanvasRectangle* temprect;
  190. TQColor colcol;
  191. TQPen colPen;
  192. bool colorIterator = true;
  193. if (myGanttView->showMinorTicks()){//minor
  194. colPen.setWidth(cw);
  195. TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
  196. TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
  197. for ( ; itgrid.current(); ++itgrid ) {
  198. if (i < wid) {
  199. itgrid.current()->setPoints(i,0,i,h);
  200. itgrid.current()->show();
  201. if (myGanttView->myTimeHeader->getColumnColor(colcol,i,i+cw))
  202. {
  203. colPen.setColor(colcol);
  204. if (colorIterator)
  205. colorIterator = itcol.current();
  206. if (colorIterator)
  207. {/*
  208. itcol.current()->setPen(colPen);
  209. itcol.current()->setPoints(i+(cw/2),0,i+(cw/2),h);
  210. */
  211. itcol.current()->setPen( Qt::NoPen );
  212. itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
  213. itcol.current()->setSize(cw ,h );
  214. itcol.current()->move( i, 0 );
  215. itcol.current()->show();
  216. ++itcol;
  217. } else {
  218. /*
  219. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  220. templine->setPen(colPen);
  221. templine->setPoints(i+(cw/2),0,i+(cw/2),h);
  222. */
  223. temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  224. temprect->setPen( Qt::NoPen );
  225. temprect->setBrush( TQBrush( colcol, SolidPattern) );
  226. temprect->setSize(cw ,h );
  227. temprect->move( i, 0 );
  228. temprect->setZ(-20);
  229. temprect->show();
  230. columnColorList.append(temprect);
  231. }
  232. }
  233. i += cw;
  234. } else {
  235. itgrid.current()->hide();
  236. }
  237. }
  238. // create additional Lines for vertical grid
  239. for ( ;i < wid;i += cw) {
  240. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  241. templine->setPen(gridPen);
  242. templine->setPoints(i,0,i,h);
  243. templine->setZ(0);
  244. templine->show();
  245. verGridList.append(templine);
  246. if (myGanttView->myTimeHeader->getColumnColor(colcol,i,i+cw))
  247. {
  248. colPen.setColor(colcol);
  249. if (colorIterator)
  250. colorIterator = itcol.current();
  251. if (colorIterator)
  252. {/*
  253. itcol.current()->setPen(colPen);
  254. itcol.current()->setPoints(i+(cw/2),0,i+(cw/2),h);
  255. */
  256. itcol.current()->setPen( Qt::NoPen );
  257. itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
  258. itcol.current()->setSize(cw ,h );
  259. itcol.current()->move( i, 0 );
  260. itcol.current()->show();
  261. ++itcol;
  262. } else {
  263. temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  264. temprect->setPen( Qt::NoPen );
  265. temprect->setBrush( TQBrush( colcol, SolidPattern) );
  266. temprect->setSize(cw ,h );
  267. temprect->move( i, 0 );
  268. temprect->setZ(-20);
  269. temprect->show();
  270. columnColorList.append(temprect);
  271. /*
  272. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  273. templine->setPen(colPen);
  274. templine->setPoints(i+(cw/2),0,i+(cw/2),h);
  275. templine->setZ(-20);
  276. templine->show();
  277. columnColorList.append(templine);
  278. */
  279. }
  280. }
  281. }
  282. if (colorIterator)
  283. for ( ; itcol.current(); ++itcol )
  284. itcol.current()->hide();
  285. } else {//major
  286. if (myGanttView->showMajorTicks()) {
  287. TQValueList<int>::iterator intIt = myGanttView->myTimeHeader->majorTicks.begin();
  288. TQValueList<int>::iterator intItEnd = myGanttView->myTimeHeader->majorTicks.end();
  289. TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
  290. TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
  291. int left = 0;
  292. for ( ; itgrid.current(); ++itgrid ) {
  293. if (intIt != intItEnd) {
  294. left = (*intIt);
  295. ++intIt;
  296. itgrid.current()->setPoints(left,0,left,h);
  297. itgrid.current()->show();
  298. //int right = (*intIt);
  299. if ((*intIt))
  300. if (myGanttView->myTimeHeader->getColumnColor(colcol,left,(*intIt) ))
  301. {
  302. int mid = (-left+(*intIt));
  303. colPen.setColor(colcol);
  304. colPen.setWidth((*intIt)-left);
  305. if (colorIterator)
  306. colorIterator = itcol.current();
  307. if (colorIterator)
  308. {/*
  309. itcol.current()->setPen(colPen);
  310. itcol.current()->setPoints(i+mid,0,mid,h);
  311. */
  312. itcol.current()->setPen( Qt::NoPen );
  313. itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
  314. itcol.current()->setSize(mid ,h );
  315. itcol.current()->move( left, 0 );
  316. itcol.current()->show();
  317. ++itcol;
  318. } else {
  319. temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  320. temprect->setPen( Qt::NoPen );
  321. temprect->setBrush( TQBrush( colcol, SolidPattern) );
  322. temprect->setSize(mid,h );
  323. temprect->move( left, 0 );
  324. temprect->setZ(-20);
  325. temprect->show();
  326. columnColorList.append(temprect);
  327. /*
  328. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  329. templine->setPen(colPen);
  330. templine->setPoints(mid,0,i+mid,h);
  331. templine->setZ(-20);
  332. templine->show();
  333. columnColorList.append(templine);
  334. */
  335. }
  336. }
  337. } else {
  338. itgrid.current()->hide();
  339. }
  340. }
  341. KDCanvasLine* templine;
  342. // create additional Lines for vertical grid
  343. for ( ;intIt != intItEnd ;++intIt) {
  344. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  345. templine->setPen(gridPen);
  346. templine->setPoints((*intIt),0,(*intIt),h);
  347. templine->setZ(0);
  348. templine->show();
  349. verGridList.append(templine);
  350. if ((*intIt))
  351. if (myGanttView->myTimeHeader->getColumnColor(colcol,left,(*intIt)))
  352. {
  353. int mid = (-left+(*intIt));
  354. colPen.setColor(colcol);
  355. colPen.setWidth((*intIt)-left);
  356. if (colorIterator)
  357. colorIterator = itcol.current();
  358. if (colorIterator)
  359. {/*
  360. itcol.current()->setPen(colPen);
  361. itcol.current()->setPoints(i+mid,0,mid,h);
  362. */
  363. itcol.current()->setPen( Qt::NoPen );
  364. itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
  365. itcol.current()->setSize(mid ,h );
  366. itcol.current()->move( left, 0 );
  367. itcol.current()->show();
  368. ++itcol;
  369. } else {
  370. temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  371. temprect->setPen( Qt::NoPen );
  372. temprect->setBrush( TQBrush( colcol, SolidPattern) );
  373. temprect->setSize(mid ,h );
  374. temprect->move( left, 0 );
  375. temprect->setZ(-20);
  376. temprect->show();
  377. columnColorList.append(temprect);
  378. /*
  379. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  380. templine->setPen(colPen);
  381. templine->setPoints(mid,0,i+mid,h);
  382. templine->setZ(-20);
  383. templine->show();
  384. columnColorList.append(templine);
  385. */
  386. }
  387. }
  388. left = (*intIt);
  389. }
  390. if (colorIterator)
  391. for ( ; itcol.current(); ++itcol ) {
  392. itcol.current()->hide();
  393. }
  394. }
  395. else {
  396. //hideall
  397. TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
  398. for ( ; itgrid.current(); ++itgrid ) {
  399. itgrid.current()->hide();
  400. }
  401. TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
  402. for ( ; itcol.current(); ++itcol ) {
  403. itcol.current()->hide();
  404. }
  405. }
  406. }
  407. }
  408. void KDTimeTableWidget::computeHorizontalGrid()
  409. {
  410. // compute horizontal grid
  411. //tqDebug("computeHorizontalGrid() ");
  412. KDGanttViewItem* temp = myGanttView->firstChild();
  413. int wid;
  414. if ( pendingWidth )
  415. wid = pendingWidth;
  416. else
  417. wid = width();
  418. KDCanvasLine* templine;
  419. TQPtrListIterator<KDCanvasLine> ithor(horGridList);
  420. if ( ithor.current() ) {
  421. templine = ithor.current();
  422. ++ithor;
  423. } else {
  424. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  425. templine->setPen(gridPen);
  426. templine->setZ(0);
  427. horGridList.append(templine);
  428. }
  429. templine->setPoints(0,0,wid,0);
  430. templine->show();
  431. int posY;
  432. while ( temp ) {
  433. posY = temp->itemPos() + temp->height();
  434. if ( ithor.current() ) {
  435. templine = ithor.current();
  436. ++ithor;
  437. } else {
  438. //new vertical grid line
  439. templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
  440. templine->setPen(gridPen);
  441. templine->setZ(0);
  442. horGridList.append(templine);
  443. }
  444. if ( templine->endPoint() != TQPoint(wid,posY ))
  445. templine->setPoints(0,posY,wid,posY );
  446. if ( !templine->isVisible() )
  447. templine->show();
  448. //TQString ts = "asGroup";
  449. //if (!temp->displaySubitemsAsGroup() )
  450. // ts = " NOT asGroup";
  451. //tqDebug("temp name %s %s", temp->listViewText(0).latin1(), ts.latin1());
  452. temp = temp->itemBelow ();
  453. }
  454. while ( ithor.current() ) {
  455. if ( ithor.current()->isVisible() )
  456. ithor.current()->hide();
  457. ++ithor;
  458. }
  459. }
  460. void KDTimeTableWidget::computeDenseLines()
  461. {
  462. KDGanttViewItem* temp = myGanttView->firstChild();
  463. int wid;
  464. if ( pendingWidth )
  465. wid = pendingWidth;
  466. else
  467. wid = width();
  468. TQPtrListIterator<KDCanvasRectangle> ithordense(horDenseList);
  469. KDCanvasRectangle* denseLine;
  470. int tempDenseLineCount = 0;
  471. while ( temp ) {
  472. if ( temp->isVisible() ) {
  473. ++tempDenseLineCount;
  474. if ( tempDenseLineCount == denseLineCount ) {
  475. tempDenseLineCount = 0;
  476. if ( ithordense.current() ) {
  477. denseLine = ithordense.current();
  478. ++ithordense;
  479. } else {
  480. denseLine =new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  481. denseLine->setZ(-2);
  482. horDenseList.append( denseLine );
  483. }
  484. if ( denseLine->rect() != TQRect(0, temp->itemPos(),wid, temp->height()) ) {
  485. denseLine->move( 0, temp->itemPos() );
  486. denseLine->setSize( wid, temp->height());
  487. }
  488. if (denseLine->brush() != denseLineBrush ) {
  489. denseLine->setPen( TQPen( TQt::NoPen ) );
  490. denseLine->setBrush( denseLineBrush);
  491. }
  492. if (!denseLine->isVisible() )
  493. denseLine->show();
  494. } else {
  495. ;
  496. }
  497. }
  498. temp = temp->itemBelow ();
  499. }
  500. while ( ithordense.current() ) {
  501. if ( ithordense.current()->isVisible() ) {
  502. ithordense.current()->hide();
  503. }
  504. ++ithordense;
  505. }
  506. }
  507. void KDTimeTableWidget::computeShowNoInformation()
  508. {
  509. KDGanttViewItem* temp = myGanttView->firstChild();
  510. int wid;
  511. if ( pendingWidth )
  512. wid = pendingWidth;
  513. else
  514. wid = width();
  515. TQPtrListIterator<KDCanvasRectangle> itnoinfo(showNoInfoList);
  516. KDCanvasRectangle* noInfoLine;
  517. while ( temp ) {
  518. if ( temp->showNoInformation() ) {
  519. if ( itnoinfo.current() ) {
  520. noInfoLine = itnoinfo.current();
  521. ++itnoinfo;
  522. } else {
  523. noInfoLine =new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
  524. showNoInfoList.append( noInfoLine );
  525. noInfoLine->setZ(-1);
  526. }
  527. noInfoLine->move( 0, temp->itemPos() );
  528. noInfoLine->setSize( wid, temp->height());
  529. noInfoLine->setPen( TQPen( TQt::NoPen ) );
  530. noInfoLine->setBrush( noInfoLineBrush);
  531. noInfoLine->show();
  532. }
  533. temp = temp->itemBelow ();
  534. }
  535. while ( itnoinfo.current() ) {
  536. itnoinfo.current()->hide();
  537. ++itnoinfo;
  538. }
  539. }
  540. void KDTimeTableWidget::computeTaskLinks()
  541. {
  542. //compute and show tasklinks
  543. TQPtrListIterator<KDGanttViewTaskLink> it((myTaskLinkList));
  544. for ( ; it.current(); ++it ) {
  545. if (it.current()->isVisible())
  546. it.current()->showMe(true);
  547. else
  548. it.current()->showMe(false);
  549. }
  550. }
  551. // updateMyContent() can be blocked by blockUpdating( true ) or inc_blockUpdating()
  552. // updateMyContent() is blocked, if the GanttView is hidden after startup
  553. void KDTimeTableWidget::updateMyContent()
  554. {
  555. if ( flag_blockUpdating || int_blockUpdating ) {
  556. // tqDebug("KDTimeTableWidget::updateMyContent() blocked! ");
  557. return;
  558. }
  559. //tqDebug("KDTimeTableWidget::updateMyContent() ********************************* ");
  560. /*
  561. // debug output
  562. KDGanttViewItem* temp = myGanttView->firstChild();
  563. while (temp != 0) {
  564. temp->printinfo(" " );
  565. temp = temp->nextSibling();
  566. }
  567. */
  568. int hei = computeHeight();
  569. minimumHeight = hei;
  570. int viewport_hei = myGanttView->myCanvasView->viewport()->height();
  571. if ( viewport_hei > hei )
  572. hei = viewport_hei + 100;
  573. if ( myGanttView->myTimeHeader->registerStartTime() )
  574. return; // try again via timeheader computeTicks();
  575. if ( myGanttView->myTimeHeader->registerEndTime() )
  576. return; // try again via timeheader computeTicks();
  577. if ( hei > height() ) {
  578. if ( ! pendingWidth )
  579. pendingWidth = width();
  580. if ( pendingHeight < hei )
  581. pendingHeight = hei;
  582. }
  583. if (pendingHeight > hei )
  584. hei = pendingHeight;
  585. if (hei > maximumComputedGridHeight)
  586. {
  587. maximumComputedGridHeight = hei;
  588. // compute the background interval lines
  589. myGanttView->myTimeHeader->computeIntervals( hei );
  590. //computeQt::VerticalGrid and column color
  591. computeVerticalGrid();
  592. }
  593. computeTaskLinks();
  594. computeHorizontalGrid();
  595. computeDenseLines();
  596. computeShowNoInformation();
  597. //setAllChanged();
  598. update();
  599. if (pendingWidth && pendingHeight ) {
  600. resize( pendingWidth, pendingHeight );
  601. pendingWidth = 0;
  602. pendingHeight = 0;
  603. emit heightComputed( 0 );
  604. }
  605. pendingWidth = 0;
  606. pendingHeight = 0;
  607. //tqDebug("KDTimeTableWidget::updateMyContent() -------------------------");
  608. }
  609. // used for blocking recursive methods
  610. // e.g. KDGanttViewItem::setHighlight() and displaySubitemsAsGroup() == true
  611. void KDTimeTableWidget::inc_blockUpdating( )
  612. {
  613. ++ int_blockUpdating;
  614. }
  615. // used for blocking recursive methods
  616. void KDTimeTableWidget::dec_blockUpdating( )
  617. {
  618. -- int_blockUpdating;
  619. }
  620. // if false(i.e. unblock), sets int_blockUpdating to 0
  621. void KDTimeTableWidget::setBlockUpdating( bool block )
  622. {
  623. if ( !block )
  624. int_blockUpdating = 0;
  625. flag_blockUpdating = block;
  626. }
  627. bool KDTimeTableWidget::blockUpdating()
  628. {
  629. return flag_blockUpdating;
  630. }
  631. void KDTimeTableWidget::setShowTaskLinks( bool show )
  632. {
  633. taskLinksVisible = show;
  634. updateMyContent();
  635. }
  636. bool KDTimeTableWidget::showTaskLinks()
  637. {
  638. return taskLinksVisible;
  639. }
  640. void KDTimeTableWidget::setHorBackgroundLines( int count, TQBrush brush )
  641. {
  642. denseLineBrush = brush;
  643. denseLineCount = 0;
  644. if ( count > 1 )
  645. denseLineCount = count;
  646. }
  647. int KDTimeTableWidget::horBackgroundLines( TQBrush& brush )
  648. {
  649. brush = denseLineBrush;
  650. return denseLineCount;
  651. }
  652. int KDTimeTableWidget::getCoordX( TQDateTime dt ) {
  653. return myGanttView->myTimeHeader->getCoordX(dt);
  654. }
  655. /* ***************************************************************
  656. KDTimeHeaderWidget:: KDTimeHeaderWidget
  657. ***************************************************************** */
  658. KDTimeHeaderWidget:: KDTimeHeaderWidget( TQWidget* parent,KDGanttView* gant )
  659. : TQWidget (parent)
  660. {
  661. myToolTip = new KDTimeHeaderToolTip(this,this);
  662. mySizeHint = 0;
  663. myGanttView = gant;
  664. flagDoNotRecomputeAfterChange = true;
  665. TQDateTime start = (TQDateTime::currentDateTime ()).addSecs(-3600);
  666. setHorizonStart(start);
  667. setHorizonEnd( start.addSecs(3600*2));
  668. flagStartTimeSet = false;
  669. flagEndTimeSet = false;
  670. myCenterDateTime = TQDateTime::currentDateTime ();
  671. setScale(KDGanttView::Auto);
  672. //setScale(KDGanttView::Hour);
  673. myMaxScale = KDGanttView::Month;
  674. myMinScale = KDGanttView::Minute;
  675. myAutoScaleMinorTickcount = 100;
  676. setMajorScaleCount( 1 );
  677. setMinorScaleCount( 1);
  678. setMinimumColumnWidth( 5 );
  679. setYearFormat(KDGanttView::FourDigit );
  680. setHourFormat( KDGanttView::Hour_12 );
  681. myZoomFactor = 1.0;
  682. setWeekendBackgroundColor(TQColor(220,220,220) );
  683. setWeekendDays( 6, 7 );
  684. myGridMinorWidth = 0;
  685. myPopupMenu = new TQPopupMenu(this);
  686. TQPopupMenu * zoomPopupMenu = new TQPopupMenu(this);
  687. myPopupMenu->insertItem (i18n("Zoom"),zoomPopupMenu, 1);
  688. zoomPopupMenu->insertItem( i18n("Zoom to 100%"),this, TQT_SLOT(setSettings(int)),0 ,21,21 );
  689. zoomPopupMenu->insertItem( i18n("Zoom to Fit"),this, TQT_SLOT(setSettings(int)),0 ,20,20 );
  690. zoomPopupMenu->insertItem( i18n("Zoom In (x 2)"),this, TQT_SLOT(setSettings(int)),0 ,22,22 );
  691. zoomPopupMenu->insertItem( i18n("Zoom In (x 6)"),this, TQT_SLOT(setSettings(int)),0 ,24,24 );
  692. zoomPopupMenu->insertItem( i18n("Zoom In (x 12)"),this, TQT_SLOT(setSettings(int)),0 ,26,26 );
  693. zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/2)"),this, TQT_SLOT(setSettings(int)),0 ,23,23 );
  694. zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/6)"),this, TQT_SLOT(setSettings(int)),0 ,25,25 );
  695. zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/12)"),this, TQT_SLOT(setSettings(int)),0 ,27,27 );
  696. scalePopupMenu = new TQPopupMenu(this);
  697. myPopupMenu->insertItem (i18n("Scale"),scalePopupMenu, 2);
  698. scalePopupMenu->insertItem( i18n("Minute"),this, TQT_SLOT(setSettings(int)),0 ,1,1 );
  699. scalePopupMenu->insertItem( i18n("Hour"),this, TQT_SLOT(setSettings(int)),0 ,2,2 );
  700. scalePopupMenu->insertItem( i18n("Day"),this, TQT_SLOT(setSettings(int)),0 ,3,3 );
  701. scalePopupMenu->insertItem( i18n("Week"),this, TQT_SLOT(setSettings(int)),0 ,4,4 );
  702. scalePopupMenu->insertItem( i18n("Month"),this, TQT_SLOT(setSettings(int)),0 ,5,5 );
  703. scalePopupMenu->insertItem( i18n("Auto"),this, TQT_SLOT(setSettings(int)),0 ,6,6 );
  704. scalePopupMenu->setCheckable ( true );
  705. timePopupMenu = new TQPopupMenu(this);
  706. myPopupMenu->insertItem (i18n("Time Format"),timePopupMenu, 3);
  707. timePopupMenu->insertItem( i18n("24 Hour"),this, TQT_SLOT(setSettings(int)),0 ,40,40 );
  708. timePopupMenu->insertItem( i18n("12 PM Hour"),this, TQT_SLOT(setSettings(int)),0 ,41,41 );
  709. timePopupMenu->insertItem( i18n("24:00 Hour"),this, TQT_SLOT(setSettings(int)),0 ,42,42 );
  710. yearPopupMenu = new TQPopupMenu(this);
  711. myPopupMenu->insertItem (i18n("Year Format"),yearPopupMenu, 4);
  712. yearPopupMenu->insertItem( i18n("Four Digit"),this, TQT_SLOT(setSettings(int)),0 ,50,50 );
  713. yearPopupMenu->insertItem( i18n("Two Digit"),this, TQT_SLOT(setSettings(int)),0 ,51,51 );
  714. yearPopupMenu->insertItem( i18n("Two Digit Apostrophe"),this, TQT_SLOT(setSettings(int)),0 ,52,52 );
  715. yearPopupMenu->insertItem( i18n("No Date on Minute/Hour Scale"),this, TQT_SLOT(setSettings(int)),0 ,53,53 );
  716. gridPopupMenu = new TQPopupMenu(this);
  717. myPopupMenu->insertItem (i18n("Grid"),gridPopupMenu,5);
  718. gridPopupMenu->insertItem( i18n("Show Minor Grid"),this, TQT_SLOT(setSettings(int)),0 ,10,10 );
  719. gridPopupMenu->insertItem( i18n("Show Major Grid"),this, TQT_SLOT(setSettings(int)),0 ,11,11 );
  720. gridPopupMenu->insertItem( i18n("Show No Grid"),this, TQT_SLOT(setSettings(int)),0 ,12,12 );
  721. myPopupMenu->insertItem( i18n("Print"),this, TQT_SLOT(setSettings(int)),0 ,30,30 );
  722. connect(myPopupMenu, TQT_SIGNAL ( aboutToShow () ) , this, TQT_SLOT( preparePopupMenu() )) ;
  723. flagZoomToFit = false;
  724. setShowMinorTicks( true );
  725. myRealEnd = myHorizonEnd;
  726. myRealStart = myHorizonStart;
  727. autoComputeTimeLine = true;
  728. flagDoNotRecomputeAfterChange = false;
  729. flagDoNotRepaintAfterChange = false;
  730. setShowPopupMenu(false,false,false,false,false,false,false);
  731. for (int j =1;j<8;++j)
  732. weekdayColor[j] = TQt::white;
  733. myMinimumWidth = 0;
  734. mouseDown = false;
  735. beginMouseDown = 0;
  736. endMouseDown = 0;
  737. }
  738. KDTimeHeaderWidget::~KDTimeHeaderWidget()
  739. {
  740. delete myToolTip;
  741. }
  742. void KDTimeHeaderWidget::preparePopupMenu()
  743. {
  744. myPopupMenu->setItemVisible ( 1, flagShowZoom );
  745. myPopupMenu->setItemVisible ( 2, flagShowScale );
  746. myPopupMenu->setItemVisible ( 3, flagShowTime );
  747. myPopupMenu->setItemVisible ( 4, flagShowYear );
  748. myPopupMenu->setItemVisible ( 5, flagShowGrid);
  749. myPopupMenu->setItemVisible ( 30, flagShowPrint );
  750. if (flagZoomToFit)
  751. myPopupMenu->changeItem( 1, i18n("Zoom (Fit)"));
  752. else
  753. myPopupMenu->changeItem( 1, i18n("Zoom (%1)").arg( TQString::number( zoomFactor(), 'f',3) ) );
  754. int i = 0;
  755. int id;
  756. while ( ( id = scalePopupMenu->idAt( i++ )) >= 0 ) {
  757. scalePopupMenu->setItemChecked ( id, false );
  758. }
  759. scalePopupMenu->setItemChecked ( scalePopupMenu->idAt ( (int)( scale()) ), true );
  760. i = 0;
  761. while ( ( id = timePopupMenu->idAt( i++ )) >= 0 ) {
  762. timePopupMenu->setItemChecked ( id, false );
  763. }
  764. timePopupMenu->setItemChecked ( timePopupMenu->idAt ( (int)( hourFormat()) ), true );
  765. i = 0;
  766. while ( ( id = yearPopupMenu->idAt( i++ )) >= 0 ) {
  767. yearPopupMenu->setItemChecked ( id, false );
  768. }
  769. yearPopupMenu->setItemChecked ( yearPopupMenu->idAt ( (int)( yearFormat()) ), true );
  770. i = 0;
  771. while ( ( id = gridPopupMenu->idAt( i++ )) >= 0 ) {
  772. gridPopupMenu->setItemChecked ( id, false );
  773. }
  774. gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 0 ), showMinorTicks() );
  775. gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 1 ), showMajorTicks() );
  776. gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 2 ),
  777. !(showMajorTicks() || showMinorTicks()) );
  778. }
  779. TQString KDTimeHeaderWidget::getToolTipText(TQPoint p)
  780. {
  781. return TDEGlobal::locale()->formatDateTime(getDateTimeForIndex(p.x()));
  782. }
  783. void KDTimeHeaderWidget::addTickRight( int num )
  784. {
  785. int secs = ((num*getTickTime())-30);
  786. setHorizonEnd(getDateTimeForIndex(width()).addSecs(secs));
  787. //tqApp->processEvents();
  788. }
  789. void KDTimeHeaderWidget::addTickLeft( int num )
  790. {
  791. int secs = ((num*getTickTime())-30);
  792. setHorizonStart(getDateTimeForIndex(0).addSecs(-secs));
  793. //tqApp->processEvents();
  794. }
  795. // the time in secs of one minor grid tick
  796. int KDTimeHeaderWidget::getTickTime()
  797. {
  798. return getDateTimeForIndex(0).secsTo(getDateTimeForIndex(myGridMinorWidth));
  799. }
  800. void KDTimeHeaderWidget::checkWidth( int wid )
  801. {
  802. // we have to set the minimum width one pixel higher than the
  803. // viewport width of the canvas view in order to
  804. // avoid that the horiz. scrollbar of the canvasview is hidden
  805. myMinimumWidth = wid + 1;
  806. if ( myMinimumWidth > width() ||
  807. ( myMinimumWidth > mySizeHint &&
  808. myMinimumWidth < (width() - myGridMinorWidth )) )
  809. computeTicks();
  810. // Update (horizontal) scrollbar,
  811. // We probably come from an external resize and then we must
  812. // calculate on basis of myCanvasView.
  813. // (NOTE: we have disconnected the auto TQScrollView scrollbar update)
  814. if (myGanttView && myGanttView->myCanvasView)
  815. myGanttView->myCanvasView->updateScrollBars();
  816. }
  817. bool KDTimeHeaderWidget::registerStartTime()
  818. {
  819. TQListViewItemIterator it( myGanttView->myListView );
  820. if (!flagStartTimeSet) {
  821. TQDateTime temp , time;
  822. KDGanttViewItem* item;
  823. bool setNewTime = false;
  824. item = (KDGanttViewItem*)myGanttView->myListView->firstChild();
  825. if ( item ) {
  826. temp = item->startTime();
  827. time = temp;
  828. // while ( item != 0)
  829. for ( ; it.current(); ++it ) {
  830. item = ( KDGanttViewItem* )it.current();
  831. if (item->isVisibleInGanttView) {
  832. if ( !setNewTime )
  833. temp = item->startTime();
  834. switch( item->type() ) {
  835. case KDGanttViewItem::Event:
  836. time = ((KDGanttViewEventItem*)item)->leadTime();
  837. setNewTime = true;
  838. break;
  839. case KDGanttViewItem::Summary:
  840. case KDGanttViewItem::Task:
  841. time = item->startTime();
  842. setNewTime = true;
  843. break;
  844. default:
  845. time = temp;
  846. }
  847. if ( time < temp) {
  848. temp = time ;
  849. }
  850. }
  851. }
  852. if ( setNewTime )
  853. if ( myHorizonStart != temp) {
  854. myHorizonStart = temp;
  855. computeTicks();
  856. return true;
  857. }
  858. }
  859. }
  860. return false;
  861. }
  862. bool KDTimeHeaderWidget::registerEndTime()
  863. {
  864. if (!flagEndTimeSet) {
  865. TQDateTime temp , time;
  866. KDGanttViewItem* item;
  867. bool setNewTime = false;
  868. item = (KDGanttViewItem*)myGanttView->myListView->firstChild();
  869. if ( item ) {
  870. temp = item->startTime();
  871. time = temp;
  872. TQListViewItemIterator it( myGanttView->myListView );
  873. for ( ; it.current(); ++it ) {
  874. item = ( KDGanttViewItem* )it.current();
  875. if (item->isVisibleInGanttView) {
  876. if ( !setNewTime )
  877. temp = item->startTime();
  878. switch( item->type() ) {
  879. case KDGanttViewItem::Event:
  880. time = ((KDGanttViewEventItem*)item)->startTime();
  881. setNewTime = true;
  882. break;
  883. case KDGanttViewItem::Summary:
  884. time = item->endTime();
  885. if ( time < ((KDGanttViewSummaryItem*)item)->actualEndTime())
  886. time = ((KDGanttViewSummaryItem*)item)->actualEndTime();
  887. setNewTime = true;
  888. break;
  889. case KDGanttViewItem::Task:
  890. time = item->endTime();
  891. setNewTime = true;
  892. break;
  893. default:
  894. time = temp;
  895. }
  896. if ( time > temp)
  897. temp = time ;
  898. }
  899. }
  900. if ( setNewTime )
  901. if (myHorizonEnd != temp ) {
  902. myHorizonEnd = temp;
  903. computeTicks();
  904. return true;
  905. }
  906. }
  907. }
  908. return false;
  909. }
  910. void KDTimeHeaderWidget::setShowPopupMenu( bool show,
  911. bool showZoom,
  912. bool showScale,
  913. bool showTime,
  914. bool showYear,
  915. bool showGrid,
  916. bool showPrint)
  917. {
  918. flagShowPopupMenu = show;
  919. flagShowZoom = showZoom;
  920. flagShowScale = showScale;
  921. flagShowTime = showTime;
  922. flagShowYear = showYear;
  923. flagShowGrid = showGrid;
  924. flagShowPrint = showPrint;
  925. }
  926. bool KDTimeHeaderWidget::showPopupMenu() const
  927. {
  928. return flagShowPopupMenu;
  929. }
  930. void KDTimeHeaderWidget::setSettings(int i)
  931. {
  932. switch (i) {
  933. case 1:
  934. setScale(KDGanttView::Minute );
  935. break;
  936. case 2:
  937. setScale(KDGanttView::Hour );
  938. break;
  939. case 3:
  940. setScale(KDGanttView::Day );
  941. break;
  942. case 4:
  943. setScale(KDGanttView::Week );
  944. break;
  945. case 5:
  946. setScale(KDGanttView::Month );
  947. break;
  948. case 6:
  949. setScale(KDGanttView::Auto );
  950. break;
  951. case 10:
  952. setShowMinorTicks( true );
  953. break;
  954. case 11:
  955. setShowMajorTicks( true );{
  956. }
  957. break;
  958. case 12:
  959. setShowMajorTicks( false );
  960. setShowMinorTicks( false);
  961. break;
  962. case 20:
  963. zoomToFit();
  964. break;
  965. case 21:
  966. zoom(1.0);
  967. break;
  968. case 22:
  969. zoom(2.0,false);
  970. break;
  971. case 23:
  972. zoom(0.5,false);
  973. break;
  974. case 24:
  975. zoom(6.0,false);
  976. break;
  977. case 25:
  978. zoom(0.16666,false);
  979. break;
  980. case 26:
  981. zoom(12.0,false);
  982. break;
  983. case 27:
  984. zoom(0.08333,false);
  985. break;
  986. case 30:
  987. myGanttView->print();
  988. break;
  989. case 40:
  990. case 41:
  991. case 42:
  992. setHourFormat( (KDGanttView::HourFormat) (i - 40) );
  993. break;
  994. case 50:
  995. case 51:
  996. case 52:
  997. case 53:
  998. setYearFormat( (KDGanttView::YearFormat) ( i - 50) );
  999. break;
  1000. case 60:
  1001. break;
  1002. case 61:
  1003. break;
  1004. case 62:
  1005. break;
  1006. case 63:
  1007. break;
  1008. case 64:
  1009. break;
  1010. }
  1011. // myGanttView->myTimeTable->updateMyContent();
  1012. }
  1013. void KDTimeHeaderWidget::zoomToFit()
  1014. {
  1015. flagZoomToFit = true;
  1016. computeTicks();
  1017. // Since we have disconnected autoupdate of scrollbars, we must do it ourselves
  1018. if (myGanttView && myGanttView->myCanvasView)
  1019. myGanttView->myCanvasView->updateScrollBars();
  1020. }
  1021. double KDTimeHeaderWidget::zoomFactor()
  1022. {
  1023. return myZoomFactor;
  1024. }
  1025. double KDTimeHeaderWidget::secsFromTo( TQDateTime begin, TQDateTime end )
  1026. {
  1027. TQDateTime temp;
  1028. double secs, days;
  1029. days = begin.daysTo(end);
  1030. temp = begin.addDays((int) days);
  1031. secs = temp.secsTo(end);
  1032. secs += days * 86400.0;
  1033. return secs;
  1034. }
  1035. void KDTimeHeaderWidget::zoomToSelection( TQDateTime start, TQDateTime end)
  1036. {
  1037. if (start < myHorizonStart) {
  1038. myHorizonStart = start;
  1039. flagStartTimeSet = true;
  1040. //tqDebug("myHorizonStart reset");
  1041. }
  1042. if (end > myHorizonEnd) {
  1043. myHorizonEnd = end;
  1044. flagEndTimeSet = true;
  1045. //tqDebug("myHorizonEnd reset ");
  1046. }
  1047. flagDoNotRepaintAfterChange = true;//avoid flicker
  1048. zoom(1.0); // set to 100%
  1049. int viewWid = myGanttView->myCanvasView->viewport()->width();
  1050. int timeWid = getCoordX(end)-getCoordX(start);
  1051. double fac;
  1052. fac = ( (double)viewWid)/((double) timeWid );
  1053. zoom (fac);
  1054. timeWid = getCoordX(end)-getCoordX(start);
  1055. int count = 0;
  1056. int lastScaleCount = 0;
  1057. while (timeWid >viewWid || ( ( myRealMinorScaleCount != lastScaleCount) && timeWid*2 < viewWid ) ) {
  1058. lastScaleCount = myRealMinorScaleCount;
  1059. fac = (fac * (double)viewWid)/(double)timeWid;
  1060. zoom (fac);
  1061. timeWid = getCoordX(end)-getCoordX(start);
  1062. if ( count++ > 10 ) {
  1063. //tqDebug("Exiting while loop in zoomToSelection ");
  1064. break;
  1065. }
  1066. }
  1067. flagDoNotRepaintAfterChange = false;
  1068. updateTimeTable();
  1069. repaint();
  1070. moveTimeLineTo((getCoordX(start)-(viewWid-timeWid)/2));
  1071. // Since we have disconnected autoupdate of scrollbars, we must do it ourselves
  1072. if (myGanttView && myGanttView->myCanvasView)
  1073. myGanttView->myCanvasView->updateScrollBars();
  1074. }
  1075. void KDTimeHeaderWidget::moveTimeLineTo(int X)
  1076. {
  1077. int Y = myGanttView->myCanvasView->contentsY ();
  1078. myGanttView->myCanvasView->setContentsPos (X, Y );
  1079. }
  1080. void KDTimeHeaderWidget::zoom(double factor, bool absolute)
  1081. {
  1082. flagZoomToFit = false;
  1083. if ( factor < 0.000001 ) {
  1084. tqDebug("KDGanttView::zoom() : Zoom factor to low. Nothing zoomed. ");
  1085. return;
  1086. }
  1087. double newZoom;
  1088. if (absolute)
  1089. newZoom = factor;
  1090. else
  1091. newZoom = myZoomFactor * factor;
  1092. double relativeZoom;
  1093. relativeZoom = newZoom / myZoomFactor;
  1094. //tqDebug("zooming relative %f ", relativeZoom);
  1095. //tqDebug("zooming absolute %f ", newZoom);
  1096. int viewWid = myGanttView->myCanvasView->viewport()->width();
  1097. if ( width() * relativeZoom < viewWid && ( newZoom > 1.01 || newZoom < 0.99 ) ) {
  1098. tqDebug("KDGanttView::zoom() : Zoom factor to low for current horizon. ");
  1099. // tqDebug("zooming relative %f, zooming absolute %f, viewWidth %d width %d ", relativeZoom, newZoom, viewWid, width() );
  1100. return;
  1101. }
  1102. myZoomFactor = newZoom;
  1103. computeTicks();
  1104. // Since we have disconnected autoupdate of scrollbars, we must do it ourselves
  1105. if (myGanttView && myGanttView->myCanvasView)
  1106. myGanttView->myCanvasView->updateScrollBars();
  1107. }
  1108. /*!
  1109. Sets the start of the horizon of the Gantt chart. If \a start is
  1110. null, the horizon start is computed automatically.
  1111. \param start the start of the horizon
  1112. \sa horizonStart()
  1113. */
  1114. void KDTimeHeaderWidget::setHorizonStart( const TQDateTime& start )
  1115. {
  1116. myHorizonStart = start;
  1117. flagStartTimeSet = true;
  1118. computeTicks();
  1119. }
  1120. /*!
  1121. Returns the start of the horizon of the Gantt chart.
  1122. \return the start of the horizon of the Gantt chart
  1123. \sa setHorizonStart()
  1124. */
  1125. TQDateTime KDTimeHeaderWidget::horizonStart() const
  1126. {
  1127. return myHorizonStart;
  1128. }
  1129. /*!
  1130. Sets the end of the horizon of the Gantt chart. If \a end is
  1131. null, the horizon end is computed automatically.
  1132. \param end the end of the horizon
  1133. \sa setHorizonEnd()
  1134. */
  1135. void KDTimeHeaderWidget::setHorizonEnd( const TQDateTime& start )
  1136. {
  1137. myHorizonEnd = start;
  1138. flagEndTimeSet = true;
  1139. computeTicks();
  1140. }
  1141. /*!
  1142. Returns the end of the horizon of the Gantt chart.
  1143. \return the end of the horizon of the Gantt chart
  1144. \sa setHorizonEnd()
  1145. */
  1146. TQDateTime KDTimeHeaderWidget::horizonEnd() const
  1147. {
  1148. return myHorizonEnd;
  1149. }
  1150. /*!
  1151. Configures the unit of the lower scale of the header. The higher
  1152. unit is computed automatically.
  1153. Resets the zoomng factor to 1 (i.e. 100%).
  1154. \param unit the unit of the lower scale of the header.
  1155. \sa scale()
  1156. */
  1157. void KDTimeHeaderWidget::setScale(Scale unit )
  1158. {
  1159. myScale = unit;
  1160. myZoomFactor = 1.0;
  1161. computeTicks();
  1162. // Since we have disconnected autoupdate of scrollbars, we must do it ourselves
  1163. if (myGanttView && myGanttView->myCanvasView)
  1164. myGanttView->myCanvasView->updateScrollBars();
  1165. }
  1166. /*!
  1167. Returns the unit of the lower scale of the header.
  1168. \return the unit of the lower scale of the header.
  1169. \sa setScale()
  1170. */
  1171. KDTimeHeaderWidget::Scale KDTimeHeaderWidget::scale() const
  1172. {
  1173. return myScale;
  1174. }
  1175. /*!
  1176. Sets the maximal allowed time scale of the lower scale of the header.
  1177. \param unit the unit of the lower scale of the header.
  1178. \sa scale()
  1179. */
  1180. void KDTimeHeaderWidget::setMaximumScale( Scale unit )
  1181. {
  1182. myMaxScale = unit;
  1183. computeTicks();
  1184. }
  1185. /*!
  1186. Returns the maximal allowed time scale of the lower scale of the header.
  1187. \return the unit of the lower scale of the header.
  1188. \sa setScale()
  1189. */
  1190. KDTimeHeaderWidget::Scale KDTimeHeaderWidget::maximumScale() const
  1191. {
  1192. return myMaxScale;
  1193. }
  1194. /*!
  1195. Sets the minimal allowed time scale of the lower scale of the header.
  1196. \param unit the unit of the lower scale of the header.
  1197. \sa scale()
  1198. */
  1199. void KDTimeHeaderWidget::setMinimumScale( Scale unit )
  1200. {
  1201. myMinScale = unit;
  1202. computeTicks();
  1203. }
  1204. /*!
  1205. Returns the minimal allowed time scale of the lower scale of the header.
  1206. \return the unit of the lower scale of the header.
  1207. \sa setScale()
  1208. */
  1209. KDTimeHeaderWidget::Scale KDTimeHeaderWidget::minimumScale() const
  1210. {
  1211. return myMinScale;
  1212. }
  1213. /*!
  1214. Sets the minimum width a column needs to have. If the size of the
  1215. Gantt chart and the scale would make it necessary to go below this
  1216. limit otherwise, the chart will automatically be made less exact.
  1217. \param width the minimum column width
  1218. \sa minimumColumnWidth()
  1219. */
  1220. void KDTimeHeaderWidget::setMinimumColumnWidth( int width )
  1221. {
  1222. myMinimumColumWidth = width;
  1223. computeTicks();
  1224. }
  1225. /*!
  1226. Returns the minimum width a column needs to have.
  1227. \return the column minimum width
  1228. \sa setMinimumColumnWidth()
  1229. */
  1230. int KDTimeHeaderWidget::minimumColumnWidth() const
  1231. {
  1232. return myMinimumColumWidth;
  1233. }
  1234. /*!
  1235. Specifies the format in which to display years. If no years are
  1236. shown, this method has no effect.
  1237. \param format the year format
  1238. \sa yearFormat(), setHourFormat(), hourFormat()
  1239. */
  1240. void KDTimeHeaderWidget::setYearFormat( YearFormat format )
  1241. {
  1242. myYearFormat = format;
  1243. computeTicks();
  1244. }
  1245. /*!
  1246. Returns the format in which to display years.
  1247. \return the year format
  1248. \sa setYearFormat(), setHourFormat(), hourFormat()
  1249. */
  1250. KDTimeHeaderWidget::YearFormat KDTimeHeaderWidget::yearFormat() const
  1251. {
  1252. return myYearFormat;
  1253. }
  1254. /*!
  1255. Specifies the format in which to display hours. If no hours are
  1256. shown, this method has no effect.
  1257. \param format the hour format
  1258. \sa hourFormat(), setYearFormat(), yearFormat()
  1259. */
  1260. void KDTimeHeaderWidget::setHourFormat( HourFormat format )
  1261. {
  1262. myHourFormat = format;
  1263. computeTicks();
  1264. }
  1265. /*!
  1266. Returns the format in which to display hours.
  1267. \return the hour format
  1268. \sa setHourFormat(), setYearFormat(), yearFormat()
  1269. */
  1270. KDTimeHeaderWidget::HourFormat KDTimeHeaderWidget::hourFormat() const
  1271. {
  1272. return myHourFormat;
  1273. }
  1274. /*!
  1275. Specifies whether ticks should be shown on the major scale.
  1276. \param show true in order to show ticks, false in order to hide them
  1277. \sa showMajorTicks(), setShowMinorTicks(), showMinorTicks()
  1278. */
  1279. void KDTimeHeaderWidget::setShowMajorTicks( bool show )
  1280. {
  1281. flagShowMajorTicks = show;
  1282. if (show) {
  1283. setShowMinorTicks(false);
  1284. }
  1285. updateTimeTable();
  1286. }
  1287. /*!
  1288. Returns whether ticks are shown on the major scale.
  1289. \return true if ticks are shown on the major scale
  1290. \sa setShowMajorTicks(), setShowMinorTicks(), showMinorTicks()
  1291. */
  1292. bool KDTimeHeaderWidget::showMajorTicks() const
  1293. {
  1294. return flagShowMajorTicks;
  1295. }
  1296. /*!
  1297. Specifies whether ticks should be shown on the minor scale.
  1298. \param show true in order to show ticks, false in order to hide them
  1299. \sa showMinorTicks(), setShowMajorTicks(), showMajorTicks()
  1300. */
  1301. void KDTimeHeaderWidget::setShowMinorTicks( bool show )
  1302. {
  1303. flagShowMinorTicks = show;
  1304. if (show)
  1305. setShowMajorTicks(false );
  1306. //repaintMe();
  1307. updateTimeTable();
  1308. }
  1309. /*!
  1310. Returns whether ticks are shown on the minor scale.
  1311. \return true if ticks are shown on the minor scale
  1312. \sa setShowMinorTicks(), setShowMajorTicks(), showMajorTicks()
  1313. */
  1314. bool KDTimeHeaderWidget::showMinorTicks() const
  1315. {
  1316. return flagShowMinorTicks;
  1317. }
  1318. /*!
  1319. Sets the background color for the column closest to \a column.
  1320. \param column the column to set the background color for
  1321. \param color the background color
  1322. \sa columnBackgroundColor(), setWeekendBackgroundColor(),
  1323. weekendBackgroundColor()
  1324. */
  1325. void KDTimeHeaderWidget::setColumnBackgroundColor( const TQDateTime& column,
  1326. const TQColor& color,
  1327. Scale mini, Scale maxi )
  1328. {
  1329. ColumnColorList::iterator it;
  1330. for ( it = ccList.begin(); it != ccList.end(); ++it ) {
  1331. if ((*it).datetime == column) {
  1332. (*it).color = color;
  1333. (*it).minScaleView = mini;
  1334. (*it).maxScaleView = maxi;
  1335. return;
  1336. }
  1337. }
  1338. DateTimeColor newItem;
  1339. newItem.datetime = column;
  1340. newItem.color = color;
  1341. newItem.minScaleView = mini;
  1342. newItem.maxScaleView = maxi;
  1343. ccList.append(newItem);
  1344. updateTimeTable();
  1345. }
  1346. void KDTimeHeaderWidget::computeIntervals( int height )
  1347. {
  1348. IntervalColorList::iterator it;
  1349. int left, right;
  1350. for ( it = icList.begin(); it != icList.end(); ++it ) {
  1351. if ( (*it).minScaleView <= myRealScale && (*it).maxScaleView >= myRealScale ) {
  1352. left = getCoordX((*it).datetime);
  1353. right = getCoordX((*it).end);
  1354. if ( right == left )
  1355. ++right;
  1356. (*it).canvasRect->setPen( Qt::NoPen );
  1357. (*it).canvasRect->setBrush( TQBrush( (*it).color, SolidPattern) );
  1358. (*it).canvasRect->setSize( right - left ,height );
  1359. (*it).canvasRect->move( left,0 );
  1360. (*it).canvasRect->show();
  1361. } else {
  1362. (*it).canvasRect->hide();
  1363. /*
  1364. (*it).canvasLine->setPen( TQPen( (*it).color, right - left ) );
  1365. (*it).canvasLine->setPoints( mid ,0 ,mid ,height );
  1366. (*it).canvasLine->show();
  1367. } else {
  1368. (*it).canvasLine->hide();
  1369. */
  1370. }
  1371. }
  1372. }
  1373. bool KDTimeHeaderWidget::changeBackgroundInterval( const TQDateTime& oldstart,
  1374. const TQDateTime& oldend,
  1375. const TQDateTime& newstart,
  1376. const TQDateTime& newend )
  1377. {
  1378. IntervalColorList::iterator it;
  1379. for ( it = icList.begin(); it != icList.end(); ++it ) {
  1380. if ((*it).datetime == oldstart && (*it).end == oldend ) {
  1381. IntervalColorList::iterator it2;
  1382. for ( it2 = icList.begin(); it2 != icList.end(); ++it2 ) {
  1383. if ((*it2).datetime == newstart && (*it2).end == newend )
  1384. return false;
  1385. }
  1386. (*it).datetime = newstart;
  1387. (*it).end = newend;
  1388. updateTimeTable();
  1389. return true;
  1390. }
  1391. }
  1392. return false;
  1393. }
  1394. bool KDTimeHeaderWidget::deleteBackgroundInterval( const TQDateTime& start,
  1395. const TQDateTime& end)
  1396. {
  1397. IntervalColorList::iterator it;
  1398. for ( it = icList.begin(); it != icList.end(); ++it ) {
  1399. if ((*it).datetime == start && (*it).end == end ) {
  1400. //delete (*it).canvasLine;
  1401. delete (*it).canvasRect;
  1402. icList.remove(it);
  1403. updateTimeTable();
  1404. return true;
  1405. }
  1406. }
  1407. return false;
  1408. }
  1409. void KDTimeHeaderWidget::setIntervalBackgroundColor( const TQDateTime& start,
  1410. const TQDateTime& end,
  1411. const TQColor& color,
  1412. Scale mini ,
  1413. Scale maxi )
  1414. {
  1415. IntervalColorList::iterator it;
  1416. for ( it = icList.begin(); it != icList.end(); ++it ) {
  1417. if ((*it).datetime == start && (*it).end == end ) {
  1418. (*it).color = color;
  1419. (*it).minScaleView = mini;
  1420. (*it).maxScaleView = maxi;
  1421. return;
  1422. }
  1423. }
  1424. DateTimeColor newItem;
  1425. if ( start <= end ) {
  1426. newItem.datetime = start;
  1427. newItem.end = end;
  1428. } else {
  1429. newItem.datetime = end;
  1430. newItem.end = start;
  1431. }
  1432. newItem.color = color;
  1433. newItem.minScaleView = mini;
  1434. newItem.maxScaleView = maxi;
  1435. //newItem.canvasLine = new KDCanvasLine(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
  1436. newItem.canvasRect = new KDCanvasRectangle(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
  1437. newItem.canvasRect->setZ(-19);
  1438. icList.append(newItem);
  1439. updateTimeTable();
  1440. }
  1441. void KDTimeHeaderWidget::clearBackgroundColor()
  1442. {
  1443. IntervalColorList::iterator itic;
  1444. for ( itic = icList.begin(); itic != icList.end(); ++itic ) {
  1445. delete (*itic).canvasRect;
  1446. }
  1447. ccList.clear();
  1448. icList.clear();
  1449. updateTimeTable();
  1450. }
  1451. TQDateTime KDTimeHeaderWidget::getDateTimeForIndex(int X, bool local )
  1452. {
  1453. int coordX = X;
  1454. if ( !local ) {
  1455. TQPoint p = TQPoint ( X, 1 );
  1456. coordX = myGanttView->myTimeHeaderScroll->viewportToContents(myGanttView->myTimeHeaderScroll->mapFromGlobal( p )).x();
  1457. }
  1458. double secs = (secsFromTo( myRealStart, myRealEnd ) * ((double)coordX))/(double)width();
  1459. double days = secs/86400.0;
  1460. secs = secs - ( ((int) days) *86400.0 );
  1461. return (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
  1462. }
  1463. //FIXME: This doesn't work quite intuitively (imho) when scale is day
  1464. // and each column containes more than 1 day:
  1465. // 1) If a column includes a weekend day, the whole column gets weekend color,
  1466. // 2) If a column includes 7 days, either *all* columns get weekend color, or
  1467. // *none* get weekend color (haven't figured out why)
  1468. // Proposal: Only use weekend color if the whole column is a weekend.
  1469. // Alt: Color the area that actually is the weekend.
  1470. bool KDTimeHeaderWidget::getColumnColor(TQColor& col,int coordLow, int coordHigh)
  1471. {
  1472. if (!flagShowMajorTicks && !flagShowMinorTicks)
  1473. return false;
  1474. TQDateTime start,end;
  1475. start = getDateTimeForIndex(coordLow);
  1476. end = getDateTimeForIndex(coordHigh).addSecs(-1);
  1477. Scale tempScale = myRealScale;
  1478. if (flagShowMajorTicks)
  1479. switch (myRealScale)
  1480. {
  1481. case KDGanttView::Minute: tempScale = KDGanttView::Hour; break;
  1482. case KDGanttView::Hour: tempScale = KDGanttView::Day ; break;
  1483. case KDGanttView::Day: tempScale = KDGanttView::Week ; break;
  1484. case KDGanttView::Week: tempScale = KDGanttView::Month ; break;
  1485. case KDGanttView::Month: return false ; break;
  1486. case KDGanttView::Auto: return false ; break;
  1487. }
  1488. //check defined column color
  1489. ColumnColorList::iterator it;
  1490. for ( it = ccList.begin(); it != ccList.end(); ++it ) {
  1491. if ((*it).datetime >= start && (*it).datetime <= end) {
  1492. if (tempScale >= (*it).minScaleView && tempScale <= (*it).maxScaleView ) {
  1493. col = (*it).color;
  1494. return true;
  1495. }
  1496. }
  1497. }
  1498. if (tempScale > KDGanttView::Day) return false;
  1499. start = getDateTimeForIndex((coordLow+coordHigh)/2);
  1500. int day = start.date().dayOfWeek ();
  1501. //checkweekdaycolor
  1502. if (weekdayColor[day] != TQt::white) {
  1503. col = weekdayColor[day];
  1504. return true;
  1505. }
  1506. //checkweekendcolor
  1507. int endday = myWeekendDaysEnd;
  1508. col = myWeekendBackgroundColor;
  1509. if (myWeekendDaysStart > myWeekendDaysEnd)
  1510. endday +=7;
  1511. if (day >= myWeekendDaysStart && day <= endday) {
  1512. return true;
  1513. } else {
  1514. if (day+7 >= myWeekendDaysStart && day+7 <= endday) {
  1515. return true;
  1516. }
  1517. }
  1518. return false;
  1519. }
  1520. /*!
  1521. Returns the background color for the column closes to \a column.
  1522. \param column the column to query the background color for
  1523. \return the background color of the specified column
  1524. \sa setColumnBackgroundColor(), setWeekendBackgroundColor(),
  1525. weekendBackgroundColor()
  1526. */
  1527. TQColor KDTimeHeaderWidget::columnBackgroundColor( const TQDateTime& column ) const
  1528. {
  1529. TQColor c;
  1530. c = white;
  1531. ColumnColorList::const_iterator ite;
  1532. for ( ite = ccList.begin(); ite != ccList.end(); ++ite ) {
  1533. if ((*ite).datetime == column) {
  1534. c = (*ite).color;
  1535. }
  1536. }
  1537. return c;
  1538. }
  1539. /*!
  1540. Specifies the background color for weekend days. If no individual
  1541. days are visible on the Gantt chart, this method has no visible
  1542. effect.
  1543. \param color the background color to use for weekend days.
  1544. \sa weekendBackgroundColor(), setWeekendDays(), weekendDays()
  1545. */
  1546. void KDTimeHeaderWidget::setWeekendBackgroundColor( const TQColor& color )
  1547. {
  1548. myWeekendBackgroundColor = color ;
  1549. updateTimeTable();
  1550. }
  1551. /*!
  1552. Returns the background color for weekend days.
  1553. \return the background color for weekend days
  1554. \sa setWeekendBackgroundColor(), setWeekendDays(), weekendDays()
  1555. */
  1556. TQColor KDTimeHeaderWidget::weekendBackgroundColor() const
  1557. {
  1558. return myWeekendBackgroundColor;
  1559. }
  1560. /*!
  1561. Specifies the background color for week days. If no individual
  1562. days are visible on the Gantt chart, this method has no visible
  1563. effect. The days are specified as an interval of integer values
  1564. where 1 means Monday and 7 means Sunday.
  1565. \param color the background color to use for weekend days.
  1566. \param weekday the day of the week (Monday = 1, Sunday = 7)
  1567. \sa weekendBackgroundColor(), setWeekendDays(), weekendDays()
  1568. */
  1569. void KDTimeHeaderWidget::setWeekdayBackgroundColor( const TQColor& color, int weekday )
  1570. {
  1571. weekdayColor[weekday] = color;
  1572. updateTimeTable();
  1573. }
  1574. /*!
  1575. Returns the background color for weekday days.
  1576. \param the day of the week (Monday = 1, Sunday = 7)
  1577. \return the background color for weekend days
  1578. \sa setWeekendBackgroundColor(), setWeekendDays(), weekendDays()
  1579. */
  1580. TQColor KDTimeHeaderWidget::weekdayBackgroundColor(int weekday) const
  1581. {
  1582. return weekdayColor[weekday];
  1583. }
  1584. /*!
  1585. Defines which days are considered weekends. The days are specified
  1586. as an interval of integer values where 1 means Monday and 7 means
  1587. Sunday. In order to define a weekend from Sunday to Monday, specify
  1588. (7,1).
  1589. \param start the first day of the weekend
  1590. \param end the last day of the weekend
  1591. \sa weekendDays(), setWeekendBackgroundColor(), weekendBackgroundColor()
  1592. */
  1593. void KDTimeHeaderWidget::setWeekendDays( int start, int end )
  1594. {
  1595. myWeekendDaysStart = start;
  1596. myWeekendDaysEnd = end;
  1597. updateTimeTable();
  1598. }
  1599. /*!
  1600. Returns which days are considered weekends.
  1601. \param start in this parameter, the first day of the weekend is returned
  1602. \param end in this parameter, the end day of the weekend is returned
  1603. \sa setWeekendDays(), setWeekendBackgroundColor(), weekendBackgroundColor()
  1604. */
  1605. void KDTimeHeaderWidget::weekendDays( int& start, int& end ) const
  1606. {
  1607. start = myWeekendDaysStart;
  1608. end = myWeekendDaysEnd ;
  1609. }
  1610. /*!
  1611. Sets the number of ticks in the major scale.
  1612. \param count the number of ticks in the major scale
  1613. \sa majorScaleCount(), setMinorScaleCount(), minorScaleCount()
  1614. */
  1615. void KDTimeHeaderWidget::setMajorScaleCount( int count )
  1616. {
  1617. myMajorScaleCount=count;
  1618. computeTicks();
  1619. }
  1620. /*!
  1621. Returns the number of ticks per unit in the major scale.
  1622. \return the number of ticks in the major scale
  1623. \sa setMajorScaleCount(), setMinorScaleCount(), minorScaleCount()
  1624. */
  1625. int KDTimeHeaderWidget::majorScaleCount() const
  1626. {
  1627. return myMajorScaleCount;
  1628. }
  1629. /*!
  1630. Sets the number of ticks in the minor scale.
  1631. \param count the number of ticks in the minor scale
  1632. \sa minorScaleCount, setMajorScaleCount, majorScaleCount()
  1633. */
  1634. void KDTimeHeaderWidget::setMinorScaleCount( int count )
  1635. {
  1636. myMinorScaleCount = count;
  1637. computeTicks();
  1638. }
  1639. /*!
  1640. Returns the number of ticks per unit in the minor scale.
  1641. \return the number of ticks in the minor scale
  1642. \sa setMinorScaleCount(), setMajorScaleCount(), majorScaleCount()
  1643. */
  1644. int KDTimeHeaderWidget::minorScaleCount() const
  1645. {
  1646. return myMinorScaleCount ;
  1647. }
  1648. void KDTimeHeaderWidget::resizeEvent ( TQResizeEvent * )
  1649. {
  1650. // tqDebug("KDTimeHeaderWidget:: resizeEvent ");
  1651. paintPix.resize( 800, height () );
  1652. }
  1653. void KDTimeHeaderWidget::updateTimeTable()
  1654. {
  1655. //tqDebug("KDTimeHeaderWidget::updateTimeTable() ");
  1656. if (flagDoNotRecomputeAfterChange) return;
  1657. // setting the scrolling steps
  1658. int scrollLineStep = myGridMinorWidth;
  1659. if (showMajorTicks()) {
  1660. TQValueList<int>::iterator intIt = majorTicks.begin();
  1661. scrollLineStep = 5 * myGridMinorWidth;
  1662. if (intIt != majorTicks.end()) {
  1663. int left = *intIt;
  1664. ++intIt;
  1665. if (intIt != majorTicks.end()) {
  1666. scrollLineStep = *intIt-left;
  1667. }
  1668. }
  1669. }
  1670. myGanttView->myCanvasView->horizontalScrollBar()->setLineStep(scrollLineStep);
  1671. myGanttView->myTimeTable->maximumComputedGridHeight = 0;
  1672. myGanttView->myTimeTable->updateMyContent();
  1673. }
  1674. void KDTimeHeaderWidget::setAutoScaleMinorTickCount( int count )
  1675. {
  1676. myAutoScaleMinorTickcount = count;
  1677. computeTicks();
  1678. }
  1679. int KDTimeHeaderWidget::autoScaleMinorTickCount()
  1680. {
  1681. return myAutoScaleMinorTickcount;
  1682. }
  1683. void KDTimeHeaderWidget::repaintMe(int left,int paintwid, TQPainter* painter)
  1684. {
  1685. if (flagDoNotRecomputeAfterChange) return;
  1686. TQColorGroup qcg =TQColorGroup( white, black,white, darkGray,black,gray,gray) ;
  1687. TQPainter* p;
  1688. int offsetLeft = 0;
  1689. if ( paintwid > paintPix.width()-100 )
  1690. paintPix.resize( paintwid+100, height () );
  1691. if ( painter )
  1692. p = painter;
  1693. else {
  1694. p = new TQPainter( &paintPix );
  1695. offsetLeft = left-50;
  1696. }
  1697. if ( mouseDown ) {
  1698. p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
  1699. int start ;
  1700. int wid;
  1701. if ( beginMouseDown < endMouseDown ) {
  1702. start = beginMouseDown ;
  1703. wid = endMouseDown - beginMouseDown ;
  1704. } else {
  1705. start = endMouseDown ;
  1706. wid = -endMouseDown + beginMouseDown ;
  1707. }
  1708. p->fillRect( start-offsetLeft, 0, wid, height(), TQBrush(paletteBackgroundColor().dark()) );
  1709. } else {
  1710. if (! painter )
  1711. p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
  1712. }
  1713. p->setPen(TQColor(40,40,40));
  1714. TQFont tempFont = p->font();
  1715. tempFont.setWeight(63);
  1716. p->setFont(tempFont);
  1717. int hei1 = myMajorGridHeight,
  1718. hei2 = height(),
  1719. wid1 = myGridMinorWidth;
  1720. int xCoord;
  1721. int lwid = 1;
  1722. TQValueList<TQString>::iterator it;
  1723. TQValueList<int>::iterator intIt = majorTicks.begin();
  1724. for ( it = majorText.begin(); it != majorText.end(); ++it ) {
  1725. xCoord = (*intIt++);
  1726. if (((*intIt)>= left && xCoord <= left+paintwid)) {
  1727. qDrawShadeLine ( p,xCoord-offsetLeft ,hei1+1, xCoord-offsetLeft, -2, qcg, true, lwid, 1 );
  1728. p->drawText(xCoord+4-offsetLeft,hei1-4,(*it));
  1729. }
  1730. }
  1731. qDrawShadeLine ( p,left-offsetLeft ,hei1, left+paintwid-offsetLeft, hei1, qcg, true, lwid, 1 );
  1732. int i = 0;
  1733. for ( it = minorText.begin(); it != minorText.end(); ++it ) {
  1734. if (i*wid1 >= left-wid1 && i*wid1 <= left+paintwid) {
  1735. qDrawShadeLine ( p,i*wid1-offsetLeft ,hei1-1, i*wid1-offsetLeft, hei2, qcg, true, lwid, 1 );
  1736. p->drawText(i*wid1+1-offsetLeft,hei1+1,wid1-1,hei2-hei1,TQt::AlignCenter,(*it));
  1737. }
  1738. ++i;
  1739. }
  1740. p->setPen(black);
  1741. p->drawLine(left-offsetLeft,hei1,left+paintwid-offsetLeft,hei1);
  1742. qDrawShadeLine ( p,left-offsetLeft ,hei2-1, left+paintwid-offsetLeft, hei2-1, qcg, true, lwid, 1 );
  1743. p->drawLine(left-offsetLeft,hei2-1,left+paintwid-offsetLeft,hei2-1);
  1744. if ( !painter ) {
  1745. p->end();
  1746. delete p;
  1747. bitBlt ( this, left, 0, &paintPix, 50, 0, paintwid, height() );
  1748. }
  1749. }
  1750. // cuts the secs in the DateTime if scale is Minute ,
  1751. // the minutes and secs if scale is Hour and so on
  1752. TQDateTime KDTimeHeaderWidget::getEvenTimeDate(TQDateTime tempdatetime ,Scale sc)
  1753. {
  1754. TQDate tempdate;
  1755. int min, hour;
  1756. int tempMinorScaleCount = myRealMinorScaleCount;
  1757. switch (sc)
  1758. {
  1759. case KDGanttView::Month:
  1760. tempdate = tempdatetime.date();
  1761. while (tempdate.day ()!= 1 )
  1762. tempdate = tempdate.addDays(-1);
  1763. //while (tempdate.month ()!= 1 )
  1764. //tempdate = tempdate.addMonths(-1);
  1765. tempdatetime = TQDateTime (tempdate, TQTime (0,0));
  1766. break;
  1767. case KDGanttView::Week:
  1768. tempdate = tempdatetime.date();
  1769. while (tempdate.dayOfWeek ()!= TDEGlobal::locale()->weekStartDay())
  1770. tempdate = tempdate.addDays(-1);
  1771. //tempdate = tempdate.addDays(-7);
  1772. tempdatetime = TQDateTime (tempdate, TQTime (0,0));
  1773. break;
  1774. case KDGanttView::Day:
  1775. tempdatetime = TQDateTime (tempdatetime.date(), TQTime ( 0,0 ) );
  1776. break;
  1777. case KDGanttView::Hour:
  1778. hour = tempdatetime.time().hour();
  1779. while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
  1780. ++tempMinorScaleCount;
  1781. hour = ( hour /tempMinorScaleCount)*tempMinorScaleCount;
  1782. tempdatetime = TQDateTime (tempdatetime.date(), TQTime (hour, 0 ));
  1783. break;
  1784. case KDGanttView::Minute:
  1785. min = tempdatetime.time().minute();
  1786. while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
  1787. ++tempMinorScaleCount;
  1788. // tqDebug("myMinorScaleCount %d %d %d",myMinorScaleCount, myRealMinorScaleCount, tempMinorScaleCount);
  1789. min = (min /tempMinorScaleCount)*tempMinorScaleCount;
  1790. tempdatetime = TQDateTime (tempdatetime.date(), TQTime (tempdatetime.time().hour(),min ));
  1791. break;
  1792. case KDGanttView::Auto:
  1793. break;
  1794. }
  1795. return tempdatetime;
  1796. }
  1797. void KDTimeHeaderWidget::computeRealScale(TQDateTime start)
  1798. {
  1799. if (myScale ==KDGanttView::Auto) {
  1800. //tqDebug("Autoscale ");
  1801. //double secsPerMinor = (((double)start.daysTo(myHorizonEnd))* 86400.00)/((double)myAutoScaleMinorTickcount);
  1802. double secsPerMinor = (((double)start.secsTo(myHorizonEnd)))/((double)myAutoScaleMinorTickcount);
  1803. secsPerMinor /= myZoomFactor;
  1804. if (secsPerMinor <= 1800) {
  1805. myRealScale = KDGanttView::Minute;
  1806. myRealMinorScaleCount = (int) secsPerMinor/60;
  1807. } else {
  1808. if (secsPerMinor <= 12*3600) {
  1809. myRealScale = KDGanttView::Hour;
  1810. myRealMinorScaleCount = (int) secsPerMinor/3600;
  1811. } else {
  1812. if (secsPerMinor <= 24*3600*3) {
  1813. myRealScale = KDGanttView::Day;
  1814. myRealMinorScaleCount = (int) secsPerMinor/(3600*24);
  1815. } else {
  1816. if (secsPerMinor <= 24*3600*14) {
  1817. myRealScale = KDGanttView::Week;
  1818. myRealMinorScaleCount = (int) secsPerMinor/(3600*24*7);
  1819. } else {
  1820. myRealScale = KDGanttView::Month;
  1821. myRealMinorScaleCount = (int) secsPerMinor/(3600*24*30);
  1822. }
  1823. }
  1824. }
  1825. }
  1826. if(myRealMinorScaleCount == 0)
  1827. myRealMinorScaleCount = 1;
  1828. myRealMajorScaleCount = 1;
  1829. }
  1830. else {
  1831. //tqDebug("Fixed scale ");
  1832. myRealScale = myScale;
  1833. if (myRealScale > myMaxScale)
  1834. myRealScale = myMaxScale;
  1835. if (myRealScale < myMinScale)
  1836. myRealScale = myMinScale;
  1837. myRealMinorScaleCount = (int) ( ((double)myMinorScaleCount) /myZoomFactor );
  1838. double tempZoom = myZoomFactor;
  1839. myRealMajorScaleCount = myMajorScaleCount;
  1840. while (myRealMinorScaleCount == 0) {
  1841. if (myRealScale == myMinScale) {
  1842. myRealMinorScaleCount = 1;
  1843. break;
  1844. }
  1845. switch (myRealScale)
  1846. {
  1847. case KDGanttView::Minute:
  1848. myRealMinorScaleCount = 1;
  1849. return;
  1850. break;
  1851. case KDGanttView::Hour:
  1852. myRealScale = KDGanttView::Minute;
  1853. tempZoom = tempZoom/60;
  1854. break;
  1855. case KDGanttView::Day:
  1856. myRealScale = KDGanttView::Hour;
  1857. tempZoom = tempZoom/24;
  1858. break;
  1859. case KDGanttView::Week:
  1860. myRealScale = KDGanttView::Day;
  1861. tempZoom = tempZoom/7;
  1862. break;
  1863. case KDGanttView::Month:
  1864. myRealScale = KDGanttView::Week ;
  1865. tempZoom = tempZoom*7/30;
  1866. break;
  1867. case KDGanttView::Auto:
  1868. break;
  1869. }
  1870. myRealMinorScaleCount = (int) ( myMinorScaleCount /tempZoom );
  1871. }
  1872. }
  1873. }
  1874. void KDTimeHeaderWidget::computeTicks(bool doNotComputeRealScale)
  1875. {
  1876. if (flagDoNotRecomputeAfterChange) return;
  1877. bool block = myGanttView->myTimeTable->blockUpdating();
  1878. myGanttView->myTimeTable->setBlockUpdating( true );
  1879. //tqDebug("computeticks ");
  1880. majorTicks.clear();
  1881. minorText.clear();
  1882. majorText.clear();
  1883. if ( !doNotComputeRealScale )
  1884. saveCenterDateTime();
  1885. if (!doNotComputeRealScale)
  1886. computeRealScale(myHorizonStart);
  1887. myRealStart = getEvenTimeDate(myHorizonStart ,myRealScale);
  1888. if (!doNotComputeRealScale)
  1889. computeRealScale(myRealStart);
  1890. int tempMinorScaleCount = myRealMinorScaleCount,
  1891. tempMajorScaleCount = myRealMajorScaleCount;
  1892. int minorItems,minorPerMajor = 1;
  1893. minorItems = (int) (secsFromTo( myRealStart, myHorizonEnd)/60.0);
  1894. //tqDebug("tempMinorScaleCount %d ", tempMinorScaleCount);
  1895. TQPainter p(this);
  1896. int Width, Height;
  1897. TQString testTextMinor,testTextMajor, tempStr;
  1898. TQRect itemRectMinor, itemRectMajor;
  1899. TQDate tempDate = myRealStart.date();
  1900. myRealEnd = myRealStart;
  1901. // preparing the testtext for the differennt scales
  1902. switch (myRealScale)
  1903. {
  1904. // the x in testTextMajor is added to reserve a little bit more space
  1905. case KDGanttView::Minute:
  1906. testTextMinor = "60";
  1907. if (myHourFormat == KDGanttView::Hour_12)
  1908. testTextMajor = "Mon Aug 30, 12 AMx";
  1909. else
  1910. testTextMajor = "Mon Aug 30, 24:00x";
  1911. minorPerMajor = 6000;
  1912. break;
  1913. case KDGanttView::Hour:
  1914. minorItems = minorItems/60;
  1915. if (myHourFormat == KDGanttView::Hour_24)
  1916. testTextMinor = "24x";
  1917. else
  1918. testTextMinor = "12 AM";
  1919. testTextMajor = "Mon Aug 30, x";
  1920. if ( yearFormat() != KDGanttView::NoDate )
  1921. testTextMajor += getYear(TQDate::currentDate());
  1922. minorPerMajor = 2400;
  1923. break;
  1924. case KDGanttView::Day:
  1925. minorItems = minorItems/(60*24);
  1926. testTextMinor = "88";
  1927. testTextMajor = "Aug 30, x"+getYear(TQDate::currentDate());
  1928. minorPerMajor = 700;
  1929. break;
  1930. case KDGanttView::Week:
  1931. minorItems = minorItems/(60*24*7);
  1932. testTextMinor = "88";
  1933. testTextMajor = "Aug x"+getYear(TQDate::currentDate());
  1934. minorPerMajor = 435; // 435 = 365days/12months/7days * 100
  1935. break;
  1936. case KDGanttView::Month:
  1937. minorItems = (minorItems*12)/(60*24*365);
  1938. testTextMinor = "M";
  1939. testTextMajor = "x"+getYear(TQDate::currentDate());
  1940. minorPerMajor = 1200;
  1941. break;
  1942. case KDGanttView::Auto:
  1943. tqDebug("KDGanttView::Internal Error in KDTimeHeaderWidget::computeTicks() ");
  1944. tqDebug(" RealScale == Auto : This may not be! ");
  1945. break;
  1946. }
  1947. itemRectMinor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMinor);
  1948. itemRectMajor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMajor);
  1949. p.end();
  1950. //tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
  1951. Height = itemRectMinor.height()+itemRectMajor.height()+11;
  1952. Width = (itemRectMinor.width()+5);
  1953. if (Width < minimumColumnWidth()) Width = minimumColumnWidth();
  1954. // if the desired width is greater than the maximum width of this widget
  1955. // increase the minorscalecount
  1956. int maxWid = myGanttView->myCanvasView->viewport()->width();
  1957. if (!flagZoomToFit)
  1958. maxWid = maximumWidth();
  1959. while((minorItems/tempMinorScaleCount+1)*Width > maxWid)
  1960. ++tempMinorScaleCount;
  1961. //tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
  1962. mySizeHint = (minorItems/tempMinorScaleCount+1)*Width;
  1963. switch (myRealScale)
  1964. {
  1965. case KDGanttView::Minute:
  1966. if (tempMinorScaleCount < 60)
  1967. while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
  1968. ++tempMinorScaleCount;
  1969. if (tempMinorScaleCount >= 60) {
  1970. myRealScale = KDGanttView::Hour;
  1971. myRealMinorScaleCount = tempMinorScaleCount/ 60;
  1972. // myRealMinorScaleCount = 1;
  1973. myRealMajorScaleCount = 1;
  1974. tqDebug("KDGantt::Overzoom:Rescaling from Minute to Hour");
  1975. myGanttView->myTimeTable->setBlockUpdating( block );
  1976. emit myGanttView->rescaling( KDGanttView::Hour );
  1977. computeTicks(true);
  1978. return;
  1979. }
  1980. break;
  1981. case KDGanttView::Hour:
  1982. while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
  1983. ++tempMinorScaleCount;
  1984. if (tempMinorScaleCount >= 24) {
  1985. myRealScale = KDGanttView::Day;
  1986. myRealMinorScaleCount = tempMinorScaleCount/ 24;
  1987. //myRealMinorScaleCount = 1;
  1988. myRealMajorScaleCount = 1;
  1989. tqDebug("KDGantt::Overzoom:Rescaling from Hour to Day");
  1990. myGanttView->myTimeTable->setBlockUpdating( block );
  1991. emit myGanttView->rescaling( KDGanttView::Day );
  1992. computeTicks(true);
  1993. return;
  1994. }
  1995. break;
  1996. default:
  1997. break;
  1998. }
  1999. //flagZoomToFit = false;
  2000. while((minorItems/tempMinorScaleCount+1)*Width < myMinimumWidth ) {
  2001. ++minorItems;
  2002. }
  2003. minorItems = (minorItems/tempMinorScaleCount)+1;
  2004. // if not enough space for the text of the major scale, increase majorscalecount
  2005. minorPerMajor = (minorPerMajor*tempMajorScaleCount)/tempMinorScaleCount;
  2006. // checking, if enough space for majorscale
  2007. // if not, increasing MajorScaleCount
  2008. while ((minorPerMajor*Width)/100 < itemRectMajor.width()) {
  2009. minorPerMajor = minorPerMajor/tempMajorScaleCount;
  2010. ++tempMajorScaleCount;
  2011. minorPerMajor = minorPerMajor*tempMajorScaleCount;
  2012. }
  2013. // now we have the fixed width of the minorscale computed
  2014. myGridMinorWidth = Width;
  2015. // the width of this widget is the gridwidth * the amount of items
  2016. Width *= minorItems;
  2017. // if size changed, reset geometry
  2018. if (width() != Width || height() != Height )
  2019. {
  2020. resize( Width, Height );
  2021. emit sizeChanged( Width );
  2022. }
  2023. myMajorGridHeight = itemRectMajor.height()+5;
  2024. TQTime tempTime = myRealStart.time();
  2025. TQDateTime tempDateTime;
  2026. int i;
  2027. const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
  2028. switch (myRealScale)
  2029. {
  2030. case KDGanttView::Minute:
  2031. myRealEnd = myRealEnd.addSecs((minorItems)*tempMinorScaleCount*60);
  2032. for ( i = 0; i < minorItems;++i) {
  2033. tempStr.setNum(tempTime.minute());
  2034. minorText.append(tempStr);
  2035. tempTime = tempTime.addSecs(60*tempMinorScaleCount);
  2036. }
  2037. tempDateTime = myRealStart;
  2038. while (tempDateTime.time().minute() != 0)
  2039. tempDateTime = tempDateTime.addSecs(60);
  2040. while (tempDateTime < myRealEnd) {
  2041. majorTicks.append( getCoordX(tempDateTime));
  2042. tempStr.setNum(tempDateTime.date().day());
  2043. if ( yearFormat() == KDGanttView::NoDate ) {
  2044. tempStr = calendar->weekDayName( tempDateTime.date() )+", "
  2045. +getHour(tempDateTime.time());
  2046. } else {
  2047. tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
  2048. calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
  2049. tempStr+", "+getHour(tempDateTime.time());
  2050. }
  2051. majorText.append(tempStr);
  2052. tempDateTime = tempDateTime.addSecs(3600*tempMajorScaleCount);
  2053. }
  2054. majorTicks.append( getCoordX(tempDateTime));
  2055. break;
  2056. case KDGanttView::Hour:
  2057. myRealEnd = myRealEnd.addSecs(minorItems*tempMinorScaleCount*60*60);
  2058. for ( i = 0; i < minorItems;++i) {
  2059. tempStr = getHour(tempTime);
  2060. minorText.append(tempStr);
  2061. tempTime = tempTime.addSecs(3600*tempMinorScaleCount);
  2062. }
  2063. tempDateTime = myRealStart;
  2064. while (tempDateTime.time().hour() != 0)
  2065. tempDateTime = tempDateTime.addSecs(3600);
  2066. while (tempDateTime < myRealEnd) {
  2067. majorTicks.append( getCoordX(tempDateTime));
  2068. tempStr.setNum(tempDateTime.date().day());
  2069. if ( yearFormat() == KDGanttView::NoDate ) {
  2070. tempStr = calendar->weekDayName( tempDateTime.date() );
  2071. } else {
  2072. tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
  2073. calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
  2074. tempStr+", "+getYear(tempDateTime.date());
  2075. }
  2076. majorText.append(tempStr);
  2077. tempDateTime = tempDateTime.addDays(tempMajorScaleCount);
  2078. }
  2079. majorTicks.append( getCoordX(tempDateTime));
  2080. break;
  2081. case KDGanttView::Day:
  2082. myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount);
  2083. for ( i = 0; i < minorItems;++i) {
  2084. if (tempMinorScaleCount == 1)
  2085. minorText.append((calendar->weekDayName(tempDate, true)).left(1)); //TODO: BIDI
  2086. else
  2087. minorText.append(TQString::number(tempDate.day()));
  2088. tempDate = tempDate.addDays(tempMinorScaleCount);
  2089. }
  2090. tempDate = myRealStart.date();
  2091. while (tempDate.dayOfWeek() != TDEGlobal::locale()->weekStartDay())
  2092. tempDate = tempDate.addDays(1);
  2093. while (tempDate < myRealEnd.date()) {
  2094. majorTicks.append( getCoordX(tempDate));
  2095. tempStr.setNum(tempDate.day());
  2096. tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+
  2097. tempStr+", "+getYear(tempDate);
  2098. majorText.append(tempStr);
  2099. tempDate = tempDate.addDays(7*tempMajorScaleCount);
  2100. }
  2101. majorTicks.append( getCoordX(tempDate));
  2102. break;
  2103. case KDGanttView::Week:
  2104. myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount*7);
  2105. for ( i = 0; i < minorItems;++i) {
  2106. tempStr.setNum(tempDate.day());
  2107. minorText.append(tempStr);
  2108. tempDate = tempDate.addDays(7*tempMinorScaleCount);
  2109. }
  2110. tempDate = myRealStart.date();
  2111. while (tempDate.day() != TDEGlobal::locale()->weekStartDay())
  2112. tempDate = tempDate.addDays(1);
  2113. while (tempDate < myRealEnd.date()) {
  2114. majorTicks.append( getCoordX(tempDate));
  2115. tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+getYear(tempDate);
  2116. majorText.append(tempStr);
  2117. tempDate = tempDate.addMonths(tempMajorScaleCount);
  2118. }
  2119. majorTicks.append( getCoordX(tempDate));
  2120. break;
  2121. case KDGanttView::Month:
  2122. myRealEnd = myRealEnd.addMonths(minorItems*tempMinorScaleCount);
  2123. for ( i = 0; i < minorItems;++i) {
  2124. minorText.append((calendar->monthName(tempDate.month(), tempDate.year(), true)).left(1)); //TODO: BIDI
  2125. tempDate = tempDate.addMonths(tempMinorScaleCount);
  2126. }
  2127. tempDate = myRealStart.date();
  2128. while (tempDate.month() != 1)
  2129. tempDate = tempDate.addMonths(1);
  2130. while (tempDate < myRealEnd.date()) {
  2131. majorTicks.append( getCoordX(tempDate));
  2132. tempStr = getYear(tempDate);
  2133. majorText.append(tempStr);
  2134. tempDate = tempDate.addYears(tempMajorScaleCount);
  2135. }
  2136. majorTicks.append( getCoordX(tempDate));
  2137. break;
  2138. case KDGanttView::Auto:
  2139. break;
  2140. }
  2141. if (flagDoNotRepaintAfterChange) {
  2142. myGanttView->myTimeTable->setBlockUpdating( block );
  2143. return;
  2144. }
  2145. //tqDebug("KDTimeHeaderWidget width %d, viewport width %d ",width (), myGanttView->myCanvasView->viewport()->width());
  2146. myGanttView->myTimeTable->setBlockUpdating( block );
  2147. updateTimeTable();
  2148. centerDateTime(myCenterDateTime);
  2149. repaint();
  2150. }
  2151. void KDTimeHeaderWidget::saveCenterDateTime()
  2152. {
  2153. double wid = width();
  2154. double allsecs = secsFromTo( myRealStart, myRealEnd );
  2155. double center = myGanttView->myCanvasView->viewport()->width();
  2156. center = center / 2;
  2157. center = center + myGanttView->myCanvasView->contentsX();
  2158. double secs = (allsecs*center)/wid;
  2159. double days = secs/86400.0;
  2160. secs = secs - ( (int) days *86400.0 );
  2161. myCenterDateTime = (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
  2162. }
  2163. void KDTimeHeaderWidget::centerDateTime( const TQDateTime& center )
  2164. {
  2165. moveTimeLineTo(getCoordX( center )-(myGanttView->myCanvasView->viewport()->width() /2));
  2166. // tqDebug("centerDateTime %s %d %d", center.toString().latin1(),getCoordX( center ),(myGanttView->myCanvasView->viewport()->width() /2) );
  2167. }
  2168. void KDTimeHeaderWidget::paintEvent(TQPaintEvent *p)
  2169. {
  2170. repaintMe(p->rect().x(),p->rect().width());
  2171. }
  2172. int KDTimeHeaderWidget::getCoordX(TQDate date)
  2173. {
  2174. int wid = width();
  2175. int daysAll = myRealStart.daysTo(myRealEnd);
  2176. if (daysAll == 0) return 0;
  2177. int days = myRealStart.daysTo(TQDateTime(date));
  2178. return (wid *days) /daysAll;
  2179. }
  2180. int KDTimeHeaderWidget::getCoordX(TQDateTime datetime)
  2181. {
  2182. double wid = width();
  2183. double secsAll = secsFromTo( myRealStart, myRealEnd );
  2184. if (secsAll == 0.0) return 0;
  2185. double secs = secsFromTo( myRealStart, datetime);
  2186. return ((int)((wid *(secs /secsAll))+0.5));
  2187. }
  2188. TQString KDTimeHeaderWidget::getYear(TQDate date)
  2189. {
  2190. TQString ret;
  2191. ret.setNum(date.year());
  2192. switch (yearFormat()) {
  2193. case KDGanttView::FourDigit:
  2194. // nothing to do
  2195. break;
  2196. case KDGanttView::TwoDigit:
  2197. ret = ret.right(2);
  2198. break;
  2199. case KDGanttView::TwoDigitApostrophe:
  2200. ret = "'"+ret.right(2);
  2201. break;
  2202. case KDGanttView::NoDate:
  2203. // nothing to do
  2204. break;
  2205. }
  2206. return ret;
  2207. }
  2208. TQString KDTimeHeaderWidget::getHour(TQTime time)
  2209. {
  2210. TQString ret;
  2211. int hour = time.hour();
  2212. if (myHourFormat == KDGanttView::Hour_12) {
  2213. if (hour >= 12) {
  2214. if (hour > 12) hour -=12;
  2215. ret.setNum(hour);
  2216. ret = ret +" PM";
  2217. } else {
  2218. if (hour == 0) hour = 12;
  2219. ret.setNum(hour);
  2220. ret = ret +" AM";
  2221. }
  2222. } else {
  2223. if (myHourFormat == KDGanttView::Hour_24)
  2224. ret.setNum(hour);
  2225. else {
  2226. ret.setNum(hour);
  2227. ret += ":00";
  2228. }
  2229. }
  2230. return ret;
  2231. }
  2232. void KDTimeHeaderWidget::mousePressEvent ( TQMouseEvent * e )
  2233. {
  2234. mouseDown = false;
  2235. switch ( e->button() ) {
  2236. case Qt::LeftButton:
  2237. mouseDown = true;
  2238. beginMouseDown = e->pos().x();
  2239. endMouseDown = e->pos().x();
  2240. break;
  2241. case Qt::RightButton:
  2242. if (flagShowPopupMenu)
  2243. myPopupMenu->popup(e->globalPos());
  2244. break;
  2245. case Qt::MidButton:
  2246. break;
  2247. default:
  2248. break;
  2249. }
  2250. }
  2251. void KDTimeHeaderWidget::mouseReleaseEvent ( TQMouseEvent * )
  2252. {
  2253. if ( mouseDown ) {
  2254. mouseDown = false;
  2255. // zoom to selection getDateTimeForIndex(
  2256. int start, end;
  2257. if ( beginMouseDown < endMouseDown ) {
  2258. start = beginMouseDown;
  2259. end = endMouseDown;
  2260. } else {
  2261. start = endMouseDown;
  2262. end = beginMouseDown;
  2263. }
  2264. if (start < 0 )
  2265. start = 0;
  2266. if ( end > width() )
  2267. end = width();
  2268. //tqDebug("start %s ",getDateTimeForIndex(start).toString().latin1() );
  2269. //tqDebug("end %s ",getDateTimeForIndex(end).toString().latin1() );
  2270. emit myGanttView->timeIntervalSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
  2271. emit myGanttView->timeIntervallSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
  2272. //zoomToSelection( getDateTimeForIndex(start),getDateTimeForIndex(end) );
  2273. }
  2274. mouseDown = false;
  2275. repaint();
  2276. }
  2277. void KDTimeHeaderWidget::mouseDoubleClickEvent ( TQMouseEvent * )
  2278. {
  2279. }
  2280. void KDTimeHeaderWidget::mouseMoveEvent ( TQMouseEvent * e )
  2281. {
  2282. if ( mouseDown ) {
  2283. if ( e->pos().y() < -height() || e->pos().y() > 2* height() ) {
  2284. mouseDown = false;
  2285. repaint();
  2286. return;
  2287. }
  2288. endMouseDown = e->pos().x();
  2289. //repaint;
  2290. int val = -1;
  2291. if (endMouseDown < -x() ) {
  2292. val = myGanttView->myCanvasView->horizontalScrollBar()->value() -
  2293. myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
  2294. if ( val < 0 ) {
  2295. val = 0;
  2296. }
  2297. }
  2298. if (endMouseDown > -x() +parentWidget()->width() ) {
  2299. val = myGanttView->myCanvasView->horizontalScrollBar()->value() +
  2300. myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
  2301. }
  2302. repaintMe(-x(),parentWidget()->width());
  2303. if ( val > -1 ) {
  2304. if ( val > myGanttView->myCanvasView->horizontalScrollBar()->maxValue() ) {
  2305. val = myGanttView->myCanvasView->horizontalScrollBar()->maxValue();
  2306. }
  2307. myGanttView->myCanvasView->horizontalScrollBar()->setValue( val );
  2308. }
  2309. //tqDebug("mousemove %d %d %d %d",endMouseDown, -x(),parentWidget()->width() , e->pos().y());
  2310. }
  2311. }
  2312. /* ***************************************************************
  2313. KDLegendWidget:: KDLegendWidget
  2314. ***************************************************************** */
  2315. KDLegendWidget:: KDLegendWidget( TQWidget* parent,
  2316. KDGanttMinimizeSplitter* legendParent ) :
  2317. KDGanttSemiSizingControl ( KDGanttSemiSizingControl::Before,Qt::Vertical,
  2318. parent)
  2319. {
  2320. myLegendParent = legendParent;
  2321. dock = 0;
  2322. scroll = new TQScrollView( legendParent );
  2323. setMaximizedWidget( scroll );
  2324. setMinimizedWidget( myLabel = new TQLabel( i18n( " Legend is hidden" ), this) );
  2325. setGeometry( 0, 0, 50, 50 );
  2326. myLegend = 0;
  2327. clearLegend();
  2328. showMe ( false );
  2329. }
  2330. void KDLegendWidget::setAsDoctwindow( bool dockwin )
  2331. {
  2332. if ( (dock == 0 && !dockwin) || ( dock && dockwin ) )
  2333. return;
  2334. if ( dockwin )
  2335. {
  2336. setMaximizedWidget( 0 );
  2337. showMe ( false );
  2338. if ( dock ) delete dock;
  2339. dock = new TQDockWindow(TQDockWindow:: OutsideDock,0 );
  2340. dock->resize( 200, 100 );
  2341. dock->setHorizontallyStretchable( true );
  2342. dock->setVerticallyStretchable( true );
  2343. dock->setCaption(i18n("Legend: ") );
  2344. dock->setResizeEnabled (true );
  2345. delete myLegend;
  2346. myLegend = 0;
  2347. delete scroll;
  2348. scroll = new TQScrollView( dock );
  2349. clearLegend();
  2350. dock->setWidget(scroll);
  2351. setMaximizedWidget( dock );
  2352. showMe ( false );
  2353. } else {
  2354. setMaximizedWidget( 0 );
  2355. showMe ( false );
  2356. delete myLegend;
  2357. myLegend = 0;
  2358. delete scroll;
  2359. delete dock;
  2360. dock = 0;
  2361. scroll = new TQScrollView( myLegendParent );
  2362. clearLegend();
  2363. setMaximizedWidget( scroll );
  2364. showMe ( false );
  2365. }
  2366. }
  2367. bool KDLegendWidget::asDoctwindow( )
  2368. {
  2369. if ( dock )
  2370. return true;
  2371. return false;
  2372. }
  2373. TQDockWindow* KDLegendWidget::dockwindow( )
  2374. {
  2375. return dock;
  2376. }
  2377. void KDLegendWidget::setFont( TQFont font)
  2378. {
  2379. myLegend->setFont( font);
  2380. myLabel->setFont( font);
  2381. TQWidget::setFont( font );
  2382. }
  2383. void KDLegendWidget::drawToPainter( TQPainter *p )
  2384. {
  2385. p->drawPixmap( 0, 0, TQPixmap::grabWidget( myLegend ) );
  2386. }
  2387. TQSize KDLegendWidget::legendSize()
  2388. {
  2389. return myLegend->size();
  2390. }
  2391. TQSize KDLegendWidget::legendSizeHint()
  2392. {
  2393. TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
  2394. return TQSize( myLegend->sizeHint().width(), myLegend->sizeHint().height()+scroll->horizontalScrollBar()->height());
  2395. }
  2396. void KDLegendWidget::showMe ( bool show )
  2397. {
  2398. minimize( !show );
  2399. }
  2400. void KDLegendWidget::clearLegend ( )
  2401. {
  2402. if ( myLegend ) delete myLegend;
  2403. if ( dock )
  2404. myLegend = new TQGroupBox( 1, Qt::Horizontal, scroll->viewport() );
  2405. else
  2406. myLegend = new TQGroupBox( 1, Qt::Horizontal, i18n( "Legend" ), scroll->viewport() );
  2407. myLegend->setBackgroundColor( TQt::white );
  2408. myLegend->setFont( font() );
  2409. scroll->addChild( myLegend );
  2410. scroll->setResizePolicy( TQScrollView::AutoOneFit );
  2411. myLegend->layout()->setMargin( 11 );
  2412. myLegend->setFrameStyle( TQFrame::NoFrame );
  2413. if ( dock )
  2414. scroll->setMaximumHeight( 32000 );
  2415. else
  2416. scroll->setMaximumHeight( legendSizeHint().height() );
  2417. }
  2418. void KDLegendWidget::addLegendItem( KDGanttViewItem::Shape shape, const TQColor& shapeColor, const TQString& text )
  2419. {
  2420. TQLabel * temp;
  2421. TQPixmap p = KDGanttView::getPixmap( shape, shapeColor, TQt::white, 10);
  2422. TQWidget *w = new TQWidget( myLegend );
  2423. w->setBackgroundColor( TQt::white );
  2424. TQHBoxLayout *lay = new TQHBoxLayout( w ,0, 6);
  2425. temp = new TQLabel ( w );
  2426. lay->addWidget( temp, 0, TQt:: AlignRight);
  2427. temp->setPixmap(p);
  2428. temp = new TQLabel ( text, w );
  2429. temp->setBackgroundColor( TQt::white );
  2430. lay->addWidget( temp, 0, TQt:: AlignLeft);
  2431. lay->addStretch();
  2432. if ( dock )
  2433. scroll->setMaximumHeight( 32000 );
  2434. else
  2435. scroll->setMaximumHeight( legendSizeHint().height() );
  2436. }
  2437. bool KDLegendWidget::isShown ( )
  2438. {
  2439. return !isMinimized();
  2440. }
  2441. KDListView::KDListView(TQWidget* parent, KDGanttView* gantView):TQListView (parent)
  2442. {
  2443. myGanttView = gantView;
  2444. setAcceptDrops(true);
  2445. new KDListViewWhatsThis(viewport(),this);
  2446. setRootIsDecorated( true );
  2447. setAllColumnsShowFocus( true );
  2448. addColumn( i18n( "Task Name" ) );
  2449. setSorting( -1 );
  2450. //setVScrollBarMode (TQScrollView::AlwaysOn );
  2451. setHScrollBarMode (TQScrollView::AlwaysOn );
  2452. setDefaultRenameAction(TQListView::Accept);
  2453. setColumnWidthMode ( 0,Maximum );
  2454. _calendarMode = false;
  2455. // TQObject::connect(this, TQT_SIGNAL ( pressed ( TQListViewItem * )) , this, TQT_SLOT( dragItem( TQListViewItem *))) ;
  2456. }
  2457. void KDListView::dragItem( TQListViewItem * )
  2458. {
  2459. // tqDebug("drag ");
  2460. // startDrag();
  2461. }
  2462. TQString KDListView::getWhatsThisText(TQPoint p)
  2463. {
  2464. KDGanttViewItem* item = ( KDGanttViewItem* ) itemAt( p );
  2465. if ( item )
  2466. return item->whatsThisText();
  2467. return i18n( "No item Found" );
  2468. }
  2469. void KDListView::setCalendarMode( bool mode )
  2470. {
  2471. _calendarMode = mode;
  2472. // setRootIsDecorated ( ! mode );
  2473. }
  2474. void KDListView::setOpen(TQListViewItem * item, bool open )
  2475. {
  2476. if (! _calendarMode || ! open ) {
  2477. (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
  2478. TQListView::setOpen ( item, open );
  2479. (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
  2480. return;
  2481. }
  2482. // we are in calendarmode
  2483. // in calendarmode only items can be opened which have subitems which have subitems
  2484. TQListViewItem* temp;
  2485. temp = item->firstChild();
  2486. bool openItem = false;
  2487. while (temp) {
  2488. if ( (( KDGanttViewItem*)temp)->displaySubitemsAsGroup() ) {
  2489. temp->setVisible( true );
  2490. openItem = true;
  2491. }
  2492. else {
  2493. temp->setVisible( false );
  2494. //tqDebug(" temp->setVisible( false );");
  2495. }
  2496. temp = temp->nextSibling();
  2497. }
  2498. if ( openItem ) {
  2499. (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
  2500. TQListView::setOpen ( item, open );
  2501. (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
  2502. }
  2503. }
  2504. void KDListView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
  2505. {
  2506. TQListView::contentsMouseDoubleClickEvent ( e );
  2507. //if ( ! _calendarMode )
  2508. // TQListView::contentsMouseDoubleClickEvent ( e );
  2509. // else
  2510. {
  2511. emit myGanttView->lvItemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
  2512. emit myGanttView->itemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
  2513. }
  2514. }
  2515. void KDListView::drawToPainter ( TQPainter * p, bool drawHeader )
  2516. {
  2517. // Draw list
  2518. drawAllContents ( p, 0, 0, contentsWidth(), contentsHeight() );
  2519. if (!drawHeader) {
  2520. return;
  2521. }
  2522. // Draw headers
  2523. TQPen pen = TQPen(TQt::lightGray, 1);
  2524. p->save();
  2525. TQHeader *h = header();
  2526. for (int s = 0; s < h->count(); ++s) {
  2527. TQRect r = h->sectionRect(s);
  2528. if (s==0) {
  2529. p->translate(0, -r.height());
  2530. }
  2531. //kdDebug()<<s<<": "<<h->label(s)<<" "<<r<<endl;
  2532. p->drawText(r.x()+2, r.y(), r.width()-2, r.height(), columnAlignment(s)|TQt::AlignVCenter, h->label(s), -1);
  2533. p->save();
  2534. p->setPen(pen);
  2535. p->drawRect(r.x(), r.y()+1, r.width(), r.height()-2);
  2536. p->restore();
  2537. }
  2538. p->restore();
  2539. }
  2540. int KDListView::buildDrawables(TQPtrList<KDListView::DrawableItem> &lst, int level, int ypos, TQListViewItem *item, int ymin, int ymax) const {
  2541. int y = ypos;
  2542. int ih = item->height();
  2543. if (y < ymin && y+ih > ymin) {
  2544. y = ymin; // include partial item at top
  2545. }
  2546. if (y >= ymin && y < ymax) { // include partial item at bottom
  2547. KDListView::DrawableItem *dr = new KDListView::DrawableItem(level, y, item);
  2548. lst.append(dr);
  2549. //kdDebug()<<k_funcinfo<<level<<", "<<y<<" : "<<item->text(0)<<endl;
  2550. }
  2551. y += ih;
  2552. if (item->isOpen()) {
  2553. TQListViewItem *child = item->firstChild();
  2554. for (; child; child = child->nextSibling()) {
  2555. y = buildDrawables(lst, level+1, y, child, ymin, ymax);
  2556. }
  2557. }
  2558. return y;
  2559. }
  2560. // This is a copy of TQListView::drawContentsOffset(), with a few changes
  2561. // because drawContentsOffset() only draws *visible* items,
  2562. // we want to draw *all* items.
  2563. // FIXME: Haven't got paintBraches() to work, atm live without it.
  2564. void KDListView::drawAllContents(TQPainter * p, int cx, int cy, int cw, int ch) {
  2565. if ( columns() == 0 ) {
  2566. paintEmptyArea( p, TQRect( cx, cy, cw, ch ) );
  2567. return;
  2568. }
  2569. //kdDebug()<<k_funcinfo<<TQRect(cx, cy, cw, ch)<<endl;
  2570. TQPtrList<KDListView::DrawableItem> drawables;
  2571. drawables.setAutoDelete(true);
  2572. TQListViewItem *child = firstChild();
  2573. int level = 0;
  2574. int ypos = 0;
  2575. for (; child; child = child->nextSibling()) {
  2576. ypos = buildDrawables(drawables, level, ypos, child, cy, cy+ch);
  2577. }
  2578. p->setFont( font() );
  2579. TQPtrListIterator<KDListView::DrawableItem> it(drawables);
  2580. TQRect r;
  2581. int fx = -1, x, fc = 0, lc = 0;
  2582. int tx = -1;
  2583. KDListView::DrawableItem * current;
  2584. while ( (current = it.current()) != 0 ) {
  2585. ++it;
  2586. int ih = current->i->height();
  2587. int ith = current->i->totalHeight();
  2588. int c;
  2589. int cs;
  2590. // need to paint current?
  2591. if ( ih > 0 && current->y < cy+ch && current->y+ih > cy ) {
  2592. //kdDebug()<<k_funcinfo<<"Paint: "<<current->i->text(0)<<" y="<<current->y<<endl;
  2593. if ( fx < 0 ) {
  2594. // find first interesting column, once
  2595. x = 0;
  2596. c = 0;
  2597. cs = header()->cellSize( 0 );
  2598. while ( x + cs <= cx && c < header()->count() ) {
  2599. x += cs;
  2600. c++;
  2601. if ( c < header()->count() )
  2602. cs = header()->cellSize( c );
  2603. }
  2604. fx = x;
  2605. fc = c;
  2606. while( x < cx + cw && c < header()->count() ) {
  2607. x += cs;
  2608. c++;
  2609. if ( c < header()->count() )
  2610. cs = header()->cellSize( c );
  2611. }
  2612. lc = c;
  2613. }
  2614. x = fx;
  2615. c = fc;
  2616. // draw to last interesting column
  2617. const TQColorGroup &cg = ( palette().inactive() );
  2618. while ( c < lc && !drawables.isEmpty() ) {
  2619. int i = header()->mapToLogical( c );
  2620. cs = header()->cellSize( c );
  2621. r.setRect( x, current->y-cy, cs, ih );
  2622. if ( i == 0 )
  2623. r.setLeft( r.left() + current->l * treeStepSize() );
  2624. p->save();
  2625. // No need to paint if the cell isn't technically visible
  2626. if ( !( r.width() == 0 || r.height() == 0 ) ) {
  2627. p->translate( r.left(), r.top() );
  2628. int ac = header()->mapToLogical( c );
  2629. // map to Left currently. This should change once we
  2630. // can really reverse the listview.
  2631. int align = columnAlignment( ac );
  2632. if ( align == AlignAuto ) align = AlignLeft;
  2633. bool sel = current->i->isSelected();
  2634. if (sel)
  2635. current->i->setSelected(false);
  2636. current->i->paintCell( p, cg, ac, r.width(), align );
  2637. if (sel)
  2638. current->i->setSelected(sel);
  2639. }
  2640. p->restore();
  2641. x += cs;
  2642. c++;
  2643. }
  2644. }
  2645. const int cell = header()->mapToActual( 0 );
  2646. if ( tx < 0 )
  2647. tx = header()->cellPos( cell );
  2648. // do any children of current need to be painted?
  2649. /* FIXME: painting branches doesn't work for some reason...
  2650. if ( ih != ith &&
  2651. rootIsDecorated() &&
  2652. current->y + ith > cy &&
  2653. current->y + ih < cy + ch &&
  2654. tx + current->l * treeStepSize() < cx + cw &&
  2655. tx + (current->l+1) * treeStepSize() > cx ) {
  2656. // compute the clip rectangle the safe way
  2657. int rtop = current->y + ih;
  2658. int rbottom = current->y + ith;
  2659. int rleft = tx + current->l*treeStepSize();
  2660. int rright = rleft + treeStepSize();
  2661. int crtop = TQMAX( rtop, cy );
  2662. int crbottom = TQMIN( rbottom, cy+ch );
  2663. int crleft = TQMAX( rleft, cx );
  2664. int crright = TQMIN( rright, cx+cw );
  2665. r.setRect( crleft, crtop,
  2666. crright-crleft, crbottom-crtop );
  2667. if ( r.isValid() ) {
  2668. p->save();
  2669. p->translate( rleft, crtop );
  2670. //kdDebug()<<k_funcinfo<<"paintBranches: "<<current->i->text(0)<<endl;
  2671. current->i->paintBranches( p, colorGroup(), treeStepSize(),
  2672. rtop - crtop, r.height() );
  2673. p->restore();
  2674. }
  2675. }*/
  2676. }
  2677. }
  2678. void KDListView::resizeEvent(TQResizeEvent *)
  2679. {
  2680. triggerUpdate ();
  2681. }
  2682. void KDListView::dragEnterEvent ( TQDragEnterEvent * e)
  2683. {
  2684. if ( !myGanttView->dropEnabled() ) {
  2685. e->accept( false );
  2686. return;
  2687. }
  2688. myGanttView->lvDragEnterEvent(e);
  2689. //e->accept(KDGanttViewItemDrag::canDecode(e) );
  2690. }
  2691. void KDListView::dragMoveEvent ( TQDragMoveEvent * e)
  2692. {
  2693. if ( !myGanttView->dropEnabled() ) {
  2694. e->accept( false );
  2695. return;
  2696. }
  2697. KDGanttViewItem* draggedItem = 0;
  2698. KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
  2699. setCurrentItem( gItem );
  2700. if ( e->source() == myGanttView )
  2701. draggedItem = myGanttView->myCanvasView->lastClickedItem;
  2702. // execute user defined dragMoveEvent handling
  2703. if (myGanttView->lvDragMoveEvent ( e , draggedItem, gItem ) )
  2704. return;
  2705. if ( !KDGanttViewItemDrag::canDecode(e) ) {
  2706. e->accept( false );
  2707. return;
  2708. }
  2709. if ( e->source() == myGanttView && gItem ){
  2710. // internal drag - do not allow to drag the item to a subitem of itself
  2711. KDGanttViewItem* pItem = gItem->parent();
  2712. while ( pItem ) {
  2713. if ( pItem == myGanttView->myCanvasView->lastClickedItem ) {
  2714. e->accept( false );
  2715. return;
  2716. }
  2717. pItem = pItem->parent();
  2718. }
  2719. if ( gItem == myGanttView->myCanvasView->lastClickedItem ) {
  2720. e->accept( false );
  2721. return;
  2722. }
  2723. }
  2724. e->accept( true );
  2725. }
  2726. void KDListView::dragLeaveEvent ( TQDragLeaveEvent * )
  2727. {
  2728. //tqDebug("contentsDragLeaveEvent ");
  2729. }
  2730. void KDListView::dropEvent ( TQDropEvent *e )
  2731. {
  2732. if ( !myGanttView->dropEnabled() ) {
  2733. e->accept( false );
  2734. return;
  2735. }
  2736. KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
  2737. KDGanttViewItem* draggedItem = 0;
  2738. if ( e->source() == myGanttView )
  2739. draggedItem = myGanttView->myCanvasView->lastClickedItem;
  2740. if (myGanttView->lvDropEvent ( e, draggedItem, gItem ))
  2741. return;
  2742. TQString string;
  2743. KDGanttViewItemDrag::decode( e, string );
  2744. KDGanttViewItem* newItem = 0;
  2745. if ( gItem == myGanttView->myCanvasView->lastClickedItem && gItem != 0 ) {
  2746. tqDebug("KDGanttView::Possible bug in drag&drop code ");
  2747. return;
  2748. }
  2749. TQDomDocument doc( "GanttView" );
  2750. doc.setContent( string );
  2751. TQDomElement docRoot = doc.documentElement(); // ChartParams element
  2752. TQDomNode node = docRoot.firstChild();
  2753. bool enable = myGanttView->myTimeTable->blockUpdating( );
  2754. myGanttView->myTimeTable->setBlockUpdating( true );
  2755. while( !node.isNull() ) {
  2756. TQDomElement element = node.toElement();
  2757. if( !element.isNull() ) { // was really an element
  2758. TQString tagName = element.tagName();
  2759. if( tagName == "Items" ) {
  2760. TQDomNode node = element.firstChild();
  2761. while( !node.isNull() ) {
  2762. TQDomElement element = node.toElement();
  2763. if( !element.isNull() ) { // was really an element
  2764. TQString tagName = element.tagName();
  2765. if( tagName == "Item" ) {
  2766. if ( gItem )
  2767. newItem = KDGanttViewItem::createFromDomElement( gItem,
  2768. element );
  2769. else
  2770. newItem = KDGanttViewItem::createFromDomElement( myGanttView,
  2771. element );
  2772. } else {
  2773. tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
  2774. Q_ASSERT( false );
  2775. }
  2776. }
  2777. //tqDebug("next node1 ");
  2778. node = node.nextSibling();
  2779. }
  2780. }
  2781. }
  2782. //tqDebug("next node2 ");
  2783. node = node.nextSibling();
  2784. }
  2785. newItem->setDisplaySubitemsAsGroup(myGanttView->displaySubitemsAsGroup());
  2786. newItem->resetSubitemVisibility();
  2787. myGanttView->slot_lvDropped(e, draggedItem, gItem);
  2788. myGanttView->myTimeTable->setBlockUpdating( enable );
  2789. myGanttView->myTimeTable->updateMyContent();
  2790. return;
  2791. }
  2792. TQDragObject * KDListView::dragObject ()
  2793. {
  2794. return TQListView::dragObject ();
  2795. }
  2796. void KDListView::startDrag ()
  2797. {
  2798. if ( ! myGanttView->dragEnabled() )
  2799. return;
  2800. KDGanttViewItem* cItem = (KDGanttViewItem*) currentItem ();
  2801. myGanttView->myCanvasView->lastClickedItem = cItem;
  2802. myGanttView->lvStartDrag (cItem);
  2803. }
  2804. KDCanvasText::KDCanvasText( KDTimeTableWidget* canvas,
  2805. void* parentItem,
  2806. int type ) :
  2807. TQCanvasText(canvas)
  2808. {
  2809. myParentType = type;
  2810. myParentItem = parentItem;
  2811. }
  2812. KDCanvasLine::KDCanvasLine( KDTimeTableWidget* canvas,
  2813. void* parentItem,
  2814. int type ) :
  2815. TQCanvasLine(canvas)
  2816. {
  2817. myParentType = type;
  2818. myParentItem = parentItem;
  2819. }
  2820. KDCanvasPolygonItem::KDCanvasPolygonItem( KDTimeTableWidget* canvas,
  2821. void* parentItem,
  2822. int type ) :
  2823. TQCanvasPolygonalItem( canvas )
  2824. {
  2825. myParentType = type;
  2826. myParentItem = parentItem;
  2827. }
  2828. KDCanvasPolygon::KDCanvasPolygon( KDTimeTableWidget* canvas,
  2829. void* parentItem,
  2830. int type ) :
  2831. TQCanvasPolygon( canvas )
  2832. {
  2833. myParentType = type;
  2834. myParentItem = parentItem;
  2835. }
  2836. KDCanvasEllipse::KDCanvasEllipse( KDTimeTableWidget* canvas,
  2837. void* parentItem,
  2838. int type ) :
  2839. TQCanvasEllipse( canvas )
  2840. {
  2841. myParentType = type;
  2842. myParentItem = parentItem;
  2843. }
  2844. KDCanvasRectangle::KDCanvasRectangle( KDTimeTableWidget* canvas,
  2845. void* parentItem,
  2846. int type ) :
  2847. TQCanvasRectangle( canvas )
  2848. {
  2849. myParentType = type;
  2850. myParentItem = parentItem;
  2851. }
  2852. KDGanttCanvasView::KDGanttCanvasView( KDGanttView* sender,TQCanvas* canvas, TQWidget* parent, const
  2853. char* name ) : TQCanvasView ( canvas, parent, name ), scrollBarTimer( 0, "scrollBarTimer" )
  2854. {
  2855. setHScrollBarMode (TQScrollView::AlwaysOn );
  2856. setVScrollBarMode( TQScrollView::AlwaysOn );
  2857. myToolTip = new KDCanvasToolTip(viewport(),this);
  2858. mySignalSender = sender;
  2859. currentItem = 0;
  2860. currentLink = 0;
  2861. cuttedItem = 0;
  2862. fromItem = 0;
  2863. fromArea = 0;
  2864. linkItemsEnabled = false;
  2865. linkLine = new TQCanvasLine(canvas);
  2866. linkLine->hide();
  2867. linkLine->setZ(1000);
  2868. //set_Mouse_Tracking(true);
  2869. new KDCanvasWhatsThis(viewport(),this);
  2870. onItem = new TQPopupMenu( this );
  2871. TQPopupMenu * newMenu = new TQPopupMenu( this );
  2872. TQPopupMenu * onView = new TQPopupMenu( this );
  2873. onView->insertItem( i18n( "Summary" ), this,
  2874. TQT_SLOT ( newRootItem( int ) ), 0, 0 );
  2875. onView->insertItem( i18n( "Event" ), this,
  2876. TQT_SLOT ( newRootItem( int ) ), 0, 1);
  2877. onView->insertItem( i18n( "Task" ), this,
  2878. TQT_SLOT ( newRootItem( int ) ), 0, 2 );
  2879. onItem->insertItem( i18n( "New Root" ), onView );
  2880. newMenu->insertItem( i18n( "Summary" ),
  2881. this, TQT_SLOT ( newChildItem( int) ), 0, 0 );
  2882. newMenu->insertItem( i18n( "Event" ),
  2883. this, TQT_SLOT ( newChildItem( int ) ), 0, 1 );
  2884. newMenu->insertItem( i18n( "Task" ),
  2885. this, TQT_SLOT ( newChildItem( int ) ), 0, 2 );
  2886. onItem->insertItem( i18n( "New Child" ), newMenu );
  2887. TQPopupMenu * afterMenu = new TQPopupMenu( this );
  2888. afterMenu->insertItem( i18n( "Summary" ),
  2889. this, TQT_SLOT ( newChildItem( int) ), 0, 0+4 );
  2890. afterMenu->insertItem( i18n( "Event" ),
  2891. this, TQT_SLOT ( newChildItem( int ) ), 0, 1+4 );
  2892. afterMenu->insertItem( i18n( "Task" ),
  2893. this, TQT_SLOT ( newChildItem( int ) ), 0, 2+4 );
  2894. onItem->insertItem( i18n( "New After" ), afterMenu );
  2895. TQPopupMenu *pasteMenu = new TQPopupMenu( this );
  2896. pasteMenu->insertItem( i18n( "As Root" ),
  2897. this, TQT_SLOT ( pasteItem( int ) ), 0, 0 );
  2898. pasteMenu->insertItem( i18n( "As Child" ),
  2899. this, TQT_SLOT ( pasteItem( int ) ), 0, 1 );
  2900. pasteMenu->insertItem( i18n( "After" ),
  2901. this, TQT_SLOT ( pasteItem( int ) ), 0, 2 );
  2902. onItem->insertItem( i18n( "Paste" ), pasteMenu, 3 );
  2903. onItem->insertItem( i18n( "Cut Item" ), this, TQT_SLOT ( cutItem() ) );
  2904. onItem->setItemEnabled( 3, false );
  2905. myMyContentsHeight = 0;
  2906. _showItemAddPopupMenu = false;
  2907. TQObject *scrollViewTimer = child( "scrollview scrollbar timer", TQTIMER_OBJECT_NAME_STRING, false );
  2908. Q_ASSERT( scrollViewTimer );
  2909. if ( scrollViewTimer ) {
  2910. disconnect( scrollViewTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateScrollBars() ) );
  2911. }
  2912. // If they needed a scrollbar timer in scrollview...
  2913. connect( &scrollBarTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(myUpdateScrollBars() ) );
  2914. myScrollTimer = new TQTimer( this, "myScrollTimer" );
  2915. connect( myScrollTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( slotScrollTimer() ) );
  2916. autoScrollEnabled = false;
  2917. }
  2918. KDGanttCanvasView::~KDGanttCanvasView()
  2919. {
  2920. delete myToolTip;
  2921. }
  2922. void KDGanttCanvasView::setShowPopupMenu( bool show )
  2923. {
  2924. _showItemAddPopupMenu = show;
  2925. }
  2926. bool KDGanttCanvasView::showPopupMenu()
  2927. {
  2928. return _showItemAddPopupMenu;
  2929. }
  2930. void KDGanttCanvasView::moveMyContent( int, int y)
  2931. {
  2932. setContentsPos(contentsX(), y);
  2933. }
  2934. void KDGanttCanvasView::resizeEvent ( TQResizeEvent * e )
  2935. {
  2936. int ho = e->oldSize().height();
  2937. int wo = e->oldSize().width();
  2938. int hi = height();
  2939. int wi = width();
  2940. //TQScrollView::blockSignals( true );
  2941. verticalScrollBar()->setUpdatesEnabled( false );
  2942. TQScrollView::resizeEvent ( e ) ;
  2943. if ( ho != hi )
  2944. emit heightResized( viewport()->height());
  2945. if ( wo != wi )
  2946. emit widthResized( viewport()->width() );
  2947. //setMyContentsHeight( 0 ); // via timer
  2948. //TQScrollView::blockSignals( false );
  2949. scrollBarTimer.start(0, true);
  2950. }
  2951. void KDGanttCanvasView::myUpdateScrollBars()
  2952. {
  2953. setMyContentsHeight( 0 );
  2954. }
  2955. void KDGanttCanvasView::setMyContentsHeight( int hei )
  2956. {
  2957. //tqDebug("setMyContentsHeight %d %d ", hei, myMyContentsHeight);
  2958. if ( hei > 0 )
  2959. myMyContentsHeight = hei;
  2960. verticalScrollBar()->setUpdatesEnabled( true ); // set false in resizeEvent()
  2961. if ( viewport()->height() <= myMyContentsHeight )
  2962. verticalScrollBar()->setRange( 0, myMyContentsHeight- viewport()->height()+1);
  2963. else
  2964. verticalScrollBar()->setRange( 0,0 );
  2965. // testing for unmatching ScrollBar values of timeheader and timetable
  2966. // may happen after external resizing
  2967. if ( horizontalScrollBar()->value() != mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value() ) {
  2968. // I am the Boss!
  2969. mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->setValue(horizontalScrollBar()->value() );
  2970. }
  2971. }
  2972. // Call after *internal* resizing (like addTickRight())
  2973. // Then the new scrollbar maxValue is in myTimeHeader.
  2974. void KDGanttCanvasView::updateHorScrollBar() {
  2975. //tqDebug("horizontalScrollBar max=%d, myTimeHeaderScroll=%d", horizontalScrollBar()->maxValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value());
  2976. horizontalScrollBar()->setRange(mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->minValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->maxValue());
  2977. }
  2978. void KDGanttCanvasView::cutItem( KDGanttViewItem* item )
  2979. {
  2980. lastClickedItem = item;
  2981. cutItem();
  2982. }
  2983. void KDGanttCanvasView::insertItemAsRoot( KDGanttViewItem* item )
  2984. {
  2985. mySignalSender->myListView->insertItem( item );
  2986. if ( item == cuttedItem )
  2987. cuttedItem = 0;
  2988. }
  2989. void KDGanttCanvasView::insertItemAsChild( KDGanttViewItem* parent, KDGanttViewItem* item )
  2990. {
  2991. parent->insertItem( cuttedItem );
  2992. if ( item == cuttedItem )
  2993. cuttedItem = 0;
  2994. }
  2995. void KDGanttCanvasView::insertItemAfter( KDGanttViewItem* parent , KDGanttViewItem* item )
  2996. {
  2997. if ( parent->parent() ) {
  2998. parent->parent()->insertItem( item );
  2999. }
  3000. else
  3001. mySignalSender->myListView->insertItem( item );
  3002. item->moveItem( parent );
  3003. if ( item == cuttedItem )
  3004. cuttedItem = 0;
  3005. }
  3006. void KDGanttCanvasView::cutItem()
  3007. {
  3008. lastClickedItem->hideSubtree();
  3009. //tqDebug("last clicked %d parent %d ", lastClickedItem , lastClickedItem->parent());
  3010. if ( lastClickedItem->parent() )
  3011. lastClickedItem->parent()->takeItem(lastClickedItem);
  3012. else
  3013. mySignalSender->myListView->takeItem( lastClickedItem );
  3014. mySignalSender->myTimeTable->updateMyContent();
  3015. if ( cuttedItem )
  3016. delete cuttedItem;
  3017. cuttedItem = lastClickedItem;
  3018. onItem->setItemEnabled( 3, true );
  3019. }
  3020. // called from the destructor in KDGanttViewItem or KDGanttView
  3021. void KDGanttCanvasView::resetCutPaste( KDGanttViewItem* item )
  3022. {
  3023. if ( item == 0 && cuttedItem ) {
  3024. delete cuttedItem;
  3025. cuttedItem = 0;
  3026. }
  3027. if (item == cuttedItem) {
  3028. onItem->setItemEnabled( 3, false );
  3029. cuttedItem = 0;
  3030. }
  3031. }
  3032. void KDGanttCanvasView::pasteItem( int type )
  3033. {
  3034. if ( !cuttedItem )
  3035. return;
  3036. switch( type ) {
  3037. case 0://root
  3038. mySignalSender->myListView->insertItem( cuttedItem );
  3039. break;
  3040. case 1://child
  3041. lastClickedItem->insertItem( cuttedItem );
  3042. break;
  3043. case 2://after
  3044. if ( lastClickedItem->parent() ) {
  3045. lastClickedItem->parent()->insertItem( cuttedItem );
  3046. }
  3047. else
  3048. mySignalSender->myListView->insertItem( cuttedItem );
  3049. cuttedItem->moveItem( lastClickedItem );
  3050. break;
  3051. default:
  3052. ;
  3053. }
  3054. cuttedItem = 0;
  3055. onItem->setItemEnabled( 3, false );
  3056. mySignalSender->myTimeTable->updateMyContent();
  3057. }
  3058. void KDGanttCanvasView::newRootItem(int type)
  3059. {
  3060. KDGanttViewItem* temp = 0;
  3061. switch( type ) {
  3062. case 1:
  3063. temp = new KDGanttViewEventItem( mySignalSender, i18n( "New Event" ) );
  3064. break;
  3065. case 0:
  3066. temp = new KDGanttViewSummaryItem( mySignalSender, i18n( "New Summary" ) );
  3067. break;
  3068. case 2:
  3069. temp = new KDGanttViewTaskItem( mySignalSender, i18n( "New Task" ) );
  3070. break;
  3071. default:
  3072. ;
  3073. }
  3074. if ( temp )
  3075. mySignalSender->editItem( temp );
  3076. }
  3077. void KDGanttCanvasView::newChildItem( int type )
  3078. {
  3079. KDGanttViewItem* temp = 0;
  3080. switch( type ) {
  3081. case 1:
  3082. temp = new KDGanttViewEventItem( lastClickedItem, i18n( "New Event" ) );
  3083. break;
  3084. case 0:
  3085. temp = new KDGanttViewSummaryItem( lastClickedItem, i18n( "New Summary" ) );
  3086. break;
  3087. case 2:
  3088. temp = new KDGanttViewTaskItem( lastClickedItem, i18n( "New Task" ) );
  3089. break;
  3090. case 5:
  3091. if ( lastClickedItem->parent() )
  3092. temp = new KDGanttViewEventItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Event" ) );
  3093. else
  3094. temp = new KDGanttViewEventItem( mySignalSender, lastClickedItem, i18n( "New Event" ) );
  3095. break;
  3096. case 4:
  3097. if ( lastClickedItem->parent() )
  3098. temp = new KDGanttViewSummaryItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Summary" ) );
  3099. else
  3100. temp = new KDGanttViewSummaryItem( mySignalSender, lastClickedItem, i18n( "New Summary" ) );
  3101. break;
  3102. case 6:
  3103. if ( lastClickedItem->parent() )
  3104. temp = new KDGanttViewTaskItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Task" ) );
  3105. else
  3106. temp = new KDGanttViewTaskItem( mySignalSender, lastClickedItem, i18n( "New Task" ) );
  3107. break;
  3108. default:
  3109. ;
  3110. }
  3111. if ( temp )
  3112. mySignalSender->editItem( temp );
  3113. }
  3114. void KDGanttCanvasView::drawToPainter ( TQPainter * p )
  3115. {
  3116. drawContents ( p, 0, 0, canvas()->width(), canvas()->height() );
  3117. }
  3118. TQString KDGanttCanvasView::getToolTipText(TQPoint p)
  3119. {
  3120. TQCanvasItemList il = canvas()->collisions ( viewportToContents( p ));
  3121. TQCanvasItemList::Iterator it;
  3122. for ( it = il.begin(); it != il.end(); ++it ) {
  3123. switch (getType(*it)) {
  3124. case Type_is_KDGanttViewItem:
  3125. return (getItem(*it))->tooltipText();
  3126. break;
  3127. case Type_is_KDGanttTaskLink:
  3128. return (getLink(*it))->tooltipText();
  3129. break;
  3130. default:
  3131. break;
  3132. }
  3133. }
  3134. return "";
  3135. }
  3136. TQString KDGanttCanvasView::getWhatsThisText(TQPoint p)
  3137. {
  3138. TQCanvasItemList il = canvas() ->collisions (viewportToContents( p ));
  3139. TQCanvasItemList::Iterator it;
  3140. for ( it = il.begin(); it != il.end(); ++it ) {
  3141. switch (getType(*it)) {
  3142. case Type_is_KDGanttViewItem:
  3143. return (getItem(*it))->whatsThisText();
  3144. break;
  3145. case Type_is_KDGanttTaskLink:
  3146. return (getLink(*it))->whatsThisText();
  3147. break;
  3148. default:
  3149. break;
  3150. }
  3151. }
  3152. return "";
  3153. }
  3154. /**
  3155. Handles the mouseevent if a mousekey is pressed
  3156. \param e the mouseevent
  3157. */
  3158. void KDGanttCanvasView::contentsMousePressEvent ( TQMouseEvent * e )
  3159. {
  3160. //tqDebug("mousepress! %d ", this);
  3161. //tqDebug("focus %d ",tqApp->focusWidget());
  3162. setFocus();
  3163. currentLink = 0;
  3164. currentItem = 0;
  3165. if (e->button() == Qt::RightButton && mySignalSender->editable()) {
  3166. lastClickedItem = (KDGanttViewItem*) mySignalSender->myListView->itemAt( TQPoint(2,e->pos().y()));
  3167. if ( lastClickedItem ) {
  3168. if ( lastClickedItem->displaySubitemsAsGroup() && ! lastClickedItem->isOpen() ) {
  3169. // findSub subitem
  3170. TQCanvasItemList il = canvas() ->collisions ( e->pos() );
  3171. TQCanvasItemList::Iterator it;
  3172. for ( it = il.begin(); it != il.end(); ++it ) {
  3173. if ( getType(*it) == Type_is_KDGanttViewItem ) {
  3174. lastClickedItem = getItem(*it);
  3175. }
  3176. }
  3177. }
  3178. if ( _showItemAddPopupMenu )
  3179. onItem->popup(e->globalPos());
  3180. }
  3181. }
  3182. TQCanvasItemList il = canvas() ->collisions ( e->pos() );
  3183. TQCanvasItemList::Iterator it;
  3184. for ( it = il.begin(); it != il.end(); ++it ) {
  3185. switch ( e->button() ) {
  3186. case Qt::LeftButton:
  3187. switch (getType(*it)) {
  3188. case Type_is_KDGanttViewItem:
  3189. currentItem = getItem(*it);
  3190. if (! currentItem->enabled() ) {
  3191. currentItem = 0;
  3192. } else if (linkItemsEnabled &&
  3193. !currentItem->isMyTextCanvas(*it)) {
  3194. fromArea = getItemArea(currentItem, e->pos().x());
  3195. if (fromArea > 0) {
  3196. fromItem = currentItem;
  3197. linkLine->setPoints(e->pos().x(), e->pos().y(), e->pos().x(), e->pos().y());
  3198. linkLine->show();
  3199. }
  3200. }
  3201. break;
  3202. case Type_is_KDGanttTaskLink:
  3203. currentLink = getLink(*it);
  3204. break;
  3205. default:
  3206. break;
  3207. }
  3208. break;
  3209. case Qt::RightButton:
  3210. switch (getType(*it)) {
  3211. case Type_is_KDGanttViewItem:
  3212. currentItem = getItem(*it);
  3213. if (! currentItem->enabled() )
  3214. currentItem = 0;
  3215. break;
  3216. case Type_is_KDGanttTaskLink:
  3217. currentLink = getLink(*it);
  3218. break;
  3219. }
  3220. break;
  3221. case Qt::MidButton:
  3222. switch (getType(*it)) {
  3223. case Type_is_KDGanttViewItem:
  3224. currentItem = getItem(*it);
  3225. if (! currentItem->enabled() )
  3226. currentItem = 0;
  3227. break;
  3228. case Type_is_KDGanttTaskLink:
  3229. currentLink = getLink(*it);
  3230. break;
  3231. }
  3232. break;
  3233. default:
  3234. break;
  3235. }
  3236. }
  3237. if (e->button() == Qt::RightButton ) {
  3238. mySignalSender->gvContextMenuRequested( currentItem, e->globalPos() );
  3239. }
  3240. if (autoScrollEnabled && e->button() == Qt::LeftButton) {
  3241. myScrollTimer->start(50);
  3242. }
  3243. }
  3244. /**
  3245. Handles the mouseevent if a mousekey is released
  3246. \param e the mouseevent
  3247. */
  3248. void KDGanttCanvasView::contentsMouseReleaseEvent ( TQMouseEvent * e )
  3249. {
  3250. static KDGanttViewItem* lastClicked = 0;
  3251. mySignalSender->gvMouseButtonClicked( e->button(), currentItem , e->globalPos() );
  3252. //tqDebug("datetime %s ",mySignalSender->getDateTimeForCoordX(e->globalPos().x(), true ).toString().latin1() );
  3253. //tqDebug("mousepos %d %d ",e->pos().x(),e->pos().y() );
  3254. //tqDebug("mouseup ");
  3255. // if ( currentLink || currentItem )
  3256. {
  3257. switch ( e->button() ) {
  3258. case Qt::LeftButton:
  3259. myScrollTimer->stop();
  3260. {
  3261. mySignalSender->itemLeftClicked( currentItem );
  3262. mySignalSender->gvItemLeftClicked( currentItem );
  3263. }
  3264. if ( currentLink )
  3265. mySignalSender->taskLinkLeftClicked( currentLink );
  3266. if (linkItemsEnabled && fromItem) {
  3267. linkLine->hide();
  3268. canvas()->update();
  3269. TQCanvasItemList il = canvas() ->collisions ( e->pos() );
  3270. TQCanvasItemList::Iterator it;
  3271. for ( it = il.begin(); it != il.end(); ++it ) {
  3272. if (getType(*it) == Type_is_KDGanttViewItem) {
  3273. KDGanttViewItem *toItem = getItem(*it);
  3274. if (!toItem->isMyTextCanvas(*it)) {
  3275. int toArea = getItemArea(toItem, e->pos().x());
  3276. if (toArea > 0 && toItem && fromItem != toItem) {
  3277. mySignalSender->linkItems(fromItem, toItem, getLinkType(fromArea, toArea));
  3278. }
  3279. }
  3280. break;
  3281. }
  3282. }
  3283. }
  3284. fromItem = 0;
  3285. break;
  3286. case Qt::RightButton:
  3287. {
  3288. mySignalSender->itemRightClicked( currentItem );
  3289. mySignalSender->gvItemRightClicked( currentItem );
  3290. }
  3291. if ( currentLink )
  3292. mySignalSender->taskLinkRightClicked( currentLink );
  3293. break;
  3294. case Qt::MidButton:
  3295. {
  3296. mySignalSender->itemMidClicked( currentItem );
  3297. mySignalSender->gvItemMidClicked( currentItem );
  3298. }
  3299. if ( currentLink )
  3300. mySignalSender->taskLinkRightClicked( currentLink );
  3301. break;
  3302. default:
  3303. break;
  3304. }
  3305. }
  3306. if ( lastClicked != currentItem )
  3307. mySignalSender->gvCurrentChanged( currentItem );
  3308. lastClicked = currentItem;
  3309. currentLink = 0;
  3310. currentItem = 0;
  3311. }
  3312. /**
  3313. Handles the mouseevent if a mousekey is doubleclicked
  3314. \param e the mouseevent
  3315. */
  3316. void KDGanttCanvasView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
  3317. {
  3318. TQCanvasItemList il = canvas() ->collisions ( e->pos() );
  3319. TQCanvasItemList::Iterator it;
  3320. for ( it = il.begin(); it != il.end(); ++it ) {
  3321. switch ( e->button() ) {
  3322. case Qt::LeftButton:
  3323. switch (getType(*it)) {
  3324. case Type_is_KDGanttViewItem:
  3325. if ( getItem(*it)->enabled() )
  3326. mySignalSender->itemDoubleClicked(getItem(*it));
  3327. mySignalSender->gvItemDoubleClicked(getItem(*it));
  3328. return;
  3329. break;
  3330. case Type_is_KDGanttTaskLink:
  3331. mySignalSender->taskLinkDoubleClicked(getLink(*it));
  3332. return;
  3333. break;
  3334. default:
  3335. break;
  3336. }
  3337. break;
  3338. /*
  3339. case RightButton:
  3340. switch (getType(*it)) {
  3341. case Type_is_KDGanttViewItem:
  3342. mySignalSender->itemRightClicked(getItem(*it));
  3343. return;
  3344. break;
  3345. case Type_is_KDGanttTaskLink:
  3346. mySignalSender->taskLinkRightClicked(getLink(*it));
  3347. return;
  3348. break;
  3349. }
  3350. break;
  3351. case MidButton:
  3352. switch (getType(*it)) {
  3353. case Type_is_KDGanttViewItem:
  3354. mySignalSender->itemMidClicked(getItem(*it));
  3355. return;
  3356. break;
  3357. case Type_is_KDGanttTaskLink:
  3358. mySignalSender->taskLinkMidClicked(getLink(*it));
  3359. return;
  3360. break;
  3361. }
  3362. break;
  3363. */
  3364. default:
  3365. break;
  3366. }
  3367. }
  3368. }
  3369. /**
  3370. Handles the mouseevent if a mousekey is pressed an the mouse is moved
  3371. \param e the mouseevent
  3372. */
  3373. void KDGanttCanvasView::contentsMouseMoveEvent ( TQMouseEvent *e )
  3374. {
  3375. //tqDebug("mousemove! ");
  3376. static int moves = 0;
  3377. if ( (currentLink || currentItem) && (moves < 3) ) {
  3378. ++moves;
  3379. } else {
  3380. moves = 0;
  3381. currentLink = 0;
  3382. currentItem = 0;
  3383. }
  3384. if (autoScrollEnabled)
  3385. mousePos = e->pos()- TQPoint(contentsX(),contentsY()); // make mousePos relative 0
  3386. if (fromItem) {
  3387. //tqDebug("mousemove: linking %s: %d,%d ",fromItem->listViewText().latin1(), e->pos().x(), e->pos().y());
  3388. linkLine->setPoints(linkLine->startPoint().x(), linkLine->startPoint().y(), e->pos().x(), e->pos().y());
  3389. canvas()->update();
  3390. }
  3391. // no action implemented
  3392. //tqDebug("mousemove ");
  3393. //TQToolTip::setGloballyEnabled (false);
  3394. //TQToolTip::remove(viewport());
  3395. // TQToolTip::add(viewport(), "hello");
  3396. // TQToolTip::setGloballyEnabled (true);
  3397. /*
  3398. TQCanvasItemList il = canvas() ->collisions ( e->pos() );
  3399. TQCanvasItemList::Iterator it;
  3400. KDGanttItem* mouseover = 0;
  3401. for ( it = il.begin(); it != il.end(); ++it ) {
  3402. }
  3403. */
  3404. }
  3405. void KDGanttCanvasView::viewportPaintEvent ( TQPaintEvent * pe )
  3406. {
  3407. TQCanvasView::viewportPaintEvent ( pe );
  3408. }
  3409. void KDGanttCanvasView::set_Mouse_Tracking(bool on)
  3410. {
  3411. viewport()->setMouseTracking(on);
  3412. }
  3413. int KDGanttCanvasView::getType(TQCanvasItem* it)
  3414. {
  3415. switch (it->rtti()) {
  3416. case TQCanvasItem::Rtti_Line: return ((KDCanvasLine*)it)->myParentType;
  3417. case TQCanvasItem::Rtti_Ellipse: return ((KDCanvasEllipse *)it)->myParentType;
  3418. case TQCanvasItem::Rtti_Text: return ((KDCanvasText *)it)->myParentType;
  3419. case TQCanvasItem::Rtti_Polygon: return ((KDCanvasPolygon *)it)->myParentType;
  3420. case TQCanvasItem::Rtti_Rectangle: return ((KDCanvasRectangle *)it)->myParentType;
  3421. }
  3422. return -1;
  3423. }
  3424. KDGanttViewItem* KDGanttCanvasView::getItem(TQCanvasItem* it)
  3425. {
  3426. switch (it->rtti()) {
  3427. case TQCanvasItem::Rtti_Line: return (KDGanttViewItem*) ((KDCanvasLine*)it)->myParentItem;
  3428. case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewItem*) ((KDCanvasEllipse *)it)->myParentItem;
  3429. case TQCanvasItem::Rtti_Text: return (KDGanttViewItem*) ((KDCanvasText *)it)->myParentItem;
  3430. case TQCanvasItem::Rtti_Polygon: return (KDGanttViewItem*) ((KDCanvasPolygon *)it)->myParentItem;
  3431. case TQCanvasItem::Rtti_Rectangle: return (KDGanttViewItem*) ((KDCanvasRectangle *)it)->myParentItem;
  3432. }
  3433. return 0;
  3434. }
  3435. KDGanttViewTaskLink* KDGanttCanvasView::getLink(TQCanvasItem* it)
  3436. {
  3437. switch (it->rtti()) {
  3438. case TQCanvasItem::Rtti_Line: return (KDGanttViewTaskLink*) ((KDCanvasLine*)it)->myParentItem;
  3439. case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewTaskLink*) ((KDCanvasEllipse *)it)->myParentItem;
  3440. case TQCanvasItem::Rtti_Text: return (KDGanttViewTaskLink*) ((KDCanvasText *)it)->myParentItem;
  3441. case TQCanvasItem::Rtti_Polygon: return (KDGanttViewTaskLink*) ((KDCanvasPolygon *)it)->myParentItem;
  3442. }
  3443. return 0;
  3444. }
  3445. void KDGanttCanvasView::slotScrollTimer() {
  3446. int mx = mousePos.x();
  3447. int my = mousePos.y();
  3448. int dx = 0;
  3449. int dy = 0;
  3450. if (mx < 0)
  3451. dx = -5;
  3452. else if (mx > visibleWidth())
  3453. dx = 5;
  3454. if (my < 0)
  3455. dy = -5;
  3456. else if (my > visibleHeight())
  3457. dy = TQMIN(5, verticalScrollBar()->maxValue()-verticalScrollBar()->value());
  3458. if (dx != 0 || dy != 0)
  3459. scrollBy(dx, dy);
  3460. }
  3461. int KDGanttCanvasView::getItemArea(KDGanttViewItem *item, int x) {
  3462. // area can be: no area = 0, Start = 1, Finish = 2
  3463. // TODO: middle (move, dnd), front, back (resize)
  3464. KDTimeTableWidget *tt = dynamic_cast<KDTimeTableWidget *>(canvas());
  3465. if (!tt) {
  3466. tqWarning("Cannot cast canvas to KDTimeTableWidget");
  3467. return 0;
  3468. }
  3469. int area = 0;
  3470. int start = tt->getCoordX(item->startTime());
  3471. int end = start;
  3472. if (item->type() == KDGanttViewItem::Event) {
  3473. x > start ? area = 2 : area = 1;
  3474. } else {
  3475. end = tt->getCoordX(item->endTime());
  3476. if ((end - start)/2 > (x - start))
  3477. area = 1;
  3478. else
  3479. area = 2;
  3480. }
  3481. return area;
  3482. }
  3483. int KDGanttCanvasView::getLinkType(int from, int to) {
  3484. // from, to should be Start = 1 or Finish = 2
  3485. if ((from == 1) && (to == 1)) {
  3486. return KDGanttViewTaskLink::StartStart;
  3487. }
  3488. if ((from == 1) && (to == 2)) {
  3489. return KDGanttViewTaskLink::StartFinish;
  3490. }
  3491. if ((from == 2) && (to == 1)) {
  3492. return KDGanttViewTaskLink::FinishStart;
  3493. }
  3494. if ((from == 2) && (to == 2)) {
  3495. return KDGanttViewTaskLink::FinishFinish;
  3496. }
  3497. return KDGanttViewTaskLink::None;
  3498. }