kdgantt

KDGanttView.cpp
1/*
2 $Id$
3 KDGantt - a multi-platform charting engine
4*/
5
6/****************************************************************************
7 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
8 **
9 ** This file is part of the KDGantt library.
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.GPL included in the
14 ** packaging of this file.
15 **
16 ** Licensees holding valid commercial KDGantt licenses may use this file in
17 ** accordance with the KDGantt Commercial License Agreement provided with
18 ** the Software.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
24 ** information about KDGantt Commercial License Agreements.
25 **
26 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
27 ** licensing are not clear to you.
28 **
29 ** As a special exception, permission is given to link this program
30 ** with any edition of TQt, and distribute the resulting executable,
31 ** without including the source code for TQt in the source distribution.
32 **
33 **********************************************************************/
34
35
36#include "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 mFixedHorizon( false )
88{
89#if defined KDAB_EVAL
90 EvalDialog::checkEvalLicense( "KD Gantt" );
91#endif
92 myCurrentItem = 0;
93 setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
94 mySplitter = new KDGanttMinimizeSplitter( this );
95 mySplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left );
96 leftWidget = new TQVBox( mySplitter );
97 rightWidget = new TQVBox( mySplitter );
98
99 myLegend = new KDLegendWidget( leftWidget, this );
100 spacerLeft = new TQHBox( leftWidget );
101 myListView = new KDListView(leftWidget, this);
102 myListView->setVScrollBarMode (TQScrollView::AlwaysOff );
103 connect( myListView, TQ_SIGNAL( selectionChanged( TQListViewItem* ) ),
104 this, TQ_SLOT( slotSelectionChanged( TQListViewItem* ) ) );
105
106 connect( myListView, TQ_SIGNAL( mouseButtonClicked ( int, TQListViewItem * , const TQPoint &, int ) ), this, TQ_SLOT( slotmouseButtonClicked ( int , TQListViewItem * , const TQPoint &, int ) ) );
107 connect( myListView, TQ_SIGNAL( contextMenuRequested ( TQListViewItem * , const TQPoint &, int ) ), this, TQ_SLOT( slotcontextMenuRequested ( TQListViewItem * , const TQPoint & , int ) ) );
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
488void KDGanttView::emptySpaceDoubleClicked( TQMouseEvent * e )
489{
490 emit dateTimeDoubleClicked( getDateTimeForCoordX( e->x(), false ) );
491}
492
493
494/*
495 Implements a casted pass-through of the currentChanged() signal.
496*/
497void KDGanttView::slotCurrentChanged ( TQListViewItem * item )
498{
499 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
500 myCurrentItem = gItem;
501 emit lvCurrentChanged( gItem );
502}
503
504
505/*
506 Implements a casted pass-through of the itemRenamed() signal.
507*/
508void KDGanttView::slotItemRenamed ( TQListViewItem * item , int col,
509 const TQString & text )
510{
511 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
512 emit lvItemRenamed( gItem, col, text );
513}
514
515
516/*
517 Implements a casted pass-through of the mouseButtonPressed() signal.
518*/
519void KDGanttView::slotMouseButtonPressed ( int button, TQListViewItem * item,
520 const TQPoint & pos, int c )
521{
522 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
523 emit lvMouseButtonPressed( button, gItem, pos, c );
524}
525
526
542{
543
544 TQScrollBar *cvh, *cvv;
545 cvh = myCanvasView->horizontalScrollBar();
546 cvv = myCanvasView->verticalScrollBar();
547 // first disconnect
548 cvh->disconnect( this );
549 cvv->disconnect( this );
550
551 switch ( mode ) {
552 case No:
553
554 break;
555 case Medium:
556 connect( cvv, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
557 connect( cvh, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
558 connect( cvv, TQ_SIGNAL (nextLine () ) ,this, TQ_SLOT(forceRepaint()));
559 connect( cvh, TQ_SIGNAL (nextLine () ) ,this, TQ_SLOT(forceRepaint()));
560 connect( cvv, TQ_SIGNAL (prevLine () ) ,this, TQ_SLOT(forceRepaint()));
561 connect( cvh, TQ_SIGNAL (prevLine () ) ,this, TQ_SLOT(forceRepaint()));
562 break;
563 case Always:
564 connect( cvv, TQ_SIGNAL (valueChanged ( int ) ) ,this, TQ_SLOT(forceRepaint( int )));
565 connect( cvh, TQ_SIGNAL (valueChanged ( int ) ) ,this, TQ_SLOT(forceRepaint( int )));
566 connect( cvv, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
567 connect( cvh, TQ_SIGNAL (sliderReleased () ) ,this, TQ_SLOT(forceRepaint()));
568 break;
569 }
570}
571
572
573void KDGanttView::forceRepaint( int )
574{
575 if ( myTimeTable->blockUpdating() )
576 return;
577 // tqDebug("forceRepaint( int ) ");
578 myTimeTable->setAllChanged();
579 myTimeTable->update();
580}
581
582
583void KDGanttView::slotHeaderSizeChanged()
584{
585 int legendHeight = 0;
586 if ( showLegendButton() )
587 legendHeight = 24;
588 int listViewHeaderHeight = 0;
589 if ( headerVisible() )
590 listViewHeaderHeight = myListView->header()->height();
591 int timeHeaderHeight = myTimeHeader->height()+myTimeHeaderScroll->frameWidth()*2;;
592 int diffY = timeHeaderHeight-legendHeight-listViewHeaderHeight;
593 if ( diffY < 0 ) {
594 spacerLeft->setFixedHeight( 0 );
595 spacerRight->setFixedHeight(-diffY);
596 } else {
597 spacerRight->setFixedHeight( 0 );
598 spacerLeft->setFixedHeight( diffY );
599 }
600 myLegend->setFixedHeight( legendHeight );
601 myTimeHeaderContainer->setFixedHeight( timeHeaderHeight );
602}
603
604
611{
612 bool isdock = myLegend->asDoctwindow();
613 if ( show != isdock ) {
614 myLegend->setAsDoctwindow(show);
615 // legend is cleared - reinit legend with list
616 legendItem* li;
617 for ( li = myLegendItems->first(); li; li = myLegendItems->next() ) {
618 myLegend->addLegendItem(li->shape, li->color, li->text );
619 }
620 }
621}
622
623
630{
631 return myLegend->asDoctwindow();
632}
633
634
647TQDockWindow* KDGanttView::legendDoctwindow() const
648{
649 return myLegend->dockwindow();
650}
651
652
662{
663 myLegend->showMe(show);
664}
665
666
676{
677 return myLegend->isShown();
678}
679
680
690{
691 if(listViewIsVisible == show) return;
692 listViewIsVisible = show;
693 if (listViewIsVisible)
694 myListView->parentWidget()->show();
695 else
696 myListView->parentWidget()->hide();
697}
698
699
707{
708 return listViewIsVisible;
709}
710
711
720
722{
723 editorIsEnabled = enable;
724}
725
726
734
736{
737 return editorIsEnabled;
738}
739
740
748
750{
751 chartIsEditable = editable;
752}
753
754
761
763{
764 return chartIsEditable;
765}
766
767
778
779bool KDGanttView::saveProject( TQIODevice* device )
780{
781 Q_ASSERT( device );
782
783 TQDomDocument doc = saveXML();
784 if( device->isOpen() )
785 device->close();
786 if( device->open( IO_WriteOnly ) ) {
787 TQTextStream ts( device );
788 ts << doc.toString();
789 return true;
790 } else
791 return false;
792}
793
794
805
806bool KDGanttView::loadProject( TQIODevice* device )
807{
808 Q_ASSERT( device );
809
810 if( device->isOpen() )
811 device->close();
812 if( device->open( IO_ReadOnly ) ) {
813 TQDomDocument doc( "GanttView" );
814 TQString err;
815 int errline, errcol;
816 if ( !doc.setContent( device, &err, &errline, &errcol ) ) {
817 tqDebug("KDGantt::Error parsing XML data at line %d. Message is:", errline );
818 tqDebug("%s ", err.latin1());
819 device->close();
820 return false;
821 }
822 device->close();
823 return loadXML( doc );
824 } else
825 return false;
826}
827
828
846
847void KDGanttView::print( TQPrinter* printer ,
848 bool printListView, bool printTimeLine,
849 bool printLegend )
850{
851 bool deletePrinter = false;
852 if (! printer ) {
853 printer = new TQPrinter();
854 deletePrinter = true;
855 if ( !printer->setup()) {
856 delete printer;
857 return;
858 }
859 }
860 // now we have a printer to print on
861 TQPainter p( printer );
862 // get the paper metrics
863 TQPaintDeviceMetrics m = TQPaintDeviceMetrics ( printer );
864 float dx, dy;
865 // get the size of the desired output for scaling.
866 // here we want to print all: ListView, TimeLine, and Legend
867 // for this purpose, we call drawContents() with a 0 pointer as painter
868 TQSize size = drawContents( 0, printListView, printTimeLine, printLegend );
869
870 // at the top, we want to print current time/date
871 TQString date = "Printing Time: " + TQDateTime::currentDateTime().toString();
872 int hei = p.boundingRect(0,0, 5, 5, TQt::AlignLeft, date ).height();
873 p.drawText( 0, 0, date );
874
875 // compute the scale
876 dx = (float) m.width() / (float)size.width();
877 dy = (float)(m.height() - ( 2 * hei )) / (float)size.height();
878 float scale;
879 // scale to fit the width or height of the paper
880 if ( dx < dy )
881 scale = dx;
882 else
883 scale = dy;
884 // set the scale
885 p.scale( scale, scale );
886 // now printing with y offset: 2 hei
887 p.translate( 0, 2*hei );
888 drawContents( &p, printListView, printTimeLine, printLegend );
889 // the drawContents() has the side effect, that the painter translation is
890 // after drawContents() set to the bottom of the painted stuff
891 // for instance a
892 // p.drawText(0, 0, "printend");
893 // would be painted directly below the paintout of drawContents()
894 p.end();
895 if ( deletePrinter )
896 delete printer;
897}
898
899
939TQSize KDGanttView::drawContents( TQPainter* p,
940 bool drawListView , bool drawTimeLine, bool drawLegend )
941{
942 TQSize size;
943 int lvX, lvY, thX, thY, tlX, tlY, lwX, lwY, allX, allY;
944 lvX = myListView->contentsWidth();
945 lvY = myCanvasView->canvas()->height() + 20;
946 thX = myTimeHeader->width();
947 thY = myTimeHeader->height();
948 tlX = myCanvasView->canvas()->width();
949 tlY = lvY;
950 lwX = myLegend->legendSize().width();
951 lwY = myLegend->legendSize().height();
952 allX = 0;
953 allY = 0;
954 if ( drawListView ) {
955 allX += lvX;
956 allY += tlY;
957 }
958 if ( drawTimeLine ) {
959 allX += thX;
960 allY += thY;
961 }
962 if ( drawLegend ) {
963 allY += lwY;
964 if ( allX < lwX )
965 allX = lwX ;
966 }
967 size = TQSize( allX, allY );
968 int temp = 0;
969 if ( p ) {
970 if ( drawListView ) {
971 if ( drawTimeLine )
972 temp = thY;
973 p->translate( 0, temp );
974 //HACK: Only draw list headers if we draw timeline, else
975 // there is no room for it. This will most probably be changed
976 // with qt4 anyway, so I think we can live with it atm.
977 myListView->drawToPainter( p, drawTimeLine );
978 p->translate( lvX, -temp);
979 }
980 if ( drawTimeLine ) {
981 p->translate( myCanvasView->frameWidth(), 0);
982 myTimeHeader->repaintMe( 0, myTimeHeader->width(), p );
983 p->translate( -myCanvasView->frameWidth(), thY);
984 myCanvasView->drawToPainter( p );
985 if ( drawListView )
986 p->translate( -lvX, tlY);
987 else
988 p->translate( 0, tlY);
989 } else {
990 if ( drawListView )
991 p->translate( -lvX, 0 );
992 }
993 if ( drawLegend ) {
994 myLegend->drawToPainter( p );
995 p->translate( 0, lwY );
996 }
997 }
998 return size;
999}
1000
1013
1014void KDGanttView::setZoomFactor( double factor, bool absolute )
1015{
1016 myTimeHeader->zoom(factor,absolute);
1017}
1018
1019
1026
1028{
1029 return myTimeHeader->zoomFactor();
1030}
1031
1032
1040
1042{
1043 myTimeHeader->zoomToFit();
1044}
1045
1046
1057
1058void KDGanttView::zoomToSelection( const TQDateTime& start, const TQDateTime& end )
1059{
1060
1061 myTimeHeader->zoomToSelection( start, end);
1062
1063}
1064
1065
1072void KDGanttView::ensureVisible( KDGanttViewItem* item )
1073{
1074 myListView->ensureItemVisible (item);
1075}
1076
1077
1086void KDGanttView::centerTimeline( const TQDateTime& center )
1087{
1088 myTimeHeader->centerDateTime( center );
1089}
1090
1091
1106{
1107 myTimeHeader->centerDateTime( center );
1108 if ( ! isVisible() ) {
1109 dtCenterTimeLineAfterShow = center;
1110 fCenterTimeLineAfterShow = true;
1111 }
1112}
1113
1117
1119{
1120 myCanvasView->horizontalScrollBar()->setValue( 0 );
1121}
1122
1123
1128{
1129 myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->maxValue());
1130}
1131
1132
1144{
1145 myTimeHeader->addTickLeft( num );
1146}
1147
1148
1159{
1160 myTimeHeader->addTickRight( num );
1161}
1162
1163
1168void KDGanttView::center( KDGanttViewItem* item )
1169{
1170 ensureVisible(item);
1171 int x = myListView->contentsWidth()/2;
1172 int y = myListView->itemPos (item );
1173 myListView->center(x,y);
1174}
1175
1176
1184{
1185 myTimeTable->setShowTaskLinks(show);
1186
1187}
1188
1189
1197{
1198 return myTimeTable->showTaskLinks();
1199}
1200
1201
1209void KDGanttView::setFont(const TQFont& font)
1210{
1211 myListView->setFont(font);
1212 myListView->repaint();
1213 myTimeHeader->setFont(font);
1214 myLegend->setFont( font );
1215 TQWidget::setFont( font );
1216 setScale(scale());
1217}
1218
1219
1245 bool showZoom,
1246 bool showScale,
1247 bool showTime,
1248 bool showYear,
1249 bool showGrid,
1250 bool showPrint)
1251{
1252 myTimeHeader->setShowPopupMenu( show,showZoom,showScale,showTime,
1253 showYear,showGrid,showPrint );
1254}
1255
1256
1264{
1265 return myTimeHeader->showPopupMenu();
1266}
1267//****************************************************
1268
1269
1284{
1285 myCanvasView->setShowPopupMenu( show );
1286}
1287
1288
1296{
1297 return myCanvasView->showPopupMenu();
1298}
1299
1300
1322 bool overwriteExisting )
1323{
1324 if ( overwriteExisting ) {
1325 TQListViewItemIterator it(myListView);
1326 for ( ; it.current(); ++it ) {
1327 if ( ((KDGanttViewItem*)it.current())->type() == type)
1328 ((KDGanttViewItem*)it.current())->setShapes(start,middle, end );
1329 }
1330 }
1331 int index = getIndex( type );
1332 myDefaultShape [index*3] = start;
1333 myDefaultShape [index*3+1] = middle;
1334 myDefaultShape [index*3+2] = end;
1335 undefinedShape[index] = false;
1336}
1337
1338
1353 KDGanttViewItem::Shape& middle,
1354 KDGanttViewItem::Shape& end ) const
1355{
1356 int index = getIndex( type );
1357 start = myDefaultShape [index*3];
1358 middle = myDefaultShape [index*3+1];
1359 end = myDefaultShape [index*3+2];
1360 return !undefinedShape[index];
1361}
1362
1363
1382 const TQColor& start, const TQColor& middle,
1383 const TQColor& end,
1384 bool overwriteExisting )
1385{
1386 if ( overwriteExisting ) {
1387 TQListViewItemIterator it(myListView);
1388 for ( ; it.current(); ++it ) {
1389 if ( ((KDGanttViewItem*)it.current())->type() == type)
1390 ((KDGanttViewItem*)it.current())->setColors(start,middle, end );
1391 }
1392 }
1393 int index = getIndex( type );
1394 myColor [index*3] = start;
1395 myColor [index*3+1] = middle;
1396 myColor [index*3+2] = end;
1397 undefinedColor[index] = false;
1398}
1399
1400
1414 TQColor& start, TQColor& middle, TQColor& end ) const
1415{
1416 int index = getIndex( type );
1417 start = myColor [index*3];
1418 middle = myColor [index*3+1];
1419 end = myColor [index*3+2];
1420 return !undefinedColor[index];
1421}
1422
1423
1444 const TQColor& start,
1445 const TQColor& middle,
1446 const TQColor& end,
1447 bool overwriteExisting )
1448{
1449 if ( overwriteExisting ) {
1450 TQListViewItemIterator it(myListView);
1451 for ( ; it.current(); ++it ) {
1452 if ( ((KDGanttViewItem*)it.current())->type() == type)
1453 ((KDGanttViewItem*)it.current())->setHighlightColors(start,middle, end );
1454 }
1455 }
1456 int index = getIndex( type );
1457 myColorHL [index*3] = start;
1458 myColorHL [index*3+1] = middle;
1459 myColorHL [index*3+2] = end;
1460 undefinedColorHL[index] = false;
1461
1462}
1463
1464
1480 TQColor& start, TQColor& middle,
1481 TQColor& end ) const
1482{
1483 int index = getIndex( type );
1484 start = myColorHL [index*3];
1485 middle = myColorHL [index*3+1];
1486 end = myColorHL [index*3+2];
1487 return !undefinedColorHL[index];
1488}
1489
1490
1498void KDGanttView::setTextColor( const TQColor& color )
1499{
1500 TQListViewItemIterator it(myListView);
1501 for ( ; it.current(); ++it ) {
1502 ((KDGanttViewItem*)it.current())->setTextColor(color);
1503 }
1504 myTextColor = color;
1505}
1506
1507
1515{
1516 return myTextColor;
1517}
1518
1519
1530void KDGanttView::setNoInformationBrush( const TQBrush& brush )
1531{
1532 myTimeTable->setNoInformationBrush( brush );
1533}
1534
1535
1543{
1544 return myTimeTable->noInformationBrush();
1545}
1546
1547
1554{
1555 myLegend->clearLegend();
1556 myLegendItems->setAutoDelete( true );
1557 delete myLegendItems;
1558 myLegendItems = new TQPtrList<legendItem>;
1559}
1560
1561
1571 const TQColor& shapeColor,
1572 const TQString& text )
1573{
1574 myLegend->addLegendItem( shape,shapeColor,text );
1575 legendItem* item = new legendItem;
1576 item->shape = shape;
1577 item->color = shapeColor;
1578 item->text = text;
1579 myLegendItems->append( item );
1580}
1581
1582
1590void KDGanttView::setHorizonStart( const TQDateTime& start )
1591{
1592 myTimeHeader->setHorizonStart(start);
1593}
1594
1595
1603{
1604 return myTimeHeader->horizonStart();
1605}
1606
1607
1615void KDGanttView::setHorizonEnd( const TQDateTime& end )
1616{
1617 myTimeHeader->setHorizonEnd(end);
1618}
1619
1620
1628TQDateTime KDGanttView::horizonEnd() const
1629{
1630 return myTimeHeader->horizonEnd();
1631}
1632
1633
1642{
1643 myTimeHeader->setScale( unit );
1644}
1645
1646
1654{
1655 return myTimeHeader->scale();
1656}
1657
1658
1666{
1667 myTimeHeader->setMaximumScale( unit );
1668}
1669
1670
1678{
1679 return myTimeHeader->maximumScale();
1680}
1681
1682
1690{
1691 myTimeHeader->setMinimumScale( unit );
1692}
1693
1694
1702{
1703 return myTimeHeader->minimumScale();
1704}
1705
1706
1717{
1718 myTimeHeader->setAutoScaleMinorTickCount( count );
1719}
1720
1721
1729{
1730 return myTimeHeader->autoScaleMinorTickCount();
1731}
1732
1733
1743{
1744 myTimeHeader->setMinimumColumnWidth( width );
1745}
1746
1747
1755{
1756 return myTimeHeader->minimumColumnWidth();
1757}
1758
1759
1768{
1769 myTimeHeader->setYearFormat(format );
1770}
1771
1772
1780{
1781 return myTimeHeader->yearFormat();
1782}
1783
1784
1794{
1795 myTimeHeader->setHourFormat( format );
1796}
1797
1798
1807{
1808 return myTimeHeader->hourFormat();
1809}
1810
1811
1823{
1824 myTimeHeader->setShowMajorTicks(show );
1825}
1826
1827
1835{
1836 return myTimeHeader->showMajorTicks();
1837}
1838
1839
1853{
1854 myTimeHeader->setShowMinorTicks( show );
1855}
1856
1857
1865{
1866 return myTimeHeader->showMinorTicks();
1867}
1868
1869
1887void KDGanttView::setColumnBackgroundColor( const TQDateTime& column,
1888 const TQColor& color ,
1889 Scale mini, Scale maxi )
1890{
1891 myTimeHeader->setColumnBackgroundColor( column, color,mini,maxi );
1892}
1893
1894#if 0
1921void KDGanttView::setIntervalBackgroundColor( const TQDateTime& start,
1922 const TQDateTime& end,
1923 const TQColor& color ,
1924 Scale mini, Scale maxi )
1925{
1926 myTimeHeader->setIntervalBackgroundColor( start, end, color,mini,maxi );
1927}
1928
1929
1948bool KDGanttView::changeBackgroundInterval( const TQDateTime& oldstart,
1949 const TQDateTime& oldend,
1950 const TQDateTime& newstart,
1951 const TQDateTime& newend )
1952{
1953 return myTimeHeader->changeBackgroundInterval( oldstart, oldend,
1954 newstart, newend );
1955}
1956
1966bool KDGanttView::deleteBackgroundInterval( const TQDateTime& start,
1967 const TQDateTime& end)
1968{
1969 return myTimeHeader->deleteBackgroundInterval( start, end );
1970}
1971#endif
1972
1978void KDGanttView::addIntervalBackgroundColor( KDIntervalColorRectangle* newItem )
1979{
1980 myTimeHeader->addIntervalBackgroundColor( newItem );
1981}
1982
1992{
1993 myTimeHeader->clearBackgroundColor();
1994}
1995
1996
2005TQColor KDGanttView::columnBackgroundColor( const TQDateTime& column ) const
2006{
2007 return myTimeHeader->columnBackgroundColor( column ) ;
2008}
2009
2010
2019void KDGanttView::setWeekendBackgroundColor( const TQColor& color )
2020{
2021 myTimeHeader->setWeekendBackgroundColor( color );
2022}
2023
2024
2032{
2033 return myTimeHeader->weekendBackgroundColor();
2034}
2035
2036
2047void KDGanttView::setWeekdayBackgroundColor( const TQColor& color, int weekday )
2048{
2049 myTimeHeader->setWeekdayBackgroundColor( color, weekday );
2050}
2051
2052
2060TQColor KDGanttView::weekdayBackgroundColor(int weekday) const
2061{
2062 return myTimeHeader->weekdayBackgroundColor( weekday);
2063}
2064
2065
2066
2077void KDGanttView::setWeekendDays( int start, int end )
2078{
2079 myTimeHeader->setWeekendDays( start, end );
2080}
2081
2082
2090void KDGanttView::weekendDays( int& start, int& end ) const
2091{
2092 myTimeHeader->weekendDays( start, end );
2093}
2094
2095
2102
2103
2110
2111
2118
2119
2125
2126
2133
2134
2135
2142
2143
2150
2151
2158
2159
2165
2166
2172
2173
2179
2180
2186
2187
2188
2189
2197{
2198 myTimeHeader->setMajorScaleCount(count );
2199}
2200
2201
2209{
2210 return myTimeHeader->majorScaleCount();
2211}
2212
2213
2221{
2222 myTimeHeader->setMinorScaleCount(count );
2223}
2224
2225
2233{
2234 return myTimeHeader->minorScaleCount();
2235
2236}
2237
2238
2252 const TQColor& color,
2253 bool overwriteExisting )
2254{
2255 if ( overwriteExisting ) {
2256 TQListViewItemIterator it(myListView);
2257 for ( ; it.current(); ++it ) {
2258 if ( ((KDGanttViewItem*)it.current())->type() == type)
2259 ((KDGanttViewItem*)it.current())->setDefaultColor(color );
2260 }
2261 }
2262 int index = getIndex( type );
2263 myDefaultColor [index] = color;
2264}
2265
2266
2267
2279{
2280 int index = getIndex( type );
2281 return myDefaultColor [index];
2282}
2283
2284
2298 const TQColor& color,
2299 bool overwriteExisting )
2300{
2301 if ( overwriteExisting ) {
2302 TQListViewItemIterator it(myListView);
2303 for ( ; it.current(); ++it ) {
2304 if ( ((KDGanttViewItem*)it.current())->type() == type)
2305 ((KDGanttViewItem*)it.current())->setDefaultHighlightColor(color );
2306 }
2307 }
2308 int index = getIndex( type );
2309 myDefaultColorHL [index] = color;
2310}
2311
2312
2313
2325{
2326 int index = getIndex( type );
2327 return myDefaultColorHL [index];
2328}
2329
2330
2336KDGanttViewItem* KDGanttView::firstChild() const
2337{
2338 return (KDGanttViewItem*)myListView->firstChild();
2339
2340}
2341
2359{
2360 myListView->setCalendarMode( mode );
2361}
2362
2363
2372{
2373 return myListView->calendarMode();
2374}
2375
2376
2377
2388{
2389 TQListViewItemIterator it( myListView );
2390 for ( ; it.current(); ++it ) {
2391 KDGanttViewItem* currentItem = ( KDGanttViewItem* )it.current();
2392 currentItem->setDisplaySubitemsAsGroup( show );
2393 }
2394 _displaySubitemsAsGroup = show;
2395}
2396
2397
2407{
2408 return _displaySubitemsAsGroup;
2409}
2410
2411
2420{
2421 _displayEmptyTasksAsLine = show;
2422}
2423
2424
2432{
2433 return _displayEmptyTasksAsLine;
2434}
2435
2436
2451void KDGanttView::setHorBackgroundLines( int count, TQBrush brush )
2452{
2453 myTimeTable->setHorBackgroundLines( count, brush );
2454}
2455
2456
2467{
2468 return myTimeTable->horBackgroundLines( brush );
2469}
2470
2471
2477KDGanttViewItem* KDGanttView::lastItem() const
2478{
2479 return (KDGanttViewItem*)myListView->lastItem ();
2480}
2481
2482
2488TQPtrList<KDGanttViewTaskLink> KDGanttView::taskLinks() const
2489{
2490
2491 return myTimeTable->taskLinks();
2492}
2493
2494
2500TQPtrList<KDGanttViewTaskLinkGroup> KDGanttView::taskLinkGroups() const
2501{
2502 return myTaskLinkGroupList;
2503}
2504
2505
2513bool KDGanttView::loadXML( const TQDomDocument& doc )
2514{
2515 TQDomElement docRoot = doc.documentElement(); // ChartParams element
2516 TQDomNode node = docRoot.firstChild();
2517 while( !node.isNull() ) {
2518 TQDomElement element = node.toElement();
2519 if( !element.isNull() ) { // was really an element
2520 TQString tagName = element.tagName();
2521 if( tagName == "ShowLegend" ) {
2522 bool value;
2523 if( KDGanttXML::readBoolNode( element, value ) )
2524 setShowLegend( value );
2525 } else if( tagName == "ShowLegendButton" ) {
2526 bool value;
2527 if( KDGanttXML::readBoolNode( element, value ) )
2528 setShowLegendButton( value );
2529 } else if( tagName == "LegendIsDockWindow" ) {
2530 bool value;
2531 if( KDGanttXML::readBoolNode( element, value ) )
2532 setLegendIsDoctwindow( value );
2533 } else if( tagName == "ShowListView" ) {
2534 bool value;
2535 if( KDGanttXML::readBoolNode( element, value ) )
2536 setShowListView( value );
2537 } else if( tagName == "ShowHeader" ) {
2538 bool value;
2539 if( KDGanttXML::readBoolNode( element, value ) )
2540 setHeaderVisible( value );
2541 } else if( tagName == "ShowTaskLinks" ) {
2542 bool value;
2543 if( KDGanttXML::readBoolNode( element, value ) )
2544 setShowTaskLinks( value );
2545 } else if( tagName == "EditorEnabled" ) {
2546 bool value;
2547 if( KDGanttXML::readBoolNode( element, value ) )
2548 setEditorEnabled( value );
2549 } else if( tagName == "DisplayEmptyTasksAsLine" ) {
2550 bool value;
2551 if( KDGanttXML::readBoolNode( element, value ) )
2553 } else if( tagName == "GlobalFont" ) {
2554 TQFont font;
2555 if( KDGanttXML::readFontNode( element, font ) )
2556 setFont( font );
2557 } else if( tagName == "HorizonStart" ) {
2558 TQDateTime value;
2559 if( KDGanttXML::readDateTimeNode( element, value ) )
2560 setHorizonStart( value );
2561 } else if( tagName == "HorizonEnd" ) {
2562 TQDateTime value;
2563 if( KDGanttXML::readDateTimeNode( element, value ) )
2564 setHorizonEnd( value );
2565 } else if( tagName == "Scale" ) {
2566 TQString value;
2567 if( KDGanttXML::readStringNode( element, value ) )
2568 setScale( stringToScale( value ) );
2569 } else if( tagName == "MinimumScale" ) {
2570 TQString value;
2571 if( KDGanttXML::readStringNode( element, value ) )
2572 setMinimumScale( stringToScale( value ) );
2573 } else if( tagName == "MaximumScale" ) {
2574 TQString value;
2575 if( KDGanttXML::readStringNode( element, value ) )
2576 setMaximumScale( stringToScale( value ) );
2577 } else if( tagName == "YearFormat" ) {
2578 TQString value;
2579 if( KDGanttXML::readStringNode( element, value ) )
2580 setYearFormat( stringToYearFormat( value ) );
2581 } else if( tagName == "HourFormat" ) {
2582 TQString value;
2583 if( KDGanttXML::readStringNode( element, value ) )
2584 setHourFormat( stringToHourFormat( value ) );
2585 } else if( tagName == "ShowMinorTicks" ) {
2586 bool value;
2587 if( KDGanttXML::readBoolNode( element, value ) )
2588 setShowMinorTicks( value );
2589 } else if( tagName == "ShowMajorTicks" ) {
2590 bool value;
2591 if( KDGanttXML::readBoolNode( element, value ) )
2592 setShowMajorTicks( value );
2593 } else if( tagName == "DragEnabled" ) {
2594 bool value;
2595 if( KDGanttXML::readBoolNode( element, value ) )
2596 setDragEnabled( value );
2597 } else if( tagName == "DropEnabled" ) {
2598 bool value;
2599 if( KDGanttXML::readBoolNode( element, value ) )
2600 setDropEnabled( value );
2601 } else if( tagName == "CalendarMode" ) {
2602 bool value;
2603 if( KDGanttXML::readBoolNode( element, value ) )
2604 setCalendarMode( value );
2605 } else if( tagName == "Editable" ) {
2606 bool value;
2607 if( KDGanttXML::readBoolNode( element, value ) )
2608 setEditable( value );
2609 } else if( tagName == "TextColor" ) {
2610 TQColor value;
2611 if( KDGanttXML::readColorNode( element, value ) )
2612 setTextColor( value );
2613 } else if( tagName == "MajorScaleCount" ) {
2614 int value;
2615 if( KDGanttXML::readIntNode( element, value ) )
2616 setMajorScaleCount( value );
2617 } else if( tagName == "MinorScaleCount" ) {
2618 int value;
2619 if( KDGanttXML::readIntNode( element, value ) )
2620 setMinorScaleCount( value );
2621 } else if( tagName == "AutoScaleMinorTickCount" ) {
2622 int value;
2623 if( KDGanttXML::readIntNode( element, value ) )
2625 } else if( tagName == "MinimumColumnWidth" ) {
2626 int value;
2627 if( KDGanttXML::readIntNode( element, value ) )
2628 setMinimumColumnWidth( value );
2629 } else if( tagName == "GanttMaximumWidth" ) {
2630 int value;
2631 if( KDGanttXML::readIntNode( element, value ) )
2632 setGanttMaximumWidth( value );
2633 } else if( tagName == "NoInformationBrush" ) {
2634 TQBrush value;
2635 if( KDGanttXML::readBrushNode( element, value ) )
2636 setNoInformationBrush( value );
2637 } else if( tagName == "GanttViewBackgroundColor" ) {
2638 TQColor value;
2639 if( KDGanttXML::readColorNode( element, value ) )
2640 setGvBackgroundColor( value );
2641 } else if( tagName == "ListViewBackgroundColor" ) {
2642 TQColor value;
2643 if( KDGanttXML::readColorNode( element, value ) )
2644 setLvBackgroundColor( value );
2645 } else if( tagName == "TimeHeaderBackgroundColor" ) {
2646 TQColor value;
2647 if( KDGanttXML::readColorNode( element, value ) )
2649 } else if( tagName == "LegendHeaderBackgroundColor" ) {
2650 TQColor value;
2651 if( KDGanttXML::readColorNode( element, value ) )
2653 } else if( tagName == "WeekendBackgroundColor" ) {
2654 TQColor value;
2655 if( KDGanttXML::readColorNode( element, value ) )
2657 } else if( tagName == "WeekdayBackgroundColor" ) {
2658 TQDomNode node = element.firstChild();
2659 int day = 0;
2660 TQColor color;
2661 while( !node.isNull() ) {
2662 TQDomElement element = node.toElement();
2663 if( !element.isNull() ) { // was really an elemente
2664 TQString tagName = element.tagName();
2665 if( tagName == "Day" ) {
2666 int value;
2667 if( KDGanttXML::readIntNode( element, value ) )
2668 day = value;
2669 } else if( tagName == "Color" ) {
2670 TQColor value;
2671 if( KDGanttXML::readColorNode( element, value ) )
2672 color = value;
2673 } else {
2674 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2675 Q_ASSERT( false );
2676 }
2677 }
2678 node = node.nextSibling();
2679 }
2680
2681 if( day && color.isValid() )
2682 setWeekdayBackgroundColor( color, day );
2683 } else if( tagName == "WeekendDays" ) {
2684 TQString startString = element.attribute( "Start" );
2685 TQString endString = element.attribute( "End" );
2686 bool startOk = false, endOk = false;
2687 int start = startString.toInt( &startOk );
2688 int end = startString.toInt( &endOk );
2689 if( startOk && endOk )
2690 setWeekendDays( start, end );
2691 } else if( tagName == "ZoomFactor" ) {
2692 double value;
2693 if( KDGanttXML::readDoubleNode( element, value ) )
2694 setZoomFactor( value, true );
2695 } else if( tagName == "ShowHeaderPopupMenu" ) {
2696 bool value;
2697 if( KDGanttXML::readBoolNode( element, value ) )
2698 setShowHeaderPopupMenu( value );
2699 } else if( tagName == "ShowTimeTablePopupMenu" ) {
2700 bool value;
2701 if( KDGanttXML::readBoolNode( element, value ) )
2703 } else if( tagName == "Shapes" ) {
2704 TQDomNode node = element.firstChild();
2705 bool undefinedShape = false;
2706 while( !node.isNull() ) {
2707 TQDomElement element = node.toElement();
2708 if( !element.isNull() ) { // was really an elemente
2709 TQString tagName = element.tagName();
2710 if( tagName == "Event" ) {
2711 KDGanttViewItem::Shape startShape, middleShape, endShape;
2712 startShape = KDGanttViewItem::TriangleDown;
2713 middleShape = KDGanttViewItem::TriangleDown;
2714 endShape = KDGanttViewItem::TriangleDown;
2715 TQDomNode node = element.firstChild();
2716 while( !node.isNull() ) {
2717 TQDomElement element = node.toElement();
2718 if( !element.isNull() ) { // was really an elemente
2719 TQString tagName = element.tagName();
2720 if( tagName == "Start" ) {
2721 TQString value;
2722 if( KDGanttXML::readStringNode( element, value ) )
2723 startShape = KDGanttViewItem::stringToShape( value );
2724 if ( value == "Undefined" )
2725 undefinedShape = true;
2726 } else if( tagName == "Middle" ) {
2727 TQString value;
2728 if( KDGanttXML::readStringNode( element, value ) )
2729 middleShape = KDGanttViewItem::stringToShape( value );
2730 if ( value == "Undefined" )
2731 undefinedShape = true;
2732 } else if( tagName == "End" ) {
2733 TQString value;
2734 if( KDGanttXML::readStringNode( element, value ) )
2735 endShape = KDGanttViewItem::stringToShape( value );
2736 if ( value == "Undefined" )
2737 undefinedShape = true;
2738 } else {
2739 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2740 Q_ASSERT( false );
2741 }
2742 }
2743 node = node.nextSibling();
2744 }
2745 if ( ! undefinedShape )
2746 setShapes( KDGanttViewItem::Event, startShape,
2747 middleShape, endShape, false );
2748 undefinedShape = false;
2749 } else if( tagName == "Task" ) {
2750 KDGanttViewItem::Shape startShape, middleShape, endShape;
2751 startShape = KDGanttViewItem::TriangleDown;
2752 middleShape = KDGanttViewItem::TriangleDown;
2753 endShape = KDGanttViewItem::TriangleDown;
2754 TQDomNode node = element.firstChild();
2755 while( !node.isNull()) {
2756 TQDomElement element = node.toElement();
2757 if( !element.isNull() ) { // was really an elemente
2758 TQString tagName = element.tagName();
2759 if( tagName == "Start" ) {
2760 TQString value;
2761 if( KDGanttXML::readStringNode( element, value ) )
2762 startShape = KDGanttViewItem::stringToShape( value );
2763 if ( value == "Undefined" )
2764 undefinedShape = true;
2765 } else if( tagName == "Middle" ) {
2766 TQString value;
2767 if( KDGanttXML::readStringNode( element, value ) )
2768 middleShape = KDGanttViewItem::stringToShape( value );
2769 if ( value == "Undefined" )
2770 undefinedShape = true;
2771 } else if( tagName == "End" ) {
2772 TQString value;
2773 if( KDGanttXML::readStringNode( element, value ) )
2774 endShape = KDGanttViewItem::stringToShape( value );
2775 if ( value == "Undefined" )
2776 undefinedShape = true;
2777 } else {
2778 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2779 Q_ASSERT( false );
2780 }
2781 }
2782 node = node.nextSibling();
2783 }
2784 if ( ! undefinedShape )
2785 setShapes( KDGanttViewItem::Task, startShape, middleShape, endShape, false );
2786 undefinedShape = false;
2787 } else if( tagName == "Summary" ) {
2788 KDGanttViewItem::Shape startShape, middleShape, endShape;
2789 startShape = KDGanttViewItem::TriangleDown;
2790 middleShape = KDGanttViewItem::TriangleDown;
2791 endShape = KDGanttViewItem::TriangleDown;
2792 TQDomNode node = element.firstChild();
2793 while( !node.isNull() ) {
2794 TQDomElement element = node.toElement();
2795 if( !element.isNull() ) { // was really an elemente
2796 TQString tagName = element.tagName();
2797 if( tagName == "Start" ) {
2798 TQString value;
2799 if( KDGanttXML::readStringNode( element, value ) )
2800 startShape = KDGanttViewItem::stringToShape( value );
2801 if ( value == "Undefined" )
2802 undefinedShape = true;
2803 } else if( tagName == "Middle" ) {
2804 TQString value;
2805 if( KDGanttXML::readStringNode( element, value ) )
2806 middleShape = KDGanttViewItem::stringToShape( value );
2807 if ( value == "Undefined" )
2808 undefinedShape = true;
2809 } else if( tagName == "End" ) {
2810 TQString value;
2811 if( KDGanttXML::readStringNode( element, value ) )
2812 endShape = KDGanttViewItem::stringToShape( value );
2813 if ( value == "Undefined" )
2814 undefinedShape = true;
2815 } else {
2816 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2817 Q_ASSERT( false );
2818 }
2819 }
2820 node = node.nextSibling();
2821 }
2822 if ( ! undefinedShape )
2823 setShapes( KDGanttViewItem::Summary, startShape,
2824 middleShape, endShape, false );
2825 undefinedShape = false;
2826 } else {
2827 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2828 Q_ASSERT( false );
2829 }
2830 }
2831 node = node.nextSibling();
2832 }
2833 } else if( tagName == "Colors" ) {
2834 TQDomNode node = element.firstChild();
2835 while( !node.isNull()) {
2836 TQDomElement element = node.toElement();
2837 if( !element.isNull() ) { // was really an elemente
2838 TQString tagName = element.tagName();
2839 if( tagName == "Event" ) {
2840 TQColor startColor, middleColor, endColor;
2841 TQDomNode node = element.firstChild();
2842 while( !node.isNull() ) {
2843 TQDomElement element = node.toElement();
2844 if( !element.isNull() ) { // was really an elemente
2845 TQString tagName = element.tagName();
2846 if( tagName == "Start" ) {
2847 TQColor value;
2848 if( KDGanttXML::readColorNode( element, value ) )
2849 startColor = value;
2850 } else if( tagName == "Middle" ) {
2851 TQColor value;
2852 if( KDGanttXML::readColorNode( element, value ) )
2853 middleColor = value;
2854 } else if( tagName == "End" ) {
2855 TQColor value;
2856 if( KDGanttXML::readColorNode( element, value ) )
2857 endColor = value;
2858 } else {
2859 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2860 Q_ASSERT( false );
2861 }
2862 }
2863 node = node.nextSibling();
2864 }
2865 setColors( KDGanttViewItem::Event, startColor,
2866 middleColor, endColor, false );
2867 } else if( tagName == "Task" ) {
2868 TQColor startColor, middleColor, endColor;
2869 TQDomNode node = element.firstChild();
2870 while( !node.isNull() ) {
2871 TQDomElement element = node.toElement();
2872 if( !element.isNull() ) { // was really an elemente
2873 TQString tagName = element.tagName();
2874 if( tagName == "Start" ) {
2875 TQColor value;
2876 if( KDGanttXML::readColorNode( element, value ) )
2877 startColor = value;
2878 } else if( tagName == "Middle" ) {
2879 TQColor value;
2880 if( KDGanttXML::readColorNode( element, value ) )
2881 middleColor = value;
2882 } else if( tagName == "End" ) {
2883 TQColor value;
2884 if( KDGanttXML::readColorNode( element, value ) )
2885 endColor = value;
2886 } else {
2887 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2888 Q_ASSERT( false );
2889 }
2890 }
2891 node = node.nextSibling();
2892 }
2893 setColors( KDGanttViewItem::Task, startColor,
2894 middleColor, endColor, false );
2895 } else if( tagName == "Summary" ) {
2896 TQColor startColor, middleColor, endColor;
2897 TQDomNode node = element.firstChild();
2898 while( !node.isNull() ) {
2899 TQDomElement element = node.toElement();
2900 if( !element.isNull() ) { // was really an elemente
2901 TQString tagName = element.tagName();
2902 if( tagName == "Start" ) {
2903 TQColor value;
2904 if( KDGanttXML::readColorNode( element, value ) )
2905 startColor = value;
2906 } else if( tagName == "Middle" ) {
2907 TQColor value;
2908 if( KDGanttXML::readColorNode( element, value ) )
2909 middleColor = value;
2910 } else if( tagName == "End" ) {
2911 TQColor value;
2912 if( KDGanttXML::readColorNode( element, value ) )
2913 endColor = value;
2914 } else {
2915 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2916 Q_ASSERT( false );
2917 }
2918 }
2919 node = node.nextSibling();
2920 }
2921 setColors( KDGanttViewItem::Summary, startColor,
2922 middleColor, endColor , false);
2923 } else {
2924 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2925 Q_ASSERT( false );
2926 }
2927 }
2928 node = node.nextSibling();
2929 }
2930 } else if( tagName == "DefaultColors" ) {
2931 TQDomNode node = element.firstChild();
2932 while( !node.isNull() ) {
2933 TQDomElement element = node.toElement();
2934 if( !element.isNull() ) { // was really an element
2935 TQString tagName = element.tagName();
2936 if( tagName == "Event" ) {
2937 TQColor value;
2938 if( KDGanttXML::readColorNode( element, value ) )
2939 setDefaultColor( KDGanttViewItem::Event,
2940 value, false );
2941 } else if( tagName == "Task" ) {
2942 TQColor value;
2943 if( KDGanttXML::readColorNode( element, value ) )
2944 setDefaultColor( KDGanttViewItem::Task,
2945 value, false );
2946 } else if( tagName == "Summary" ) {
2947 TQColor value;
2948 if( KDGanttXML::readColorNode( element, value ) )
2949 setDefaultColor( KDGanttViewItem::Summary,
2950 value , false);
2951 } else {
2952 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2953 Q_ASSERT( false );
2954 }
2955 }
2956
2957 node = node.nextSibling();
2958 }
2959 } else if( tagName == "HighlightColors" ) {
2960 TQDomNode node = element.firstChild();
2961 while( !node.isNull() ) {
2962 TQDomElement element = node.toElement();
2963 if( !element.isNull() ) { // was really an elemente
2964 TQString tagName = element.tagName();
2965 if( tagName == "Event" ) {
2966 TQColor startColor, middleColor, endColor;
2967 TQDomNode node = element.firstChild();
2968 while( !node.isNull() ) {
2969 TQDomElement element = node.toElement();
2970 if( !element.isNull() ) { // was really an elemente
2971 TQString tagName = element.tagName();
2972 if( tagName == "Start" ) {
2973 TQColor value;
2974 if( KDGanttXML::readColorNode( element, value ) )
2975 startColor = value;
2976 } else if( tagName == "Middle" ) {
2977 TQColor value;
2978 if( KDGanttXML::readColorNode( element, value ) )
2979 middleColor = value;
2980 } else if( tagName == "End" ) {
2981 TQColor value;
2982 if( KDGanttXML::readColorNode( element, value ) )
2983 endColor = value;
2984 } else {
2985 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
2986 Q_ASSERT( false );
2987 }
2988 }
2989 node = node.nextSibling();
2990 }
2991 setHighlightColors( KDGanttViewItem::Event,
2992 startColor,
2993 middleColor, endColor, false );
2994 } else if( tagName == "Task" ) {
2995 TQColor startColor, middleColor, endColor;
2996 TQDomNode node = element.firstChild();
2997 while( !node.isNull() ) {
2998 TQDomElement element = node.toElement();
2999 if( !element.isNull() ) { // was really an elemente
3000 TQString tagName = element.tagName();
3001 if( tagName == "Start" ) {
3002 TQColor value;
3003 if( KDGanttXML::readColorNode( element, value ) )
3004 startColor = value;
3005 } else if( tagName == "Middle" ) {
3006 TQColor value;
3007 if( KDGanttXML::readColorNode( element, value ) )
3008 middleColor = value;
3009 } else if( tagName == "End" ) {
3010 TQColor value;
3011 if( KDGanttXML::readColorNode( element, value ) )
3012 endColor = value;
3013 } else {
3014 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3015 Q_ASSERT( false );
3016 }
3017 }
3018 node = node.nextSibling();
3019 }
3020 setHighlightColors( KDGanttViewItem::Task,
3021 startColor,
3022 middleColor, endColor , false);
3023 } else if( tagName == "Summary" ) {
3024 TQColor startColor, middleColor, endColor;
3025 TQDomNode node = element.firstChild();
3026 while( !node.isNull() ) {
3027 TQDomElement element = node.toElement();
3028 if( !element.isNull() ) { // was really an elemente
3029 TQString tagName = element.tagName();
3030 if( tagName == "Start" ) {
3031 TQColor value;
3032 if( KDGanttXML::readColorNode( element, value ) )
3033 startColor = value;
3034 } else if( tagName == "Middle" ) {
3035 TQColor value;
3036 if( KDGanttXML::readColorNode( element, value ) )
3037 middleColor = value;
3038 } else if( tagName == "End" ) {
3039 TQColor value;
3040 if( KDGanttXML::readColorNode( element, value ) )
3041 endColor = value;
3042 } else {
3043 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3044 Q_ASSERT( false );
3045 }
3046 }
3047 node = node.nextSibling();
3048 }
3049 setHighlightColors( KDGanttViewItem::Summary,
3050 startColor,
3051 middleColor, endColor, false );
3052 } else {
3053 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3054 Q_ASSERT( false );
3055 }
3056 }
3057 node = node.nextSibling();
3058 }
3059 } else if( tagName == "DefaultHighlightColors" ) {
3060 TQDomNode node = element.firstChild();
3061 while( !node.isNull() ) {
3062 TQDomElement element = node.toElement();
3063 if( !element.isNull() ) { // was really an element
3064 TQString tagName = element.tagName();
3065 if( tagName == "Event" ) {
3066 TQColor value;
3067 if( KDGanttXML::readColorNode( element, value ) )
3068 setDefaultHighlightColor( KDGanttViewItem::Event,
3069 value , false);
3070 } else if( tagName == "Task" ) {
3071 TQColor value;
3072 if( KDGanttXML::readColorNode( element, value ) )
3073 setDefaultHighlightColor( KDGanttViewItem::Task,
3074 value, false );
3075 } else if( tagName == "Summary" ) {
3076 TQColor value;
3077 if( KDGanttXML::readColorNode( element, value ) )
3078 setDefaultHighlightColor( KDGanttViewItem::Summary,
3079 value, false );
3080 } else {
3081 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3082 Q_ASSERT( false );
3083 }
3084 }
3085
3086 node = node.nextSibling();
3087 }
3088 } else if( tagName == "Items" ) {
3089 TQDomNode node = element.firstChild();
3090 KDGanttViewItem* previous = 0;
3091 while( !node.isNull() ) {
3092 TQDomElement element = node.toElement();
3093 if( !element.isNull() ) { // was really an element
3094 TQString tagName = element.tagName();
3095 if( tagName == "Item" ) {
3096 KDGanttViewItem* newItem;
3097 if( previous )
3098 newItem =
3100 previous,
3101 element );
3102 else
3103 newItem =
3105 element );
3106 previous = newItem;
3107 } else {
3108 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3109 Q_ASSERT( false );
3110 }
3111 }
3112
3113 node = node.nextSibling();
3114 }
3115 } else if( tagName == "TaskLinks" ) {
3116 TQDomNode node = element.firstChild();
3117 while( !node.isNull() ) {
3118 TQDomElement element = node.toElement();
3119 if( !element.isNull() ) { // was really an element
3120 TQString tagName = element.tagName();
3121 if( tagName == "TaskLink" )
3123 else {
3124 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3125 Q_ASSERT( false );
3126 }
3127 }
3128
3129 node = node.nextSibling();
3130 }
3131 } else if( tagName == "TaskLinkGroups" ) {
3132 TQDomNode node = element.firstChild();
3133 while( !node.isNull() ) {
3134 TQDomElement element = node.toElement();
3135 if( !element.isNull() ) { // was really an element
3136 TQString tagName = element.tagName();
3137 if( tagName == "TaskLink" )
3139 } else {
3140 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3141 Q_ASSERT( false );
3142 }
3143
3144 node = node.nextSibling();
3145 }
3146 } else if( tagName == "ColumnBackgroundColors" ) {
3147 TQDomNode node = element.firstChild();
3148 while( !node.isNull() ) {
3149 TQDomElement element = node.toElement();
3150 if( !element.isNull() ) { // was really an element
3151 TQString tagName = element.tagName();
3152 if( tagName == "ColumnBackgroundColor" ) {
3153 TQDomNode node = element.firstChild();
3154 TQDateTime dateTime;
3155 TQColor color;
3156 while( !node.isNull() ) {
3157 TQDomElement element = node.toElement();
3158 if( !element.isNull() ) { // was
3159 // really an
3160 // element
3161 TQString tagName = element.tagName();
3162 if( tagName == "DateTime" ) {
3163 TQDateTime value;
3164 if( KDGanttXML::readDateTimeNode( element, value ) )
3165 dateTime = value;
3166 } else if( tagName == "Color" ) {
3167 TQColor value;
3168 if( KDGanttXML::readColorNode( element, value ) )
3169 color = value;
3170 } else {
3171 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3172 Q_ASSERT( false );
3173 }
3174 }
3175
3176 node = node.nextSibling();
3177 }
3178 setColumnBackgroundColor( dateTime, color );
3179 } else {
3180 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3181 Q_ASSERT( false );
3182 }
3183 }
3184 node = node.nextSibling();
3185 }
3186 } else if( tagName == "LegendItems" ) {
3187 clearLegend();
3188 TQDomNode node = element.firstChild();
3189 while( !node.isNull() ) {
3190 TQDomElement element = node.toElement();
3191 if( !element.isNull() ) { // was really an element
3192 TQString tagName = element.tagName();
3193 if( tagName == "LegendItem" ) {
3194 KDGanttViewItem::Shape tempLegendShape;
3195 tempLegendShape = KDGanttViewItem::TriangleDown;
3196 TQColor tempLegendColor;
3197 TQString tempLegendString;
3198 bool ok = true;
3199 TQDomNode node = element.firstChild();
3200 while( !node.isNull() ) {
3201 TQDomElement element = node.toElement();
3202 if( !element.isNull() ) { // was really an element
3203 TQString tagName = element.tagName();
3204 if( tagName == "Shape" ) {
3205 TQString value;
3206 if( KDGanttXML::readStringNode( element, value ) )
3207 tempLegendShape = KDGanttViewItem::stringToShape( value );
3208 else
3209 ok = false;
3210 } else if( tagName == "Color" ) {
3211 TQColor value;
3212 if( KDGanttXML::readColorNode( element, value ) )
3213 tempLegendColor = value;
3214 else
3215 ok = false;
3216 } else if( tagName == "Text" ) {
3217 TQString value;
3218 if( KDGanttXML::readStringNode( element, value ) )
3219 tempLegendString = value;
3220 else
3221 ok = false;
3222 } else {
3223 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3224 Q_ASSERT( false );
3225 }
3226 }
3227 node = node.nextSibling();
3228 }
3229 if( ok ) {
3230 addLegendItem( tempLegendShape,
3231 tempLegendColor,
3232 tempLegendString );
3233 tqDebug( "Adding legend item %s", tempLegendString.latin1() );
3234 }
3235 } else {
3236 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3237 Q_ASSERT( false );
3238 }
3239 }
3240 node = node.nextSibling();
3241 }
3242 } else {
3243 tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
3244 Q_ASSERT( false );
3245 }
3246 }
3247
3248 node = node.nextSibling();
3249 } // while
3250 return true; /* FIXME: Do real error-reporting. The ASSERT's should be "return false" stmnts */
3251} // method
3252
3253
3262TQDomDocument KDGanttView::saveXML( bool withPI ) const
3263{
3264 // Create an inital DOM document
3265 TQString docstart = "<GanttView/>";
3266
3267 TQDomDocument doc( "GanttView" );
3268 doc.setContent( docstart );
3269 if( withPI ) {
3270 TQDomProcessingInstruction pin = doc.createProcessingInstruction( "kdgantt", "version=\"1.0\" encoding=\"UTF-8\"" ) ;
3271 doc.appendChild ( pin );
3272 }
3273
3274 TQDomElement docRoot = doc.documentElement();
3275 docRoot.setAttribute( "xmlns", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
3276 docRoot.setAttribute( "xmlns:xsi", "http://www.w3.org/2000/10/XMLSchema-instance" );
3277 docRoot.setAttribute( "xsi:schemaLocation", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
3278
3279 // the ShowLegend element
3280 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegend", showLegend() );
3281
3282 // the ShowLegendButton element
3283 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegendButton",
3284 showLegendButton() );
3285
3286 // the LegendIsDockWindow element
3287 KDGanttXML::createBoolNode( doc, docRoot, "LegendIsDockWindow",
3289
3290 // the ShowListView element
3291 KDGanttXML::createBoolNode( doc, docRoot, "ShowListView", showListView() );
3292
3293 // the ShowHeader element
3294 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeader", headerVisible() );
3295
3296 // the ShowTaskLinks element
3297 KDGanttXML::createBoolNode( doc, docRoot, "ShowTaskLinks", showTaskLinks() );
3298
3299 // the EditorEnabled element
3300 KDGanttXML::createBoolNode( doc, docRoot, "EditorEnabled", editorEnabled() );
3301
3302 // the global font element
3303 KDGanttXML::createFontNode( doc, docRoot, "GlobalFont", font() );
3304
3305 // the DisplayEmptyTasksAsLine element
3306 KDGanttXML::createBoolNode( doc, docRoot, "DisplayEmptyTasksAsLine",
3308
3309 // the HorizonStart element
3310 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonStart", horizonStart() );
3311
3312 // the HorizonEnd element
3313 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonEnd", horizonEnd() );
3314
3315 // the Scale, MinimumScale, MaximumScale elements
3316 KDGanttXML::createStringNode( doc, docRoot, "Scale", scaleToString( scale() ) );
3317 KDGanttXML::createStringNode( doc, docRoot, "MinimumScale",
3318 scaleToString( minimumScale() ) );
3319 KDGanttXML::createStringNode( doc, docRoot, "MaximumScale",
3320 scaleToString( maximumScale() ) );
3321
3322 // the YearFormat element
3323 KDGanttXML::createStringNode( doc, docRoot, "YearFormat",
3324 yearFormatToString( yearFormat() ) );
3325
3326 // the HourFormat element
3327 KDGanttXML::createStringNode( doc, docRoot, "HourFormat",
3328 hourFormatToString( hourFormat() ) );
3329
3330 // the ShowMinorTicks element
3331 KDGanttXML::createBoolNode( doc, docRoot, "ShowMinorTicks", showMinorTicks() );
3332
3333 // the ShowMajorTicks element
3334 KDGanttXML::createBoolNode( doc, docRoot, "ShowMajorTicks", showMajorTicks() );
3335
3336 // the Editable element
3337 KDGanttXML::createBoolNode( doc, docRoot, "Editable", editable() );
3338
3339 // the TextColor element
3340 KDGanttXML::createColorNode( doc, docRoot, "TextColor", textColor() );
3341
3342 // the MajorScaleCount element
3343 KDGanttXML::createIntNode( doc, docRoot, "MajorScaleCount", majorScaleCount() );
3344
3345 // the MinorScaleCount element
3346 KDGanttXML::createIntNode( doc, docRoot, "MinorScaleCount", minorScaleCount() );
3347
3348 // the AutoScaleMinorTickCount element
3349 KDGanttXML::createIntNode( doc, docRoot, "AutoScaleMinorTickCount",
3351
3352 // the MinimumColumnWidth element
3353 KDGanttXML::createIntNode( doc, docRoot, "MinimumColumnWidth",
3355
3356 // the GanttMaximumWidth element
3357 KDGanttXML::createIntNode( doc, docRoot, "GanttMaximumWidth",
3359
3360 // the NoInformationBrush element
3361 KDGanttXML::createBrushNode( doc, docRoot, "NoInformationBrush",
3363
3364 // the GanttViewBackgroundColor element
3365 KDGanttXML::createColorNode( doc, docRoot, "GanttViewBackgroundColor",
3367
3368 // the ListViewBackgroundColor element
3369 KDGanttXML::createColorNode( doc, docRoot, "ListViewBackgroundColor",
3371
3372 // the TimeHeaderBackgroundColor element
3373 KDGanttXML::createColorNode( doc, docRoot, "TimeHeaderBackgroundColor",
3375
3376 // the LegendHeaderBackgroundColor element
3377 KDGanttXML::createColorNode( doc, docRoot, "LegendHeaderBackgroundColor",
3379
3380 // the WeekendBackgroundColor element
3381 KDGanttXML::createColorNode( doc, docRoot, "WeekendBackgroundColor",
3383
3384 // the WeekdayBackgroundColor elements
3385 for( int weekday = 1; weekday <= 7; weekday++ ) {
3386 TQColor color = weekdayBackgroundColor( weekday );
3387 if( color.isValid() ) {
3388 TQDomElement weekendBackgroundColorElement = doc.createElement( "WeekdayBackgroundColor" );
3389 docRoot.appendChild( weekendBackgroundColorElement );
3390 KDGanttXML::createIntNode( doc, weekendBackgroundColorElement,
3391 "Day", weekday );
3392 KDGanttXML::createColorNode( doc, weekendBackgroundColorElement,
3393 "Color", color );
3394 }
3395 }
3396
3397 // the WeekendDays element
3398 TQDomElement weekendDaysElement = doc.createElement( "WeekendDays" );
3399 docRoot.appendChild( weekendDaysElement );
3400 int weekendStart, weekendEnd;
3401 weekendDays( weekendStart, weekendEnd );
3402 weekendDaysElement.setAttribute( "Start", weekendStart );
3403 weekendDaysElement.setAttribute( "End", weekendStart );
3404
3405 // the ZoomFactor element
3406 KDGanttXML::createDoubleNode( doc, docRoot, "ZoomFactor",
3407 zoomFactor() );
3408
3409 // the ShowHeaderPopupMenu element
3410 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeaderPopupMenu",
3412
3413 // the ShowTimeTablePopupMenu element
3414 KDGanttXML::createBoolNode( doc, docRoot, "ShowTimeTablePopupMenu",
3416
3417 // the Shapes element
3418 TQDomElement shapesElement = doc.createElement( "Shapes" );
3419 docRoot.appendChild( shapesElement );
3420 TQDomElement shapesEventElement = doc.createElement( "Event" );
3421 shapesElement.appendChild( shapesEventElement );
3422 KDGanttViewItem::Shape start, middle, end;
3423 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
3424 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
3425 KDGanttViewItem::shapeToString( start ) );
3426 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
3427 KDGanttViewItem::shapeToString( middle ) );
3428 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
3429 KDGanttViewItem::shapeToString( end ) );
3430 } else {
3431 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
3432 "Undefined" );
3433 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
3434 "Undefined" );
3435 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
3436 "Undefined" );
3437 }
3438 TQDomElement shapesTaskElement = doc.createElement( "Task" );
3439 shapesElement.appendChild( shapesTaskElement );
3440 if( shapes( KDGanttViewItem::Task, start, middle, end ) ) {
3441 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
3442 KDGanttViewItem::shapeToString( start ) );
3443 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
3444 KDGanttViewItem::shapeToString( middle ) );
3445 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
3446 KDGanttViewItem::shapeToString( end ) );
3447 } else {
3448 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
3449 "Undefined" );
3450 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
3451 "Undefined" );
3452 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
3453 "Undefined" );
3454 }
3455 TQDomElement shapesSummaryElement = doc.createElement( "Summary" );
3456 shapesElement.appendChild( shapesSummaryElement );
3457 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
3458 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
3459 KDGanttViewItem::shapeToString( start ) );
3460 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
3461 KDGanttViewItem::shapeToString( middle ) );
3462 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
3463 KDGanttViewItem::shapeToString( end ) );
3464 } else {
3465 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
3466 "Undefined" );
3467 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
3468 "Undefined" );
3469 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
3470 "Undefined" );
3471 }
3472
3473 // the Colors element
3474 TQDomElement colorsElement = doc.createElement( "Colors" );
3475 docRoot.appendChild( colorsElement );
3476 TQDomElement colorsEventElement = doc.createElement( "Event" );
3477 colorsElement.appendChild( colorsEventElement );
3478 TQColor startColor, middleColor, endColor;
3479 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3480 KDGanttXML::createColorNode( doc, colorsEventElement, "Start", startColor );
3481 KDGanttXML::createColorNode( doc, colorsEventElement, "Middle", middleColor );
3482 KDGanttXML::createColorNode( doc, colorsEventElement, "End", endColor );
3483 TQDomElement colorsTaskElement = doc.createElement( "Task" );
3484 colorsElement.appendChild( colorsTaskElement );
3485 colors( KDGanttViewItem::Task, startColor, middleColor, endColor );
3486 KDGanttXML::createColorNode( doc, colorsTaskElement, "Start", startColor );
3487 KDGanttXML::createColorNode( doc, colorsTaskElement, "Middle", middleColor );
3488 KDGanttXML::createColorNode( doc, colorsTaskElement, "End", endColor );
3489 TQDomElement colorsSummaryElement = doc.createElement( "Summary" );
3490 colorsElement.appendChild( colorsSummaryElement );
3491 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3492 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Start", startColor );
3493 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Middle", middleColor );
3494 KDGanttXML::createColorNode( doc, colorsSummaryElement, "End", endColor );
3495
3496 // the DefaultColor element
3497 TQDomElement defaultColorsElement = doc.createElement( "DefaultColors" );
3498 docRoot.appendChild( defaultColorsElement );
3499 KDGanttXML::createColorNode( doc, defaultColorsElement, "Event",
3500 defaultColor( KDGanttViewItem::Event ) );
3501 KDGanttXML::createColorNode( doc, defaultColorsElement, "Task",
3502 defaultColor( KDGanttViewItem::Task ) );
3503 KDGanttXML::createColorNode( doc, defaultColorsElement, "Summary",
3504 defaultColor( KDGanttViewItem::Summary ) );
3505
3506
3507 // the HighlightColors element
3508 TQDomElement highlightColorsElement = doc.createElement( "HighlightColors" );
3509 docRoot.appendChild( highlightColorsElement );
3510 TQDomElement highlightColorsEventElement = doc.createElement( "Event" );
3511 highlightColorsElement.appendChild( highlightColorsEventElement );
3512 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3513 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Start", startColor );
3514 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Middle", middleColor );
3515 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "End", endColor );
3516 TQDomElement highlightColorsTaskElement = doc.createElement( "Task" );
3517 highlightColorsElement.appendChild( highlightColorsTaskElement );
3518 highlightColors( KDGanttViewItem::Task, startColor, middleColor, endColor );
3519 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Start", startColor );
3520 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Middle", middleColor );
3521 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "End", endColor );
3522 TQDomElement highlightColorsSummaryElement = doc.createElement( "Summary" );
3523 highlightColorsElement.appendChild( highlightColorsSummaryElement );
3524 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
3525 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
3526 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
3527 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
3528
3529
3530 /*
3531 if( highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor ) ) {
3532 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
3533 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
3534 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
3535 } else {
3536 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", TQColor() );
3537 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", TQColor() );
3538 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", TQColor() );
3539 }
3540 */
3541 // the DefaultHighlightColor element
3542 TQDomElement defaultHighlightColorsElement = doc.createElement( "DefaultHighlightColors" );
3543 docRoot.appendChild( defaultHighlightColorsElement );
3544 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Event",
3545 defaultHighlightColor( KDGanttViewItem::Event ) );
3546 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Task",
3547 defaultHighlightColor( KDGanttViewItem::Task ) );
3548 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Summary",
3549 defaultHighlightColor( KDGanttViewItem::Summary ) );
3550
3551
3552 // the Items element
3553 TQDomElement itemsElement = doc.createElement( "Items" );
3554 docRoot.appendChild( itemsElement );
3555 KDGanttViewItem* currentItem = firstChild();
3556 while( currentItem ) {
3557 currentItem->createNode( doc, itemsElement );
3558 currentItem = currentItem->nextSibling();
3559 }
3560
3561 // the TaskLinks element
3562 TQDomElement taskLinksElement = doc.createElement( "TaskLinks" );
3563 docRoot.appendChild( taskLinksElement );
3564 TQPtrList<KDGanttViewTaskLink> taskLinkList = taskLinks();
3565 KDGanttViewTaskLink* currentTL = 0;
3566 for( currentTL = taskLinkList.first(); currentTL;
3567 currentTL = taskLinkList.next() )
3568 currentTL->createNode( doc, taskLinksElement );
3569
3570 // the TaskLinkGroups element
3571 TQDomElement taskLinkGroupsElement = doc.createElement( "TaskLinkGroups" );
3572 docRoot.appendChild( taskLinkGroupsElement );
3573 TQPtrList<KDGanttViewTaskLinkGroup> taskLinkGroupList = taskLinkGroups();
3574 KDGanttViewTaskLinkGroup* currentTLG = 0;
3575 for( currentTLG = taskLinkGroupList.first(); currentTLG;
3576 currentTLG = taskLinkGroupList.next() )
3577 currentTLG->createNode( doc, taskLinkGroupsElement );
3578
3579 // the ColumnBackgroundColors element
3580 TQDomElement columnBackgroundColorsElement =
3581 doc.createElement( "ColumnBackgroundColors" );
3582 docRoot.appendChild( columnBackgroundColorsElement );
3583 KDTimeHeaderWidget::ColumnColorList ccList =
3584 myTimeHeader->columnBackgroundColorList();
3585 for( KDTimeHeaderWidget::ColumnColorList::iterator it = ccList.begin();
3586 it != ccList.end(); ++it ) {
3587 TQDomElement columnBackgroundColorElement =
3588 doc.createElement( "ColumnBackgroundColor" );
3589 columnBackgroundColorsElement.appendChild( columnBackgroundColorElement );
3590 KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
3591 "DateTime", (*it).datetime );
3592 KDGanttXML::createColorNode( doc, columnBackgroundColorElement,
3593 "Color", (*it).color );
3594 }
3595
3596 // the LegendItems element
3597 TQDomElement legendItemsElement =
3598 doc.createElement( "LegendItems" );
3599 docRoot.appendChild( legendItemsElement );
3600 legendItem* current;
3601 TQPtrListIterator<legendItem> lit( *myLegendItems );
3602 while( ( current = lit.current() ) ) {
3603 ++lit;
3604 TQDomElement legendItemElement = doc.createElement( "LegendItem" );
3605 legendItemsElement.appendChild( legendItemElement );
3606 KDGanttXML::createStringNode( doc, legendItemElement, "Shape",
3607 KDGanttViewItem::shapeToString( current->shape ) );
3608 KDGanttXML::createColorNode( doc, legendItemElement, "Color",
3609 current->color );
3610 KDGanttXML::createStringNode( doc, legendItemElement, "Text",
3611 current->text );
3612 }
3613
3614 // the DragEnabled element
3615 KDGanttXML::createBoolNode( doc, docRoot, "DragEnabled", isDragEnabled() );
3616
3617 // the DropEnabled element
3618 KDGanttXML::createBoolNode( doc, docRoot, "DropEnabled", isDropEnabled() );
3619
3620 // the CalendarMode element
3621 KDGanttXML::createBoolNode( doc, docRoot, "CalendarMode", calendarMode() );
3622
3623 return doc;
3624}
3625
3626
3627
3628TQString KDGanttView::scaleToString( Scale scale )
3629{
3630 switch( scale ) {
3631 case Minute:
3632 return "Minute";
3633 case Hour:
3634 return "Hour";
3635 case Day:
3636 return "Day";
3637 case Week:
3638 return "Week";
3639 case Month:
3640 return "Month";
3641 case Auto:
3642 return "Auto";
3643 }
3644 return "";
3645}
3646
3647
3648KDGanttView::Scale KDGanttView::stringToScale( const TQString& string )
3649{
3650 if( string == "Minute" )
3651 return Minute;
3652 else if( string == "Hour" )
3653 return Hour;
3654 else if( string == "Day" )
3655 return Day;
3656 else if( string == "Week" )
3657 return Week;
3658 else if( string == "Month" )
3659 return Month;
3660 else if( string == "Auto" )
3661 return Auto;
3662
3663 return Auto;
3664}
3665
3666
3667TQString KDGanttView::yearFormatToString( YearFormat format )
3668{
3669 switch( format ) {
3670 case FourDigit:
3671 return "FourDigit";
3672 case TwoDigit:
3673 return "TwoDigit";
3674 case TwoDigitApostrophe:
3675 return "TwoDigitApostrophe";
3676 case NoDate:
3677 return "NoDate";
3678 }
3679 return "";
3680}
3681
3682
3683KDGanttView::YearFormat KDGanttView::stringToYearFormat( const TQString& string )
3684{
3685 if( string == "FourDigit" )
3686 return FourDigit;
3687 else if( string == "TwoDigit" )
3688 return TwoDigit;
3689 else if( string == "TwoDigitApostrophe" )
3690 return TwoDigitApostrophe;
3691 else if( string == "NoDate" )
3692 return NoDate;
3693 else
3694 return FourDigit;
3695}
3696
3697
3698TQString KDGanttView::hourFormatToString( HourFormat format )
3699{
3700 switch( format ) {
3701 case Hour_12:
3702 return "Hour_12";
3703 case Hour_24:
3704 return "Hour_24";
3705 case Hour_24_FourDigit:
3706 return "Hour_24_FourDigit";
3707 }
3708 return "";
3709}
3710
3711
3712KDGanttView::HourFormat KDGanttView::stringToHourFormat( const TQString& string )
3713{
3714 if( string == "Hour_12" )
3715 return Hour_12;
3716 else if( string == "Hour_24" )
3717 return Hour_24;
3718 else
3719 return Hour_24;
3720}
3721
3722
3723void KDGanttView::addTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
3724{
3725
3726 if (myTaskLinkGroupList.isEmpty()) {
3727 myTaskLinkGroupList.append(group);
3728 return;
3729 }
3730 if (myTaskLinkGroupList.find(group) == -1)
3731 myTaskLinkGroupList.append(group);
3732}
3733
3734
3735void KDGanttView::removeTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
3736{
3737 myTaskLinkGroupList.remove(group);
3738}
3739
3740
3746void KDGanttView::editItem( KDGanttViewItem* item)
3747{
3748 if ( ! item )
3749 return;
3750 if ( editorEnabled() ) {
3751 if ( item->editable() ) {
3752 myItemAttributeDialog->reset( item );
3753 myItemAttributeDialog->show();
3754 }
3755 }
3756}
3757
3758
3770 const TQColor& shapeColor,
3771 const TQColor& backgroundColor, int itemSize)
3772{
3773 // 10 is a good value as size
3774 int size = itemSize+2;
3775 int hei = ( itemSize/3 ) / 2;
3776 TQPixmap p = TQPixmap( size+4, size+4 );
3777 p.fill( backgroundColor );
3778 TQPainter paint (&p);
3779 TQBrush b = TQBrush ( TQt::SolidPattern );
3780 b.setColor( shapeColor );
3781 paint.setBrush( b );
3782 TQPen pen( TQt::black, 1 ) ;
3783 paint.setPen( pen );
3784 switch (shape) {
3785 case KDGanttViewItem::TriangleDown:{
3786 TQPointArray arr = TQPointArray(3);
3787 arr.setPoint(0,-size/2,-hei);
3788 arr.setPoint(1,size/2,-hei);
3789 arr.setPoint(2,0,((size/2)-hei));
3790 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3791 paint.drawPolygon( arr );
3792 break;
3793 }
3794 case KDGanttViewItem::TriangleUp :{
3795 TQPointArray arr = TQPointArray(3);
3796 arr.setPoint(0,-size/2,hei);
3797 arr.setPoint(1,size/2,hei);
3798 arr.setPoint(2,0,(-size/2)+hei);
3799 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3800 paint.drawPolygon( arr );
3801 break;
3802 }
3803 case KDGanttViewItem::Diamond :{
3804 TQPointArray arr = TQPointArray(4);
3805 arr.setPoint(0,0,-size/2);
3806 arr.setPoint(1,size/2,0);
3807 arr.setPoint(2,0,size/2);
3808 arr.setPoint(3,-size/2,0);
3809 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3810 paint.drawPolygon( arr );
3811 break;
3812 }
3813 case KDGanttViewItem::Square :{
3814 TQPointArray arr = TQPointArray(4);
3815 arr.setPoint(0,-size/2,-size/2);
3816 arr.setPoint(1,size/2,-size/2);
3817 arr.setPoint(2,size/2,size/2);
3818 arr.setPoint(3,-size/2,size/2);
3819 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
3820 paint.drawPolygon( arr );
3821 break;
3822 }
3823 case KDGanttViewItem::Circle :{
3824 paint.drawEllipse( 2, 2, size, size);
3825 break;
3826 }
3827 }
3828 paint.end();
3829 return p;
3830}
3831
3832int KDGanttView::getIndex( KDGanttViewItem::Type type) const
3833{
3834 int index = -1;
3835 switch (type) {
3836 case (KDGanttViewItem::Event):
3837 index = 0;
3838 break;
3839 case (KDGanttViewItem::Task):
3840 index = 1;
3841 break;
3842 case (KDGanttViewItem::Summary):
3843 index = 2;
3844 break;
3845 }
3846 return index;
3847}
3848
3849
3850void KDGanttView::initDefaults()
3851{
3852 int i;
3853 // We have 3 item types. Set all undefined to true.
3854 for (i = 0;i<3;++i) {
3855 undefinedShape[i] = true;
3856 undefinedColor[i] = true;
3857 undefinedColorHL[i] = true;
3858 }
3859 // setting the default colors
3860 myDefaultColor [ getIndex( KDGanttViewItem::Event ) ] = TQt::blue; //event
3861 myDefaultColorHL [ getIndex( KDGanttViewItem::Event ) ] = TQt::red;
3862 myDefaultColor [ getIndex( KDGanttViewItem::Task ) ] = TQt::green;//task
3863 myDefaultColorHL [ getIndex( KDGanttViewItem::Task ) ] = TQt::red;
3864 myDefaultColor [ getIndex( KDGanttViewItem::Summary ) ] = TQt::cyan;//summary
3865 myDefaultColorHL [ getIndex( KDGanttViewItem::Summary ) ] = TQt::red;
3866
3867 // setting the default shape types
3868 // currently, we take for each item for all three shapes (start, middle, end) the same default shape
3869 for (i = 0;i<3;++i) {
3870 myDefaultShape [3*getIndex( KDGanttViewItem::Event )+ i] = KDGanttViewItem::Diamond; //event
3871 myDefaultShape [3*getIndex( KDGanttViewItem::Task ) +i] = KDGanttViewItem::Square; //task
3872 myDefaultShape [3*getIndex( KDGanttViewItem::Summary ) +i] = KDGanttViewItem::TriangleDown; //summary
3873
3874 }
3875}
3876
3877
3878
3882int KDGanttView::addColumn( const TQString& label, int width )
3883{
3884 return myListView->addColumn( label, width );
3885}
3886
3887
3891
3892int KDGanttView::addColumn( const TQIconSet& iconset, const TQString& label,
3893 int width )
3894{
3895 return myListView->addColumn( iconset, label, width );
3896}
3897
3898
3903{
3904 myListView->removeColumn( index );
3905}
3906
3907
3911KDGanttViewItem* KDGanttView::selectedItem() const
3912{
3913 return static_cast<KDGanttViewItem*>( myListView->selectedItem() );
3914}
3915
3916
3920void KDGanttView::setSelected( KDGanttViewItem* item, bool selected )
3921{
3922 myListView->setSelected( item, selected );
3923}
3924
3925
3938KDGanttViewItem* KDGanttView::getItemByName( const TQString& name ) const
3939{
3940 KDGanttViewItem* temp = firstChild(),* ret;
3941 while (temp != 0) {
3942 if ( (ret = temp->getChildByName( name ) ) )
3943 return ret;
3944 temp = temp->nextSibling();
3945 }
3946 return 0;
3947}
3948
3949
3961KDGanttViewItem* KDGanttView::getItemByListViewPos( const TQPoint& pos ) const
3962{
3963 return static_cast<KDGanttViewItem*>( myListView->itemAt(myListView->mapFromGlobal(pos) ));
3964}
3965
3966
3981KDGanttViewItem* KDGanttView::getItemByGanttViewPos( const TQPoint& pos ) const
3982{
3983 KDGanttViewItem* item;
3984 TQPoint local = myCanvasView->mapFromGlobal(pos);
3985
3986 TQCanvasItemList il = myTimeTable->collisions( myCanvasView->viewportToContents( local ));
3987 TQCanvasItemList::Iterator it;
3988 for ( it = il.begin(); it != il.end(); ++it ) {
3989 if ( myCanvasView->getType(*it) == Type_is_KDGanttViewItem) {
3990 item = myCanvasView->getItem(*it);
3991 if ( item->enabled() )
3992 return item;
3993 }
3994 }
3995 return 0;
3996}
3997
3998
4013KDGanttViewItem* KDGanttView::getItemAt( const TQPoint& pos, bool global ) const
4014{
4015 /* buggy code - commented out
4016 TQPoint myPos;
4017 if ( global )
4018 myPos = myListView->contentsToViewport( myListView->mapFromGlobal(pos) );
4019 else
4020 myPos = myListView->contentsToViewport( pos );
4021 return (KDGanttViewItem*) myListView->itemAt( myPos );
4022 */
4023
4024 KDGanttViewItem* item;
4025 KDGanttViewItem* retItem = 0;
4026 int y;
4027 if ( global )
4028 y = myCanvasView->mapFromGlobal(pos).y();
4029 else
4030 y = pos.y();
4031 item = firstChild();
4032 while ( item != 0 ) {
4033 int yc = item->itemPos();
4034 if ( yc <= y && y < yc + item->height()) {
4035 retItem = item;
4036 break;
4037 }
4038 item = item->itemBelow();
4039 }
4040 return retItem;
4041
4042}
4043
4044
4045void KDGanttView::addTickRight()
4046{
4047 if ( !mFixedHorizon && _enableAdding && myCanvasView->horizontalScrollBar()->value() == myCanvasView->horizontalScrollBar()->maxValue()) {
4048 //myCanvasView->horizontalScrollBar()->blockSignals( true );
4049 myTimeHeader->addTickRight();
4050 //myCanvasView->horizontalScrollBar()->blockSignals( false );
4051 myCanvasView->updateHorScrollBar();
4053 }
4054}
4055
4056
4057void KDGanttView::addTickLeft()
4058{
4059 if ( !mFixedHorizon && _enableAdding && myCanvasView->horizontalScrollBar()->value() == 0 ) {
4060 myCanvasView->horizontalScrollBar()->blockSignals( true );
4061 myTimeHeader->addTickLeft();
4062 myCanvasView->horizontalScrollBar()->blockSignals( false );
4064 }
4065}
4066
4067
4068void KDGanttView::enableAdding( int val )
4069{
4070 _enableAdding = ( val == 0 || val == myCanvasView->horizontalScrollBar()->maxValue());
4071}
4072
4073
4080{
4081 return myListView->childCount();
4082}
4083
4084
4089{
4090 bool block = myTimeTable->blockUpdating();
4091 myTimeTable->setBlockUpdating( true );
4092 myListView->clear();
4093 myTimeTable->setBlockUpdating( false );
4094 myTimeTable->updateMyContent();
4095 myTimeTable->setBlockUpdating( block );
4096}
4097
4098
4102void KDGanttView::slot_lvDropped(TQDropEvent* e, KDGanttViewItem* droppedItem, KDGanttViewItem* itemBelowMouse )
4103{
4104 emit dropped( e, droppedItem, itemBelowMouse);
4105}
4106
4111{
4112 return myListView->dragObject ();
4113}
4114
4115
4120{
4121 //myListView->pt_startDrag ();
4122}
4123
4124
4129{
4130 TQWidget::setPaletteBackgroundColor( col );
4131 timeHeaderSpacerWidget->setPaletteBackgroundColor( col );
4132}
4133
4134
4141void KDGanttView::setGvBackgroundColor ( const TQColor & c )
4142{
4143 myTimeTable->setBackgroundColor( c );
4144}
4145
4146
4154{
4155 myTimeHeader->setPaletteBackgroundColor( c );
4156 //rightWidget->setPaletteBackgroundColor( c );
4157 timeHeaderSpacerWidget->setPaletteBackgroundColor( c );
4158}
4159
4160
4168{
4169 myLegend->setPaletteBackgroundColor( c );
4170 leftWidget->setPaletteBackgroundColor( c );
4171}
4172
4173
4180void KDGanttView::setLvBackgroundColor ( const TQColor & c )
4181{
4182 myListView->viewport()->setPaletteBackgroundColor( c );
4183}
4184
4185
4193{
4194 return myListView->viewport()->paletteBackgroundColor( );
4195}
4196
4197
4205{
4206 return myTimeTable->backgroundColor( );
4207}
4208
4209
4217{
4218 return myTimeHeader->paletteBackgroundColor( );
4219}
4220
4221
4229{
4230 return myLegend->paletteBackgroundColor( );
4231}
4232
4233
4249{
4250 if ( w ) {
4251 w->reparent ( spacerLeft, 0, TQPoint(0,0) );
4252 }
4253}
4254
4255
4265{
4266 fDragEnabled = b;
4267 TQListViewItemIterator it( myListView );
4268 for ( ; it.current(); ++it ) {
4269 (( KDGanttViewItem* )it.current())->setDragEnabled(b);
4270 }
4271
4272}
4273
4274
4284{
4285 fDropEnabled = b;
4286
4287 //myListView->setAcceptDrops( b );
4288 TQListViewItemIterator it( myListView );
4289 for ( ; it.current(); ++it ) {
4290 (( KDGanttViewItem* )it.current())->setDropEnabled(b);
4291 }
4292}
4293
4294
4304{
4305 setDropEnabled( b );
4306 setDragEnabled( b );
4307}
4308
4309
4317{
4318 return fDragEnabled;
4319}
4320
4321
4329{
4330 return fDropEnabled;
4331}
4332
4333
4338{
4339 return isDragEnabled();
4340}
4341
4342
4347{
4348 return isDropEnabled();
4349}
4350
4351
4378bool KDGanttView::lvDropEvent ( TQDropEvent* e,
4379 KDGanttViewItem* droppedItem,
4380 KDGanttViewItem* itemBelowMouse )
4381{
4382 Q_UNUSED( e );
4383 Q_UNUSED( droppedItem );
4384 Q_UNUSED( itemBelowMouse );
4385
4386 // Example code for user defined behaviour:
4387 // we want to accept the usual drags and the drags of files, which may be
4388 // a saved Gantt file.
4389 // Please uncomment the following lines for this behaviour
4390 // You have to uncomment lines in lvDragMoveEvent() and llvDragEnterEvent() as well
4391
4392 // ************** begin example ************
4393 /*
4394 if ( TQUriDrag::canDecode( e ) ) {
4395 TQStrList lst;
4396 TQUriDrag::decode( e, lst );
4397 // we try the first file of icon-url-list
4398 TQString str = lst.at ( 0 );
4399 // remove file: at beginning of string
4400 str = str.right( str.length() - 5 );
4401 TQFileInfo info;
4402 info.setFile( str ) ;
4403 if ( info.isFile() ) {
4404 if (!TQMessageBox::information( this, "KDGantt Drag&Drop test",
4405 "Try to insert file: "+ str + " ?",
4406 "&Okay", "&Cancel",0,1 ) ) {
4407 TQFile file( str );
4408 // store current updating status
4409 bool uen = myTimeTable->blockUpdating();
4410 // block updating while insertion of items
4411 myTimeTable->setBlockUpdating();
4412 loadProject( &file ) ;
4413 // restore updating status and execute an update via setUpdateEnabled( true );
4414 if ( !uen )
4415 setUpdateEnabled( true );
4416 }
4417 }
4418 return true;
4419 }
4420 */
4421 // *********** end example ****************
4422 return false;
4423}
4424
4425
4442void KDGanttView::lvDragEnterEvent ( TQDragEnterEvent * e)
4443{
4444 // the standard behaviour:
4445 // accept drag enter events, if KDGanttViewItemDrag can decode the event
4446 // e->accept(KDGanttViewItemDrag::canDecode(e) );
4447
4449 e->accept( true);
4450 return;
4451 }
4452
4453 // example code for user defined behaviour:
4454 // we want to accecpt the usual drags and the drags of files, which may be
4455 // a saved Gantt file
4456 // Please uncomment the following lines for this behaviour
4457 // You have to uncomment lines in lvDragMoveEvent() and lvDropEvent () as well
4458
4459 // if ( TQUriDrag::canDecode( e ) ) {
4460 // e->accept(true);
4461 // return;
4462 // }
4463
4464 e->accept( false );
4465}
4466
4467
4496bool KDGanttView::lvDragMoveEvent ( TQDragMoveEvent* /*e*/,
4497 KDGanttViewItem* /* draggedItem*/,
4498 KDGanttViewItem* /*itemBelowMouse*/)
4499{
4500
4501 // Example code 1:
4502 // To generally block items to be inserted as root items, subclass KDGanttView
4503 // and reimplement this method with to following code uncommented:
4504
4505 // if ( !itemBelowMouse ) {
4506 // e->accept( false );
4507 // return true;
4508 //}
4509 //return false;
4510
4511 // Example code 2:
4512 // To allow the drags of files, which may be
4513 // a saved Gantt file, subclass KDGanttView
4514 // and reimplement this method with to following code uncommented:
4515
4516 // if ( TQUriDrag::canDecode( e ) ) {
4517 // e->accept(true);
4518 // return true;
4519 // }
4520
4521
4522 // normal behaviour - the internal drag move event handling should be executed
4523 return false;
4524}
4525
4526
4536void KDGanttView::lvStartDrag (KDGanttViewItem* item)
4537{
4538 TQDragObject* d = new KDGanttViewItemDrag(item, this, "itemdrag" );
4539 // call d->drag() to start the dragging
4540 // d->drag() returns true, if a move was requested as a drag
4541 // if a copy (by pressing the <Ctrl>-key) was performed, d->drag() returns false
4542 // In order to avoid starting drags for particular items, subclass KDGanttView
4543 // an reimplement this method.
4544 // insert here some code like
4545 // if ( item->parent() )
4546 // return;
4547 // This particular code will make it impossible to drag other items but root items.
4548 if ( d->drag() ) {
4549 delete item;
4550 }
4551}
4552
4553
4562{
4563 int sw = mySplitter->width();
4564 TQValueList<int> list;
4565 list.append(w);
4566 list.append(sw-w);
4567 mySplitter->setSizes( list );
4568}
4569
4570
4578{
4579 return leftWidget->width();
4580}
4581
4582
4592void KDGanttView::setLvVScrollBarMode( TQScrollView::ScrollBarMode m )
4593{
4594 myListView->setVScrollBarMode ( m );
4595}
4596
4597
4607void KDGanttView::setGvVScrollBarMode( TQScrollView::ScrollBarMode m )
4608{
4609 if ( m == TQScrollView::Auto )
4610 tqDebug("KDGanttView::setListViewVScrollBarMode: TQScrollView::Auto not supported. Nothing changed. ");
4611 else
4612 {
4613 myCanvasView->setVScrollBarMode ( m );
4614 if ( m == TQScrollView::AlwaysOn )
4615 timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
4616 else
4617 timeHeaderSpacerWidget->setFixedWidth( 0 );
4618 }
4619}
4620
4621
4622void KDGanttView::notifyEditdialog( KDGanttViewItem * item)
4623{
4624 if (myItemAttributeDialog->getItem() == item ) {
4625 myItemAttributeDialog->reset( 0 );
4626 }
4627}
4628
4637{
4638 myCanvasView->linkItemsEnabled = on;
4639 myCanvasView->autoScrollEnabled = true;
4640}
4641
4648{
4649 return myCanvasView->linkItemsEnabled;
4650}
4651
4660
4661
4669
4670
4685
4686
4693
4694
4701
4702
4709
4716
4723
4729
4736
4737
4743
4744
4751
4752
4759
4760
4767
4774
4782
4791
4797
4806
4814
4821
4822
4839
4840
4847
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 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
TQDateTime getDateTimeForCoordX(int coordX, bool global=true) const
bool editable() const
void addIntervalBackgroundColor(KDIntervalColorRectangle *newItem)
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
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)
void setTimeHeaderBackgroundColor(const TQColor &)
void centerTimelineAfterShow(const TQDateTime &center)
void editItem(KDGanttViewItem *)
TQColor weekdayBackgroundColor(int weekday) const