KDGanttViewSummaryItem.cpp
00001 /* -*- Mode: C++ -*- 00002 $Id$ 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 distributed and/or modified under the terms of the 00011 ** GNU General Public License version 2 as published by the Free Software 00012 ** Foundation and appearing in the file LICENSE.GPL included in the 00013 ** packaging of this file. 00014 ** 00015 ** Licensees holding valid commercial KDGantt licenses may use this file in 00016 ** accordance with the KDGantt Commercial License Agreement provided with 00017 ** the Software. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for 00023 ** information about KDGantt Commercial License Agreements. 00024 ** 00025 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this 00026 ** licensing are not clear to you. 00027 ** 00028 ** As a special exception, permission is given to link this program 00029 ** with any edition of TQt, and distribute the resulting executable, 00030 ** without including the source code for TQt in the source distribution. 00031 ** 00032 **********************************************************************/ 00033 00034 00035 #include "KDGanttViewSummaryItem.h" 00036 #include "KDGanttViewSubwidgets.h" 00037 00038 #include "itemAttributeDialog.h" 00039 00056 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttView* view, 00057 const TQString& lvtext, 00058 const TQString& name ) : 00059 KDGanttViewItem( Summary, view, lvtext, name ) 00060 { 00061 initItem(); 00062 } 00063 00064 00073 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttViewItem* parent, 00074 const TQString& lvtext, 00075 const TQString& name ) : 00076 KDGanttViewItem( Summary, parent, lvtext, name ) 00077 { 00078 initItem(); 00079 } 00080 00081 00091 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttView* view, 00092 KDGanttViewItem* after, 00093 const TQString& lvtext, 00094 const TQString& name ) : 00095 KDGanttViewItem( Summary, view, after, lvtext, name ) 00096 { 00097 initItem(); 00098 } 00099 00100 00110 KDGanttViewSummaryItem::KDGanttViewSummaryItem( KDGanttViewItem* parent, 00111 KDGanttViewItem* after, 00112 const TQString& lvtext, 00113 const TQString& name ) : 00114 KDGanttViewItem( Summary, parent, after, lvtext, name ) 00115 { 00116 00117 initItem(); 00118 00119 } 00120 00121 00125 KDGanttViewSummaryItem::~KDGanttViewSummaryItem() 00126 { 00127 00128 } 00129 00130 00138 void KDGanttViewSummaryItem::setMiddleTime( const TQDateTime& dateTime ) 00139 { 00140 if (! dateTime.isValid() ) { 00141 qDebug("KDGanttViewSummaryItem::setMiddleTime():Invalid parameter-no time set"); 00142 return; 00143 } 00144 if (!myMiddleTime) myMiddleTime = new TQDateTime; 00145 *myMiddleTime = dateTime; 00146 if ( myEndTime < middleTime() ) 00147 setEndTime( middleTime() ); 00148 if ( myStartTime > middleTime() ) 00149 setStartTime( middleTime() ); 00150 updateCanvasItems(); 00151 } 00152 00153 00161 TQDateTime KDGanttViewSummaryItem::middleTime() const 00162 { 00163 if(myMiddleTime) 00164 return *myMiddleTime; 00165 return myStartTime; 00166 } 00167 00168 00177 void KDGanttViewSummaryItem::setEndTime( const TQDateTime& end ) 00178 { 00179 if (! end.isValid() ) { 00180 qDebug("KDGanttViewSummaryItem::setEndTime():Invalid parameter-no time set"); 00181 return; 00182 } 00183 myEndTime = end; 00184 if ( myEndTime < middleTime() ) 00185 setMiddleTime( myEndTime ); 00186 else 00187 updateCanvasItems(); 00188 } 00189 00190 00200 void KDGanttViewSummaryItem::setStartTime( const TQDateTime& start ) 00201 { 00202 if (! start.isValid() ) { 00203 qDebug("KDGanttViewSummaryItem::setStartTime():Invalid parameter-no time set"); 00204 return; 00205 } 00206 myStartTime = start; 00207 if ( myStartTime > middleTime() ) { 00208 setMiddleTime( myStartTime ); 00209 } 00210 else 00211 updateCanvasItems(); 00212 } 00213 00214 00224 void KDGanttViewSummaryItem::setActualEndTime( const TQDateTime& end ) 00225 { 00226 if (!myActualEndTime) myActualEndTime = new TQDateTime; 00227 *myActualEndTime = end; 00228 00229 updateCanvasItems(); 00230 00231 } 00232 00233 00241 TQDateTime KDGanttViewSummaryItem::actualEndTime() const 00242 { 00243 if(myActualEndTime) 00244 return *myActualEndTime; 00245 return myEndTime; 00246 } 00247 00248 00249 void KDGanttViewSummaryItem::hideMe() 00250 { 00251 startShape->hide(); 00252 midShape->hide(); 00253 endShape->hide(); 00254 startShapeBack->hide(); 00255 midShapeBack->hide(); 00256 endShapeBack->hide(); 00257 startLine->hide(); 00258 endLine->hide(); 00259 textCanvas->hide(); 00260 startLineBack->hide(); 00261 endLineBack->hide(); 00262 actualEnd->hide(); 00263 } 00264 00265 // shows the item 00266 // if coordY >0, this is taken as the middle y-coordinate 00267 void KDGanttViewSummaryItem::showItem( bool show, int coordY ) 00268 { 00269 isVisibleInGanttView = show; 00270 invalidateHeight () ; 00271 if (!show) { 00272 hideMe(); 00273 return; 00274 } 00275 if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) { 00276 hideMe(); 00277 return; 00278 } 00279 float prio = ((float) ( priority() - 100 )) / 100.0; 00280 startShape->setZ( prio + 0.0055 ); 00281 midShape->setZ( prio + 0.004 ); 00282 endShape->setZ( prio + 0.005 ); 00283 startShapeBack->setZ( prio + 0.003 ); 00284 midShapeBack->setZ( prio + 0.003 ); 00285 endShapeBack->setZ( prio + 0.003 ); 00286 startLine->setZ( prio + 0.0015 ); 00287 endLine->setZ( prio + 0.001 ); 00288 textCanvas->setZ( prio + 0.006 ); 00289 startLineBack->setZ( prio ); 00290 endLineBack->setZ( prio ); 00291 actualEnd->setZ( prio + 0.007 ); 00292 if ( displaySubitemsAsGroup() && firstChild() ) { 00293 myStartTime = myChildStartTime(); 00294 myEndTime = myChildEndTime(); 00295 } 00296 int startX, endX, midX = 0,allY; 00297 if ( coordY ) 00298 allY = coordY; 00299 else 00300 allY = getCoordY(); 00301 startX = myGanttView->myTimeHeader->getCoordX(myStartTime); 00302 endX = myGanttView->myTimeHeader->getCoordX(myEndTime); 00303 if (myMiddleTime) 00304 midX = myGanttView->myTimeHeader->getCoordX(*myMiddleTime); 00305 else 00306 midX = endX; 00307 00308 startLine->setPoints(startX,allY,midX,allY); 00309 startLine->show(); 00310 startLineBack->setPoints(startX-1,allY,midX+1,allY); 00311 startLineBack->show(); 00312 startShape->move(startX,allY); 00313 startShapeBack->move(startX,allY); 00314 00315 endShape->move(endX,allY); 00316 endShapeBack->move(endX,allY); 00317 moveTextCanvas(endX,allY); 00318 startShape->show(); 00319 startShapeBack->show(); 00320 endShape->show(); 00321 endShapeBack->show(); 00322 textCanvas->show(); 00323 if (myMiddleTime) { 00324 endLine->setPoints(midX,allY,endX,allY); 00325 endLine->show(); 00326 endLineBack->setPoints(midX,allY,endX+1,allY); 00327 endLineBack->show(); 00328 midShape->move(midX,allY); 00329 midShape->show(); 00330 midShapeBack->move(midX,allY); 00331 midShapeBack->show(); 00332 } 00333 else { 00334 endLine->hide(); 00335 endLineBack->hide(); 00336 midShape->hide(); 00337 midShapeBack->hide(); 00338 } 00339 if (myActualEndTime) { 00340 if ( *myActualEndTime == myEndTime ) { 00341 actualEnd->hide(); 00342 } 00343 else { 00344 int actendX = myGanttView->myTimeHeader->getCoordX(*myActualEndTime); 00345 actualEnd->setPoints(actendX,allY-5,actendX,allY+5); 00346 actualEnd->show(); 00347 } 00348 } 00349 else { 00350 actualEnd->hide(); 00351 } 00352 if(myStartTime == myEndTime) 00353 { 00354 endShape->moveBy(myItemSize+4,0); 00355 endShapeBack->moveBy(myItemSize+4,0); 00356 textCanvas->moveBy(myItemSize+4,0); 00357 midShape->hide(); 00358 midShapeBack->hide(); 00359 startLine->hide(); 00360 endLine->hide(); 00361 startLineBack->hide(); 00362 endLineBack->hide(); 00363 } 00364 if (textCanvas->text().isEmpty()) 00365 textCanvas->hide(); 00366 } 00367 void KDGanttViewSummaryItem::initItem() 00368 { 00369 isVisibleInGanttView = false; 00370 myActualEndTime = 0; 00371 myMiddleTime = 0; 00372 showItem(true); 00373 myGanttView->myTimeTable->updateMyContent(); 00374 setDragEnabled( myGanttView->dragEnabled() ); 00375 setDropEnabled( myGanttView->dropEnabled() ); 00376 } 00377