• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kdgantt1

KDGanttView.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttView.cpp 937849 2009-03-10 15:15:48Z winterz $
00003    KDGantt - a multi-platform charting engine
00004 */
00005 
00006 /****************************************************************************
00007  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00008  **
00009  ** This file is part of the KDGantt library.
00010  **
00011  ** This file may be used under the terms of the GNU General Public
00012  ** License versions 2.0 or 3.0 as published by the Free Software
00013  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00014  ** included in the packaging of this file.  Alternatively you may (at
00015  ** your option) use any later version of the GNU General Public
00016  ** License if such license has been publicly approved by
00017  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00018  **
00019  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00020  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00021  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00022  ** not expressly granted herein.
00023  **
00024  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00025  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00026  **
00027  ** As a special exception, permission is given to link this program
00028  ** with any edition of Qt, and distribute the resulting executable,
00029  ** without including the source code for Qt in the source distribution.
00030  **
00031  **********************************************************************/
00032 
00033 // we need the protected QHeader method
00034 // QHeader::paintSection ( QPainter * p, int index, const QRect & fr )
00035 // in order to print the header of the list view
00036 // because we cannot reimplement QHeader to access this method we
00037 // have to get access to the protected QHeader methods
00038 
00039 #include "KDGanttView.h"
00040 #include "KDGanttViewSubwidgets.h"
00041 #include "KDGanttMinimizeSplitter.h"
00042 #include "KDGanttViewItem.h"
00043 #include "KDGanttViewTaskItem.h"
00044 #include "KDGanttViewEventItem.h"
00045 #include "KDGanttViewSummaryItem.h"
00046 #include "KDGanttXMLTools.h"
00047 #if QT_VERSION < 0x040000
00048 #include "itemAttributeDialog.h"
00049 #endif
00050 #include <QPrinter>
00051 #include <QPainter>
00052 #include <QLayout>
00053 #include <QFile>
00054 #include <QApplication>
00055 #include <QtDebug>
00056 #include <QPrintDialog>
00057 #include <QDragEnterEvent>
00058 
00059 #include <QMessageBox>
00060 #include <QFileInfo>
00061 #include <QTextStream>
00062 
00063 
00064 
00065 #if defined KDAB_EVAL
00066 #include "../evaldialog/evaldialog.h"
00067 #endif
00068 
00089 KDGanttView::KDGanttView( QWidget* parent, const char* name  )
00090     : KDGanttMinimizeSplitter( Qt::Vertical, parent ),
00091       myCanvasView(0),
00092       myTimeHeaderScroll(0),
00093       mFixedHorizon( false )
00094 {
00095   setObjectName( name );
00096 
00097 #if defined KDAB_EVAL
00098     EvalDialog::checkEvalLicense( "KD Gantt" );
00099 #endif
00100   myCurrentItem = 0;
00101   mUserHorizonChangeEnabled = true;
00102 #if QT_VERSION < 0x040000
00103     setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
00104 #endif
00105     mySplitter = new KDGanttMinimizeSplitter( this );
00106 #if QT_VERSION < 0x040000
00107     mySplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left );
00108 #endif
00109     leftWidget = new QVBox( mySplitter );
00110     rightWidget = new QVBox( mySplitter );
00111     //leftWidget->setMinimumSize( 20, 20 );
00112     //rightWidget->setMinimumSize( 20, 20 );
00113     myLegend = new KDLegendWidget( leftWidget, this );
00114     spacerLeft = new QWidget( leftWidget );
00115     spacerLeftLayout = new QHBoxLayout( spacerLeft );
00116     spacerLeftLayout->setMargin( 0 );
00117     spacerLeftLayout->setSpacing( 0 );
00118 
00119     myListView = new KDListView(leftWidget, this);
00120     myListView->setVScrollBarMode (QScrollView::AlwaysOff );
00121 #if QT_VERSION < 0x040000
00122     connect( myListView, SIGNAL( selectionChanged( QListViewItem* ) ),
00123              this, SLOT( slotSelectionChanged( QListViewItem* ) ) );
00124     connect( myListView, SIGNAL( mouseButtonClicked ( int, QListViewItem * , const QPoint &, int ) ),
00125              this, SLOT( slotmouseButtonClicked ( int , QListViewItem * , const QPoint &, int ) ) );
00126     connect( myListView, SIGNAL( contextMenuRequested ( QListViewItem * , const QPoint &, int  ) ),
00127              this, SLOT( slotcontextMenuRequested ( QListViewItem * , const QPoint & , int ) ) );
00128     connect( myListView, SIGNAL(expanded ( QListViewItem *  ) ),
00129              this, SLOT(slotItemExpanded ( QListViewItem * ) ) );
00130     connect( myListView, SIGNAL(collapsed ( QListViewItem *  ) ),
00131              this, SLOT(slotItemCollapsed( QListViewItem * ) ) );
00132     connect( myListView, SIGNAL(currentChanged( QListViewItem *  ) ),
00133              this, SLOT(slotCurrentChanged ( QListViewItem * ) ) );
00134     connect( myListView, SIGNAL(itemRenamed ( QListViewItem * , int , const QString &  ) ),
00135              this, SLOT(slotItemRenamed ( QListViewItem *, int , const QString &  ) ) );
00136     connect( myListView, SIGNAL(mouseButtonPressed(  int, QListViewItem * , const QPoint &, int ) ),
00137              this, SLOT(slotMouseButtonPressed (  int , QListViewItem * , const QPoint & , int ) ) );
00138 #else
00139     connect( myListView, SIGNAL( selectionChanged( Q3ListViewItem* ) ),
00140              this, SLOT( slotSelectionChanged( Q3ListViewItem* ) ) );
00141     connect( myListView, SIGNAL( mouseButtonClicked ( int, Q3ListViewItem * , const QPoint &, int ) ),
00142              this, SLOT( slotmouseButtonClicked ( int , Q3ListViewItem * , const QPoint &, int ) ) );
00143     connect( myListView, SIGNAL( contextMenuRequested ( Q3ListViewItem * , const QPoint &, int  ) ),
00144              this, SLOT( slotcontextMenuRequested ( Q3ListViewItem * , const QPoint & , int ) ) );
00145     connect( myListView, SIGNAL(expanded ( Q3ListViewItem *  ) ),
00146              this, SLOT(slotItemExpanded ( Q3ListViewItem * ) ) );
00147     connect( myListView, SIGNAL(collapsed ( Q3ListViewItem *  ) ),
00148              this, SLOT(slotItemCollapsed( Q3ListViewItem * ) ) );
00149     connect( myListView, SIGNAL(currentChanged( Q3ListViewItem *  ) ),
00150              this, SLOT(slotCurrentChanged ( Q3ListViewItem * ) ) );
00151     connect( myListView, SIGNAL(itemRenamed ( Q3ListViewItem * , int , const QString &  ) ),
00152              this, SLOT(slotItemRenamed ( Q3ListViewItem *, int , const QString &  ) ) );
00153     connect( myListView, SIGNAL(mouseButtonPressed(  int, Q3ListViewItem * , const QPoint &, int ) ),
00154              this, SLOT(slotMouseButtonPressed (  int , Q3ListViewItem * , const QPoint & , int ) ) );
00155 #endif
00156     //connect( myListView, SIGNAL( ), this, SLOT( ) );
00157     myTimeTable = new KDTimeTableWidget (0,this);
00158 
00159     spacerRight = new QWidget(  rightWidget );
00160 
00161     myTimeHeaderContainer = new QHBox( rightWidget );
00162     myTimeHeaderContainer->setFrameStyle( QFrame::NoFrame  );
00163     myTimeHeaderContainer->setMargin( 0 );
00164     myTimeHeaderScroll = new QScrollView ( myTimeHeaderContainer );
00165     myTimeHeaderScroll->setHScrollBarMode( QScrollView::AlwaysOff );
00166     myTimeHeaderScroll->setVScrollBarMode( QScrollView::AlwaysOff );
00167     timeHeaderSpacerWidget = new QWidget( myTimeHeaderContainer );
00168 
00169 
00170     /*
00171     myTimeHeaderScroll = new QScrollView ( rightWidget );
00172     myTimeHeaderScroll->setHScrollBarMode( QScrollView::AlwaysOff );
00173     myTimeHeaderScroll->setVScrollBarMode( QScrollView::AlwaysOn );
00174     */
00175     //myTimeHeader = new KDTimeHeaderWidget (rightWidget,this);
00176     myTimeHeader = new KDTimeHeaderWidget (myTimeHeaderScroll->viewport(),this);
00177     myTimeHeaderScroll->addChild( myTimeHeader );
00178     QPalette pal = myTimeHeader->palette();
00179     myTimeHeaderScroll->viewport()->setPalette( pal );
00180     timeHeaderSpacerWidget->setPalette( pal );
00181     myCanvasView = new KDGanttCanvasView( this, myTimeTable, rightWidget);
00182     myTimeHeaderScroll->setFrameStyle( QFrame::NoFrame  );
00183     //
00184     myCanvasView->setFrameStyle( QFrame::NoFrame  );
00185     myCanvasView->setMargin( 0 );
00186     //
00187     myTimeHeaderScroll->setMargin( 0 );//myCanvasView->frameWidth() );
00188     setFrameStyle(myListView->frameStyle());
00189     setLineWidth( 2 );
00190     myListView->setFrameStyle( QFrame::NoFrame  );
00191     myListView->setMargin( 0 );
00192 #if QT_VERSION < 0x040000
00193     QObject::connect(myListView, SIGNAL (  expanded ( QListViewItem * ) ) ,
00194                      myTimeTable , SLOT( expandItem(QListViewItem * ))) ;
00195     QObject::connect(myListView, SIGNAL (collapsed ( QListViewItem * ) ) ,
00196                      myTimeTable , SLOT(collapseItem(QListViewItem * ))) ;
00197 #else
00198     QObject::connect(myListView, SIGNAL (  expanded ( Q3ListViewItem * ) ) ,
00199                      myTimeTable , SLOT( expandItem(Q3ListViewItem * ))) ;
00200     QObject::connect(myListView, SIGNAL (collapsed ( Q3ListViewItem * ) ) ,
00201                      myTimeTable , SLOT(collapseItem(Q3ListViewItem * ))) ;
00202 #endif
00203     timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
00204     listViewIsVisible = true;
00205     chartIsEditable = true;
00206     editorIsEnabled = true;
00207     _displaySubitemsAsGroup = false;
00208     initDefaults();
00209     _showHeader = false;
00210 
00211     myTextColor = Qt::black;
00212     //QObject::connect( this, SIGNAL (itemDoubleClicked( KDGanttViewItem* ) ) , this, SLOT( editItem( KDGanttViewItem*  ))) ;
00213 #if QT_VERSION < 0x040000
00214     myItemAttributeDialog = 0;
00215 #endif
00216     setRepaintMode( KDGanttView::Medium );
00217     setShowLegendButton( true );
00218     setHeaderVisible( false );
00219 
00220     // now connecting the widgets
00221     connect(myCanvasView->horizontalScrollBar(), SIGNAL (  valueChanged ( int )) ,myTimeHeaderScroll->horizontalScrollBar(), SLOT( setValue ( int))) ;
00222     connect(myCanvasView, SIGNAL (  heightResized( int )) ,myTimeTable, SLOT( checkHeight ( int))) ;
00223     connect(myCanvasView, SIGNAL (  widthResized( int )) ,myTimeHeader, SLOT( checkWidth ( int))) ;
00224 
00225     QObject::connect(myCanvasView->verticalScrollBar(), SIGNAL ( valueChanged ( int ) ) ,myListView->verticalScrollBar(), SLOT( setValue ( int ))) ;
00226     connect(myTimeHeader, SIGNAL ( sizeChanged( int ) ) ,this, SLOT(slotHeaderSizeChanged()  )) ;
00227     connect(myTimeHeader, SIGNAL ( sizeChanged( int ) ) ,myTimeTable, SLOT(resetWidth( int ) )) ;
00228     connect(myListView, SIGNAL ( contentsMoving ( int, int ) ) ,myCanvasView, SLOT(  moveMyContent( int, int ))) ;
00229     connect(myTimeTable, SIGNAL ( heightComputed ( int ) ) ,myCanvasView, SLOT(  setMyContentsHeight( int ))) ;
00230    // the next three are for adding new ticks at left/right
00231 #if QT_VERSION < 0x040000
00232     //connect( myCanvasView->horizontalScrollBar(), SIGNAL( prevLine () ) ,this, SLOT( addTickLeft()));
00233     //connect( myCanvasView->horizontalScrollBar(), SIGNAL( nextLine () ) ,this, SLOT( addTickRight()));
00234 #else
00235     connect( myCanvasView->horizontalScrollBar(), SIGNAL( actionTriggered ( int ) ) ,this, SLOT( hScrollBarAction( int )));
00236     connect( myCanvasView->verticalScrollBar(), SIGNAL( actionTriggered ( int ) ) ,this, SLOT( vScrollBarAction( int )));
00237 #endif
00238    // now initing
00239     fCenterTimeLineAfterShow = false;
00240     fDragEnabled = false;
00241     fDropEnabled = false;
00242     closingBlocked = false;
00243    myTimeHeader->computeTicks();
00244    centerTimelineAfterShow( QDateTime::currentDateTime () );
00245    setDisplayEmptyTasksAsLine( false );
00246    //QValueList<int> list;
00247    //list.append(240);
00248    //list.append(530);
00249    //mySplitter->setSizes( list );
00250    myTimeTable->setBlockUpdating();// block updating until this->show() is called
00251    mAddTickcountForTimeline = 1;
00252    myListView->setDefaultRenameAction( QListView::Reject );
00253 }
00254 
00255 KDGanttView::~KDGanttView()
00256 {
00257     // Don't call clearAll, it recreates widgets inside KDLegendWidget
00258   QPtrList<KDGanttViewTaskLink>  tll = taskLinks();
00259   tll.setAutoDelete( true );
00260   tll.clear();
00261   QPtrList<KDGanttViewTaskLinkGroup> tlg = myTaskLinkGroupList;
00262   tlg.setAutoDelete( true );
00263   tlg.clear();
00264   clear();
00265 
00266   // delete cut item, if there is any
00267     myCanvasView->resetCutPaste( 0 );
00268     delete myTimeTable;
00269 }
00288 void KDGanttView::vScrollBarAction( int action )
00289 {
00290     //qDebug() << "vScrollBarAction " << action ;
00291     switch ( mRepaintMode ) {
00292     case  No:
00293 
00294         break;
00295     case Medium:
00296         if ( action == 2 || action == 1 )
00297             forceRepaint();
00298         break;
00299     case Always:
00300         if ( action != 0 )
00301             forceRepaint();
00302         break;
00303     }
00304 
00305 }
00306 void KDGanttView::hScrollBarAction( int action )
00307 {
00308     //qDebug() << "hScrollBarAction " << action;
00309     if (  action == 2 ) { // left
00310         addTickLeft();
00311     } else if ( action == 1 ) {
00312         addTickRight();
00313     }
00314     switch ( mRepaintMode ) {
00315     case  No:
00316 
00317         break;
00318     case Medium:
00319         if ( action == 2 || action == 1 )
00320             forceRepaint();
00321         break;
00322     case Always:
00323         if ( action != 0 )
00324             forceRepaint();
00325         break;
00326     }
00327 }
00328 
00329 KDGanttViewItem* KDGanttView::createUserDefinedItem( QString kdGanttViewItemTypeAsString,
00330                                                      KDGanttViewItem* parent,
00331                                                      KDGanttViewItem* after,
00332                                                      const QString& lvtext,
00333                                                      const QString& name )
00334 {
00335     Q_UNUSED( kdGanttViewItemTypeAsString )
00336     Q_UNUSED( parent )
00337     Q_UNUSED( after )
00338     Q_UNUSED( lvtext )
00339     Q_UNUSED( name )
00340     qDebug() << "KDGanttView::createUserDefinedItem: Unknown type " << kdGanttViewItemTypeAsString;
00341     return 0;
00342 }
00387 KDGanttViewItem* KDGanttView::createNewItem( QString KDGanttViewItemTypeAsString,
00388                                              KDGanttViewItem* parent,
00389                                              KDGanttViewItem* after,
00390                                              const QString& lvtext,
00391                                              const QString& name )
00392 {
00393     KDGanttViewItem* retItem = 0;
00394     KDGanttViewItem::Type type = KDGanttViewItem::stringToType( KDGanttViewItemTypeAsString );
00395    switch( type ) {
00396     case KDGanttViewItem::Event:
00397         if ( parent ) {
00398             if ( after )
00399                 retItem = new KDGanttViewEventItem( parent, after, lvtext, name);
00400             else
00401                 retItem = new KDGanttViewEventItem( parent, lvtext, name);
00402         } else {
00403             if ( after )
00404                 retItem = new KDGanttViewEventItem( this, after, lvtext, name);
00405             else
00406                 retItem = new KDGanttViewEventItem( this, lvtext, name);
00407         }
00408         break;
00409     case KDGanttViewItem::Summary:
00410         if ( parent ) {
00411             if ( after )
00412                 retItem = new KDGanttViewSummaryItem( parent, after, lvtext, name);
00413             else
00414                 retItem = new KDGanttViewSummaryItem( parent, lvtext, name);
00415         } else {
00416             if ( after )
00417                 retItem = new KDGanttViewSummaryItem( this, after, lvtext, name);
00418             else
00419                 retItem = new KDGanttViewSummaryItem( this, lvtext, name);
00420         }
00421         break;
00422     case KDGanttViewItem::Task:
00423         if ( parent ) {
00424             if ( after )
00425                 retItem = new KDGanttViewTaskItem( parent, after, lvtext, name);
00426             else
00427                 retItem = new KDGanttViewTaskItem( parent, lvtext, name);
00428         } else {
00429             if ( after )
00430                 retItem = new KDGanttViewTaskItem( this, after, lvtext, name);
00431             else
00432                 retItem = new KDGanttViewTaskItem( this, lvtext, name);
00433         }
00434         break;
00435     case KDGanttViewItem::UnknownType:
00436         retItem = createUserDefinedItem( KDGanttViewItemTypeAsString,parent,after,lvtext,name );
00437         break;
00438     default:
00439         qDebug() << "Unknown type in KDGanttView::createNewItem()";
00440     }
00441    return retItem;
00442 }
00449 void KDGanttView::setListViewColumnWidth ( int col, int w )
00450 {
00451     myListView->setColumnWidth ( col, w );
00452 }
00453 
00463 QHeader * KDGanttView::listViewHeader () const
00464 {
00465     return myListView->header();
00466 }
00467 
00474 void KDGanttView::setAllOpen()
00475 {
00476 
00477     KDGanttViewItem* curItem = (KDGanttViewItem*) myListView->itemAt( QPoint (  myListView->width() - 10 , 5 ));
00478     bool block = myTimeTable->blockUpdating();
00479     myTimeTable->setBlockUpdating( true );
00480     KDGanttViewItem* temp = firstChild();
00481     while (temp != 0) {
00482       temp->setAllSubitemsExpanded( true );
00483       temp = temp->nextSibling();
00484     }
00485     myTimeTable->setBlockUpdating( block );
00486     myTimeTable->updateMyContent();
00487     if ( curItem && ! block ) {
00488         myListView->ensureItemVisible( curItem );
00489     }
00490 
00491 }
00498 void KDGanttView::setAllClose()
00499 {
00500     KDGanttViewItem* curItem = (KDGanttViewItem*) myListView->itemAt( QPoint (  myListView->width() - 10 , 5 ));
00501     bool block = myTimeTable->blockUpdating();
00502     myTimeTable->setBlockUpdating( true );
00503     KDGanttViewItem* temp = firstChild();
00504     while (temp != 0) {
00505         temp->setAllSubitemsExpanded( false );
00506         temp = temp->nextSibling();
00507     }
00508     myTimeTable->setBlockUpdating( block );
00509     myTimeTable->updateMyContent();
00510     if ( curItem && !block ) {
00511         myListView->ensureItemVisible( curItem );
00512     }
00513 }
00514 
00515 
00539 void KDGanttView::setUpdateEnabled( bool enable )
00540 {
00541   myTimeTable->setBlockUpdating( !enable );
00542   if ( enable ) {
00543       QTimer::singleShot( 0, this, SLOT ( updateGanttContent() ) );
00544       //updateGanttContent();
00545   }
00546 }
00547 void KDGanttView::updateGanttContent()
00548 {
00549     myTimeTable->updateMyContent();
00550     myCanvasView->setMyContentsHeight( 0 );
00551 }
00552 
00560 bool KDGanttView::getUpdateEnabled() const
00561 {
00562   return !myTimeTable->blockUpdating();
00563 }
00564 
00573 void KDGanttView::setGanttMaximumWidth( int w )
00574 {
00575   myTimeHeader->setMaximumWidth ( w );
00576 }
00584 int  KDGanttView::ganttMaximumWidth() const
00585 {
00586   return myTimeHeader->maximumWidth();
00587 }
00588 
00595 void KDGanttView::showEvent( QShowEvent * event )
00596 {
00597   if ( event->spontaneous() ) {
00598     KDGanttMinimizeSplitter::showEvent( event );
00599     return;
00600   }
00601 
00602   myTimeTable->setBlockUpdating( false );
00603   if (myCanvasView->horizontalScrollBar()->value() > 0 )
00604     myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->value()-1  );
00605   else
00606     myCanvasView->horizontalScrollBar()->setValue(1 );
00607   myTimeTable->updateMyContent();
00608 
00609   KDGanttMinimizeSplitter::showEvent( event );
00610 
00611   myCanvasView->setMyContentsHeight( 0 );
00612   if ( fCenterTimeLineAfterShow ) {
00613     fCenterTimeLineAfterShow = false;
00614     centerTimeline (dtCenterTimeLineAfterShow);
00615   }
00616 }
00624 void KDGanttView::closeEvent( QCloseEvent * event )
00625 {
00626   //qDebug() << "close ";
00627   if ( closingBlocked ) {
00628     event->ignore();
00629     return;
00630   }
00631   KDGanttMinimizeSplitter::closeEvent( event );
00632 }
00633 
00634 
00643 QSize KDGanttView::sizeHint() const
00644 {
00645   bool block = myTimeTable->blockUpdating();
00646   myTimeTable->setBlockUpdating( false );
00647   myTimeTable->updateMyContent();
00648   /* The below causes recursive calls to various size updating methods, which
00649    * cause QCanvas to hide and show items like mad, which is very slow. If
00650    * there is a legitimate gui updating issue here somewhere, it will need
00651    * to be solved differently.
00652    */
00653   //qApp->processEvents();
00654   int hintHeight = myTimeHeader->height();
00655   int legendHeight = 0;
00656   if ( showLegendButton() )
00657     legendHeight = myLegend->height();
00658   int listViewHeaderHeight = 0;
00659   if ( headerVisible() )
00660     listViewHeaderHeight = myListView->header()->height();
00661   if ( hintHeight < legendHeight+listViewHeaderHeight )
00662     hintHeight = legendHeight + listViewHeaderHeight;
00663   hintHeight += myListView->horizontalScrollBar()->height();
00664   if ( myLegend->isShown() )
00665     hintHeight += myLegend->legendSizeHint().height() +10;
00666   hintHeight += myTimeTable->minimumHeight()+myListView->frameWidth()*2+2;
00667   int hintWid = myListView->sizeHint().width();
00668   //hintWid += myTimeHeader->mySizeHint+myCanvasView->verticalScrollBar()->width();
00669   hintWid += myCanvasView->sizeHint().width();
00670   // add 10 for the splitter-bars
00671   // qDebug() << "sizehint " << hintWid+10 << " " << hintHeight;
00672   myTimeTable->setBlockUpdating( block );
00673   return QSize( hintWid+10, hintHeight );
00674 }
00675 
00676 
00684 void KDGanttView::setShowLegendButton( bool show )
00685 {
00686   _showLegendButton = show;
00687      if ( show )
00688          myLegend->show();
00689     else
00690          myLegend->hide();
00691      slotHeaderSizeChanged();
00692 }
00693 
00694 
00701 bool KDGanttView::showLegendButton() const
00702 {
00703     return _showLegendButton;
00704 }
00705 
00706 
00714 void KDGanttView::setHeaderVisible( bool visible )
00715 {
00716     if( visible )
00717         myListView->header()->show();
00718     else
00719         myListView->header()->hide();
00720     _showHeader = visible;
00721     slotHeaderSizeChanged();
00722 }
00723 
00724 
00731 bool KDGanttView::headerVisible() const
00732 {
00733   return _showHeader;
00734 }
00735 
00736 
00745 QDateTime KDGanttView::getDateTimeForCoordX(int coordX, bool global ) const
00746 {
00747   // default for myTimeHeader->getDateTimeForIndex() is local
00748    return myTimeHeader->getDateTimeForIndex(coordX, !global );
00749 }
00750 
00751 
00755 void KDGanttView::slotSelectionChanged( QListViewItem* item )
00756 {
00757     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00758     Q_ASSERT( gItem );
00759     emit lvSelectionChanged( gItem );
00760 }
00761 
00762 
00763 /*
00764   Implements a casted pass-through of the mouseButtonClicked() signal.
00765   Signals itemLeftClicked() , itemMidClicked() are emitted as well.
00766 */
00767 void KDGanttView::slotmouseButtonClicked ( int button, QListViewItem * item,
00768                                            const QPoint & pos, int c )
00769 {
00770   KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00771   emit lvMouseButtonClicked ( button , gItem,  pos,  c );
00772   if (gItem == 0 && myCurrentItem != 0 ) {
00773     myCurrentItem = 0;
00774     emit lvCurrentChanged( gItem );
00775   }
00776   if (gItem != 0 && myCurrentItem == 0 ) {
00777     myCurrentItem = gItem;
00778     emit lvCurrentChanged( gItem );
00779   }
00780 
00781   // removed - makes no sense!
00782   //emit mouseButtonClicked ( button , gItem,  pos,  c );
00783    {
00784     switch ( button ) {
00785     case  Qt::LeftButton:
00786       emit lvItemLeftClicked( gItem );
00787       emit itemLeftClicked( gItem );
00788       break;
00789     case  Qt::MidButton:
00790       emit lvItemMidClicked( gItem );
00791       emit itemMidClicked( gItem );
00792       break;
00793     }
00794   }
00795 }
00796 
00797 
00798 /*
00799   Implements a casted pass-through of the contextMenuRequested() signal.
00800   The signal itemRightClicked() is emitted as well;
00801   the position is the global position.
00802 */
00803 void KDGanttView::slotcontextMenuRequested ( QListViewItem * item, const QPoint & pos, int col )
00804 {
00805     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00806     emit lvContextMenuRequested ( gItem,  pos,  col );
00807     emit lvItemRightClicked( gItem );
00808     emit itemRightClicked( gItem );
00809 }
00810 
00811 /*
00812   Implements a casted pass-through of the collapsed() signal.
00813 */
00814 void KDGanttView::slotItemCollapsed ( QListViewItem * item )
00815 {
00816    {
00817     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00818     emit itemCollapsed ( gItem );
00819   }
00820 }
00821 
00822 
00823 /*
00824   Implements a casted pass-through of the  expanded() signal.
00825 */
00826 void KDGanttView::slotItemExpanded ( QListViewItem * item )
00827 {
00828    {
00829        KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00830        emit itemExpanded( gItem );
00831    }
00832 }
00833 
00834 
00835 
00836 
00837 void KDGanttView::emptySpaceDoubleClicked( QMouseEvent * e )
00838 {
00839     emit dateTimeDoubleClicked( getDateTimeForCoordX( e->x(), false ) );
00840 }
00841 
00842 
00843 /*
00844   Implements a casted pass-through of the currentChanged() signal.
00845 */
00846 void KDGanttView::slotCurrentChanged ( QListViewItem * item )
00847 {
00848     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00849     myCurrentItem = gItem;
00850     emit lvCurrentChanged( gItem );
00851 }
00852 
00853 
00854 /*
00855   Implements a casted pass-through of the itemRenamed() signal.
00856 */
00857 void KDGanttView::slotItemRenamed ( QListViewItem * item , int col,
00858                                     const QString & text )
00859 {
00860     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00861     emit lvItemRenamed( gItem,  col, text );
00862 }
00863 
00864 
00865 /*
00866   Implements a casted pass-through of the mouseButtonPressed() signal.
00867 */
00868 void KDGanttView::slotMouseButtonPressed ( int button, QListViewItem * item,
00869                                            const QPoint & pos, int c )
00870 {
00871     KDGanttViewItem* gItem = static_cast<KDGanttViewItem*>( item );
00872     emit lvMouseButtonPressed( button, gItem,  pos,  c  );
00873 }
00874 
00875 
00890 void KDGanttView::setRepaintMode( RepaintMode mode )
00891 {
00892 
00893   QScrollBar  *cvh, *cvv;
00894   cvh = myCanvasView->horizontalScrollBar();
00895   cvv = myCanvasView->verticalScrollBar();
00896   // first disconnect
00897   mRepaintMode = mode;
00898   cvh->disconnect( this );
00899   cvv->disconnect( this );
00900 
00901 #if QT_VERSION < 0x040000
00902   connect( myCanvasView->horizontalScrollBar(), SIGNAL( prevLine () ) ,this, SLOT( addTickLeft()));
00903   connect( myCanvasView->horizontalScrollBar(), SIGNAL( nextLine () ) ,this, SLOT( addTickRight()));
00904 #endif
00905   switch ( mode ) {
00906   case  No:
00907 
00908     break;
00909   case Medium:
00910     connect( cvv, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00911     connect( cvh, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00912 #if QT_VERSION < 0x040000
00913     connect( cvv, SIGNAL (nextLine () ) ,this, SLOT(forceRepaint()));
00914     connect( cvh, SIGNAL (nextLine () ) ,this, SLOT(forceRepaint()));
00915     connect( cvv, SIGNAL (prevLine () ) ,this, SLOT(forceRepaint()));
00916     connect( cvh, SIGNAL (prevLine () ) ,this, SLOT(forceRepaint()));
00917 #endif
00918     break;
00919   case Always:
00920 #if QT_VERSION < 0x040000
00921     connect( cvv, SIGNAL (valueChanged ( int ) ) ,this, SLOT(forceRepaint( int )));
00922     connect( cvh, SIGNAL (valueChanged ( int ) ) ,this, SLOT(forceRepaint( int )));
00923 #endif
00924     connect( cvv, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00925     connect( cvh, SIGNAL (sliderReleased () ) ,this, SLOT(forceRepaint()));
00926     break;
00927   }
00928 }
00929 
00930 
00931 void KDGanttView::forceRepaint( int )
00932 {
00933   if ( myTimeTable->blockUpdating() )
00934     return;
00935   // qDebug() << "forceRepaint( int ) ";
00936   myTimeTable->setAllChanged();
00937   myTimeTable->update();
00938 }
00939 
00940 
00941 void KDGanttView::slotHeaderSizeChanged()
00942 {
00943   int legendHeight = 0;
00944   if ( showLegendButton() )
00945     legendHeight = 24;
00946   int listViewHeaderHeight = 0;
00947   if ( headerVisible() )
00948     listViewHeaderHeight = myListView->header()->height();
00949   int timeHeaderHeight = myTimeHeader->height()+myTimeHeaderScroll->frameWidth()*2;;
00950   int diffY = timeHeaderHeight-legendHeight-listViewHeaderHeight;
00951   if ( diffY < 0 ) {
00952     spacerLeft->setFixedHeight( 0 );
00953     spacerRight->setFixedHeight(-diffY);
00954   } else {
00955     spacerRight->setFixedHeight( 0 );
00956     spacerLeft->setFixedHeight( diffY );
00957   }
00958   myLegend->setFixedHeight( legendHeight );
00959   myTimeHeaderContainer->setFixedHeight( timeHeaderHeight );
00960 }
00961 
00962 void KDGanttView::setLegendIsDockwindow( bool show )
00969 {
00970   bool isdock = myLegend->asDockwindow();
00971   if ( show != isdock ) {
00972     myLegend->setAsDockwindow(show);
00973     // legend is cleared - reinit legend with list
00974     legendItem* li;
00975     for ( li = myLegendItems.first(); li; li = myLegendItems.next() ) {
00976         if ( li->has2 )
00977             myLegend->addLegendItem(li->shape, li->color, li->text,li->shape2, li->color2, li->text2 );
00978         else
00979             myLegend->addLegendItem(li->shape, li->color, li->text );
00980     }
00981   }
00982 }
00983 
00984 bool KDGanttView::legendIsDockwindow() const
00991 {
00992     return myLegend->asDockwindow();
00993 }
00994 
00995 
01008 QDockWindow* KDGanttView::legendDockwindow() const
01009 {
01010   return myLegend->dockwindow();
01011 }
01012 
01013 
01022 void KDGanttView::setShowLegend( bool show )
01023 {
01024     myLegend->showMe(show);
01025 }
01026 
01027 
01036 bool KDGanttView::showLegend() const
01037 {
01038     return myLegend->isShown();
01039 }
01040 
01041 
01050 void KDGanttView::setShowListView( bool show )
01051 {
01052     if(listViewIsVisible == show) return;
01053     listViewIsVisible = show;
01054     if (listViewIsVisible)
01055         myListView->parentWidget()->show();
01056     else
01057         myListView->parentWidget()->hide();
01058 }
01059 
01060 
01067 bool KDGanttView::showListView() const
01068 {
01069     return listViewIsVisible;
01070 }
01071 
01072 
01082 void KDGanttView::setEditorEnabled( bool enable )
01083 {
01084   editorIsEnabled =  enable;
01085 }
01086 
01087 
01096 bool KDGanttView::editorEnabled() const
01097 {
01098     return editorIsEnabled;
01099 }
01100 
01101 
01110 void KDGanttView::setEditable( bool editable )
01111 {
01112   chartIsEditable =  editable;
01113 }
01114 
01115 
01123 bool KDGanttView::editable() const
01124 {
01125     return chartIsEditable;
01126 }
01127 
01128 
01140 bool KDGanttView::saveProject( QIODevice* device )
01141 {
01142     Q_ASSERT( device );
01143 
01144     QDomDocument doc = saveXML();
01145     if( device->isOpen() )
01146         device->close();
01147     if( device->open( IO_WriteOnly ) ) {
01148         QTextStream ts( device );
01149         ts << doc.toString();
01150         return true;
01151     } else
01152         return false;
01153 }
01154 
01155 
01167 bool KDGanttView::loadProject( QIODevice* device )
01168 {
01169     Q_ASSERT( device );
01170 
01171     if( device->isOpen() )
01172         device->close();
01173     if( device->open( IO_ReadOnly ) ) {
01174         QDomDocument doc( "GanttView" );
01175     QString err;
01176     int errline, errcol;
01177     if ( !doc.setContent( device, &err, &errline, &errcol ) ) {
01178       qDebug() << "KDGantt::Error parsing XML data at line " << errline << ". Message is: ";
01179       qDebug() << err;
01180       device->close();
01181       return false;
01182     }
01183         device->close();
01184         clearAll();
01185         return loadXML( doc );
01186     } else
01187         return false;
01188 }
01189 
01190 // slot, can be connected to menu action
01191 // Note: This should possibly have a setup dialog so the user can print
01192 //       something other than the default
01193 void KDGanttView::print()
01194 {
01195     print(0);
01196 }
01197 
01216 void KDGanttView::print( QPrinter* printer ,
01217                          bool printListView, bool printTimeLine,
01218                          bool printLegend )
01219 {
01220   bool deletePrinter = false;
01221   if (! printer ) {
01222     printer = new QPrinter();
01223     deletePrinter = true;
01224     QPrintDialog dialog(printer);
01225     if ( !dialog.exec() ) {
01226       delete printer;
01227       return;
01228     }
01229   }
01230   // now we have a printer to print on
01231   QPainter p( printer );
01232   // get the paper metrics
01233   float dx, dy;
01234   // get the size of the desired output for scaling.
01235   // here we want to print all: ListView, TimeLine, and Legend
01236   // for this purpose, we call drawContents() with a 0 pointer as painter
01237   QSize size = drawContents( 0, printListView, printTimeLine, printLegend );
01238 
01239   // at the top, we want to print current time/date
01240   QString date = "Printing Time: " + QDateTime::currentDateTime().toString();
01241   int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
01242   p.drawText( 0, 0, date );
01243 
01244   // compute the scale
01245 #if QT_VERSION >= 0x040000
01246   dx = (float) printer->width()  / (float)size.width();
01247   dy  = (float)(printer->height() - ( 2 * hei )) / (float)size.height();
01248 #else
01249   QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
01250   dx = (float) m.width()  / (float)size.width();
01251   dy  = (float)(m.height() - ( 2 * hei )) / (float)size.height();
01252 #endif
01253   float scale;
01254   // scale to fit the width or height of the paper
01255   if ( dx < dy )
01256     scale = dx;
01257   else
01258     scale = dy;
01259   // set the scale
01260   p.scale( scale, scale );
01261   // now printing with y offset:  2 hei
01262   p.translate( 0, 2*hei );
01263   drawContents( &p, printListView, printTimeLine, printLegend );
01264   // the drawContents() has the side effect, that the painter translation is
01265   // after drawContents() set to the bottom of the painted stuff
01266   // for instance a
01267   // p.drawText(0, 0, "printend");
01268   // would be painted directly below the paintout of drawContents()
01269   p.end();
01270   if ( deletePrinter )
01271     delete printer;
01272 }
01273 
01274 
01314 QSize KDGanttView::drawContents( QPainter* p,
01315               bool drawListView , bool drawTimeLine, bool drawLegend )
01316 {
01317     QSize size;
01318     int lvX, lvY, thX, thY, tlX, tlY, lwX, lwY, allX, allY;
01319     lvX = myListView->contentsWidth();
01320     lvY = myTimeTable->minimumHeight() + 2;
01321     thX = myTimeHeader->width();
01322     thY = myTimeHeader->height();
01323     tlX = myCanvasView->canvas()->width();
01324     tlY = lvY;
01325     lwX = myLegend->legendSize().width();
01326     lwY = myLegend->legendSize().height();
01327     allX = 0;
01328     allY = 0;
01329     if ( drawListView ) {
01330         allX += lvX;
01331         allY += tlY;
01332     }
01333     if ( drawTimeLine ) {
01334         allX += thX;
01335         allY += thY;
01336     }
01337     if ( drawLegend ) {
01338         allY += lwY;
01339         if ( allX < lwX )
01340             allX = lwX ;
01341     }
01342     size = QSize( allX, allY );
01343     int temp = 0;
01344     if ( p ) {
01345         if ( drawListView ) {
01346             if ( drawTimeLine )
01347                 temp =  thY;
01348             p->translate( 0, temp );
01349             if ( headerVisible() ) {
01350                 p->translate( 0,  -myListView->header()->height());
01351                 int cou = myListView->header()->count();
01352                 int iii;
01353                 QRect rect ( 0,0,0, myListView->header()->height());
01354                 for ( iii = 0; iii < cou; ++iii ) {
01355                     rect.setLeft ( myListView->header()->sectionPos( iii ) );
01356                     rect.setRight ( myListView->header()->sectionPos( iii ) + myListView->header()->sectionSize (iii));
01357                     myListView->header()->paintSection ( p,  myListView->header()->mapToIndex (iii),  rect );
01358                 }
01359                 p->translate( 0,  myListView->header()->height());
01360             }
01361             myListView->drawToPainter( p );
01362             p->translate( lvX, -temp);
01363         }
01364         if ( drawTimeLine ) {
01365             p->translate( myCanvasView->frameWidth(), 0);
01366             myTimeHeader->repaintMe( 0, myTimeHeader->width(), p );
01367             p->translate( -myCanvasView->frameWidth(), thY);
01368             myCanvasView->drawToPainter( p );
01369             if ( drawListView )
01370                 p->translate( -lvX, tlY);
01371             else
01372                 p->translate( 0, tlY);
01373         } else {
01374             if ( drawListView )
01375                 p->translate( -lvX, 0 );
01376         }
01377         if ( drawLegend ) {
01378             myLegend->drawToPainter( p );
01379             p->translate( 0, lwY );
01380         }
01381     }
01382     return size;
01383 }
01384 
01398 void KDGanttView::setZoomFactor( double factor, bool absolute )
01399 {
01400     myTimeHeader->zoom(factor,absolute);
01401 }
01402 
01403 
01411 double KDGanttView::zoomFactor() const
01412 {
01413     return myTimeHeader->zoomFactor();
01414 }
01415 
01416 
01425 void KDGanttView::zoomToFit()
01426 {
01427   myTimeHeader->zoomToFit();
01428 }
01429 
01430 
01443 void KDGanttView::zoomToSelection( const QDateTime& start,  const QDateTime&  end )
01444 {
01445 
01446   myTimeHeader->zoomToSelection( start, end);
01447 
01448 }
01462 void KDGanttView::zoomToSelectionAndSetStartEnd( const QDateTime& start,  const QDateTime&  end )
01463 {
01464     /*
01465     myTimeHeader->setHorizonStart(start);
01466     myTimeHeader->setHorizonEnd(start);
01467     myTimeHeader->zoomToSelection( start, end);
01468     */
01469     myTimeHeader->zoomToSelectionAndSetStartEnd( start, end);
01470 }
01471 
01472 
01479 void KDGanttView::ensureVisible( KDGanttViewItem* item )
01480 {
01481     if ( item == 0 ) return;
01482     myListView->ensureItemVisible (item);
01483 }
01484 
01485 
01506 void KDGanttView::centerTimeline( const QDateTime& center )
01507 {
01508     myTimeHeader->centerDateTime( center, mUserHorizonChangeEnabled );
01509 }
01510 
01511 
01525 void KDGanttView::centerTimelineAfterShow( const QDateTime& center )
01526 {
01527   myTimeHeader->centerDateTime( center );
01528   if ( isVisible() ) return;
01529   dtCenterTimeLineAfterShow = center;
01530   fCenterTimeLineAfterShow = true;
01531 }
01532 
01537 void KDGanttView::setTimelineToStart()
01538 {
01539   myCanvasView->horizontalScrollBar()->setValue( 0 );
01540 }
01541 
01542 
01546 void KDGanttView::setTimelineToEnd()
01547 {
01548  myCanvasView->horizontalScrollBar()->setValue(myCanvasView->horizontalScrollBar()->maximum());
01549 }
01550 
01551 
01562 void KDGanttView::addTicksLeft( int num )
01563 {
01564   myTimeHeader->addTickLeft( num  );
01565 }
01566 
01567 
01577 void KDGanttView::addTicksRight( int num )
01578 {
01579   myTimeHeader->addTickRight( num );
01580 }
01581 
01582 
01587 void KDGanttView::center( KDGanttViewItem* item )
01588 {
01589     ensureVisible(item);
01590     int x =  myListView->contentsWidth()/2;
01591     int y = myListView->itemPos (item );
01592     myListView->center(x,y);
01593 }
01594 
01595 
01602 void KDGanttView::setShowTaskLinks( bool show )
01603 {
01604     myTimeTable->setShowTaskLinks(show);
01605 
01606 }
01607 
01608 
01615 bool KDGanttView::showTaskLinks() const
01616 {
01617     return  myTimeTable->showTaskLinks();
01618 }
01619 
01620 
01628 void KDGanttView::setFont(const QFont& font)
01629 {
01630     myListView->setFont(font);
01631     myListView->repaint();
01632     myTimeHeader->setFont(font);
01633     myLegend->setFont( font );
01634     QWidget::setFont( font );
01635     setScale(scale());
01636     QTimer::singleShot( 0, this, SLOT( slotHeaderSizeChanged() ) );
01637 }
01638 
01639 
01664 void KDGanttView::setShowHeaderPopupMenu( bool show,
01665                                           bool showZoom,
01666                                           bool showScale,
01667                                           bool showTime,
01668                                           bool showYear,
01669                                           bool showGrid,
01670                                           bool showPrint)
01671 {
01672     if ( show && myTimeHeader->showPopupMenu() ) return;
01673     myTimeHeader->setShowPopupMenu( show,showZoom,showScale,showTime,
01674                                     showYear,showGrid,showPrint );
01675 }
01676 
01677 
01684 bool KDGanttView::showHeaderPopupMenu() const
01685 {
01686     return myTimeHeader->showPopupMenu();
01687 }
01688 //****************************************************
01689 
01690 
01704 void KDGanttView::setShowTimeTablePopupMenu( bool show )
01705 {
01706     myCanvasView->setShowPopupMenu( show );
01707 }
01708 
01709 
01716 bool KDGanttView::showTimeTablePopupMenu() const
01717 {
01718     return myCanvasView->showPopupMenu();
01719 }
01720 
01721 
01739 void KDGanttView::setShapes( KDGanttViewItem::Type type,
01740                              KDGanttViewItem::Shape start,
01741                              KDGanttViewItem::Shape middle,
01742                              KDGanttViewItem::Shape end,
01743                              bool overwriteExisting )
01744 {
01745     if ( overwriteExisting ) {
01746       QListViewItemIterator it(myListView);
01747       for ( ; it.current(); ++it ) {
01748         if ( ((KDGanttViewItem*)it.current())->type() == type)
01749       ((KDGanttViewItem*)it.current())->setShapes(start,middle, end );
01750       }
01751     }
01752     int index = getIndex( type );
01753 
01754     if ( index < 0 ) {
01755       return;
01756     }
01757 
01758     myDefaultShape [index*3] = start;
01759     myDefaultShape [index*3+1] = middle;
01760     myDefaultShape [index*3+2] = end;
01761     undefinedShape[index] = false;
01762 }
01763 
01764 
01777 bool KDGanttView::shapes( KDGanttViewItem::Type type,
01778                           KDGanttViewItem::Shape& start,
01779                           KDGanttViewItem::Shape& middle,
01780                           KDGanttViewItem::Shape& end ) const
01781 {
01782     int index = getIndex( type );
01783 
01784     if ( index < 0 ) {
01785         return false;
01786     }
01787 
01788     start = myDefaultShape [index*3];
01789     middle = myDefaultShape [index*3+1];
01790     end = myDefaultShape [index*3+2];
01791     return !undefinedShape[index];
01792 }
01793 
01794 
01812 void KDGanttView::setColors( KDGanttViewItem::Type type,
01813                              const QColor& start, const QColor& middle,
01814                              const QColor& end,
01815                              bool overwriteExisting )
01816 {
01817     if ( overwriteExisting ) {
01818       QListViewItemIterator it(myListView);
01819       for ( ; it.current(); ++it ) {
01820         if ( ((KDGanttViewItem*)it.current())->type() == type)
01821       ((KDGanttViewItem*)it.current())->setColors(start,middle, end );
01822       }
01823     }
01824     int index = getIndex( type );
01825     if (index < 0) return;
01826     myColor [index*3] = start;
01827     myColor [index*3+1] = middle;
01828     myColor [index*3+2] = end;
01829     undefinedColor[index] = false;
01830 }
01831 
01832 
01845 bool KDGanttView::colors( KDGanttViewItem::Type type,
01846                           QColor& start, QColor& middle, QColor& end ) const
01847 {
01848     int index = getIndex( type );
01849     if (index < 0) return false;
01850     start = myColor [index*3];
01851     middle = myColor [index*3+1];
01852     end = myColor [index*3+2];
01853     return !undefinedColor[index];
01854 }
01855 
01856 
01876 void KDGanttView::setHighlightColors( KDGanttViewItem::Type type,
01877                                       const QColor& start,
01878                                       const QColor& middle,
01879                                       const QColor& end,
01880                                       bool overwriteExisting )
01881 {
01882     if ( overwriteExisting ) {
01883       QListViewItemIterator it(myListView);
01884       for ( ; it.current(); ++it ) {
01885         if ( ((KDGanttViewItem*)it.current())->type() == type)
01886       ((KDGanttViewItem*)it.current())->setHighlightColors(start,middle, end );
01887       }
01888     }
01889     int index = getIndex( type );
01890     if (index < 0) return;
01891 
01892     myColorHL [index*3] = start;
01893     myColorHL [index*3+1] = middle;
01894     myColorHL [index*3+2] = end;
01895     undefinedColorHL[index] = false;
01896 
01897 }
01898 
01899 
01914 bool KDGanttView::highlightColors( KDGanttViewItem::Type type,
01915                                    QColor& start, QColor& middle,
01916                                    QColor& end ) const
01917 {
01918     int index = getIndex( type );
01919     if (index < 0) return false;
01920 
01921     start = myColorHL [index*3];
01922     middle = myColorHL [index*3+1];
01923     end = myColorHL [index*3+2];
01924     return !undefinedColorHL[index];
01925 }
01926 
01927 
01935 void KDGanttView::setTextColor( const QColor& color )
01936 {
01937     QListViewItemIterator it(myListView);
01938     for ( ; it.current(); ++it ) {
01939     ((KDGanttViewItem*)it.current())->setTextColor(color);
01940     }
01941     myTextColor = color;
01942 }
01943 
01944 
01951 QColor KDGanttView::textColor() const
01952 {
01953     return myTextColor;
01954 }
01955 
01956 
01967 void KDGanttView::setNoInformationBrush( const QBrush& brush )
01968 {
01969   myTimeTable->setNoInformationBrush( brush );
01970 }
01971 
01972 
01979 QBrush KDGanttView::noInformationBrush() const
01980 {
01981   return myTimeTable->noInformationBrush();
01982 }
01983 
01984 
01990 void KDGanttView::clearLegend( )
01991 {
01992     setShowLegend( false );
01993     myLegend->clearLegend();
01994     myLegendItems.setAutoDelete( true );
01995     myLegendItems.clear();
01996 }
01997 
01998 
02007 void KDGanttView::addLegendItem( KDGanttViewItem::Shape shape,
02008                                  const QColor& shapeColor,
02009                                  const QString& text )
02010 {
02011     myLegend->addLegendItem( shape,shapeColor,text );
02012     legendItem* item = new legendItem;
02013     item->shape = shape;
02014     item->color = shapeColor;
02015     item->text = text;
02016     item->has2 = false;
02017     myLegendItems.append( item );
02018 }
02019 
02032 void KDGanttView::addLegendItem( KDGanttViewItem::Shape shape,
02033                                  const QColor& shapeColor,
02034                                  const QString& text,
02035                                  KDGanttViewItem::Shape shape2,
02036                                  const QColor& shapeColor2,
02037                                  const QString& text2 )
02038 {
02039     myLegend->addLegendItem( shape,shapeColor,text,shape2,shapeColor2,text2 );
02040     legendItem* item = new legendItem;
02041     item->shape = shape;
02042     item->color = shapeColor;
02043     item->text = text;
02044     item->has2 = true;
02045     item->shape2 = shape2;
02046     item->color2 = shapeColor2;
02047     item->text2 = text2;
02048 
02049     myLegendItems.append( item );
02050 }
02051 
02052 
02053 
02061 void KDGanttView::setHorizonStart( const QDateTime& start )
02062 {
02063     myTimeHeader->setHorizonStart(start);
02064 }
02065 
02066 
02073 QDateTime KDGanttView::horizonStart() const
02074 {
02075     return myTimeHeader->horizonStart();
02076 }
02077 
02078 
02086 void KDGanttView::setHorizonEnd( const QDateTime& end )
02087 {
02088     myTimeHeader->setHorizonEnd(end);
02089 }
02090 
02091 
02099 QDateTime KDGanttView::horizonEnd() const
02100 {
02101     return myTimeHeader->horizonEnd();
02102 }
02103 
02112 void KDGanttView::setScaleSilent( Scale unit )
02113 {
02114     myTimeHeader->setScale( unit, false );
02115 }
02116 
02124 void KDGanttView::setScale( Scale unit )
02125 {
02126     myTimeHeader->setScale( unit );
02127 }
02128 
02129 
02136 KDGanttView::Scale KDGanttView::scale() const
02137 {
02138     return myTimeHeader->scale();
02139 }
02140 
02141 
02148 void KDGanttView::setMaximumScale( Scale unit )
02149 {
02150     myTimeHeader->setMaximumScale( unit );
02151 }
02152 
02153 
02160 KDGanttView::Scale KDGanttView::maximumScale() const
02161 {
02162     return myTimeHeader->maximumScale();
02163 }
02164 
02165 
02172 void KDGanttView::setMinimumScale( Scale unit )
02173 {
02174     myTimeHeader->setMinimumScale( unit );
02175 }
02176 
02177 
02184 KDGanttView::Scale KDGanttView::minimumScale() const
02185 {
02186     return myTimeHeader->minimumScale();
02187 }
02188 
02189 
02199 void KDGanttView::setAutoScaleMinorTickCount( int count )
02200 {
02201   myTimeHeader->setAutoScaleMinorTickCount( count );
02202 }
02203 
02204 
02211 int KDGanttView::autoScaleMinorTickCount() const
02212 {
02213   return myTimeHeader->autoScaleMinorTickCount();
02214 }
02215 
02216 
02225 void KDGanttView::setMinimumColumnWidth( int width )
02226 {
02227     myTimeHeader->setMinimumColumnWidth( width );
02228 }
02229 
02230 
02237 int KDGanttView::minimumColumnWidth() const
02238 {
02239     return myTimeHeader->minimumColumnWidth();
02240 }
02241 
02242 
02250 void KDGanttView::setYearFormat( YearFormat format )
02251 {
02252     myTimeHeader->setYearFormat(format );
02253 }
02254 
02255 
02262 KDGanttView::YearFormat KDGanttView::yearFormat() const
02263 {
02264     return myTimeHeader->yearFormat();
02265 }
02266 
02267 
02276 void KDGanttView::setHourFormat( HourFormat format )
02277 {
02278     myTimeHeader->setHourFormat( format );
02279 }
02280 
02281 
02289 KDGanttView::HourFormat KDGanttView::hourFormat() const
02290 {
02291     return myTimeHeader->hourFormat();
02292 }
02293 
02294 
02302 void KDGanttView::setShowTicks( ShowTicksType show )
02303 {
02304     myTimeHeader->setShowTicks(show );
02305 }
02306 
02307 
02314 KDGanttView::ShowTicksType KDGanttView::showTicks() const
02315 {
02316     return myTimeHeader->showTicks();
02317 }
02318 
02319 
02320 
02338 void KDGanttView::setColumnBackgroundColor( const QDateTime& column,
02339                                             const QColor& color ,
02340                                             Scale mini, Scale maxi )
02341 {
02342   myTimeHeader->setColumnBackgroundColor( column, color,mini,maxi );
02343 }
02344 
02345 #if 0
02346 
02374 void KDGanttView::setIntervalBackgroundColor( const QDateTime& start,
02375                                               const QDateTime& end,
02376                                               const QColor& color ,
02377                                               int priority,
02378                                               Scale mini, Scale maxi )
02379 {
02380     myTimeHeader->setIntervalBackgroundColor( start, end, color, priority, mini,maxi );
02381 }
02382 
02383 
02402 bool KDGanttView::changeBackgroundInterval( const QDateTime& oldstart,
02403                    const QDateTime& oldend,
02404                    const QDateTime& newstart,
02405                    const QDateTime& newend )
02406 {
02407   return myTimeHeader->changeBackgroundInterval( oldstart, oldend,
02408                          newstart, newend );
02409 }
02410 
02420 bool KDGanttView::deleteBackgroundInterval( const QDateTime& start,
02421                            const QDateTime& end)
02422 {
02423   return myTimeHeader->deleteBackgroundInterval( start, end );
02424 }
02425 #endif
02426 
02432 void KDGanttView::addIntervalBackgroundColor( KDIntervalColorRectangle* newItem )
02433 {
02434   myTimeHeader->addIntervalBackgroundColor( newItem );
02435 }
02436 
02445 void KDGanttView::clearBackgroundColor()
02446 {
02447   myTimeHeader->clearBackgroundColor();
02448 }
02449 
02450 
02459 QColor KDGanttView::columnBackgroundColor( const QDateTime& column ) const
02460 {
02461     return myTimeHeader->columnBackgroundColor( column ) ;
02462 }
02463 
02464 
02473 void KDGanttView::setWeekendBackgroundColor( const QColor& color )
02474 {
02475     myTimeHeader->setWeekendBackgroundColor( color );
02476 }
02477 
02478 
02485 QColor KDGanttView::weekendBackgroundColor() const
02486 {
02487     return myTimeHeader->weekendBackgroundColor();
02488 }
02489 
02490 
02501 void KDGanttView::setWeekdayBackgroundColor( const QColor& color, int  weekday )
02502 {
02503   myTimeHeader->setWeekdayBackgroundColor( color,  weekday );
02504 }
02505 
02506 
02514 QColor KDGanttView::weekdayBackgroundColor(int weekday) const
02515 {
02516   return myTimeHeader->weekdayBackgroundColor( weekday);
02517 }
02518 
02519 
02520 
02531 void KDGanttView::setWeekendDays( int start, int end )
02532 {
02533     myTimeHeader->setWeekendDays( start,  end );
02534 }
02535 
02536 
02544 void KDGanttView::weekendDays( int& start, int& end ) const
02545 {
02546     myTimeHeader->weekendDays( start,  end );
02547 }
02548 
02549 
02663 void KDGanttView::setMajorScaleCount( int count )
02664 {
02665     myTimeHeader->setMajorScaleCount(count );
02666 }
02667 
02668 
02675 int KDGanttView::majorScaleCount() const
02676 {
02677     return myTimeHeader->majorScaleCount();
02678 }
02679 
02680 
02687 void KDGanttView::setMinorScaleCount( int count )
02688 {
02689     myTimeHeader->setMinorScaleCount(count );
02690 }
02691 
02692 
02699 int KDGanttView::minorScaleCount() const
02700 {
02701     return myTimeHeader->minorScaleCount();
02702 
02703 }
02704 
02705 
02718 void KDGanttView::setDefaultColor( KDGanttViewItem::Type type,
02719                                    const QColor& color,
02720                                    bool overwriteExisting )
02721 {
02722     if ( overwriteExisting ) {
02723       QListViewItemIterator it(myListView);
02724       for ( ; it.current(); ++it ) {
02725         if ( ((KDGanttViewItem*)it.current())->type() == type)
02726       ((KDGanttViewItem*)it.current())->setDefaultColor(color );
02727       }
02728     }
02729     int index = getIndex( type );
02730     myDefaultColor [index] = color;
02731 }
02732 
02733 
02734 
02745 QColor KDGanttView::defaultColor( KDGanttViewItem::Type type ) const
02746 {
02747   int index = getIndex( type );
02748   return myDefaultColor [index];
02749 }
02750 
02751 
02764 void KDGanttView::setDefaultHighlightColor( KDGanttViewItem::Type type,
02765                                             const QColor& color,
02766                                             bool overwriteExisting )
02767 {
02768     if ( overwriteExisting ) {
02769       QListViewItemIterator it(myListView);
02770       for ( ; it.current(); ++it ) {
02771         if ( ((KDGanttViewItem*)it.current())->type() == type)
02772       ((KDGanttViewItem*)it.current())->setDefaultHighlightColor(color );
02773       }
02774     }
02775     int index = getIndex( type );
02776     myDefaultColorHL [index] = color;
02777 }
02778 
02779 
02780 
02791 QColor KDGanttView::defaultHighlightColor( KDGanttViewItem::Type type ) const
02792 {
02793   int index = getIndex( type );
02794   return myDefaultColorHL [index];
02795 }
02796 
02797 
02803 KDGanttViewItem* KDGanttView::firstChild() const
02804 {
02805     return (KDGanttViewItem*)myListView->firstChild();
02806 
02807 }
02825 void KDGanttView::setCalendarMode( bool mode )
02826 {
02827   myListView->setCalendarMode( mode );
02828 }
02829 
02830 
02838 bool  KDGanttView::calendarMode() const
02839 {
02840   return  myListView->calendarMode();
02841 }
02842 
02843 
02844 
02854 void KDGanttView::setDisplaySubitemsAsGroup( bool show )
02855 {
02856  QListViewItemIterator it( myListView );
02857  for ( ; it.current(); ++it ) {
02858    KDGanttViewItem* currentItem = ( KDGanttViewItem* )it.current();
02859    currentItem->setDisplaySubitemsAsGroup( show );
02860  }
02861  _displaySubitemsAsGroup = show;
02862 }
02863 
02864 
02873 bool KDGanttView::displaySubitemsAsGroup() const
02874 {
02875   return _displaySubitemsAsGroup;
02876 }
02877 
02878 
02886 void KDGanttView::setDisplayEmptyTasksAsLine( bool show )
02887 {
02888   _displayEmptyTasksAsLine = show;
02889 }
02890 
02891 
02898 bool KDGanttView::displayEmptyTasksAsLine() const
02899 {
02900   return _displayEmptyTasksAsLine;
02901 }
02902 
02903 
02918 void KDGanttView::setHorBackgroundLines( int count, QBrush brush )
02919 {
02920   myTimeTable->setHorBackgroundLines(  count, brush );
02921 }
02922 
02923 
02933 int KDGanttView::horBackgroundLines( QBrush& brush ) const
02934 {
02935   return myTimeTable->horBackgroundLines( brush );
02936 }
02937 
02938 
02944 KDGanttViewItem* KDGanttView::lastItem() const
02945 {
02946     return (KDGanttViewItem*)myListView->lastItem ();
02947 }
02948 
02949 
02955 QPtrList<KDGanttViewTaskLink> KDGanttView::taskLinks() const
02956 {
02957     QPtrList<KDGanttViewTaskLink> retVal = myTimeTable->taskLinks();
02958     return retVal;
02959 }
02960 
02961 
02967 QPtrList<KDGanttViewTaskLinkGroup> KDGanttView::taskLinkGroups() const
02968 {
02969     return myTaskLinkGroupList;
02970 }
02971 
02972 
02980 bool KDGanttView::loadXML( const QDomDocument& doc )
02981 {
02982     bool block = getUpdateEnabled();
02983     setUpdateEnabled( false );
02984     QDomElement docRoot = doc.documentElement(); // ChartParams element
02985     QDomNode node = docRoot.firstChild();
02986     while( !node.isNull() ) {
02987         QDomElement element = node.toElement();
02988         if( !element.isNull() ) { // was really an element
02989             QString tagName = element.tagName();
02990             if( tagName == "ShowLegend" ) {
02991                 bool value;
02992                 if( KDGanttXML::readBoolNode( element, value ) )
02993                     setShowLegend( value );
02994             } else if( tagName == "ShowLegendButton" ) {
02995                 bool value;
02996                 if( KDGanttXML::readBoolNode( element, value ) )
02997                     setShowLegendButton( value );
02998             } else if( tagName == "LegendIsDockWindow" ) {
02999                 bool value;
03000                 if( KDGanttXML::readBoolNode( element, value ) )
03001                     setLegendIsDockwindow( value );
03002             } else if( tagName == "ShowListView" ) {
03003                 bool value;
03004                 if( KDGanttXML::readBoolNode( element, value ) )
03005                     setShowListView( value );
03006             } else if( tagName == "ShowHeader" ) {
03007                 bool value;
03008                 if( KDGanttXML::readBoolNode( element, value ) )
03009                     setHeaderVisible( value );
03010             } else if( tagName == "ShowTaskLinks" ) {
03011                 bool value;
03012                 if( KDGanttXML::readBoolNode( element, value ) )
03013                     setShowTaskLinks( value );
03014             } else if( tagName == "EditorEnabled" ) {
03015                 bool value;
03016                 if( KDGanttXML::readBoolNode( element, value ) )
03017                     setEditorEnabled( value );
03018             } else if( tagName == "DisplayEmptyTasksAsLine" ) {
03019                 bool value;
03020                 if( KDGanttXML::readBoolNode( element, value ) )
03021                     setDisplayEmptyTasksAsLine( value );
03022             } else if( tagName == "GlobalFont" ) {
03023                 QFont font;
03024                 if( KDGanttXML::readFontNode( element, font ) )
03025                     setFont( font );
03026             } else if( tagName == "HorizonStart" ) {
03027                 QDateTime value;
03028                 if( KDGanttXML::readDateTimeNode( element, value ) )
03029                     setHorizonStart( value );
03030             } else if( tagName == "HorizonEnd" ) {
03031                 QDateTime value;
03032                 if( KDGanttXML::readDateTimeNode( element, value ) )
03033                     setHorizonEnd( value );
03034             } else if( tagName == "Scale" ) {
03035                 QString value;
03036                 if( KDGanttXML::readStringNode( element, value ) )
03037                     setScale( stringToScale( value ) );
03038             } else if( tagName == "MinimumScale" ) {
03039                 QString value;
03040                 if( KDGanttXML::readStringNode( element, value ) )
03041                     setMinimumScale( stringToScale( value ) );
03042             } else if( tagName == "MaximumScale" ) {
03043                 QString value;
03044                 if( KDGanttXML::readStringNode( element, value ) )
03045                     setMaximumScale( stringToScale( value ) );
03046             } else if( tagName == "YearFormat" ) {
03047                 QString value;
03048                 if( KDGanttXML::readStringNode( element, value ) )
03049                     setYearFormat( stringToYearFormat( value ) );
03050             } else if( tagName == "HourFormat" ) {
03051                 QString value;
03052                 if( KDGanttXML::readStringNode( element, value ) )
03053                     setHourFormat( stringToHourFormat( value ) );
03054             } else if( tagName == "ShowMinorTicks" ) {
03055                 bool value;
03056                 if( KDGanttXML::readBoolNode( element, value ) ) {
03057                   if ( value ) setShowTicks( ShowMinorTicks );
03058                 }
03059             } else if( tagName == "ShowMajorTicks" ) {
03060                 bool value;
03061                 if( KDGanttXML::readBoolNode( element, value ) ) {
03062                   if ( value ) setShowTicks( ShowMajorTicks );
03063                 }
03064             } else if( tagName == "ShowTicks" ) {
03065                 int value;
03066                 if( KDGanttXML::readIntNode( element, value ) )
03067                     setShowTicks( (ShowTicksType)value );
03068             } else if( tagName == "DragEnabled" ) {
03069                 bool value;
03070                 if( KDGanttXML::readBoolNode( element, value ) )
03071                     setDragEnabled( value );
03072             } else if( tagName == "DropEnabled" ) {
03073                 bool value;
03074                 if( KDGanttXML::readBoolNode( element, value ) )
03075                     setDropEnabled( value );
03076             }  else if( tagName == "TickcountForTimeline" ) {
03077                 int value;
03078                 if( KDGanttXML::readIntNode( element, value ) )
03079                     setAddTickcountForTimeline( value );
03080             } else if( tagName == "DisplaySubitemsAsGroup" ) {
03081                 bool value;
03082                 if( KDGanttXML::readBoolNode( element, value ) )
03083                     _displaySubitemsAsGroup = value;
03084             } else if( tagName == "WeekScaleShowNumber" ) {
03085                 bool value;
03086                 if( KDGanttXML::readBoolNode( element, value ) )
03087                     setWeekScaleShowNumber( value );
03088             } else if( tagName == "WeekStartsMonday" ) {
03089                 bool value;
03090                 if( KDGanttXML::readBoolNode( element, value ) )
03091                     setWeekStartsMonday( value );
03092             } else if( tagName == "UserHorizonChangeEnabled" ) {
03093                 bool value;
03094                 if( KDGanttXML::readBoolNode( element, value ) )
03095                     setUserHorizonChangeEnabled( value );
03096             } else if( tagName == "TimeHeaderDatetimeFormatHour" ) {
03097                 QString value;
03098                 if( KDGanttXML::readStringNode( element, value ) )
03099                     setTimeHeaderDatetimeFormatHour( value );
03100             } else if( tagName == "TimeHeaderDatetimeFormatSecond" ) {
03101                 QString value;
03102                 if( KDGanttXML::readStringNode( element, value ) )
03103                     setTimeHeaderDatetimeFormatSecond( value );
03104             } else if( tagName == "TimeHeaderDatetimeFormatMinute" ) {
03105                 QString value;
03106                 if( KDGanttXML::readStringNode( element, value ) )
03107                     setTimeHeaderDatetimeFormatMinute( value );
03108             } else if( tagName == "TimeHeaderDateFormatDay" ) {
03109                 QString value;
03110                 if( KDGanttXML::readStringNode( element, value ) )
03111                     setTimeHeaderDateFormatDay( value );
03112             } else if( tagName == "TimeHeaderDateFormatWeek" ) {
03113                 QString value;
03114                 if( KDGanttXML::readStringNode( element, value ) )
03115                     setTimeHeaderDateFormatWeek( value );
03116             } else if( tagName == "TimeHeaderDateFormatMonth" ) {
03117                 QString value;
03118                 if( KDGanttXML::readStringNode( element, value ) )
03119                     setTimeHeaderDateFormatMonth( value );
03120             } else if( tagName == "TimeHeaderTooltipDateTimeFormat" ) {
03121                 QString value;
03122                 if( KDGanttXML::readStringNode( element, value ) )
03123                     setTimeHeaderTooltipDateTimeFormat( value );
03124             } else if( tagName == "CalendarMode" ) {
03125                 bool value;
03126                 if( KDGanttXML::readBoolNode( element, value ) )
03127                     setCalendarMode( value );
03128             } else if( tagName == "Editable" ) {
03129                 bool value;
03130                 if( KDGanttXML::readBoolNode( element, value ) )
03131                     setEditable( value );
03132             } else if( tagName == "TextColor" ) {
03133                 QColor value;
03134                 if( KDGanttXML::readColorNode( element, value ) )
03135                     setTextColor( value );
03136             } else if( tagName == "MajorScaleCount" ) {
03137                 int value;
03138                 if( KDGanttXML::readIntNode( element, value ) )
03139                     setMajorScaleCount( value );
03140             } else if( tagName == "MinorScaleCount" ) {
03141                 int value;
03142                 if( KDGanttXML::readIntNode( element, value ) )
03143                     setMinorScaleCount( value );
03144             } else if( tagName == "AutoScaleMinorTickCount" ) {
03145                 int value;
03146                 if( KDGanttXML::readIntNode( element, value ) )
03147                     setAutoScaleMinorTickCount( value );
03148             } else if( tagName == "MinimumColumnWidth" ) {
03149                 int value;
03150                 if( KDGanttXML::readIntNode( element, value ) )
03151                     setMinimumColumnWidth( value );
03152             } else if( tagName == "GanttMaximumWidth" ) {
03153                 int value;
03154                 if( KDGanttXML::readIntNode( element, value ) )
03155                     setGanttMaximumWidth( value );
03156             } else if( tagName == "Backgroundlines" ) {
03157                 QBrush value;
03158                 int linecount = 0;
03159                 QDomNode node = element.firstChild();
03160                 while( !node.isNull() ) {
03161                     QDomElement element = node.toElement();
03162                     if( !element.isNull() ) {
03163                         QString tagName = element.tagName();
03164                         if( tagName == "BackGroundBrush" )
03165                             KDGanttXML::readBrushNode( element, value );
03166                         else if( tagName == "LineCount" )
03167                             KDGanttXML::readIntNode( element, linecount );
03168                     }
03169                     node = node.nextSibling();
03170                 }
03171                 if ( linecount )
03172                     setHorBackgroundLines( linecount, value );
03173             } else if( tagName == "NoInformationBrush" ) {
03174                 QBrush value;
03175                 if( KDGanttXML::readBrushNode( element, value ) )
03176                     setNoInformationBrush( value );
03177             } else if( tagName == "GanttViewBackgroundColor" ) {
03178                 QColor value;
03179                 if( KDGanttXML::readColorNode( element, value ) )
03180                     setGvBackgroundColor( value );
03181             } else if( tagName == "ListViewBackgroundColor" ) {
03182                 QColor value;
03183                 if( KDGanttXML::readColorNode( element, value ) )
03184                     setLvBackgroundColor( value );
03185             } else if( tagName == "TimeHeaderBackgroundColor" ) {
03186                 QColor value;
03187                 if( KDGanttXML::readColorNode( element, value ) )
03188                     setTimeHeaderBackgroundColor( value );
03189             } else if( tagName == "LegendHeaderBackgroundColor" ) {
03190                 QColor value;
03191                 if( KDGanttXML::readColorNode( element, value ) )
03192                     setLegendHeaderBackgroundColor( value );
03193             } else if( tagName == "WeekendBackgroundColor" ) {
03194                 QColor value;
03195                 if( KDGanttXML::readColorNode( element, value ) )
03196                     setWeekendBackgroundColor( value );
03197             } else if( tagName == "WeekdayBackgroundColor" ) {
03198                 QDomNode node = element.firstChild();
03199                 int day = 0;
03200                 QColor color;
03201                 while( !node.isNull() ) {
03202                     QDomElement element = node.toElement();
03203                     if( !element.isNull() ) { // was really an elemente
03204                         QString tagName = element.tagName();
03205                         if( tagName == "Day" ) {
03206                             int value;
03207                             if( KDGanttXML::readIntNode( element, value ) )
03208                                 day = value;
03209                         } else if( tagName == "Color" ) {
03210                             QColor value;
03211                             if( KDGanttXML::readColorNode( element, value ) )
03212                                 color = value;
03213                         } else {
03214                             qDebug() << "Unrecognized tag name: " << tagName;
03215                             Q_ASSERT( false );
03216                         }
03217                     }
03218                     node = node.nextSibling();
03219                 }
03220 
03221                 if( day && color.isValid() )
03222                     setWeekdayBackgroundColor( color, day );
03223             } else if( tagName == "WeekendDays" ) {
03224                 QString startString = element.attribute( "Start" );
03225                 QString endString = element.attribute( "End" );
03226                 bool startOk = false, endOk = false;
03227                 int start = startString.toInt( &startOk );
03228                 int end = startString.toInt( &endOk );
03229                 if( startOk && endOk )
03230                     setWeekendDays( start, end );
03231             } else if( tagName == "ZoomFactor" ) {
03232                 double value;
03233                 if( KDGanttXML::readDoubleNode( element, value ) )
03234                     setZoomFactor( value, true );
03235             } else if( tagName == "ShowHeaderPopupMenu" ) {
03236                 bool value;
03237                 if( KDGanttXML::readBoolNode( element, value ) )
03238                     setShowHeaderPopupMenu( value );
03239             } else if( tagName == "ShowTimeTablePopupMenu" ) {
03240                 bool value;
03241                 if( KDGanttXML::readBoolNode( element, value ) )
03242                     setShowTimeTablePopupMenu( value );
03243             } else if( tagName == "Shapes" ) {
03244                 QDomNode node = element.firstChild();
03245                 bool undefinedShape = false;
03246                 while( !node.isNull() ) {
03247                     QDomElement element = node.toElement();
03248                     if( !element.isNull() ) { // was really an elemente
03249                         QString tagName = element.tagName();
03250                         if( tagName == "Event" ) {
03251                             KDGanttViewItem::Shape startShape, middleShape, endShape;
03252                             startShape = KDGanttViewItem::TriangleDown;
03253                             middleShape = KDGanttViewItem::TriangleDown;
03254                             endShape = KDGanttViewItem::TriangleDown;
03255                             QDomNode node = element.firstChild();
03256                             while( !node.isNull() ) {
03257                                 QDomElement element = node.toElement();
03258                                 if( !element.isNull() ) { // was really an elemente
03259                                     QString tagName = element.tagName();
03260                                     if( tagName == "Start" ) {
03261                                         QString value;
03262                                         if( KDGanttXML::readStringNode( element, value ) )
03263                                             startShape = KDGanttViewItem::stringToShape( value );
03264                                         if ( value == "Undefined" )
03265                                             undefinedShape = true;
03266                                     } else if( tagName == "Middle" ) {
03267                                         QString value;
03268                                         if( KDGanttXML::readStringNode( element, value ) )
03269                                             middleShape = KDGanttViewItem::stringToShape( value );
03270                                         if ( value == "Undefined" )
03271                                             undefinedShape = true;
03272                                     } else if( tagName == "End" ) {
03273                                         QString value;
03274                                         if( KDGanttXML::readStringNode( element, value ) )
03275                                             endShape = KDGanttViewItem::stringToShape( value );
03276                                         if ( value == "Undefined" )
03277                                             undefinedShape = true;
03278                                     } else {
03279                                         qDebug() << "Unrecognized tag name: " << tagName;
03280                                         Q_ASSERT( false );
03281                                     }
03282                                 }
03283                                 node = node.nextSibling();
03284                             }
03285                             if ( ! undefinedShape )
03286                                 setShapes( KDGanttViewItem::Event, startShape,
03287                                            middleShape, endShape, false );
03288                             undefinedShape = false;
03289                         } else if( tagName == "Task" ) {
03290                             KDGanttViewItem::Shape startShape, middleShape, endShape;
03291                             startShape = KDGanttViewItem::TriangleDown;
03292                             middleShape = KDGanttViewItem::TriangleDown;
03293                             endShape = KDGanttViewItem::TriangleDown;
03294                             QDomNode node = element.firstChild();
03295                             while( !node.isNull()) {
03296                                 QDomElement element = node.toElement();
03297                                 if( !element.isNull() ) { // was really an elemente
03298                                     QString tagName = element.tagName();
03299                                     if( tagName == "Start" ) {
03300                                         QString value;
03301                                         if( KDGanttXML::readStringNode( element, value ) )
03302                                             startShape = KDGanttViewItem::stringToShape( value );
03303                                         if ( value == "Undefined" )
03304                                             undefinedShape = true;
03305                                     } else if( tagName == "Middle" ) {
03306                                         QString value;
03307                                         if( KDGanttXML::readStringNode( element, value ) )
03308                                             middleShape = KDGanttViewItem::stringToShape( value );
03309                                         if ( value == "Undefined" )
03310                                             undefinedShape = true;
03311                                     } else if( tagName == "End" ) {
03312                                         QString value;
03313                                         if( KDGanttXML::readStringNode( element, value ) )
03314                                             endShape = KDGanttViewItem::stringToShape( value );
03315                                         if ( value == "Undefined" )
03316                                             undefinedShape = true;
03317                                     } else {
03318                                         qDebug() << "Unrecognized tag name: " << tagName;
03319                                         Q_ASSERT( false );
03320                                     }
03321                                 }
03322                                 node = node.nextSibling();
03323                             }
03324                             if ( ! undefinedShape )
03325                                 setShapes( KDGanttViewItem::Task, startShape, middleShape, endShape, false );
03326                             undefinedShape = false;
03327                         } else if( tagName == "Summary" ) {
03328                             KDGanttViewItem::Shape startShape, middleShape, endShape;
03329                             startShape = KDGanttViewItem::TriangleDown;
03330                             middleShape = KDGanttViewItem::TriangleDown;
03331                             endShape = KDGanttViewItem::TriangleDown;
03332                             QDomNode node = element.firstChild();
03333                             while( !node.isNull() ) {
03334                                 QDomElement element = node.toElement();
03335                                 if( !element.isNull() ) { // was really an elemente
03336                                     QString tagName = element.tagName();
03337                                     if( tagName == "Start" ) {
03338                                         QString value;
03339                                         if( KDGanttXML::readStringNode( element, value ) )
03340                                             startShape = KDGanttViewItem::stringToShape( value );
03341                                         if ( value == "Undefined" )
03342                                             undefinedShape = true;
03343                                     } else if( tagName == "Middle" ) {
03344                                         QString value;
03345                                         if( KDGanttXML::readStringNode( element, value ) )
03346                                             middleShape = KDGanttViewItem::stringToShape( value );
03347                                         if ( value == "Undefined" )
03348                                             undefinedShape = true;
03349                                     } else if( tagName == "End" ) {
03350                                         QString value;
03351                                         if( KDGanttXML::readStringNode( element, value ) )
03352                                             endShape = KDGanttViewItem::stringToShape( value );
03353                                         if ( value == "Undefined" )
03354                                             undefinedShape = true;
03355                                     } else {
03356                                         qDebug() << "Unrecognized tag name: " << tagName;
03357                                         Q_ASSERT( false );
03358                                     }
03359                                 }
03360                                 node = node.nextSibling();
03361                             }
03362                             if ( ! undefinedShape )
03363                                 setShapes( KDGanttViewItem::Summary, startShape,
03364                                            middleShape, endShape, false );
03365                             undefinedShape = false;
03366                         } else {
03367                             qDebug() << "Unrecognized tag name: " << tagName;
03368                             Q_ASSERT( false );
03369                         }
03370                     }
03371                     node = node.nextSibling();
03372                 }
03373             } else if( tagName == "Colors" ) {
03374                 QDomNode node = element.firstChild();
03375                 while( !node.isNull()) {
03376                     QDomElement element = node.toElement();
03377                     if( !element.isNull() ) { // was really an elemente
03378                         QString tagName = element.tagName();
03379                         if( tagName == "Event" ) {
03380                             QColor startColor, middleColor, endColor;
03381                             QDomNode node = element.firstChild();
03382                             while( !node.isNull() ) {
03383                                 QDomElement element = node.toElement();
03384                                 if( !element.isNull() ) { // was really an elemente
03385                                     QString tagName = element.tagName();
03386                                     if( tagName == "Start" ) {
03387                                         QColor value;
03388                                         if( KDGanttXML::readColorNode( element, value ) )
03389                                             startColor = value;
03390                                     } else if( tagName == "Middle" ) {
03391                                         QColor value;
03392                                         if( KDGanttXML::readColorNode( element, value ) )
03393                                             middleColor = value;
03394                                     } else if( tagName == "End" ) {
03395                                         QColor value;
03396                                         if( KDGanttXML::readColorNode( element, value ) )
03397                                             endColor = value;
03398                                     } else {
03399                                         qDebug() << "Unrecognized tag name: " << tagName;
03400                                         Q_ASSERT( false );
03401                                     }
03402                                 }
03403                                 node = node.nextSibling();
03404                             }
03405                             setColors( KDGanttViewItem::Event, startColor,
03406                                        middleColor, endColor, false );
03407                         } else if( tagName == "Task" ) {
03408                             QColor startColor, middleColor, endColor;
03409                             QDomNode node = element.firstChild();
03410                             while( !node.isNull() ) {
03411                                 QDomElement element = node.toElement();
03412                                 if( !element.isNull() ) { // was really an elemente
03413                                     QString tagName = element.tagName();
03414                                     if( tagName == "Start" ) {
03415                                         QColor value;
03416                                         if( KDGanttXML::readColorNode( element, value ) )
03417                                             startColor = value;
03418                                     } else if( tagName == "Middle" ) {
03419                                         QColor value;
03420                                         if( KDGanttXML::readColorNode( element, value ) )
03421                                             middleColor = value;
03422                                     } else if( tagName == "End" ) {
03423                                         QColor value;
03424                                         if( KDGanttXML::readColorNode( element, value ) )
03425                                             endColor = value;
03426                                     } else {
03427                                         qDebug() << "Unrecognized tag name: " << tagName;
03428                                         Q_ASSERT( false );
03429                                     }
03430                                 }
03431                                 node = node.nextSibling();
03432                             }
03433                             setColors( KDGanttViewItem::Task, startColor,
03434                                        middleColor, endColor, false );
03435                         } else if( tagName == "Summary" ) {
03436                             QColor startColor, middleColor, endColor;
03437                             QDomNode node = element.firstChild();
03438                             while( !node.isNull() ) {
03439                                 QDomElement element = node.toElement();
03440                                 if( !element.isNull() ) { // was really an elemente
03441                                     QString tagName = element.tagName();
03442                                     if( tagName == "Start" ) {
03443                                         QColor value;
03444                                         if( KDGanttXML::readColorNode( element, value ) )
03445                                             startColor = value;
03446                                     } else if( tagName == "Middle" ) {
03447                                         QColor value;
03448                                         if( KDGanttXML::readColorNode( element, value ) )
03449                                             middleColor = value;
03450                                     } else if( tagName == "End" ) {
03451                                         QColor value;
03452                                         if( KDGanttXML::readColorNode( element, value ) )
03453                                             endColor = value;
03454                                     } else {
03455                                         qDebug() << "Unrecognized tag name: " << tagName;
03456                                         Q_ASSERT( false );
03457                                     }
03458                                 }
03459                                 node = node.nextSibling();
03460                             }
03461                             setColors( KDGanttViewItem::Summary, startColor,
03462                                        middleColor, endColor , false);
03463                         } else {
03464                             qDebug() << "Unrecognized tag name: " << tagName;
03465                             Q_ASSERT( false );
03466                         }
03467                     }
03468                     node = node.nextSibling();
03469                 }
03470             } else if( tagName == "DefaultColors" ) {
03471                 QDomNode node = element.firstChild();
03472                 while( !node.isNull() ) {
03473                     QDomElement element = node.toElement();
03474                     if( !element.isNull() ) { // was really an element
03475                         QString tagName = element.tagName();
03476                         if( tagName == "Event" ) {
03477                             QColor value;
03478                             if( KDGanttXML::readColorNode( element, value ) )
03479                                 setDefaultColor( KDGanttViewItem::Event,
03480                                                  value, false );
03481                         } else if( tagName == "Task" ) {
03482                             QColor value;
03483                             if( KDGanttXML::readColorNode( element, value ) )
03484                                 setDefaultColor( KDGanttViewItem::Task,
03485                                                  value, false );
03486                         } else if( tagName == "Summary" ) {
03487                             QColor value;
03488                             if( KDGanttXML::readColorNode( element, value ) )
03489                                 setDefaultColor( KDGanttViewItem::Summary,
03490                                                  value , false);
03491                         } else {
03492                             qDebug() << "Unrecognized tag name: " << tagName;
03493                             Q_ASSERT( false );
03494                         }
03495                     }
03496 
03497                     node = node.nextSibling();
03498                 }
03499             } else if( tagName == "HighlightColors" ) {
03500                 QDomNode node = element.firstChild();
03501                 while( !node.isNull() ) {
03502                     QDomElement element = node.toElement();
03503                     if( !element.isNull() ) { // was really an elemente
03504                         QString tagName = element.tagName();
03505                         if( tagName == "Event" ) {
03506                             QColor startColor, middleColor, endColor;
03507                             QDomNode node = element.firstChild();
03508                             while( !node.isNull() ) {
03509                                 QDomElement element = node.toElement();
03510                                 if( !element.isNull() ) { // was really an elemente
03511                                     QString tagName = element.tagName();
03512                                     if( tagName == "Start" ) {
03513                                         QColor value;
03514                                         if( KDGanttXML::readColorNode( element, value ) )
03515                                             startColor = value;
03516                                     } else if( tagName == "Middle" ) {
03517                                         QColor value;
03518                                         if( KDGanttXML::readColorNode( element, value ) )
03519                                             middleColor = value;
03520                                     } else if( tagName == "End" ) {
03521                                         QColor value;
03522                                         if( KDGanttXML::readColorNode( element, value ) )
03523                                             endColor = value;
03524                                     } else {
03525                                         qDebug() << "Unrecognized tag name: " << tagName;
03526                                         Q_ASSERT( false );
03527                                     }
03528                                 }
03529                                 node = node.nextSibling();
03530                             }
03531                             setHighlightColors( KDGanttViewItem::Event,
03532                                                 startColor,
03533                                                 middleColor, endColor, false );
03534                         } else if( tagName == "Task" ) {
03535                             QColor startColor, middleColor, endColor;
03536                             QDomNode node = element.firstChild();
03537                             while( !node.isNull() ) {
03538                                 QDomElement element = node.toElement();
03539                                 if( !element.isNull() ) { // was really an elemente
03540                                     QString tagName = element.tagName();
03541                                     if( tagName == "Start" ) {
03542                                         QColor value;
03543                                         if( KDGanttXML::readColorNode( element, value ) )
03544                                             startColor = value;
03545                                     } else if( tagName == "Middle" ) {
03546                                         QColor value;
03547                                         if( KDGanttXML::readColorNode( element, value ) )
03548                                             middleColor = value;
03549                                     } else if( tagName == "End" ) {
03550                                         QColor value;
03551                                         if( KDGanttXML::readColorNode( element, value ) )
03552                                             endColor = value;
03553                                     } else {
03554                                         qDebug() << "Unrecognized tag name: " << tagName;
03555                                         Q_ASSERT( false );
03556                                     }
03557                                 }
03558                                 node = node.nextSibling();
03559                             }
03560                             setHighlightColors( KDGanttViewItem::Task,
03561                                                 startColor,
03562                                                 middleColor, endColor , false);
03563                         } else if( tagName == "Summary" ) {
03564                             QColor startColor, middleColor, endColor;
03565                             QDomNode node = element.firstChild();
03566                             while( !node.isNull() ) {
03567                                 QDomElement element = node.toElement();
03568                                 if( !element.isNull() ) { // was really an elemente
03569                                     QString tagName = element.tagName();
03570                                     if( tagName == "Start" ) {
03571                                         QColor value;
03572                                         if( KDGanttXML::readColorNode( element, value ) )
03573                                             startColor = value;
03574                                     } else if( tagName == "Middle" ) {
03575                                         QColor value;
03576                                         if( KDGanttXML::readColorNode( element, value ) )
03577                                             middleColor = value;
03578                                     } else if( tagName == "End" ) {
03579                                         QColor value;
03580                                         if( KDGanttXML::readColorNode( element, value ) )
03581                                             endColor = value;
03582                                     } else {
03583                                         qDebug() << "Unrecognized tag name: " << tagName;
03584                                         Q_ASSERT( false );
03585                                     }
03586                                 }
03587                                 node = node.nextSibling();
03588                             }
03589                             setHighlightColors( KDGanttViewItem::Summary,
03590                                                 startColor,
03591                                                 middleColor, endColor, false );
03592                         } else {
03593                             qDebug() << "Unrecognized tag name: " << tagName;
03594                             Q_ASSERT( false );
03595                         }
03596                     }
03597                     node = node.nextSibling();
03598                 }
03599             } else if( tagName == "DefaultHighlightColors" ) {
03600                 QDomNode node = element.firstChild();
03601                 while( !node.isNull() ) {
03602                     QDomElement element = node.toElement();
03603                     if( !element.isNull() ) { // was really an element
03604                         QString tagName = element.tagName();
03605                         if( tagName == "Event" ) {
03606                             QColor value;
03607                             if( KDGanttXML::readColorNode( element, value ) )
03608                                 setDefaultHighlightColor( KDGanttViewItem::Event,
03609                                                           value , false);
03610                         } else if( tagName == "Task" ) {
03611                             QColor value;
03612                             if( KDGanttXML::readColorNode( element, value ) )
03613                                 setDefaultHighlightColor( KDGanttViewItem::Task,
03614                                                           value, false );
03615                         } else if( tagName == "Summary" ) {
03616                             QColor value;
03617                             if( KDGanttXML::readColorNode( element, value ) )
03618                                 setDefaultHighlightColor( KDGanttViewItem::Summary,
03619                                                           value, false );
03620                         } else {
03621                             qDebug() << "Unrecognized tag name: " << tagName;
03622                             Q_ASSERT( false );
03623                         }
03624                     }
03625 
03626                     node = node.nextSibling();
03627                 }
03628             } else if( tagName == "Items" ) {
03629                 QDomNode node = element.firstChild();
03630                 KDGanttViewItem* previous = 0;
03631                 while( !node.isNull() ) {
03632                     QDomElement element = node.toElement();
03633                     if( !element.isNull() ) { // was really an element
03634                         QString tagName = element.tagName();
03635                         if( tagName == "Item" ) {
03636                             KDGanttViewItem* newItem;
03637                             if( previous )
03638                                 newItem =
03639                                     KDGanttViewItem::createFromDomElement( this,
03640                                                                            previous,
03641                                                                            element );
03642                             else
03643                                 newItem =
03644                                     KDGanttViewItem::createFromDomElement( this,
03645                                                                            element );
03646                             if ( newItem )
03647                                 previous = newItem;
03648                         } else {
03649                             qDebug() << "Unrecognized tag name: " << tagName;
03650                             Q_ASSERT( false );
03651                         }
03652                     }
03653 
03654                     node = node.nextSibling();
03655                 }
03656             } else if( tagName == "TaskLinks" ) {
03657                 QDomNode node = element.firstChild();
03658                 while( !node.isNull() ) {
03659                     QDomElement element = node.toElement();
03660                     if( !element.isNull() ) { // was really an element
03661                         QString tagName = element.tagName();
03662                         if( tagName == "TaskLink" )
03663                             KDGanttViewTaskLink::createFromDomElement( element );
03664                         else {
03665                             qDebug() << "Unrecognized tag name: " << tagName;
03666                             Q_ASSERT( false );
03667                         }
03668                     }
03669 
03670                     node = node.nextSibling();
03671                 }
03672             } else if( tagName == "TaskLinkGroups" ) {
03673                 QDomNode node = element.firstChild();
03674                 while( !node.isNull() ) {
03675                     QDomElement element = node.toElement();
03676                     if( !element.isNull() ) { // was really an element
03677                         QString tagName = element.tagName();
03678                         if( tagName == "TaskLinkGroup" )
03679                             KDGanttViewTaskLinkGroup::createFromDomElement( element );
03680                     } else {
03681                         qDebug() << "Unrecognized tag name: " << tagName;
03682                         Q_ASSERT( false );
03683                     }
03684 
03685                     node = node.nextSibling();
03686                 }
03687             } else if( tagName == "ColumnBackgroundColors" ) {
03688                 QDomNode node = element.firstChild();
03689                 while( !node.isNull() ) {
03690                     QDomElement element = node.toElement();
03691                     if( !element.isNull() ) { // was really an element
03692                         QString tagName = element.tagName();
03693                         if( tagName == "ColumnBackgroundColor" ) {
03694                             QDomNode node = element.firstChild();
03695                             QDateTime dateTime;
03696                             QColor color;
03697                             Scale mini = Minute;
03698                             Scale maxi = Month;
03699                             while( !node.isNull() ) {
03700                                 QDomElement element = node.toElement();
03701                                 if( !element.isNull() ) { // was
03702                                     // really an
03703                                     // element
03704                                     QString tagName = element.tagName();
03705                                     if( tagName == "DateTime" ) {
03706                                         QDateTime value;
03707                                         if( KDGanttXML::readDateTimeNode( element, value ) )
03708                                             dateTime = value;
03709                                     } else if( tagName == "Color" ) {
03710                                         QColor value;
03711                                         if( KDGanttXML::readColorNode( element, value ) )
03712                                             color = value;
03713                                     } else if( tagName == "MinScale" ) {
03714                                         QString value;
03715                                         if( KDGanttXML::readStringNode( element, value ) )
03716                                             mini = stringToScale( value );
03717                                     } else if( tagName == "MaxScale" ) {
03718                                         QString value;
03719                                         if( KDGanttXML::readStringNode( element, value ) )
03720                                             maxi = stringToScale( value );
03721                                     } else {
03722                                         qDebug() << "Unrecognized tag name: " << tagName;
03723                                         Q_ASSERT( false );
03724                                     }
03725                                 }
03726 
03727                                 node = node.nextSibling();
03728                             }
03729                             setColumnBackgroundColor( dateTime, color, mini, maxi );
03730                         } else {
03731                             qDebug() << "Unrecognized tag name: " << tagName;
03732                             Q_ASSERT( false );
03733                         }
03734                     }
03735                     node = node.nextSibling();
03736                 }
03737             } else if( tagName == "IntervalBackgroundColors" ) {
03738                 QDomNode node = element.firstChild();
03739                 while( !node.isNull() ) {
03740                     QDomElement element = node.toElement();
03741                     if( !element.isNull() ) { // was really an element
03742                         QString tagName = element.tagName();
03743                         if( tagName == "IntervalBackgroundColor" ) {
03744                             QDomNode node = element.firstChild();
03745                             QDateTime dateTime;
03746                             QDateTime ente;
03747                             QColor color;
03748                             Scale mini = Minute;
03749                             Scale maxi = Month;
03750                             int prio = 0;
03751                             while( !node.isNull() ) {
03752                                 QDomElement element = node.toElement();
03753                                 if( !element.isNull() ) { // was
03754                                     // really an
03755                                     // element
03756                                     QString tagName = element.tagName();
03757                                     if( tagName == "DateTimeEnd" ) {
03758                                         QDateTime value;
03759                                         if( KDGanttXML::readDateTimeNode( element, value ) )
03760                                             ente = value;
03761                                     }  else if( tagName == "Priority" ) {
03762                                         int value;
03763                                         if( KDGanttXML::readIntNode( element, value ) )
03764                                             prio = value;
03765                                     } else if( tagName == "DateTimeStart" ) {
03766                                         QDateTime value;
03767                                         if( KDGanttXML::readDateTimeNode( element, value ) )
03768                                             dateTime = value;
03769                                     } else if( tagName == "Color" ) {
03770                                         QColor value;
03771                                         if( KDGanttXML::readColorNode( element, value ) )
03772                                             color = value;
03773                                     } else if( tagName == "MinScale" ) {
03774                                         QString value;
03775                                         if( KDGanttXML::readStringNode( element, value ) )
03776                                             mini = stringToScale( value );
03777                                     } else if( tagName == "MaxScale" ) {
03778                                         QString value;
03779                                         if( KDGanttXML::readStringNode( element, value ) )
03780                                             maxi = stringToScale( value );
03781                                     } else {
03782                                         qDebug() << "Unrecognized tag name: " << tagName;
03783                                         Q_ASSERT( false );
03784                                     }
03785                                 }
03786                                 node = node.nextSibling();
03787                             }
03788                             //setIntervalBackgroundColor( dateTime, ente, color, prio, mini, maxi );
03789                             KDIntervalColorRectangle* icr = new KDIntervalColorRectangle( this );
03790                             icr->setDateTimes( dateTime, ente );
03791                             icr->setColor( color );
03792                             Q_UNUSED( prio );
03793                             Q_UNUSED( mini );
03794                             Q_UNUSED( maxi );
03795                             addIntervalBackgroundColor(icr);
03796 
03797                         } else {
03798                             qDebug() << "Unrecognized tag name: " << tagName;
03799                             Q_ASSERT( false );
03800                         }
03801                     }
03802                     node = node.nextSibling();
03803                 }
03804             } else if( tagName == "LegendItems" ) {
03805                 QDomNode node = element.firstChild();
03806                 while( !node.isNull() ) {
03807                     QDomElement element = node.toElement();
03808                     if( !element.isNull() ) { // was really an element
03809                         QString tagName = element.tagName();
03810                         if( tagName == "LegendItem" ) {
03811                             KDGanttViewItem::Shape tempLegendShape;
03812                             tempLegendShape = KDGanttViewItem::TriangleDown;
03813                             QColor tempLegendColor;
03814                             QString tempLegendString;
03815                             KDGanttViewItem::Shape tempLegendShape2;
03816                             tempLegendShape2 = KDGanttViewItem::TriangleDown;
03817                             QColor tempLegendColor2;
03818                             QString tempLegendString2;
03819                             bool has2 = false;
03820                             bool ok = true;
03821                             QDomNode node = element.firstChild();
03822                             while( !node.isNull() ) {
03823                                 QDomElement element = node.toElement();
03824                                 if( !element.isNull() ) { // was really an element
03825                                     QString tagName = element.tagName();
03826                                     if( tagName == "Shape" ) {
03827                                         QString value;
03828                                         if( KDGanttXML::readStringNode( element, value ) )
03829                                             tempLegendShape = KDGanttViewItem::stringToShape( value );
03830                                         else
03831                                             ok = false;
03832                                     } else if( tagName == "Color" ) {
03833                                         QColor value;
03834                                         if( KDGanttXML::readColorNode( element, value ) )
03835                                             tempLegendColor = value;
03836                                         else
03837                                             ok = false;
03838                                     } else if( tagName == "Text" ) {
03839                                         QString value;
03840                                         if( KDGanttXML::readStringNode( element, value ) )
03841                                             tempLegendString = value;
03842                                         else
03843                                             ok = false;
03844                                     } else if( tagName == "Shape2" ) {
03845                                         QString value;
03846                                         has2 = true;
03847                                         if( KDGanttXML::readStringNode( element, value ) )
03848                                             tempLegendShape2 = KDGanttViewItem::stringToShape( value );
03849                                         else
03850                                             ok = false;
03851                                     } else if( tagName == "Color2" ) {
03852                                         QColor value;
03853                                         has2 = true;
03854                                         if( KDGanttXML::readColorNode( element, value ) )
03855                                             tempLegendColor2 = value;
03856                                         else
03857                                             ok = false;
03858                                     } else if( tagName == "Text2" ) {
03859                                         QString value;
03860                                         has2 = true;
03861                                         if( KDGanttXML::readStringNode( element, value ) )
03862                                             tempLegendString2 = value;
03863                                         else
03864                                             ok = false;
03865                                     } else {
03866                                         qDebug() << "Unrecognized tag name: " << tagName;
03867                                         Q_ASSERT( false );
03868                                     }
03869                                 }
03870                                 node = node.nextSibling();
03871                             }
03872                             if( ok ) {
03873                                 if ( has2 )
03874                                     addLegendItem( tempLegendShape,
03875                                                    tempLegendColor,
03876                                                    tempLegendString,
03877                                                    tempLegendShape2,
03878                                                    tempLegendColor2,
03879                                                    tempLegendString2 );
03880                                 else
03881                                     addLegendItem( tempLegendShape,
03882                                                    tempLegendColor,
03883                                                    tempLegendString );
03884                                 //qDebug() << "Adding legend item " << tempLegendString;
03885                             }
03886                         } else {
03887                             qDebug() << "Unrecognized tag name: " << tagName;
03888                             Q_ASSERT( false );
03889                         }
03890                     }
03891                     node = node.nextSibling();
03892                 }
03893             } else if( tagName == "UserSavedData" ) {
03894                 userReadFromElement( element );
03895             } else {
03896                 qDebug() << "Unrecognized tag name: " << tagName;
03897                 Q_ASSERT( false );
03898             }
03899         }
03900 
03901         node = node.nextSibling();
03902     } // while
03903     setUpdateEnabled( block );
03904     return true; /* FIXME: Do real error-reporting. The ASSERT's should be "return false" stmnts */
03905 } // method
03906 
03907 
03916 QDomDocument KDGanttView::saveXML( bool withPI ) const
03917 {
03918     // Create an initial DOM document
03919     QString docstart = "<GanttView/>";
03920 
03921     QDomDocument doc( "GanttView" );
03922     doc.setContent( docstart );
03923     if( withPI ) {
03924         QDomProcessingInstruction pin = doc.createProcessingInstruction( "kdgantt", "version=\"1.0\" encoding=\"UTF-8\""  ) ;
03925         doc.appendChild ( pin );
03926     }
03927 
03928     QDomElement docRoot = doc.documentElement();
03929     docRoot.setAttribute( "xmlns", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
03930     docRoot.setAttribute( "xmlns:xsi", "http://www.w3.org/2000/10/XMLSchema-instance" );
03931     docRoot.setAttribute( "xsi:schemaLocation", "http://www.klaralvdalens-datakonsult.se/kdgantt" );
03932 
03933     // the ShowLegend element
03934     KDGanttXML::createBoolNode( doc, docRoot, "ShowLegend", showLegend() );
03935 
03936     // the ShowLegendButton element
03937     KDGanttXML::createBoolNode( doc, docRoot, "ShowLegendButton",
03938                                 showLegendButton() );
03939 
03940     // the LegendIsDockWindow element
03941     KDGanttXML::createBoolNode( doc, docRoot, "LegendIsDockWindow",
03942                                 legendIsDockwindow() );
03943 
03944     // the ShowListView element
03945     KDGanttXML::createBoolNode( doc, docRoot, "ShowListView", showListView() );
03946 
03947     // the ShowHeader element
03948     KDGanttXML::createBoolNode( doc, docRoot, "ShowHeader", headerVisible() );
03949 
03950     // the ShowTaskLinks element
03951     KDGanttXML::createBoolNode( doc, docRoot, "ShowTaskLinks", showTaskLinks() );
03952 
03953     // the EditorEnabled element
03954     KDGanttXML::createBoolNode( doc, docRoot, "EditorEnabled", editorEnabled() );
03955 
03956     // the global font element
03957     KDGanttXML::createFontNode( doc, docRoot, "GlobalFont", font() );
03958 
03959     // the DisplayEmptyTasksAsLine element
03960     KDGanttXML::createBoolNode( doc, docRoot, "DisplayEmptyTasksAsLine",
03961                                 displayEmptyTasksAsLine() );
03962 
03963     // the HorizonStart element
03964     KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonStart", horizonStart() );
03965 
03966     // the HorizonEnd element
03967     KDGanttXML::createDateTimeNode( doc, docRoot, "HorizonEnd", horizonEnd() );
03968 
03969     // the Scale, MinimumScale, MaximumScale elements
03970     KDGanttXML::createStringNode( doc, docRoot, "Scale", scaleToString( scale() ) );
03971     KDGanttXML::createStringNode( doc, docRoot, "MinimumScale",
03972                                   scaleToString( minimumScale() ) );
03973     KDGanttXML::createStringNode( doc, docRoot, "MaximumScale",
03974                                   scaleToString( maximumScale() ) );
03975 
03976     // the YearFormat element
03977     KDGanttXML::createStringNode( doc, docRoot, "YearFormat",
03978                                   yearFormatToString( yearFormat() ) );
03979 
03980     // the HourFormat element
03981     KDGanttXML::createStringNode( doc, docRoot, "HourFormat",
03982                                   hourFormatToString( hourFormat() ) );
03983 
03984     // the ShowTicks element
03985     KDGanttXML::createIntNode( doc, docRoot, "ShowTicks", showTicks() );
03986 
03987     // the Editable element
03988     KDGanttXML::createBoolNode( doc, docRoot, "Editable", editable() );
03989 
03990     // the TextColor element
03991     KDGanttXML::createColorNode( doc, docRoot, "TextColor", textColor() );
03992 
03993     // the MajorScaleCount element
03994     KDGanttXML::createIntNode( doc, docRoot, "MajorScaleCount", majorScaleCount() );
03995 
03996     // the MinorScaleCount element
03997     KDGanttXML::createIntNode( doc, docRoot, "MinorScaleCount", minorScaleCount() );
03998 
03999     // the AutoScaleMinorTickCount element
04000     KDGanttXML::createIntNode( doc, docRoot, "AutoScaleMinorTickCount",
04001                                autoScaleMinorTickCount() );
04002 
04003     // the MinimumColumnWidth element
04004     KDGanttXML::createIntNode( doc, docRoot, "MinimumColumnWidth",
04005                                minimumColumnWidth() );
04006 
04007     // the GanttMaximumWidth element
04008     KDGanttXML::createIntNode( doc, docRoot, "GanttMaximumWidth",
04009                                ganttMaximumWidth() );
04010 
04011     QBrush backBrush;
04012     int backgroundlines = horBackgroundLines( backBrush );
04013     if ( backgroundlines ) {
04014         QDomElement backElement = doc.createElement( "Backgroundlines" );
04015         docRoot.appendChild( backElement );
04016         KDGanttXML::createBrushNode( doc, backElement, "BackGroundBrush",backBrush );
04017         KDGanttXML::createIntNode( doc, backElement, "LineCount",  backgroundlines );
04018     }
04019     // the NoInformationBrush element
04020     KDGanttXML::createBrushNode( doc, docRoot, "NoInformationBrush",
04021                                  noInformationBrush() );
04022 
04023     // the GanttViewBackgroundColor element
04024     KDGanttXML::createColorNode( doc, docRoot, "GanttViewBackgroundColor",
04025                                  gvBackgroundColor() );
04026 
04027     // the ListViewBackgroundColor element
04028     KDGanttXML::createColorNode( doc, docRoot, "ListViewBackgroundColor",
04029                                  lvBackgroundColor() );
04030 
04031     // the TimeHeaderBackgroundColor element
04032     KDGanttXML::createColorNode( doc, docRoot, "TimeHeaderBackgroundColor",
04033                                  timeHeaderBackgroundColor() );
04034 
04035     // the LegendHeaderBackgroundColor element
04036     KDGanttXML::createColorNode( doc, docRoot, "LegendHeaderBackgroundColor",
04037                                  legendHeaderBackgroundColor() );
04038 
04039     // the WeekendBackgroundColor element
04040     KDGanttXML::createColorNode( doc, docRoot, "WeekendBackgroundColor",
04041                                  weekendBackgroundColor() );
04042 
04043     // the WeekdayBackgroundColor elements
04044     for( int weekday = 1; weekday <= 7; weekday++ ) {
04045         QColor color = weekdayBackgroundColor( weekday );
04046         if( color.isValid() ) {
04047             QDomElement weekendBackgroundColorElement = doc.createElement( "WeekdayBackgroundColor" );
04048             docRoot.appendChild( weekendBackgroundColorElement );
04049             KDGanttXML::createIntNode( doc, weekendBackgroundColorElement,
04050                                        "Day", weekday );
04051             KDGanttXML::createColorNode( doc, weekendBackgroundColorElement,
04052                                          "Color", color );
04053         }
04054     }
04055 
04056     // the WeekendDays element
04057     QDomElement weekendDaysElement = doc.createElement( "WeekendDays" );
04058     docRoot.appendChild( weekendDaysElement );
04059     int weekendStart, weekendEnd;
04060     weekendDays( weekendStart, weekendEnd );
04061     weekendDaysElement.setAttribute( "Start", weekendStart );
04062     weekendDaysElement.setAttribute( "End", weekendStart );
04063 
04064     // the ZoomFactor element
04065     KDGanttXML::createDoubleNode( doc, docRoot, "ZoomFactor",
04066                                   zoomFactor() );
04067 
04068     // the ShowHeaderPopupMenu element
04069     KDGanttXML::createBoolNode( doc, docRoot, "ShowHeaderPopupMenu",
04070                                 showHeaderPopupMenu() );
04071 
04072     // the ShowTimeTablePopupMenu element
04073     KDGanttXML::createBoolNode( doc, docRoot, "ShowTimeTablePopupMenu",
04074                                 showTimeTablePopupMenu() );
04075 
04076     // the Shapes element
04077     QDomElement shapesElement = doc.createElement( "Shapes" );
04078     docRoot.appendChild( shapesElement );
04079     QDomElement shapesEventElement = doc.createElement( "Event" );
04080     shapesElement.appendChild( shapesEventElement );
04081     KDGanttViewItem::Shape start, middle, end;
04082     if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
04083         KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
04084                                       KDGanttViewItem::shapeToString( start ) );
04085         KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
04086                                       KDGanttViewItem::shapeToString( middle ) );
04087         KDGanttXML::createStringNode( doc, shapesEventElement, "End",
04088                                       KDGanttViewItem::shapeToString( end ) );
04089     } else {
04090         KDGanttXML::createStringNode( doc, shapesEventElement, "Start",
04091                                       "Undefined" );
04092         KDGanttXML::createStringNode( doc, shapesEventElement, "Middle",
04093                                       "Undefined" );
04094         KDGanttXML::createStringNode( doc, shapesEventElement, "End",
04095                                       "Undefined" );
04096     }
04097     QDomElement shapesTaskElement = doc.createElement( "Task" );
04098     shapesElement.appendChild( shapesTaskElement );
04099     if( shapes( KDGanttViewItem::Task, start, middle, end ) ) {
04100         KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
04101                                       KDGanttViewItem::shapeToString( start ) );
04102         KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
04103                                       KDGanttViewItem::shapeToString( middle ) );
04104         KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
04105                                       KDGanttViewItem::shapeToString( end ) );
04106     } else {
04107         KDGanttXML::createStringNode( doc, shapesTaskElement, "Start",
04108                                       "Undefined" );
04109         KDGanttXML::createStringNode( doc, shapesTaskElement, "Middle",
04110                                       "Undefined" );
04111         KDGanttXML::createStringNode( doc, shapesTaskElement, "End",
04112                                       "Undefined" );
04113     }
04114     QDomElement shapesSummaryElement = doc.createElement( "Summary" );
04115     shapesElement.appendChild( shapesSummaryElement );
04116     if( shapes( KDGanttViewItem::Event, start, middle, end ) ) {
04117         KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
04118                                       KDGanttViewItem::shapeToString( start ) );
04119         KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
04120                                       KDGanttViewItem::shapeToString( middle ) );
04121         KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
04122                                       KDGanttViewItem::shapeToString( end ) );
04123     } else {
04124         KDGanttXML::createStringNode( doc, shapesSummaryElement, "Start",
04125                                       "Undefined" );
04126         KDGanttXML::createStringNode( doc, shapesSummaryElement, "Middle",
04127                                       "Undefined" );
04128         KDGanttXML::createStringNode( doc, shapesSummaryElement, "End",
04129                                       "Undefined" );
04130     }
04131 
04132     // the Colors element
04133     QDomElement colorsElement = doc.createElement( "Colors" );
04134     docRoot.appendChild( colorsElement );
04135     QDomElement colorsEventElement = doc.createElement( "Event" );
04136     colorsElement.appendChild( colorsEventElement );
04137     QColor startColor, middleColor, endColor;
04138     colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
04139     KDGanttXML::createColorNode( doc, colorsEventElement, "Start", startColor );
04140     KDGanttXML::createColorNode( doc, colorsEventElement, "Middle", middleColor );
04141     KDGanttXML::createColorNode( doc, colorsEventElement, "End", endColor );
04142     QDomElement colorsTaskElement = doc.createElement( "Task" );
04143     colorsElement.appendChild( colorsTaskElement );
04144     colors( KDGanttViewItem::Task, startColor, middleColor, endColor );
04145     KDGanttXML::createColorNode( doc, colorsTaskElement, "Start", startColor );
04146     KDGanttXML::createColorNode( doc, colorsTaskElement, "Middle", middleColor );
04147     KDGanttXML::createColorNode( doc, colorsTaskElement, "End", endColor );
04148     QDomElement colorsSummaryElement = doc.createElement( "Summary" );
04149     colorsElement.appendChild( colorsSummaryElement );
04150     colors( KDGanttViewItem::Event, startColor, middleColor, endColor );
04151     KDGanttXML::createColorNode( doc, colorsSummaryElement, "Start", startColor );
04152     KDGanttXML::createColorNode( doc, colorsSummaryElement, "Middle", middleColor );
04153     KDGanttXML::createColorNode( doc, colorsSummaryElement, "End", endColor );
04154 
04155     // the DefaultColor element
04156     QDomElement defaultColorsElement = doc.createElement( "DefaultColors" );
04157     docRoot.appendChild( defaultColorsElement );
04158     KDGanttXML::createColorNode( doc, defaultColorsElement, "Event",
04159                                  defaultColor( KDGanttViewItem::Event ) );
04160     KDGanttXML::createColorNode( doc, defaultColorsElement, "Task",
04161                                  defaultColor( KDGanttViewItem::Task ) );
04162     KDGanttXML::createColorNode( doc, defaultColorsElement, "Summary",
04163                                  defaultColor( KDGanttViewItem::Summary ) );
04164 
04165 
04166     // the HighlightColors element
04167     QDomElement highlightColorsElement = doc.createElement( "HighlightColors" );
04168     docRoot.appendChild( highlightColorsElement );
04169     QDomElement highlightColorsEventElement = doc.createElement( "Event" );
04170     highlightColorsElement.appendChild( highlightColorsEventElement );
04171     highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
04172     KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Start", startColor );
04173     KDGanttXML::createColorNode( doc, highlightColorsEventElement, "Middle", middleColor );
04174     KDGanttXML::createColorNode( doc, highlightColorsEventElement, "End", endColor );
04175     QDomElement highlightColorsTaskElement = doc.createElement( "Task" );
04176     highlightColorsElement.appendChild( highlightColorsTaskElement );
04177     highlightColors( KDGanttViewItem::Task, startColor, middleColor, endColor );
04178     KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Start", startColor );
04179     KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "Middle", middleColor );
04180     KDGanttXML::createColorNode( doc, highlightColorsTaskElement, "End", endColor );
04181     QDomElement highlightColorsSummaryElement = doc.createElement( "Summary" );
04182     highlightColorsElement.appendChild( highlightColorsSummaryElement );
04183     highlightColors( KDGanttViewItem::Event, startColor, middleColor, endColor );
04184     KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Start", startColor );
04185     KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "Middle", middleColor );
04186     KDGanttXML::createColorNode( doc, highlightColorsSummaryElement, "End", endColor );
04187 
04188     // the DefaultHighlightColor element
04189     QDomElement defaultHighlightColorsElement = doc.createElement( "DefaultHighlightColors" );
04190     docRoot.appendChild( defaultHighlightColorsElement );
04191     KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Event",
04192                                  defaultHighlightColor( KDGanttViewItem::Event ) );
04193     KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Task",
04194                                  defaultHighlightColor( KDGanttViewItem::Task ) );
04195     KDGanttXML::createColorNode( doc, defaultHighlightColorsElement, "Summary",
04196                                  defaultHighlightColor( KDGanttViewItem::Summary ) );
04197 
04198 
04199     // the Items element
04200     QDomElement itemsElement = doc.createElement( "Items" );
04201     docRoot.appendChild( itemsElement );
04202     KDGanttViewItem* currentItem = firstChild();
04203     while( currentItem ) {
04204         currentItem->createNode( doc, itemsElement );
04205         currentItem = currentItem->nextSibling();
04206     }
04207 
04208     // the TaskLinks element
04209     QDomElement taskLinksElement = doc.createElement( "TaskLinks" );
04210     docRoot.appendChild( taskLinksElement );
04211     QPtrList<KDGanttViewTaskLink> taskLinkList = taskLinks();
04212     KDGanttViewTaskLink* currentTL = 0;
04213     for( currentTL = taskLinkList.first(); currentTL;
04214          currentTL = taskLinkList.next() )
04215         currentTL->createNode( doc, taskLinksElement );
04216 
04217     // the TaskLinkGroups element
04218     QDomElement taskLinkGroupsElement = doc.createElement( "TaskLinkGroups" );
04219     docRoot.appendChild( taskLinkGroupsElement );
04220     QPtrList<KDGanttViewTaskLinkGroup> taskLinkGroupList = taskLinkGroups();
04221     KDGanttViewTaskLinkGroup* currentTLG = 0;
04222     for( currentTLG = taskLinkGroupList.first(); currentTLG;
04223          currentTLG = taskLinkGroupList.next() )
04224         currentTLG->createNode( doc, taskLinkGroupsElement );
04225 
04226     // the ColumnBackgroundColors element
04227     QDomElement columnBackgroundColorsElement =
04228         doc.createElement( "ColumnBackgroundColors" );
04229     docRoot.appendChild( columnBackgroundColorsElement );
04230     KDTimeHeaderWidget::ColumnColorList ccList =
04231         myTimeHeader->columnBackgroundColorList();
04232     for( KDTimeHeaderWidget::ColumnColorList::iterator it = ccList.begin();
04233          it != ccList.end(); ++it ) {
04234         QDomElement columnBackgroundColorElement =
04235             doc.createElement( "ColumnBackgroundColor" );
04236         columnBackgroundColorsElement.appendChild( columnBackgroundColorElement );
04237         KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
04238                                         "DateTime", (*it).datetime );
04239         KDGanttXML::createColorNode( doc, columnBackgroundColorElement,
04240                                      "Color", (*it).color );
04241         KDGanttXML::createStringNode( doc, columnBackgroundColorElement, "MinScale", scaleToString( (*it).minScaleView ) );
04242         KDGanttXML::createStringNode( doc, columnBackgroundColorElement, "MaxScale", scaleToString( (*it).maxScaleView ) );
04243     }
04244 
04245     // the IntervalBackgroundColors element
04246     columnBackgroundColorsElement =
04247         doc.createElement( "IntervalBackgroundColors" );
04248     docRoot.appendChild( columnBackgroundColorsElement );
04249     KDTimeHeaderWidget::IntervalColorList icList = myTimeHeader->intervalBackgroundColorList();
04250     for( KDTimeHeaderWidget::IntervalColorList::iterator it = icList.begin();
04251          it != icList.end(); ++it ) {
04252         QDomElement columnBackgroundColorElement =
04253             doc.createElement( "IntervalBackgroundColor" );
04254         columnBackgroundColorsElement.appendChild( columnBackgroundColorElement );
04255         KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
04256                                         "DateTimeStart", (*it)->start() );
04257         KDGanttXML::createDateTimeNode( doc, columnBackgroundColorElement,
04258                                         "DateTimeEnd", (*it)->end() );
04259         KDGanttXML::createColorNode( doc, columnBackgroundColorElement,
04260                                      "Color", (*it)->color() );
04261         //KDGanttXML::createIntNode( doc, columnBackgroundColorElement, "Priority", (*it).priority );
04262         //KDGanttXML::createStringNode( doc, columnBackgroundColorElement, "MinScale", scaleToString( (*it).minScaleView ) );
04263         //KDGanttXML::createStringNode( doc, columnBackgroundColorElement, "MaxScale", scaleToString( (*it).maxScaleView ) );
04264     }
04265 
04266     // the LegendItems element
04267     QDomElement legendItemsElement =
04268         doc.createElement( "LegendItems" );
04269     docRoot.appendChild( legendItemsElement );
04270     legendItem* current;
04271     QPtrListIterator<legendItem> lit( myLegendItems );
04272     while( ( current = lit.current() ) ) {
04273         ++lit;
04274         QDomElement legendItemElement = doc.createElement( "LegendItem" );
04275         legendItemsElement.appendChild( legendItemElement );
04276         KDGanttXML::createStringNode( doc, legendItemElement, "Shape",
04277                                       KDGanttViewItem::shapeToString( current->shape ) );
04278         KDGanttXML::createColorNode( doc, legendItemElement, "Color",
04279                                      current->color );
04280         KDGanttXML::createStringNode( doc, legendItemElement, "Text",
04281                                       current->text );
04282         if ( current->has2 ) {
04283             KDGanttXML::createStringNode( doc, legendItemElement, "Shape2",
04284                                           KDGanttViewItem::shapeToString( current->shape2 ) );
04285             KDGanttXML::createColorNode( doc, legendItemElement, "Color2",
04286                                          current->color2 );
04287             KDGanttXML::createStringNode( doc, legendItemElement, "Text2",
04288                                           current->text2 );
04289         }
04290     }
04291 
04292     // the DragEnabled element
04293     KDGanttXML::createBoolNode( doc, docRoot, "DragEnabled", isDragEnabled() );
04294 
04295     // the DropEnabled element
04296     KDGanttXML::createBoolNode( doc, docRoot, "DropEnabled", isDropEnabled() );
04297 
04298     // the CalendarMode element
04299     KDGanttXML::createBoolNode( doc, docRoot, "CalendarMode", calendarMode() );
04300     KDGanttXML::createIntNode( doc, docRoot, "TickcountForTimeline", addTickcountForTimeline()  );
04301 
04302     KDGanttXML::createBoolNode( doc, docRoot, "DisplaySubitemsAsGroup", displaySubitemsAsGroup()  );
04303     KDGanttXML::createBoolNode( doc, docRoot, "WeekScaleShowNumber",weekScaleShowNumber()  );
04304     KDGanttXML::createBoolNode( doc, docRoot, "WeekStartsMonday", weekStartsMonday() );
04305     KDGanttXML::createBoolNode( doc, docRoot, "UserHorizonChangeEnabled", userHorizonChangeEnabled() );
04306 
04307     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDatetimeFormatHour",timeHeaderDatetimeFormatHour()  );
04308     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDatetimeFormatMinute", timeHeaderDatetimeFormatMinute() );
04309     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDatetimeFormatSecond", timeHeaderDatetimeFormatSecond() );
04310     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDateFormatDay", timeHeaderDateFormatDay() );
04311     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDateFormatWeek", timeHeaderDateFormatWeek() );
04312     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderDateFormatMonth", timeHeaderDateFormatMonth() );
04313     KDGanttXML::createStringNode( doc, docRoot, "TimeHeaderTooltipDateTimeFormat", timeHeaderTooltipDateTimeFormat() );
04314     QDomElement userElement = doc.createElement( "UserSavedData" );
04315     docRoot.appendChild( userElement );
04316     userWriteToElement( doc, userElement );
04317 
04318     return doc;
04319 }
04333 void KDGanttView::userWriteToElement( QDomDocument& doc,
04334                                       QDomElement& userElement ) const
04335 {
04336     Q_UNUSED( doc );
04337     Q_UNUSED( userElement );
04338     // example for writing user defined data
04339     /*
04340     int userNumber = 815;
04341     QString userData = "this is saved text from the user";
04342     KDGanttXML::createStringNode( doc, userElement, "ExampleText", userData );
04343     KDGanttXML::createIntNode( doc, userElement, "ExampleNumber", userNumber );
04344     */
04345 
04346 }
04360 void KDGanttView::userReadFromElement( QDomElement& element )
04361 {
04362     Q_UNUSED( element );
04363     // example for reading user defined data
04364     /*
04365     int userNumber = 0;
04366     QString userData = "";
04367     QDomNode node = element.firstChild();
04368     while( !node.isNull() ) {
04369         QDomElement userElement = node.toElement();
04370         QString tagName = userElement.tagName();
04371         if ( tagName == "ExampleNumber" ) {
04372                 int value;
04373                 if( KDGanttXML::readIntNode( userElement, value ) )
04374                     userNumber = value;
04375         } else if ( tagName == "ExampleText" ) {
04376                 QString value;
04377                 if( KDGanttXML::readStringNode( userElement, value ) )
04378                     userData = value;
04379 
04380         }
04381         node = node.nextSibling();
04382     }
04383     qDebug() <<"User data read: " << userNumber << " " << userData;
04384     */
04385 }
04386 
04387 QString KDGanttView::scaleToString( Scale scale )
04388 {
04389     switch( scale ) {
04390     case Second:
04391         return "Second";
04392     case Minute:
04393         return "Minute";
04394     case Hour:
04395         return "Hour";
04396     case Day:
04397         return "Day";
04398     case Week:
04399         return "Week";
04400     case Month:
04401         return "Month";
04402     case Auto:
04403         return "Auto";
04404     }
04405     return "";
04406 }
04407 
04408 
04409 KDGanttView::Scale KDGanttView::stringToScale( const QString& string )
04410 {
04411 
04412     if( string == "Second" )
04413         return Second;
04414     else if( string == "Minute" )
04415         return Minute;
04416     else if( string == "Hour" )
04417         return Hour;
04418     else if( string == "Day" )
04419         return Day;
04420     else if( string == "Week" )
04421         return Week;
04422     else if( string == "Month" )
04423         return Month;
04424     else if( string == "Auto" )
04425         return Auto;
04426 
04427     return Auto;
04428 }
04429 
04430 
04431 QString KDGanttView::yearFormatToString( YearFormat format )
04432 {
04433     switch( format ) {
04434     case FourDigit:
04435         return "FourDigit";
04436     case TwoDigit:
04437         return "TwoDigit";
04438     case TwoDigitApostrophe:
04439         return "TwoDigitApostrophe";
04440     case NoDate:
04441         return "NoDate";
04442     }
04443     return "";
04444 }
04445 
04446 
04447 KDGanttView::YearFormat KDGanttView::stringToYearFormat( const QString& string )
04448 {
04449     if( string == "FourDigit" )
04450         return FourDigit;
04451     else if( string == "TwoDigit" )
04452         return TwoDigit;
04453     else if( string == "TwoDigitApostrophe" )
04454         return TwoDigitApostrophe;
04455     else if( string == "NoDate" )
04456         return NoDate;
04457     else
04458         return FourDigit;
04459 }
04460 
04461 
04462 QString KDGanttView::hourFormatToString( HourFormat format )
04463 {
04464     switch( format ) {
04465     case Hour_12:
04466         return "Hour_12";
04467     case Hour_24:
04468         return "Hour_24";
04469     case Hour_24_FourDigit:
04470         return "Hour_24_FourDigit";
04471     }
04472     return "";
04473 }
04474 
04475 
04476 KDGanttView::HourFormat KDGanttView::stringToHourFormat( const QString& string )
04477 {
04478     if( string == "Hour_12" )
04479         return Hour_12;
04480     else if( string == "Hour_24" )
04481         return Hour_24;
04482 
04483     return Hour_24_FourDigit;
04484 }
04485 
04486 
04487 void KDGanttView::addTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
04488 {
04489     if ( group == 0 ) return;
04490   if (myTaskLinkGroupList.isEmpty()) {
04491     myTaskLinkGroupList.append(group);
04492     return;
04493   }
04494     if (myTaskLinkGroupList.find(group) == -1)
04495         myTaskLinkGroupList.append(group);
04496 }
04497 
04498 
04499 void KDGanttView::removeTaskLinkGroup(KDGanttViewTaskLinkGroup* group)
04500 {
04501     myTaskLinkGroupList.remove(group);
04502 }
04503 
04504 
04510 void KDGanttView::editItem( KDGanttViewItem*  item)
04511 {
04512   if ( ! item )
04513     return;
04514   if ( editorEnabled() ) {
04515     if ( item->editable() ) {
04516 #if QT_VERSION < 0x040000
04517         if ( !myItemAttributeDialog ) {
04518             myItemAttributeDialog = new itemAttributeDialog();
04519             myItemAttributeDialog->resize( myItemAttributeDialog->minimumSizeHint() );
04520         }
04521         myItemAttributeDialog->reset( item );
04522         myItemAttributeDialog->show();
04523 #endif
04524     }
04525   }
04526 }
04527 
04528 
04539 QPixmap KDGanttView::getPixmap( KDGanttViewItem::Shape shape,
04540                                 const QColor& shapeColor,
04541                                 const QColor& backgroundColor, int itemSize)
04542 {
04543   // 10 is a good value as size
04544   int size = itemSize+2;
04545   int hei = ( itemSize/3 ) / 2;
04546   QPixmap p = QPixmap( size+4, size+4 );
04547   p.fill( backgroundColor );
04548   QPainter paint (&p);
04549   QBrush b = QBrush ( Qt::SolidPattern );
04550   b.setColor( shapeColor );
04551   paint.setBrush( b );
04552   QPen pen( Qt::black, 1 ) ;
04553   paint.setPen( pen );
04554   switch (shape) {
04555   case KDGanttViewItem::TriangleDown:{
04556     QPointArray arr = QPointArray(3);
04557     arr.setPoint(0,-size/2,-hei);
04558     arr.setPoint(1,size/2,-hei);
04559     arr.setPoint(2,0,((size/2)-hei));
04560     arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
04561     paint.drawPolygon( arr );
04562     break;
04563   }
04564   case KDGanttViewItem::TriangleUp :{
04565     QPointArray arr = QPointArray(3);
04566     arr.setPoint(0,-size/2,hei);
04567     arr.setPoint(1,size/2,hei);
04568     arr.setPoint(2,0,(-size/2)+hei);
04569     arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
04570     paint.drawPolygon( arr );
04571     break;
04572   }
04573   case  KDGanttViewItem::Diamond :{
04574     QPointArray arr = QPointArray(4);
04575     arr.setPoint(0,0,-size/2);
04576     arr.setPoint(1,size/2,0);
04577     arr.setPoint(2,0,size/2);
04578     arr.setPoint(3,-size/2,0);
04579     arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
04580     paint.drawPolygon( arr );
04581     break;
04582   }
04583   case KDGanttViewItem::Square :{
04584     QPointArray arr = QPointArray(4);
04585     arr.setPoint(0,-size/2,-size/2);
04586     arr.setPoint(1,size/2,-size/2);
04587     arr.setPoint(2,size/2,size/2);
04588     arr.setPoint(3,-size/2,size/2);
04589     arr.translate( ( size/2 ) +2 , ( size/2 ) +2);
04590     paint.drawPolygon( arr );
04591     break;
04592   }
04593   case  KDGanttViewItem::Circle  :{
04594     paint.drawEllipse( 2, 2, size, size);
04595     break;
04596   }
04597   }
04598   paint.end();
04599   return p;
04600 }
04601 
04602 int KDGanttView::getIndex( KDGanttViewItem::Type type) const
04603 {
04604     int index = -1;
04605     switch (type) {
04606     case (KDGanttViewItem::Event):
04607         index = 0;
04608         break;
04609     case (KDGanttViewItem::Task):
04610         index = 1;
04611         break;
04612     case (KDGanttViewItem::Summary):
04613         index = 2;
04614         break;
04615     default:
04616         index = -1;
04617     }
04618     return index;
04619 }
04620 
04621 
04622 void KDGanttView::initDefaults()
04623 {
04624   int i;
04625   // We have 3 item types. Set all undefined to true.
04626     for (i = 0;i<3;++i) {
04627         undefinedShape[i] = true;
04628         undefinedColor[i] = true;
04629         undefinedColorHL[i] = true;
04630     }
04631     // setting the default colors
04632     myDefaultColor [ getIndex( KDGanttViewItem::Event ) ] =  Qt::blue; //event
04633     myDefaultColorHL [ getIndex( KDGanttViewItem::Event ) ] =  Qt::red;
04634     myDefaultColor [ getIndex( KDGanttViewItem::Task ) ] =  Qt::green;//task
04635     myDefaultColorHL [ getIndex( KDGanttViewItem::Task ) ] =  Qt::red;
04636     myDefaultColor [ getIndex( KDGanttViewItem::Summary ) ] =  Qt::cyan;//summary
04637     myDefaultColorHL [ getIndex( KDGanttViewItem::Summary ) ] =  Qt::red;
04638 
04639     // setting the default shape types
04640     // currently, we take for each item for all three shapes (start, middle, end) the same default shape
04641     for (i = 0;i<3;++i) {
04642       myDefaultShape [3*getIndex( KDGanttViewItem::Event )+ i] =  KDGanttViewItem::Diamond; //event
04643       myDefaultShape [3*getIndex( KDGanttViewItem::Task ) +i] =  KDGanttViewItem::Square; //task
04644       myDefaultShape [3*getIndex( KDGanttViewItem::Summary ) +i] =  KDGanttViewItem::TriangleDown; //summary
04645 
04646     }
04647 }
04648 
04649 
04650 
04654 int KDGanttView::addColumn( const QString& label, int width )
04655 {
04656     return myListView->addColumn( label, width );
04657 }
04658 
04659 
04664 int KDGanttView::addColumn( const QIconSet& iconset, const QString& label,
04665                             int width )
04666 {
04667     return myListView->addColumn( iconset, label, width );
04668 }
04669 
04670 
04674 void KDGanttView::removeColumn( int index )
04675 {
04676     myListView->removeColumn( index );
04677 }
04678 
04679 
04683 KDGanttViewItem* KDGanttView::selectedItem() const
04684 {
04685     return static_cast<KDGanttViewItem*>( myListView->selectedItem() );
04686 }
04687 
04688 
04692 void KDGanttView::setSelected( KDGanttViewItem* item, bool selected )
04693 {
04694     myListView->setSelected( item, selected );
04695 }
04696 
04697 
04711 KDGanttViewItem* KDGanttView::getItemByName( const QString& name ) const
04712 {
04713     KDGanttViewItem* temp =  firstChild(),* ret;
04714     while (temp != 0) {
04715       if ( (ret = temp->getChildByName( name ) ) )
04716     return ret;
04717       temp = temp->nextSibling();
04718     }
04719     return 0;
04720 }
04739 KDGanttViewItem* KDGanttView::getItemByUid( const QString& uid,  KDGanttViewItem* parentItem ) const
04740 {
04741     if ( parentItem != 0 )
04742         return parentItem->getChildByUid( uid );
04743 
04744     KDGanttViewItem* temp =  firstChild(),* ret;
04745     while (temp != 0) {
04746       if ( (ret = temp->getChildByUid( uid ) ) )
04747     return ret;
04748       temp = temp->nextSibling();
04749     }
04750     return 0;
04751 }
04752 
04753 
04765 KDGanttViewItem* KDGanttView::getItemByListViewPos( const QPoint& pos ) const
04766 {
04767     return static_cast<KDGanttViewItem*>( myListView->itemAt(myListView->mapFromGlobal(pos) ));
04768 }
04769 
04770 
04785 KDGanttViewItem* KDGanttView::getItemByGanttViewPos( const QPoint& pos ) const
04786 {
04787   KDGanttViewItem* item;
04788   QPoint local = myCanvasView->mapFromGlobal(pos);
04789 
04790     QCanvasItemList il = myTimeTable->collisions( myCanvasView->viewportToContents( local ));
04791     QCanvasItemList::Iterator it;
04792     for ( it = il.begin(); it != il.end(); ++it ) {
04793       if ( myCanvasView->getType(*it) == Type_is_KDGanttViewItem) {
04794     item = myCanvasView->getItem(*it);
04795     if ( item->enabled() )
04796       return item;
04797       }
04798     }
04799     return 0;
04800 }
04801 
04802 
04817 KDGanttViewItem* KDGanttView::getItemAt( const QPoint& pos, bool global ) const
04818 {
04819   KDGanttViewItem* item;
04820   KDGanttViewItem* retItem = 0;
04821   int y;
04822   if ( global )
04823       y = myCanvasView->viewport()->mapFromGlobal(pos).y()+myCanvasView->contentsY ();
04824   else
04825     y = pos.y();
04826   item = firstChild();
04827   while ( item != 0 ) {
04828     int yc = item->itemPos();
04829     if ( yc <= y && y < yc + item->height()) {
04830       retItem = item;
04831       break;
04832     }
04833     item = item->itemBelow();
04834   }
04835   return retItem;
04836 
04837 }
04846 void  KDGanttView::setAddTickcountForTimeline( int count )
04847 {
04848     mAddTickcountForTimeline = count;
04849 }
04857 int  KDGanttView::addTickcountForTimeline() const
04858 {
04859     return mAddTickcountForTimeline;
04860 }
04861 
04862 void KDGanttView::addTickRight()
04863 {
04864   if ( !mFixedHorizon && _enableAdding && myCanvasView->horizontalScrollBar()->value() ==  myCanvasView->horizontalScrollBar()->maximum()) {
04865     //myCanvasView->horizontalScrollBar()->blockSignals( true );
04866     myTimeHeader->addTickRight();
04867     //myCanvasView->horizontalScrollBar()->blockSignals( false );
04868     myCanvasView->updateHorScrollBar();
04869     setTimelineToEnd();
04870   }
04871 }
04872 
04873 void KDGanttView::addTickLeft()
04874 {
04875     if (!mUserHorizonChangeEnabled) {
04876         emit addOneTickLeft();
04877         return;
04878     }
04879     if (  myCanvasView->horizontalScrollBar()->value() == 0 ) {
04880         myTimeHeader->addTickLeft( mAddTickcountForTimeline );
04881     }
04882   if ( !mFixedHorizon && _enableAdding && myCanvasView->horizontalScrollBar()->value() == 0 ) {
04883     myCanvasView->horizontalScrollBar()->blockSignals( true );
04884     myTimeHeader->addTickLeft();
04885     myCanvasView->horizontalScrollBar()->blockSignals( false );
04886     setTimelineToStart();
04887   }
04888 }
04889 
04890 
04891 void KDGanttView::enableAdding( int val )
04892 {
04893   _enableAdding = ( val == 0 || val == myCanvasView->horizontalScrollBar()->maximum());
04894 }
04895 
04896 
04902 int KDGanttView::childCount() const
04903 {
04904     return myListView->childCount();
04905 }
04906 
04917 void KDGanttView::clearAll()
04918 {
04919   bool block = myTimeTable->blockUpdating();
04920   myTimeTable->setBlockUpdating( true );
04921   clearLegend();
04922   clearBackgroundColor();
04923   setHorBackgroundLines( 0 );
04924   QPtrList<KDGanttViewTaskLink>  tll = taskLinks();
04925   tll.setAutoDelete( true );
04926   tll.clear();
04927   QPtrList<KDGanttViewTaskLinkGroup> tlg = myTaskLinkGroupList;
04928   tlg.setAutoDelete( true );
04929   tlg.clear();
04930   clear();
04931   myTimeTable->setBlockUpdating( block );
04932 }
04936 void KDGanttView::clear()
04937 {
04938     if ( ! childCount() ) return;
04939   bool block = myTimeTable->blockUpdating();
04940   myTimeTable->setBlockUpdating( true );
04941   myListView->clear();
04942   // in Qt3 wee need the processEvents(); to fix a crash
04943   // in Qt4 with Qt3 compat it crashes here
04944   // I had a look at the Q3ListView source code:
04945   // in theory it may not crash ... in theory
04946 #if QT_VERSION < 0x040000
04947   qApp->processEvents();
04948 #endif
04949   myTimeTable->setBlockUpdating( false );
04950   myTimeTable->updateMyContent();
04951 #if QT_VERSION < 0x040000
04952   qApp->processEvents();
04953 #endif
04954   myTimeTable->setBlockUpdating( block );
04955 }
04956 
04957 
04961 void KDGanttView::slot_lvDropped(QDropEvent* e, KDGanttViewItem* droppedItem, KDGanttViewItem* itemBelowMouse  )
04962 {
04963   emit dropped( e, droppedItem, itemBelowMouse);
04964 }
04965 
04969 QDragObject * KDGanttView::dragObject ()
04970 {
04971   return myListView->dragObject ();
04972 }
04973 
04974 
04978 void KDGanttView::startDrag ()
04979 {
04980   //myListView->pt_startDrag ();
04981 }
04982 
04983 
04987 #if 0
04988 // This overridden method is not called any more, as it is deprecated"
04989 void KDGanttView::setPaletteBackgroundColor( const QColor& col)
04990 {
04991   QPalette pal = palette();
04992   pal.setColor( backgroundRole(), col );
04993   QWidget::setPalette( pal );
04994   timeHeaderSpacerWidget->setPalette( pal );
04995 }
04996 #endif
04997 
05004 void KDGanttView::setGvBackgroundColor ( const QColor & c )
05005 {
05006   myTimeTable->setBackgroundColor( c );
05007 }
05008 
05009 
05016 void KDGanttView::setTimeHeaderBackgroundColor ( const QColor & c )
05017 {
05018   QPalette pal;
05019   pal.setColor( myTimeHeader->backgroundRole(), c );
05020 
05021   myTimeHeader->setPalette( pal );
05022   //rightWidget->setPalette( pal );
05023 
05024   pal.setColor( timeHeaderSpacerWidget->backgroundRole(), c );
05025   timeHeaderSpacerWidget->setPalette( pal );
05026 }
05027 
05028 
05035 void KDGanttView::setLegendHeaderBackgroundColor ( const QColor & c )
05036 {
05037   QPalette pal;
05038   pal.setColor( myLegend->backgroundRole(), c );
05039   myLegend->setPalette( pal );
05040 
05041   pal.setColor( leftWidget->backgroundRole(), c );
05042   leftWidget->setPalette( pal );
05043 }
05044 
05045 
05052 void KDGanttView::setLvBackgroundColor ( const QColor & c )
05053 {
05054   QPalette pal;
05055   pal.setColor( myListView->viewport()->backgroundRole(), c );
05056   myListView->viewport()->setPalette( pal );
05057 }
05058 
05059 
05066 QColor KDGanttView::lvBackgroundColor ( )const
05067 {
05068   return myListView->viewport()->palette().color(myListView->viewport()->backgroundRole());
05069 }
05070 
05071 
05078 QColor KDGanttView::gvBackgroundColor () const
05079 {
05080  return myTimeTable->backgroundColor( );
05081 }
05082 
05083 
05090 QColor KDGanttView::timeHeaderBackgroundColor () const
05091 {
05092   return myTimeHeader->palette().color(myTimeHeader->backgroundRole());
05093 }
05094 
05095 
05102 QColor KDGanttView::legendHeaderBackgroundColor () const
05103 {
05104   return myLegend->palette().color(myLegend->backgroundRole());
05105 }
05106 
05107 
05122 void KDGanttView::addUserdefinedLegendHeaderWidget( QWidget * w )
05123 {
05124   if ( w ) {
05125     w->setParent ( spacerLeft );
05126     spacerLeftLayout->addWidget( w );
05127   }
05128 }
05129 
05130 
05139 void KDGanttView::setDragEnabled( bool b )
05140 {
05141   fDragEnabled = b;
05142  QListViewItemIterator it( myListView );
05143  for ( ; it.current(); ++it ) {
05144    (( KDGanttViewItem* )it.current())->setDragEnabled(b);
05145  }
05146 
05147 }
05148 
05149 
05158 void KDGanttView::setDropEnabled( bool b )
05159 {
05160   fDropEnabled = b;
05161 
05162   //myListView->setAcceptDrops( b );
05163  QListViewItemIterator it( myListView );
05164  for ( ; it.current(); ++it ) {
05165    (( KDGanttViewItem* )it.current())->setDropEnabled(b);
05166  }
05167 }
05168 
05169 
05178 void KDGanttView::setDragDropEnabled( bool b )
05179 {
05180   setDropEnabled( b );
05181   setDragEnabled( b );
05182 }
05183 
05184 
05191 bool KDGanttView::isDragEnabled() const
05192 {
05193   return fDragEnabled;
05194 }
05195 
05196 
05203 bool KDGanttView::isDropEnabled() const
05204 {
05205  return fDropEnabled;
05206 }
05207 
05208 
05212 bool KDGanttView::dragEnabled() const
05213 {
05214   return isDragEnabled();
05215 }
05216 
05217 
05221 bool KDGanttView::dropEnabled() const
05222 {
05223  return isDropEnabled();
05224 }
05225 
05226 
05253 bool  KDGanttView::lvDropEvent ( QDropEvent* e,
05254                  KDGanttViewItem* droppedItem,
05255                  KDGanttViewItem* itemBelowMouse )
05256 {
05257     Q_UNUSED( e );
05258     Q_UNUSED( droppedItem );
05259     Q_UNUSED( itemBelowMouse );
05260 
05261   // Example code for user defined behaviour:
05262   // we want to accept the usual drags and the drags of files, which may be
05263   // a saved Gantt file.
05264   // Please uncomment the following lines for this behaviour
05265   // You have to uncomment lines in lvDragMoveEvent() and llvDragEnterEvent() as well
05266 
05267   // ************** begin example ************
05268   /*
05269   if ( QUriDrag::canDecode( e ) ) {
05270     QStrList lst;
05271     QUriDrag::decode( e, lst );
05272     // we try the first file of icon-url-list
05273     QString str = lst.at ( 0 );
05274     // remove file: at beginning of string
05275     str = str.right( str.length() - 5  );
05276     QFileInfo info;
05277     info.setFile( str ) ;
05278     if ( info.isFile() ) {
05279       if (!QMessageBox::information( this, "KDGantt Drag&Drop test",
05280                      "Try to insert file: "+ str + " ?",
05281                      "&Okay", "&Cancel",0,1  ) ) {
05282     QFile file( str );
05283     loadProject( &file ) ;
05284     }
05285     return true;
05286   }
05287   */
05288   // *********** end example ****************
05289   return false;
05290 }
05291 
05292 
05309 void  KDGanttView::lvDragEnterEvent ( QDragEnterEvent * e)
05310 {
05311   // the standard behaviour:
05312   // accept drag enter events, if KDGanttViewItemDrag can decode the event
05313   // e->accept(KDGanttViewItemDrag::canDecode(e) );
05314 
05315   if ( KDGanttViewItemDrag::canDecode(e) ) {
05316     e->setAccepted( true);
05317     return;
05318   }
05319 
05320   // example code for user defined behaviour:
05321   // we want to accecpt the usual drags and the drags of files, which may be
05322   // a saved Gantt file
05323   // Please uncomment the following lines for this behaviour
05324   // You have to uncomment lines in lvDragMoveEvent() and lvDropEvent () as well
05325 
05326   //  if ( QUriDrag::canDecode( e ) ) {
05327   // e->accept(true);
05328   //  return;
05329   // }
05330 
05331   e->setAccepted( false );
05332 }
05333 
05334 
05363 bool  KDGanttView::lvDragMoveEvent ( QDragMoveEvent* /*e*/,
05364                      KDGanttViewItem* /* draggedItem*/,
05365                      KDGanttViewItem* /*itemBelowMouse*/)
05366 {
05367 
05368   // Example code 1:
05369   // To generally block items to be inserted as root items, subclass KDGanttView
05370   // and reimplement this method with to following code uncommented:
05371 
05372   // if ( !itemBelowMouse ) {
05373   //  e->accept( false );
05374   //  return true;
05375   //}
05376   //return false;
05377 
05378   // Example code 2:
05379   // To allow the drags of files, which may be
05380   // a saved Gantt file, subclass KDGanttView
05381   // and reimplement this method with to following code uncommented:
05382 
05383   // if ( QUriDrag::canDecode( e ) ) {
05384   //   e->accept(true);
05385   //   return true;
05386   //  }
05387 
05388 
05389  // normal behaviour - the internal drag move event handling should be executed
05390   return false;
05391 }
05392 
05393 
05403 void  KDGanttView::lvStartDrag (KDGanttViewItem* item)
05404 {
05405   QDragObject* d = new KDGanttViewItemDrag(item, this, "itemdrag" );
05406   // call d->drag() to start the dragging
05407   // d->drag() returns true, if a move was requested as a drag
05408   // if a copy (by pressing the <Ctrl>-key) was performed, d->drag() returns false
05409   // In order to avoid starting drags for particular items, subclass KDGanttView
05410   // an reimplement this method.
05411   // insert here some code like
05412   // if ( item->parent() )
05413   // return;
05414   // This particular code will make it impossible to drag other items but root items.
05415   if ( d->drag()) {
05416       delete item;
05417   }
05418 }
05419 
05420 
05428 void  KDGanttView::setListViewWidth( int w )
05429 {
05430   int sw = mySplitter->width();
05431   QValueList<int> list;
05432   list.append(w);
05433   list.append(sw-w);
05434   mySplitter->setSizes( list );
05435 }
05436 
05437 
05444 int  KDGanttView::listViewWidth( )
05445 {
05446   return leftWidget->width();
05447 }
05448 
05449 
05459 void  KDGanttView::setLvVScrollBarMode( QScrollView::ScrollBarMode m )
05460 {
05461   myListView->setVScrollBarMode ( m );
05462 }
05463 
05464 
05474 void  KDGanttView::setGvVScrollBarMode( QScrollView::ScrollBarMode m )
05475 {
05476     myCanvasView->setMyVScrollBarMode ( m );
05477 #if 0
05478   if ( m == QScrollView::Auto )
05479     qDebug() "KDGanttView::setListViewVScrollBarMode: QScrollView::Auto not supported. Nothing changed. ";
05480   else
05481     {
05482       myCanvasView->setMyVScrollBarMode ( m );
05483       if ( m == QScrollView::AlwaysOn )
05484     timeHeaderSpacerWidget->setFixedWidth(myCanvasView->verticalScrollBar()->width() );
05485       else
05486     timeHeaderSpacerWidget->setFixedWidth( 0 );
05487     }
05488 #endif
05489 }
05490 
05491 
05492 void  KDGanttView::itemAboutToBeDeleted( KDGanttViewItem * item)
05493 {
05494 #if QT_VERSION < 0x040000
05495   if ( myItemAttributeDialog && myItemAttributeDialog->getItem() == item ) {
05496     myItemAttributeDialog->reset( 0 );
05497   }
05498 #endif
05499   emit itemDeleted( item );
05500 }
05501 
05502 
05514 void KDGanttView::setUserHorizonChangeEnabled( bool b )
05515 {
05516     mUserHorizonChangeEnabled = b;
05517 }
05518 
05519 bool KDGanttView::userHorizonChangeEnabled() const
05527 {
05528     return mUserHorizonChangeEnabled;
05529 }
05530 
05548 void KDGanttView::setGermanDateTimeFormat()
05549 {
05550     setTimeHeaderTooltipDateTimeFormat( "dddd, dd. MMMM yyyy - h:mm:ss" );
05551     setHourFormat(Hour_24_FourDigit);
05552     setWeekScaleShowNumber( true );
05553     setWeekStartsMonday( true );
05554     setTimeHeaderDateFormatWeek( " d. MMM 'yy" );
05555     setTimeHeaderDateFormatDay( " d. MMM 'yy" );
05556     setTimeHeaderDatetimeFormatHour( "dddd, dd. MMM 'yy" );
05557     setTimeHeaderDatetimeFormatMinute( "ddd, dd. MMM h:mm" );
05558     //setTimeHeaderDatetimeFormatSecond( "dddd, dd. MMM h:mm" );
05559 }
05560 
05572 QString KDGanttView::timeHeaderTooltipDateTimeFormat() const
05573 {
05574     return myTimeHeader->tooltipDateTimeFormat();
05575 }
05587 void KDGanttView::setTimeHeaderTooltipDateTimeFormat( const QString& fmt )
05588 {
05589     myTimeHeader->setTooltipDateTimeFormat( fmt );
05590 }
05591 
05603 QString KDGanttView::timeHeaderDateFormatMonth() const
05604 {
05605     return myTimeHeader->dateFormatMonth();
05606 }
05607 
05618 void KDGanttView::setTimeHeaderDateFormatMonth( const QString& fmt )
05619 {
05620     myTimeHeader->setDateFormatMonth( fmt );
05621 }
05622 
05634 QString KDGanttView::timeHeaderDateFormatWeek() const
05635 {
05636     return myTimeHeader->dateFormatWeek();
05637 }
05648 void KDGanttView::setTimeHeaderDateFormatWeek( const QString& fmt )
05649 {
05650     myTimeHeader->setDateFormatWeek( fmt );
05651 }
05663 QString KDGanttView::timeHeaderDateFormatDay() const
05664 {
05665     return myTimeHeader->dateFormatDay();
05666 }
05677 void KDGanttView::setTimeHeaderDateFormatDay( const QString& fmt )
05678 {
05679     myTimeHeader->setDateFormatDay( fmt );
05680 }
05681 
05682 
05683 
05695 QString KDGanttView::timeHeaderDatetimeFormatSecond() const
05696 {
05697     return myTimeHeader->datetimeFormatSecond();
05698 }
05709 void KDGanttView::setTimeHeaderDatetimeFormatSecond( const QString& fmt )
05710 {
05711     myTimeHeader->setDatetimeFormatSecond( fmt );
05712 }
05713 
05725 QString KDGanttView::timeHeaderDatetimeFormatMinute() const
05726 {
05727     return myTimeHeader->datetimeFormatMinute();
05728 }
05739 void KDGanttView::setTimeHeaderDatetimeFormatMinute( const QString& fmt )
05740 {
05741     myTimeHeader->setDatetimeFormatMinute( fmt );
05742 }
05743 
05744 
05756 QString KDGanttView::timeHeaderDatetimeFormatHour() const
05757 {
05758     return myTimeHeader->datetimeFormatHour();
05759 }
05770 void KDGanttView::setTimeHeaderDatetimeFormatHour( const QString& fmt )
05771 {
05772     myTimeHeader->setDatetimeFormatHour( fmt );
05773 }
05785 void KDGanttView::setWeekStartsMonday( bool b )
05786 {
05787     myTimeHeader->setWeekStartsMonday( b );
05788 }
05789 
05796 bool KDGanttView::weekStartsMonday() const
05797 {
05798     return</