kdgantt

KDGanttView.cpp
1/*
2 $Id: KDGanttView.cpp 536225 2006-05-01 16:46:33Z tilladam $
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 "KDGanttView.h"
37#include "KDGanttViewSubwidgets.h"
38#include "KDGanttMinimizeSplitter.h"
39#include "KDGanttViewItem.h"
40#include "KDGanttXMLTools.h"
41#include "itemAttributeDialog.h"
42#include <tqprinter.h>
43#include <tqpainter.h>
44#include <tqlayout.h>
45#include <tqpaintdevicemetrics.h>
46#include <tqfile.h>
47#include <tqheader.h>
48#include <tqscrollview.h>
49#include <tqapplication.h>
50#include <tqevent.h>
51#include <tqiconview.h>
52
53#include <tqmessagebox.h>
54#include <tqfileinfo.h>
55
56#ifndef KDGANTT_MASTER_CVS
57#include "KDGanttView.moc"
58#endif
59
60#if defined KDAB_EVAL
61#include "../evaldialog/evaldialog.h"
62#endif
63
75
82
83KDGanttView::KDGanttView( TQWidget* parent, const char* name )
84 : KDGanttMinimizeSplitter( TQt::Vertical, parent, name ),
85 myCanvasView(0),
86 myTimeHeaderScroll(0)
87{
88#if defined KDAB_EVAL
89 EvalDialog::checkEvalLicense( "KD Gantt" );
90#endif
91 myCurrentItem = 0;
92 setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
93 mySplitter = new KDGanttMinimizeSplitter( this );
94 mySplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left );
95 leftWidget = new TQVBox( mySplitter );
96 rightWidget = new TQVBox( mySplitter );
97
98 myLegend = new KDLegendWidget( leftWidget, this );
99 spacerLeft = new TQHBox( leftWidget );
100 myListView = new KDListView(leftWidget, this);
101 myListView->setVScrollBarMode (TQScrollView::AlwaysOff );
102 connect( myListView, TQ_SIGNAL( selectionChanged( TQListViewItem* ) ),
103 this, TQ_SLOT( slotSelectionChanged( TQListViewItem* ) ) );
104
105 connect( myListView, TQ_SIGNAL( mouseButtonClicked ( int, TQListViewItem * , const TQPoint &, int ) ), this, TQ_SLOT( slotmouseButtonClicked ( int , TQListViewItem * , const TQPoint &, int ) ) );
106 connect( myListView, TQ_SIGNAL( contextMenuRequested ( TQListViewItem * , const TQPoint &, int ) ), this, TQ_SLOT( slotcontextMenuRequested ( TQListViewItem * , const TQPoint & , int ) ) );
107 connect( myListView, TQ_SIGNAL(doubleClicked ( TQListViewItem * ) ), this, TQ_SLOT(slotdoubleClicked ( TQListViewItem * ) ) );
108
109 connect( myListView, TQ_SIGNAL(currentChanged( TQListViewItem * ) ), this, TQ_SLOT(slotCurrentChanged ( TQListViewItem * ) ) );
110 connect( myListView, TQ_SIGNAL(itemRenamed ( TQListViewItem * , int , const TQString & ) ), this, TQ_SLOT(slotItemRenamed ( TQListViewItem *, int , const TQString & ) ) );
111 connect( myListView, TQ_SIGNAL(mouseButtonPressed( int, TQListViewItem * , const TQPoint &, int ) ), this, TQ_SLOT(slotMouseButtonPressed ( int , TQListViewItem * , const TQPoint & , int ) ) );
112
113 //connect( myListView, TQ_SIGNAL( ), this, TQ_SLOT( ) );
114 myTimeTable = new KDTimeTableWidget (rightWidget,this);
115
116 spacerRight = new TQWidget( rightWidget );
117
118 myTimeHeaderContainer = new TQHBox( rightWidget );
119 myTimeHeaderContainer->setFrameStyle( TQFrame::NoFrame );
120 myTimeHeaderContainer->setMargin( 0 );
121 myTimeHeaderScroll = new TQScrollView ( myTimeHeaderContainer );
122 myTimeHeaderScroll->setHScrollBarMode( TQScrollView::AlwaysOff );
123 myTimeHeaderScroll->setVScrollBarMode( TQScrollView::AlwaysOff );
124 timeHeaderSpacerWidget = new TQWidget( myTimeHeaderContainer );
125
126
127 /*
128 myTimeHeaderScroll = new TQScrollView ( rightWidget );
129 myTimeHeaderScroll->setHScrollBarMode( TQScrollView::AlwaysOff );
130 myTimeHeaderScroll->setVScrollBarMode( TQScrollView::AlwaysOn );
131 */
132 //myTimeHeader = new KDTimeHeaderWidget (rightWidget,this);
133 myTimeHeader = new KDTimeHeaderWidget (myTimeHeaderScroll->viewport(),this);
134 myTimeHeaderScroll->addChild( myTimeHeader );
135 myTimeHeaderScroll->viewport()->setBackgroundColor( myTimeHeader->backgroundColor() );
136 timeHeaderSpacerWidget->setBackgroundColor( myTimeHeader->backgroundColor() );
137 myCanvasView = new KDGanttCanvasView (this,myTimeTable,rightWidget);
138 myTimeHeaderScroll->setFrameStyle( TQFrame::NoFrame );
139 //
140 myCanvasView->setFrameStyle( TQFrame::NoFrame );
141 myCanvasView->setMargin( 0 );
142 //
143 myTimeHeaderScroll->setMargin( 0 );//myCanvasView->frameWidth() );
144 setFrameStyle(myListView->frameStyle());
145 setLineWidth( 2 );
146 myListView->setFrameStyle( TQFrame::NoFrame );
147 myListView->setMargin( 0 );
148 TQObject::connect(myListView, TQ_SIGNAL ( expanded ( TQListViewItem * ) ) , myTimeTable , TQ_SLOT( expandItem(TQListViewItem * ))) ;
149 TQObject::connect(myListView, TQ_SIGNAL (collapsed ( TQListViewItem * ) ) , myTimeTable , TQ_SLOT(collapseItem(TQListViewItem * ))) ;
150
151 timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
152 listViewIsVisible = true;
153 chartIsEditable = true;
154 editorIsEnabled = true;
155 _displaySubitemsAsGroup = false;
156 initDefaults();
157 _showHeader = false;
158
159 myTextColor = TQt::black;
160 myLegendItems = new TQPtrList<legendItem>;
161 //TQObject::connect( this, TQ_SIGNAL (itemDoubleClicked( KDGanttViewItem* ) ) , this, TQ_SLOT( editItem( KDGanttViewItem* ))) ;
162 myItemAttributeDialog = new itemAttributeDialog();
163 setRepaintMode( KDGanttView::Medium );
164 //setRepaintMode( KDGanttView::Always );
165 setShowLegendButton( true );
166 setHeaderVisible( false );
167
168 // now connecting the widgets
169 connect(myCanvasView->horizontalScrollBar(), TQ_SIGNAL ( valueChanged ( int )) ,myTimeHeaderScroll->horizontalScrollBar(), TQ_SLOT( setValue ( int))) ;
170 connect(myCanvasView, TQ_SIGNAL ( heightResized( int )) ,myTimeTable, TQ_SLOT( checkHeight ( int))) ;
171 connect(myCanvasView, TQ_SIGNAL ( widthResized( int )) ,myTimeHeader, TQ_SLOT( checkWidth ( int))) ;
172
173 TQObject::connect(myCanvasView->verticalScrollBar(), TQ_SIGNAL ( valueChanged ( int ) ) ,myListView->verticalScrollBar(), TQ_SLOT( setValue ( int ))) ;
174 connect(myTimeHeader, TQ_SIGNAL ( sizeChanged( int ) ) ,this, TQ_SLOT(slotHeaderSizeChanged() )) ;
175 connect(myTimeHeader, TQ_SIGNAL ( sizeChanged( int ) ) ,myTimeTable, TQ_SLOT(resetWidth( int ) )) ;
176 connect(myListView, TQ_SIGNAL ( contentsMoving ( int, int ) ) ,myCanvasView, TQ_SLOT( moveMyContent( int, int ))) ;
177 connect(myTimeTable, TQ_SIGNAL ( heightComputed ( int ) ) ,myCanvasView, TQ_SLOT( setMyContentsHeight( int ))) ;
178 // the next three are for adding new ticks at left/right
179 connect( myCanvasView->horizontalScrollBar(), TQ_SIGNAL (prevLine () ) ,this, TQ_SLOT(addTickLeft()));
180 connect( myCanvasView->horizontalScrollBar(), TQ_SIGNAL (nextLine () ) ,this, TQ_SLOT(addTickRight()));
181 connect( myCanvasView->horizontalScrollBar(), TQ_SIGNAL (valueChanged ( int ) ) ,this, TQ_SLOT( enableAdding( int )));
182
183 // now initing
184 fCenterTimeLineAfterShow = false;
185 fDragEnabled = false;
186 fDropEnabled = false;
187 closingBlocked = false;
188 myTimeHeader->computeTicks();
189 centerTimelineAfterShow( TQDateTime::currentDateTime () );
191 TQValueList<int> list;
192 list.append(240);
193 list.append(530);
194 mySplitter->setSizes( list );
195 myTimeTable->setBlockUpdating();// block updating until this->show() is called
196}
197
198
199
200KDGanttView::~KDGanttView()
201{
202 setUpdateEnabled(false);
203 // delete cut item, if there is any
204 myCanvasView->resetCutPaste( 0 );
205 myTimeTable->clearTaskLinks();
206}
231{
232 myTimeTable->setBlockUpdating( !enable );
233 if ( enable ) {
234 myTimeTable->updateMyContent();
235 myCanvasView->setMyContentsHeight( 0 );
236 }
237}
238
245
247{
248 return !myTimeTable->blockUpdating();
249}
250
251
252
253
259
261{
262 myTimeHeader->setMaximumWidth ( w );
263}
264
270
272{
273 return myTimeHeader->maximumWidth();
274}
275
281
283{
284 myTimeTable->setBlockUpdating( false );
285 if (myCanvasView->horizontalScrollBar()->value() > 0 )
286 myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->value()-1 );
287 else
288 myCanvasView->horizontalScrollBar()->setValue(1 );
289 myTimeTable->updateMyContent();
290 TQWidget::show();
291 myCanvasView->setMyContentsHeight( 0 );
292 if ( fCenterTimeLineAfterShow ) {
293 fCenterTimeLineAfterShow = false;
294 centerTimeline (dtCenterTimeLineAfterShow);
295 }
296}
297
303
304bool KDGanttView::close ( bool alsoDelete )
305{
306 //tqDebug("close ");
307 if ( closingBlocked )
308 return false;
309 return TQWidget::close ( alsoDelete );
310}
311
312
320
322{
323 bool block = myTimeTable->blockUpdating();
324 myTimeTable->setBlockUpdating( false );
325 myTimeTable->updateMyContent();
326 /* The below causes recursive calls to various size updating methods, which
327 * cause TQCanvas to hide and show items like mad, which is very slow. If
328 * there is a legitimate gui updating issue here somewhere, it will need
329 * to be solved differently.
330 */
331 //tqApp->processEvents();
332 int hintHeight = myTimeHeader->height();
333 int legendHeight = 0;
334 if ( showLegendButton() )
335 legendHeight = myLegend->height();
336 int listViewHeaderHeight = 0;
337 if ( headerVisible() )
338 listViewHeaderHeight = myListView->header()->height();
339 if ( hintHeight < legendHeight+listViewHeaderHeight )
340 hintHeight = legendHeight + listViewHeaderHeight;
341 hintHeight += myListView->horizontalScrollBar()->height();
342 if ( myLegend->isShown() )
343 hintHeight += myLegend->legendSizeHint().height() +10;
344 hintHeight += myTimeTable->minimumHeight+myListView->frameWidth()*2+2;
345 int hintWid = myListView->sizeHint().width();
346 //hintWid += myTimeHeader->mySizeHint+myCanvasView->verticalScrollBar()->width();
347 hintWid += myCanvasView->sizeHint().width();
348 // add 10 for the splitter-bars
349 // tqDebug("sizehint %d %d ",hintWid+10, hintHeight );
350 myTimeTable->setBlockUpdating( block );
351 return TQSize( hintWid+10, hintHeight );
352}
353
354
363{
364 _showLegendButton = show;
365 if ( show )
366 myLegend->show();
367 else
368 myLegend->hide();
369 slotHeaderSizeChanged();
370}
371
372
380{
381 return _showLegendButton;
382}
383
384
392{
393 if( visible )
394 myListView->header()->show();
395 else
396 myListView->header()->hide();
397 _showHeader = visible;
398 slotHeaderSizeChanged();
399}
400
401
408{
409 return _showHeader;
410}
411
412
421TQDateTime KDGanttView::getDateTimeForCoordX(int coordX, bool global ) const
422{
423 // default for myTimeHeader->getDateTimeForIndex() is local
424 return myTimeHeader->getDateTimeForIndex(coordX, !global );
425}
426
427
431void KDGanttView::slotSelectionChanged( TQListViewItem* item )
432{
433 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
434 Q_ASSERT( gItem );
435 emit lvSelectionChanged( gItem );
436}
437
438
439/*
440 Implements a casted pass-through of the mouseButtonClicked() signal.
441 Signals itemLeftClicked() , itemMidClicked() are emitted as well.
442*/
443void KDGanttView::slotmouseButtonClicked ( int button, TQListViewItem * item,
444 const TQPoint & pos, int c )
445{
446 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
447 emit lvMouseButtonClicked ( button , gItem, pos, c );
448 if (gItem == 0 && myCurrentItem != 0 ) {
449 myCurrentItem = 0;
450 emit lvCurrentChanged( gItem );
451 }
452 if (gItem != 0 && myCurrentItem == 0 ) {
453 myCurrentItem = gItem;
454 emit lvCurrentChanged( gItem );
455 }
456
457 // removed - makes no sense!
458 //emit mouseButtonClicked ( button , gItem, pos, c );
459 {
460 switch ( button ) {
461 case TQt::LeftButton:
462 emit lvItemLeftClicked( gItem );
463 emit itemLeftClicked( gItem );
464 break;
465 case TQt::MidButton:
466 emit lvItemMidClicked( gItem );
467 emit itemMidClicked( gItem );
468 break;
469 }
470 }
471}
472
473
474/*
475 Implements a casted pass-through of the contextMenuRequested() signal.
476 The signal itemRightClicked() is emitted as well;
477 the position is the global position.
478*/
479void KDGanttView::slotcontextMenuRequested ( TQListViewItem * item, const TQPoint & pos, int col )
480{
481 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
482 emit lvContextMenuRequested ( gItem, pos, col );
483 emit lvItemRightClicked( gItem );
484 emit itemRightClicked( gItem );
485}
486
487
488/*
489 Implements a casted pass-through of the doubleClicked() signal.
490*/
491void KDGanttView::slotdoubleClicked ( TQListViewItem * item )
492{
493 {
494 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
495 emit lvItemDoubleClicked( gItem );
496 emit itemDoubleClicked( gItem );
497 }
498}
499
500
501/*
502 Implements a casted pass-through of the currentChanged() signal.
503*/
504void KDGanttView::slotCurrentChanged ( TQListViewItem * item )
505{
506 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
507 myCurrentItem = gItem;
508 emit lvCurrentChanged( gItem );
509}
510
511
512/*
513 Implements a casted pass-through of the itemRenamed() signal.
514*/
515void KDGanttView::slotItemRenamed ( TQListViewItem * item , int col,
516 const TQString & text )
517{
518 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
519 emit lvItemRenamed( gItem, col, text );
520}
521
522
523/*
524 Implements a casted pass-through of the mouseButtonPressed() signal.
525*/
526void KDGanttView::slotMouseButtonPressed ( int button, TQListViewItem * item,
527 const TQPoint & pos, int c )
528{
529 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
530 emit lvMouseButtonPressed( button, gItem, pos, c );
531}
532
533
549{
550
551 TQScrollBar *cvh, *cvv;
552 cvh = myCanvasView->horizontalScrollBar();
553 cvv = myCanvasView->verticalScrollBar();
554 // first disconnect
555 cvh->disconnect( this );
556 cvv->disconnect( this );
557
558 switch ( mode ) {
559 case No:
560
561 break;
562 case Medium:
563 connect( cvv, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
564 connect( cvh, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
565 connect( cvv, TQ_SIGNAL (nextLine () ) ,this, TQ_SLOT(forceRepaint()));
566 connect( cvh, TQ_SIGNAL (nextLine () ) ,this, TQ_SLOT(forceRepaint()));
567 connect( cvv, TQ_SIGNAL (prevLine () ) ,this, TQ_SLOT(forceRepaint()));
568 connect( cvh, TQ_SIGNAL (prevLine () ) ,this, TQ_SLOT(forceRepaint()));
569 break;
570 case Always:
571 connect( cvv, TQ_SIGNAL (valueChanged ( int ) ) ,this, TQ_SLOT(forceRepaint( int )));
572 connect( cvh, TQ_SIGNAL (valueChanged ( int ) ) ,this, TQ_SLOT(forceRepaint( int )));
573 connect( cvv, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
574 connect( cvh, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
575 break;
576 }
577}
578
579
580void KDGanttView::forceRepaint( int )
581{
582 if ( myTimeTable->blockUpdating() )
583 return;
584 // tqDebug("forceRepaint( int ) ");
585 myTimeTable->setAllChanged();
586 myTimeTable->update();
587}
588
589
590void KDGanttView::slotHeaderSizeChanged()
591{
592 int legendHeight = 0;
593 if ( showLegendButton() )
594 legendHeight = 24;
595 int listViewHeaderHeight = 0;
596 if ( headerVisible() )
597 listViewHeaderHeight = myListView->header()->height();
598 int timeHeaderHeight = myTimeHeader->height()+myTimeHeaderScroll->frameWidth()*2;;
599 int diffY = timeHeaderHeight-legendHeight-listViewHeaderHeight;
600 if ( diffY < 0 ) {
601 spacerLeft->setFixedHeight( 0 );
602 spacerRight->setFixedHeight(-diffY);
603 } else {
604 spacerRight->setFixedHeight( 0 );
605 spacerLeft->setFixedHeight( diffY );
606 }
607 myLegend->setFixedHeight( legendHeight );
608 myTimeHeaderContainer->setFixedHeight( timeHeaderHeight );
609}
610
611
618{
619 bool isdock = myLegend->asDoctwindow();
620 if ( show != isdock ) {
621 myLegend->setAsDoctwindow(show);
622 // legend is cleared - reinit legend with list
623 legendItem* li;
624 for ( li = myLegendItems->first(); li; li = myLegendItems->next() ) {
625 myLegend->addLegendItem(li->shape, li->color, li->text );
626 }
627 }
628}
629
630
637{
638 return myLegend->asDoctwindow();
639}
640
641
654TQDockWindow* KDGanttView::legendDoctwindow() const
655{
656 return myLegend->dockwindow();
657}
658
659
669{
670 myLegend->showMe(show);
671}
672
673
683{
684 return myLegend->isShown();
685}
686
687
697{
698 if(listViewIsVisible == show) return;
699 listViewIsVisible = show;
700 if (listViewIsVisible)
701 myListView->parentWidget()->show();
702 else
703 myListView->parentWidget()->hide();
704}
705
706
714{
715 return listViewIsVisible;
716}
717
718
727
729{
730 editorIsEnabled = enable;
731}
732
733
741
743{
744 return editorIsEnabled;
745}
746
747
755
757{
758 chartIsEditable = editable;
759}
760
761
768
770{
771 return chartIsEditable;
772}
773
774
785
786bool KDGanttView::saveProject( TQIODevice* device )
787{
788 Q_ASSERT( device );
789
790 TQDomDocument doc = saveXML();
791 if( device->isOpen() )
792 device->close();
793 if( device->open( IO_WriteOnly ) ) {
794 TQTextStream ts( device );
795 ts << doc.toString();
796 return true;
797 } else
798 return false;
799}
800
801
812
813bool KDGanttView::loadProject( TQIODevice* device )
814{
815 Q_ASSERT( device );
816
817 if( device->isOpen() )
818 device->close();
819 if( device->open( IO_ReadOnly ) ) {
820 TQDomDocument doc( "GanttView" );
821 TQString err;
822 int errline, errcol;
823 if ( !doc.setContent( device, &err, &errline, &errcol ) ) {
824 tqDebug("KDGantt::Error parsing XML data at line %d. Message is:", errline );
825 tqDebug("%s ", err.latin1());
826 device->close();
827 return false;
828 }
829 device->close();
830 return loadXML( doc );
831 } else
832 return false;
833}
834
835
853
854void KDGanttView::print( TQPrinter* printer ,
855 bool printListView, bool printTimeLine,
856 bool printLegend )
857{
858 bool deletePrinter = false;
859 if (! printer ) {
860 printer = new TQPrinter();
861 deletePrinter = true;
862 if ( !printer->setup()) {
863 delete printer;
864 return;
865 }
866 }
867 // now we have a printer to print on
868 TQPainter p( printer );
869 // get the paper metrics
870 TQPaintDeviceMetrics m = TQPaintDeviceMetrics ( printer );
871 float dx, dy;
872 // get the size of the desired output for scaling.
873 // here we want to print all: ListView, TimeLine, and Legend
874 // for this purpose, we call drawContents() with a 0 pointer as painter
875 TQSize size = drawContents( 0, printListView, printTimeLine, printLegend );
876
877 // at the top, we want to print current time/date
878 TQString date = "Printing Time: " + TQDateTime::currentDateTime().toString();
879 int hei = p.boundingRect(0,0, 5, 5, TQt::AlignLeft, date ).height();
880 p.drawText( 0, 0, date );
881
882 // compute the scale
883 dx = (float) m.width() / (float)size.width();
884 dy = (float)(m.height() - ( 2 * hei )) / (float)size.height();
885 float scale;
886 // scale to fit the width or height of the paper
887 if ( dx < dy )
888 scale = dx;
889 else
890 scale = dy;
891 // set the scale
892 p.scale( scale, scale );
893 // now printing with y offset: 2 hei
894 p.translate( 0, 2*hei );
895 drawContents( &p, printListView, printTimeLine, printLegend );
896 // the drawContents() has the side effect, that the painter translation is
897 // after drawContents() set to the bottom of the painted stuff
898 // for instance a
899 // p.drawText(0, 0, "printend");
900 // would be painted directly below the paintout of drawContents()
901 p.end();
902 if ( deletePrinter )
903 delete printer;
904}
905
906
946TQSize KDGanttView::drawContents( TQPainter* p,
947 bool drawListView , bool drawTimeLine, bool drawLegend )
948{
949 TQSize size;
950 int lvX, lvY, thX, thY, tlX, tlY, lwX, lwY, allX, allY;
951 lvX = myListView->contentsWidth();
952 lvY = myCanvasView->canvas()->height() + 20;
953 thX = myTimeHeader->width();
954 thY = myTimeHeader->height();
955 tlX = myCanvasView->canvas()->width();
956 tlY = lvY;
957 lwX = myLegend->legendSize().width();
958 lwY = myLegend->legendSize().height();
959 allX = 0;
960 allY = 0;
961 if ( drawListView ) {
962 allX += lvX;
963 allY += tlY;
964 }
965 if ( drawTimeLine ) {
966 allX += thX;
967 allY += thY;
968 }
969 if ( drawLegend ) {
970 allY += lwY;
971 if ( allX < lwX )
972 allX = lwX ;
973 }
974 size = TQSize( allX, allY );
975 int temp = 0;
976 if ( p ) {
977 if ( drawListView ) {
978 if ( drawTimeLine )
979 temp = thY;
980 p->translate( 0, temp );
981 //HACK: Only draw list headers if we draw timeline, else
982 // there is no room for it.
983 myListView->drawToPainter( p, drawTimeLine );
984 p->translate( lvX, -temp);
985 }
986 if ( drawTimeLine ) {
987 p->translate( myCanvasView->frameWidth(), 0);
988 myTimeHeader->repaintMe( 0, myTimeHeader->width(), p );
989 p->translate( -myCanvasView->frameWidth(), thY);
990 myCanvasView->drawToPainter( p );
991 if ( drawListView )
992 p->translate( -lvX, tlY);
993 else
994 p->translate( 0, tlY);
995 } else {
996 if ( drawListView )
997 p->translate( -lvX, 0 );
998 }
999 if ( drawLegend ) {
1000 myLegend->drawToPainter( p );
1001 p->translate( 0, lwY );
1002 }
1003 }
1004 return size;
1005}
1006
1019
1020void KDGanttView::setZoomFactor( double factor, bool absolute )
1021{
1022 myTimeHeader->zoom(factor,absolute);
1023}
1024
1025
1032
1034{
1035 return myTimeHeader->zoomFactor();
1036}
1037
1038
1046
1048{
1049 myTimeHeader->zoomToFit();
1050}
1051
1052
1063
1064void KDGanttView::zoomToSelection( const TQDateTime& start, const TQDateTime& end )
1065{
1066
1067 myTimeHeader->zoomToSelection( start, end);
1068
1069}
1070
1071
1078void KDGanttView::ensureVisible( KDGanttViewItem* item )
1079{
1080 myListView->ensureItemVisible (item);
1081}
1082
1083
1092void KDGanttView::centerTimeline( const TQDateTime& center )
1093{
1094 myTimeHeader->centerDateTime( center );
1095}
1096
1097
1112{
1113 myTimeHeader->centerDateTime( center );
1114 if ( ! isVisible() ) {
1115 dtCenterTimeLineAfterShow = center;
1116 fCenterTimeLineAfterShow = true;
1117 }
1118}
1119
1123
1125{
1126 myCanvasView->horizontalScrollBar()->setValue( 0 );
1127}
1128
1129
1134{
1135 myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->maxValue());
1136}
1137
1138
1150{
1151 myTimeHeader->addTickLeft( num );
1152}
1153
1154
1165{
1166 myTimeHeader->addTickRight( num );
1167}
1168
1169
1174void KDGanttView::center( KDGanttViewItem* item )
1175{
1176 ensureVisible(item);
1177 int x = myListView->contentsWidth()/2;
1178 int y = myListView->itemPos (item );
1179 myListView->center(x,y);
1180}
1181
1182
1190{
1191 myTimeTable->setShowTaskLinks(show);
1192
1193}
1194
1195
1203{
1204 return myTimeTable->showTaskLinks();
1205}
1206
1207
1215void KDGanttView::setFont(const TQFont& font)
1216{
1217 myListView->setFont(font);
1218 myListView->repaint();
1219 myTimeHeader->setFont(font);
1220 myLegend->setFont( font );
1221 TQWidget::setFont( font );
1222 setScale(scale());
1223}
1224
1225
1251 bool showZoom,
1252 bool showScale,
1253 bool showTime,
1254 bool showYear,
1255 bool showGrid,
1256 bool showPrint)
1257{
1258 myTimeHeader->setShowPopupMenu( show,showZoom,showScale,showTime,
1259 showYear,showGrid,showPrint );
1260}
1261
1262
1270{
1271 return myTimeHeader->showPopupMenu();
1272}
1273//****************************************************
1274
1275
1290{
1291 myCanvasView->setShowPopupMenu( show );
1292}
1293
1294
1302{
1303 return myCanvasView->showPopupMenu();
1304}
1305
1306
1328 bool overwriteExisting )
1329{
1330 if ( overwriteExisting ) {
1331 TQListViewItemIterator it(myListView);
1332 for ( ; it.current(); ++it ) {
1333 if ( ((KDGanttViewItem*)it.current())->type() == type)
1334 ((KDGanttViewItem*)it.current())->setShapes(start,middle, end );
1335 }
1336 }
1337 int index = getIndex( type );
1338 myDefaultShape [index*3] = start;
1339 myDefaultShape [index*3+1] = middle;
1340 myDefaultShape [index*3+2] = end;
1341 undefinedShape[index] = false;
1342}
1343
1344
1359 KDGanttViewItem::Shape& middle,
1360 KDGanttViewItem::Shape& end ) const
1361{
1362 int index = getIndex( type );
1363 start = myDefaultShape [index*3];
1364 middle = myDefaultShape [index*3+1];
1365 end = myDefaultShape [index*3+2];
1366 return !undefinedShape[index];
1367}
1368
1369
1388 const TQColor& start, const TQColor& middle,
1389 const TQColor& end,
1390 bool overwriteExisting )
1391{
1392 if ( overwriteExisting ) {
1393 TQListViewItemIterator it(myListView);
1394 for ( ; it.current(); ++it ) {
1395 if ( ((KDGanttViewItem*)it.current())->type() == type)
1396 ((KDGanttViewItem*)it.current())->setColors(start,middle, end );
1397 }
1398 }
1399 int index = getIndex( type );
1400 myColor [index*3] = start;
1401 myColor [index*3+1] = middle;
1402 myColor [index*3+2] = end;
1403 undefinedColor[index] = false;
1404}
1405
1406
1420 TQColor& start, TQColor& middle, TQColor& end ) const
1421{
1422 int index = getIndex( type );
1423 start = myColor [index*3];
1424 middle = myColor [index*3+1];
1425 end = myColor [index*3+2];
1426 return !undefinedColor[index];
1427}
1428
1429
1450 const TQColor& start,
1451 const TQColor& middle,
1452 const TQColor& end,
1453 bool overwriteExisting )
1454{
1455 if ( overwriteExisting ) {
1456 TQListViewItemIterator it(myListView);
1457 for ( ; it.current(); ++it ) {
1458 if ( ((KDGanttViewItem*)it.current())->type() == type)
1459 ((KDGanttViewItem*)it.current())->setHighlightColors(start,middle, end );
1460 }
1461 }
1462 int index = getIndex( type );
1463 myColorHL [index*3] = start;
1464 myColorHL [index*3+1] = middle;
1465 myColorHL [index*3+2] = end;
1466 undefinedColorHL[index] = false;
1467
1468}
1469
1470
1486 TQColor& start, TQColor& middle,
1487 TQColor& end ) const
1488{
1489 int index = getIndex( type );
1490 start = myColorHL [index*3];
1491 middle = myColorHL [index*3+1];
1492 end = myColorHL [index*3+2];
1493 return !undefinedColorHL[index];
1494}
1495
1496
1504void KDGanttView::setTextColor( const TQColor& color )
1505{
1506 TQListViewItemIterator it(myListView);
1507 for ( ; it.current(); ++it ) {
1508 ((KDGanttViewItem*)it.current())->setTextColor(color);
1509 }
1510 myTextColor = color;
1511}
1512
1513
1521{
1522 return myTextColor;
1523}
1524
1525
1536void KDGanttView::setNoInformationBrush( const TQBrush& brush )
1537{
1538 myTimeTable->setNoInformationBrush( brush );
1539}
1540
1541
1549{
1550 return myTimeTable->noInformationBrush();
1551}
1552
1553
1560{
1561 myLegend->clearLegend();
1562 myLegendItems->setAutoDelete( true );
1563 delete myLegendItems;
1564 myLegendItems = new TQPtrList<legendItem>;
1565}
1566
1567
1577 const TQColor& shapeColor,
1578 const TQString& text )
1579{
1580 myLegend->addLegendItem( shape,shapeColor,text );
1581 legendItem* item = new legendItem;
1582 item->shape = shape;
1583 item->color = shapeColor;
1584 item->text = text;
1585 myLegendItems->append( item );
1586}
1587
1588
1596void KDGanttView::setHorizonStart( const TQDateTime& start )
1597{
1598 myTimeHeader->setHorizonStart(start);
1599}
1600
1601
1609{
1610 return myTimeHeader->horizonStart();
1611}
1612
1613
1621void KDGanttView::setHorizonEnd( const TQDateTime& end )
1622{
1623 myTimeHeader->setHorizonEnd(end);
1624}
1625
1626
1634TQDateTime KDGanttView::horizonEnd() const
1635{
1636 return myTimeHeader->horizonEnd();
1637}
1638
1639
1648{
1649 myTimeHeader->setScale( unit );
1650}
1651
1652
1660{
1661 return myTimeHeader->scale();
1662}
1663
1664
1672{
1673 myTimeHeader->setMaximumScale( unit );
1674}
1675
1676
1684{
1685 return myTimeHeader->maximumScale();
1686}
1687
1688
1696{
1697 myTimeHeader->setMinimumScale( unit );
1698}
1699
1700
1708{
1709 return myTimeHeader->minimumScale();
1710}
1711
1712
1723{
1724 myTimeHeader->setAutoScaleMinorTickCount( count );
1725}
1726
1727
1735{
1736 return myTimeHeader->autoScaleMinorTickCount();
1737}
1738
1739
1749{
1750 myTimeHeader->setMinimumColumnWidth( width );
1751}
1752
1753
1761{
1762 return myTimeHeader->minimumColumnWidth();
1763}
1764
1765
1774{
1775 myTimeHeader->setYearFormat(format );
1776}
1777
1778
1786{
1787 return myTimeHeader->yearFormat();
1788}
1789
1790
1800{
1801 myTimeHeader->setHourFormat( format );
1802}
1803
1804
1813{
1814 return myTimeHeader->hourFormat();
1815}
1816
1817
1829{
1830 myTimeHeader->setShowMajorTicks(show );
1831}
1832
1833
1841{
1842 return myTimeHeader->showMajorTicks();
1843}
1844
1845
1859{
1860 myTimeHeader->setShowMinorTicks( show );
1861}
1862
1863
1871{
1872 return myTimeHeader->showMinorTicks();
1873}
1874
1875
1893void KDGanttView::setColumnBackgroundColor( const TQDateTime& column,
1894 const TQColor& color ,
1895 Scale mini, Scale maxi )
1896{
1897 myTimeHeader->setColumnBackgroundColor( column, color,mini,maxi );
1898}
1899
1900
1927void KDGanttView::setIntervalBackgroundColor( const TQDateTime& start,
1928 const TQDateTime& end,
1929 const TQColor& color ,
1930 Scale mini, Scale maxi )
1931{
1932 myTimeHeader->setIntervalBackgroundColor( start, end, color,mini,maxi );
1933}
1934
1935
1954bool KDGanttView::changeBackgroundInterval( const TQDateTime& oldstart,
1955 const TQDateTime& oldend,
1956 const TQDateTime& newstart,
1957 const TQDateTime& newend )
1958{
1959 return myTimeHeader->changeBackgroundInterval( oldstart, oldend,
1960 newstart, newend );
1961}
1962
1972bool KDGanttView::deleteBackgroundInterval( const TQDateTime& start,
1973 const TQDateTime& end)
1974{
1975 return myTimeHeader->deleteBackgroundInterval( start, end );
1976}
1977
1978
1988{
1989 myTimeHeader->clearBackgroundColor();
1990}
1991
1992
2001TQColor KDGanttView::columnBackgroundColor( const TQDateTime& column ) const
2002{
2003 return myTimeHeader->columnBackgroundColor( column ) ;
2004}
2005
2006
2015void KDGanttView::setWeekendBackgroundColor( const TQColor& color )
2016{
2017 myTimeHeader->setWeekendBackgroundColor( color );
2018}
2019
2020
2028{
2029 return myTimeHeader->weekendBackgroundColor();
2030}
2031
2032
2043void KDGanttView::setWeekdayBackgroundColor( const TQColor& color, int weekday )
2044{
2045 myTimeHeader->setWeekdayBackgroundColor( color, weekday );
2046}
2047
2048
2056TQColor KDGanttView::weekdayBackgroundColor(int weekday) const
2057{
2058 return myTimeHeader->weekdayBackgroundColor( weekday);
2059}
2060
2061
2062
2073void KDGanttView::setWeekendDays( int start, int end )
2074{
2075 myTimeHeader->setWeekendDays( start, end );
2076}
2077
2078
2086void KDGanttView::weekendDays( int& start, int& end ) const
2087{
2088 myTimeHeader->weekendDays( start, end );
2089}
2090
2091
2098
2099
2106
2107
2114
2115
2121
2122
2129
2130
2131
2138
2139
2146
2147
2154
2155
2161
2162
2168
2169
2175
2176
2182
2183
2184
2185
2193{
2194 myTimeHeader->setMajorScaleCount(count );
2195}
2196
2197
2205{
2206 return myTimeHeader->majorScaleCount();
2207}
2208
2209
2217{
2218 myTimeHeader->setMinorScaleCount(count );
2219}
2220
2221
2229{
2230 return myTimeHeader->minorScaleCount();
2231
2232}
2233
2234
2248 const TQColor& color,
2249 bool overwriteExisting )
2250{
2251 if ( overwriteExisting ) {
2252 TQListViewItemIterator it(myListView);
2253 for ( ; it.current(); ++it ) {
2254 if ( ((KDGanttViewItem*)it.current())->type() == type)
2255 ((KDGanttViewItem*)it.current())->setDefaultColor(color );
2256 }
2257 }
2258 int index = getIndex( type );
2259 myDefaultColor [index] = color;
2260}
2261
2262
2263
2275{
2276 int index = getIndex( type );
2277 return myDefaultColor [index];
2278}
2279
2280
2294 const TQColor& color,
2295 bool overwriteExisting )
2296{
2297 if ( overwriteExisting ) {
2298 TQListViewItemIterator it(myListView);
2299 for ( ; it.current(); ++it ) {
2300 if ( ((KDGanttViewItem*)it.current())->type() == type)
2301 ((KDGanttViewItem*)it.current())->setDefaultHighlightColor(color );
2302 }
2303 }
2304 int index = getIndex( type );
2305 myDefaultColorHL [index] = color;
2306}
2307
2308
2309
2321{
2322 int index = getIndex( type );
2323 return myDefaultColorHL [index];
2324}
2325
2326
2332KDGanttViewItem* KDGanttView::firstChild() const
2333{
2334 return (KDGanttViewItem*)myListView->firstChild();
2335
2336}
2337
2355{
2356 myListView->setCalendarMode( mode );
2357}
2358
2359
2368{
2369 return myListView->calendarMode();
2370}
2371
2372
2373
2384{
2385 TQListViewItemIterator it( myListView );
2386 for ( ; it.current(); ++it ) {
2387 KDGanttViewItem* currentItem = ( KDGanttViewItem* )it.current();
2388 currentItem->setDisplaySubitemsAsGroup( show );
2389 }
2390 _displaySubitemsAsGroup = show;
2391}
2392
2393
2403{
2404 return _displaySubitemsAsGroup;
2405}
2406
2407
2416{
2417 _displayEmptyTasksAsLine = show;
2418}
2419
2420
2428{
2429 return _displayEmptyTasksAsLine;
2430}
2431
2432
2447void KDGanttView::setHorBackgroundLines( int count, TQBrush brush )
2448{
2449 myTimeTable->setHorBackgroundLines( count, brush );
2450}
2451
2452
2463{
2464 return myTimeTable->horBackgroundLines( brush );
2465}
2466
2467
2473KDGanttViewItem* KDGanttView::lastItem() const
2474{
2475 return (KDGanttViewItem*)myListView->lastItem ();
2476}
2477
2478
2484TQPtrList<KDGanttViewTaskLink> KDGanttView::taskLinks() const
2485{
2486
2487 return myTimeTable->taskLinks();
2488}
2489
2490
2496TQPtrList<KDGanttViewTaskLinkGroup> KDGanttView::taskLinkGroups() const
2497{
2498 return myTaskLinkGroupList;
2499}
2500
2501
2509bool KDGanttView::loadXML( const TQDomDocument& doc )
2510{
2511 TQDomElement docRoot = doc.documentElement(); // ChartParams element
2512 TQDomNode node = docRoot.firstChild();
2513 while( !node.isNull() ) {
2514 TQDomElement element = node.toElement();
2515 if( !element.isNull() ) { // was really an element
2516 TQString tagName = element.tagName();
2517 if( tagName == "ShowLegend" ) {
2518 bool value;
2519 if( KDGanttXML::readBoolNode( element, value ) )
2520 setShowLegend( value );
2521 } else if( tagName == "ShowLegendButton" ) {
2522 bool value;
2523 if( KDGanttXML::readBoolNode( element, value ) )
2524 setShowLegendButton( value );
2525 } else if( tagName == "LegendIsDockWindow" ) {
2526 bool value;
2527 if( KDGanttXML::readBoolNode( element, value ) )
2528 setLegendIsDoctwindow( value );
2529 } else if( tagName == "ShowListView" ) {
2530 bool value;
2531 if( KDGanttXML::readBoolNode( element, value ) )
2532 setShowListView( value );
2533 } else if( tagName == "ShowHeader" ) {
2534 bool value;
2535 if( KDGanttXML::readBoolNode( element, value ) )
2536 setHeaderVisible( value );
2537 } else if( tagName == "ShowTaskLinks" ) {
2538 bool value;
2539 if( KDGanttXML::readBoolNode( element, value ) )
2540 setShowTaskLinks( value );
2541 } else if( tagName == "EditorEnabled" ) {
2542 bool value;
2543 if( KDGanttXML::readBoolNode( element, value ) )
2544 setEditorEnabled( value );
2545 } else if( tagName == "DisplayEmptyTasksAsLine" ) {
2546 bool value;
2547 if( KDGanttXML::readBoolNode( element, value ) )
2549 } else if( tagName == "GlobalFont" ) {
2550 TQFont font;
2551 if( KDGanttXML::readFontNode( element, font ) )
2552 setFont( font );
2553 } else if( tagName == "HorizonStart" ) {
2554 TQDateTime value;
2555 if( KDGanttXML::readDateTimeNode( element, value ) )
2556 setHorizonStart( value );
2557 } else if( tagName == "HorizonEnd" ) {
2558 TQDateTime value;
2559 if( KDGanttXML::readDateTimeNode( element, value ) )
2560 setHorizonEnd( value );
2561 } else if( tagName == "Scale" ) {
2562 TQString value;
2563 if( KDGanttXML::readStringNode( element, value ) )
2564 setScale( stringToScale( value ) );
2565 } else if( tagName == "MinimumScale" ) {
2566 TQString value;
2567 if( KDGanttXML::readStringNode( element, value ) )
2568 setMinimumScale( stringToScale( value ) );
2569 } else if( tagName == "MaximumScale" ) {
2570 TQString value;
2571 if( KDGanttXML::readStringNode( element, value ) )
2572 setMaximumScale( stringToScale( value ) );
2573 } else if( tagName == "YearFormat" ) {
2574 TQString value;
2575 if( KDGanttXML::readStringNode( element, value ) )
2576 setYearFormat( stringToYearFormat( value ) );
2577 } else if( tagName == "HourFormat" ) {
2578 TQString value;
2579 if( KDGanttXML::readStringNode( element, value ) )
2580 setHourFormat( stringToHourFormat( value ) );
2581 } else if( tagName == "ShowMinorTicks" ) {
2582 bool value;
2583 if( KDGanttXML::readBoolNode( element, value ) )
2584 setShowMinorTicks( value );
2585 } else if( tagName == "ShowMajorTicks" ) {
2586 bool value;
2587 if( KDGanttXML::readBoolNode( element, value ) )
2588 setShowMajorTicks( value );
2589 } else if( tagName == "DragEnabled" ) {
2590 bool value;
2591 if( KDGanttXML::readBoolNode( element, value ) )
2592 setDragEnabled( value );
2593 } else if( tagName == "DropEnabled" ) {
2594 bool value;
2595 if( KDGanttXML::readBoolNode( element, value ) )
2596 setDropEnabled( value );
2597 } else if( tagName == "CalendarMode" ) {
2598 bool value;
2599 if( KDGanttXML::readBoolNode( element, value ) )
2600 setCalendarMode( value );
2601 } else if( tagName == "Editable" ) {
2602 bool value;
2603 if( KDGanttXML::readBoolNode( element, value ) )
2604 setEditable( value );
2605 } else if( tagName == "TextColor" ) {
2606 TQColor value;
2607 if( KDGanttXML::readColorNode( element, value ) )
2608 setTextColor( value );
2609 } else if( tagName == "MajorScaleCount" ) {
2610 int value;
2611 if( KDGanttXML::readIntNode( element, value ) )
2612 setMajorScaleCount( value );
2613 } else if( tagName == "MinorScaleCount" ) {
2614 int value;
2615 if( KDGanttXML::readIntNode( element, value ) )
2616 setMinorScaleCount( value );
2617 } else if( tagName == "AutoScaleMinorTickCount" ) {
2618 int value;
2619 if( KDGanttXML::readIntNode( element, value ) )
2621 } else if( tagName == "MinimumColumnWidth" ) {
2622 int value;
2623 if( KDGanttXML::readIntNode( element, value ) )
2624 setMinimumColumnWidth( value );
2625 } else if( tagName == "GanttMaximumWidth" ) {
2626 int value;
2627 if( KDGanttXML::readIntNode( element, value ) )
2628 setGanttMaximumWidth( value );
2629 } else if( tagName == "NoInformationBrush" ) {
2630 TQBrush value;
2631 if( KDGanttXML::readBrushNode( element, value ) )
2632 setNoInformationBrush( value );
2633 } else if( tagName == "GanttViewBackgroundColor" ) {
2634 TQColor value;
2635 if( KDGanttXML::readColorNode( element, value ) )
2636 setGvBackgroundColor( value );
2637 } else if( tagName == "ListViewBackgroundColor" ) {
2638 TQColor value;
2639 if( KDGanttXML::readColorNode( element, value ) )
2640 setLvBackgroundColor( value );
2641 } else if( tagName == "TimeHeaderBackgroundColor" ) {
2642 TQColor value;
2643 if( KDGanttXML::readColorNode( element, value ) )
2645 } else if( tagName == "LegendHeaderBackgroundColor" ) {
2646 TQColor value;
2647 if( KDGanttXML::readColorNode( element, value ) )
2649 } else if( tagName == "WeekendBackgroundColor" ) {
2650 TQColor value;
2651 if( KDGanttXML::readColorNode( element, value ) )
2653 } else if( tagName == "WeekdayBackgroundColor" ) {
2654 TQDomNode node = element.firstChild();
2655 int day = 0;
2656 TQColor color;
2657 while( !node.isNull() ) {
2658 TQDomElement element = node.toElement();
2659 if( !element.isNull() ) { // was really an elemente
2660 TQString tagName = element.tagName();
2661 if( tagName == "Day" ) {
2662 int value;
2663 if( KDGanttXML::readIntNode( element, value ) )
2664 day = value;
2665 } else if( tagName == "Color" ) {
2666 TQColor value;
2667 if( KDGanttXML::readColorNode( element, value ) )
2668 color = value;
2669 } else {
2670 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2671 Q_ASSERT( false );
2672 }
2673 }
2674 node = node.nextSibling();
2675 }
2676
2677 if( day && color.isValid() )
2678 setWeekdayBackgroundColor( color, day );
2679 } else if( tagName == "WeekendDays" ) {
2680 TQString startString = element.attribute( "Start" );
2681 TQString endString = element.attribute( "End" );
2682 bool startOk = false, endOk = false;
2683 int start = startString.toInt( &startOk );
2684 int end = startString.toInt( &endOk );
2685 if( startOk && endOk )
2686 setWeekendDays( start, end );
2687 } else if( tagName == "ZoomFactor" ) {
2688 double value;
2689 if( KDGanttXML::readDoubleNode( element, value ) )
2690 setZoomFactor( value, true );
2691 } else if( tagName == "ShowHeaderPopupMenu" ) {
2692 bool value;
2693 if( KDGanttXML::readBoolNode( element, value ) )
2694 setShowHeaderPopupMenu( value );
2695 } else if( tagName == "ShowTimeTablePopupMenu" ) {
2696 bool value;
2697 if( KDGanttXML::readBoolNode( element, value ) )
2699 } else if( tagName == "Shapes" ) {
2700 TQDomNode node = element.firstChild();
2701 bool undefinedShape = false;
2702 while( !node.isNull() ) {
2703 TQDomElement element = node.toElement();
2704 if( !element.isNull() ) { // was really an elemente
2705 TQString tagName = element.tagName();
2706 if( tagName == "Event" ) {
2707 KDGanttViewItem::Shape startShape, middleShape, endShape;
2708 startShape = KDGanttViewItem::TriangleDown;
2709 middleShape = KDGanttViewItem::TriangleDown;
2710 endShape = KDGanttViewItem::TriangleDown;
2711 TQDomNode node = element.firstChild();
2712 while( !node.isNull() ) {
2713 TQDomElement element = node.toElement();
2714 if( !element.isNull() ) { // was really an elemente
2715 TQString tagName = element.tagName();
2716 if( tagName == "Start" ) {
2717 TQString value;
2718 if( KDGanttXML::readStringNode( element, value ) )
2719 startShape = KDGanttViewItem::stringToShape( value );
2720 if ( value == "Undefined" )
2721 undefinedShape = true;
2722 } else if( tagName == "Middle" ) {
2723 TQString value;
2724 if( KDGanttXML::readStringNode( element, value ) )
2725 middleShape = KDGanttViewItem::stringToShape( value );
2726 if ( value == "Undefined" )
2727 undefinedShape = true;
2728 } else if( tagName == "End" ) {
2729 TQString value;
2730 if( KDGanttXML::readStringNode( element, value ) )
2731 endShape = KDGanttViewItem::stringToShape( value );
2732 if ( value == "Undefined" )
2733 undefinedShape = true;
2734 } else {
2735 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2736 Q_ASSERT( false );
2737 }
2738 }
2739 node = node.nextSibling();
2740 }
2741 if ( ! undefinedShape )
2742 setShapes( KDGanttViewItem::Event, startShape,
2743 middleShape, endShape, false );
2744 undefinedShape = false;
2745 } else if( tagName == "Task" ) {
2746 KDGanttViewItem::Shape startShape, middleShape, endShape;
2747 startShape = KDGanttViewItem::TriangleDown;
2748 middleShape = KDGanttViewItem::TriangleDown;
2749 endShape = KDGanttViewItem::TriangleDown;
2750 TQDomNode node = element.firstChild();
2751 while( !node.isNull()) {
2752 TQDomElement element = node.toElement();
2753 if( !element.isNull() ) { // was really an elemente
2754 TQString tagName = element.tagName();
2755 if( tagName == "Start" ) {
2756 TQString value;
2757 if( KDGanttXML::readStringNode( element, value ) )
2758 startShape = KDGanttViewItem::stringToShape( value );
2759 if ( value == "Undefined" )
2760 undefinedShape = true;
2761 } else if( tagName == "Middle" ) {
2762 TQString value;
2763 if( KDGanttXML::readStringNode( element, value ) )
2764 middleShape = KDGanttViewItem::stringToShape( value );
2765 if ( value == "Undefined" )
2766 undefinedShape = true;
2767 } else if( tagName == "End" ) {
2768 TQString value;
2769 if( KDGanttXML::readStringNode( element, value ) )
2770 endShape = KDGanttViewItem::stringToShape( value );
2771 if ( value == "Undefined" )
2772 undefinedShape = true;
2773 } else {
2774 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2775 Q_ASSERT( false );
2776 }
2777 }
2778 node = node.nextSibling();
2779 }
2780 if ( ! undefinedShape )
2781 setShapes( KDGanttViewItem::Task, startShape, middleShape, endShape, false );
2782 undefinedShape = false;
2783 } else if( tagName == "Summary" ) {
2784 KDGanttViewItem::Shape startShape, middleShape, endShape;
2785 startShape = KDGanttViewItem::TriangleDown;
2786 middleShape = KDGanttViewItem::TriangleDown;
2787 endShape = KDGanttViewItem::TriangleDown;
2788 TQDomNode node = element.firstChild();
2789 while( !node.isNull() ) {
2790 TQDomElement element = node.toElement();
2791 if( !element.isNull() ) { // was really an elemente
2792 TQString tagName = element.tagName();
2793 if( tagName == "Start" ) {
2794 TQString value;
2795 if( KDGanttXML::readStringNode( element, value ) )
2796 startShape = KDGanttViewItem::stringToShape( value );
2797 if ( value == "Undefined" )
2798 undefinedShape = true;
2799 } else if( tagName == "Middle" ) {
2800 TQString value;
2801 if( KDGanttXML::readStringNode( element, value ) )
2802 middleShape = KDGanttViewItem::stringToShape( value );
2803 if ( value == "Undefined" )
2804 undefinedShape = true;
2805 } else if( tagName == "End" ) {
2806 TQString value;
2807 if( KDGanttXML::readStringNode( element, value ) )
2808 endShape = KDGanttViewItem::stringToShape( value );
2809 if ( value == "Undefined" )
2810 undefinedShape = true;
2811 } else {
2812 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2813 Q_ASSERT( false );
2814 }
2815 }
2816 node = node.nextSibling();
2817 }
2818 if ( ! undefinedShape )
2819 setShapes( KDGanttViewItem::Summary, startShape,
2820 middleShape, endShape, false );
2821 undefinedShape = false;
2822 } else {
2823 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2824 Q_ASSERT( false );
2825 }
2826 }
2827 node = node.nextSibling();
2828 }
2829 } else if( tagName == "Colors" ) {
2830 TQDomNode node = element.firstChild();
2831 while( !node.isNull()) {
2832 TQDomElement element = node.toElement();
2833 if( !element.isNull() ) { // was really an elemente
2834 TQString tagName = element.tagName();
2835 if( tagName == "Event" ) {
2836 TQColor startColor, middleColor, endColor;
2837 TQDomNode node = element.firstChild();
2838 while( !node.isNull() ) {
2839 TQDomElement element = node.toElement();
2840 if( !element.isNull() ) { // was really an elemente
2841 TQString tagName = element.tagName();
2842 if( tagName == "Start" ) {
2843 TQColor value;
2844 if( KDGanttXML::readColorNode( element, value ) )
2845 startColor = value;
2846 } else if( tagName == "Middle" ) {
2847 TQColor value;
2848 if( KDGanttXML::readColorNode( element, value ) )
2849 middleColor = value;
2850 } else if( tagName == "End" ) {
2851 TQColor value;
2852 if( KDGanttXML::readColorNode( element, value ) )
2853 endColor = value;
2854 } else {
2855 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2856 Q_ASSERT( false );
2857 }
2858 }
2859 node = node.nextSibling();
2860 }
2861 setColors( KDGanttViewItem::Event, startColor,
2862 middleColor, endColor, false );
2863 } else if( tagName == "Task" ) {
2864 TQColor startColor, middleColor, endColor;
2865 TQDomNode node = element.firstChild();
2866 while( !node.isNull() ) {
2867 TQDomElement element = node.toElement();
2868 if( !element.isNull() ) { // was really an elemente
2869 TQString tagName = element.tagName();
2870 if( tagName == "Start" ) {
2871 TQColor value;
2872 if( KDGanttXML::readColorNode( element, value ) )
2873 startColor = value;
2874 } else if( tagName == "Middle" ) {
2875 TQColor value;
2876 if( KDGanttXML::readColorNode( element, value ) )
2877 middleColor = value;
2878 } else if( tagName == "End" ) {
2879 TQColor value;
2880 if( KDGanttXML::readColorNode( element, value ) )
2881 endColor = value;
2882 } else {
2883 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2884 Q_ASSERT( false );
2885 }
2886 }
2887 node = node.nextSibling();
2888 }
2889 setColors( KDGanttViewItem::Task, startColor,
2890 middleColor, endColor, false );
2891 } else if( tagName == "Summary" ) {
2892 TQColor startColor, middleColor, endColor;
2893 TQDomNode node = element.firstChild();
2894 while( !node.isNull() ) {
2895 TQDomElement element = node.toElement();
2896 if( !element.isNull() ) { // was really an elemente
2897 TQString tagName = element.tagName();
2898 if( tagName == "Start" ) {
2899 TQColor value;
2900 if( KDGanttXML::readColorNode( element, value ) )
2901 startColor = value;
2902 } else if( tagName == "Middle" ) {
2903 TQColor value;
2904 if( KDGanttXML::readColorNode( element, value ) )
2905 middleColor = value;
2906 } else if( tagName == "End" ) {
2907 TQColor value;
2908 if( KDGanttXML::readColorNode( element, value ) )
2909 endColor = value;
2910 } else {
2911 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2912 Q_ASSERT( false );
2913 }
2914 }
2915 node = node.nextSibling();
2916 }
2917 setColors( KDGanttViewItem::Summary, startColor,
2918 middleColor, endColor , false);
2919 } else {
2920 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2921 Q_ASSERT( false );
2922 }
2923 }
2924 node = node.nextSibling();
2925 }
2926 } else if( tagName == "DefaultColors" ) {
2927 TQDomNode node = element.firstChild();
2928 while( !node.isNull() ) {
2929 TQDomElement element = node.toElement();
2930 if( !element.isNull() ) { // was really an element
2931 TQString tagName = element.tagName();
2932 if( tagName == "Event" ) {
2933 TQColor value;
2934 if( KDGanttXML::readColorNode( element, value ) )
2935 setDefaultColor( KDGanttViewItem::Event,
2936 value, false );
2937 } else if( tagName == "Task" ) {
2938 TQColor value;
2939 if( KDGanttXML::readColorNode( element, value ) )
2940 setDefaultColor( KDGanttViewItem::Task,
2941 value, false );
2942 } else if( tagName == "Summary" ) {
2943 TQColor value;
2944 if( KDGanttXML::readColorNode( element, value ) )
2945 setDefaultColor( KDGanttViewItem::Summary,
2946 value , false);
2947 } else {
2948 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2949 Q_ASSERT( false );
2950 }
2951 }
2952
2953 node = node.nextSibling();
2954 }
2955 } else if( tagName == "HighlightColors" ) {
2956 TQDomNode node = element.firstChild();
2957 while( !node.isNull() ) {
2958 TQDomElement element = node.toElement();
2959 if( !element.isNull() ) { // was really an elemente
2960 TQString tagName = element.tagName();
2961 if( tagName == "Event" ) {
2962 TQColor startColor, middleColor, endColor;
2963 TQDomNode node = element.firstChild();
2964 while( !node.isNull() ) {
2965 TQDomElement element = node.toElement();
2966 if( !element.isNull() ) { // was really an elemente
2967 TQString tagName = element.tagName();
2968 if( tagName == "Start" ) {
2969 TQColor value;
2970 if( KDGanttXML::readColorNode( element, value ) )
2971 startColor = value;
2972 } else if( tagName == "Middle" ) {
2973 TQColor value;
2974 if( KDGanttXML::readColorNode( element, value ) )
2975 middleColor = value;
2976 } else if( tagName == "End" ) {
2977 TQColor value;
2978 if( KDGanttXML::readColorNode( element, value ) )
2979 endColor = value;
2980 } else {
2981 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2982 Q_ASSERT( false );
2983 }
2984 }
2985 node = node.nextSibling();
2986 }
2987 setHighlightColors( KDGanttViewItem::Event,
2988 startColor,
2989 middleColor, endColor, false );
2990 } else if( tagName == "Task" ) {
2991 TQColor startColor, middleColor, endColor;
2992 TQDomNode node = element.firstChild();
2993 while( !node.isNull() ) {
2994 TQDomElement element = node.toElement();
2995 if( !element.isNull() ) { // was really an elemente
2996 TQString tagName = element.tagName();
2997 if( tagName == "Start" ) {
2998 TQColor value;
2999 if( KDGanttXML::readColorNode( element, value ) )
3000 startColor = value;
3001 } else if( tagName == "Middle" ) {
3002 TQColor value;
3003 if( KDGanttXML::readColorNode( element, value ) )
3004 middleColor = value;
3005 } else if( tagName == "End" ) {
3006 TQColor value;
3007 if( KDGanttXML::readColorNode( element, value ) )
3008 endColor = value;
3009 } else {
3010 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3011 Q_ASSERT( false );
3012 }
3013 }
3014 node = node.nextSibling();
3015 }
3016 setHighlightColors( KDGanttViewItem::Task,
3017 startColor,
3018 middleColor, endColor , false);
3019 } else if( tagName == "Summary" ) {
3020 TQColor startColor, middleColor, endColor;
3021 TQDomNode node = element.firstChild();
3022 while( !node.isNull() ) {
3023 TQDomElement element = node.toElement();
3024 if( !element.isNull() ) { // was really an elemente
3025 TQString tagName = element.tagName();
3026 if( tagName == "Start" ) {
3027 TQColor value;
3028 if( KDGanttXML::readColorNode( element, value ) )
3029 startColor = value;
3030 } else if( tagName == "Middle" ) {
3031 TQColor value;
3032 if( KDGanttXML::readColorNode( element, value ) )
3033 middleColor = value;
3034 } else if( tagName == "End" ) {
3035 TQColor value;
3036 if( KDGanttXML::readColorNode( element, value ) )
3037 endColor = value;
3038 } else {
3039 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3040 Q_ASSERT( false );
3041 }
3042 }
3043 node = node.nextSibling();
3044 }
3045 setHighlightColors( KDGanttViewItem::Summary,
3046 startColor,
3047 middleColor, endColor, false );
3048 } else {
3049 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3050 Q_ASSERT( false );
3051 }
3052 }
3053 node = node.nextSibling();
3054 }
3055 } else if( tagName == "DefaultHighlightColors" ) {
3056 TQDomNode node = element.firstChild();
3057 while( !node.isNull() ) {
3058 TQDomElement element = node.toElement();
3059 if( !element.isNull() ) { // was really an element
3060 TQString tagName = element.tagName();
3061 if( tagName == "Event" ) {
3062 TQColor value;
3063 if( KDGanttXML::readColorNode( element, value ) )
3064 setDefaultHighlightColor( KDGanttViewItem::Event,
3065 value , false);
3066 } else if( tagName == "Task" ) {
3067 TQColor value;
3068 if( KDGanttXML::readColorNode( element, value ) )
3069 setDefaultHighlightColor( KDGanttViewItem::Task,
3070 value, false );
3071 } else if( tagName == "Summary" ) {
3072 TQColor value;
3073 if( KDGanttXML::readColorNode( element, value ) )
3074 setDefaultHighlightColor( KDGanttViewItem::Summary,
3075 value, false );
3076 } else {
3077 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3078 Q_ASSERT( false );
3079 }
3080 }
3081
3082 node = node.nextSibling();
3083 }
3084 } else if( tagName == "Items" ) {
3085 TQDomNode node = element.firstChild();
3086 KDGanttViewItem* previous = 0;
3087 while( !node.isNull() ) {
3088 TQDomElement element = node.toElement();
3089 if( !element.isNull() ) { // was really an element
3090 TQString tagName = element.tagName();
3091 if( tagName == "Item" ) {
3092 KDGanttViewItem* newItem;
3093 if( previous )
3094 newItem =
3096 previous,
3097 element );
3098 else
3099 newItem =
3101 element );
3102 previous = newItem;
3103 } else {
3104 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3105 Q_ASSERT( false );
3106 }
3107 }
3108
3109 node = node.nextSibling();
3110 }
3111 } else if( tagName == "TaskLinks" ) {
3112 TQDomNode node = element.firstChild();
3113 while( !node.isNull() ) {
3114 TQDomElement element = node.toElement();
3115 if( !element.isNull() ) { // was really an element
3116 TQString tagName = element.tagName();
3117 if( tagName == "TaskLink" )
3119 else {
3120 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3121 Q_ASSERT( false );
3122 }
3123 }
3124
3125 node = node.nextSibling();
3126 }
3127 } else if( tagName == "TaskLinkGroups" ) {
3128 TQDomNode node = element.firstChild();
3129 while( !node.isNull() ) {
3130 TQDomElement element = node.toElement();
3131 if( !element.isNull() ) { // was really an element
3132 TQString tagName = element.tagName();
3133 if( tagName == "TaskLink" )
3135 } else {
3136 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3137 Q_ASSERT( false );
3138 }
3139
3140 node = node.nextSibling();
3141 }
3142 } else if( tagName == "ColumnBackgroundColors" ) {
3143 TQDomNode node = element.firstChild();
3144 while( !node.isNull() ) {
3145 TQDomElement element = node.toElement();
3146 if( !element.isNull() ) { // was really an element
3147 TQString tagName = element.tagName();
3148 if( tagName == "ColumnBackgroundColor" ) {
3149 TQDomNode node = element.firstChild();
3150 TQDateTime dateTime;
3151 TQColor color;
3152 while( !node.isNull() ) {
3153 TQDomElement element = node.toElement();
3154 if( !element.isNull() ) { // was
3155 // really an
3156 // element
3157 TQString tagName = element.tagName();
3158 if( tagName == "DateTime" ) {
3159 TQDateTime value;
3160 if( KDGanttXML::readDateTimeNode( element, value ) )
3161 dateTime = value;
3162 } else if( tagName == "Color" ) {
3163 TQColor value;
3164 if( KDGanttXML::readColorNode( element, value ) )
3165 color = value;
3166 } else {
3167 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3168 Q_ASSERT( false );
3169 }
3170 }
3171
3172 node = node.nextSibling();
3173 }
3174 setColumnBackgroundColor( dateTime, color );
3175 } else {
3176 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3177 Q_ASSERT( false );
3178 }
3179 }
3180 node = node.nextSibling();
3181 }
3182 } else if( tagName == "LegendItems" ) {
3183 clearLegend();
3184 TQDomNode node = element.firstChild();
3185 while( !node.isNull() ) {
3186 TQDomElement element = node.toElement();
3187 if( !element.isNull() ) { // was really an element
3188 TQString tagName = element.tagName();
3189 if( tagName == "LegendItem" ) {
3190 KDGanttViewItem::Shape tempLegendShape;
3191 tempLegendShape = KDGanttViewItem::TriangleDown;
3192 TQColor tempLegendColor;
3193 TQString tempLegendString;
3194 bool ok = true;
3195 TQDomNode node = element.firstChild();
3196 while( !node.isNull() ) {
3197 TQDomElement element = node.toElement();
3198 if( !element.isNull() ) { // was really an element
3199 TQString tagName = element.tagName();
3200 if( tagName == "Shape" ) {
3201 TQString value;
3202 if( KDGanttXML::readStringNode( element, value ) )
3203 tempLegendShape = KDGanttViewItem::stringToShape( value );
3204 else
3205 ok = false;
3206 } else if( tagName == "Color" ) {
3207 TQColor value;
3208 if( KDGanttXML::readColorNode( element, value ) )
3209 tempLegendColor = value;
3210 else
3211 ok = false;
3212 } else if( tagName == "Text" ) {
3213 TQString value;
3214 if( KDGanttXML::readStringNode( element, value ) )
3215 tempLegendString = value;
3216 else
3217 ok = false;
3218 } else {
3219 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3220 Q_ASSERT( false );
3221 }
3222 }
3223 node = node.nextSibling();
3224 }
3225 if( ok ) {
3226 addLegendItem( tempLegendShape,
3227 tempLegendColor,
3228 tempLegendString );
3229 tqDebug( "Adding legend item %s", tempLegendString.latin1() );
3230 }
3231 } else {
3232 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3233 Q_ASSERT( false );
3234 }
3235 }
3236 node = node.nextSibling();
3237 }
3238 } else {
3239 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3240 Q_ASSERT( false );
3241 }
3242 }
3243
3244 node = node.nextSibling();
3245 } // while
3246 return true; /* FIXME: Do real error-reporting. The ASSERT's should be "return false" stmnts */
3247} // method
3248
3249
3258TQDomDocument KDGanttView::saveXML( bool withPI ) const
3259{
3260 // Create an inital DOM document
3261 TQString docstart = "<GanttView/>";
3262
3263 TQDomDocument doc( "GanttView" );
3264 doc.setContent( docstart );
3265 if( withPI ) {
3266 TQDomProcessingInstruction pin = doc.createProcessingInstruction( "kdgantt", "version=\"1.0\" encoding=\"UTF-8\"" ) ;
3267 doc.appendChild ( pin );
3268 }
3269
3270 TQDomElement docRoot = doc.documentElement();
3271 docRoot.setAttribute( "xmlns", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
3272 docRoot.setAttribute( "xmlns:xsi", "http://www.w3.org/2000/10/XMLSchema-instance" );
3273 docRoot.setAttribute( "xsi:schemaLocation", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
3274
3275 // the ShowLegend element
3276 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegend", showLegend() );
3277
3278 // the ShowLegendButton element
3279 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegendButton",
3280 showLegendButton() );
3281
3282 // the LegendIsDockWindow element
3283 KDGanttXML::createBoolNode( doc, docRoot, "LegendIsDockWindow",
3285
3286 // the ShowListView element
3287 KDGanttXML::createBoolNode( doc, docRoot, "ShowListView", showListView() );
3288
3289 // the ShowHeader element
3290 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeader", headerVisible() );
3291
3292 // the ShowTaskLinks element
3293 KDGanttXML::createBoolNode( doc, docRoot, "ShowTaskLinks", showTaskLinks() );
3294
3295 // the EditorEnabled element
3296 KDGanttXML::createBoolNode( doc, docRoot, "EditorEnabled", editorEnabled() );
3297
3298 // the global font element
3299 KDGanttXML::createFontNode( doc, docRoot, "GlobalFont", font() );
3300
3301 // the DisplayEmptyTasksAsLine element
3302 KDGanttXML::createBoolNode( doc, docRoot, "DisplayEmptyTasksAsLine",
3304
3305 // the HorizonStart element
3306 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonStart", horizonStart() );
3307
3308 // the HorizonEnd element
3309 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonEnd", horizonEnd() );
3310
3311 // the Scale, MinimumScale, MaximumScale elements
3312 KDGanttXML::createStringNode( doc, docRoot, "Scale", scaleToString( scale() ) );
3313 KDGanttXML::createStringNode( doc, docRoot, "MinimumScale",
3314 scaleToString( minimumScale() ) );
3315 KDGanttXML::createStringNode( doc, docRoot, "MaximumScale",
3316 scaleToString( maximumScale() ) );
3317
3318 // the YearFormat element
3319 KDGanttXML::createStringNode( doc, docRoot, "YearFormat",
3320 yearFormatToString( yearFormat() ) );
3321
3322 // the HourFormat element
3323 KDGanttXML::createStringNode( doc, docRoot, "HourFormat",
3324 hourFormatToString( hourFormat() ) );
3325
3326 // the ShowMinorTicks element
3327 KDGanttXML::createBoolNode( doc, docRoot, "ShowMinorTicks", showMinorTicks() );
3328
3329 // the ShowMajorTicks element
3330 KDGanttXML::createBoolNode( doc, docRoot, "ShowMajorTicks", showMajorTicks() );
3331
3332 // the Editable element
3333 KDGanttXML::createBoolNode( doc, docRoot, "Editable", editable() );
3334
3335 // the TextColor element
3336 KDGanttXML::createColorNode( doc, docRoot, "TextColor", textColor() );
3337
3338 // the MajorScaleCount element
3339 KDGanttXML::createIntNode( doc, docRoot, "MajorScaleCount", majorScaleCount() );
3340
3341 // the MinorScaleCount element
3342 KDGanttXML::createIntNode( doc, docRoot, "MinorScaleCount", minorScaleCount() );
3343
3344 // the AutoScaleMinorTickCount element
3345 KDGanttXML::createIntNode( doc, docRoot, "AutoScaleMinorTickCount",
3347
3348 // the MinimumColumnWidth element
3349 KDGanttXML::createIntNode( doc, docRoot, "MinimumColumnWidth",
3351
3352 // the GanttMaximumWidth element
3353 KDGanttXML::createIntNode( doc, docRoot, "GanttMaximumWidth",
3355
3356 // the NoInformationBrush element
3357 KDGanttXML::createBrushNode( doc, docRoot, "NoInformationBrush",
3359
3360 // the GanttViewBackgroundColor element
3361 KDGanttXML::createColorNode( doc, docRoot, "GanttViewBackgroundColor",
3363
3364 // the ListViewBackgroundColor element
3365 KDGanttXML::createColorNode( doc, docRoot, "ListViewBackgroundColor",
3367
3368 // the TimeHeaderBackgroundColor element
3369 KDGanttXML::createColorNode( doc, docRoot, "TimeHeaderBackgroundColor",
3371
3372 // the LegendHeaderBackgroundColor element
3373 KDGanttXML::createColorNode( doc, docRoot, "LegendHeaderBackgroundColor",
3375
3376 // the WeekendBackgroundColor element
3377 KDGanttXML::createColorNode( doc, docRoot, "WeekendBackgroundColor",
3379
3380 // the WeekdayBackgroundColor elements
3381 for( int weekday = 1; weekday <= 7; weekday++ ) {
3382 TQColor color = weekdayBackgroundColor( weekday );
3383 if( color.isValid() ) {
3384 TQDomElement weekendBackgroundColorElement = doc.createElement( "WeekdayBackgroundColor" );
3385 docRoot.appendChild( weekendBackgroundColorElement );
3386 KDGanttXML::createIntNode( doc, weekendBackgroundColorElement,
3387 "Day", weekday );
3388 KDGanttXML::createColorNode( doc, weekendBackgroundColorElement,
3389 "Color", color );
3390 }
3391 }
3392
3393 // the WeekendDays element
3394 TQDomElement weekendDaysElement = doc.createElement( "WeekendDays" );
3395 docRoot.appendChild( weekendDaysElement );
3396 int weekendStart, weekendEnd;
3397 weekendDays( weekendStart, weekendEnd );
3398 weekendDaysElement.setAttribute( "Start", weekendStart );
3399 weekendDaysElement.setAttribute( "End", weekendStart );
3400
3401 // the ZoomFactor element
3402 KDGanttXML::createDoubleNode( doc, docRoot, "ZoomFactor",
3403 zoomFactor() );
3404
3405 // the ShowHeaderPopupMenu element
3406 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeaderPopupMenu",
3408
3409 // the ShowTimeTablePopupMenu element
3410 KDGanttXML::createBoolNode( doc, docRoot, "ShowTimeTablePopupMenu",
3412
3413 // the Shapes element
3414 TQDomElement shapesElement = doc.createElement( "Shapes" );
3415 docRoot.appendChild( shapesElement );
3416 TQDomElement shapesEventElement = doc.createElement( "Event" );
3417 shapesElement.appendChild( shapesEventElement );
3418 KDGanttViewItem::Shape start, middle, end;
3419 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
3420 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
3421 KDGanttViewItem::shapeToString( start ) );
3422 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
3423 KDGanttViewItem::shapeToString( middle ) );
3424 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
3425 KDGanttViewItem::shapeToString( end ) );
3426 } else {
3427 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
3428 "Undefined" );
3429 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
3430 "Undefined" );
3431 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
3432 "Undefined" );
3433 }
3434 TQDomElement shapesTaskElement = doc.createElement( "Task" );
3435 shapesElement.appendChild( shapesTaskElement );
3436 if( shapes( KDGanttViewItem::Task, start, middle, end ) ) {
3437 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
3438 KDGanttViewItem::shapeToString( start ) );
3439 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
3440 KDGanttViewItem::shapeToString( middle ) );
3441 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
3442 KDGanttViewItem::shapeToString( end ) );
3443 } else {
3444 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
3445 "Undefined" );
3446 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
3447 "Undefined" );
3448 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
3449 "Undefined" );
3450 }
3451 TQDomElement shapesSummaryElement = doc.createElement( "Summary" );
3452 shapesElement.appendChild( shapesSummaryElement );
3453 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
3454 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
3455 KDGanttViewItem::shapeToString( start ) );
3456 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
3457 KDGanttViewItem::shapeToString( middle ) );
3458 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
3459 KDGanttViewItem::shapeToString( end ) );
3460 } else {
3461 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
3462 "Undefined" );
3463 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
3464 "Undefined" );
3465 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
3466 "Undefined" );
3467 }
3468
3469 // the Colors element
3470 TQDomElement colorsElement = doc.createElement( "Colors" );
3471 docRoot.appendChild( colorsElement );
3472 TQDomElement colorsEventElement = doc.createElement( "Event" );
3473 colorsElement.appendChild( colorsEventElement );
3474 TQColor startColor, middleColor, endColor;
3475 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3476 KDGanttXML::createColorNode( doc, colorsEventElement, "Start", startColor );
3477 KDGanttXML::createColorNode( doc, colorsEventElement, "Middle", middleColor );
3478 KDGanttXML::createColorNode( doc, colorsEventElement, "End", endColor );
3479 TQDomElement colorsTaskElement = doc.createElement( "Task" );
3480 colorsElement.appendChild( colorsTaskElement );
3481 colors( KDGanttViewItem::Task, startColor, middleColor, endColor );
3482 KDGanttXML::createColorNode( doc, colorsTaskElement, "Start", startColor );
3483 KDGanttXML::createColorNode( doc, colorsTaskElement, "Middle", middleColor );
3484 KDGanttXML::createColorNode( doc, colorsTaskElement, "End", endColor );
3485 TQDomElement colorsSummaryElement = doc.createElement( "Summary" );
3486 colorsElement.appendChild( colorsSummaryElement );
3487 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3488 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Start", startColor );
3489 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Middle", middleColor );
3490 KDGanttXML::createColorNode( doc, colorsSummaryElement, "End", endColor );
3491
3492 // the DefaultColor element
3493 TQDomElement defaultColorsElement = doc.createElement( "DefaultColors" );
3494 docRoot.appendChild( defaultColorsElement );
3495 KDGanttXML::createColorNode( doc, defaultColorsElement, "Event",
3496 defaultColor( KDGanttViewItem::Event ) );
3497 KDGanttXML::createColorNode( doc, defaultColorsElement, "Task",
3498 defaultColor( KDGanttViewItem::Task ) );
3499 KDGanttXML::createColorNode( doc, defaultColorsElement, "Summary",
3500 defaultColor( KDGanttViewItem::Summary ) );
3501
3502
3503 // the HighlightColors element
3504 TQDomElement highlightColorsElement = doc.createElement( "HighlightColors" );
3505 docRoot.appendChild( highlightColorsElement );
3506 TQDomElement highlightColorsEventElement = doc.createElement( "Event" );
3507 highlightColorsElement.appendChild( highlightColorsEventElement );
3508 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3509 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Start", startColor );
3510 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Middle", middleColor );
3511 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "End", endColor );
3512 TQDomElement highlightColorsTaskElement = doc.createElement( "Task" );
3513 highlightColorsElement.appendChild( highlightColorsTaskElement );
3514 highlightColors( KDGanttViewItem::Task, startColor, middleColor, endColor );
3515 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Start", startColor );
3516 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Middle", middleColor );
3517 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "End", endColor );
3518 TQDomElement highlightColorsSummaryElement = doc.createElement( "Summary" );
3519 highlightColorsElement.appendChild( highlightColorsSummaryElement );
3520 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3521 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
3522 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
3523 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
3524
3525
3526 /*
3527 if( highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor ) ) {
3528 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
3529 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
3530 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
3531 } else {
3532 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", TQColor() );
3533 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", TQColor() );
3534 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", TQColor() );
3535 }
3536 */
3537 // the DefaultHighlightColor element
3538 TQDomElement defaultHighlightColorsElement = doc.createElement( "DefaultHighlightColors" );
3539 docRoot.appendChild( defaultHighlightColorsElement );
3540 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Event",
3541 defaultHighlightColor( KDGanttViewItem::Event ) );
3542 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Task",
3543 defaultHighlightColor( KDGanttViewItem::Task ) );
3544 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Summary",
3545 defaultHighlightColor( KDGanttViewItem::Summary ) );
3546
3547
3548 // the Items element
3549 TQDomElement itemsElement = doc.createElement( "Items" );
3550 docRoot.appendChild( itemsElement );
3551 KDGanttViewItem* currentItem = firstChild();
3552 while( currentItem ) {
3553 currentItem->createNode( doc, itemsElement );
3554 currentItem = currentItem->nextSibling();
3555 }
3556
3557 // the TaskLinks element
3558 TQDomElement taskLinksElement = doc.createElement( "TaskLinks" );
3559 docRoot.appendChild( taskLinksElement );
3560 TQPtrList<KDGanttViewTaskLink> taskLinkList = taskLinks();
3561 KDGanttViewTaskLink* currentTL = 0;
3562 for( currentTL = taskLinkList.first(); currentTL;
3563 currentTL = taskLinkList.next() )
3564 currentTL->createNode( doc, taskLinksElement );
3565
3566 // the TaskLinkGroups element
3567 TQDomElement taskLinkGroupsElement = doc.createElement( "TaskLinkGroups" );
3568 docRoot.appendChild( taskLinkGroupsElement );
3569 TQPtrList<KDGanttViewTaskLinkGroup> taskLinkGroupList = taskLinkGroups();
3570 KDGanttViewTaskLinkGroup* currentTLG = 0;
3571 for( currentTLG = taskLinkGroupList.first(); currentTLG;
3572 currentTLG = taskLinkGroupList.next() )
3573 currentTLG->createNode( doc, taskLinkGroupsElement );
3574
3575 // the ColumnBackgroundColors element
3576 TQDomElement columnBackgroundColorsElement =
3577 doc.createElement( "ColumnBackgroundColors" );
3578 docRoot.appendChild( columnBackgroundColorsElement );
3579 KDTimeHeaderWidget::ColumnColorList ccList =
3580 myTimeHeader->columnBackgroundColorList();
3581 for( KDTimeHeaderWidget::ColumnColorList::iterator it = ccList.begin();
3582 it != ccList.end(); ++it ) {
3583 TQDomElement columnBackgroundColorElement =
3584 doc.createElement( "ColumnBackgroundColor" );
3585 columnBackgroundColorsElement.appendChild( columnBackgroundColorElement );
3586 KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
3587 "DateTime", (*it).datetime );
3588 KDGanttXML::createColorNode( doc, columnBackgroundColorElement,
3589 "Color", (*it).color );
3590 }
3591
3592 // the LegendItems element
3593 TQDomElement legendItemsElement =
3594 doc.createElement( "LegendItems" );
3595 docRoot.appendChild( legendItemsElement );
3596 legendItem* current;
3597 TQPtrListIterator<legendItem> lit( *myLegendItems );
3598 while( ( current = lit.current() ) ) {
3599 ++lit;
3600 TQDomElement legendItemElement = doc.createElement( "LegendItem" );
3601 legendItemsElement.appendChild( legendItemElement );
3602 KDGanttXML::createStringNode( doc, legendItemElement, "Shape",
3603 KDGanttViewItem::shapeToString( current->shape ) );
3604 KDGanttXML::createColorNode( doc, legendItemElement, "Color",
3605 current->color );
3606 KDGanttXML::createStringNode( doc, legendItemElement, "Text",
3607 current->text );
3608 }
3609
3610 // the DragEnabled element
3611 KDGanttXML::createBoolNode( doc, docRoot, "DragEnabled", isDragEnabled() );
3612
3613 // the DropEnabled element
3614 KDGanttXML::createBoolNode( doc, docRoot, "DropEnabled", isDropEnabled() );
3615
3616 // the CalendarMode element
3617 KDGanttXML::createBoolNode( doc, docRoot, "CalendarMode", calendarMode() );
3618
3619 return doc;
3620}
3621
3622
3623
3624TQString KDGanttView::scaleToString( Scale scale )
3625{
3626 switch( scale ) {
3627 case Minute:
3628 return "Minute";
3629 case Hour:
3630 return "Hour";
3631 case Day:
3632 return "Day";
3633 case Week:
3634 return "Week";
3635 case Month:
3636 return "Month";
3637 case Auto:
3638 return "Auto";
3639 }
3640 return "";
3641}
3642
3643
3644KDGanttView::Scale KDGanttView::stringToScale( const TQString& string )
3645{
3646 if( string == "Minute" )
3647 return Minute;
3648 else if( string == "Hour" )
3649 return Hour;
3650 else if( string == "Day" )
3651 return Day;
3652 else if( string == "Week" )
3653 return Week;
3654 else if( string == "Month" )
3655 return Month;
3656 else if( string == "Auto" )
3657 return Auto;
3658
3659 return Auto;
3660}
3661
3662
3663TQString KDGanttView::yearFormatToString( YearFormat format )
3664{
3665 switch( format ) {
3666 case FourDigit:
3667 return "FourDigit";
3668 case TwoDigit:
3669 return "TwoDigit";
3670 case TwoDigitApostrophe:
3671 return "TwoDigitApostrophe";
3672 case NoDate:
3673 return "NoDate";
3674 }
3675 return "";
3676}
3677
3678
3679KDGanttView::YearFormat KDGanttView::stringToYearFormat( const TQString& string )
3680{
3681 if( string == "FourDigit" )
3682 return FourDigit;
3683 else if( string == "TwoDigit" )
3684 return TwoDigit;
3685 else if( string == "TwoDigitApostrophe" )
3686 return TwoDigitApostrophe;
3687 else if( string == "NoDate" )
3688 return NoDate;
3689 else
3690 return FourDigit;
3691}
3692
3693
3694TQString KDGanttView::hourFormatToString( HourFormat format )
3695{
3696 switch( format ) {
3697 case Hour_12:
3698 return "Hour_12";
3699 case Hour_24:
3700 return "Hour_24";
3701 case Hour_24_FourDigit:
3702 return "Hour_24_FourDigit";
3703 }
3704 return "";
3705}
3706
3707
3708KDGanttView::HourFormat KDGanttView::stringToHourFormat( const TQString& string )
3709{
3710 if( string == "Hour_12" )
3711 return Hour_12;
3712 else if( string == "Hour_24" )
3713 return Hour_24;
3714 else
3715 return Hour_24;
3716}
3717
3718
3719void KDGanttView::addTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
3720{
3721
3722 if (myTaskLinkGroupList.isEmpty()) {
3723 myTaskLinkGroupList.append(group);
3724 return;
3725 }
3726 if (myTaskLinkGroupList.find(group) == -1)
3727 myTaskLinkGroupList.append(group);
3728}
3729
3730
3731void KDGanttView::removeTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
3732{
3733 myTaskLinkGroupList.remove(group);
3734}
3735
3736
3742void KDGanttView::editItem( KDGanttViewItem* item)
3743{
3744 if ( ! item )
3745 return;
3746 if ( editorEnabled() ) {
3747 if ( item->editable() ) {
3748 myItemAttributeDialog->reset( item );
3749 myItemAttributeDialog->show();
3750 }
3751 }
3752}
3753
3754
3766 const TQColor& shapeColor,
3767 const TQColor& backgroundColor, int itemSize)
3768{
3769 // 10 is a good value as size
3770 int size = itemSize+2;
3771 int hei = ( itemSize/3 ) / 2;
3772 TQPixmap p = TQPixmap( size+4, size+4 );
3773 p.fill( backgroundColor );
3774 TQPainter paint (&p);
3775 TQBrush b = TQBrush ( TQt::SolidPattern );
3776 b.setColor( shapeColor );
3777 paint.setBrush( b );
3778 TQPen pen( TQt::black, 1 ) ;
3779 paint.setPen( pen );
3780 switch (shape) {
3781 case KDGanttViewItem::TriangleDown:{
3782 TQPointArray arr = TQPointArray(3);
3783 arr.setPoint(0,-size/2,-hei);
3784 arr.setPoint(1,size/2,-hei);
3785 arr.setPoint(2,0,((size/2)-hei));
3786 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3787 paint.drawPolygon( arr );
3788 break;
3789 }
3790 case KDGanttViewItem::TriangleUp :{
3791 TQPointArray arr = TQPointArray(3);
3792 arr.setPoint(0,-size/2,hei);
3793 arr.setPoint(1,size/2,hei);
3794 arr.setPoint(2,0,(-size/2)+hei);
3795 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3796 paint.drawPolygon( arr );
3797 break;
3798 }
3799 case KDGanttViewItem::Diamond :{
3800 TQPointArray arr = TQPointArray(4);
3801 arr.setPoint(0,0,-size/2);
3802 arr.setPoint(1,size/2,0);
3803 arr.setPoint(2,0,size/2);
3804 arr.setPoint(3,-size/2,0);
3805 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3806 paint.drawPolygon( arr );
3807 break;
3808 }
3809 case KDGanttViewItem::Square :{
3810 TQPointArray arr = TQPointArray(4);
3811 arr.setPoint(0,-size/2,-size/2);
3812 arr.setPoint(1,size/2,-size/2);
3813 arr.setPoint(2,size/2,size/2);
3814 arr.setPoint(3,-size/2,size/2);
3815 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3816 paint.drawPolygon( arr );
3817 break;
3818 }
3819 case KDGanttViewItem::Circle :{
3820 paint.drawEllipse( 2, 2, size, size);
3821 break;
3822 }
3823 }
3824 paint.end();
3825 return p;
3826}
3827
3828int KDGanttView::getIndex( KDGanttViewItem::Type type) const
3829{
3830 int index = -1;
3831 switch (type) {
3832 case (KDGanttViewItem::Event):
3833 index = 0;
3834 break;
3835 case (KDGanttViewItem::Task):
3836 index = 1;
3837 break;
3838 case (KDGanttViewItem::Summary):
3839 index = 2;
3840 break;
3841 }
3842 return index;
3843}
3844
3845
3846void KDGanttView::initDefaults()
3847{
3848 int i;
3849 // We have 3 item types. Set all undefined to true.
3850 for (i = 0;i<3;++i) {
3851 undefinedShape[i] = true;
3852 undefinedColor[i] = true;
3853 undefinedColorHL[i] = true;
3854 }
3855 // setting the default colors
3856 myDefaultColor [ getIndex( KDGanttViewItem::Event ) ] = TQt::blue; //event
3857 myDefaultColorHL [ getIndex( KDGanttViewItem::Event ) ] = TQt::red;
3858 myDefaultColor [ getIndex( KDGanttViewItem::Task ) ] = TQt::green;//task
3859 myDefaultColorHL [ getIndex( KDGanttViewItem::Task ) ] = TQt::red;
3860 myDefaultColor [ getIndex( KDGanttViewItem::Summary ) ] = TQt::cyan;//summary
3861 myDefaultColorHL [ getIndex( KDGanttViewItem::Summary ) ] = TQt::red;
3862
3863 // setting the default shape types
3864 // currently, we take for each item for all three shapes (start, middle, end) the same default shape
3865 for (i = 0;i<3;++i) {
3866 myDefaultShape [3*getIndex( KDGanttViewItem::Event )+ i] = KDGanttViewItem::Diamond; //event
3867 myDefaultShape [3*getIndex( KDGanttViewItem::Task ) +i] = KDGanttViewItem::Square; //task
3868 myDefaultShape [3*getIndex( KDGanttViewItem::Summary ) +i] = KDGanttViewItem::TriangleDown; //summary
3869
3870 }
3871}
3872
3873
3874
3878int KDGanttView::addColumn( const TQString& label, int width )
3879{
3880 return myListView->addColumn( label, width );
3881}
3882
3883
3887
3888int KDGanttView::addColumn( const TQIconSet& iconset, const TQString& label,
3889 int width )
3890{
3891 return myListView->addColumn( iconset, label, width );
3892}
3893
3894
3899{
3900 myListView->removeColumn( index );
3901}
3902
3903
3907KDGanttViewItem* KDGanttView::selectedItem() const
3908{
3909 return static_cast<KDGanttViewItem*>( myListView->selectedItem() );
3910}
3911
3912
3916void KDGanttView::setSelected( KDGanttViewItem* item, bool selected )
3917{
3918 myListView->setSelected( item, selected );
3919}
3920
3921
3934KDGanttViewItem* KDGanttView::getItemByName( const TQString& name ) const
3935{
3936 KDGanttViewItem* temp = firstChild(),* ret;
3937 while (temp != 0) {
3938 if ( (ret = temp->getChildByName( name ) ) )
3939 return ret;
3940 temp = temp->nextSibling();
3941 }
3942 return 0;
3943}
3944
3945
3957KDGanttViewItem* KDGanttView::getItemByListViewPos( const TQPoint& pos ) const
3958{
3959 return static_cast<KDGanttViewItem*>( myListView->itemAt(myListView->mapFromGlobal(pos) ));
3960}
3961
3962
3977KDGanttViewItem* KDGanttView::getItemByGanttViewPos( const TQPoint& pos ) const
3978{
3979 KDGanttViewItem* item;
3980 TQPoint local = myCanvasView->mapFromGlobal(pos);
3981
3982 TQCanvasItemList il = myTimeTable->collisions( myCanvasView->viewportToContents( local ));
3983 TQCanvasItemList::Iterator it;
3984 for ( it = il.begin(); it != il.end(); ++it ) {
3985 if ( myCanvasView->getType(*it) == Type_is_KDGanttViewItem) {
3986 item = myCanvasView->getItem(*it);
3987 if ( item->enabled() )
3988 return item;
3989 }
3990 }
3991 return 0;
3992}
3993
3994
4009KDGanttViewItem* KDGanttView::getItemAt( const TQPoint& pos, bool global ) const
4010{
4011 /* buggy code - commented out
4012 TQPoint myPos;
4013 if ( global )
4014 myPos = myListView->contentsToViewport( myListView->mapFromGlobal(pos) );
4015 else
4016 myPos = myListView->contentsToViewport( pos );
4017 return (KDGanttViewItem*) myListView->itemAt( myPos );
4018 */
4019
4020 KDGanttViewItem* item;
4021 KDGanttViewItem* retItem = 0;
4022 int y;
4023 if ( global )
4024 y = myCanvasView->mapFromGlobal(pos).y();
4025 else
4026 y = pos.y();
4027 item = firstChild();
4028 while ( item != 0 ) {
4029 int yc = item->itemPos();
4030 if ( yc <= y && y < yc + item->height()) {
4031 retItem = item;
4032 break;
4033 }
4034 item = item->itemBelow();
4035 }
4036 return retItem;
4037
4038}
4039
4040
4041void KDGanttView::addTickRight()
4042{
4043 if ( _enableAdding && myCanvasView->horizontalScrollBar()->value() == myCanvasView->horizontalScrollBar()->maxValue()) {
4044 //myCanvasView->horizontalScrollBar()->blockSignals( true );
4045 myTimeHeader->addTickRight();
4046 //myCanvasView->horizontalScrollBar()->blockSignals( false );
4047 myCanvasView->updateHorScrollBar();
4049 }
4050}
4051
4052
4053void KDGanttView::addTickLeft()
4054{
4055 if ( _enableAdding && myCanvasView->horizontalScrollBar()->value() == 0 ) {
4056 myCanvasView->horizontalScrollBar()->blockSignals( true );
4057 myTimeHeader->addTickLeft();
4058 myCanvasView->horizontalScrollBar()->blockSignals( false );
4060 }
4061}
4062
4063
4064void KDGanttView::enableAdding( int val )
4065{
4066 _enableAdding = ( val == 0 || val == myCanvasView->horizontalScrollBar()->maxValue());
4067}
4068
4069
4076{
4077 return myListView->childCount();
4078}
4079
4080
4085{
4086 bool block = myTimeTable->blockUpdating();
4087 myTimeTable->setBlockUpdating( true );
4088 myListView->clear();
4089 myTimeTable->setBlockUpdating( false );
4090 myTimeTable->updateMyContent();
4091 myTimeTable->setBlockUpdating( block );
4092}
4093
4094
4098void KDGanttView::slot_lvDropped(TQDropEvent* e, KDGanttViewItem* droppedItem, KDGanttViewItem* itemBelowMouse )
4099{
4100 emit dropped( e, droppedItem, itemBelowMouse);
4101}
4102
4107{
4108 return myListView->dragObject ();
4109}
4110
4111
4116{
4117 //myListView->pt_startDrag ();
4118}
4119
4120
4125{
4126 TQWidget::setPaletteBackgroundColor( col );
4127 timeHeaderSpacerWidget->setPaletteBackgroundColor( col );
4128}
4129
4130
4137void KDGanttView::setGvBackgroundColor ( const TQColor & c )
4138{
4139 myTimeTable->setBackgroundColor( c );
4140}
4141
4142
4150{
4151 myTimeHeader->setPaletteBackgroundColor( c );
4152 //rightWidget->setPaletteBackgroundColor( c );
4153 timeHeaderSpacerWidget->setPaletteBackgroundColor( c );
4154}
4155
4156
4164{
4165 myLegend->setPaletteBackgroundColor( c );
4166 leftWidget->setPaletteBackgroundColor( c );
4167}
4168
4169
4176void KDGanttView::setLvBackgroundColor ( const TQColor & c )
4177{
4178 myListView->viewport()->setPaletteBackgroundColor( c );
4179}
4180
4181
4189{
4190 return myListView->viewport()->paletteBackgroundColor( );
4191}
4192
4193
4201{
4202 return myTimeTable->backgroundColor( );
4203}
4204
4205
4213{
4214 return myTimeHeader->paletteBackgroundColor( );
4215}
4216
4217
4225{
4226 return myLegend->paletteBackgroundColor( );
4227}
4228
4229
4245{
4246 if ( w ) {
4247 w->reparent ( spacerLeft, 0, TQPoint(0,0) );
4248 }
4249}
4250
4251
4261{
4262 fDragEnabled = b;
4263 TQListViewItemIterator it( myListView );
4264 for ( ; it.current(); ++it ) {
4265 (( KDGanttViewItem* )it.current())->setDragEnabled(b);
4266 }
4267
4268}
4269
4270
4280{
4281 fDropEnabled = b;
4282
4283 //myListView->setAcceptDrops( b );
4284 TQListViewItemIterator it( myListView );
4285 for ( ; it.current(); ++it ) {
4286 (( KDGanttViewItem* )it.current())->setDropEnabled(b);
4287 }
4288}
4289
4290
4300{
4301 setDropEnabled( b );
4302 setDragEnabled( b );
4303}
4304
4305
4313{
4314 return fDragEnabled;
4315}
4316
4317
4325{
4326 return fDropEnabled;
4327}
4328
4329
4334{
4335 return isDragEnabled();
4336}
4337
4338
4343{
4344 return isDropEnabled();
4345}
4346
4347
4374bool KDGanttView::lvDropEvent ( TQDropEvent* e,
4375 KDGanttViewItem* droppedItem,
4376 KDGanttViewItem* itemBelowMouse )
4377{
4378 Q_UNUSED( e );
4379 Q_UNUSED( droppedItem );
4380 Q_UNUSED( itemBelowMouse );
4381
4382 // Example code for user defined behaviour:
4383 // we want to accept the usual drags and the drags of files, which may be
4384 // a saved Gantt file.
4385 // Please uncomment the following lines for this behaviour
4386 // You have to uncomment lines in lvDragMoveEvent() and llvDragEnterEvent() as well
4387
4388 // ************** begin example ************
4389 /*
4390 if ( TQUriDrag::canDecode( e ) ) {
4391 TQStrList lst;
4392 TQUriDrag::decode( e, lst );
4393 // we try the first file of icon-url-list
4394 TQString str = lst.at ( 0 );
4395 // remove file: at beginning of string
4396 str = str.right( str.length() - 5 );
4397 TQFileInfo info;
4398 info.setFile( str ) ;
4399 if ( info.isFile() ) {
4400 if (!TQMessageBox::information( this, "KDGantt Drag&Drop test",
4401 "Try to insert file: "+ str + " ?",
4402 "&Okay", "&Cancel",0,1 ) ) {
4403 TQFile file( str );
4404 // store current updating status
4405 bool uen = myTimeTable->blockUpdating();
4406 // block updating while insertion of items
4407 myTimeTable->setBlockUpdating();
4408 loadProject( &file ) ;
4409 // restore updating status and execute an update via setUpdateEnabled( true );
4410 if ( !uen )
4411 setUpdateEnabled( true );
4412 }
4413 }
4414 return true;
4415 }
4416 */
4417 // *********** end example ****************
4418 return false;
4419}
4420
4421
4438void KDGanttView::lvDragEnterEvent ( TQDragEnterEvent * e)
4439{
4440 // the standard behaviour:
4441 // accept drag enter events, if KDGanttViewItemDrag can decode the event
4442 // e->accept(KDGanttViewItemDrag::canDecode(e) );
4443
4445 e->accept( true);
4446 return;
4447 }
4448
4449 // example code for user defined behaviour:
4450 // we want to accecpt the usual drags and the drags of files, which may be
4451 // a saved Gantt file
4452 // Please uncomment the following lines for this behaviour
4453 // You have to uncomment lines in lvDragMoveEvent() and lvDropEvent () as well
4454
4455 // if ( TQUriDrag::canDecode( e ) ) {
4456 // e->accept(true);
4457 // return;
4458 // }
4459
4460 e->accept( false );
4461}
4462
4463
4492bool KDGanttView::lvDragMoveEvent ( TQDragMoveEvent* /*e*/,
4493 KDGanttViewItem* /* draggedItem*/,
4494 KDGanttViewItem* /*itemBelowMouse*/)
4495{
4496
4497 // Example code 1:
4498 // To generally block items to be inserted as root items, subclass KDGanttView
4499 // and reimplement this method with to following code uncommented:
4500
4501 // if ( !itemBelowMouse ) {
4502 // e->accept( false );
4503 // return true;
4504 //}
4505 //return false;
4506
4507 // Example code 2:
4508 // To allow the drags of files, which may be
4509 // a saved Gantt file, subclass KDGanttView
4510 // and reimplement this method with to following code uncommented:
4511
4512 // if ( TQUriDrag::canDecode( e ) ) {
4513 // e->accept(true);
4514 // return true;
4515 // }
4516
4517
4518 // normal behaviour - the internal drag move event handling should be executed
4519 return false;
4520}
4521
4522
4532void KDGanttView::lvStartDrag (KDGanttViewItem* item)
4533{
4534 TQDragObject* d = new KDGanttViewItemDrag(item, this, "itemdrag" );
4535 // call d->drag() to start the dragging
4536 // d->drag() returns true, if a move was requested as a drag
4537 // if a copy (by pressing the <Ctrl>-key) was performed, d->drag() returns false
4538 // In order to avoid starting drags for particular items, subclass KDGanttView
4539 // an reimplement this method.
4540 // insert here some code like
4541 // if ( item->parent() )
4542 // return;
4543 // This particular code will make it impossible to drag other items but root items.
4544 if ( d->drag() ) {
4545 delete item;
4546 }
4547}
4548
4549
4558{
4559 int sw = mySplitter->width();
4560 TQValueList<int> list;
4561 list.append(w);
4562 list.append(sw-w);
4563 mySplitter->setSizes( list );
4564}
4565
4566
4574{
4575 return leftWidget->width();
4576}
4577
4578
4588void KDGanttView::setLvVScrollBarMode( TQScrollView::ScrollBarMode m )
4589{
4590 myListView->setVScrollBarMode ( m );
4591}
4592
4593
4603void KDGanttView::setGvVScrollBarMode( TQScrollView::ScrollBarMode m )
4604{
4605 if ( m == TQScrollView::Auto )
4606 tqDebug("KDGanttView::setListViewVScrollBarMode: TQScrollView::Auto not supported. Nothing changed. ");
4607 else
4608 {
4609 myCanvasView->setVScrollBarMode ( m );
4610 if ( m == TQScrollView::AlwaysOn )
4611 timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
4612 else
4613 timeHeaderSpacerWidget->setFixedWidth( 0 );
4614 }
4615}
4616
4617
4618void KDGanttView::notifyEditdialog( KDGanttViewItem * item)
4619{
4620 if (myItemAttributeDialog->getItem() == item ) {
4621 myItemAttributeDialog->reset( 0 );
4622 }
4623}
4624
4633{
4634 myCanvasView->linkItemsEnabled = on;
4635 myCanvasView->autoScrollEnabled = true;
4636}
4637
4644{
4645 return myCanvasView->linkItemsEnabled;
4646}
4647
4656
4657
4665
4666
4681
4682
4689
4690
4697
4698
4705
4712
4719
4725
4732
4733
4739
4740
4747
4748
4755
4756
4763
4770
4778
4787
4793
4802
4810
4817
4818
4835
4836
4843
KDGanttMinimizeSplitter(TQWidget *parent=0, const char *name=0)
Drag and drop of KD Gantt items.
static bool canDecode(const TQMimeSource *e)
KDGanttViewItem * getChildByName(const TQString &name)
KDGanttViewItem * itemBelow(bool includeDisabled=true)
void createNode(TQDomDocument &doc, TQDomElement &parentElement)
KDGanttViewItem * nextSibling() const
bool editable() const
static KDGanttViewItem * createFromDomElement(KDGanttView *view, TQDomElement &element)
void setDisplaySubitemsAsGroup(bool show)
KDGanttViewItem * firstChild() const
static KDGanttViewTaskLinkGroup * createFromDomElement(TQDomElement &)
void createNode(TQDomDocument &doc, TQDomElement &parentElement)
bool showMinorTicks() const
bool showListView() const
void setTimelineToEnd()
void setZoomFactor(double factor, bool absolute)
void setYearFormat(YearFormat format)
void itemRightClicked(KDGanttViewItem *)
virtual void show()
bool isLinkItemsEnabled() const
void setDisplaySubitemsAsGroup(bool show)
void setMinimumColumnWidth(int width)
TQBrush noInformationBrush() const
TQSize drawContents(TQPainter *p=0, bool drawListView=true, bool drawTimeLine=true, bool drawLegend=false)
void setScale(Scale)
void setWeekendDays(int start, int end)
void lvItemRenamed(KDGanttViewItem *, int col, const TQString &text)
bool editorEnabled() const
void lvMouseButtonPressed(int button, KDGanttViewItem *item, const TQPoint &pos, int c)
void addUserdefinedLegendHeaderWidget(TQWidget *w)
void clearBackgroundColor()
TQColor timeHeaderBackgroundColor() const
virtual void startDrag()
void print(TQPrinter *printer=0, bool printListView=true, bool printTimeLine=true, bool printLegend=false)
static TQPixmap getPixmap(KDGanttViewItem::Shape shape, const TQColor &shapeColor, const TQColor &backgroundColor, int itemSize)
void lvCurrentChanged(KDGanttViewItem *)
KDGanttViewItem * getItemAt(const TQPoint &pos, bool global=true) const
void setShowMajorTicks(bool)
bool dragEnabled() const
void itemMidClicked(KDGanttViewItem *)
virtual int addColumn(const TQString &label, int width=-1)
virtual void lvStartDrag(KDGanttViewItem *)
void setShowTaskLinks(bool show)
int ganttMaximumWidth() const
void setDefaultColor(KDGanttViewItem::Type type, const TQColor &, bool overwriteExisting=true)
KDGanttViewItem * firstChild() const
KDGanttViewItem * getItemByGanttViewPos(const TQPoint &pos) const
void setEditable(bool editable)
bool colors(KDGanttViewItem::Type type, TQColor &start, TQColor &middle, TQColor &end) const
void setSelected(KDGanttViewItem *, bool)
TQColor columnBackgroundColor(const TQDateTime &column) const
void setLegendHeaderBackgroundColor(const TQColor &)
bool isDropEnabled() const
TQPtrList< KDGanttViewTaskLinkGroup > taskLinkGroups() const
void center(KDGanttViewItem *)
void lvContextMenuRequested(KDGanttViewItem *item, const TQPoint &pos, int col)
KDGanttView(TQWidget *parent=0, const char *name=0)
void lvItemDoubleClicked(KDGanttViewItem *)
void setPaletteBackgroundColor(const TQColor &col)
double zoomFactor() const
virtual void removeColumn(int index)
void setShowListView(bool show)
void setGanttMaximumWidth(int w)
void setDragDropEnabled(bool b)
void setShapes(KDGanttViewItem::Type type, KDGanttViewItem::Shape start, KDGanttViewItem::Shape middle, KDGanttViewItem::Shape end, bool overwriteExisting=true)
void setCalendarMode(bool mode)
void setDropEnabled(bool b)
void setWeekendBackgroundColor(const TQColor &color)
void setHighlightColors(KDGanttViewItem::Type type, const TQColor &start, const TQColor &middle, const TQColor &end, bool overwriteExisting=true)
bool saveProject(TQIODevice *)
void setLinkItemsEnabled(bool on)
void addLegendItem(KDGanttViewItem::Shape shape, const TQColor &shapeColor, const TQString &text)
void setListViewWidth(int)
Scale minimumScale() const
bool getUpdateEnabled() const
void setShowHeaderPopupMenu(bool show=true, bool showZoom=true, bool showScale=true, bool showTime=true, bool showYear=true, bool showGrid=true, bool showPrint=false)
void setDisplayEmptyTasksAsLine(bool show)
void centerTimeline(const TQDateTime &center)
bool calendarMode() const
bool highlightColors(KDGanttViewItem::Type type, TQColor &start, TQColor &middle, TQColor &end) const
void setGvVScrollBarMode(TQScrollView::ScrollBarMode)
void setHorBackgroundLines(int count=2, TQBrush brush=TQBrush(TQColor(200, 200, 200), TQt::Dense6Pattern))
virtual bool lvDragMoveEvent(TQDragMoveEvent *e, KDGanttViewItem *, KDGanttViewItem *)
void setMinorScaleCount(int count)
void addTicksLeft(int num=1)
void setDragEnabled(bool b)
bool isDragEnabled() const
void setShowLegend(bool show)
TQColor defaultHighlightColor(KDGanttViewItem::Type type) const
int minimumColumnWidth() const
void lvSelectionChanged(KDGanttViewItem *)
void setShowLegendButton(bool show)
bool showLegend() const
TQColor lvBackgroundColor() const
TQColor legendHeaderBackgroundColor() const
virtual TQSize sizeHint() const
TQColor defaultColor(KDGanttViewItem::Type type) const
Scale scale() const
void setIntervalBackgroundColor(const TQDateTime &start, const TQDateTime &end, const TQColor &color, Scale mini=KDGanttView::Minute, Scale maxi=KDGanttView::Month)
TQDateTime getDateTimeForCoordX(int coordX, bool global=true) const
bool editable() const
void setEditorEnabled(bool enable)
bool showTaskLinks() const
bool showMajorTicks() const
int majorScaleCount() const
void itemLeftClicked(KDGanttViewItem *)
TQDateTime horizonStart() const
void setHorizonEnd(const TQDateTime &start)
virtual TQDragObject * dragObject()
void setDefaultHighlightColor(KDGanttViewItem::Type type, const TQColor &, bool overwriteExisting=true)
KDGanttViewItem * getItemByListViewPos(const TQPoint &pos) const
Scale maximumScale() const
void itemDoubleClicked(KDGanttViewItem *)
bool loadProject(TQIODevice *)
TQPtrList< KDGanttViewTaskLink > taskLinks() const
void setMaximumScale(Scale)
TQColor gvBackgroundColor() const
virtual void lvDragEnterEvent(TQDragEnterEvent *e)
void setMajorScaleCount(int count)
void lvItemMidClicked(KDGanttViewItem *)
bool showTimeTablePopupMenu() const
void lvItemLeftClicked(KDGanttViewItem *)
void setTextColor(const TQColor &color)
void setShowTimeTablePopupMenu(bool)
void setHorizonStart(const TQDateTime &start)
bool legendIsDoctwindow() const
void setFont(const TQFont &f)
void setLvVScrollBarMode(TQScrollView::ScrollBarMode)
bool shapes(KDGanttViewItem::Type type, KDGanttViewItem::Shape &start, KDGanttViewItem::Shape &middle, KDGanttViewItem::Shape &end) const
void setAutoScaleMinorTickCount(int count)
void setLegendIsDoctwindow(bool dock)
TQColor weekendBackgroundColor() const
void weekendDays(int &start, int &end) const
bool showLegendButton() const
TQColor textColor() const
HourFormat hourFormat() const
bool displaySubitemsAsGroup() const
void setWeekdayBackgroundColor(const TQColor &color, int weekday)
void ensureVisible(KDGanttViewItem *)
void zoomToSelection(const TQDateTime &start, const TQDateTime &end)
void setUpdateEnabled(bool enable)
bool dropEnabled() const
bool showHeaderPopupMenu() const
void setHourFormat(HourFormat format)
int autoScaleMinorTickCount() const
KDGanttViewItem * selectedItem() const
bool headerVisible() const
int childCount() const
int minorScaleCount() const
void dropped(TQDropEvent *e, KDGanttViewItem *droppedItem, KDGanttViewItem *itemBelowMouse)
void setHeaderVisible(bool)
virtual bool close(bool alsoDelete)
void setColors(KDGanttViewItem::Type type, const TQColor &start, const TQColor &middle, const TQColor &end, bool overwriteExisting=true)
YearFormat yearFormat() const
virtual bool lvDropEvent(TQDropEvent *e, KDGanttViewItem *, KDGanttViewItem *)
TQDateTime horizonEnd() const
void setNoInformationBrush(const TQBrush &brush)
void setLvBackgroundColor(const TQColor &)
KDGanttViewItem * getItemByName(const TQString &name) const
void setShowMinorTicks(bool)
bool displayEmptyTasksAsLine() const
int horBackgroundLines(TQBrush &brush)
void setGvBackgroundColor(const TQColor &)
TQDockWindow * legendDoctwindow() const
void setMinimumScale(Scale)
void setColumnBackgroundColor(const TQDateTime &column, const TQColor &color, Scale mini=KDGanttView::Minute, Scale maxi=KDGanttView::Month)
void setTimelineToStart()
void lvItemRightClicked(KDGanttViewItem *)
void lvMouseButtonClicked(int button, KDGanttViewItem *item, const TQPoint &pos, int c)
KDGanttViewItem * lastItem() const
void addTicksRight(int num=1)
void setRepaintMode(RepaintMode mode)
bool changeBackgroundInterval(const TQDateTime &oldstart, const TQDateTime &oldend, const TQDateTime &newstart, const TQDateTime &newend)
void setTimeHeaderBackgroundColor(const TQColor &)
void centerTimelineAfterShow(const TQDateTime &center)
void editItem(KDGanttViewItem *)
TQColor weekdayBackgroundColor(int weekday) const
bool deleteBackgroundInterval(const TQDateTime &start, const TQDateTime &end)