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

kdgantt1

KDGanttViewItem.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewItem.cpp 836291 2008-07-22 04:34:42Z pradeepto $
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 
00034 #include "KDGanttViewSubwidgets.h"
00035 #include "KDGanttViewTaskItem.h"
00036 #include "KDGanttViewSummaryItem.h"
00037 #include "KDGanttViewEventItem.h"
00038 #if QT_VERSION < 0x040000
00039 #include "itemAttributeDialog.h"
00040 #endif
00041 #include <QtDebug>
00042 
00043 #include "qpainter.h"
00044 
00045 #include "KDGanttXMLTools.h"
00046 
00047 
00161 QDict<KDGanttViewItem> KDGanttViewItem::sItemDict;
00162 
00172 KDGanttViewItem::KDGanttViewItem( Type type, KDGanttView* view,
00173                                   const QString& lvtext,
00174                                   const QString& name ) :
00175     QListViewItem(view->myListView,lvtext)
00176 {
00177     initColorAndShapes(type);
00178     generateAndInsertName( name );
00179 
00180 }
00181 
00182 
00193 KDGanttViewItem::KDGanttViewItem( Type type, KDGanttViewItem* parentItem,
00194                                   const QString& lvtext,
00195                                   const QString& name ) :
00196     QListViewItem(parentItem,lvtext)
00197 {
00198     initColorAndShapes(type);
00199     generateAndInsertName( name );
00200 }
00201 
00202 
00214 KDGanttViewItem::KDGanttViewItem( Type type, KDGanttView* view,
00215                                   KDGanttViewItem* after,
00216                                   const QString& lvtext,
00217                                   const QString& name ) :
00218     QListViewItem(view->myListView,after, lvtext)
00219 {
00220     initColorAndShapes(type);
00221     generateAndInsertName( name );
00222 }
00223 
00224 
00236 KDGanttViewItem::KDGanttViewItem( Type type, KDGanttViewItem* parentItem,
00237                                   KDGanttViewItem* after,
00238                                   const QString& lvtext,
00239                                   const QString& name ) :
00240     QListViewItem( parentItem, after, lvtext )
00241 {
00242     initColorAndShapes(type);
00243     generateAndInsertName( name );
00244 }
00245 
00246 
00250 KDGanttViewItem::~KDGanttViewItem()
00251 {
00252   myGanttView->itemAboutToBeDeleted( this );
00253   if ( startLine ) delete startLine;
00254   if ( endLine ) delete endLine  ;
00255   if ( startLineBack ) delete startLineBack  ;
00256   if ( endLineBack ) delete  endLineBack ;
00257   if ( actualEnd ) delete actualEnd  ;
00258   if ( mTextCanvas  ) delete mTextCanvas   ;
00259   if ( startShape ) delete  startShape ;
00260   if ( midShape ) delete midShape  ;
00261   if ( endShape ) delete endShape  ;
00262   if ( startShapeBack ) delete startShapeBack  ;
00263   if ( midShapeBack ) delete midShapeBack   ;
00264   if ( endShapeBack ) delete endShapeBack  ;
00265   if ( progressShape ) delete  progressShape ;
00266   if ( floatStartShape ) delete  floatStartShape ;
00267   if ( floatEndShape ) delete  floatEndShape ;
00268   bool block = myGanttView->myTimeTable->blockUpdating();
00269   myGanttView->myTimeTable->setBlockUpdating(); 
00270   myGanttView->myTimeTable->removeItemFromTasklinks( this );
00271   myGanttView->myCanvasView->resetCutPaste( this );
00272   if ( listView() ) {
00273       if ( isOpen() )
00274           setOpen( false );
00275       if ( parent() )
00276           parent()->takeItem( this );
00277       else
00278           myGanttView->myListView->takeItem( this );
00279       myGanttView->myTimeTable->setBlockUpdating( block );
00280       myGanttView->myTimeTable->updateMyContent();
00281   } else
00282     myGanttView->myTimeTable->setBlockUpdating( block );
00283   if( !_name.isEmpty() )
00284       sItemDict.remove( _name );
00285 }
00286 
00291 void KDGanttViewItem::generateAndInsertName( const QString& name )
00292 {
00293     // First check if we already had a name. This can be the case if
00294     // the item was reconstructed from an XML file.
00295     if( !_name.isEmpty() )
00296         // We had a name, remove it
00297         sItemDict.remove( _name );
00298     QString newName;
00299     if ( name.isEmpty() )
00300         // create unique name
00301         newName.sprintf( "%p", (void* )this );
00302     else {
00303         if ( sItemDict.find( name ) ) {
00304             newName.sprintf( "%p", (void* )this );
00305         }
00306         else 
00307             newName = name;
00308     }
00309     while (  sItemDict.find( newName ) )
00310         newName += "_";
00311     sItemDict.insert( newName, this );
00312     _name = newName;
00313 
00314 }
00315 
00325 bool KDGanttViewItem::moveConnector( KDGanttViewItem::Connector c, QPoint p )
00326 {
00327 
00328     Q_UNUSED( p )
00329     Q_UNUSED( c )
00330     return false;
00331 }
00332 
00342 KDGanttViewItem::Connector  KDGanttViewItem::getConnector( QPoint p )
00343 {
00344 
00345     Q_UNUSED( p )
00346             return KDGanttViewItem::NoConnector;
00347 }
00348 
00349 KDGanttViewItem::Connector KDGanttViewItem::getConnector( QPoint p, bool linkMode )
00350 {
00351 
00352     Q_UNUSED( p )
00353     Q_UNUSED( linkMode )
00354     return KDGanttViewItem::NoConnector;
00355 }
00356 
00365 KDGanttViewItem* KDGanttViewItem::find( const QString& name )
00366 {
00367     return sItemDict.find( name );
00368 }
00369 
00370 
00378 QString KDGanttViewItem::name() const
00379 {
00380     return _name;
00381 }
00382 
00383 
00393 QString KDGanttViewItem::typeString() const
00394 {
00395     return typeToString( myType );
00396 }
00397 
00398 
00406 KDGanttViewItem::Type KDGanttViewItem::type() const
00407 {
00408 
00409     return myType;
00410 
00411 }
00412 
00429 QPtrList <KDGanttViewItem>  KDGanttViewItem::getChildListForTimespan( const QDateTime& start, const QDateTime& end )
00430 {
00431     QPtrList <KDGanttViewItem> childList;
00432     KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00433     while (temp != 0) {
00434         if ( temp->getTimeForTimespan( start, end ) )
00435             childList.append( temp );
00436         temp = temp->nextSibling();
00437     }
00438     return childList;
00439 }
00440 
00470 unsigned int KDGanttViewItem::getTimeForTimespan( const QDateTime&, const QDateTime&)
00471 {
00472     return 0;
00473 }
00474 
00492 unsigned int KDGanttViewItem::getAllSubChildTimeForTimespan(  const QDateTime& start,  const QDateTime& end )
00493 {
00494     unsigned int retval = 0;
00495     KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00496     while (temp != 0) {
00497         retval += temp->getAllSubChildTimeForTimespan( start, end );
00498         temp = temp->nextSibling();
00499     }
00500     retval += getTimeForTimespan( start, end );
00501     return retval;
00502 }
00503 
00522 unsigned int KDGanttViewItem::getChildTimeForTimespan(  const QDateTime& start,  const QDateTime& end )
00523 {
00524     unsigned int retval = 0;
00525     KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00526     while (temp != 0) {
00527         retval += temp->getTimeForTimespan( start, end );
00528         temp = temp->nextSibling();
00529     }
00530     return retval;
00531 }
00532 
00540 void KDGanttViewItem::setAllSubitemsExpanded ( bool expand )
00541 {
00542     bool block = myGanttView->myTimeTable->blockUpdating();
00543     myGanttView->myTimeTable->setBlockUpdating( true );
00544     setOpen( expand );
00545     KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00546     while (temp != 0) {
00547         temp->setAllSubitemsExpanded(  expand );
00548         temp = temp->nextSibling();
00549     }
00550     myGanttView->myTimeTable->setBlockUpdating( block );
00551 
00552 }
00553 
00565 void KDGanttViewItem::setEnabled( bool on )
00566 {
00567   _enabled = on;
00568   if ( displaySubitemsAsGroup() ) {
00569     myGanttView->myTimeTable->inc_blockUpdating();
00570     KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00571     while (temp != 0) {
00572       temp->setEnabled(  on );
00573       temp = temp->nextSibling();
00574     }
00575     QListViewItem::setEnabled( on );
00576     myGanttView->myTimeTable->dec_blockUpdating();
00577   }
00578   updateCanvasItems();
00579 }
00580 
00581 
00588 bool KDGanttViewItem::enabled () const
00589 {
00590   return _enabled;
00591 }
00592 
00593 
00594 // *********************************
00601 void KDGanttViewItem::setItemVisible( bool on )
00602 {
00603   if ( on ) {
00604     resetSubitemVisibility();
00605   } else
00606     setVisible( false );
00607   //updateCanvasItems();
00608   myGanttView->myTimeTable->updateMyContent();
00609 }
00610 
00611 
00618 bool KDGanttViewItem::itemVisible () const
00619 {
00620   return QListViewItem::isVisible();
00621 }
00622 
00623 
00624 // *************************************
00625 
00633 void KDGanttViewItem::setEditable( bool editable )
00634 {
00635     isEditable = editable;
00636 }
00637 
00638 
00646 bool KDGanttViewItem::editable() const
00647 {
00648     return isEditable;
00649 }
00650 
00651 
00664 void KDGanttViewItem::setDisplaySubitemsAsGroup( bool show )
00665 {
00666   if ( !show && _displaySubitemsAsGroup)
00667     isVisibleInGanttView = true;
00668   _displaySubitemsAsGroup = show;
00669   if ( parent() )
00670     if ( parent()->isOpen() )
00671      parent()->setOpen( true );
00672   if ( isOpen() )
00673     setOpen( true );
00674   updateCanvasItems();
00675 }
00676 
00677 
00685 bool KDGanttViewItem::displaySubitemsAsGroup() const
00686 {
00687     return _displaySubitemsAsGroup;
00688 }
00689 
00690 
00710 void KDGanttViewItem::setPriority( int prio )
00711 {
00712   if ( prio < 1 )
00713     prio = 1;
00714   if (prio > 199 )
00715     prio = 199;
00716   _priority = prio;
00717   updateCanvasItems();
00718 }
00719 
00720 
00726 int KDGanttViewItem::priority()
00727 {
00728     return _priority;
00729 }
00730 
00731 
00740 void KDGanttViewItem::setStartTime( const QDateTime&  )
00741 {
00742 }
00743 
00744 
00751 QDateTime KDGanttViewItem::startTime() const
00752 {
00753     return myStartTime;
00754 }
00755 
00756 
00765 void KDGanttViewItem::setEndTime( const QDateTime& end )
00766 {
00767     switch( type() ) {
00768     case Event:
00769         qDebug( "KDGantt:Event Item has no end time" );
00770         break;
00771     case Summary:
00772         ((KDGanttViewSummaryItem*)this)->setEndTime( end );
00773         break;
00774     case Task:
00775         qDebug( "KDGantt:Task Item has no end time" );
00776         break;
00777     default:
00778         qDebug( "Unknown type in KDGanttViewItem::typeToString()" );
00779     }
00780 }
00781 
00782 
00789 QDateTime KDGanttViewItem::endTime() const
00790 {
00791     return myEndTime;
00792 }
00793 
00794 
00806 void KDGanttViewItem::setText( const QString& text )
00807 {
00808     textcanvas()->setText(text);
00809     textCanvasText = text;
00810     updateCanvasItems();
00811 }
00812 
00813 
00821 QString KDGanttViewItem::text() const
00822 {
00823     return textCanvasText;
00824 }
00825 
00826 
00830 void KDGanttViewItem::setListViewText( const QString& text, int column )
00831 {
00832     QListViewItem::setText( column, text );
00833 }
00834 
00835 
00843 void KDGanttViewItem::setListViewText( int column, const QString& text )
00844 {
00845     QListViewItem::setText( column, text );
00846 }
00847 
00848 
00857 QString KDGanttViewItem::listViewText( int column ) const
00858 {
00859     return QListViewItem::text( column );
00860 }
00861 
00862 
00869 void KDGanttViewItem::setFont( const QFont& font )
00870 {
00871     textcanvas()->setFont(font);
00872     updateCanvasItems();
00873 }
00874 
00875 
00882 QFont KDGanttViewItem::font() const
00883 {
00884 
00885     if (mTextCanvas) 
00886         return mTextCanvas->font();
00887     return myGanttView->font();
00888 }
00889 
00890 
00897 void KDGanttViewItem::setTooltipText( const QString& text )
00898 {
00899     myToolTipText = text;
00900 }
00901 
00902 
00909 QString KDGanttViewItem::tooltipText() const
00910 {
00911 
00912     return myToolTipText;
00913 }
00914 
00915 
00922 void KDGanttViewItem::setWhatsThisText( const QString& text )
00923 {
00924     myWhatsThisText = text;
00925 }
00926 
00927 
00935 QString KDGanttViewItem::whatsThisText() const
00936 {
00937     return myWhatsThisText;
00938 }
00939 
00940 
00952 void KDGanttViewItem::setHighlight( bool highlight )
00953 {
00954 
00955     isHighlighted = highlight;
00956     if ( displaySubitemsAsGroup() ) {
00957       myGanttView->myTimeTable->inc_blockUpdating();
00958       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
00959       while (temp != 0) {
00960     temp->setHighlight( highlight );
00961     temp = temp->nextSibling();
00962       }
00963       myGanttView->myTimeTable->dec_blockUpdating();
00964     }
00965 
00966     updateCanvasItems();
00967 }
00968 
00969 
00977 bool KDGanttViewItem::highlight() const
00978 {
00979     return isHighlighted;
00980 }
00981 
00982 
00995 void KDGanttViewItem::setShapes( Shape start, Shape middle, Shape end )
00996 {
00997 
00998     myStartShape =  start;
00999     myMiddleShape= middle;
01000     myEndShape=  end;
01001     createShape(startShape,startShapeBack,start);
01002     createShape(midShape,midShapeBack,middle);
01003     midShape->setZ( 4 );
01004     createShape(endShape,endShapeBack,end);
01005     updateCanvasItems();
01006 }
01007 
01008 
01021 void KDGanttViewItem::createShape( KDCanvasPolygonItem* &itemShape,
01022                                    KDCanvasPolygonItem* &itemShapeBack,
01023                                    Shape shape )
01024 {
01025   if ( itemShape && type() ==  Task )
01026     return;
01027     if (itemShape) delete itemShape;
01028     if (itemShapeBack) delete itemShapeBack;
01029 
01030     QCanvasPolygonalItem * item;
01031     QCanvasPolygonalItem * itemBack;
01032     int size = myItemSize+2;
01033     int hei = (myItemSize/3)/2;
01034     switch (shape) {
01035     case TriangleDown:
01036         {
01037             item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01038             QPointArray arr = QPointArray(3);
01039             arr.setPoint(0,-size/2,-hei);
01040             arr.setPoint(1,size/2,-hei);
01041             arr.setPoint(2,0,((size/2)-hei));
01042             ((QCanvasPolygon*)item)->setPoints(arr);
01043             size += 4;hei +=1;
01044             itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01045             arr.setPoint(0,-size/2,-hei);
01046             arr.setPoint(1,size/2,-hei);
01047             arr.setPoint(2,0,((size/2)-hei));
01048             ((QCanvasPolygon*)itemBack)->setPoints(arr);
01049 
01050             break;
01051         }
01052     case TriangleUp:
01053         {
01054             // I really do not know why, but  we get only an TriangleUp-icon
01055             // of the same size as a TriangleDown-icon, if we increment the size by 2
01056             size+=2;
01057             item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01058             QPointArray arr = QPointArray(3);
01059             arr.setPoint(0,-size/2,hei);
01060             arr.setPoint(1,size/2,hei);
01061             arr.setPoint(2,0,(-size/2)+hei);
01062             ((QCanvasPolygon*)item)->setPoints(arr);
01063             size += 4;hei +=1;
01064             itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01065             arr.setPoint(0,-size/2,hei);
01066             arr.setPoint(1,size/2,hei);
01067             arr.setPoint(2,0,(-size/2)+hei);
01068             ((QCanvasPolygon*)itemBack)->setPoints(arr);
01069 
01070             break;
01071         }
01072 
01073     case Diamond:
01074         {
01075             item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01076             QPointArray arr = QPointArray(4);
01077             arr.setPoint(0,0,-size/2);
01078             arr.setPoint(1,size/2,0);
01079             arr.setPoint(2,0,size/2);
01080             arr.setPoint(3,-size/2,0);
01081             ((QCanvasPolygon*)item)->setPoints(arr);
01082             size += 2;hei +=1;
01083             itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01084             arr.setPoint(0,0,-size/2);
01085             arr.setPoint(1,size/2,0);
01086             arr.setPoint(2,0,size/2);
01087             arr.setPoint(3,-size/2,0);
01088             ((QCanvasPolygon*)itemBack)->setPoints(arr);
01089             break;
01090         }
01091 
01092     case Square:
01093         {
01094             size -=2;
01095             item = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01096             QPointArray arr = QPointArray(4);
01097             arr.setPoint(0,-size/2,-size/2);
01098             arr.setPoint(1,size/2,-size/2);
01099             arr.setPoint(2,size/2,size/2);
01100             arr.setPoint(3,-size/2,size/2);
01101             ((QCanvasPolygon*)item)->setPoints(arr);
01102             size += 2;hei +=1;
01103             itemBack = new KDCanvasPolygon(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01104             arr.setPoint(0,-size/2,-size/2);
01105             arr.setPoint(1,size/2,-size/2);
01106             arr.setPoint(2,size/2,size/2);
01107             arr.setPoint(3,-size/2,size/2);
01108             ((QCanvasPolygon*)itemBack)->setPoints(arr);
01109             break;
01110         }
01111 
01112     case Circle:
01113         {
01114             size -= 2;
01115             item = new KDCanvasEllipse(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01116             ((KDCanvasEllipse*)item)->setSize(size,size);
01117             size += 2;hei +=1;
01118             itemBack = new KDCanvasEllipse(myGanttView->myTimeTable, this,Type_is_KDGanttViewItem);
01119             ((KDCanvasEllipse*)itemBack)->setSize(size,size);
01120             break;
01121         }
01122     default:
01123         // Uninitialized shape, can e.g. be the case with free-busy
01124         // items which don't have any shapes
01125         return;
01126     }
01127     item->setBrush(Qt::SolidPattern);
01128     item->setZ(5);
01129     itemShape = (KDCanvasPolygonItem*) item;
01130     itemBack->setBrush(Qt::SolidPattern);
01131     itemBack->setZ(3);
01132     itemShapeBack = (KDCanvasPolygonItem*) itemBack;
01133 
01134 }
01135 
01136 
01145 void KDGanttViewItem::shapes( Shape& start, Shape& middle, Shape& end ) const
01146 {
01147     start = myStartShape;
01148     middle = myMiddleShape;
01149     end = myEndShape;
01150 }
01151 
01152 
01165 void KDGanttViewItem::setColors( const QColor& start, const QColor& middle,
01166                                  const QColor& end )
01167 {
01168 
01169     myStartColor=start ;
01170     myMiddleColor= middle;
01171     myEndColor= end;
01172     if ( displaySubitemsAsGroup() ) {
01173       myGanttView->myTimeTable->inc_blockUpdating();
01174       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
01175       while (temp != 0) {
01176           if ( !temp->displaySubitemsAsGroup() )
01177               temp->setColors( start, middle, end );
01178           temp = temp->nextSibling();
01179       }
01180       myGanttView->myTimeTable->dec_blockUpdating();
01181     }
01182     updateCanvasItems();
01183 }
01184 
01185 
01194 void KDGanttViewItem::colors( QColor& start, QColor& middle, QColor& end ) const
01195 {
01196     start = myStartColor ;
01197     middle =  myMiddleColor;
01198     end  = myEndColor;
01199 
01200 }
01201 
01202 
01220 void KDGanttViewItem::setHighlightColors( const QColor& start, const QColor& middle, const QColor& end )
01221 {
01222     myStartColorHL=start ;
01223     myMiddleColorHL= middle;
01224     myEndColorHL= end;
01225     if ( displaySubitemsAsGroup() ) {
01226       myGanttView->myTimeTable->inc_blockUpdating();
01227       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
01228       while (temp != 0) {
01229           if ( !temp->displaySubitemsAsGroup() )
01230               temp->setHighlightColors( start,  middle,  end );
01231           temp = temp->nextSibling();
01232       }
01233       myGanttView->myTimeTable->dec_blockUpdating();
01234     }
01235     updateCanvasItems();
01236 }
01237 
01238 
01247 void KDGanttViewItem::highlightColors( QColor& start, QColor& middle, QColor& end ) const
01248 {
01249     start = myStartColorHL ;
01250     middle =  myMiddleColorHL;
01251     end  = myEndColorHL;
01252 }
01253 
01254 
01267 void KDGanttViewItem::setTextColor( const QColor& color )
01268 {
01269 
01270    myTextColor = color;
01271    if ( displaySubitemsAsGroup() ) {
01272       myGanttView->myTimeTable->inc_blockUpdating();
01273       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
01274       while (temp != 0) {
01275     temp->setTextColor(color);
01276     temp = temp->nextSibling();
01277       }
01278       myGanttView->myTimeTable->dec_blockUpdating();
01279     }
01280     updateCanvasItems();
01281 }
01282 
01283 
01290 QColor KDGanttViewItem::textColor() const
01291 {
01292     return myTextColor;
01293 }
01294 
01295 
01324 void KDGanttViewItem::setPixmap( int column, const QPixmap& pixmap )
01325 {
01326     QListViewItem::setPixmap( column, pixmap );
01327 }
01328 
01332 void KDGanttViewItem::setPixmap( const QPixmap& pixmap )
01333 {
01334     QListViewItem::setPixmap( 0, pixmap );
01335 }
01336 
01337 
01345 const QPixmap* KDGanttViewItem::pixmap( int column ) const
01346 {
01347     return QListViewItem::pixmap( column );
01348 }
01349 
01350 
01366 void KDGanttViewItem::setDefaultColor( const QColor& color )
01367 {
01368     myDefaultColor = color;
01369 
01370 
01371    if ( displaySubitemsAsGroup() ) {
01372       myGanttView->myTimeTable->inc_blockUpdating();
01373       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
01374       while (temp != 0) {
01375     temp->setDefaultColor( color );
01376     temp = temp->nextSibling();
01377       }
01378       myGanttView->myTimeTable->dec_blockUpdating();
01379     }
01380     updateCanvasItems();
01381 }
01382 
01383 
01384 
01392 QColor KDGanttViewItem::defaultColor() const
01393 {
01394     return myDefaultColor;
01395 }
01396 
01397 
01413 void KDGanttViewItem::setDefaultHighlightColor( const QColor& color )
01414 {
01415     myDefaultColorHL = color;
01416    if ( displaySubitemsAsGroup() ) {
01417       myGanttView->myTimeTable->inc_blockUpdating();
01418       KDGanttViewItem* temp = (KDGanttViewItem*) firstChild();
01419       while (temp != 0) {
01420     temp->setDefaultHighlightColor( color );
01421     temp = temp->nextSibling();
01422       }
01423       myGanttView->myTimeTable->dec_blockUpdating();
01424     }
01425     updateCanvasItems();
01426 }
01427 
01428 
01436 QColor KDGanttViewItem::defaultHighlightColor() const
01437 {
01438     return myDefaultColorHL;
01439 }
01440 
01441 
01447 KDGanttViewItem* KDGanttViewItem::firstChild() const
01448 {
01449 
01450     return (KDGanttViewItem* )QListViewItem::firstChild();
01451 }
01452 
01453 
01460 KDGanttViewItem* KDGanttViewItem::nextSibling() const
01461 {
01462     return (KDGanttViewItem* )QListViewItem::nextSibling();
01463 }
01464 
01465 
01472 KDGanttViewItem* KDGanttViewItem::parent() const
01473 {
01474     return (KDGanttViewItem*)QListViewItem::parent();
01475 }
01476 
01477 
01483 KDGanttViewItem* KDGanttViewItem::itemAbove()
01484 {
01485     return (KDGanttViewItem* )QListViewItem::itemAbove();
01486 }
01487 
01488 
01497 KDGanttViewItem* KDGanttViewItem::itemBelow( bool includeDisabled )
01498 {
01499 
01500   KDGanttViewItem*  retItem = (KDGanttViewItem* )QListViewItem::itemBelow();
01501   if ( !includeDisabled ) {
01502     return  retItem;
01503   }
01504   if ( retItem ) {
01505     if (itemPos() + height() == retItem->itemPos() ) {
01506       return retItem;
01507     }
01508   }
01509   KDGanttViewItem*  Item2 = (KDGanttViewItem* )QListViewItem::listView()->itemAt(QPoint (2, QListViewItem::itemPos() + QListViewItem::height() +2) );
01510   if ( Item2 != 0 )
01511     if (!Item2->enabled() )
01512       return Item2;
01513   return retItem;
01514 }
01515 
01516 
01520 void KDGanttViewItem::updateCanvasItems()
01521 {
01522     if (blockUpdating) return;
01523     QPen p,pBack;
01524     QBrush b;
01525     b.setStyle(Qt::SolidPattern);
01526     if ( type() == Task ) {
01527         if ( enabled() ) {
01528             if ( mTextCanvas )
01529                 mTextCanvas->setColor(myTextColor);
01530             if (isHighlighted) {
01531                 b.setStyle(Qt::SolidPattern);
01532                 b.setColor(myStartColorHL);
01533                 startShape->setBrush(b);
01534             } else {
01535                 b.setStyle(Qt::SolidPattern);
01536                 b.setColor(myStartColor);
01537                 startShape->setBrush(b);
01538             }
01539         } else {
01540             QColor discol = QColor(232,232,232);
01541             if ( mTextCanvas )
01542                 mTextCanvas->setColor( QColor(150,150,150) );
01543             b.setStyle(Qt::SolidPattern);
01544             b.setColor(discol);
01545             startShape->setBrush(b);
01546         }
01547     } else {
01548         if ( enabled() ) {
01549             if ( mTextCanvas )
01550                 mTextCanvas->setColor(myTextColor);
01551             if (isHighlighted) {
01552                 b.setStyle(Qt::SolidPattern);
01553                 b.setColor(myStartColorHL);
01554                 startShape->setBrush(b);
01555                 b.setColor(myMiddleColorHL);
01556                 midShape->setBrush(b);
01557                 b.setColor(myEndColorHL);
01558                 endShape->setBrush(b);
01559                 p.setWidth(myItemSize/3 -1);
01560                 p.setColor(myStartColorHL);
01561                 startLine->setPen(p);
01562                 p.setColor(myEndColorHL);
01563                 endLine->setPen(p);
01564             } else {
01565                 b.setStyle(Qt::SolidPattern);
01566                 b.setColor(myStartColor);
01567                 //  qDebug("update color  %s %s", listViewText().toLatin1(),myStartColor.name().toLatin1() );
01568                 startShape->setBrush(b);
01569                 b.setColor(myMiddleColor);
01570                 midShape->setBrush(b);
01571                 b.setColor(myEndColor);
01572                 endShape->setBrush(b);
01573                 p.setWidth(myItemSize/3-1);
01574                 p.setColor(myStartColor);
01575                 startLine->setPen(p);
01576                 p.setColor(myEndColor);
01577                 endLine->setPen(p);
01578             }
01579         } else {
01580             //QColor discol = Qt::lightGray;
01581             QColor discol = QColor(232,232,232);
01582             if ( mTextCanvas )
01583                 mTextCanvas->setColor( QColor(150,150,150) );
01584             b.setStyle(Qt::SolidPattern);
01585             b.setColor(discol);
01586             startShape->setBrush(b);
01587             midShape->setBrush(b);
01588             endShape->setBrush(b);
01589             p.setWidth(myItemSize/3 -1);
01590             p.setColor(discol);
01591             startLine->setPen(p);
01592             endLine->setPen(p);
01593         }
01594     
01595         pBack.setWidth((myItemSize/3-1)+2);
01596         startLineBack->setPen(pBack);
01597         endLineBack->setPen(pBack);
01598     }
01599     if ( mTextCanvas ) {
01600         QFont f = mTextCanvas->font();
01601         f.setPixelSize(myItemSize);
01602         mTextCanvas->setFont(f);
01603     }
01604     updateItemsOnCanvas();
01605 }
01606 
01607 
01608 void KDGanttViewItem::initItem()
01609 {
01610 }
01611 
01612 
01616 void KDGanttViewItem::setOpen( bool open )
01617 {
01618   if ( _callListViewOnSetOpen ) {
01619     // notify the listview about a programatically called setOpen()
01620     if ( listView () )
01621       listView ()->setOpen( this, open );
01622 
01623   } else {
01624 
01625     QListViewItem::setOpen( open );
01626   }
01627 }
01628 
01629 
01630 void KDGanttViewItem::showItem( bool, int )
01631 {
01632 }
01633 
01634 
01635 QPoint KDGanttViewItem::getTaskLinkStartCoord(QPoint p)
01636 {
01637 
01638     if ( mTextCanvas )
01639         mTextCanvas->move(p.x()+myItemSize, itemPos() + height()/2-myItemSize/2);
01640     return QPoint (myGanttView->myTimeHeader->getCoordX(myEndTime) +myItemSize/2,itemPos()+height()/2);
01641 }
01642 
01643 
01644 QPoint KDGanttViewItem::getTaskLinkEndCoord()
01645 {
01646     return QPoint (myGanttView->myTimeHeader->getCoordX(myStartTime)-myItemSize/2 ,itemPos()-myItemSize/2+height()/2-2);
01647 }
01648 
01649 
01650 void KDGanttViewItem::hideSubtree()
01651 {
01652   if (firstChild())
01653     firstChild()->hideSubtree();
01654   if ( nextSibling () )
01655     nextSibling ()->hideSubtree();
01656   showItem(false);
01657 }
01658 
01659 
01660 void KDGanttViewItem::setCallListViewOnSetOpen( bool call )
01661 {
01662   _callListViewOnSetOpen = call;
01663 }
01664 
01665 
01666 QCanvasText* KDGanttViewItem::textcanvas()
01667 {
01668     if ( !mTextCanvas ) {
01669         mTextCanvas = new KDCanvasText(myGanttView->myTimeTable,this,Type_is_KDGanttViewItem);
01670         mTextCanvas->setText("");
01671         mTextCanvas->setZ(10);
01672         mTextCanvas->setFont(myGanttView->font());
01673         // set default textcolor
01674         setTextColor( myGanttView->textColor());
01675     }
01676     return (QCanvasText*) mTextCanvas;
01677 }
01678 
01679 void KDGanttViewItem::updateItemsOnCanvas( bool forceUpdate  )
01680 {
01681     if ( !forceUpdate && myGanttView->myTimeTable->blockUpdating() )
01682         return; 
01683     showItem( isVisibleInGanttView, mCurrentCoord_Y );
01684     KDGanttViewItem * par = parent();
01685     while ( par ) {
01686         par->showItem( par->isVisibleInGanttView, par->mCurrentCoord_Y );
01687         par = par->parent();
01688     }
01689     myGanttView->myTimeTable->computeTaskLinksForItem(