kdgantt

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