00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "KDGanttView.h"
00037 #include "KDGanttViewSubwidgets.h"
00038 #include "KDGanttMinimizeSplitter.h"
00039 #include "KDGanttViewItem.h"
00040 #include "KDGanttXMLTools.h"
00041 #include "itemAttributeDialog.h"
00042 #include <qprinter.h>
00043 #include <qpainter.h>
00044 #include <qlayout.h>
00045 #include <qpaintdevicemetrics.h>
00046 #include <qfile.h>
00047 #include <qheader.h>
00048 #include <qscrollview.h>
00049 #include <qapplication.h>
00050 #include <qevent.h>
00051 #include <qiconview.h>
00052
00053 #include <qmessagebox.h>
00054 #include <qfileinfo.h>
00055
00056 #ifndef KDGANTT_MASTER_CVS
00057 #include "KDGanttView.moc"
00058 #endif
00059
00060 #if defined KDAB_EVAL
00061 #include "../evaldialog/evaldialog.h"
00062 #endif
00063
00083 KDGanttView::KDGanttView( QWidget* parent, const char* name )
00084 : KDGanttMinimizeSplitter( Qt::Vertical, parent, name ),
00085 myCanvasView(0),
00086 myTimeHeaderScroll(0)
00087 {
00088 #if defined KDAB_EVAL
00089 EvalDialog::checkEvalLicense( "KD Gantt" );
00090 #endif
00091 myCurrentItem = 0;
00092 setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
00093 mySplitter = new KDGanttMinimizeSplitter( this );
00094 mySplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left );
00095 leftWidget = new QVBox( mySplitter );
00096 rightWidget = new QVBox( mySplitter );
00097
00098 myLegend = new KDLegendWidget( leftWidget, this );
00099 spacerLeft = new QHBox( leftWidget );
00100 myListView = new KDListView(leftWidget, this);
00101 myListView->setVScrollBarMode (QScrollView::AlwaysOff );
00102 connect( myListView, SIGNAL( selectionChanged( QListViewItem* ) ),
00103 this, SLOT( slotSelectionChanged( QListViewItem* ) ) );
00104
00105 connect( myListView, SIGNAL( mouseButtonClicked ( int, QListViewItem * , const QPoint &, int ) ), this, SLOT( slotmouseButtonClicked ( int , QListViewItem * , const QPoint &, int ) ) );
00106 connect( myListView, SIGNAL( contextMenuRequested ( QListViewItem * , const QPoint &, int ) ), this, SLOT( slotcontextMenuRequested ( QListViewItem * , const QPoint & , int ) ) );
00107 connect( myListView, SIGNAL(doubleClicked ( QListViewItem * ) ), this, SLOT(slotdoubleClicked ( QListViewItem * ) ) );
00108
00109 connect( myListView, SIGNAL(currentChanged( QListViewItem * ) ), this, SLOT(slotCurrentChanged ( QListViewItem * ) ) );
00110 connect( myListView, SIGNAL(itemRenamed ( QListViewItem * , int , const QString & ) ), this, SLOT(slotItemRenamed ( QListViewItem *, int , const QString & ) ) );
00111 connect( myListView, SIGNAL(mouseButtonPressed( int, QListViewItem * , const QPoint &, int ) ), this, SLOT(slotMouseButtonPressed ( int , QListViewItem * , const QPoint & , int ) ) );
00112
00113
00114 myTimeTable = new KDTimeTableWidget (rightWidget,this);
00115
00116 spacerRight = new QWidget( rightWidget );
00117
00118 myTimeHeaderContainer = new QHBox( rightWidget );
00119 myTimeHeaderContainer->setFrameStyle( QFrame::NoFrame );
00120 myTimeHeaderContainer->setMargin( 0 );
00121 myTimeHeaderScroll = new QScrollView ( myTimeHeaderContainer );
00122 myTimeHeaderScroll->setHScrollBarMode( QScrollView::AlwaysOff );
00123 myTimeHeaderScroll->setVScrollBarMode( QScrollView::AlwaysOff );
00124 timeHeaderSpacerWidget = new QWidget( myTimeHeaderContainer );
00125
00126
00127
00128
00129
00130
00131
00132
00133 myTimeHeader = new KDTimeHeaderWidget (myTimeHeaderScroll->viewport(),this);
00134 myTimeHeaderScroll->addChild( myTimeHeader );
00135 myTimeHeaderScroll->viewport()->setBackgroundColor( myTimeHeader->backgroundColor() );
00136 timeHeaderSpacerWidget->setBackgroundColor( myTimeHeader->backgroundColor() );
00137 myCanvasView = new KDGanttCanvasView (this,myTimeTable,rightWidget);
00138 myTimeHeaderScroll->setFrameStyle( QFrame::NoFrame );
00139
00140 myCanvasView->setFrameStyle( QFrame::NoFrame );
00141 myCanvasView->setMargin( 0 );
00142
00143 myTimeHeaderScroll->setMargin( 0 );
00144 setFrameStyle(myListView->frameStyle());
00145 setLineWidth( 2 );
00146 myListView->setFrameStyle( QFrame::NoFrame );
00147 myListView->setMargin( 0 );
00148 QObject::connect(myListView, SIGNAL ( expanded ( QListViewItem * ) ) , myTimeTable , SLOT( expandItem(QListViewItem * ))) ;
00149 QObject::connect(myListView, SIGNAL (collapsed ( QListViewItem * ) ) , myTimeTable , SLOT(collapseItem(QListViewItem * ))) ;
00150
00151 timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
00152 listViewIsVisible = true;
00153 chartIsEditable = true;
00154 editorIsEnabled = true;
00155 _displaySubitemsAsGroup = false;
00156 initDefaults();
00157 _showHeader = false;
00158
00159 myTextColor = Qt::black;
00160 myLegendItems = new QPtrList<legendItem>;
00161
00162 myItemAttributeDialog = new itemAttributeDialog();
00163 setRepaintMode( KDGanttView::Medium );
00164
00165 setShowLegendButton( true );
00166 setHeaderVisible( false );
00167
00168
00169 connect(myCanvasView->horizontalScrollBar(), SIGNAL ( valueChanged ( int )) ,myTimeHeaderScroll->horizontalScrollBar(), SLOT( setValue ( int))) ;
00170 connect(myCanvasView, SIGNAL ( heightResized( int )) ,myTimeTable, SLOT( checkHeight ( int))) ;
00171 connect(myCanvasView, SIGNAL ( widthResized( int )) ,myTimeHeader, SLOT( checkWidth ( int))) ;
00172
00173 QObject::connect(myCanvasView->verticalScrollBar(), SIGNAL ( valueChanged ( int ) ) ,myListView->verticalScrollBar(), SLOT( setValue ( int ))) ;
00174 connect(myTimeHeader, SIGNAL ( sizeChanged( int ) ) ,this, SLOT(slotHeaderSizeChanged() )) ;
00175 connect(myTimeHeader, SIGNAL ( sizeChanged( int ) ) ,myTimeTable, SLOT(resetWidth( int ) )) ;
00176 connect(myListView, SIGNAL ( contentsMoving ( int, int ) ) ,myCanvasView, SLOT( moveMyContent( int, int ))) ;
00177 connect(myTimeTable, SIGNAL ( heightComputed ( int ) ) ,myCanvasView, SLOT( setMyContentsHeight( int ))) ;
00178
00179 connect( myCanvasView->horizontalScrollBar(), SIGNAL (prevLine () ) ,this, SLOT(addTickLeft()));
00180 connect( myCanvasView->horizontalScrollBar(), SIGNAL (nextLine () ) ,this, SLOT(addTickRight()));
00181 connect( myCanvasView->horizontalScrollBar(), SIGNAL (valueChanged ( int ) ) ,this, SLOT( enableAdding( int )));
00182
00183
00184 fCenterTimeLineAfterShow = false;
00185 fDragEnabled = false;
00186 fDropEnabled = false;
00187 closingBlocked = false;
00188 myTimeHeader->computeTicks();
00189 centerTimelineAfterShow( QDateTime::currentDateTime () );
00190 setDisplayEmptyTasksAsLine( false );
00191 QValueList<int> list;
00192 list.append(240);
00193 list.append(530);
00194 mySplitter->setSizes( list );
00195 myTimeTable->setBlockUpdating();
00196 }
00197
00198
00199
00200 KDGanttView::~KDGanttView()
00201 {
00202 setUpdateEnabled(false);
00203
00204 myCanvasView->resetCutPaste( 0 );
00205 myTimeTable->clearTaskLinks();
00206 }
00230 void KDGanttView::setUpdateEnabled( bool enable )
00231 {
00232 myTimeTable->setBlockUpdating( !enable );
00233 if ( enable ) {
00234 myTimeTable->updateMyContent();
00235 myCanvasView->setMyContentsHeight( 0 );
00236 }
00237 }
00238
00246 bool KDGanttView::getUpdateEnabled() const
00247 {
00248 return !myTimeTable->blockUpdating();
00249 }
00250
00251
00252
00253
00260 void KDGanttView::setGanttMaximumWidth( int w )
00261 {
00262 myTimeHeader->setMaximumWidth ( w );
00263 }
00271 int KDGanttView::ganttMaximumWidth() const
00272 {
00273 return myTimeHeader->maximumWidth();
00274 }
00275
00282 void KDGanttView::show()
00283 {
00284 myTimeTable->setBlockUpdating( false );
00285 if (myCanvasView->horizontalScrollBar()->value() > 0 )
00286 myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->value()-1 );
00287 else
00288 myCanvasView->horizontalScrollBar()->setValue(1 );
00289 myTimeTable->updateMyContent();
00290 QWidget::show();
00291 myCanvasView->setMyContentsHeight( 0 );
00292 if ( fCenterTimeLineAfterShow ) {
00293 fCenterTimeLineAfterShow = false;
00294 centerTimeline (dtCenterTimeLineAfterShow);
00295 }
00296 }
00304 bool KDGanttView::close ( bool alsoDelete )
00305 {
00306
00307 if ( closingBlocked )
00308 return false;
00309 return QWidget::close ( alsoDelete );
00310 }
00311
00312
00321 QSize KDGanttView::sizeHint() const
00322 {
00323 bool block = myTimeTable->blockUpdating();
00324 myTimeTable->setBlockUpdating( false );
00325 myTimeTable->updateMyContent();
00326
00327
00328
00329
00330
00331
00332 int hintHeight = myTimeHeader->height();
00333 int legendHeight = 0;
00334 if ( showLegendButton() )
00335 legendHeight = myLegend->height();
00336 int listViewHeaderHeight = 0;
00337 if ( headerVisible() )
00338 listViewHeaderHeight = myListView->header()->height();
00339 if ( hintHeight < legendHeight+listViewHeaderHeight )
00340 hintHeight = legendHeight + listViewHeaderHeight;
00341 hintHeight += myListView->horizontalScrollBar()->height();
00342 if ( myLegend->isShown() )
00343 hintHeight += myLegend->legendSizeHint().height() +10;
00344 hintHeight += myTimeTable->minimumHeight+myListView->frameWidth()*2+2;
00345 int hintWid = myListView->sizeHint().width();
00346
00347 hintWid += myCanvasView->sizeHint().width();
00348
00349
00350 myTimeTable->setBlockUpdating( block );
00351 return QSize( hintWid+10, hintHeight );
00352 }
00353
00354
00362 void KDGanttView::setShowLegendButton( bool show )
00363 {
00364 _showLegendButton = show;
00365 if ( show )
00366 myLegend->show();
00367 else
00368 myLegend->hide();
00369 slotHeaderSizeChanged();
00370 }
00371
00372
00379 bool KDGanttView::showLegendButton() const
00380 {
00381 return _showLegendButton;
00382 }
00383
00384
00391 void KDGanttView::setHeaderVisible( bool visible )
00392 {
00393 if( visible )
00394 myListView->header()->show();
00395 else
00396 myListView->header()->hide();
00397 _showHeader = visible;
00398 slotHeaderSizeChanged();
00399 }
00400
00401
00407 bool KDGanttView::headerVisible() const
00408 {
00409 return _showHeader;
00410 }
00411
00412
00421 QDateTime KDGanttView::getDateTimeForCoordX(int coordX, bool global ) const
00422 {
00423
00424 return myTimeHeader->getDateTimeForIndex(coordX, !global );
00425 }
00426
00427
00431 void KDGanttView::slotSelectionChanged( QListViewItem* item )
00432 {
00433 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00434 Q_ASSERT( gItem );
00435 emit lvSelectionChanged( gItem );
00436 }
00437
00438
00439
00440
00441
00442
00443 void KDGanttView::slotmouseButtonClicked ( int button, QListViewItem * item,
00444 const QPoint & pos, int c )
00445 {
00446 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00447 emit lvMouseButtonClicked ( button , gItem, pos, c );
00448 if (gItem == 0 && myCurrentItem != 0 ) {
00449 myCurrentItem = 0;
00450 emit lvCurrentChanged( gItem );
00451 }
00452 if (gItem != 0 && myCurrentItem == 0 ) {
00453 myCurrentItem = gItem;
00454 emit lvCurrentChanged( gItem );
00455 }
00456
00457
00458
00459 {
00460 switch ( button ) {
00461 case LeftButton:
00462 emit lvItemLeftClicked( gItem );
00463 emit itemLeftClicked( gItem );
00464 break;
00465 case MidButton:
00466 emit lvItemMidClicked( gItem );
00467 emit itemMidClicked( gItem );
00468 break;
00469 }
00470 }
00471 }
00472
00473
00474
00475
00476
00477
00478
00479 void KDGanttView::slotcontextMenuRequested ( QListViewItem * item, const QPoint & pos, int col )
00480 {
00481 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00482 emit lvContextMenuRequested ( gItem, pos, col );
00483 emit lvItemRightClicked( gItem );
00484 emit itemRightClicked( gItem );
00485 }
00486
00487
00488
00489
00490
00491 void KDGanttView::slotdoubleClicked ( QListViewItem * item )
00492 {
00493 {
00494 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00495 emit lvItemDoubleClicked( gItem );
00496 emit itemDoubleClicked( gItem );
00497 }
00498 }
00499
00500
00501
00502
00503
00504 void KDGanttView::slotCurrentChanged ( QListViewItem * item )
00505 {
00506 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00507 myCurrentItem = gItem;
00508 emit lvCurrentChanged( gItem );
00509 }
00510
00511
00512
00513
00514
00515 void KDGanttView::slotItemRenamed ( QListViewItem * item , int col,
00516 const QString & text )
00517 {
00518 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00519 emit lvItemRenamed( gItem, col, text );
00520 }
00521
00522
00523
00524
00525
00526 void KDGanttView::slotMouseButtonPressed ( int button, QListViewItem * item,
00527 const QPoint & pos, int c )
00528 {
00529 KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00530 emit lvMouseButtonPressed( button, gItem, pos, c );
00531 }
00532
00533
00548 void KDGanttView::setRepaintMode( RepaintMode mode )
00549 {
00550
00551 QScrollBar *cvh, *cvv;
00552 cvh = myCanvasView->horizontalScrollBar();
00553 cvv = myCanvasView->verticalScrollBar();
00554
00555 cvh->disconnect( this );
00556 cvv->disconnect( this );
00557
00558 switch ( mode ) {
00559 case No:
00560
00561 break;
00562 case Medium:
00563 connect( cvv, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00564 connect( cvh, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00565 connect( cvv, SIGNAL (nextLine () ) ,this, SLOT(forceRepaint()));
00566 connect( cvh, SIGNAL (nextLine () ) ,this, SLOT(forceRepaint()));
00567 connect( cvv, SIGNAL (prevLine () ) ,this, SLOT(forceRepaint()));
00568 connect( cvh, SIGNAL (prevLine () ) ,this, SLOT(forceRepaint()));
00569 break;
00570 case Always:
00571 connect( cvv, SIGNAL (valueChanged ( int ) ) ,this, SLOT(forceRepaint( int )));
00572 connect( cvh, SIGNAL (valueChanged ( int ) ) ,this, SLOT(forceRepaint( int )));
00573 connect( cvv, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00574 connect( cvh, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00575 break;
00576 }
00577 }
00578
00579
00580 void KDGanttView::forceRepaint( int )
00581 {
00582 if ( myTimeTable->blockUpdating() )
00583 return;
00584
00585 myTimeTable->setAllChanged();
00586 myTimeTable->update();
00587 }
00588
00589
00590 void KDGanttView::slotHeaderSizeChanged()
00591 {
00592 int legendHeight = 0;
00593 if ( showLegendButton() )
00594 legendHeight = 24;
00595 int listViewHeaderHeight = 0;
00596 if ( headerVisible() )
00597 listViewHeaderHeight = myListView->header()->height();
00598 int timeHeaderHeight = myTimeHeader->height()+myTimeHeaderScroll->frameWidth()*2;;
00599 int diffY = timeHeaderHeight-legendHeight-listViewHeaderHeight;
00600 if ( diffY < 0 ) {
00601 spacerLeft->setFixedHeight( 0 );
00602 spacerRight->setFixedHeight(-diffY);
00603 } else {
00604 spacerRight->setFixedHeight( 0 );
00605 spacerLeft->setFixedHeight( diffY );
00606 }
00607 myLegend->setFixedHeight( legendHeight );
00608 myTimeHeaderContainer->setFixedHeight( timeHeaderHeight );
00609 }
00610
00611 void KDGanttView::setLegendIsDockwindow( bool show )
00618 {
00619 bool isdock = myLegend->asDockwindow();
00620 if ( show != isdock ) {
00621 myLegend->setAsDockwindow(show);
00622
00623 legendItem* li;
00624 for ( li = myLegendItems->first(); li; li = myLegendItems->next() ) {
00625 myLegend->addLegendItem(li->shape, li->color, li->text );
00626 }
00627 }
00628 }
00629
00630 bool KDGanttView::legendIsDockwindow() const
00637 {
00638 return myLegend->asDockwindow();
00639 }
00640
00641
00654 QDockWindow* KDGanttView::legendDockwindow() const
00655 {
00656 return myLegend->dockwindow();
00657 }
00658
00659
00668 void KDGanttView::setShowLegend( bool show )
00669 {
00670 myLegend->showMe(show);
00671 }
00672
00673
00682 bool KDGanttView::showLegend() const
00683 {
00684 return myLegend->isShown();
00685 }
00686
00687
00696 void KDGanttView::setShowListView( bool show )
00697 {
00698 if(listViewIsVisible == show) return;
00699 listViewIsVisible = show;
00700 if (listViewIsVisible)
00701 myListView->parentWidget()->show();
00702 else
00703 myListView->parentWidget()->hide();
00704 }
00705
00706
00713 bool KDGanttView::showListView() const
00714 {
00715 return listViewIsVisible;
00716 }
00717
00718
00728 void KDGanttView::setEditorEnabled( bool enable )
00729 {
00730 editorIsEnabled = enable;
00731 }
00732
00733
00742 bool KDGanttView::editorEnabled() const
00743 {
00744 return editorIsEnabled;
00745 }
00746
00747
00756 void KDGanttView::setEditable( bool editable )
00757 {
00758 chartIsEditable = editable;
00759 }
00760
00761
00769 bool KDGanttView::editable() const
00770 {
00771 return chartIsEditable;
00772 }
00773
00774
00786 bool KDGanttView::saveProject( QIODevice* device )
00787 {
00788 Q_ASSERT( device );
00789
00790 QDomDocument doc = saveXML();
00791 if( device->isOpen() )
00792 device->close();
00793 if( device->open( IO_WriteOnly ) ) {
00794 QTextStream ts( device );
00795 ts << doc.toString();
00796 return true;
00797 } else
00798 return false;
00799 }
00800
00801
00813 bool KDGanttView::loadProject( QIODevice* device )
00814 {
00815 Q_ASSERT( device );
00816
00817 if( device->isOpen() )
00818 device->close();
00819 if( device->open( IO_ReadOnly ) ) {
00820 QDomDocument doc( "GanttView" );
00821 QString err;
00822 int errline, errcol;
00823 if ( !doc.setContent( device, &err, &errline, &errcol ) ) {
00824 qDebug("KDGantt::Error parsing XML data at line %d. Message is:", errline );
00825 qDebug("%s ", err.latin1());
00826 device->close();
00827 return false;
00828 }
00829 device->close();
00830 return loadXML( doc );
00831 } else
00832 return false;
00833 }
00834
00835
00854 void KDGanttView::print( QPrinter* printer ,
00855 bool printListView, bool printTimeLine,
00856 bool printLegend )
00857 {
00858 bool deletePrinter = false;
00859 if (! printer ) {
00860 printer = new QPrinter();
00861 deletePrinter = true;
00862 if ( !printer->setup()) {
00863 delete printer;
00864 return;
00865 }
00866 }
00867
00868 QPainter p( printer );
00869
00870 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
00871 float dx, dy;
00872
00873
00874
00875 QSize size = drawContents( 0, printListView, printTimeLine, printLegend );
00876
00877
00878 QString date = "Printing Time: " + QDateTime::currentDateTime().toString();
00879 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
00880 p.drawText( 0, 0, date );
00881
00882
00883 dx = (float) m.width() / (float)size.width();
00884 dy = (float)(m.height() - ( 2 * hei )) / (float)size.height();
00885 float scale;
00886
00887 if ( dx < dy )
00888 scale = dx;
00889 else
00890 scale = dy;
00891
00892 p.scale( scale, scale );
00893
00894 p.translate( 0, 2*hei );
00895 drawContents( &p, printListView, printTimeLine, printLegend );
00896
00897
00898
00899
00900
00901 p.end();
00902 if ( deletePrinter )
00903 delete printer;
00904 }
00905
00906
00946 QSize KDGanttView::drawContents( QPainter* p,
00947 bool drawListView , bool drawTimeLine, bool drawLegend )
00948 {
00949 QSize size;
00950 int lvX, lvY, thX, thY, tlX, tlY, lwX, lwY, allX, allY;
00951 lvX = myListView->contentsWidth();
00952 lvY = myCanvasView->canvas()->height() + 20;
00953 thX = myTimeHeader->width();
00954 thY = myTimeHeader->height();
00955 tlX = myCanvasView->canvas()->width();
00956 tlY = lvY;
00957 lwX = myLegend->legendSize().width();
00958 lwY = myLegend->legendSize().height();
00959 allX = 0;
00960 allY = 0;
00961 if ( drawListView ) {
00962 allX += lvX;
00963 allY += tlY;
00964 }
00965 if ( drawTimeLine ) {
00966 allX += thX;
00967 allY += thY;
00968 }
00969 if ( drawLegend ) {
00970 allY += lwY;
00971 if ( allX < lwX )
00972 allX = lwX ;
00973 }
00974 size = QSize( allX, allY );
00975 int temp = 0;
00976 if ( p ) {
00977 if ( drawListView ) {
00978 if ( drawTimeLine )
00979 temp = thY;
00980 p->translate( 0, temp );
00981
00982
00983
00984 myListView->drawToPainter( p, drawTimeLine );
00985 p->translate( lvX, -temp);
00986 }
00987 if ( drawTimeLine ) {
00988 p->translate( myCanvasView->frameWidth(), 0);
00989 myTimeHeader->repaintMe( 0, myTimeHeader->width(), p );
00990 p->translate( -myCanvasView->frameWidth(), thY);
00991 myCanvasView->drawToPainter( p );
00992 if ( drawListView )
00993 p->translate( -lvX, tlY);
00994 else
00995 p->translate( 0, tlY);
00996 } else {
00997 if ( drawListView )
00998 p->translate( -lvX, 0 );
00999 }
01000 if ( drawLegend ) {
01001 myLegend->drawToPainter( p );
01002 p->translate( 0, lwY );
01003 }
01004 }
01005 return size;
01006 }
01007
01021 void KDGanttView::setZoomFactor( double factor, bool absolute )
01022 {
01023 myTimeHeader->zoom(factor,absolute);
01024 }
01025
01026
01034 double KDGanttView::zoomFactor() const
01035 {
01036 return myTimeHeader->zoomFactor();
01037 }
01038
01039
01048 void KDGanttView::zoomToFit()
01049 {
01050 myTimeHeader->zoomToFit();
01051 }
01052
01053
01065 void KDGanttView::zoomToSelection( const QDateTime& start, const QDateTime& end )
01066 {
01067
01068 myTimeHeader->zoomToSelection( start, end);
01069
01070 }
01071
01072
01079 void KDGanttView::ensureVisible( KDGanttViewItem* item )
01080 {
01081 myListView->ensureItemVisible (item);
01082 }
01083
01084
01093 void KDGanttView::centerTimeline( const QDateTime& center )
01094 {
01095 myTimeHeader->centerDateTime( center );
01096 }
01097
01098
01112 void KDGanttView::centerTimelineAfterShow( const QDateTime& center )
01113 {
01114 myTimeHeader->centerDateTime( center );
01115 if ( ! isVisible() ) {
01116 dtCenterTimeLineAfterShow = center;
01117 fCenterTimeLineAfterShow = true;
01118 }
01119 }
01120
01125 void KDGanttView::setTimelineToStart()
01126 {
01127 myCanvasView->horizontalScrollBar()->setValue( 0 );
01128 }
01129
01130
01134 void KDGanttView::setTimelineToEnd()
01135 {
01136 myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->maxValue());
01137 }
01138
01139
01150 void KDGanttView::addTicksLeft( int num )
01151 {
01152 myTimeHeader->addTickLeft( num );
01153 }
01154
01155
01165 void KDGanttView::addTicksRight( int num )
01166 {
01167 myTimeHeader->addTickRight( num );
01168 }
01169
01170
01175 void KDGanttView::center( KDGanttViewItem* item )
01176 {
01177 ensureVisible(item);
01178 int x = myListView->contentsWidth()/2;
01179 int y = myListView->itemPos (item );
01180 myListView->center(x,y);
01181 }
01182
01183
01190 void KDGanttView::setShowTaskLinks( bool show )
01191 {
01192 myTimeTable->setShowTaskLinks(show);
01193
01194 }
01195
01196
01203 bool KDGanttView::showTaskLinks() const
01204 {
01205 return myTimeTable->showTaskLinks();
01206 }
01207
01208
01216 void KDGanttView::setFont(const QFont& font)
01217 {
01218 myListView->setFont(font);
01219 myListView->repaint();
01220 myTimeHeader->setFont(font);
01221 myLegend->setFont( font );
01222 QWidget::setFont( font );
01223 setScale(scale());
01224 }
01225
01226
01251 void KDGanttView::setShowHeaderPopupMenu( bool show,
01252 bool showZoom,
01253 bool showScale,
01254 bool showTime,
01255 bool showYear,
01256 bool showGrid,
01257 bool showPrint)
01258 {
01259 myTimeHeader->setShowPopupMenu( show,showZoom,showScale,showTime,
01260 showYear,showGrid,showPrint );
01261 }
01262
01263
01270 bool KDGanttView::showHeaderPopupMenu() const
01271 {
01272 return myTimeHeader->showPopupMenu();
01273 }
01274
01275
01276
01290 void KDGanttView::setShowTimeTablePopupMenu( bool show )
01291 {
01292 myCanvasView->setShowPopupMenu( show );
01293 }
01294
01295
01302 bool KDGanttView::showTimeTablePopupMenu() const
01303 {
01304 return myCanvasView->showPopupMenu();
01305 }
01306
01307
01325 void KDGanttView::setShapes( KDGanttViewItem::Type type,
01326 KDGanttViewItem::Shape start,
01327 KDGanttViewItem::Shape middle,
01328 KDGanttViewItem::Shape end,
01329 bool overwriteExisting )
01330 {
01331 if ( overwriteExisting ) {
01332 QListViewItemIterator it(myListView);
01333 for ( ; it.current(); ++it ) {
01334 if ( ((KDGanttViewItem*)it.current())->type() == type)
01335 ((KDGanttViewItem*)it.current())->setShapes(start,middle, end );
01336 }
01337 }
01338 int index = getIndex( type );
01339 myDefaultShape [index*3] = start;
01340 myDefaultShape [index*3+1] = middle;
01341 myDefaultShape [index*3+2] = end;
01342 undefinedShape[index] = false;
01343 }
01344
01345
01358 bool KDGanttView::shapes( KDGanttViewItem::Type type,
01359 KDGanttViewItem::Shape& start,
01360 KDGanttViewItem::Shape& middle,
01361 KDGanttViewItem::Shape& end ) const
01362 {
01363 int index = getIndex( type );
01364 start = myDefaultShape [index*3];
01365 middle = myDefaultShape [index*3+1];
01366 end = myDefaultShape [index*3+2];
01367 return !undefinedShape[index];
01368 }
01369
01370
01388 void KDGanttView::setColors( KDGanttViewItem::Type type,
01389 const QColor& start, const QColor& middle,
01390 const QColor& end,
01391 bool overwriteExisting )
01392 {
01393 if ( overwriteExisting ) {
01394 QListViewItemIterator it(myListView);
01395 for ( ; it.current(); ++it ) {
01396 if ( ((KDGanttViewItem*)it.current())->type() == type)
01397 ((KDGanttViewItem*)it.current())->setColors(start,middle, end );
01398 }
01399 }
01400 int index = getIndex( type );
01401 myColor [index*3] = start;
01402 myColor [index*3+1] = middle;
01403 myColor [index*3+2] = end;
01404 undefinedColor[index] = false;
01405 }
01406
01407
01420 bool KDGanttView::colors( KDGanttViewItem::Type type,
01421 QColor& start, QColor& middle, QColor& end ) const
01422 {
01423 int index = getIndex( type );
01424 start = myColor [index*3];
01425 middle = myColor [index*3+1];
01426 end = myColor [index*3+2];
01427 return !undefinedColor[index];
01428 }
01429
01430
01450 void KDGanttView::setHighlightColors( KDGanttViewItem::Type type,
01451 const QColor& start,
01452 const QColor& middle,
01453 const QColor& end,
01454 bool overwriteExisting )
01455 {
01456 if ( overwriteExisting ) {
01457 QListViewItemIterator it(myListView);
01458 for ( ; it.current(); ++it ) {
01459 if ( ((KDGanttViewItem*)it.current())->type() == type)
01460 ((KDGanttViewItem*)it.current())->setHighlightColors(start,middle, end );
01461 }
01462 }
01463 int index = getIndex( type );
01464 myColorHL [index*3] = start;
01465 myColorHL [index*3+1] = middle;
01466 myColorHL [index*3+2] = end;
01467 undefinedColorHL[index] = false;
01468
01469 }
01470
01471
01486 bool KDGanttView::highlightColors( KDGanttViewItem::Type type,
01487 QColor& start, QColor& middle,
01488 QColor& end ) const
01489 {
01490 int index = getIndex( type );
01491 start = myColorHL [index*3];
01492 middle = myColorHL [index*3+1];
01493 end = myColorHL [index*3+2];
01494 return !undefinedColorHL[index];
01495 }
01496
01497
01505 void KDGanttView::setTextColor( const QColor& color )
01506 {
01507 QListViewItemIterator it(myListView);
01508 for ( ; it.current(); ++it ) {
01509 ((KDGanttViewItem*)it.current())->setTextColor(color);
01510 }
01511 myTextColor = color;
01512 }
01513
01514
01521 QColor KDGanttView::textColor() const
01522 {
01523 return myTextColor;
01524 }
01525
01526
01537 void KDGanttView::setNoInformationBrush( const QBrush& brush )
01538 {
01539 myTimeTable->setNoInformationBrush( brush );
01540 }
01541
01542
01549 QBrush KDGanttView::noInformationBrush() const
01550 {
01551 return myTimeTable->noInformationBrush();
01552 }
01553
01554
01560 void KDGanttView::clearLegend( )
01561 {
01562 myLegend->clearLegend();
01563 myLegendItems->setAutoDelete( true );
01564 delete myLegendItems;
01565 myLegendItems = new QPtrList<legendItem>;
01566 }
01567
01568
01577 void KDGanttView::addLegendItem( KDGanttViewItem::Shape shape,
01578 const QColor& shapeColor,
01579 const QString& text )
01580 {
01581 myLegend->addLegendItem( shape,shapeColor,text );
01582 legendItem* item = new legendItem;
01583 item->shape = shape;
01584 item->color = shapeColor;
01585 item->text = text;
01586 myLegendItems->append( item );
01587 }
01588
01589
01597 void KDGanttView::setHorizonStart( const QDateTime& start )
01598 {
01599 myTimeHeader->setHorizonStart(start);
01600 }
01601
01602
01609 QDateTime KDGanttView::horizonStart() const
01610 {
01611 return myTimeHeader->horizonStart();
01612 }
01613
01614
01622 void KDGanttView::setHorizonEnd( const QDateTime& end )
01623 {
01624 myTimeHeader->setHorizonEnd(end);
01625 }
01626
01627
01635 QDateTime KDGanttView::horizonEnd() const
01636 {
01637 return myTimeHeader->horizonEnd();
01638 }
01639
01640
01648 void KDGanttView::setScale( Scale unit )
01649 {
01650 myTimeHeader->setScale( unit );
01651 }
01652
01653
01660 KDGanttView::Scale KDGanttView::scale() const
01661 {
01662 return myTimeHeader->scale();
01663 }
01664
01665
01672 void KDGanttView::setMaximumScale( Scale unit )
01673 {
01674 myTimeHeader->setMaximumScale( unit );
01675 }
01676
01677
01684 KDGanttView::Scale KDGanttView::maximumScale() const
01685 {
01686 return myTimeHeader->maximumScale();
01687 }
01688
01689
01696 void KDGanttView::setMinimumScale( Scale unit )
01697 {
01698 myTimeHeader->setMinimumScale( unit );
01699 }
01700
01701
01708 KDGanttView::Scale KDGanttView::minimumScale() const
01709 {
01710 return myTimeHeader->minimumScale();
01711 }
01712
01713
01723 void KDGanttView::setAutoScaleMinorTickCount( int count )
01724 {
01725 myTimeHeader->setAutoScaleMinorTickCount( count );
01726 }
01727
01728
01735 int KDGanttView::autoScaleMinorTickCount() const
01736 {
01737 return myTimeHeader->autoScaleMinorTickCount();
01738 }
01739
01740
01749 void KDGanttView::setMinimumColumnWidth( int width )
01750 {
01751 myTimeHeader->setMinimumColumnWidth( width );
01752 }
01753
01754
01761 int KDGanttView::minimumColumnWidth() const
01762 {
01763 return myTimeHeader->minimumColumnWidth();
01764 }
01765
01766
01774 void KDGanttView::setYearFormat( YearFormat format )
01775 {
01776 myTimeHeader->setYearFormat(format );
01777 }
01778
01779
01786 KDGanttView::YearFormat KDGanttView::yearFormat() const
01787 {
01788 return myTimeHeader->yearFormat();
01789 }
01790
01791
01800 void KDGanttView::setHourFormat( HourFormat format )
01801 {
01802 myTimeHeader->setHourFormat( format );
01803 }
01804
01805
01813 KDGanttView::HourFormat KDGanttView::hourFormat() const
01814 {
01815 return myTimeHeader->hourFormat();
01816 }
01817
01818
01829 void KDGanttView::setShowMajorTicks( bool show )
01830 {
01831 myTimeHeader->setShowMajorTicks(show );
01832 }
01833
01834
01841 bool KDGanttView::showMajorTicks() const
01842 {
01843 return myTimeHeader->showMajorTicks();
01844 }
01845
01846
01859 void KDGanttView::setShowMinorTicks( bool show)
01860 {
01861 myTimeHeader->setShowMinorTicks( show );
01862 }
01863
01864
01871 bool KDGanttView::showMinorTicks() const
01872 {
01873 return myTimeHeader->showMinorTicks();
01874 }
01875
01876
01894 void KDGanttView::setColumnBackgroundColor( const QDateTime& column,
01895 const QColor& color ,
01896 Scale mini, Scale maxi )
01897 {
01898 myTimeHeader->setColumnBackgroundColor( column, color,mini,maxi );
01899 }
01900
01901
01928 void KDGanttView::setIntervalBackgroundColor( const QDateTime& start,
01929 const QDateTime& end,
01930 const QColor& color ,
01931 Scale mini, Scale maxi )
01932 {
01933 myTimeHeader->setIntervalBackgroundColor( start, end, color,mini,maxi );
01934 }
01935
01936
01955 bool KDGanttView::changeBackgroundInterval( const QDateTime& oldstart,
01956 const QDateTime& oldend,
01957 const QDateTime& newstart,
01958 const QDateTime& newend )
01959 {
01960 return myTimeHeader->changeBackgroundInterval( oldstart, oldend,
01961 newstart, newend );
01962 }
01963
01973 bool KDGanttView::deleteBackgroundInterval( const QDateTime& start,
01974 const QDateTime& end)
01975 {
01976 return myTimeHeader->deleteBackgroundInterval( start, end );
01977 }
01978
01979
01988 void KDGanttView::clearBackgroundColor()
01989 {
01990 myTimeHeader->clearBackgroundColor();
01991 }
01992
01993
02002 QColor KDGanttView::columnBackgroundColor( const QDateTime& column ) const
02003 {
02004 return myTimeHeader->columnBackgroundColor( column ) ;
02005 }
02006
02007
02016 void KDGanttView::setWeekendBackgroundColor( const QColor& color )
02017 {
02018 myTimeHeader->setWeekendBackgroundColor( color );
02019 }
02020
02021
02028 QColor KDGanttView::weekendBackgroundColor() const
02029 {
02030 return myTimeHeader->weekendBackgroundColor();
02031 }
02032
02033
02044 void KDGanttView::setWeekdayBackgroundColor( const QColor& color, int weekday )
02045 {
02046 myTimeHeader->setWeekdayBackgroundColor( color, weekday );
02047 }
02048
02049
02057 QColor KDGanttView::weekdayBackgroundColor(int weekday) const
02058 {
02059 return myTimeHeader->weekdayBackgroundColor( weekday);
02060 }
02061
02062
02063
02074 void KDGanttView::setWeekendDays( int start, int end )
02075 {
02076 myTimeHeader->setWeekendDays( start, end );
02077 }
02078
02079
02087 void KDGanttView::weekendDays( int& start, int& end ) const
02088 {
02089 myTimeHeader->weekendDays( start, end );
02090 }
02091
02092
02193 void KDGanttView::setMajorScaleCount( int count )
02194 {
02195 myTimeHeader->setMajorScaleCount(count );
02196 }
02197
02198
02205 int KDGanttView::majorScaleCount() const
02206 {
02207 return myTimeHeader->majorScaleCount();
02208 }
02209
02210
02217 void KDGanttView::setMinorScaleCount( int count )
02218 {
02219 myTimeHeader->setMinorScaleCount(count );
02220 }
02221
02222
02229 int KDGanttView::minorScaleCount() const
02230 {
02231 return myTimeHeader->minorScaleCount();
02232
02233 }
02234
02235
02248 void KDGanttView::setDefaultColor( KDGanttViewItem::Type type,
02249 const QColor& color,
02250 bool overwriteExisting )
02251 {
02252 if ( overwriteExisting ) {
02253 QListViewItemIterator it(myListView);
02254 for ( ; it.current(); ++it ) {
02255 if ( ((KDGanttViewItem*)it.current())->type() == type)
02256 ((KDGanttViewItem*)it.current())->setDefaultColor(color );
02257 }
02258 }
02259 int index = getIndex( type );
02260 myDefaultColor [index] = color;
02261 }
02262
02263
02264
02275 QColor KDGanttView::defaultColor( KDGanttViewItem::Type type ) const
02276 {
02277 int index = getIndex( type );
02278 return myDefaultColor [index];
02279 }
02280
02281
02294 void KDGanttView::setDefaultHighlightColor( KDGanttViewItem::Type type,
02295 const QColor& color,
02296 bool overwriteExisting )
02297 {
02298 if ( overwriteExisting ) {
02299 QListViewItemIterator it(myListView);
02300 for ( ; it.current(); ++it ) {
02301 if ( ((KDGanttViewItem*)it.current())->type() == type)
02302 ((KDGanttViewItem*)it.current())->setDefaultHighlightColor(color );
02303 }
02304 }
02305 int index = getIndex( type );
02306 myDefaultColorHL [index] = color;
02307 }
02308
02309
02310
02321 QColor KDGanttView::defaultHighlightColor( KDGanttViewItem::Type type ) const
02322 {
02323 int index = getIndex( type );
02324 return myDefaultColorHL [index];
02325 }
02326
02327
02333 KDGanttViewItem* KDGanttView::firstChild() const
02334 {
02335 return (KDGanttViewItem*)myListView->firstChild();
02336
02337 }
02355 void KDGanttView::setCalendarMode( bool mode )
02356 {
02357 myListView->setCalendarMode( mode );
02358 }
02359
02360
02368 bool KDGanttView::calendarMode() const
02369 {
02370 return myListView->calendarMode();
02371 }
02372
02373
02374
02384 void KDGanttView::setDisplaySubitemsAsGroup( bool show )
02385 {
02386 QListViewItemIterator it( myListView );
02387 for ( ; it.current(); ++it ) {
02388 KDGanttViewItem* currentItem = ( KDGanttViewItem* )it.current();
02389 currentItem->setDisplaySubitemsAsGroup( show );
02390 }
02391 _displaySubitemsAsGroup = show;
02392 }
02393
02394
02403 bool KDGanttView::displaySubitemsAsGroup() const
02404 {
02405 return _displaySubitemsAsGroup;
02406 }
02407
02408
02416 void KDGanttView::setDisplayEmptyTasksAsLine( bool show )
02417 {
02418 _displayEmptyTasksAsLine = show;
02419 }
02420
02421
02428 bool KDGanttView::displayEmptyTasksAsLine() const
02429 {
02430 return _displayEmptyTasksAsLine;
02431 }
02432
02433
02448 void KDGanttView::setHorBackgroundLines( int count, QBrush brush )
02449 {
02450 myTimeTable->setHorBackgroundLines( count, brush );
02451 }
02452
02453
02463 int KDGanttView::horBackgroundLines( QBrush& brush )
02464 {
02465 return myTimeTable->horBackgroundLines( brush );
02466 }
02467
02468
02474 KDGanttViewItem* KDGanttView::lastItem() const
02475 {
02476 return (KDGanttViewItem*)myListView->lastItem ();
02477 }
02478
02479
02485 QPtrList<KDGanttViewTaskLink> KDGanttView::taskLinks() const
02486 {
02487
02488 return myTimeTable->taskLinks();
02489 }
02490
02491
02497 QPtrList<KDGanttViewTaskLinkGroup> KDGanttView::taskLinkGroups() const
02498 {
02499 return myTaskLinkGroupList;
02500 }
02501
02502
02510 bool KDGanttView::loadXML( const QDomDocument& doc )
02511 {
02512 QDomElement docRoot = doc.documentElement();
02513 QDomNode node = docRoot.firstChild();
02514 while( !node.isNull() ) {
02515 QDomElement element = node.toElement();
02516 if( !element.isNull() ) {
02517 QString tagName = element.tagName();
02518 if( tagName == "ShowLegend" ) {
02519 bool value;
02520 if( KDGanttXML::readBoolNode( element, value ) )
02521 setShowLegend( value );
02522 } else if( tagName == "ShowLegendButton" ) {
02523 bool value;
02524 if( KDGanttXML::readBoolNode( element, value ) )
02525 setShowLegendButton( value );
02526 } else if( tagName == "LegendIsDockWindow" ) {
02527 bool value;
02528 if( KDGanttXML::readBoolNode( element, value ) )
02529 setLegendIsDockwindow( value );
02530 } else if( tagName == "ShowListView" ) {
02531 bool value;
02532 if( KDGanttXML::readBoolNode( element, value ) )
02533 setShowListView( value );
02534 } else if( tagName == "ShowHeader" ) {
02535 bool value;
02536 if( KDGanttXML::readBoolNode( element, value ) )
02537 setHeaderVisible( value );
02538 } else if( tagName == "ShowTaskLinks" ) {
02539 bool value;
02540 if( KDGanttXML::readBoolNode( element, value ) )
02541 setShowTaskLinks( value );
02542 } else if( tagName == "EditorEnabled" ) {
02543 bool value;
02544 if( KDGanttXML::readBoolNode( element, value ) )
02545 setEditorEnabled( value );
02546 } else if( tagName == "DisplayEmptyTasksAsLine" ) {
02547 bool value;
02548 if( KDGanttXML::readBoolNode( element, value ) )
02549 setDisplayEmptyTasksAsLine( value );
02550 } else if( tagName == "GlobalFont" ) {
02551 QFont font;
02552 if( KDGanttXML::readFontNode( element, font ) )
02553 setFont( font );
02554 } else if( tagName == "HorizonStart" ) {
02555 QDateTime value;
02556 if( KDGanttXML::readDateTimeNode( element, value ) )
02557 setHorizonStart( value );
02558 } else if( tagName == "HorizonEnd" ) {
02559 QDateTime value;
02560 if( KDGanttXML::readDateTimeNode( element, value ) )
02561 setHorizonEnd( value );
02562 } else if( tagName == "Scale" ) {
02563 QString value;
02564 if( KDGanttXML::readStringNode( element, value ) )
02565 setScale( stringToScale( value ) );
02566 } else if( tagName == "MinimumScale" ) {
02567 QString value;
02568 if( KDGanttXML::readStringNode( element, value ) )
02569 setMinimumScale( stringToScale( value ) );
02570 } else if( tagName == "MaximumScale" ) {
02571 QString value;
02572 if( KDGanttXML::readStringNode( element, value ) )
02573 setMaximumScale( stringToScale( value ) );
02574 } else if( tagName == "YearFormat" ) {
02575 QString value;
02576 if( KDGanttXML::readStringNode( element, value ) )
02577 setYearFormat( stringToYearFormat( value ) );
02578 } else if( tagName == "HourFormat" ) {
02579 QString value;
02580 if( KDGanttXML::readStringNode( element, value ) )
02581 setHourFormat( stringToHourFormat( value ) );
02582 } else if( tagName == "ShowMinorTicks" ) {
02583 bool value;
02584 if( KDGanttXML::readBoolNode( element, value ) )
02585 setShowMinorTicks( value );
02586 } else if( tagName == "ShowMajorTicks" ) {
02587 bool value;
02588 if( KDGanttXML::readBoolNode( element, value ) )
02589 setShowMajorTicks( value );
02590 } else if( tagName == "DragEnabled" ) {
02591 bool value;
02592 if( KDGanttXML::readBoolNode( element, value ) )
02593 setDragEnabled( value );
02594 } else if( tagName == "DropEnabled" ) {
02595 bool value;
02596 if( KDGanttXML::readBoolNode( element, value ) )
02597 setDropEnabled( value );
02598 } else if( tagName == "CalendarMode" ) {
02599 bool value;
02600 if( KDGanttXML::readBoolNode( element, value ) )
02601 setCalendarMode( value );
02602 } else if( tagName == "Editable" ) {
02603 bool value;
02604 if( KDGanttXML::readBoolNode( element, value ) )
02605 setEditable( value );
02606 } else if( tagName == "TextColor" ) {
02607 QColor value;
02608 if( KDGanttXML::readColorNode( element, value ) )
02609 setTextColor( value );
02610 } else if( tagName == "MajorScaleCount" ) {
02611 int value;
02612 if( KDGanttXML::readIntNode( element, value ) )
02613 setMajorScaleCount( value );
02614 } else if( tagName == "MinorScaleCount" ) {
02615 int value;
02616 if( KDGanttXML::readIntNode( element, value ) )
02617 setMinorScaleCount( value );
02618 } else if( tagName == "AutoScaleMinorTickCount" ) {
02619 int value;
02620 if( KDGanttXML::readIntNode( element, value ) )
02621 setAutoScaleMinorTickCount( value );
02622 } else if( tagName == "MinimumColumnWidth" ) {
02623 int value;
02624 if( KDGanttXML::readIntNode( element, value ) )
02625 setMinimumColumnWidth( value );
02626 } else if( tagName == "GanttMaximumWidth" ) {
02627 int value;
02628 if( KDGanttXML::readIntNode( element, value ) )
02629 setGanttMaximumWidth( value );
02630 } else if( tagName == "NoInformationBrush" ) {
02631 QBrush value;
02632 if( KDGanttXML::readBrushNode( element, value ) )
02633 setNoInformationBrush( value );
02634 } else if( tagName == "GanttViewBackgroundColor" ) {
02635 QColor value;
02636 if( KDGanttXML::readColorNode( element, value ) )
02637 setGvBackgroundColor( value );
02638 } else if( tagName == "ListViewBackgroundColor" ) {
02639 QColor value;
02640 if( KDGanttXML::readColorNode( element, value ) )
02641 setLvBackgroundColor( value );
02642 } else if( tagName == "TimeHeaderBackgroundColor" ) {
02643 QColor value;
02644 if( KDGanttXML::readColorNode( element, value ) )
02645 setTimeHeaderBackgroundColor( value );
02646 } else if( tagName == "LegendHeaderBackgroundColor" ) {
02647 QColor value;
02648 if( KDGanttXML::readColorNode( element, value ) )
02649 setLegendHeaderBackgroundColor( value );
02650 } else if( tagName == "WeekendBackgroundColor" ) {
02651 QColor value;
02652 if( KDGanttXML::readColorNode( element, value ) )
02653 setWeekendBackgroundColor( value );
02654 } else if( tagName == "WeekdayBackgroundColor" ) {
02655 QDomNode node = element.firstChild();
02656 int day = 0;
02657 QColor color;
02658 while( !node.isNull() ) {
02659 QDomElement element = node.toElement();
02660 if( !element.isNull() ) {
02661 QString tagName = element.tagName();
02662 if( tagName == "Day" ) {
02663 int value;
02664 if( KDGanttXML::readIntNode( element, value ) )
02665 day = value;
02666 } else if( tagName == "Color" ) {
02667 QColor value;
02668 if( KDGanttXML::readColorNode( element, value ) )
02669 color = value;
02670 } else {
02671 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02672 Q_ASSERT( false );
02673 }
02674 }
02675 node = node.nextSibling();
02676 }
02677
02678 if( day && color.isValid() )
02679 setWeekdayBackgroundColor( color, day );
02680 } else if( tagName == "WeekendDays" ) {
02681 QString startString = element.attribute( "Start" );
02682 QString endString = element.attribute( "End" );
02683 bool startOk = false, endOk = false;
02684 int start = startString.toInt( &startOk );
02685 int end = startString.toInt( &endOk );
02686 if( startOk && endOk )
02687 setWeekendDays( start, end );
02688 } else if( tagName == "ZoomFactor" ) {
02689 double value;
02690 if( KDGanttXML::readDoubleNode( element, value ) )
02691 setZoomFactor( value, true );
02692 } else if( tagName == "ShowHeaderPopupMenu" ) {
02693 bool value;
02694 if( KDGanttXML::readBoolNode( element, value ) )
02695 setShowHeaderPopupMenu( value );
02696 } else if( tagName == "ShowTimeTablePopupMenu" ) {
02697 bool value;
02698 if( KDGanttXML::readBoolNode( element, value ) )
02699 setShowTimeTablePopupMenu( value );
02700 } else if( tagName == "Shapes" ) {
02701 QDomNode node = element.firstChild();
02702 bool undefinedShape = false;
02703 while( !node.isNull() ) {
02704 QDomElement element = node.toElement();
02705 if( !element.isNull() ) {
02706 QString tagName = element.tagName();
02707 if( tagName == "Event" ) {
02708 KDGanttViewItem::Shape startShape, middleShape, endShape;
02709 startShape = KDGanttViewItem::TriangleDown;
02710 middleShape = KDGanttViewItem::TriangleDown;
02711 endShape = KDGanttViewItem::TriangleDown;
02712 QDomNode node = element.firstChild();
02713 while( !node.isNull() ) {
02714 QDomElement element = node.toElement();
02715 if( !element.isNull() ) {
02716 QString tagName = element.tagName();
02717 if( tagName == "Start" ) {
02718 QString value;
02719 if( KDGanttXML::readStringNode( element, value ) )
02720 startShape = KDGanttViewItem::stringToShape( value );
02721 if ( value == "Undefined" )
02722 undefinedShape = true;
02723 } else if( tagName == "Middle" ) {
02724 QString value;
02725 if( KDGanttXML::readStringNode( element, value ) )
02726 middleShape = KDGanttViewItem::stringToShape( value );
02727 if ( value == "Undefined" )
02728 undefinedShape = true;
02729 } else if( tagName == "End" ) {
02730 QString value;
02731 if( KDGanttXML::readStringNode( element, value ) )
02732 endShape = KDGanttViewItem::stringToShape( value );
02733 if ( value == "Undefined" )
02734 undefinedShape = true;
02735 } else {
02736 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02737 Q_ASSERT( false );
02738 }
02739 }
02740 node = node.nextSibling();
02741 }
02742 if ( ! undefinedShape )
02743 setShapes( KDGanttViewItem::Event, startShape,
02744 middleShape, endShape, false );
02745 undefinedShape = false;
02746 } else if( tagName == "Task" ) {
02747 KDGanttViewItem::Shape startShape, middleShape, endShape;
02748 startShape = KDGanttViewItem::TriangleDown;
02749 middleShape = KDGanttViewItem::TriangleDown;
02750 endShape = KDGanttViewItem::TriangleDown;
02751 QDomNode node = element.firstChild();
02752 while( !node.isNull()) {
02753 QDomElement element = node.toElement();
02754 if( !element.isNull() ) {
02755 QString tagName = element.tagName();
02756 if( tagName == "Start" ) {
02757 QString value;
02758 if( KDGanttXML::readStringNode( element, value ) )
02759 startShape = KDGanttViewItem::stringToShape( value );
02760 if ( value == "Undefined" )
02761 undefinedShape = true;
02762 } else if( tagName == "Middle" ) {
02763 QString value;
02764 if( KDGanttXML::readStringNode( element, value ) )
02765 middleShape = KDGanttViewItem::stringToShape( value );
02766 if ( value == "Undefined" )
02767 undefinedShape = true;
02768 } else if( tagName == "End" ) {
02769 QString value;
02770 if( KDGanttXML::readStringNode( element, value ) )
02771 endShape = KDGanttViewItem::stringToShape( value );
02772 if ( value == "Undefined" )
02773 undefinedShape = true;
02774 } else {
02775 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02776 Q_ASSERT( false );
02777 }
02778 }
02779 node = node.nextSibling();
02780 }
02781 if ( ! undefinedShape )
02782 setShapes( KDGanttViewItem::Task, startShape, middleShape, endShape, false );
02783 undefinedShape = false;
02784 } else if( tagName == "Summary" ) {
02785 KDGanttViewItem::Shape startShape, middleShape, endShape;
02786 startShape = KDGanttViewItem::TriangleDown;
02787 middleShape = KDGanttViewItem::TriangleDown;
02788 endShape = KDGanttViewItem::TriangleDown;
02789 QDomNode node = element.firstChild();
02790 while( !node.isNull() ) {
02791 QDomElement element = node.toElement();
02792 if( !element.isNull() ) {
02793 QString tagName = element.tagName();
02794 if( tagName == "Start" ) {
02795 QString value;
02796 if( KDGanttXML::readStringNode( element, value ) )
02797 startShape = KDGanttViewItem::stringToShape( value );
02798 if ( value == "Undefined" )
02799 undefinedShape = true;
02800 } else if( tagName == "Middle" ) {
02801 QString value;
02802 if( KDGanttXML::readStringNode( element, value ) )
02803 middleShape = KDGanttViewItem::stringToShape( value );
02804 if ( value == "Undefined" )
02805 undefinedShape = true;
02806 } else if( tagName == "End" ) {
02807 QString value;
02808 if( KDGanttXML::readStringNode( element, value ) )
02809 endShape = KDGanttViewItem::stringToShape( value );
02810 if ( value == "Undefined" )
02811 undefinedShape = true;
02812 } else {
02813 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02814 Q_ASSERT( false );
02815 }
02816 }
02817 node = node.nextSibling();
02818 }
02819 if ( ! undefinedShape )
02820 setShapes( KDGanttViewItem::Summary, startShape,
02821 middleShape, endShape, false );
02822 undefinedShape = false;
02823 } else {
02824 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02825 Q_ASSERT( false );
02826 }
02827 }
02828 node = node.nextSibling();
02829 }
02830 } else if( tagName == "Colors" ) {
02831 QDomNode node = element.firstChild();
02832 while( !node.isNull()) {
02833 QDomElement element = node.toElement();
02834 if( !element.isNull() ) {
02835 QString tagName = element.tagName();
02836 if( tagName == "Event" ) {
02837 QColor startColor, middleColor, endColor;
02838 QDomNode node = element.firstChild();
02839 while( !node.isNull() ) {
02840 QDomElement element = node.toElement();
02841 if( !element.isNull() ) {
02842 QString tagName = element.tagName();
02843 if( tagName == "Start" ) {
02844 QColor value;
02845 if( KDGanttXML::readColorNode( element, value ) )
02846 startColor = value;
02847 } else if( tagName == "Middle" ) {
02848 QColor value;
02849 if( KDGanttXML::readColorNode( element, value ) )
02850 middleColor = value;
02851 } else if( tagName == "End" ) {
02852 QColor value;
02853 if( KDGanttXML::readColorNode( element, value ) )
02854 endColor = value;
02855 } else {
02856 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02857 Q_ASSERT( false );
02858 }
02859 }
02860 node = node.nextSibling();
02861 }
02862 setColors( KDGanttViewItem::Event, startColor,
02863 middleColor, endColor, false );
02864 } else if( tagName == "Task" ) {
02865 QColor startColor, middleColor, endColor;
02866 QDomNode node = element.firstChild();
02867 while( !node.isNull() ) {
02868 QDomElement element = node.toElement();
02869 if( !element.isNull() ) {
02870 QString tagName = element.tagName();
02871 if( tagName == "Start" ) {
02872 QColor value;
02873 if( KDGanttXML::readColorNode( element, value ) )
02874 startColor = value;
02875 } else if( tagName == "Middle" ) {
02876 QColor value;
02877 if( KDGanttXML::readColorNode( element, value ) )
02878 middleColor = value;
02879 } else if( tagName == "End" ) {
02880 QColor value;
02881 if( KDGanttXML::readColorNode( element, value ) )
02882 endColor = value;
02883 } else {
02884 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02885 Q_ASSERT( false );
02886 }
02887 }
02888 node = node.nextSibling();
02889 }
02890 setColors( KDGanttViewItem::Task, startColor,
02891 middleColor, endColor, false );
02892 } else if( tagName == "Summary" ) {
02893 QColor startColor, middleColor, endColor;
02894 QDomNode node = element.firstChild();
02895 while( !node.isNull() ) {
02896 QDomElement element = node.toElement();
02897 if( !element.isNull() ) {
02898 QString tagName = element.tagName();
02899 if( tagName == "Start" ) {
02900 QColor value;
02901 if( KDGanttXML::readColorNode( element, value ) )
02902 startColor = value;
02903 } else if( tagName == "Middle" ) {
02904 QColor value;
02905 if( KDGanttXML::readColorNode( element, value ) )
02906 middleColor = value;
02907 } else if( tagName == "End" ) {
02908 QColor value;
02909 if( KDGanttXML::readColorNode( element, value ) )
02910 endColor = value;
02911 } else {
02912 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02913 Q_ASSERT( false );
02914 }
02915 }
02916 node = node.nextSibling();
02917 }
02918 setColors( KDGanttViewItem::Summary, startColor,
02919 middleColor, endColor , false);
02920 } else {
02921 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02922 Q_ASSERT( false );
02923 }
02924 }
02925 node = node.nextSibling();
02926 }
02927 } else if( tagName == "DefaultColors" ) {
02928 QDomNode node = element.firstChild();
02929 while( !node.isNull() ) {
02930 QDomElement element = node.toElement();
02931 if( !element.isNull() ) {
02932 QString tagName = element.tagName();
02933 if( tagName == "Event" ) {
02934 QColor value;
02935 if( KDGanttXML::readColorNode( element, value ) )
02936 setDefaultColor( KDGanttViewItem::Event,
02937 value, false );
02938 } else if( tagName == "Task" ) {
02939 QColor value;
02940 if( KDGanttXML::readColorNode( element, value ) )
02941 setDefaultColor( KDGanttViewItem::Task,
02942 value, false );
02943 } else if( tagName == "Summary" ) {
02944 QColor value;
02945 if( KDGanttXML::readColorNode( element, value ) )
02946 setDefaultColor( KDGanttViewItem::Summary,
02947 value , false);
02948 } else {
02949 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02950 Q_ASSERT( false );
02951 }
02952 }
02953
02954 node = node.nextSibling();
02955 }
02956 } else if( tagName == "HighlightColors" ) {
02957 QDomNode node = element.firstChild();
02958 while( !node.isNull() ) {
02959 QDomElement element = node.toElement();
02960 if( !element.isNull() ) {
02961 QString tagName = element.tagName();
02962 if( tagName == "Event" ) {
02963 QColor startColor, middleColor, endColor;
02964 QDomNode node = element.firstChild();
02965 while( !node.isNull() ) {
02966 QDomElement element = node.toElement();
02967 if( !element.isNull() ) {
02968 QString tagName = element.tagName();
02969 if( tagName == "Start" ) {
02970 QColor value;
02971 if( KDGanttXML::readColorNode( element, value ) )
02972 startColor = value;
02973 } else if( tagName == "Middle" ) {
02974 QColor value;
02975 if( KDGanttXML::readColorNode( element, value ) )
02976 middleColor = value;
02977 } else if( tagName == "End" ) {
02978 QColor value;
02979 if( KDGanttXML::readColorNode( element, value ) )
02980 endColor = value;
02981 } else {
02982 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
02983 Q_ASSERT( false );
02984 }
02985 }
02986 node = node.nextSibling();
02987 }
02988 setHighlightColors( KDGanttViewItem::Event,
02989 startColor,
02990 middleColor, endColor, false );
02991 } else if( tagName == "Task" ) {
02992 QColor startColor, middleColor, endColor;
02993 QDomNode node = element.firstChild();
02994 while( !node.isNull() ) {
02995 QDomElement element = node.toElement();
02996 if( !element.isNull() ) {
02997 QString tagName = element.tagName();
02998 if( tagName == "Start" ) {
02999 QColor value;
03000 if( KDGanttXML::readColorNode( element, value ) )
03001 startColor = value;
03002 } else if( tagName == "Middle" ) {
03003 QColor value;
03004 if( KDGanttXML::readColorNode( element, value ) )
03005 middleColor = value;
03006 } else if( tagName == "End" ) {
03007 QColor value;
03008 if( KDGanttXML::readColorNode( element, value ) )
03009 endColor = value;
03010 } else {
03011 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03012 Q_ASSERT( false );
03013 }
03014 }
03015 node = node.nextSibling();
03016 }
03017 setHighlightColors( KDGanttViewItem::Task,
03018 startColor,
03019 middleColor, endColor , false);
03020 } else if( tagName == "Summary" ) {
03021 QColor startColor, middleColor, endColor;
03022 QDomNode node = element.firstChild();
03023 while( !node.isNull() ) {
03024 QDomElement element = node.toElement();
03025 if( !element.isNull() ) {
03026 QString tagName = element.tagName();
03027 if( tagName == "Start" ) {
03028 QColor value;
03029 if( KDGanttXML::readColorNode( element, value ) )
03030 startColor = value;
03031 } else if( tagName == "Middle" ) {
03032 QColor value;
03033 if( KDGanttXML::readColorNode( element, value ) )
03034 middleColor = value;
03035 } else if( tagName == "End" ) {
03036 QColor value;
03037 if( KDGanttXML::readColorNode( element, value ) )
03038 endColor = value;
03039 } else {
03040 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03041 Q_ASSERT( false );
03042 }
03043 }
03044 node = node.nextSibling();
03045 }
03046 setHighlightColors( KDGanttViewItem::Summary,
03047 startColor,
03048 middleColor, endColor, false );
03049 } else {
03050 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03051 Q_ASSERT( false );
03052 }
03053 }
03054 node = node.nextSibling();
03055 }
03056 } else if( tagName == "DefaultHighlightColors" ) {
03057 QDomNode node = element.firstChild();
03058 while( !node.isNull() ) {
03059 QDomElement element = node.toElement();
03060 if( !element.isNull() ) {
03061 QString tagName = element.tagName();
03062 if( tagName == "Event" ) {
03063 QColor value;
03064 if( KDGanttXML::readColorNode( element, value ) )
03065 setDefaultHighlightColor( KDGanttViewItem::Event,
03066 value , false);
03067 } else if( tagName == "Task" ) {
03068 QColor value;
03069 if( KDGanttXML::readColorNode( element, value ) )
03070 setDefaultHighlightColor( KDGanttViewItem::Task,
03071 value, false );
03072 } else if( tagName == "Summary" ) {
03073 QColor value;
03074 if( KDGanttXML::readColorNode( element, value ) )
03075 setDefaultHighlightColor( KDGanttViewItem::Summary,
03076 value, false );
03077 } else {
03078 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03079 Q_ASSERT( false );
03080 }
03081 }
03082
03083 node = node.nextSibling();
03084 }
03085 } else if( tagName == "Items" ) {
03086 QDomNode node = element.firstChild();
03087 KDGanttViewItem* previous = 0;
03088 while( !node.isNull() ) {
03089 QDomElement element = node.toElement();
03090 if( !element.isNull() ) {
03091 QString tagName = element.tagName();
03092 if( tagName == "Item" ) {
03093 KDGanttViewItem* newItem;
03094 if( previous )
03095 newItem =
03096 KDGanttViewItem::createFromDomElement( this,
03097 previous,
03098 element );
03099 else
03100 newItem =
03101 KDGanttViewItem::createFromDomElement( this,
03102 element );
03103 previous = newItem;
03104 } else {
03105 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03106 Q_ASSERT( false );
03107 }
03108 }
03109
03110 node = node.nextSibling();
03111 }
03112 } else if( tagName == "TaskLinks" ) {
03113 QDomNode node = element.firstChild();
03114 while( !node.isNull() ) {
03115 QDomElement element = node.toElement();
03116 if( !element.isNull() ) {
03117 QString tagName = element.tagName();
03118 if( tagName == "TaskLink" )
03119 KDGanttViewTaskLink::createFromDomElement( element );
03120 else {
03121 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03122 Q_ASSERT( false );
03123 }
03124 }
03125
03126 node = node.nextSibling();
03127 }
03128 } else if( tagName == "TaskLinkGroups" ) {
03129 QDomNode node = element.firstChild();
03130 while( !node.isNull() ) {
03131 QDomElement element = node.toElement();
03132 if( !element.isNull() ) {
03133 QString tagName = element.tagName();
03134 if( tagName == "TaskLink" )
03135 KDGanttViewTaskLinkGroup::createFromDomElement( element );
03136 } else {
03137 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03138 Q_ASSERT( false );
03139 }
03140
03141 node = node.nextSibling();
03142 }
03143 } else if( tagName == "ColumnBackgroundColors" ) {
03144 QDomNode node = element.firstChild();
03145 while( !node.isNull() ) {
03146 QDomElement element = node.toElement();
03147 if( !element.isNull() ) {
03148 QString tagName = element.tagName();
03149 if( tagName == "ColumnBackgroundColor" ) {
03150 QDomNode node = element.firstChild();
03151 QDateTime dateTime;
03152 QColor color;
03153 while( !node.isNull() ) {
03154 QDomElement element = node.toElement();
03155 if( !element.isNull() ) {
03156
03157
03158 QString tagName = element.tagName();
03159 if( tagName == "DateTime" ) {
03160 QDateTime value;
03161 if( KDGanttXML::readDateTimeNode( element, value ) )
03162 dateTime = value;
03163 } else if( tagName == "Color" ) {
03164 QColor value;
03165 if( KDGanttXML::readColorNode( element, value ) )
03166 color = value;
03167 } else {
03168 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03169 Q_ASSERT( false );
03170 }
03171 }
03172
03173 node = node.nextSibling();
03174 }
03175 setColumnBackgroundColor( dateTime, color );
03176 } else {
03177 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03178 Q_ASSERT( false );
03179 }
03180 }
03181 node = node.nextSibling();
03182 }
03183 } else if( tagName == "LegendItems" ) {
03184 clearLegend();
03185 QDomNode node = element.firstChild();
03186 while( !node.isNull() ) {
03187 QDomElement element = node.toElement();
03188 if( !element.isNull() ) {
03189 QString tagName = element.tagName();
03190 if( tagName == "LegendItem" ) {
03191 KDGanttViewItem::Shape tempLegendShape;
03192 tempLegendShape = KDGanttViewItem::TriangleDown;
03193 QColor tempLegendColor;
03194 QString tempLegendString;
03195 bool ok = true;
03196 QDomNode node = element.firstChild();
03197 while( !node.isNull() ) {
03198 QDomElement element = node.toElement();
03199 if( !element.isNull() ) {
03200 QString tagName = element.tagName();
03201 if( tagName == "Shape" ) {
03202 QString value;
03203 if( KDGanttXML::readStringNode( element, value ) )
03204 tempLegendShape = KDGanttViewItem::stringToShape( value );
03205 else
03206 ok = false;
03207 } else if( tagName == "Color" ) {
03208 QColor value;
03209 if( KDGanttXML::readColorNode( element, value ) )
03210 tempLegendColor = value;
03211 else
03212 ok = false;
03213 } else if( tagName == "Text" ) {
03214 QString value;
03215 if( KDGanttXML::readStringNode( element, value ) )
03216 tempLegendString = value;
03217 else
03218 ok = false;
03219 } else {
03220 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03221 Q_ASSERT( false );
03222 }
03223 }
03224 node = node.nextSibling();
03225 }
03226 if( ok ) {
03227 addLegendItem( tempLegendShape,
03228 tempLegendColor,
03229 tempLegendString );
03230 qDebug( "Adding legend item %s", tempLegendString.latin1() );
03231 }
03232 } else {
03233 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03234 Q_ASSERT( false );
03235 }
03236 }
03237 node = node.nextSibling();
03238 }
03239 } else {
03240 qDebug( "Unrecognized tag name: %s", tagName.latin1() );
03241 Q_ASSERT( false );
03242 }
03243 }
03244
03245 node = node.nextSibling();
03246 }
03247 return true;
03248 }
03249
03250
03259 QDomDocument KDGanttView::saveXML( bool withPI ) const
03260 {
03261
03262 QString docstart = "<GanttView/>";
03263
03264 QDomDocument doc( "GanttView" );
03265 doc.setContent( docstart );
03266 if( withPI ) {
03267 QDomProcessingInstruction pin = doc.createProcessingInstruction( "kdgantt", "version=\"1.0\" encoding=\"UTF-8\"" ) ;
03268 doc.appendChild ( pin );
03269 }
03270
03271 QDomElement docRoot = doc.documentElement();
03272 docRoot.setAttribute( "xmlns", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
03273 docRoot.setAttribute( "xmlns:xsi", "http://www.w3.org/2000/10/XMLSchema-instance" );
03274 docRoot.setAttribute( "xsi:schemaLocation", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
03275
03276
03277 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegend", showLegend() );
03278
03279
03280 KDGanttXML::createBoolNode( doc, docRoot, "ShowLegendButton",
03281 showLegendButton() );
03282
03283
03284 KDGanttXML::createBoolNode( doc, docRoot, "LegendIsDockWindow",
03285 legendIsDockwindow() );
03286
03287
03288 KDGanttXML::createBoolNode( doc, docRoot, "ShowListView", showListView() );
03289
03290
03291 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeader", headerVisible() );
03292
03293
03294 KDGanttXML::createBoolNode( doc, docRoot, "ShowTaskLinks", showTaskLinks() );
03295
03296
03297 KDGanttXML::createBoolNode( doc, docRoot, "EditorEnabled", editorEnabled() );
03298
03299
03300 KDGanttXML::createFontNode( doc, docRoot, "GlobalFont", font() );
03301
03302
03303 KDGanttXML::createBoolNode( doc, docRoot, "DisplayEmptyTasksAsLine",
03304 displayEmptyTasksAsLine() );
03305
03306
03307 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonStart", horizonStart() );
03308
03309
03310 KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonEnd", horizonEnd() );
03311
03312
03313 KDGanttXML::createStringNode( doc, docRoot, "Scale", scaleToString( scale() ) );
03314 KDGanttXML::createStringNode( doc, docRoot, "MinimumScale",
03315 scaleToString( minimumScale() ) );
03316 KDGanttXML::createStringNode( doc, docRoot, "MaximumScale",
03317 scaleToString( maximumScale() ) );
03318
03319
03320 KDGanttXML::createStringNode( doc, docRoot, "YearFormat",
03321 yearFormatToString( yearFormat() ) );
03322
03323
03324 KDGanttXML::createStringNode( doc, docRoot, "HourFormat",
03325 hourFormatToString( hourFormat() ) );
03326
03327
03328 KDGanttXML::createBoolNode( doc, docRoot, "ShowMinorTicks", showMinorTicks() );
03329
03330
03331 KDGanttXML::createBoolNode( doc, docRoot, "ShowMajorTicks", showMajorTicks() );
03332
03333
03334 KDGanttXML::createBoolNode( doc, docRoot, "Editable", editable() );
03335
03336
03337 KDGanttXML::createColorNode( doc, docRoot, "TextColor", textColor() );
03338
03339
03340 KDGanttXML::createIntNode( doc, docRoot, "MajorScaleCount", majorScaleCount() );
03341
03342
03343 KDGanttXML::createIntNode( doc, docRoot, "MinorScaleCount", minorScaleCount() );
03344
03345
03346 KDGanttXML::createIntNode( doc, docRoot, "AutoScaleMinorTickCount",
03347 autoScaleMinorTickCount() );
03348
03349
03350 KDGanttXML::createIntNode( doc, docRoot, "MinimumColumnWidth",
03351 minimumColumnWidth() );
03352
03353
03354 KDGanttXML::createIntNode( doc, docRoot, "GanttMaximumWidth",
03355 ganttMaximumWidth() );
03356
03357
03358 KDGanttXML::createBrushNode( doc, docRoot, "NoInformationBrush",
03359 noInformationBrush() );
03360
03361
03362 KDGanttXML::createColorNode( doc, docRoot, "GanttViewBackgroundColor",
03363 gvBackgroundColor() );
03364
03365
03366 KDGanttXML::createColorNode( doc, docRoot, "ListViewBackgroundColor",
03367 lvBackgroundColor() );
03368
03369
03370 KDGanttXML::createColorNode( doc, docRoot, "TimeHeaderBackgroundColor",
03371 timeHeaderBackgroundColor() );
03372
03373
03374 KDGanttXML::createColorNode( doc, docRoot, "LegendHeaderBackgroundColor",
03375 legendHeaderBackgroundColor() );
03376
03377
03378 KDGanttXML::createColorNode( doc, docRoot, "WeekendBackgroundColor",
03379 weekendBackgroundColor() );
03380
03381
03382 for( int weekday = 1; weekday <= 7; weekday++ ) {
03383 QColor color = weekdayBackgroundColor( weekday );
03384 if( color.isValid() ) {
03385 QDomElement weekendBackgroundColorElement = doc.createElement( "WeekdayBackgroundColor" );
03386 docRoot.appendChild( weekendBackgroundColorElement );
03387 KDGanttXML::createIntNode( doc, weekendBackgroundColorElement,
03388 "Day", weekday );
03389 KDGanttXML::createColorNode( doc, weekendBackgroundColorElement,
03390 "Color", color );
03391 }
03392 }
03393
03394
03395 QDomElement weekendDaysElement = doc.createElement( "WeekendDays" );
03396 docRoot.appendChild( weekendDaysElement );
03397 int weekendStart, weekendEnd;
03398 weekendDays( weekendStart, weekendEnd );
03399 weekendDaysElement.setAttribute( "Start", weekendStart );
03400 weekendDaysElement.setAttribute( "End", weekendStart );
03401
03402
03403 KDGanttXML::createDoubleNode( doc, docRoot, "ZoomFactor",
03404 zoomFactor() );
03405
03406
03407 KDGanttXML::createBoolNode( doc, docRoot, "ShowHeaderPopupMenu",
03408 showHeaderPopupMenu() );
03409
03410
03411 KDGanttXML::createBoolNode( doc, docRoot, "ShowTimeTablePopupMenu",
03412 showTimeTablePopupMenu() );
03413
03414
03415 QDomElement shapesElement = doc.createElement( "Shapes" );
03416 docRoot.appendChild( shapesElement );
03417 QDomElement shapesEventElement = doc.createElement( "Event" );
03418 shapesElement.appendChild( shapesEventElement );
03419 KDGanttViewItem::Shape start, middle, end;
03420 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
03421 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
03422 KDGanttViewItem::shapeToString( start ) );
03423 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
03424 KDGanttViewItem::shapeToString( middle ) );
03425 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
03426 KDGanttViewItem::shapeToString( end ) );
03427 } else {
03428 KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
03429 "Undefined" );
03430 KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
03431 "Undefined" );
03432 KDGanttXML::createStringNode( doc, shapesEventElement, "End",
03433 "Undefined" );
03434 }
03435 QDomElement shapesTaskElement = doc.createElement( "Task" );
03436 shapesElement.appendChild( shapesTaskElement );
03437 if( shapes( KDGanttViewItem::Task, start, middle, end ) ) {
03438 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
03439 KDGanttViewItem::shapeToString( start ) );
03440 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
03441 KDGanttViewItem::shapeToString( middle ) );
03442 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
03443 KDGanttViewItem::shapeToString( end ) );
03444 } else {
03445 KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
03446 "Undefined" );
03447 KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
03448 "Undefined" );
03449 KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
03450 "Undefined" );
03451 }
03452 QDomElement shapesSummaryElement = doc.createElement( "Summary" );
03453 shapesElement.appendChild( shapesSummaryElement );
03454 if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
03455 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
03456 KDGanttViewItem::shapeToString( start ) );
03457 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
03458 KDGanttViewItem::shapeToString( middle ) );
03459 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
03460 KDGanttViewItem::shapeToString( end ) );
03461 } else {
03462 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
03463 "Undefined" );
03464 KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
03465 "Undefined" );
03466 KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
03467 "Undefined" );
03468 }
03469
03470
03471 QDomElement colorsElement = doc.createElement( "Colors" );
03472 docRoot.appendChild( colorsElement );
03473 QDomElement colorsEventElement = doc.createElement( "Event" );
03474 colorsElement.appendChild( colorsEventElement );
03475 QColor startColor, middleColor, endColor;
03476 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
03477 KDGanttXML::createColorNode( doc, colorsEventElement, "Start", startColor );
03478 KDGanttXML::createColorNode( doc, colorsEventElement, "Middle", middleColor );
03479 KDGanttXML::createColorNode( doc, colorsEventElement, "End", endColor );
03480 QDomElement colorsTaskElement = doc.createElement( "Task" );
03481 colorsElement.appendChild( colorsTaskElement );
03482 colors( KDGanttViewItem::Task, startColor, middleColor, endColor );
03483 KDGanttXML::createColorNode( doc, colorsTaskElement, "Start", startColor );
03484 KDGanttXML::createColorNode( doc, colorsTaskElement, "Middle", middleColor );
03485 KDGanttXML::createColorNode( doc, colorsTaskElement, "End", endColor );
03486 QDomElement colorsSummaryElement = doc.createElement( "Summary" );
03487 colorsElement.appendChild( colorsSummaryElement );
03488 colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
03489 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Start", startColor );
03490 KDGanttXML::createColorNode( doc, colorsSummaryElement, "Middle", middleColor );
03491 KDGanttXML::createColorNode( doc, colorsSummaryElement, "End", endColor );
03492
03493
03494 QDomElement defaultColorsElement = doc.createElement( "DefaultColors" );
03495 docRoot.appendChild( defaultColorsElement );
03496 KDGanttXML::createColorNode( doc, defaultColorsElement, "Event",
03497 defaultColor( KDGanttViewItem::Event ) );
03498 KDGanttXML::createColorNode( doc, defaultColorsElement, "Task",
03499 defaultColor( KDGanttViewItem::Task ) );
03500 KDGanttXML::createColorNode( doc, defaultColorsElement, "Summary",
03501 defaultColor( KDGanttViewItem::Summary ) );
03502
03503
03504
03505 QDomElement highlightColorsElement = doc.createElement( "HighlightColors" );
03506 docRoot.appendChild( highlightColorsElement );
03507 QDomElement highlightColorsEventElement = doc.createElement( "Event" );
03508 highlightColorsElement.appendChild( highlightColorsEventElement );
03509 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
03510 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Start", startColor );
03511 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Middle", middleColor );
03512 KDGanttXML::createColorNode( doc, highlightColorsEventElement, "End", endColor );
03513 QDomElement highlightColorsTaskElement = doc.createElement( "Task" );
03514 highlightColorsElement.appendChild( highlightColorsTaskElement );
03515 highlightColors( KDGanttViewItem::Task, startColor, middleColor, endColor );
03516 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Start", startColor );
03517 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Middle", middleColor );
03518 KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "End", endColor );
03519 QDomElement highlightColorsSummaryElement = doc.createElement( "Summary" );
03520 highlightColorsElement.appendChild( highlightColorsSummaryElement );
03521 highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
03522 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
03523 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
03524 KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539 QDomElement defaultHighlightColorsElement = doc.createElement( "DefaultHighlightColors" );
03540 docRoot.appendChild( defaultHighlightColorsElement );
03541 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Event",
03542 defaultHighlightColor( KDGanttViewItem::Event ) );
03543 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Task",
03544 defaultHighlightColor( KDGanttViewItem::Task ) );
03545 KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Summary",
03546 defaultHighlightColor( KDGanttViewItem::Summary ) );
03547
03548
03549
03550 QDomElement itemsElement = doc.createElement( "Items" );
03551 docRoot.appendChild( itemsElement );
03552 KDGanttViewItem* currentItem = firstChild();
03553 while( currentItem ) {
03554 currentItem->createNode( doc, itemsElement );
03555 currentItem = currentItem->nextSibling();
03556 }
03557
03558
03559 QDomElement taskLinksElement = doc.createElement( "TaskLinks" );
03560 docRoot.appendChild( taskLinksElement );
03561 QPtrList<KDGanttViewTaskLink> taskLinkList = taskLinks();
03562 KDGanttViewTaskLink* currentTL = 0;
03563 for( currentTL = taskLinkList.first(); currentTL;
03564 currentTL = taskLinkList.next() )
03565 currentTL->createNode( doc, taskLinksElement );
03566
03567
03568 QDomElement taskLinkGroupsElement = doc.createElement( "TaskLinkGroups" );
03569 docRoot.appendChild( taskLinkGroupsElement );
03570 QPtrList<KDGanttViewTaskLinkGroup> taskLinkGroupList = taskLinkGroups();
03571 KDGanttViewTaskLinkGroup* currentTLG = 0;
03572 for( currentTLG = taskLinkGroupList.first(); currentTLG;
03573 currentTLG = taskLinkGroupList.next() )
03574 currentTLG->createNode( doc, taskLinkGroupsElement );
03575
03576
03577 QDomElement columnBackgroundColorsElement =
03578 doc.createElement( "ColumnBackgroundColors" );
03579 docRoot.appendChild( columnBackgroundColorsElement );
03580 KDTimeHeaderWidget::ColumnColorList ccList =
03581 myTimeHeader->columnBackgroundColorList();
03582 for( KDTimeHeaderWidget::ColumnColorList::iterator it = ccList.begin();
03583 it != ccList.end(); ++it ) {
03584 QDomElement columnBackgroundColorElement =
03585 doc.createElement( "ColumnBackgroundColor" );
03586 columnBackgroundColorsElement.appendChild( columnBackgroundColorElement );
03587 KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
03588 "DateTime", (*it).datetime );
03589 KDGanttXML::createColorNode( doc, columnBackgroundColorElement,
03590 "Color", (*it).color );
03591 }
03592
03593
03594 QDomElement legendItemsElement =
03595 doc.createElement( "LegendItems" );
03596 docRoot.appendChild( legendItemsElement );
03597 legendItem* current;
03598 QPtrListIterator<legendItem> lit( *myLegendItems );
03599 while( ( current = lit.current() ) ) {
03600 ++lit;
03601 QDomElement legendItemElement = doc.createElement( "LegendItem" );
03602 legendItemsElement.appendChild( legendItemElement );
03603 KDGanttXML::createStringNode( doc, legendItemElement, "Shape",
03604 KDGanttViewItem::shapeToString( current->shape ) );
03605 KDGanttXML::createColorNode( doc, legendItemElement, "Color",
03606 current->color );
03607 KDGanttXML::createStringNode( doc, legendItemElement, "Text",
03608 current->text );
03609 }
03610
03611
03612 KDGanttXML::createBoolNode( doc, docRoot, "DragEnabled", isDragEnabled() );
03613
03614
03615 KDGanttXML::createBoolNode( doc, docRoot, "DropEnabled", isDropEnabled() );
03616
03617
03618 KDGanttXML::createBoolNode( doc, docRoot, "CalendarMode", calendarMode() );
03619
03620 return doc;
03621 }
03622
03623
03624
03625 QString KDGanttView::scaleToString( Scale scale )
03626 {
03627 switch( scale ) {
03628 case Minute:
03629 return "Minute";
03630 case Hour:
03631 return "Hour";
03632 case Day:
03633 return "Day";
03634 case Week:
03635 return "Week";
03636 case Month:
03637 return "Month";
03638 case Auto:
03639 return "Auto";
03640 }
03641 return "";
03642 }
03643
03644
03645 KDGanttView::Scale KDGanttView::stringToScale( const QString& string )
03646 {
03647 if( string == "Minute" )
03648 return Minute;
03649 else if( string == "Hour" )
03650 return Hour;
03651 else if( string == "Day" )
03652 return Day;
03653 else if( string == "Week" )
03654 return Week;
03655 else if( string == "Month" )
03656 return Month;
03657 else if( string == "Auto" )
03658 return Auto;
03659
03660 return Auto;
03661 }
03662
03663
03664 QString KDGanttView::yearFormatToString( YearFormat format )
03665 {
03666 switch( format ) {
03667 case FourDigit:
03668 return "FourDigit";
03669 case TwoDigit:
03670 return "TwoDigit";
03671 case TwoDigitApostrophe:
03672 return "TwoDigitApostrophe";
03673 case NoDate:
03674 return "NoDate";
03675 }
03676 return "";
03677 }
03678
03679
03680 KDGanttView::YearFormat KDGanttView::stringToYearFormat( const QString& string )
03681 {
03682 if( string == "FourDigit" )
03683 return FourDigit;
03684 else if( string == "TwoDigit" )
03685 return TwoDigit;
03686 else if( string == "TwoDigitApostrophe" )
03687 return TwoDigitApostrophe;
03688 else if( string == "NoDate" )
03689 return NoDate;
03690 else
03691 return FourDigit;
03692 }
03693
03694
03695 QString KDGanttView::hourFormatToString( HourFormat format )
03696 {
03697 switch( format ) {
03698 case Hour_12:
03699 return "Hour_12";
03700 case Hour_24:
03701 return "Hour_24";
03702 case Hour_24_FourDigit:
03703 return "Hour_24_FourDigit";
03704 }
03705 return "";
03706 }
03707
03708
03709 KDGanttView::HourFormat KDGanttView::stringToHourFormat( const QString& string )
03710 {
03711 if( string == "Hour_12" )
03712 return Hour_12;
03713 else if( string == "Hour_24" )
03714 return Hour_24;
03715 else
03716 return Hour_24;
03717 }
03718
03719
03720 void KDGanttView::addTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
03721 {
03722
03723 if (myTaskLinkGroupList.isEmpty()) {
03724 myTaskLinkGroupList.append(group);
03725 return;
03726 }
03727 if (myTaskLinkGroupList.find(group) == -1)
03728 myTaskLinkGroupList.append(group);
03729 }
03730
03731
03732 void KDGanttView::removeTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
03733 {
03734 myTaskLinkGroupList.remove(group);
03735 }
03736
03737
03743 void KDGanttView::editItem( KDGanttViewItem* item)
03744 {
03745 if ( ! item )
03746 return;
03747 if ( editorEnabled() ) {
03748 if ( item->editable() ) {
03749 myItemAttributeDialog->reset( item );
03750 myItemAttributeDialog->show();
03751 }
03752 }
03753 }
03754
03755
03766 QPixmap KDGanttView::getPixmap( KDGanttViewItem::Shape shape,
03767 const QColor& shapeColor,
03768 const QColor& backgroundColor, int itemSize)
03769 {
03770
03771 int size = itemSize+2;
03772 int hei = ( itemSize/3 ) / 2;
03773 QPixmap p = QPixmap( size+4, size+4 );
03774 p.fill( backgroundColor );
03775 QPainter paint (&p);
03776 QBrush b = QBrush ( Qt::SolidPattern );
03777 b.setColor( shapeColor );
03778 paint.setBrush( b );
03779 QPen pen( Qt::black, 1 ) ;
03780 paint.setPen( pen );
03781 switch (shape) {
03782 case KDGanttViewItem::TriangleDown:{
03783 QPointArray arr = QPointArray(3);
03784 arr.setPoint(0,-size/2,-hei);
03785 arr.setPoint(1,size/2,-hei);
03786 arr.setPoint(2,0,((size/2)-hei));
03787 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
03788 paint.drawPolygon( arr );
03789 break;
03790 }
03791 case KDGanttViewItem::TriangleUp :{
03792 QPointArray arr = QPointArray(3);
03793 arr.setPoint(0,-size/2,hei);
03794 arr.setPoint(1,size/2,hei);
03795 arr.setPoint(2,0,(-size/2)+hei);
03796 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
03797 paint.drawPolygon( arr );
03798 break;
03799 }
03800 case KDGanttViewItem::Diamond :{
03801 QPointArray arr = QPointArray(4);
03802 arr.setPoint(0,0,-size/2);
03803 arr.setPoint(1,size/2,0);
03804 arr.setPoint(2,0,size/2);
03805 arr.setPoint(3,-size/2,0);
03806 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
03807 paint.drawPolygon( arr );
03808 break;
03809 }
03810 case KDGanttViewItem::Square :{
03811 QPointArray arr = QPointArray(4);
03812 arr.setPoint(0,-size/2,-size/2);
03813 arr.setPoint(1,size/2,-size/2);
03814 arr.setPoint(2,size/2,size/2);
03815 arr.setPoint(3,-size/2,size/2);
03816 arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
03817 paint.drawPolygon( arr );
03818 break;
03819 }
03820 case KDGanttViewItem::Circle :{
03821 paint.drawEllipse( 2, 2, size, size);
03822 break;
03823 }
03824 }
03825 paint.end();
03826 return p;
03827 }
03828
03829 int KDGanttView::getIndex( KDGanttViewItem::Type type) const
03830 {
03831 int index = -1;
03832 switch (type) {
03833 case (KDGanttViewItem::Event):
03834 index = 0;
03835 break;
03836 case (KDGanttViewItem::Task):
03837 index = 1;
03838 break;
03839 case (KDGanttViewItem::Summary):
03840 index = 2;
03841 break;
03842 }
03843 return index;
03844 }
03845
03846
03847 void KDGanttView::initDefaults()
03848 {
03849 int i;
03850
03851 for (i = 0;i<3;++i) {
03852 undefinedShape[i] = true;
03853 undefinedColor[i] = true;
03854 undefinedColorHL[i] = true;
03855 }
03856
03857 myDefaultColor [ getIndex( KDGanttViewItem::Event ) ] = Qt::blue;
03858 myDefaultColorHL [ getIndex( KDGanttViewItem::Event ) ] = Qt::red;
03859 myDefaultColor [ getIndex( KDGanttViewItem::Task ) ] = Qt::green;
03860 myDefaultColorHL [ getIndex( KDGanttViewItem::Task ) ] = Qt::red;
03861 myDefaultColor [ getIndex( KDGanttViewItem::Summary ) ] = Qt::cyan;
03862 myDefaultColorHL [ getIndex( KDGanttViewItem::Summary ) ] = Qt::red;
03863
03864
03865
03866 for (i = 0;i<3;++i) {
03867 myDefaultShape [3*getIndex( KDGanttViewItem::Event )+ i] = KDGanttViewItem::Diamond;
03868 myDefaultShape [3*getIndex( KDGanttViewItem::Task ) +i] = KDGanttViewItem::Square;
03869 myDefaultShape [3*getIndex( KDGanttViewItem::Summary ) +i] = KDGanttViewItem::TriangleDown;
03870
03871 }
03872 }
03873
03874
03875
03879 int KDGanttView::addColumn( const QString& label, int width )
03880 {
03881 return myListView->addColumn( label, width );
03882 }
03883
03884
03889 int KDGanttView::addColumn( const QIconSet& iconset, const QString& label,
03890 int width )
03891 {
03892 return myListView->addColumn( iconset, label, width );
03893 }
03894
03895
03899 void KDGanttView::removeColumn( int index )
03900 {
03901 myListView->removeColumn( index );
03902 }
03903
03904
03908 KDGanttViewItem* KDGanttView::selectedItem() const
03909 {
03910 return static_cast<KDGanttViewItem*>( myListView->selectedItem() );
03911 }
03912
03913
03917 void KDGanttView::setSelected( KDGanttViewItem* item, bool selected )
03918 {
03919 myListView->setSelected( item, selected );
03920 }
03921
03922
03935 KDGanttViewItem* KDGanttView::getItemByName( const QString& name ) const
03936 {
03937 KDGanttViewItem* temp = firstChild(),* ret;
03938 while (temp != 0) {
03939 if ( (ret = temp->getChildByName( name ) ) )
03940 return ret;
03941 temp = temp->nextSibling();
03942 }
03943 return 0;
03944 }
03945
03946
03958 KDGanttViewItem* KDGanttView::getItemByListViewPos( const QPoint& pos ) const
03959 {
03960 return static_cast<KDGanttViewItem*>( myListView->itemAt(myListView->mapFromGlobal(pos) ));
03961 }
03962
03963
03978 KDGanttViewItem* KDGanttView::getItemByGanttViewPos( const QPoint& pos ) const
03979 {
03980 KDGanttViewItem* item;
03981 QPoint local = myCanvasView->mapFromGlobal(pos);
03982
03983 QCanvasItemList il = myTimeTable->collisions( myCanvasView->viewportToContents( local ));
03984 QCanvasItemList::Iterator it;
03985 for ( it = il.begin(); it != il.end(); ++it ) {
03986 if ( myCanvasView->getType(*it) == Type_is_KDGanttViewItem) {
03987 item = myCanvasView->getItem(*it);
03988 if ( item->enabled() )
03989 return item;
03990 }
03991 }
03992 return 0;
03993 }
03994
03995
04010 KDGanttViewItem* KDGanttView::getItemAt( const QPoint& pos, bool global ) const
04011 {
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021 KDGanttViewItem* item;
04022 KDGanttViewItem* retItem = 0;
04023 int y;
04024 if ( global )
04025 y = myCanvasView->mapFromGlobal(pos).y();
04026 else
04027 y = pos.y();
04028 item = firstChild();
04029 while ( item != 0 ) {
04030 int yc = item->itemPos();
04031 if ( yc <= y && y < yc + item->height()) {
04032 retItem = item;
04033 break;
04034 }
04035 item = item->itemBelow();
04036 }
04037 return retItem;
04038
04039 }
04040
04041
04042 void KDGanttView::addTickRight()
04043 {
04044 if ( _enableAdding && myCanvasView->horizontalScrollBar()->value() == myCanvasView->horizontalScrollBar()->maxValue()) {
04045
04046 myTimeHeader->addTickRight();
04047
04048 myCanvasView->updateHorScrollBar();
04049 setTimelineToEnd();
04050 }
04051 }
04052
04053
04054 void KDGanttView::addTickLeft()
04055 {
04056 if ( _enableAdding && myCanvasView->horizontalScrollBar()->value() == 0 ) {
04057 myCanvasView->horizontalScrollBar()->blockSignals( true );
04058 myTimeHeader->addTickLeft();
04059 myCanvasView->horizontalScrollBar()->blockSignals( false );
04060 setTimelineToStart();
04061 }
04062 }
04063
04064
04065 void KDGanttView::enableAdding( int val )
04066 {
04067 _enableAdding = ( val == 0 || val == myCanvasView->horizontalScrollBar()->maxValue());
04068 }
04069
04070
04076 int KDGanttView::childCount() const
04077 {
04078 return myListView->childCount();
04079 }
04080
04081
04085 void KDGanttView::clear()
04086 {
04087 bool block = myTimeTable->blockUpdating();
04088 myTimeTable->setBlockUpdating( true );
04089 myListView->clear();
04090 myTimeTable->setBlockUpdating( false );
04091 myTimeTable->updateMyContent();
04092 myTimeTable->setBlockUpdating( block );
04093 }
04094
04095
04099 void KDGanttView::slot_lvDropped(QDropEvent* e, KDGanttViewItem* droppedItem, KDGanttViewItem* itemBelowMouse )
04100 {
04101 emit dropped( e, droppedItem, itemBelowMouse);
04102 }
04103
04107 QDragObject * KDGanttView::dragObject ()
04108 {
04109 return myListView->dragObject ();
04110 }
04111
04112
04116 void KDGanttView::startDrag ()
04117 {
04118
04119 }
04120
04121
04125 void KDGanttView::setPaletteBackgroundColor( const QColor& col)
04126 {
04127 QWidget::setPaletteBackgroundColor( col );
04128 timeHeaderSpacerWidget->setPaletteBackgroundColor( col );
04129 }
04130
04131
04138 void KDGanttView::setGvBackgroundColor ( const QColor & c )
04139 {
04140 myTimeTable->setBackgroundColor( c );
04141 }
04142
04143
04150 void KDGanttView::setTimeHeaderBackgroundColor ( const QColor & c )
04151 {
04152 myTimeHeader->setPaletteBackgroundColor( c );
04153
04154 timeHeaderSpacerWidget->setPaletteBackgroundColor( c );
04155 }
04156
04157
04164 void KDGanttView::setLegendHeaderBackgroundColor ( const QColor & c )
04165 {
04166 myLegend->setPaletteBackgroundColor( c );
04167 leftWidget->setPaletteBackgroundColor( c );
04168 }
04169
04170
04177 void KDGanttView::setLvBackgroundColor ( const QColor & c )
04178 {
04179 myListView->viewport()->setPaletteBackgroundColor( c );
04180 }
04181
04182
04189 QColor KDGanttView::lvBackgroundColor ( )const
04190 {
04191 return myListView->viewport()->paletteBackgroundColor( );
04192 }
04193
04194
04201 QColor KDGanttView::gvBackgroundColor () const
04202 {
04203 return myTimeTable->backgroundColor( );
04204 }
04205
04206
04213 QColor KDGanttView::timeHeaderBackgroundColor () const
04214 {
04215 return myTimeHeader->paletteBackgroundColor( );
04216 }
04217
04218
04225 QColor KDGanttView::legendHeaderBackgroundColor () const
04226 {
04227 return myLegend->paletteBackgroundColor( );
04228 }
04229
04230
04245 void KDGanttView::addUserdefinedLegendHeaderWidget( QWidget * w )
04246 {
04247 if ( w ) {
04248 w->reparent ( spacerLeft, 0, QPoint(0,0) );
04249 }
04250 }
04251
04252
04261 void KDGanttView::setDragEnabled( bool b )
04262 {
04263 fDragEnabled = b;
04264 QListViewItemIterator it( myListView );
04265 for ( ; it.current(); ++it ) {
04266 (( KDGanttViewItem* )it.current())->setDragEnabled(b);
04267 }
04268
04269 }
04270
04271
04280 void KDGanttView::setDropEnabled( bool b )
04281 {
04282 fDropEnabled = b;
04283
04284
04285 QListViewItemIterator it( myListView );
04286 for ( ; it.current(); ++it ) {
04287 (( KDGanttViewItem* )it.current())->setDropEnabled(b);
04288 }
04289 }
04290
04291
04300 void KDGanttView::setDragDropEnabled( bool b )
04301 {
04302 setDropEnabled( b );
04303 setDragEnabled( b );
04304 }
04305
04306
04313 bool KDGanttView::isDragEnabled() const
04314 {
04315 return fDragEnabled;
04316 }
04317
04318
04325 bool KDGanttView::isDropEnabled() const
04326 {
04327 return fDropEnabled;
04328 }
04329
04330
04334 bool KDGanttView::dragEnabled() const
04335 {
04336 return isDragEnabled();
04337 }
04338
04339
04343 bool KDGanttView::dropEnabled() const
04344 {
04345 return isDropEnabled();
04346 }
04347
04348
04375 bool KDGanttView::lvDropEvent ( QDropEvent* e,
04376 KDGanttViewItem* droppedItem,
04377 KDGanttViewItem* itemBelowMouse )
04378 {
04379 Q_UNUSED( e );
04380 Q_UNUSED( droppedItem );
04381 Q_UNUSED( itemBelowMouse );
04382
04383
04384
04385
04386
04387
04388
04389
04390
04391
04392
04393
04394
04395
04396
04397
04398
04399
04400
04401
04402
04403
04404
04405
04406
04407
04408
04409
04410
04411
04412
04413
04414
04415
04416
04417
04418
04419 return false;
04420 }
04421
04422
04439 void KDGanttView::lvDragEnterEvent ( QDragEnterEvent * e)
04440 {
04441
04442
04443
04444
04445 if ( KDGanttViewItemDrag::canDecode(e) ) {
04446 e->accept( true);
04447 return;
04448 }
04449
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459
04460
04461 e->accept( false );
04462 }
04463
04464
04493 bool KDGanttView::lvDragMoveEvent ( QDragMoveEvent* ,
04494 KDGanttViewItem* ,
04495 KDGanttViewItem* )
04496 {
04497
04498
04499
04500
04501
04502
04503
04504
04505
04506
04507
04508
04509
04510
04511
04512
04513
04514
04515
04516
04517
04518
04519
04520 return false;
04521 }
04522
04523
04533 void KDGanttView::lvStartDrag (KDGanttViewItem* item)
04534 {
04535 QDragObject* d = new KDGanttViewItemDrag(item, this, "itemdrag" );
04536
04537
04538
04539
04540
04541
04542
04543
04544
04545 if ( d->drag() ) {
04546 delete item;
04547 }
04548 }
04549
04550
04558 void KDGanttView::setListViewWidth( int w )
04559 {
04560 int sw = mySplitter->width();
04561 QValueList<int> list;
04562 list.append(w);
04563 list.append(sw-w);
04564 mySplitter->setSizes( list );
04565 }
04566
04567
04574 int KDGanttView::listViewWidth( )
04575 {
04576 return leftWidget->width();
04577 }
04578
04579
04589 void KDGanttView::setLvVScrollBarMode( QScrollView::ScrollBarMode m )
04590 {
04591 myListView->setVScrollBarMode ( m );
04592 }
04593
04594
04604 void KDGanttView::setGvVScrollBarMode( QScrollView::ScrollBarMode m )
04605 {
04606 if ( m == QScrollView::Auto )
04607 qDebug("KDGanttView::setListViewVScrollBarMode: QScrollView::Auto not supported. Nothing changed. ");
04608 else
04609 {
04610 myCanvasView->setVScrollBarMode ( m );
04611 if ( m == QScrollView::AlwaysOn )
04612 timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
04613 else
04614 timeHeaderSpacerWidget->setFixedWidth( 0 );
04615 }
04616 }
04617
04618
04619 void KDGanttView::notifyEditdialog( KDGanttViewItem * item)
04620 {
04621 if (myItemAttributeDialog->getItem() == item ) {
04622 myItemAttributeDialog->reset( 0 );
04623 }
04624 }
04625
04633 void KDGanttView::setLinkItemsEnabled(bool on)
04634 {
04635 myCanvasView->linkItemsEnabled = on;
04636 myCanvasView->autoScrollEnabled = true;
04637 }
04638
04644 bool KDGanttView::isLinkItemsEnabled() const
04645 {
04646 return myCanvasView->linkItemsEnabled;
04647 }
04648