kdgantt

KDGanttViewSubwidgets.cpp
1/*
2 $Id: KDGanttViewSubwidgets.cpp 669475 2007-05-29 13:44:48Z mueller $
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
61KDTimeTableWidget:: 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
80TQPtrList<KDGanttViewTaskLink> KDTimeTableWidget::taskLinks()
81{
82 return myTaskLinkList;
83}
84
85void 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
95void 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
110void 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
123void KDTimeTableWidget::setNoInformationBrush( const TQBrush& brush )
124{
125 noInfoLineBrush = brush;
126 updateMyContent();
127}
128TQBrush KDTimeTableWidget::noInformationBrush() const
129{
130 return noInfoLineBrush;
131}
132
133void KDTimeTableWidget::removeItemFromTasklinks( KDGanttViewItem* item)
134{
135 TQPtrListIterator<KDGanttViewTaskLink> it((myTaskLinkList));
136 for ( ; it.current(); ++it ) {
137 it.current()->removeItemFromList( item );
138 }
139}
140
141void KDTimeTableWidget::expandItem( TQListViewItem * item)
142{
143 item->invalidateHeight () ;
144 //tqApp->processEvents();
145 updateMyContent();
146}
147void KDTimeTableWidget::collapseItem( TQListViewItem * item)
148{
149 item->invalidateHeight () ;
150 //tqApp->processEvents();
151 updateMyContent();
152}
153
154void 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}
167int 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}
186void 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( TQt::NoPen );
233 itcol.current()->setBrush( TQBrush( colcol, 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( TQt::NoPen );
247 temprect->setBrush( TQBrush( colcol, 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( TQt::NoPen );
279 itcol.current()->setBrush( TQBrush( colcol, 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( TQt::NoPen );
287 temprect->setBrush( TQBrush( colcol, 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( TQt::NoPen );
335 itcol.current()->setBrush( TQBrush( colcol, 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( TQt::NoPen );
343 temprect->setBrush( TQBrush( colcol, 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( TQt::NoPen );
389 itcol.current()->setBrush( TQBrush( colcol, 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( TQt::NoPen );
397 temprect->setBrush( TQBrush( colcol, 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}
434void 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
488void 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}
536void 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
571void 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
586void 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
646void KDTimeTableWidget::inc_blockUpdating( )
647{
648 ++ int_blockUpdating;
649}
650// used for blocking recursive methods
651void KDTimeTableWidget::dec_blockUpdating( )
652{
653 -- int_blockUpdating;
654}
655// if false(i.e. unblock), sets int_blockUpdating to 0
656void KDTimeTableWidget::setBlockUpdating( bool block )
657{
658 if ( !block )
659 int_blockUpdating = 0;
660 flag_blockUpdating = block;
661}
662bool KDTimeTableWidget::blockUpdating()
663{
664 return flag_blockUpdating;
665}
666
667void KDTimeTableWidget::setShowTaskLinks( bool show )
668{
669 taskLinksVisible = show;
670 updateMyContent();
671}
672bool KDTimeTableWidget::showTaskLinks()
673{
674 return taskLinksVisible;
675}
676void KDTimeTableWidget::setHorBackgroundLines( int count, TQBrush brush )
677{
678 denseLineBrush = brush;
679 denseLineCount = 0;
680 if ( count > 1 )
681 denseLineCount = count;
682}
683
684
685int KDTimeTableWidget::horBackgroundLines( TQBrush& brush )
686{
687 brush = denseLineBrush;
688 return denseLineCount;
689}
690
691int KDTimeTableWidget::getCoordX( TQDateTime dt ) {
692 return myGanttView->myTimeHeader->getCoordX(dt);
693}
694
695/* ***************************************************************
696 KDTimeHeaderWidget:: KDTimeHeaderWidget
697 ***************************************************************** */
698KDTimeHeaderWidget:: 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
780KDTimeHeaderWidget::~KDTimeHeaderWidget()
781{
782 delete myToolTip;
783}
784void 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
825TQString KDTimeHeaderWidget::getToolTipText(TQPoint p)
826{
827 return TDEGlobal::locale()->formatDateTime(getDateTimeForIndex(p.x()));
828}
829void KDTimeHeaderWidget::addTickRight( int num )
830{
831 int secs = ((num*getTickTime())-30);
832 setHorizonEnd(getDateTimeForIndex(width()).addSecs(secs));
833 //tqApp->processEvents();
834}
835
836void 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
843int KDTimeHeaderWidget::getTickTime()
844{
845 return getDateTimeForIndex(0).secsTo(getDateTimeForIndex(myGridMinorWidth));
846}
847
848
849void 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
868bool 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
916bool 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
967void 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
985bool KDTimeHeaderWidget::showPopupMenu() const
986{
987 return flagShowPopupMenu;
988}
989
990void 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}
1085void 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}
1093double KDTimeHeaderWidget::zoomFactor()
1094{
1095 return myZoomFactor;
1096}
1097double 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
1109void 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}
1149void KDTimeHeaderWidget::moveTimeLineTo(int X)
1150{
1151 int Y = myGanttView->myCanvasView->contentsY ();
1152 myGanttView->myCanvasView->setContentsPos (X, Y );
1153}
1154
1155void 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
1192void KDTimeHeaderWidget::setHorizonStart( const TQDateTime& start )
1193{
1194 myHorizonStart = start;
1195 flagStartTimeSet = true;
1196 computeTicks();
1197}
1198
1199
1206TQDateTime KDTimeHeaderWidget::horizonStart() const
1207{
1208 return myHorizonStart;
1209}
1210
1211
1219void KDTimeHeaderWidget::setHorizonEnd( const TQDateTime& start )
1220{
1221 myHorizonEnd = start;
1222 flagEndTimeSet = true;
1223 computeTicks();
1224
1225}
1226
1227
1234TQDateTime KDTimeHeaderWidget::horizonEnd() const
1235{
1236 return myHorizonEnd;
1237}
1238
1239
1248void 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->updateScrollBars();
1256}
1257
1258
1265KDTimeHeaderWidget::Scale KDTimeHeaderWidget::scale() const
1266{
1267 return myScale;
1268}
1269
1270
1277void KDTimeHeaderWidget::setMaximumScale( Scale unit )
1278{
1279 myMaxScale = unit;
1280 computeTicks();
1281}
1282
1283
1290KDTimeHeaderWidget::Scale KDTimeHeaderWidget::maximumScale() const
1291{
1292 return myMaxScale;
1293}
1294
1295
1302void KDTimeHeaderWidget::setMinimumScale( Scale unit )
1303{
1304 myMinScale = unit;
1305 computeTicks();
1306}
1307
1308
1315KDTimeHeaderWidget::Scale KDTimeHeaderWidget::minimumScale() const
1316{
1317 return myMinScale;
1318}
1319
1320
1329void KDTimeHeaderWidget::setMinimumColumnWidth( int width )
1330{
1331 myMinimumColumWidth = width;
1332 computeTicks();
1333}
1334
1335
1342int KDTimeHeaderWidget::minimumColumnWidth() const
1343{
1344 return myMinimumColumWidth;
1345}
1346
1347
1355void KDTimeHeaderWidget::setYearFormat( YearFormat format )
1356{
1357 myYearFormat = format;
1358 computeTicks();
1359}
1360
1361
1368KDTimeHeaderWidget::YearFormat KDTimeHeaderWidget::yearFormat() const
1369{
1370 return myYearFormat;
1371}
1372
1373
1381void KDTimeHeaderWidget::setHourFormat( HourFormat format )
1382{
1383 myHourFormat = format;
1384 computeTicks();
1385}
1386
1387
1394KDTimeHeaderWidget::HourFormat KDTimeHeaderWidget::hourFormat() const
1395{
1396 return myHourFormat;
1397}
1398
1399
1406void KDTimeHeaderWidget::setShowMajorTicks( bool show )
1407{
1408 flagShowMajorTicks = show;
1409 if (show) {
1410 setShowMinorTicks(false);
1411 }
1412 updateTimeTable();
1413}
1414
1415
1422bool KDTimeHeaderWidget::showMajorTicks() const
1423{
1424 return flagShowMajorTicks;
1425}
1426
1427
1434void KDTimeHeaderWidget::setShowMinorTicks( bool show )
1435{
1436 flagShowMinorTicks = show;
1437 if (show)
1438 setShowMajorTicks(false );
1439 //repaintMe();
1440 updateTimeTable();
1441}
1442
1443
1450bool KDTimeHeaderWidget::showMinorTicks() const
1451{
1452 return flagShowMinorTicks;
1453}
1454
1455
1464void 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
1486void KDTimeHeaderWidget::computeIntervals( int height )
1487{
1488
1489 IntervalColorList::iterator it;
1490 int left, right;
1491 for ( it = icList.begin(); it != icList.end(); ++it ) {
1492 if ( (*it).minScaleView <= myRealScale && (*it).maxScaleView >= myRealScale ) {
1493 left = getCoordX((*it).datetime);
1494 right = getCoordX((*it).end);
1495 if ( right == left )
1496 ++right;
1497 (*it).canvasRect->setPen( TQt::NoPen );
1498 (*it).canvasRect->setBrush( TQBrush( (*it).color, SolidPattern) );
1499 (*it).canvasRect->setSize( right - left ,height );
1500 (*it).canvasRect->move( left,0 );
1501 (*it).canvasRect->show();
1502 } else {
1503 (*it).canvasRect->hide();
1504 /*
1505 (*it).canvasLine->setPen( TQPen( (*it).color, right - left ) );
1506 (*it).canvasLine->setPoints( mid ,0 ,mid ,height );
1507 (*it).canvasLine->show();
1508 } else {
1509 (*it).canvasLine->hide();
1510 */
1511 }
1512 }
1513}
1514bool KDTimeHeaderWidget::changeBackgroundInterval( const TQDateTime& oldstart,
1515 const TQDateTime& oldend,
1516 const TQDateTime& newstart,
1517 const TQDateTime& newend )
1518{
1519 IntervalColorList::iterator it;
1520 for ( it = icList.begin(); it != icList.end(); ++it ) {
1521 if ((*it).datetime == oldstart && (*it).end == oldend ) {
1522 IntervalColorList::iterator it2;
1523 for ( it2 = icList.begin(); it2 != icList.end(); ++it2 ) {
1524 if ((*it2).datetime == newstart && (*it2).end == newend )
1525 return false;
1526 }
1527 (*it).datetime = newstart;
1528 (*it).end = newend;
1529 updateTimeTable();
1530 return true;
1531 }
1532 }
1533 return false;
1534}
1535bool KDTimeHeaderWidget::deleteBackgroundInterval( const TQDateTime& start,
1536 const TQDateTime& end)
1537{
1538 IntervalColorList::iterator it;
1539 for ( it = icList.begin(); it != icList.end(); ++it ) {
1540 if ((*it).datetime == start && (*it).end == end ) {
1541 //delete (*it).canvasLine;
1542 delete (*it).canvasRect;
1543 icList.remove(it);
1544 updateTimeTable();
1545 return true;
1546 }
1547 }
1548 return false;
1549}
1550
1551void KDTimeHeaderWidget::setIntervalBackgroundColor( const TQDateTime& start,
1552 const TQDateTime& end,
1553 const TQColor& color,
1554 Scale mini ,
1555 Scale maxi )
1556{
1557
1558 IntervalColorList::iterator it;
1559 for ( it = icList.begin(); it != icList.end(); ++it ) {
1560 if ((*it).datetime == start && (*it).end == end ) {
1561 (*it).color = color;
1562 (*it).minScaleView = mini;
1563 (*it).maxScaleView = maxi;
1564 return;
1565 }
1566 }
1567 DateTimeColor newItem;
1568 if ( start <= end ) {
1569 newItem.datetime = start;
1570 newItem.end = end;
1571 } else {
1572 newItem.datetime = end;
1573 newItem.end = start;
1574 }
1575 newItem.color = color;
1576 newItem.minScaleView = mini;
1577 newItem.maxScaleView = maxi;
1578 //newItem.canvasLine = new KDCanvasLine(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
1579 newItem.canvasRect = new KDCanvasRectangle(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
1580 newItem.canvasRect->setZ(-19);
1581 icList.append(newItem);
1582 updateTimeTable();
1583
1584}
1585void KDTimeHeaderWidget::clearBackgroundColor()
1586{
1587
1588 IntervalColorList::iterator itic;
1589 for ( itic = icList.begin(); itic != icList.end(); ++itic ) {
1590 delete (*itic).canvasRect;
1591 }
1592 ccList.clear();
1593 icList.clear();
1594 updateTimeTable();
1595}
1596TQDateTime KDTimeHeaderWidget::getDateTimeForIndex(int X, bool local )
1597{
1598 int coordX = X;
1599 if ( !local ) {
1600 TQPoint p = TQPoint ( X, 1 );
1601 coordX = myGanttView->myTimeHeaderScroll->viewportToContents(myGanttView->myTimeHeaderScroll->mapFromGlobal( p )).x();
1602
1603 }
1604 double secs = (secsFromTo( myRealStart, myRealEnd ) * ((double)coordX))/(double)width();
1605 double days = secs/86400.0;
1606 secs = secs - ( ((int) days) *86400.0 );
1607 return (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
1608}
1609
1610//FIXME: This doesn't work quite intuitively (imho) when scale is day
1611// and each column containes more than 1 day:
1612// 1) If a column includes a weekend day, the whole column gets weekend color,
1613// 2) If a column includes 7 days, either *all* columns get weekend color, or
1614// *none* get weekend color (haven't figured out why)
1615// Proposal: Only use weekend color if the whole column is a weekend.
1616// Alt: Color the area that actually is the weekend.
1617bool KDTimeHeaderWidget::getColumnColor(TQColor& col,int coordLow, int coordHigh)
1618{
1619 if (!flagShowMajorTicks && !flagShowMinorTicks)
1620 return false;
1621 TQDateTime start,end;
1622 start = getDateTimeForIndex(coordLow);
1623 end = getDateTimeForIndex(coordHigh).addSecs(-1);
1624 Scale tempScale = myRealScale;
1625 if (flagShowMajorTicks)
1626 switch (myRealScale)
1627 {
1628 case KDGanttView::Minute: tempScale = KDGanttView::Hour; break;
1629 case KDGanttView::Hour: tempScale = KDGanttView::Day ; break;
1630 case KDGanttView::Day: tempScale = KDGanttView::Week ; break;
1631 case KDGanttView::Week: tempScale = KDGanttView::Month ; break;
1632 case KDGanttView::Month: return false ; break;
1633 case KDGanttView::Auto: return false ; break;
1634 }
1635 //check defined column color
1636 ColumnColorList::iterator it;
1637 for ( it = ccList.begin(); it != ccList.end(); ++it ) {
1638 if ((*it).datetime >= start && (*it).datetime <= end) {
1639 if (tempScale >= (*it).minScaleView && tempScale <= (*it).maxScaleView ) {
1640 col = (*it).color;
1641 return true;
1642 }
1643 }
1644 }
1645
1646 if (tempScale > KDGanttView::Day) return false;
1647
1648 start = getDateTimeForIndex((coordLow+coordHigh)/2);
1649 int day = start.date().dayOfWeek ();
1650 //checkweekdaycolor
1651 if (weekdayColor[day] != TQt::white) {
1652 col = weekdayColor[day];
1653 return true;
1654 }
1655 //checkweekendcolor
1656 int endday = myWeekendDaysEnd;
1657 col = myWeekendBackgroundColor;
1658 if (myWeekendDaysStart > myWeekendDaysEnd)
1659 endday +=7;
1660 if (day >= myWeekendDaysStart && day <= endday) {
1661 return true;
1662 } else {
1663 if (day+7 >= myWeekendDaysStart && day+7 <= endday) {
1664 return true;
1665 }
1666 }
1667 return false;
1668}
1669
1678TQColor KDTimeHeaderWidget::columnBackgroundColor( const TQDateTime& column ) const
1679{
1680 TQColor c;
1681 c = white;
1682 ColumnColorList::const_iterator ite;
1683 for ( ite = ccList.begin(); ite != ccList.end(); ++ite ) {
1684 if ((*ite).datetime == column) {
1685 c = (*ite).color;
1686 }
1687 }
1688 return c;
1689}
1690
1691
1700void KDTimeHeaderWidget::setWeekendBackgroundColor( const TQColor& color )
1701{
1702 myWeekendBackgroundColor = color ;
1703 updateTimeTable();
1704}
1705
1706
1713TQColor KDTimeHeaderWidget::weekendBackgroundColor() const
1714{
1715 return myWeekendBackgroundColor;
1716}
1717
1728void KDTimeHeaderWidget::setWeekdayBackgroundColor( const TQColor& color, int weekday )
1729{
1730 weekdayColor[weekday] = color;
1731 updateTimeTable();
1732}
1733
1734
1742TQColor KDTimeHeaderWidget::weekdayBackgroundColor(int weekday) const
1743{
1744 return weekdayColor[weekday];
1745}
1746
1747
1758void KDTimeHeaderWidget::setWeekendDays( int start, int end )
1759{
1760 myWeekendDaysStart = start;
1761 myWeekendDaysEnd = end;
1762 updateTimeTable();
1763}
1764
1765
1773void KDTimeHeaderWidget::weekendDays( int& start, int& end ) const
1774{
1775 start = myWeekendDaysStart;
1776 end = myWeekendDaysEnd ;
1777}
1778
1779
1780
1787void KDTimeHeaderWidget::setMajorScaleCount( int count )
1788{
1789 myMajorScaleCount=count;
1790 computeTicks();
1791}
1792
1793
1800int KDTimeHeaderWidget::majorScaleCount() const
1801{
1802 return myMajorScaleCount;
1803}
1804
1805
1812void KDTimeHeaderWidget::setMinorScaleCount( int count )
1813{
1814 myMinorScaleCount = count;
1815 computeTicks();
1816}
1817
1818
1825int KDTimeHeaderWidget::minorScaleCount() const
1826{
1827 return myMinorScaleCount ;
1828
1829}
1830
1831
1832void KDTimeHeaderWidget::resizeEvent ( TQResizeEvent * )
1833{
1834 // tqDebug("KDTimeHeaderWidget:: resizeEvent ");
1835 paintPix.resize( 800, height () );
1836}
1837
1838
1839void KDTimeHeaderWidget::updateTimeTable()
1840{
1841 //tqDebug("KDTimeHeaderWidget::updateTimeTable() ");
1842 if (flagDoNotRecomputeAfterChange) return;
1843 // setting the scrolling steps
1844 int scrollLineStep = myGridMinorWidth;
1845 if (showMajorTicks()) {
1846 TQValueList<int>::iterator intIt = majorTicks.begin();
1847 scrollLineStep = 5 * myGridMinorWidth;
1848 if (intIt != majorTicks.end()) {
1849 int left = *intIt;
1850 ++intIt;
1851 if (intIt != majorTicks.end()) {
1852 scrollLineStep = *intIt-left;
1853 }
1854 }
1855 }
1856 myGanttView->myCanvasView->horizontalScrollBar()->setLineStep(scrollLineStep);
1857 myGanttView->myTimeTable->maximumComputedGridHeight = 0;
1858 myGanttView->myTimeTable->updateMyContent();
1859}
1860
1861
1862void KDTimeHeaderWidget::setAutoScaleMinorTickCount( int count )
1863{
1864 myAutoScaleMinorTickcount = count;
1865 computeTicks();
1866
1867}
1868
1869
1870int KDTimeHeaderWidget::autoScaleMinorTickCount()
1871{
1872 return myAutoScaleMinorTickcount;
1873}
1874
1875
1876void KDTimeHeaderWidget::repaintMe(int left,int paintwid, TQPainter* painter)
1877{
1878 if (flagDoNotRecomputeAfterChange) return;
1879 TQColorGroup qcg =TQColorGroup( white, black,white, darkGray,black,gray,gray) ;
1880 TQPainter* p;
1881 int offsetLeft = 0;
1882 if ( paintwid > paintPix.width()-100 )
1883 paintPix.resize( paintwid+100, height () );
1884 if ( painter )
1885 p = painter;
1886 else {
1887 p = new TQPainter( &paintPix );
1888 offsetLeft = left-50;
1889 }
1890 if ( mouseDown ) {
1891 p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
1892 int start ;
1893 int wid;
1894 if ( beginMouseDown < endMouseDown ) {
1895 start = beginMouseDown ;
1896 wid = endMouseDown - beginMouseDown ;
1897 } else {
1898 start = endMouseDown ;
1899 wid = -endMouseDown + beginMouseDown ;
1900 }
1901 p->fillRect( start-offsetLeft, 0, wid, height(), TQBrush(paletteBackgroundColor().dark()) );
1902 } else {
1903 if (! painter )
1904 p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
1905 }
1906 p->setPen(TQColor(40,40,40));
1907 TQFont tempFont = p->font();
1908 tempFont.setWeight(63);
1909 p->setFont(tempFont);
1910 int hei1 = myMajorGridHeight,
1911 hei2 = height(),
1912 wid1 = myGridMinorWidth;
1913 int xCoord;
1914 int lwid = 1;
1915
1916 TQValueList<TQString>::iterator it;
1917 TQValueList<int>::iterator intIt = majorTicks.begin();
1918 for ( it = majorText.begin(); it != majorText.end(); ++it ) {
1919 xCoord = (*intIt++);
1920 if (((*intIt)>= left && xCoord <= left+paintwid)) {
1921 qDrawShadeLine ( p,xCoord-offsetLeft ,hei1+1, xCoord-offsetLeft, -2, qcg, true, lwid, 1 );
1922 p->drawText(xCoord+4-offsetLeft,hei1-4,(*it));
1923 }
1924 }
1925 qDrawShadeLine ( p,left-offsetLeft ,hei1, left+paintwid-offsetLeft, hei1, qcg, true, lwid, 1 );
1926 int i = 0;
1927 for ( it = minorText.begin(); it != minorText.end(); ++it ) {
1928 if (i*wid1 >= left-wid1 && i*wid1 <= left+paintwid) {
1929 qDrawShadeLine ( p,i*wid1-offsetLeft ,hei1-1, i*wid1-offsetLeft, hei2, qcg, true, lwid, 1 );
1930 p->drawText(i*wid1+1-offsetLeft,hei1+1,wid1-1,hei2-hei1,TQt::AlignCenter,(*it));
1931 }
1932 ++i;
1933 }
1934 p->setPen(black);
1935 p->drawLine(left-offsetLeft,hei1,left+paintwid-offsetLeft,hei1);
1936 qDrawShadeLine ( p,left-offsetLeft ,hei2-1, left+paintwid-offsetLeft, hei2-1, qcg, true, lwid, 1 );
1937 p->drawLine(left-offsetLeft,hei2-1,left+paintwid-offsetLeft,hei2-1);
1938 if ( !painter ) {
1939 p->end();
1940 delete p;
1941 bitBlt ( this, left, 0, &paintPix, 50, 0, paintwid, height() );
1942 }
1943}
1944
1945// cuts the secs in the DateTime if scale is Minute ,
1946// the minutes and secs if scale is Hour and so on
1947
1948TQDateTime KDTimeHeaderWidget::getEvenTimeDate(TQDateTime tempdatetime ,Scale sc)
1949{
1950 TQDate tempdate;
1951 int min, hour;
1952 int tempMinorScaleCount = myRealMinorScaleCount;
1953 switch (sc)
1954 {
1955 case KDGanttView::Month:
1956 tempdate = tempdatetime.date();
1957 while (tempdate.day ()!= 1 )
1958 tempdate = tempdate.addDays(-1);
1959 //while (tempdate.month ()!= 1 )
1960 //tempdate = tempdate.addMonths(-1);
1961 tempdatetime = TQDateTime (tempdate, TQTime (0,0));
1962 break;
1963 case KDGanttView::Week:
1964 tempdate = tempdatetime.date();
1965 while (tempdate.dayOfWeek ()!= TDEGlobal::locale()->weekStartDay())
1966 tempdate = tempdate.addDays(-1);
1967 //tempdate = tempdate.addDays(-7);
1968 tempdatetime = TQDateTime (tempdate, TQTime (0,0));
1969 break;
1970 case KDGanttView::Day:
1971 tempdatetime = TQDateTime (tempdatetime.date(), TQTime ( 0,0 ) );
1972 break;
1973 case KDGanttView::Hour:
1974 hour = tempdatetime.time().hour();
1975 while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
1976 ++tempMinorScaleCount;
1977 hour = ( hour /tempMinorScaleCount)*tempMinorScaleCount;
1978 tempdatetime = TQDateTime (tempdatetime.date(), TQTime (hour, 0 ));
1979 break;
1980 case KDGanttView::Minute:
1981 min = tempdatetime.time().minute();
1982 while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
1983 ++tempMinorScaleCount;
1984 // tqDebug("myMinorScaleCount %d %d %d",myMinorScaleCount, myRealMinorScaleCount, tempMinorScaleCount);
1985 min = (min /tempMinorScaleCount)*tempMinorScaleCount;
1986 tempdatetime = TQDateTime (tempdatetime.date(), TQTime (tempdatetime.time().hour(),min ));
1987
1988 break;
1989 case KDGanttView::Auto:
1990 break;
1991 }
1992 return tempdatetime;
1993}
1994
1995
1996void KDTimeHeaderWidget::computeRealScale(TQDateTime start)
1997{
1998
1999 if (myScale ==KDGanttView::Auto) {
2000 //tqDebug("Autoscale ");
2001 //double secsPerMinor = (((double)start.daysTo(myHorizonEnd))* 86400.00)/((double)myAutoScaleMinorTickcount);
2002 double secsPerMinor = (((double)start.secsTo(myHorizonEnd)))/((double)myAutoScaleMinorTickcount);
2003 secsPerMinor /= myZoomFactor;
2004 if (secsPerMinor <= 1800) {
2005 myRealScale = KDGanttView::Minute;
2006 myRealMinorScaleCount = (int) secsPerMinor/60;
2007 } else {
2008 if (secsPerMinor <= 12*3600) {
2009 myRealScale = KDGanttView::Hour;
2010 myRealMinorScaleCount = (int) secsPerMinor/3600;
2011 } else {
2012 if (secsPerMinor <= 24*3600*3) {
2013 myRealScale = KDGanttView::Day;
2014 myRealMinorScaleCount = (int) secsPerMinor/(3600*24);
2015 } else {
2016 if (secsPerMinor <= 24*3600*14) {
2017 myRealScale = KDGanttView::Week;
2018 myRealMinorScaleCount = (int) secsPerMinor/(3600*24*7);
2019 } else {
2020 myRealScale = KDGanttView::Month;
2021 myRealMinorScaleCount = (int) secsPerMinor/(3600*24*30);
2022
2023 }
2024 }
2025 }
2026 }
2027 if(myRealMinorScaleCount == 0)
2028 myRealMinorScaleCount = 1;
2029 myRealMajorScaleCount = 1;
2030 }
2031 else {
2032 //tqDebug("Fixed scale ");
2033 myRealScale = myScale;
2034 if (myRealScale > myMaxScale)
2035 myRealScale = myMaxScale;
2036 if (myRealScale < myMinScale)
2037 myRealScale = myMinScale;
2038 myRealMinorScaleCount = (int) ( ((double)myMinorScaleCount) /myZoomFactor );
2039 double tempZoom = myZoomFactor;
2040 myRealMajorScaleCount = myMajorScaleCount;
2041 while (myRealMinorScaleCount == 0) {
2042 if (myRealScale == myMinScale) {
2043 myRealMinorScaleCount = 1;
2044 break;
2045 }
2046 switch (myRealScale)
2047 {
2048 case KDGanttView::Minute:
2049 myRealMinorScaleCount = 1;
2050 return;
2051 break;
2052 case KDGanttView::Hour:
2053 myRealScale = KDGanttView::Minute;
2054 tempZoom = tempZoom/60;
2055 break;
2056 case KDGanttView::Day:
2057 myRealScale = KDGanttView::Hour;
2058 tempZoom = tempZoom/24;
2059 break;
2060 case KDGanttView::Week:
2061 myRealScale = KDGanttView::Day;
2062 tempZoom = tempZoom/7;
2063 break;
2064 case KDGanttView::Month:
2065 myRealScale = KDGanttView::Week ;
2066 tempZoom = tempZoom*7/30;
2067 break;
2068 case KDGanttView::Auto:
2069 break;
2070 }
2071 myRealMinorScaleCount = (int) ( myMinorScaleCount /tempZoom );
2072 }
2073 }
2074}
2075
2076
2077void KDTimeHeaderWidget::computeTicks(bool doNotComputeRealScale)
2078{
2079 if (flagDoNotRecomputeAfterChange) return;
2080 bool block = myGanttView->myTimeTable->blockUpdating();
2081 myGanttView->myTimeTable->setBlockUpdating( true );
2082 //tqDebug("computeticks ");
2083 majorTicks.clear();
2084 minorText.clear();
2085 majorText.clear();
2086 if ( !doNotComputeRealScale )
2087 saveCenterDateTime();
2088 if (!doNotComputeRealScale)
2089 computeRealScale(myHorizonStart);
2090 myRealStart = getEvenTimeDate(myHorizonStart ,myRealScale);
2091 if (!doNotComputeRealScale)
2092 computeRealScale(myRealStart);
2093 int tempMinorScaleCount = myRealMinorScaleCount,
2094 tempMajorScaleCount = myRealMajorScaleCount;
2095 int minorItems,minorPerMajor = 1;
2096 minorItems = (int) (secsFromTo( myRealStart, myHorizonEnd)/60.0);
2097 //tqDebug("tempMinorScaleCount %d ", tempMinorScaleCount);
2098 TQPainter p(this);
2099 int Width, Height;
2100 TQString testTextMinor,testTextMajor, tempStr;
2101 TQRect itemRectMinor, itemRectMajor;
2102 TQDate tempDate = myRealStart.date();
2103 myRealEnd = myRealStart;
2104 // preparing the testtext for the differennt scales
2105 switch (myRealScale)
2106 {
2107 // the x in testTextMajor is added to reserve a little bit more space
2108 case KDGanttView::Minute:
2109 testTextMinor = "60";
2110 if (myHourFormat == KDGanttView::Hour_12)
2111 testTextMajor = "Mon Aug 30, 12 AMx";
2112 else
2113 testTextMajor = "Mon Aug 30, 24:00x";
2114 minorPerMajor = 6000;
2115 break;
2116 case KDGanttView::Hour:
2117 minorItems = minorItems/60;
2118 if (myHourFormat == KDGanttView::Hour_24)
2119 testTextMinor = "24x";
2120 else
2121 testTextMinor = "12 AM";
2122 testTextMajor = "Mon Aug 30, x";
2123 if ( yearFormat() != KDGanttView::NoDate )
2124 testTextMajor += getYear(TQDate::currentDate());
2125 minorPerMajor = 2400;
2126 break;
2127 case KDGanttView::Day:
2128 minorItems = minorItems/(60*24);
2129 testTextMinor = "88";
2130 testTextMajor = "Aug 30, x"+getYear(TQDate::currentDate());
2131 minorPerMajor = 700;
2132 break;
2133 case KDGanttView::Week:
2134 minorItems = minorItems/(60*24*7);
2135 testTextMinor = "88";
2136 testTextMajor = "Aug x"+getYear(TQDate::currentDate());
2137 minorPerMajor = 435; // 435 = 365days/12months/7days * 100
2138 break;
2139 case KDGanttView::Month:
2140 minorItems = (minorItems*12)/(60*24*365);
2141 testTextMinor = "M";
2142 testTextMajor = "x"+getYear(TQDate::currentDate());
2143 minorPerMajor = 1200;
2144 break;
2145 case KDGanttView::Auto:
2146 tqDebug("KDGanttView::Internal Error in KDTimeHeaderWidget::computeTicks() ");
2147 tqDebug(" RealScale == Auto : This may not be! ");
2148 break;
2149 }
2150 itemRectMinor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMinor);
2151 itemRectMajor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMajor);
2152 p.end();
2153 //tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
2154 Height = itemRectMinor.height()+itemRectMajor.height()+11;
2155 Width = (itemRectMinor.width()+5);
2156 if (Width < minimumColumnWidth()) Width = minimumColumnWidth();
2157 // if the desired width is greater than the maximum width of this widget
2158 // increase the minorscalecount
2159 int maxWid = myGanttView->myCanvasView->viewport()->width();
2160 if (!flagZoomToFit)
2161 maxWid = maximumWidth();
2162 while((minorItems/tempMinorScaleCount+1)*Width > maxWid)
2163 ++tempMinorScaleCount;
2164 //tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
2165 mySizeHint = (minorItems/tempMinorScaleCount+1)*Width;
2166 switch (myRealScale)
2167 {
2168 case KDGanttView::Minute:
2169 if (tempMinorScaleCount < 60)
2170 while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
2171 ++tempMinorScaleCount;
2172 if (tempMinorScaleCount >= 60) {
2173 myRealScale = KDGanttView::Hour;
2174 myRealMinorScaleCount = tempMinorScaleCount/ 60;
2175 // myRealMinorScaleCount = 1;
2176 myRealMajorScaleCount = 1;
2177 tqDebug("KDGantt::Overzoom:Rescaling from Minute to Hour");
2178 myGanttView->myTimeTable->setBlockUpdating( block );
2179 emit myGanttView->rescaling( KDGanttView::Hour );
2180 computeTicks(true);
2181 return;
2182 }
2183 break;
2184 case KDGanttView::Hour:
2185 while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
2186 ++tempMinorScaleCount;
2187 if (tempMinorScaleCount >= 24) {
2188 myRealScale = KDGanttView::Day;
2189 myRealMinorScaleCount = tempMinorScaleCount/ 24;
2190 //myRealMinorScaleCount = 1;
2191 myRealMajorScaleCount = 1;
2192 tqDebug("KDGantt::Overzoom:Rescaling from Hour to Day");
2193 myGanttView->myTimeTable->setBlockUpdating( block );
2194 emit myGanttView->rescaling( KDGanttView::Day );
2195 computeTicks(true);
2196 return;
2197 }
2198 break;
2199 default:
2200 break;
2201 }
2202 //flagZoomToFit = false;
2203 while((minorItems/tempMinorScaleCount+1)*Width < myMinimumWidth ) {
2204 ++minorItems;
2205 }
2206 minorItems = (minorItems/tempMinorScaleCount)+1;
2207 // if not enough space for the text of the major scale, increase majorscalecount
2208 minorPerMajor = (minorPerMajor*tempMajorScaleCount)/tempMinorScaleCount;
2209 // checking, if enough space for majorscale
2210 // if not, increasing MajorScaleCount
2211
2212 while ((minorPerMajor*Width)/100 < itemRectMajor.width()) {
2213 minorPerMajor = minorPerMajor/tempMajorScaleCount;
2214 ++tempMajorScaleCount;
2215 minorPerMajor = minorPerMajor*tempMajorScaleCount;
2216
2217 }
2218 // now we have the fixed width of the minorscale computed
2219 myGridMinorWidth = Width;
2220 // the width of this widget is the gridwidth * the amount of items
2221 Width *= minorItems;
2222 // if size changed, reset geometry
2223 if (width() != Width || height() != Height )
2224 {
2225 resize( Width, Height );
2226 emit sizeChanged( Width );
2227 }
2228 myMajorGridHeight = itemRectMajor.height()+5;
2229 TQTime tempTime = myRealStart.time();
2230 TQDateTime tempDateTime;
2231 int i;
2232 const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
2233 switch (myRealScale)
2234 {
2235 case KDGanttView::Minute:
2236 myRealEnd = myRealEnd.addSecs((minorItems)*tempMinorScaleCount*60);
2237 for ( i = 0; i < minorItems;++i) {
2238 tempStr.setNum(tempTime.minute());
2239 minorText.append(tempStr);
2240 tempTime = tempTime.addSecs(60*tempMinorScaleCount);
2241 }
2242 tempDateTime = myRealStart;
2243 while (tempDateTime.time().minute() != 0)
2244 tempDateTime = tempDateTime.addSecs(60);
2245 while (tempDateTime < myRealEnd) {
2246 majorTicks.append( getCoordX(tempDateTime));
2247 tempStr.setNum(tempDateTime.date().day());
2248 if ( yearFormat() == KDGanttView::NoDate ) {
2249 tempStr = calendar->weekDayName( tempDateTime.date() )+", "
2250 +getHour(tempDateTime.time());
2251 } else {
2252 tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
2253 calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
2254 tempStr+", "+getHour(tempDateTime.time());
2255 }
2256
2257 majorText.append(tempStr);
2258 tempDateTime = tempDateTime.addSecs(3600*tempMajorScaleCount);
2259 }
2260 majorTicks.append( getCoordX(tempDateTime));
2261 break;
2262
2263 case KDGanttView::Hour:
2264 myRealEnd = myRealEnd.addSecs(minorItems*tempMinorScaleCount*60*60);
2265
2266 for ( i = 0; i < minorItems;++i) {
2267 tempStr = getHour(tempTime);
2268 minorText.append(tempStr);
2269 tempTime = tempTime.addSecs(3600*tempMinorScaleCount);
2270 }
2271 tempDateTime = myRealStart;
2272 while (tempDateTime.time().hour() != 0)
2273 tempDateTime = tempDateTime.addSecs(3600);
2274 while (tempDateTime < myRealEnd) {
2275 majorTicks.append( getCoordX(tempDateTime));
2276 tempStr.setNum(tempDateTime.date().day());
2277 if ( yearFormat() == KDGanttView::NoDate ) {
2278 tempStr = calendar->weekDayName( tempDateTime.date() );
2279 } else {
2280 tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
2281 calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
2282 tempStr+", "+getYear(tempDateTime.date());
2283 }
2284 majorText.append(tempStr);
2285 tempDateTime = tempDateTime.addDays(tempMajorScaleCount);
2286 }
2287 majorTicks.append( getCoordX(tempDateTime));
2288 break;
2289 case KDGanttView::Day:
2290 myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount);
2291 for ( i = 0; i < minorItems;++i) {
2292 if (tempMinorScaleCount == 1)
2293 minorText.append((calendar->weekDayName(tempDate, true)).left(1)); //TODO: BIDI
2294 else
2295 minorText.append(TQString::number(tempDate.day()));
2296 tempDate = tempDate.addDays(tempMinorScaleCount);
2297 }
2298 tempDate = myRealStart.date();
2299 while (tempDate.dayOfWeek() != TDEGlobal::locale()->weekStartDay())
2300 tempDate = tempDate.addDays(1);
2301 while (tempDate < myRealEnd.date()) {
2302 majorTicks.append( getCoordX(tempDate));
2303 tempStr.setNum(tempDate.day());
2304 tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+
2305 tempStr+", "+getYear(tempDate);
2306 majorText.append(tempStr);
2307 tempDate = tempDate.addDays(7*tempMajorScaleCount);
2308 }
2309 majorTicks.append( getCoordX(tempDate));
2310 break;
2311 case KDGanttView::Week:
2312 myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount*7);
2313 for ( i = 0; i < minorItems;++i) {
2314 tempStr.setNum(tempDate.day());
2315 minorText.append(tempStr);
2316 tempDate = tempDate.addDays(7*tempMinorScaleCount);
2317 }
2318 tempDate = myRealStart.date();
2319 while (tempDate.day() != TDEGlobal::locale()->weekStartDay())
2320 tempDate = tempDate.addDays(1);
2321 while (tempDate < myRealEnd.date()) {
2322 majorTicks.append( getCoordX(tempDate));
2323 tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+getYear(tempDate);
2324 majorText.append(tempStr);
2325 tempDate = tempDate.addMonths(tempMajorScaleCount);
2326 }
2327 majorTicks.append( getCoordX(tempDate));
2328 break;
2329 case KDGanttView::Month:
2330 myRealEnd = myRealEnd.addMonths(minorItems*tempMinorScaleCount);
2331 for ( i = 0; i < minorItems;++i) {
2332 minorText.append((calendar->monthName(tempDate.month(), tempDate.year(), true)).left(1)); //TODO: BIDI
2333 tempDate = tempDate.addMonths(tempMinorScaleCount);
2334 }
2335 tempDate = myRealStart.date();
2336 while (tempDate.month() != 1)
2337 tempDate = tempDate.addMonths(1);
2338 while (tempDate < myRealEnd.date()) {
2339 majorTicks.append( getCoordX(tempDate));
2340 tempStr = getYear(tempDate);
2341 majorText.append(tempStr);
2342 tempDate = tempDate.addYears(tempMajorScaleCount);
2343 }
2344 majorTicks.append( getCoordX(tempDate));
2345 break;
2346 case KDGanttView::Auto:
2347 break;
2348 }
2349
2350 if (flagDoNotRepaintAfterChange) {
2351 myGanttView->myTimeTable->setBlockUpdating( block );
2352 return;
2353 }
2354 //tqDebug("KDTimeHeaderWidget width %d, viewport width %d ",width (), myGanttView->myCanvasView->viewport()->width());
2355 myGanttView->myTimeTable->setBlockUpdating( block );
2356 updateTimeTable();
2357 centerDateTime(myCenterDateTime);
2358 repaint();
2359}
2360
2361
2362void KDTimeHeaderWidget::saveCenterDateTime()
2363{
2364 double wid = width();
2365 double allsecs = secsFromTo( myRealStart, myRealEnd );
2366 double center = myGanttView->myCanvasView->viewport()->width();
2367 center = center / 2;
2368 center = center + myGanttView->myCanvasView->contentsX();
2369 double secs = (allsecs*center)/wid;
2370 double days = secs/86400.0;
2371 secs = secs - ( (int) days *86400.0 );
2372 myCenterDateTime = (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
2373}
2374
2375
2376void KDTimeHeaderWidget::centerDateTime( const TQDateTime& center )
2377{
2378 moveTimeLineTo(getCoordX( center )-(myGanttView->myCanvasView->viewport()->width() /2));
2379 // tqDebug("centerDateTime %s %d %d", center.toString().latin1(),getCoordX( center ),(myGanttView->myCanvasView->viewport()->width() /2) );
2380
2381}
2382
2383
2384void KDTimeHeaderWidget::paintEvent(TQPaintEvent *p)
2385{
2386 repaintMe(p->rect().x(),p->rect().width());
2387}
2388
2389
2390int KDTimeHeaderWidget::getCoordX(TQDate date)
2391{
2392 int wid = width();
2393 int daysAll = myRealStart.daysTo(myRealEnd);
2394 if (daysAll == 0) return 0;
2395 int days = myRealStart.daysTo(TQDateTime(date));
2396 return (wid *days) /daysAll;
2397}
2398
2399
2400int KDTimeHeaderWidget::getCoordX(TQDateTime datetime)
2401{
2402 double wid = width();
2403 double secsAll = secsFromTo( myRealStart, myRealEnd );
2404 if (secsAll == 0.0) return 0;
2405 double secs = secsFromTo( myRealStart, datetime);
2406 return ((int)((wid *(secs /secsAll))+0.5));
2407}
2408
2409
2410TQString KDTimeHeaderWidget::getYear(TQDate date)
2411{
2412 TQString ret;
2413 ret.setNum(date.year());
2414 switch (yearFormat()) {
2415 case KDGanttView::FourDigit:
2416 // nothing to do
2417 break;
2418 case KDGanttView::TwoDigit:
2419 ret = ret.right(2);
2420 break;
2421 case KDGanttView::TwoDigitApostrophe:
2422 ret = "'"+ret.right(2);
2423 break;
2424 case KDGanttView::NoDate:
2425 // nothing to do
2426 break;
2427 }
2428 return ret;
2429}
2430
2431
2432TQString KDTimeHeaderWidget::getHour(TQTime time)
2433{
2434 TQString ret;
2435 int hour = time.hour();
2436 if (myHourFormat == KDGanttView::Hour_12) {
2437 if (hour >= 12) {
2438 if (hour > 12) hour -=12;
2439 ret.setNum(hour);
2440 ret = ret +" PM";
2441 } else {
2442 if (hour == 0) hour = 12;
2443 ret.setNum(hour);
2444 ret = ret +" AM";
2445 }
2446 } else {
2447 if (myHourFormat == KDGanttView::Hour_24)
2448 ret.setNum(hour);
2449 else {
2450 ret.setNum(hour);
2451 ret += ":00";
2452 }
2453 }
2454 return ret;
2455}
2456
2457
2458void KDTimeHeaderWidget::mousePressEvent ( TQMouseEvent * e )
2459{
2460 mouseDown = false;
2461 switch ( e->button() ) {
2462 case TQt::LeftButton:
2463 mouseDown = true;
2464 beginMouseDown = e->pos().x();
2465 endMouseDown = e->pos().x();
2466 break;
2467 case TQt::RightButton:
2468 if (flagShowPopupMenu)
2469 myPopupMenu->popup(e->globalPos());
2470 break;
2471 case TQt::MidButton:
2472 break;
2473 default:
2474 break;
2475 }
2476
2477}
2478
2479
2480void KDTimeHeaderWidget::mouseReleaseEvent ( TQMouseEvent * )
2481{
2482 if ( mouseDown ) {
2483 mouseDown = false;
2484 // zoom to selection getDateTimeForIndex(
2485 int start, end;
2486 if ( beginMouseDown < endMouseDown ) {
2487 start = beginMouseDown;
2488 end = endMouseDown;
2489 } else {
2490 start = endMouseDown;
2491 end = beginMouseDown;
2492 }
2493 if (start < 0 )
2494 start = 0;
2495 if ( end > width() )
2496 end = width();
2497 //tqDebug("start %s ",getDateTimeForIndex(start).toString().latin1() );
2498 //tqDebug("end %s ",getDateTimeForIndex(end).toString().latin1() );
2499 emit myGanttView->timeIntervalSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
2500 emit myGanttView->timeIntervallSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
2501 //zoomToSelection( getDateTimeForIndex(start),getDateTimeForIndex(end) );
2502 }
2503 mouseDown = false;
2504 repaint();
2505}
2506
2507
2508void KDTimeHeaderWidget::mouseDoubleClickEvent ( TQMouseEvent * )
2509{
2510
2511}
2512
2513
2514void KDTimeHeaderWidget::mouseMoveEvent ( TQMouseEvent * e )
2515{
2516 if ( mouseDown ) {
2517 if ( e->pos().y() < -height() || e->pos().y() > 2* height() ) {
2518 mouseDown = false;
2519 repaint();
2520 return;
2521 }
2522 endMouseDown = e->pos().x();
2523 //repaint;
2524 int val = -1;
2525 if (endMouseDown < -x() ) {
2526 val = myGanttView->myCanvasView->horizontalScrollBar()->value() -
2527 myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
2528 if ( val < 0 ) {
2529 val = 0;
2530 }
2531 }
2532 if (endMouseDown > -x() +parentWidget()->width() ) {
2533 val = myGanttView->myCanvasView->horizontalScrollBar()->value() +
2534 myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
2535
2536 }
2537 repaintMe(-x(),parentWidget()->width());
2538 if ( val > -1 ) {
2539 if ( val > myGanttView->myCanvasView->horizontalScrollBar()->maxValue() ) {
2540 val = myGanttView->myCanvasView->horizontalScrollBar()->maxValue();
2541 }
2542 myGanttView->myCanvasView->horizontalScrollBar()->setValue( val );
2543 }
2544 //tqDebug("mousemove %d %d %d %d",endMouseDown, -x(),parentWidget()->width() , e->pos().y());
2545 }
2546}
2547
2548
2549/* ***************************************************************
2550 KDLegendWidget:: KDLegendWidget
2551 ***************************************************************** */
2552KDLegendWidget:: KDLegendWidget( TQWidget* parent,
2553 KDGanttMinimizeSplitter* legendParent ) :
2554 KDGanttSemiSizingControl ( KDGanttSemiSizingControl::Before,TQt::Vertical,
2555 parent)
2556{
2557 myLegendParent = legendParent;
2558 dock = 0;
2559 scroll = new TQScrollView( legendParent );
2560 setMaximizedWidget( scroll );
2561
2562 setMinimizedWidget( myLabel = new TQLabel( i18n( " Legend is hidden" ), this) );
2563 setGeometry( 0, 0, 50, 50 );
2564 myLegend = 0;
2565 clearLegend();
2566 showMe ( false );
2567}
2568void KDLegendWidget::setAsDoctwindow( bool dockwin )
2569{
2570 if ( (dock == 0 && !dockwin) || ( dock && dockwin ) )
2571 return;
2572 if ( dockwin )
2573 {
2574 setMaximizedWidget( 0 );
2575 showMe ( false );
2576 if ( dock ) delete dock;
2577 dock = new TQDockWindow(TQDockWindow:: OutsideDock,0 );
2578 dock->resize( 200, 100 );
2579 dock->setHorizontallyStretchable( true );
2580 dock->setVerticallyStretchable( true );
2581 dock->setCaption(i18n("Legend: ") );
2582 dock->setResizeEnabled (true );
2583 delete myLegend;
2584 myLegend = 0;
2585 delete scroll;
2586 scroll = new TQScrollView( dock );
2587 clearLegend();
2588 dock->setWidget(scroll);
2589 setMaximizedWidget( dock );
2590 showMe ( false );
2591
2592 } else {
2593 setMaximizedWidget( 0 );
2594 showMe ( false );
2595 delete myLegend;
2596 myLegend = 0;
2597 delete scroll;
2598 delete dock;
2599 dock = 0;
2600 scroll = new TQScrollView( myLegendParent );
2601 clearLegend();
2602 setMaximizedWidget( scroll );
2603 showMe ( false );
2604 }
2605
2606}
2607
2608
2609bool KDLegendWidget::asDoctwindow( )
2610{
2611 if ( dock )
2612 return true;
2613 return false;
2614}
2615
2616
2617TQDockWindow* KDLegendWidget::dockwindow( )
2618{
2619 return dock;
2620}
2621
2622
2623void KDLegendWidget::setFont( TQFont font)
2624{
2625 myLegend->setFont( font);
2626 myLabel->setFont( font);
2627 TQWidget::setFont( font );
2628}
2629
2630
2631void KDLegendWidget::drawToPainter( TQPainter *p )
2632{
2633 p->drawPixmap( 0, 0, TQPixmap::grabWidget( myLegend ) );
2634}
2635
2636
2637TQSize KDLegendWidget::legendSize()
2638{
2639 return myLegend->size();
2640}
2641
2642
2643TQSize KDLegendWidget::legendSizeHint()
2644{
2645 TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
2646 return TQSize( myLegend->sizeHint().width(), myLegend->sizeHint().height()+scroll->horizontalScrollBar()->height());
2647}
2648
2649
2650void KDLegendWidget::showMe ( bool show )
2651{
2652 minimize( !show );
2653}
2654
2655
2656void KDLegendWidget::clearLegend ( )
2657{
2658 if ( myLegend ) delete myLegend;
2659 if ( dock )
2660 myLegend = new TQGroupBox( 1, TQt::Horizontal, scroll->viewport() );
2661 else
2662 myLegend = new TQGroupBox( 1, TQt::Horizontal, i18n( "Legend" ), scroll->viewport() );
2663 myLegend->setBackgroundColor( TQt::white );
2664 myLegend->setFont( font() );
2665 scroll->addChild( myLegend );
2666 scroll->setResizePolicy( TQScrollView::AutoOneFit );
2667 myLegend->layout()->setMargin( 11 );
2668 myLegend->setFrameStyle( TQFrame::NoFrame );
2669 if ( dock )
2670 scroll->setMaximumHeight( 32000 );
2671 else
2672 scroll->setMaximumHeight( legendSizeHint().height() );
2673}
2674
2675
2676void KDLegendWidget::addLegendItem( KDGanttViewItem::Shape shape, const TQColor& shapeColor, const TQString& text )
2677{
2678 TQLabel * temp;
2679 TQPixmap p = KDGanttView::getPixmap( shape, shapeColor, TQt::white, 10);
2680 TQWidget *w = new TQWidget( myLegend );
2681 w->setBackgroundColor( TQt::white );
2682 TQHBoxLayout *lay = new TQHBoxLayout( w ,0, 6);
2683 temp = new TQLabel ( w );
2684 lay->addWidget( temp, 0, TQt:: AlignRight);
2685 temp->setPixmap(p);
2686 temp = new TQLabel ( text, w );
2687 temp->setBackgroundColor( TQt::white );
2688 lay->addWidget( temp, 0, TQt:: AlignLeft);
2689 lay->addStretch();
2690 if ( dock )
2691 scroll->setMaximumHeight( 32000 );
2692 else
2693 scroll->setMaximumHeight( legendSizeHint().height() );
2694}
2695
2696
2697bool KDLegendWidget::isShown ( )
2698{
2699 return !isMinimized();
2700}
2701
2702
2703KDListView::KDListView(TQWidget* parent, KDGanttView* gantView):TQListView (parent)
2704{
2705 myGanttView = gantView;
2706 setAcceptDrops(true);
2707 new KDListViewWhatsThis(viewport(),this);
2708 setRootIsDecorated( true );
2709 setAllColumnsShowFocus( true );
2710 addColumn( i18n( "Task Name" ) );
2711 setSorting( -1 );
2712 //setVScrollBarMode (TQScrollView::AlwaysOn );
2713 setHScrollBarMode (TQScrollView::AlwaysOn );
2714 setDefaultRenameAction(TQListView::Accept);
2715 setColumnWidthMode ( 0,Maximum );
2716 _calendarMode = false;
2717 // TQObject::connect(this, TQ_SIGNAL ( pressed ( TQListViewItem * )) , this, TQ_SLOT( dragItem( TQListViewItem *))) ;
2718}
2719
2720
2721void KDListView::dragItem( TQListViewItem * )
2722{
2723 // tqDebug("drag ");
2724 // startDrag();
2725}
2726TQString KDListView::getWhatsThisText(TQPoint p)
2727{
2728 KDGanttViewItem* item = ( KDGanttViewItem* ) itemAt( p );
2729 if ( item )
2730 return item->whatsThisText();
2731 return i18n( "No item Found" );
2732}
2733
2734void KDListView::setCalendarMode( bool mode )
2735{
2736 _calendarMode = mode;
2737 // setRootIsDecorated ( ! mode );
2738}
2739
2740void KDListView::setOpen(TQListViewItem * item, bool open )
2741{
2742 if (! _calendarMode || ! open ) {
2743 (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
2744 TQListView::setOpen ( item, open );
2745 (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
2746 return;
2747 }
2748 // we are in calendarmode
2749 // in calendarmode only items can be opened which have subitems which have subitems
2750
2751 TQListViewItem* temp;
2752 temp = item->firstChild();
2753 bool openItem = false;
2754 while (temp) {
2755 if ( (( KDGanttViewItem*)temp)->displaySubitemsAsGroup() ) {
2756 temp->setVisible( true );
2757 openItem = true;
2758 }
2759 else {
2760 temp->setVisible( false );
2761 //tqDebug(" temp->setVisible( false );");
2762 }
2763 temp = temp->nextSibling();
2764 }
2765 if ( openItem ) {
2766 (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
2767 TQListView::setOpen ( item, open );
2768 (( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
2769 }
2770}
2771
2772
2773void KDListView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
2774{
2775 TQListView::contentsMouseDoubleClickEvent ( e );
2776 //if ( ! _calendarMode )
2777 // TQListView::contentsMouseDoubleClickEvent ( e );
2778 // else
2779 {
2780
2781 emit myGanttView->lvItemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
2782 emit myGanttView->itemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
2783 }
2784
2785}
2786
2787
2788void KDListView::drawToPainter ( TQPainter * p, bool drawHeader )
2789{
2790 // Draw list
2791 drawAllContents ( p, 0, 0, contentsWidth(), contentsHeight() );
2792 if (!drawHeader) {
2793 return;
2794 }
2795 // Draw headers
2796 TQPen pen = TQPen(TQt::lightGray, 1);
2797 p->save();
2798 TQHeader *h = header();
2799 for (int s = 0; s < h->count(); ++s) {
2800 TQRect r = h->sectionRect(s);
2801 if (s==0) {
2802 p->translate(0, -r.height());
2803 }
2804 //kdDebug()<<s<<": "<<h->label(s)<<" "<<r<<endl;
2805 p->drawText(r.x()+2, r.y(), r.width()-2, r.height(), columnAlignment(s)|TQt::AlignVCenter, h->label(s), -1);
2806 p->save();
2807 p->setPen(pen);
2808 p->drawRect(r.x(), r.y()+1, r.width(), r.height()-2);
2809 p->restore();
2810
2811 }
2812 p->restore();
2813}
2814
2815int KDListView::buildDrawables(TQPtrList<KDListView::DrawableItem> &lst, int level, int ypos, TQListViewItem *item, int ymin, int ymax) const {
2816 int y = ypos;
2817 int ih = item->height();
2818 if (y < ymin && y+ih > ymin) {
2819 y = ymin; // include partial item at top
2820 }
2821 if (y >= ymin && y < ymax) { // include partial item at bottom
2822 KDListView::DrawableItem *dr = new KDListView::DrawableItem(level, y, item);
2823 lst.append(dr);
2824 //kdDebug()<<k_funcinfo<<level<<", "<<y<<" : "<<item->text(0)<<endl;
2825 }
2826 y += ih;
2827 if (item->isOpen()) {
2828 TQListViewItem *child = item->firstChild();
2829 for (; child; child = child->nextSibling()) {
2830 y = buildDrawables(lst, level+1, y, child, ymin, ymax);
2831 }
2832 }
2833 return y;
2834}
2835// This is a copy of TQListView::drawContentsOffset(), with a few changes
2836// because drawContentsOffset() only draws *visible* items,
2837// we want to draw *all* items.
2838// FIXME: Haven't got paintBraches() to work, atm live without it.
2839void KDListView::drawAllContents(TQPainter * p, int cx, int cy, int cw, int ch) {
2840 if ( columns() == 0 ) {
2841 paintEmptyArea( p, TQRect( cx, cy, cw, ch ) );
2842 return;
2843 }
2844 //kdDebug()<<k_funcinfo<<TQRect(cx, cy, cw, ch)<<endl;
2845 TQPtrList<KDListView::DrawableItem> drawables;
2846 drawables.setAutoDelete(true);
2847 TQListViewItem *child = firstChild();
2848 int level = 0;
2849 int ypos = 0;
2850 for (; child; child = child->nextSibling()) {
2851 ypos = buildDrawables(drawables, level, ypos, child, cy, cy+ch);
2852 }
2853
2854 p->setFont( font() );
2855
2856 TQPtrListIterator<KDListView::DrawableItem> it(drawables);
2857
2858 TQRect r;
2859 int fx = -1, x, fc = 0, lc = 0;
2860 int tx = -1;
2861 KDListView::DrawableItem * current;
2862
2863 while ( (current = it.current()) != 0 ) {
2864 ++it;
2865 int ih = current->i->height();
2866 int ith = current->i->totalHeight();
2867 int c;
2868 int cs;
2869
2870 // need to paint current?
2871 if ( ih > 0 && current->y < cy+ch && current->y+ih > cy ) {
2872 //kdDebug()<<k_funcinfo<<"Paint: "<<current->i->text(0)<<" y="<<current->y<<endl;
2873 if ( fx < 0 ) {
2874 // find first interesting column, once
2875 x = 0;
2876 c = 0;
2877 cs = header()->cellSize( 0 );
2878 while ( x + cs <= cx && c < header()->count() ) {
2879 x += cs;
2880 c++;
2881 if ( c < header()->count() )
2882 cs = header()->cellSize( c );
2883 }
2884 fx = x;
2885 fc = c;
2886 while( x < cx + cw && c < header()->count() ) {
2887 x += cs;
2888 c++;
2889 if ( c < header()->count() )
2890 cs = header()->cellSize( c );
2891 }
2892 lc = c;
2893 }
2894
2895 x = fx;
2896 c = fc;
2897 // draw to last interesting column
2898
2899 const TQColorGroup &cg = ( palette().inactive() );
2900
2901 while ( c < lc && !drawables.isEmpty() ) {
2902 int i = header()->mapToLogical( c );
2903 cs = header()->cellSize( c );
2904 r.setRect( x, current->y-cy, cs, ih );
2905 if ( i == 0 )
2906 r.setLeft( r.left() + current->l * treeStepSize() );
2907
2908 p->save();
2909 // No need to paint if the cell isn't technically visible
2910 if ( !( r.width() == 0 || r.height() == 0 ) ) {
2911 p->translate( r.left(), r.top() );
2912 int ac = header()->mapToLogical( c );
2913 // map to Left currently. This should change once we
2914 // can really reverse the listview.
2915 int align = columnAlignment( ac );
2916 if ( align == AlignAuto ) align = AlignLeft;
2917 bool sel = current->i->isSelected();
2918 if (sel)
2919 current->i->setSelected(false);
2920 current->i->paintCell( p, cg, ac, r.width(), align );
2921 if (sel)
2922 current->i->setSelected(sel);
2923 }
2924 p->restore();
2925 x += cs;
2926 c++;
2927 }
2928
2929 }
2930
2931 const int cell = header()->mapToActual( 0 );
2932
2933 if ( tx < 0 )
2934 tx = header()->cellPos( cell );
2935
2936 // do any children of current need to be painted?
2937/* FIXME: painting branches doesn't work for some reason...
2938 if ( ih != ith &&
2939 rootIsDecorated() &&
2940 current->y + ith > cy &&
2941 current->y + ih < cy + ch &&
2942 tx + current->l * treeStepSize() < cx + cw &&
2943 tx + (current->l+1) * treeStepSize() > cx ) {
2944 // compute the clip rectangle the safe way
2945
2946 int rtop = current->y + ih;
2947 int rbottom = current->y + ith;
2948 int rleft = tx + current->l*treeStepSize();
2949 int rright = rleft + treeStepSize();
2950
2951 int crtop = TQMAX( rtop, cy );
2952 int crbottom = TQMIN( rbottom, cy+ch );
2953 int crleft = TQMAX( rleft, cx );
2954 int crright = TQMIN( rright, cx+cw );
2955
2956 r.setRect( crleft, crtop,
2957 crright-crleft, crbottom-crtop );
2958
2959 if ( r.isValid() ) {
2960 p->save();
2961 p->translate( rleft, crtop );
2962 //kdDebug()<<k_funcinfo<<"paintBranches: "<<current->i->text(0)<<endl;
2963
2964 current->i->paintBranches( p, colorGroup(), treeStepSize(),
2965 rtop - crtop, r.height() );
2966 p->restore();
2967 }
2968 }*/
2969 }
2970}
2971
2972void KDListView::resizeEvent(TQResizeEvent *)
2973{
2974 triggerUpdate ();
2975}
2976void KDListView::dragEnterEvent ( TQDragEnterEvent * e)
2977{
2978 if ( !myGanttView->dropEnabled() ) {
2979 e->accept( false );
2980 return;
2981 }
2982 myGanttView->lvDragEnterEvent(e);
2983 //e->accept(KDGanttViewItemDrag::canDecode(e) );
2984}
2985
2986void KDListView::dragMoveEvent ( TQDragMoveEvent * e)
2987{
2988 if ( !myGanttView->dropEnabled() ) {
2989 e->accept( false );
2990 return;
2991 }
2992 KDGanttViewItem* draggedItem = 0;
2993 KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
2994 setCurrentItem( gItem );
2995 if ( e->source() == myGanttView )
2996 draggedItem = myGanttView->myCanvasView->lastClickedItem;
2997 // execute user defined dragMoveEvent handling
2998 if (myGanttView->lvDragMoveEvent ( e , draggedItem, gItem ) )
2999 return;
3001 e->accept( false );
3002 return;
3003 }
3004 if ( e->source() == myGanttView && gItem ){
3005 // internal drag - do not allow to drag the item to a subitem of itself
3006 KDGanttViewItem* pItem = gItem->parent();
3007 while ( pItem ) {
3008 if ( pItem == myGanttView->myCanvasView->lastClickedItem ) {
3009 e->accept( false );
3010 return;
3011 }
3012 pItem = pItem->parent();
3013 }
3014 if ( gItem == myGanttView->myCanvasView->lastClickedItem ) {
3015 e->accept( false );
3016 return;
3017 }
3018 }
3019 e->accept( true );
3020}
3021
3022void KDListView::dragLeaveEvent ( TQDragLeaveEvent * )
3023{
3024 //tqDebug("contentsDragLeaveEvent ");
3025}
3026void KDListView::dropEvent ( TQDropEvent *e )
3027{
3028 if ( !myGanttView->dropEnabled() ) {
3029 e->accept( false );
3030 return;
3031 }
3032 KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
3033 KDGanttViewItem* draggedItem = 0;
3034 if ( e->source() == myGanttView )
3035 draggedItem = myGanttView->myCanvasView->lastClickedItem;
3036 if (myGanttView->lvDropEvent ( e, draggedItem, gItem ))
3037 return;
3038 TQString string;
3039 KDGanttViewItemDrag::decode( e, string );
3040 KDGanttViewItem* newItem = 0;
3041
3042 if ( gItem == myGanttView->myCanvasView->lastClickedItem && gItem != 0 ) {
3043 tqDebug("KDGanttView::Possible bug in drag&drop code ");
3044 return;
3045 }
3046
3047 TQDomDocument doc( "GanttView" );
3048 doc.setContent( string );
3049 TQDomElement docRoot = doc.documentElement(); // ChartParams element
3050 TQDomNode node = docRoot.firstChild();
3051 bool enable = myGanttView->myTimeTable->blockUpdating( );
3052 myGanttView->myTimeTable->setBlockUpdating( true );
3053 while( !node.isNull() ) {
3054 TQDomElement element = node.toElement();
3055 if( !element.isNull() ) { // was really an element
3056 TQString tagName = element.tagName();
3057 if( tagName == "Items" ) {
3058 TQDomNode node = element.firstChild();
3059 while( !node.isNull() ) {
3060 TQDomElement element = node.toElement();
3061 if( !element.isNull() ) { // was really an element
3062 TQString tagName = element.tagName();
3063 if( tagName == "Item" ) {
3064 if ( gItem )
3066 element );
3067 else
3068 newItem = KDGanttViewItem::createFromDomElement( myGanttView,
3069 element );
3070 } else {
3071 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3072 Q_ASSERT( false );
3073 }
3074 }
3075 //tqDebug("next node1 ");
3076 node = node.nextSibling();
3077 }
3078 }
3079 }
3080 //tqDebug("next node2 ");
3081 node = node.nextSibling();
3082 }
3083 newItem->setDisplaySubitemsAsGroup(myGanttView->displaySubitemsAsGroup());
3084 newItem->resetSubitemVisibility();
3085 myGanttView->slot_lvDropped(e, draggedItem, gItem);
3086 myGanttView->myTimeTable->setBlockUpdating( enable );
3087 myGanttView->myTimeTable->updateMyContent();
3088 return;
3089}
3090
3091TQDragObject * KDListView::dragObject ()
3092{
3093 return TQListView::dragObject ();
3094}
3095
3096void KDListView::startDrag ()
3097{
3098 if ( ! myGanttView->dragEnabled() )
3099 return;
3100 KDGanttViewItem* cItem = (KDGanttViewItem*) currentItem ();
3101 myGanttView->myCanvasView->lastClickedItem = cItem;
3102 myGanttView->lvStartDrag (cItem);
3103}
3104
3105KDCanvasText::KDCanvasText( KDTimeTableWidget* canvas,
3106 void* parentItem,
3107 int type ) :
3108 TQCanvasText(canvas)
3109{
3110 myParentType = type;
3111 myParentItem = parentItem;
3112}
3113
3114
3115KDCanvasLine::KDCanvasLine( KDTimeTableWidget* canvas,
3116 void* parentItem,
3117 int type ) :
3118 TQCanvasLine(canvas)
3119{
3120 myParentType = type;
3121 myParentItem = parentItem;
3122}
3123
3124
3125KDCanvasPolygonItem::KDCanvasPolygonItem( KDTimeTableWidget* canvas,
3126 void* parentItem,
3127 int type ) :
3128 TQCanvasPolygonalItem( canvas )
3129{
3130 myParentType = type;
3131 myParentItem = parentItem;
3132}
3133
3134
3135KDCanvasPolygon::KDCanvasPolygon( KDTimeTableWidget* canvas,
3136 void* parentItem,
3137 int type ) :
3138 TQCanvasPolygon( canvas )
3139{
3140 myParentType = type;
3141 myParentItem = parentItem;
3142}
3143
3144
3145KDCanvasEllipse::KDCanvasEllipse( KDTimeTableWidget* canvas,
3146 void* parentItem,
3147 int type ) :
3148 TQCanvasEllipse( canvas )
3149{
3150 myParentType = type;
3151 myParentItem = parentItem;
3152}
3153
3154
3155KDCanvasRectangle::KDCanvasRectangle( KDTimeTableWidget* canvas,
3156 void* parentItem,
3157 int type ) :
3158 TQCanvasRectangle( canvas )
3159{
3160 myParentType = type;
3161 myParentItem = parentItem;
3162}
3163
3164
3165
3166
3167KDGanttCanvasView::KDGanttCanvasView( KDGanttView* sender,TQCanvas* canvas, TQWidget* parent, const
3168 char* name ) : TQCanvasView ( canvas, parent, name ), scrollBarTimer( 0, "scrollBarTimer" )
3169{
3170 setHScrollBarMode (TQScrollView::AlwaysOn );
3171 setVScrollBarMode( TQScrollView::AlwaysOn );
3172 myToolTip = new KDCanvasToolTip(viewport(),this);
3173 mySignalSender = sender;
3174 currentItem = 0;
3175 currentLink = 0;
3176 cuttedItem = 0;
3177 fromItem = 0;
3178 fromArea = 0;
3179 linkItemsEnabled = false;
3180 linkLine = new TQCanvasLine(canvas);
3181 linkLine->hide();
3182 linkLine->setZ(1000);
3183 //set_Mouse_Tracking(true);
3184 new KDCanvasWhatsThis(viewport(),this);
3185 onItem = new TQPopupMenu( this );
3186 TQPopupMenu * newMenu = new TQPopupMenu( this );
3187 TQPopupMenu * onView = new TQPopupMenu( this );
3188 onView->insertItem( i18n( "Summary" ), this,
3189 TQ_SLOT ( newRootItem( int ) ), 0, 0 );
3190 onView->insertItem( i18n( "Event" ), this,
3191 TQ_SLOT ( newRootItem( int ) ), 0, 1);
3192 onView->insertItem( i18n( "Task" ), this,
3193 TQ_SLOT ( newRootItem( int ) ), 0, 2 );
3194
3195 onItem->insertItem( i18n( "New Root" ), onView );
3196 newMenu->insertItem( i18n( "Summary" ),
3197 this, TQ_SLOT ( newChildItem( int) ), 0, 0 );
3198 newMenu->insertItem( i18n( "Event" ),
3199 this, TQ_SLOT ( newChildItem( int ) ), 0, 1 );
3200 newMenu->insertItem( i18n( "Task" ),
3201 this, TQ_SLOT ( newChildItem( int ) ), 0, 2 );
3202
3203 onItem->insertItem( i18n( "New Child" ), newMenu );
3204 TQPopupMenu * afterMenu = new TQPopupMenu( this );
3205 afterMenu->insertItem( i18n( "Summary" ),
3206 this, TQ_SLOT ( newChildItem( int) ), 0, 0+4 );
3207 afterMenu->insertItem( i18n( "Event" ),
3208 this, TQ_SLOT ( newChildItem( int ) ), 0, 1+4 );
3209 afterMenu->insertItem( i18n( "Task" ),
3210 this, TQ_SLOT ( newChildItem( int ) ), 0, 2+4 );
3211 onItem->insertItem( i18n( "New After" ), afterMenu );
3212 TQPopupMenu *pasteMenu = new TQPopupMenu( this );
3213 pasteMenu->insertItem( i18n( "As Root" ),
3214 this, TQ_SLOT ( pasteItem( int ) ), 0, 0 );
3215 pasteMenu->insertItem( i18n( "As Child" ),
3216 this, TQ_SLOT ( pasteItem( int ) ), 0, 1 );
3217 pasteMenu->insertItem( i18n( "After" ),
3218 this, TQ_SLOT ( pasteItem( int ) ), 0, 2 );
3219 onItem->insertItem( i18n( "Paste" ), pasteMenu, 3 );
3220 onItem->insertItem( i18n( "Cut Item" ), this, TQ_SLOT ( cutItem() ) );
3221 onItem->setItemEnabled( 3, false );
3222 myMyContentsHeight = 0;
3223 _showItemAddPopupMenu = false;
3224
3225 TQObject *scrollViewTimer = child( "scrollview scrollbar timer", "TQTimer", false );
3226 Q_ASSERT( scrollViewTimer );
3227 if ( scrollViewTimer ) {
3228 disconnect( scrollViewTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(updateScrollBars() ) );
3229 }
3230 // If they needed a scrollbar timer in scrollview...
3231 connect( &scrollBarTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(myUpdateScrollBars() ) );
3232
3233 myScrollTimer = new TQTimer( this, "myScrollTimer" );
3234 connect( myScrollTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotScrollTimer() ) );
3235 autoScrollEnabled = false;
3236}
3237
3238
3239KDGanttCanvasView::~KDGanttCanvasView()
3240{
3241 delete myToolTip;
3242}
3243
3244
3245void KDGanttCanvasView::setShowPopupMenu( bool show )
3246{
3247 _showItemAddPopupMenu = show;
3248}
3249bool KDGanttCanvasView::showPopupMenu()
3250{
3251 return _showItemAddPopupMenu;
3252}
3253
3254
3255void KDGanttCanvasView::moveMyContent( int, int y)
3256{
3257 setContentsPos(contentsX(), y);
3258}
3259
3260void KDGanttCanvasView::resizeEvent ( TQResizeEvent * e )
3261{
3262 int ho = e->oldSize().height();
3263 int wo = e->oldSize().width();
3264 int hi = height();
3265 int wi = width();
3266 //TQScrollView::blockSignals( true );
3267
3268 verticalScrollBar()->setUpdatesEnabled( false );
3269 TQScrollView::resizeEvent ( e ) ;
3270 if ( ho != hi )
3271 emit heightResized( viewport()->height());
3272 if ( wo != wi )
3273 emit widthResized( viewport()->width() );
3274 //setMyContentsHeight( 0 ); // via timer
3275 //TQScrollView::blockSignals( false );
3276 scrollBarTimer.start(0, true);
3277}
3278
3279void KDGanttCanvasView::myUpdateScrollBars()
3280{
3281 setMyContentsHeight( 0 );
3282}
3283void KDGanttCanvasView::setMyContentsHeight( int hei )
3284{
3285 //tqDebug("setMyContentsHeight %d %d ", hei, myMyContentsHeight);
3286 if ( hei > 0 )
3287 myMyContentsHeight = hei;
3288 verticalScrollBar()->setUpdatesEnabled( true ); // set false in resizeEvent()
3289 if ( viewport()->height() <= myMyContentsHeight )
3290 verticalScrollBar()->setRange( 0, myMyContentsHeight- viewport()->height()+1);
3291 else
3292 verticalScrollBar()->setRange( 0,0 );
3293 // testing for unmatching ScrollBar values of timeheader and timetable
3294 // may happen after external resizing
3295 if ( horizontalScrollBar()->value() != mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value() ) {
3296 // I am the Boss!
3297 mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->setValue(horizontalScrollBar()->value() );
3298
3299 }
3300
3301}
3302
3303// Call after *internal* resizing (like addTickRight())
3304// Then the new scrollbar maxValue is in myTimeHeader.
3305void KDGanttCanvasView::updateHorScrollBar() {
3306 //tqDebug("horizontalScrollBar max=%d, myTimeHeaderScroll=%d", horizontalScrollBar()->maxValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value());
3307
3308 horizontalScrollBar()->setRange(mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->minValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->maxValue());
3309
3310}
3311
3312void KDGanttCanvasView::cutItem( KDGanttViewItem* item )
3313{
3314 lastClickedItem = item;
3315 cutItem();
3316}
3317void KDGanttCanvasView::insertItemAsRoot( KDGanttViewItem* item )
3318{
3319 mySignalSender->myListView->insertItem( item );
3320 if ( item == cuttedItem )
3321 cuttedItem = 0;
3322}
3323void KDGanttCanvasView::insertItemAsChild( KDGanttViewItem* parent, KDGanttViewItem* item )
3324{
3325 parent->insertItem( cuttedItem );
3326 if ( item == cuttedItem )
3327 cuttedItem = 0;
3328}
3329void KDGanttCanvasView::insertItemAfter( KDGanttViewItem* parent , KDGanttViewItem* item )
3330{
3331 if ( parent->parent() ) {
3332 parent->parent()->insertItem( item );
3333 }
3334 else
3335 mySignalSender->myListView->insertItem( item );
3336 item->moveItem( parent );
3337 if ( item == cuttedItem )
3338 cuttedItem = 0;
3339}
3340
3341void KDGanttCanvasView::cutItem()
3342{
3343 lastClickedItem->hideSubtree();
3344 //tqDebug("last clicked %d parent %d ", lastClickedItem , lastClickedItem->parent());
3345 if ( lastClickedItem->parent() )
3346 lastClickedItem->parent()->takeItem(lastClickedItem);
3347 else
3348 mySignalSender->myListView->takeItem( lastClickedItem );
3349 mySignalSender->myTimeTable->updateMyContent();
3350 if ( cuttedItem )
3351 delete cuttedItem;
3352 cuttedItem = lastClickedItem;
3353 onItem->setItemEnabled( 3, true );
3354
3355}
3356// called from the destructor in KDGanttViewItem or KDGanttView
3357
3358void KDGanttCanvasView::resetCutPaste( KDGanttViewItem* item )
3359{
3360 if ( item == 0 && cuttedItem ) {
3361 delete cuttedItem;
3362 cuttedItem = 0;
3363 }
3364 if (item == cuttedItem) {
3365 onItem->setItemEnabled( 3, false );
3366 cuttedItem = 0;
3367 }
3368}
3369
3370void KDGanttCanvasView::pasteItem( int type )
3371{
3372 if ( !cuttedItem )
3373 return;
3374 switch( type ) {
3375 case 0://root
3376 mySignalSender->myListView->insertItem( cuttedItem );
3377 break;
3378 case 1://child
3379 lastClickedItem->insertItem( cuttedItem );
3380 break;
3381 case 2://after
3382 if ( lastClickedItem->parent() ) {
3383 lastClickedItem->parent()->insertItem( cuttedItem );
3384 }
3385 else
3386 mySignalSender->myListView->insertItem( cuttedItem );
3387 cuttedItem->moveItem( lastClickedItem );
3388 break;
3389 default:
3390 ;
3391 }
3392 cuttedItem = 0;
3393 onItem->setItemEnabled( 3, false );
3394 mySignalSender->myTimeTable->updateMyContent();
3395}
3396void KDGanttCanvasView::newRootItem(int type)
3397{
3398 KDGanttViewItem* temp = 0;
3399 switch( type ) {
3400 case 1:
3401 temp = new KDGanttViewEventItem( mySignalSender, i18n( "New Event" ) );
3402 break;
3403 case 0:
3404 temp = new KDGanttViewSummaryItem( mySignalSender, i18n( "New Summary" ) );
3405 break;
3406 case 2:
3407 temp = new KDGanttViewTaskItem( mySignalSender, i18n( "New Task" ) );
3408 break;
3409 default:
3410 ;
3411 }
3412 if ( temp )
3413 mySignalSender->editItem( temp );
3414}
3415
3416void KDGanttCanvasView::newChildItem( int type )
3417{
3418 KDGanttViewItem* temp = 0;
3419 switch( type ) {
3420 case 1:
3421 temp = new KDGanttViewEventItem( lastClickedItem, i18n( "New Event" ) );
3422 break;
3423 case 0:
3424 temp = new KDGanttViewSummaryItem( lastClickedItem, i18n( "New Summary" ) );
3425 break;
3426 case 2:
3427 temp = new KDGanttViewTaskItem( lastClickedItem, i18n( "New Task" ) );
3428 break;
3429 case 5:
3430 if ( lastClickedItem->parent() )
3431 temp = new KDGanttViewEventItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Event" ) );
3432 else
3433 temp = new KDGanttViewEventItem( mySignalSender, lastClickedItem, i18n( "New Event" ) );
3434 break;
3435 case 4:
3436 if ( lastClickedItem->parent() )
3437 temp = new KDGanttViewSummaryItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Summary" ) );
3438 else
3439 temp = new KDGanttViewSummaryItem( mySignalSender, lastClickedItem, i18n( "New Summary" ) );
3440 break;
3441 case 6:
3442 if ( lastClickedItem->parent() )
3443 temp = new KDGanttViewTaskItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Task" ) );
3444 else
3445 temp = new KDGanttViewTaskItem( mySignalSender, lastClickedItem, i18n( "New Task" ) );
3446 break;
3447
3448
3449 default:
3450 ;
3451 }
3452 if ( temp )
3453 mySignalSender->editItem( temp );
3454}
3455
3456void KDGanttCanvasView::drawToPainter ( TQPainter * p )
3457{
3458 drawContents ( p, 0, 0, canvas()->width(), canvas()->height() );
3459}
3460TQString KDGanttCanvasView::getToolTipText(TQPoint p)
3461{
3462 TQCanvasItemList il = canvas()->collisions ( viewportToContents( p ));
3463 TQCanvasItemList::Iterator it;
3464 for ( it = il.begin(); it != il.end(); ++it ) {
3465 switch (getType(*it)) {
3466 case Type_is_KDGanttViewItem:
3467 return (getItem(*it))->tooltipText();
3468 break;
3469 case Type_is_KDGanttTaskLink:
3470 return (getLink(*it))->tooltipText();
3471 break;
3472 default:
3473 break;
3474 }
3475 }
3476 return "";
3477}
3478
3479TQString KDGanttCanvasView::getWhatsThisText(TQPoint p)
3480{
3481 TQCanvasItemList il = canvas() ->collisions (viewportToContents( p ));
3482 TQCanvasItemList::Iterator it;
3483 for ( it = il.begin(); it != il.end(); ++it ) {
3484 switch (getType(*it)) {
3485 case Type_is_KDGanttViewItem:
3486 return (getItem(*it))->whatsThisText();
3487 break;
3488 case Type_is_KDGanttTaskLink:
3489 return (getLink(*it))->whatsThisText();
3490 break;
3491 default:
3492 break;
3493 }
3494 }
3495 return "";
3496}
3497
3498
3505
3506void KDGanttCanvasView::contentsMousePressEvent ( TQMouseEvent * e )
3507{
3508 //tqDebug("mousepress! %d ", this);
3509 //tqDebug("focus %d ",tqApp->focusWidget());
3510 setFocus();
3511 currentLink = 0;
3512 currentItem = 0;
3513 if (e->button() == TQt::RightButton && mySignalSender->editable()) {
3514 lastClickedItem = (KDGanttViewItem*) mySignalSender->myListView->itemAt( TQPoint(2,e->pos().y()));
3515 if ( lastClickedItem ) {
3516 if ( lastClickedItem->displaySubitemsAsGroup() && ! lastClickedItem->isOpen() ) {
3517 // findSub subitem
3518 TQCanvasItemList il = canvas() ->collisions ( e->pos() );
3519 TQCanvasItemList::Iterator it;
3520 for ( it = il.begin(); it != il.end(); ++it ) {
3521 if ( getType(*it) == Type_is_KDGanttViewItem ) {
3522 lastClickedItem = getItem(*it);
3523 }
3524 }
3525 }
3526 if ( _showItemAddPopupMenu )
3527 onItem->popup(e->globalPos());
3528 }
3529 }
3530 TQCanvasItemList il = canvas() ->collisions ( e->pos() );
3531 TQCanvasItemList::Iterator it;
3532 for ( it = il.begin(); it != il.end(); ++it ) {
3533 switch ( e->button() ) {
3534 case TQt::LeftButton:
3535 switch (getType(*it)) {
3536 case Type_is_KDGanttViewItem:
3537 currentItem = getItem(*it);
3538 if (! currentItem->enabled() ) {
3539 currentItem = 0;
3540 } else if (linkItemsEnabled &&
3541 !currentItem->isMyTextCanvas(*it)) {
3542 fromArea = getItemArea(currentItem, e->pos().x());
3543 if (fromArea > 0) {
3544 fromItem = currentItem;
3545 linkLine->setPoints(e->pos().x(), e->pos().y(), e->pos().x(), e->pos().y());
3546 linkLine->show();
3547 }
3548 }
3549 break;
3550 case Type_is_KDGanttTaskLink:
3551 currentLink = getLink(*it);
3552 break;
3553 default:
3554 break;
3555 }
3556 break;
3557 case TQt::RightButton:
3558 switch (getType(*it)) {
3559 case Type_is_KDGanttViewItem:
3560 currentItem = getItem(*it);
3561 if (! currentItem->enabled() )
3562 currentItem = 0;
3563 break;
3564 case Type_is_KDGanttTaskLink:
3565 currentLink = getLink(*it);
3566 break;
3567 }
3568 break;
3569 case TQt::MidButton:
3570 switch (getType(*it)) {
3571 case Type_is_KDGanttViewItem:
3572 currentItem = getItem(*it);
3573 if (! currentItem->enabled() )
3574 currentItem = 0;
3575 break;
3576 case Type_is_KDGanttTaskLink:
3577 currentLink = getLink(*it);
3578 break;
3579 }
3580 break;
3581 default:
3582 break;
3583 }
3584 }
3585 if (e->button() == TQt::RightButton ) {
3586 mySignalSender->gvContextMenuRequested( currentItem, e->globalPos() );
3587 }
3588 if (autoScrollEnabled && e->button() == TQt::LeftButton) {
3589 myScrollTimer->start(50);
3590 }
3591}
3598
3599void KDGanttCanvasView::contentsMouseReleaseEvent ( TQMouseEvent * e )
3600{
3601 static KDGanttViewItem* lastClicked = 0;
3602 mySignalSender->gvMouseButtonClicked( e->button(), currentItem , e->globalPos() );
3603 //tqDebug("datetime %s ",mySignalSender->getDateTimeForCoordX(e->globalPos().x(), true ).toString().latin1() );
3604 //tqDebug("mousepos %d %d ",e->pos().x(),e->pos().y() );
3605 //tqDebug("mouseup ");
3606 // if ( currentLink || currentItem )
3607 {
3608 switch ( e->button() ) {
3609 case TQt::LeftButton:
3610 myScrollTimer->stop();
3611 {
3612 mySignalSender->itemLeftClicked( currentItem );
3613 mySignalSender->gvItemLeftClicked( currentItem );
3614 }
3615 if ( currentLink )
3616 mySignalSender->taskLinkLeftClicked( currentLink );
3617 if (linkItemsEnabled && fromItem) {
3618 linkLine->hide();
3619 canvas()->update();
3620 TQCanvasItemList il = canvas() ->collisions ( e->pos() );
3621 TQCanvasItemList::Iterator it;
3622 for ( it = il.begin(); it != il.end(); ++it ) {
3623 if (getType(*it) == Type_is_KDGanttViewItem) {
3624 KDGanttViewItem *toItem = getItem(*it);
3625 if (!toItem->isMyTextCanvas(*it)) {
3626 int toArea = getItemArea(toItem, e->pos().x());
3627 if (toArea > 0 && toItem && fromItem != toItem) {
3628 mySignalSender->linkItems(fromItem, toItem, getLinkType(fromArea, toArea));
3629 }
3630 }
3631 break;
3632 }
3633 }
3634 }
3635 fromItem = 0;
3636 break;
3637 case TQt::RightButton:
3638 {
3639 mySignalSender->itemRightClicked( currentItem );
3640 mySignalSender->gvItemRightClicked( currentItem );
3641
3642 }
3643 if ( currentLink )
3644 mySignalSender->taskLinkRightClicked( currentLink );
3645 break;
3646 case TQt::MidButton:
3647 {
3648 mySignalSender->itemMidClicked( currentItem );
3649 mySignalSender->gvItemMidClicked( currentItem );
3650 }
3651 if ( currentLink )
3652 mySignalSender->taskLinkRightClicked( currentLink );
3653 break;
3654 default:
3655 break;
3656 }
3657 }
3658 if ( lastClicked != currentItem )
3659 mySignalSender->gvCurrentChanged( currentItem );
3660 lastClicked = currentItem;
3661 currentLink = 0;
3662 currentItem = 0;
3663}
3670
3671void KDGanttCanvasView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
3672{
3673 TQCanvasItemList il = canvas() ->collisions ( e->pos() );
3674 TQCanvasItemList::Iterator it;
3675 for ( it = il.begin(); it != il.end(); ++it ) {
3676 switch ( e->button() ) {
3677 case TQt::LeftButton:
3678 switch (getType(*it)) {
3679 case Type_is_KDGanttViewItem:
3680 if ( getItem(*it)->enabled() )
3681 mySignalSender->itemDoubleClicked(getItem(*it));
3682 mySignalSender->gvItemDoubleClicked(getItem(*it));
3683 return;
3684 break;
3685 case Type_is_KDGanttTaskLink:
3686 mySignalSender->taskLinkDoubleClicked(getLink(*it));
3687 return;
3688 break;
3689 default:
3690 break;
3691 }
3692 break;
3693 /*
3694 case RightButton:
3695 switch (getType(*it)) {
3696 case Type_is_KDGanttViewItem:
3697 mySignalSender->itemRightClicked(getItem(*it));
3698 return;
3699 break;
3700 case Type_is_KDGanttTaskLink:
3701 mySignalSender->taskLinkRightClicked(getLink(*it));
3702 return;
3703 break;
3704 }
3705 break;
3706 case MidButton:
3707 switch (getType(*it)) {
3708 case Type_is_KDGanttViewItem:
3709 mySignalSender->itemMidClicked(getItem(*it));
3710 return;
3711 break;
3712 case Type_is_KDGanttTaskLink:
3713 mySignalSender->taskLinkMidClicked(getLink(*it));
3714 return;
3715 break;
3716 }
3717 break;
3718 */
3719 default:
3720 break;
3721 }
3722 }
3723}
3730
3731void KDGanttCanvasView::contentsMouseMoveEvent ( TQMouseEvent *e )
3732{
3733 //tqDebug("mousemove! ");
3734 static int moves = 0;
3735 if ( (currentLink || currentItem) && (moves < 3) ) {
3736 ++moves;
3737
3738 } else {
3739 moves = 0;
3740 currentLink = 0;
3741 currentItem = 0;
3742 }
3743 if (autoScrollEnabled)
3744 mousePos = e->pos()- TQPoint(contentsX(),contentsY()); // make mousePos relative 0
3745 if (fromItem) {
3746 //tqDebug("mousemove: linking %s: %d,%d ",fromItem->listViewText().latin1(), e->pos().x(), e->pos().y());
3747 linkLine->setPoints(linkLine->startPoint().x(), linkLine->startPoint().y(), e->pos().x(), e->pos().y());
3748 canvas()->update();
3749 }
3750 // no action implemented
3751 //tqDebug("mousemove ");
3752 //TQToolTip::setGloballyEnabled (false);
3753 //TQToolTip::remove(viewport());
3754 // TQToolTip::add(viewport(), "hello");
3755 // TQToolTip::setGloballyEnabled (true);
3756 /*
3757 TQCanvasItemList il = canvas() ->collisions ( e->pos() );
3758
3759 TQCanvasItemList::Iterator it;
3760 KDGanttItem* mouseover = 0;
3761 for ( it = il.begin(); it != il.end(); ++it ) {
3762
3763 }
3764
3765 */
3766}
3767void KDGanttCanvasView::viewportPaintEvent ( TQPaintEvent * pe )
3768{
3769 TQCanvasView::viewportPaintEvent ( pe );
3770}
3771void KDGanttCanvasView::set_Mouse_Tracking(bool on)
3772{
3773 viewport()->setMouseTracking(on);
3774}
3775int KDGanttCanvasView::getType(TQCanvasItem* it)
3776{
3777 switch (it->rtti()) {
3778 case TQCanvasItem::Rtti_Line: return ((KDCanvasLine*)it)->myParentType;
3779 case TQCanvasItem::Rtti_Ellipse: return ((KDCanvasEllipse *)it)->myParentType;
3780 case TQCanvasItem::Rtti_Text: return ((KDCanvasText *)it)->myParentType;
3781 case TQCanvasItem::Rtti_Polygon: return ((KDCanvasPolygon *)it)->myParentType;
3782 case TQCanvasItem::Rtti_Rectangle: return ((KDCanvasRectangle *)it)->myParentType;
3783 }
3784 return -1;
3785}
3786KDGanttViewItem* KDGanttCanvasView::getItem(TQCanvasItem* it)
3787{
3788 switch (it->rtti()) {
3789 case TQCanvasItem::Rtti_Line: return (KDGanttViewItem*) ((KDCanvasLine*)it)->myParentItem;
3790 case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewItem*) ((KDCanvasEllipse *)it)->myParentItem;
3791 case TQCanvasItem::Rtti_Text: return (KDGanttViewItem*) ((KDCanvasText *)it)->myParentItem;
3792 case TQCanvasItem::Rtti_Polygon: return (KDGanttViewItem*) ((KDCanvasPolygon *)it)->myParentItem;
3793 case TQCanvasItem::Rtti_Rectangle: return (KDGanttViewItem*) ((KDCanvasRectangle *)it)->myParentItem;
3794
3795 }
3796 return 0;
3797}
3798KDGanttViewTaskLink* KDGanttCanvasView::getLink(TQCanvasItem* it)
3799{
3800 switch (it->rtti()) {
3801 case TQCanvasItem::Rtti_Line: return (KDGanttViewTaskLink*) ((KDCanvasLine*)it)->myParentItem;
3802 case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewTaskLink*) ((KDCanvasEllipse *)it)->myParentItem;
3803 case TQCanvasItem::Rtti_Text: return (KDGanttViewTaskLink*) ((KDCanvasText *)it)->myParentItem;
3804 case TQCanvasItem::Rtti_Polygon: return (KDGanttViewTaskLink*) ((KDCanvasPolygon *)it)->myParentItem;
3805 }
3806 return 0;
3807}
3808
3809void KDGanttCanvasView::slotScrollTimer() {
3810 int mx = mousePos.x();
3811 int my = mousePos.y();
3812 int dx = 0;
3813 int dy = 0;
3814 if (mx < 0)
3815 dx = -5;
3816 else if (mx > visibleWidth())
3817 dx = 5;
3818 if (my < 0)
3819 dy = -5;
3820 else if (my > visibleHeight())
3821 dy = TQMIN(5, verticalScrollBar()->maxValue()-verticalScrollBar()->value());
3822
3823 if (dx != 0 || dy != 0)
3824 scrollBy(dx, dy);
3825}
3826
3827int KDGanttCanvasView::getItemArea(KDGanttViewItem *item, int x) {
3828 // area can be: no area = 0, Start = 1, Finish = 2
3829 // TODO: middle (move, dnd), front, back (resize)
3830 KDTimeTableWidget *tt = dynamic_cast<KDTimeTableWidget *>(canvas());
3831 if (!tt) {
3832 tqWarning("Cannot cast canvas to KDTimeTableWidget");
3833 return 0;
3834 }
3835 int area = 0;
3836 int start = tt->getCoordX(item->startTime());
3837 int end = start;
3838 if (item->type() == KDGanttViewItem::Event) {
3839 x > start ? area = 2 : area = 1;
3840 } else {
3841 end = tt->getCoordX(item->endTime());
3842 if ((end - start)/2 > (x - start))
3843 area = 1;
3844 else
3845 area = 2;
3846 }
3847 return area;
3848}
3849
3850int KDGanttCanvasView::getLinkType(int from, int to) {
3851 // from, to should be Start = 1 or Finish = 2
3852 if ((from == 1) && (to == 1)) {
3853 return KDGanttViewTaskLink::StartStart;
3854 }
3855 if ((from == 1) && (to == 2)) {
3856 return KDGanttViewTaskLink::StartFinish;
3857 }
3858 if ((from == 2) && (to == 1)) {
3859 return KDGanttViewTaskLink::FinishStart;
3860 }
3861 if ((from == 2) && (to == 2)) {
3862 return KDGanttViewTaskLink::FinishFinish;
3863 }
3864 return KDGanttViewTaskLink::None;
3865}
The KDGanttMinimizeSplitter class implements a splitter widget with minimize buttons.
void setMaximizedWidget(TQWidget *widget)
virtual void minimize(bool minimize)
static bool decode(const TQMimeSource *e, TQString &)
static bool canDecode(const TQMimeSource *e)
KDGanttViewItem * itemBelow(bool includeDisabled=true)
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)