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

kdgantt1

KDGanttViewSummaryItem.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewSummaryItem.cpp 836291 2008-07-22 04:34:42Z pradeepto $
00003    KDGantt - a multi-platform charting engine
00004 */
00005 /****************************************************************************
00006  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDGantt library.
00009  **
00010  ** This file may be used under the terms of the GNU General Public
00011  ** License versions 2.0 or 3.0 as published by the Free Software
00012  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00013  ** included in the packaging of this file.  Alternatively you may (at
00014  ** your option) use any later version of the GNU General Public
00015  ** License if such license has been publicly approved by
00016  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00017  ** 
00018  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00019  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00020  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00021  ** not expressly granted herein.
00022  ** 
00023  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025  **
00026  ** As a special exception, permission is given to link this program
00027  ** with any edition of Qt, and distribute the resulting executable,
00028  ** without including the source code for Qt in the source distribution.
00029  **
00030  **********************************************************************/
00031 
00032 
00033 #include "KDGanttViewSubwidgets.h"
00034 #include "KDGanttViewSummaryItem.h"
00035 
00036 #if QT_VERSION < 0x040000
00037 #include "itemAttributeDialog.h"
00038 #endif
00039 
00056 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttView* view,
00057                                                 const QString& lvtext,
00058                                                 const QString& name ) :
00059     KDGanttViewItem( Summary, view, lvtext, name )
00060 {
00061   initItem();
00062 }
00063 
00064 
00073 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttViewItem* parent,
00074                                                 const QString& lvtext,
00075                                                 const QString& name ) :
00076     KDGanttViewItem( Summary, parent, lvtext, name )
00077 {
00078   initItem();
00079 }
00080 
00081 
00091 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttView* view,
00092                                                 KDGanttViewItem* after,
00093                                                 const QString& lvtext,
00094                                                 const QString& name ) :
00095     KDGanttViewItem( Summary, view, after, lvtext, name )
00096 {
00097   initItem();
00098 }
00099 
00100 
00110 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttViewItem* parent,
00111                                                 KDGanttViewItem* after,
00112                                                 const QString& lvtext,
00113                                                 const QString& name ) :
00114     KDGanttViewItem( Summary, parent, after, lvtext, name )
00115 {
00116 
00117   initItem();
00118 
00119 }
00120 
00121 
00125 KDGanttViewSummaryItem::~KDGanttViewSummaryItem()
00126 {
00127     if ( myActualEndTime )
00128         delete myActualEndTime;
00129     if ( myMiddleTime )
00130         delete myMiddleTime;
00131 }
00132 
00133 
00142 bool KDGanttViewSummaryItem::moveConnector( KDGanttViewItem::Connector c, QPoint p )
00143 {
00144 
00145     //qDebug("DIFF %d ",mCurrentConnectorDiffX );
00146     switch( c ) {
00147     case Start:
00148         setStartTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00149         return true;
00150         break;
00151     case End:
00152         setEndTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00153         return true;
00154         break;
00155     case Middle:
00156         setMiddleTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00157         return true;
00158         break;
00159     case ActualEnd:
00160         setActualEndTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00161         return true;
00162         break;
00163     case Move:
00164         {
00165             int secsEnd = myStartTime.secsTo( myEndTime );
00166             int secsMid = -1;
00167             if ( myMiddleTime )
00168                 secsMid = myStartTime.secsTo( *myMiddleTime );
00169             myStartTime = myGanttView->myTimeHeader->getDateTimeForIndex( p.x() - mCurrentConnectorDiffX );
00170             if ( secsMid >= 0 )
00171                 *myMiddleTime = myStartTime.addSecs( secsMid );
00172             setEndTime( myStartTime.addSecs( secsEnd ) );
00173             return true;
00174         }
00175         break;
00176     case TaskLinkStart:
00177     case TaskLinkEnd:
00178         // handled externally
00179         break;
00180     default:
00181         qDebug( "Unsupported connector type in KDGanttViewTaskItem::moveConnector: %d", c );
00182     }
00183 
00184     return false;
00185 }
00186 
00187 
00188 
00197 KDGanttViewItem::Connector  KDGanttViewSummaryItem::getConnector( QPoint p )
00198 {
00199 
00200     if (! enabled() || displaySubitemsAsGroup() )
00201         return KDGanttViewItem::NoConnector;
00202 
00203     mCurrentConnectorCoordX =  p.x();
00204     mCurrentConnectorDiffX =  int( p.x() - startShape->x() );
00205 
00206     // Summarytasks support: Start, TaskLinkStart, Middle, Move, TaskLinkEnd, End.
00207     if ( startShape->boundingRect().contains( p ) ) {
00208         int margin = startShape->boundingRect().width() / 2;
00209         if ( mCurrentConnectorCoordX < startShape->boundingRect().left() + margin ) {
00210             if ( myGanttView->isConnectorEnabled(KDGanttViewItem::Start) ) {
00211                 return KDGanttViewItem::Start;
00212             }
00213         }
00214         if ( myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkStart) ) {
00215             return KDGanttViewItem::TaskLinkStart;
00216         }
00217         return KDGanttViewItem::NoConnector;
00218     }
00219     if ( endShape->boundingRect().contains( p ) ) {
00220         int margin = endShape->boundingRect().width() / 2;
00221         if ( mCurrentConnectorCoordX > endShape->boundingRect().left() + margin ) {
00222             if ( myGanttView->isConnectorEnabled(KDGanttViewItem::End) ) {
00223                 return KDGanttViewItem::End;
00224             }
00225         }
00226         if ( myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd) ) {
00227             return KDGanttViewItem::TaskLinkEnd;
00228         }
00229         return KDGanttViewItem::NoConnector;
00230     }
00231     if ( myMiddleTime ) {
00232         if ( midShape->boundingRect().contains( p ) &&  myGanttView->isConnectorEnabled(KDGanttViewItem::Middle) ) {
00233                 return KDGanttViewItem::Middle;
00234         }
00235     }
00236     if ( actualEnd && actualEnd->isVisible () ) {
00237         if ( actualEnd->boundingRect().contains( p ) && myGanttView->isConnectorEnabled(KDGanttViewItem::ActualEnd) )
00238             return KDGanttViewItem::ActualEnd;
00239     }
00240     QRect boundingRect = QRect(startShape->boundingRect().topLeft (), 
00241                                endShape->boundingRect().bottomRight() );
00242     if ( boundingRect.contains( p ) && myGanttView->isConnectorEnabled(KDGanttViewItem::Move) )
00243         return KDGanttViewItem::Move;
00244    
00245     return KDGanttViewItem::NoConnector;
00246 }
00247 
00248 KDGanttViewItem::Connector KDGanttViewSummaryItem::getConnector( QPoint p, bool linkMode )
00249 {
00250     if ( !linkMode ) {
00251         return getConnector( p );
00252     }
00253     QRect boundingRect = QRect(startShape->boundingRect().topLeft (), 
00254                                endShape->boundingRect().bottomRight() );
00255     if ( boundingRect.contains( p ) ) {
00256         int margin = (boundingRect.right() - boundingRect.left()) / 2;
00257         if ( boundingRect.left() + margin < p.x() ) {
00258            return KDGanttViewItem::TaskLinkEnd;
00259         }
00260     }
00261     return KDGanttViewItem::TaskLinkStart;
00262 }
00263 
00264 
00272 void KDGanttViewSummaryItem::setMiddleTime( const QDateTime& dateTime )
00273 {
00274  if (! dateTime.isValid() ) {
00275     qDebug("KDGanttViewSummaryItem::setMiddleTime():Invalid parameter-no time set");
00276     return;
00277   }
00278   if (!myMiddleTime) myMiddleTime = new QDateTime;
00279   *myMiddleTime = dateTime;
00280   if ( myEndTime < middleTime() )
00281       setEndTime( middleTime() );
00282   if ( myStartTime > middleTime() )
00283       setStartTime( middleTime() );
00284   updateCanvasItems();
00285 }
00286 
00287 
00295 QDateTime KDGanttViewSummaryItem::middleTime() const
00296 {
00297   if(myMiddleTime)
00298     return *myMiddleTime;
00299   return myStartTime;
00300 }
00301 
00302 
00311 void KDGanttViewSummaryItem::setEndTime( const QDateTime& end )
00312 {
00313   if (! end.isValid() ) {
00314     qDebug("KDGanttViewSummaryItem::setEndTime():Invalid parameter-no time set");
00315     return;
00316   }
00317   myEndTime = end;
00318   if ( myEndTime < middleTime() )
00319       setMiddleTime( myEndTime );
00320   else
00321     updateCanvasItems();
00322 }
00323 
00324 
00334 void KDGanttViewSummaryItem::setStartTime( const QDateTime& start )
00335 {
00336   if (! start.isValid() ) {
00337     qDebug("KDGanttViewSummaryItem::setStartTime():Invalid parameter-no time set");
00338     return;
00339   }
00340     myStartTime = start;
00341  if ( myStartTime > middleTime() ) {
00342       setMiddleTime( myStartTime );
00343  }
00344     else
00345       updateCanvasItems();
00346 }
00347 
00348 
00358 void KDGanttViewSummaryItem::setActualEndTime( const QDateTime& end )
00359 {
00360   if (!myActualEndTime) myActualEndTime = new QDateTime;
00361   *myActualEndTime =  end;
00362 
00363   updateCanvasItems();
00364 
00365 }
00366 
00367 
00375 QDateTime KDGanttViewSummaryItem::actualEndTime() const
00376 {
00377   if(myActualEndTime)
00378     return *myActualEndTime;
00379   return myEndTime;
00380 }
00381 
00382 
00383 void KDGanttViewSummaryItem::hideMe()
00384 {
00385     startShape->hide();
00386     midShape->hide();
00387     endShape->hide();
00388     startShapeBack->hide();
00389     midShapeBack->hide();
00390     endShapeBack->hide();
00391     startLine->hide();
00392     endLine->hide();
00393     if ( mTextCanvas )
00394         mTextCanvas->hide();
00395     startLineBack->hide();
00396     endLineBack->hide();
00397     actualEnd->hide();
00398 }
00399 
00400 // shows the item
00401 // if coordY >0, this is taken as the middle y-coordinate
00402 void KDGanttViewSummaryItem::showItem( bool show, int coordY )
00403 {
00404     mCurrentCoord_Y = coordY;
00405   isVisibleInGanttView = show;
00406   invalidateHeight () ;
00407   if (!show) {
00408     hideMe();
00409     return;
00410   }
00411  if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) {
00412     hideMe();
00413     return;
00414   }
00415   float prio = ((float) ( priority() - 100 )) / 100.0;
00416   startShape->setZ( prio + 0.0055 );
00417   midShape->setZ( prio + 0.004 );
00418   endShape->setZ( prio + 0.005 );
00419   startShapeBack->setZ( prio + 0.003 );
00420   midShapeBack->setZ( prio + 0.003 );
00421   endShapeBack->setZ( prio + 0.003 );
00422   startLine->setZ( prio + 0.0015  );
00423   endLine->setZ( prio + 0.001 );
00424   if ( mTextCanvas )
00425       mTextCanvas->setZ( prio + 0.006 );
00426   startLineBack->setZ( prio );
00427   endLineBack->setZ( prio );
00428   actualEnd->setZ( prio  + 0.007 );
00429   if ( displaySubitemsAsGroup() ) {
00430       myStartTime = myChildStartTime();
00431       myEndTime = myChildEndTime();
00432   }
00433   if ( !myStartTime.isValid() || !myEndTime.isValid() ) {
00434       hideMe();
00435       return;
00436   }
00437   int startX, endX, midX = 0,allY;
00438   if ( coordY )
00439     allY = coordY;
00440   else
00441     allY = getCoordY();
00442   startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
00443   checkCoord( &startX );
00444   endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
00445   if (myMiddleTime)
00446     midX = myGanttView->myTimeHeader->getCoordX(*myMiddleTime);
00447   else
00448     midX = endX;
00449   checkCoord( &midX );
00450   //qDebug("START %d   END %d",startX ,midX);
00451   startLine->setPoints(startX,allY,midX,allY);
00452   startLine->show();
00453   startLineBack->setPoints(startX-1,allY,midX+1,allY);
00454   startLineBack->show();
00455   startShape->move(startX,allY);
00456   startShapeBack->move(startX,allY);
00457 
00458   endShape->move(endX,allY);
00459   endShapeBack->move(endX,allY);
00460   if ( mTextCanvas )
00461       mTextCanvas->move(endX+2*myItemSize,allY-myItemSize/2 );
00462   startShape->show();
00463   startShapeBack->show();
00464   endShape->show();
00465   endShapeBack->show();
00466   if ( mTextCanvas )
00467       mTextCanvas->show();
00468   if (myMiddleTime) {
00469       checkCoord( &endX );
00470     endLine->setPoints(midX,allY,endX,allY);
00471     endLine->show();
00472     endLineBack->setPoints(midX,allY,endX+1,allY);
00473     endLineBack->show();
00474     midShape->move(midX,allY);
00475     midShape->show();
00476     midShapeBack->move(midX,allY);
00477     midShapeBack->show();
00478   }
00479   else {
00480     endLine->hide();
00481     endLineBack->hide();
00482     midShape->hide();
00483     midShapeBack->hide();
00484   }
00485   if (myActualEndTime) {
00486     if ( *myActualEndTime == myEndTime ) {
00487       actualEnd->hide();
00488     }
00489     else {
00490       int actendX = myGanttView->myTimeHeader->getCoordX(*myActualEndTime);
00491       actualEnd->setPoints(actendX,allY-5,actendX,allY+5);
00492       actualEnd->show();
00493     }
00494   }
00495   else {
00496     actualEnd->hide();
00497   }
00498   if(myStartTime == myEndTime)
00499     {
00500       endShape->moveBy(myItemSize+4,0);
00501       endShapeBack->moveBy(myItemSize+4,0);
00502       if ( mTextCanvas )
00503           mTextCanvas->moveBy(myItemSize+4,0);
00504       midShape->hide();
00505       midShapeBack->hide();
00506       startLine->hide();
00507       endLine->hide();
00508       startLineBack->hide();
00509       endLineBack->hide();
00510     }
00511   if ( mTextCanvas )
00512       if (mTextCanvas->text().isEmpty())
00513           mTextCanvas->hide();
00514 }
00515 void KDGanttViewSummaryItem::initItem()
00516 {
00517   isVisibleInGanttView = false;
00518   myActualEndTime = 0;
00519   myMiddleTime = 0;
00520   showItem(true);
00521   myGanttView->myTimeTable->updateMyContent();
00522   setDragEnabled( myGanttView->dragEnabled() );
00523   setDropEnabled( myGanttView->dropEnabled() );
00524 }
00525 

kdgantt1

Skip menu "kdgantt1"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal