00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "KDGanttViewSubwidgets.h"
00035
00036 #include "KDGanttViewTaskItem.h"
00037 #include <QApplication>
00038 #if QT_VERSION < 0x040000
00039 #include "itemAttributeDialog.h"
00040 #endif
00041
00069 KDGanttViewTaskItem::KDGanttViewTaskItem( KDGanttView* view,
00070 const QString& lvtext,
00071 const QString& name ) :
00072 KDGanttViewItem( Task, view, lvtext, name )
00073 {
00074
00075 initItem();
00076 }
00077
00078
00087 KDGanttViewTaskItem::KDGanttViewTaskItem( KDGanttViewItem* parent,
00088 const QString& lvtext,
00089 const QString& name ) :
00090 KDGanttViewItem( Task, parent, lvtext, name )
00091 {
00092 initItem();
00093 }
00094
00095
00105 KDGanttViewTaskItem::KDGanttViewTaskItem( KDGanttView* view,
00106 KDGanttViewItem* after,
00107 const QString& lvtext,
00108 const QString& name ) :
00109 KDGanttViewItem( Task, view, after, lvtext, name )
00110 {
00111 initItem();
00112 }
00113
00114
00124 KDGanttViewTaskItem::KDGanttViewTaskItem( KDGanttViewItem* parent,
00125 KDGanttViewItem* after,
00126 const QString& lvtext,
00127 const QString& name ) :
00128 KDGanttViewItem( Task, parent, after, lvtext, name )
00129 {
00130 initItem();
00131 }
00132
00133
00137 KDGanttViewTaskItem::~KDGanttViewTaskItem()
00138 {
00139
00140 }
00141
00142
00151 bool KDGanttViewTaskItem::moveConnector( KDGanttViewItem::Connector c, QPoint p )
00152 {
00153
00154 switch( c ) {
00155 case Start:
00156 setStartTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00157 return true;
00158 break;
00159 case End:
00160 setEndTime( myGanttView->myTimeHeader->getDateTimeForIndex( p.x() ) );
00161 return true;
00162 break;
00163 case Move:
00164 {
00165 int secs = myStartTime.secsTo( myEndTime );
00166 myStartTime = myGanttView->myTimeHeader->getDateTimeForIndex( p.x() - mCurrentConnectorDiffX );
00167 setEndTime( myStartTime.addSecs( secs ) );
00168 return true;
00169 }
00170 break;
00171 case TaskLinkStart:
00172 case TaskLinkEnd:
00173
00174 break;
00175 default:
00176 qDebug( "Unsupported connector type in KDGanttViewTaskItem::moveConnector: %d", c );
00177 }
00178 return false;
00179 }
00180
00181
00182
00191 KDGanttViewItem::Connector KDGanttViewTaskItem::getConnector( QPoint p )
00192 {
00193 if (! enabled() || displaySubitemsAsGroup() )
00194 return KDGanttViewItem::NoConnector;
00195 KDCanvasRectangle* temp = (KDCanvasRectangle*) startShape;
00196 mCurrentConnectorCoordX = p.x();
00197 mCurrentConnectorDiffX = p.x() - (int)temp->x();
00198 if ( p.y() < (int)temp->y() ||
00199 p.y() > (int)temp->y() +(int)temp->height() ||
00200 p.x() < (int)temp->x() ||
00201 p.x() > (int)temp->x() + (int)temp->width() )
00202 return KDGanttViewItem::NoConnector;
00203
00204
00205 int miniwid = 4;
00206 if ( (int)temp->width() < miniwid ) {
00207 if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd)) {
00208 return KDGanttViewItem::TaskLinkEnd;
00209 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkStart)) {
00210 return KDGanttViewItem::TaskLinkStart;
00211 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00212 return KDGanttViewItem::Move;
00213 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::End)) {
00214 return KDGanttViewItem::End;
00215 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Start)) {
00216 return KDGanttViewItem::Start;
00217 } else {
00218 return KDGanttViewItem::NoConnector;
00219 }
00220 }
00221 int margin = 5;
00222
00223 if ( (int)temp->width() < 25 ) {
00224 --margin;
00225 if ( (int)temp->width() < 20 )
00226 --margin;
00227 if ( (int)temp->width() < 15 )
00228 --margin;
00229 if ( (int)temp->width() < 10 )
00230 --margin;
00231 } else if ( (int)temp->width() > 50 ) {
00232 margin = 10;
00233 }
00234
00235 if ( p.x() < (int)temp->x() + margin ) {
00236 if (myGanttView->isConnectorEnabled(KDGanttViewItem::Start)) {
00237 return KDGanttViewItem::Start;
00238 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkStart)) {
00239 return KDGanttViewItem::TaskLinkStart;
00240 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00241 return KDGanttViewItem::Move;
00242 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd)) {
00243 return KDGanttViewItem::TaskLinkEnd;
00244 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::End)) {
00245 return KDGanttViewItem::End;
00246 } else {
00247 return KDGanttViewItem::NoConnector;
00248 }
00249 }
00250 if ( p.x() < (int)temp->x() + margin + margin ) {
00251 if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkStart)) {
00252 return KDGanttViewItem::TaskLinkStart;
00253 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00254 return KDGanttViewItem::Move;
00255 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Start)) {
00256 return KDGanttViewItem::Start;
00257 } else {
00258 return KDGanttViewItem::NoConnector;
00259 }
00260 }
00261 if ( p.x() < (int)temp->x() + (int)temp->width() - margin - margin ) {
00262 if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00263 return KDGanttViewItem::Move;
00264 } else {
00265 return KDGanttViewItem::NoConnector;
00266 }
00267 }
00268 if ( p.x() < (int)temp->x() + (int)temp->width() - margin ) {
00269 if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd)) {
00270 return KDGanttViewItem::TaskLinkEnd;
00271 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00272 return KDGanttViewItem::Move;
00273 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::End)) {
00274 return KDGanttViewItem::End;
00275 } else {
00276 return KDGanttViewItem::NoConnector;
00277 }
00278 }
00279 if ( p.x() >= (int)temp->x() + (int)temp->width() - margin ) {
00280 if (myGanttView->isConnectorEnabled(KDGanttViewItem::End)) {
00281 return KDGanttViewItem::End;
00282 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::ActualEnd)) {
00283 return KDGanttViewItem::ActualEnd;
00284 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd)) {
00285 return KDGanttViewItem::TaskLinkEnd;
00286 } else {
00287 return KDGanttViewItem::NoConnector;
00288 }
00289 }
00290 if (myGanttView->isConnectorEnabled(KDGanttViewItem::Move)) {
00291 return KDGanttViewItem::Move;
00292 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkEnd)) {
00293 return KDGanttViewItem::TaskLinkEnd;
00294 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::TaskLinkStart)) {
00295 return KDGanttViewItem::TaskLinkStart;
00296 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::End)) {
00297 return KDGanttViewItem::End;
00298 } else if (myGanttView->isConnectorEnabled(KDGanttViewItem::Start)) {
00299 return KDGanttViewItem::Start;
00300 }
00301 return KDGanttViewItem::NoConnector;
00302 }
00303
00304 KDGanttViewItem::Connector KDGanttViewTaskItem::getConnector( QPoint p, bool linkMode )
00305 {
00306 if ( !linkMode ) {
00307 return getConnector( p );
00308 }
00309 KDTimeTableWidget *tt = myGanttView->myTimeTable;
00310 int start = tt->getCoordX(myStartTime);
00311 int end = tt->getCoordX(myEndTime);
00312 if ( (end - start)/2 < (p.x() - start) ) {
00313 return KDGanttViewItem::TaskLinkEnd;
00314 }
00315 return KDGanttViewItem::TaskLinkStart;
00316 }
00317
00326 unsigned int KDGanttViewTaskItem::getTimeForTimespan( const QDateTime& start, const QDateTime& end )
00327 {
00328 unsigned int retval = 0;
00329 if ( displaySubitemsAsGroup() )
00330 return retval;
00331 if ( start.isValid () ) {
00332 if ( end.isValid() ) {
00333 if ( myEndTime > start && myStartTime < end ) {
00334 if ( myStartTime < start ) {
00335 if ( myEndTime < end )
00336 retval = start.secsTo( myEndTime );
00337 else
00338 retval = start.secsTo( end );
00339 } else {
00340
00341 if ( myEndTime < end )
00342 retval = myStartTime.secsTo( myEndTime );
00343 else
00344 retval = myStartTime.secsTo( end );
00345 }
00346 }
00347 } else {
00348
00349 if ( myStartTime > start )
00350 retval = myStartTime.secsTo( myEndTime );
00351 else {
00352 if ( myEndTime > start )
00353 retval = start.secsTo( myEndTime );
00354 }
00355 }
00356 } else {
00357
00358 if ( end.isValid() ) {
00359 if ( myEndTime < end )
00360 retval = myStartTime.secsTo( myEndTime );
00361 else {
00362 if ( myStartTime < end )
00363 retval = myStartTime.secsTo( end );
00364 }
00365 } else {
00366
00367 retval = myStartTime.secsTo( myEndTime );
00368 }
00369 }
00370 return retval;
00371 }
00372
00373
00383 void KDGanttViewTaskItem::setEndTime( const QDateTime& end )
00384 {
00385 myEndTime = end;
00386 if ( myEndTime < startTime() )
00387 setStartTime( myEndTime );
00388 else
00389 updateCanvasItems();
00390 }
00391
00392
00402 void KDGanttViewTaskItem::setStartTime( const QDateTime& start )
00403 {
00404 if (! start.isValid() ) {
00405 qDebug("KDGanttViewTaskItem::setStartTime():Invalid parameter-no time set");
00406 return;
00407 }
00408 myStartTime = start;
00409 if ( myStartTime > endTime() )
00410 setEndTime( myStartTime );
00411 else
00412 updateCanvasItems();
00413 }
00414
00415
00420 void KDGanttViewTaskItem::hideMe()
00421 {
00422 startShape->hide();
00423 if ( mTextCanvas )
00424 mTextCanvas->hide();
00425
00426 progressShape->hide();
00427 floatStartShape->hide();
00428 floatEndShape->hide();
00429 }
00430
00431
00432 void KDGanttViewTaskItem::showItem(bool show, int coordY)
00433 {
00434
00435
00436 isVisibleInGanttView = show;
00437 mCurrentCoord_Y = coordY;
00438 invalidateHeight () ;
00439 if (!show) {
00440 hideMe();
00441 return;
00442 }
00443 float prio = ((float) ( priority() - 100 )) / 100.0;
00444 startShape->setZ( prio );
00445 progressShape->setZ(startShape->z()+0.003);
00446 progressShape->hide();
00447 floatStartShape->setZ(startShape->z()-0.003);
00448 floatStartShape->hide();
00449 floatEndShape->setZ(startShape->z()-0.003);
00450 floatEndShape->hide();
00451 if ( mTextCanvas )
00452 mTextCanvas->setZ( prio + 0.005 );
00453 if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) {
00454 hideMe();
00455 return;
00456 }
00457 if ( displaySubitemsAsGroup() && ( firstChild() || myGanttView->calendarMode() ) ) {
00458 hideMe();
00459 return;
00460 myStartTime = myChildStartTime();
00461 myEndTime = myChildEndTime();
00462 }
00463
00464 KDCanvasRectangle* temp = (KDCanvasRectangle*) startShape;
00465 KDCanvasRectangle* progtemp = (KDCanvasRectangle*) progressShape;
00466 int startX, endX, midX = 0,allY, progX=0;
00467 if ( coordY )
00468 allY = coordY;
00469 else
00470 allY = getCoordY();
00471 startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
00472 checkCoord( &startX );
00473 endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
00474 checkCoord( &endX );
00475 midX = endX;
00476 if (myProgress > 0) {
00477 progX = (endX - startX) * myProgress / 100;
00478 }
00479 int hei ;
00480 #if 0
00481 bool takedefaultHeight = true ;
00482
00483 hei = height();
00484 if ( ! isVisible() ) {
00485 KDGanttViewItem * par = parent();
00486 while ( par != 0 && !par->isVisible() )
00487 par = par->parent();
00488 if ( par )
00489 hei = par->height();
00490 }
00491
00492 if ( takedefaultHeight )
00493 #endif
00494 hei = 16;
00495 if ( myStartTime == myEndTime ) {
00496 if ( mTextCanvas )
00497 mTextCanvas->hide();
00498 if ( showNoInformation() ) {
00499 startShape->hide();
00500 } else {
00501 startShape->setZ( 1.01 );
00502 if (myGanttView->displayEmptyTasksAsLine() ) {
00503 hei = myGanttView->myTimeTable->height();
00504 if (hei < myGanttView->myTimeTable->pendingHeight )
00505 hei = myGanttView->myTimeTable->pendingHeight;
00506 temp->setSize(5, hei );
00507 temp->move(startX, 0);
00508 temp->show();
00509 } else {
00510 temp->setSize( 1, hei -3 );
00511 temp->move(startX, allY-hei/2 +2);
00512 temp->show();
00513 }
00514 }
00515 return;
00516 }
00517 if ( startX +3 >= endX )
00518 temp->setSize( 3, hei-3 );
00519 else
00520 temp->setSize(endX-startX, hei-3 );
00521 temp->move(startX, allY-hei/2 +2);
00522 temp->show();
00523 if (progX > 0) {
00524
00525 QColor c = temp->brush().color();
00526 int h, s, v;
00527 c.getHsv(&h, &s, &v);
00528 h > 359/2 ? h -= 359/2 : h += 359/2;
00529 c.setHsv(h, s, v);
00530 progtemp->setBrush(QBrush(c));
00531
00532 progtemp->setSize(progX, hei-3);
00533 progtemp->move(temp->x(), temp->y());
00534 progtemp->show();
00535 }
00536 if (myFloatStartTime.isValid()) {
00537 KDCanvasRectangle* floatStartTemp = (KDCanvasRectangle*) floatStartShape;
00538 int floatStartX = myGanttView->myTimeHeader->getCoordX(myFloatStartTime);
00539
00540 QBrush b(temp->brush().color(), Qt::Dense4Pattern);
00541 floatStartTemp->setBrush(b);
00542 floatStartTemp->setPen(QPen(Qt::gray));
00543 if (floatStartX < startX) {
00544 floatStartTemp->setSize(startX - floatStartX, temp->size().height()/2);
00545 floatStartTemp->move(floatStartX, temp->y() + temp->size().height()/4);
00546 } else {
00547 floatStartTemp->setSize(floatStartX - startX, temp->size().height()/2);
00548 floatStartTemp->move(startX, temp->y() + temp->size().height()/4);
00549 }
00550 floatStartTemp->show();
00551 }
00552 if (myFloatEndTime.isValid()) {
00553 KDCanvasRectangle* floatEndTemp = (KDCanvasRectangle*) floatEndShape;
00554 int floatEndX = myGanttView->myTimeHeader->getCoordX(myFloatEndTime);
00555
00556 QBrush b(temp->brush().color(), Qt::Dense4Pattern);
00557 floatEndTemp->setBrush(b);
00558 floatEndTemp->setPen(QPen(Qt::gray));
00559 int ex = startX + temp->size().width();
00560 if (floatEndX > ex) {
00561 floatEndTemp->setSize(floatEndX - ex, temp->size().height()/2);
00562 floatEndTemp->move(ex, temp->y() + temp->size().height()/4);
00563 } else {
00564 floatEndTemp->setSize(ex - floatEndX, temp->size().height()/2);
00565 floatEndTemp->move(floatEndX, temp->y() + temp->size().height()/4);
00566 }
00567 floatEndTemp->show();
00568 }
00569
00570 int wid = endX-startX - 4;
00571 if ( mTextCanvas ) {
00572 if ( !displaySubitemsAsGroup() && !myGanttView->calendarMode()) {
00573 mTextCanvas->move(endX+2*myItemSize,allY-myItemSize/2 );
00574 mTextCanvas->show();
00575
00576 } else {
00577 if ( textCanvasText.isEmpty() || wid < 5)
00578 mTextCanvas->hide();
00579 else {
00580 mTextCanvas->move(startX+3, allY-mTextCanvas->boundingRect().height()/2);
00581 QString temp = textCanvasText;
00582 mTextCanvas->setText(temp);
00583 int len = temp.length();
00584 while ( mTextCanvas->boundingRect().width() > wid ) {
00585 temp.truncate(--len);
00586 mTextCanvas->setText(temp);
00587 }
00588 if ( temp.isEmpty())
00589 mTextCanvas->hide();
00590 else {
00591 mTextCanvas->show();
00592 }
00593 }
00594 }
00595 }
00596 }
00597
00598
00599 void KDGanttViewTaskItem::initItem()
00600 {
00601 isVisibleInGanttView = false;
00602
00603 if ( myGanttView->calendarMode() && parent() ) {
00604 setVisible( false );
00605 parent()->setVisible( true );
00606 } else
00607 showItem(true);
00608
00609 myGanttView->myTimeTable->updateMyContent();
00610 setDragEnabled( myGanttView->dragEnabled() );
00611 setDropEnabled( myGanttView->dropEnabled() );
00612 }
00613