kdgantt

KDGanttViewTaskItem.cpp

00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewTaskItem.cpp 369055 2004-12-07 13:56:58Z danders $
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 distributed and/or modified under the terms of the
00012  ** GNU General Public License version 2 as published by the Free Software
00013  ** Foundation and appearing in the file LICENSE.GPL included in the
00014  ** packaging of this file.
00015  **
00016  ** Licensees holding valid commercial KDGantt licenses may use this file in
00017  ** accordance with the KDGantt Commercial License Agreement provided with
00018  ** the Software.
00019  **
00020  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022  **
00023  ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
00024  **   information about KDGantt Commercial License Agreements.
00025  **
00026  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00027  ** licensing are not clear to you.
00028  **
00029  ** As a special exception, permission is given to link this program
00030  ** with any edition of Qt, and distribute the resulting executable,
00031  ** without including the source code for Qt in the source distribution.
00032  **
00033  **********************************************************************/
00034 
00035 
00036 #include "KDGanttViewTaskItem.h"
00037 #include "KDGanttViewSubwidgets.h"
00038 
00039 #include "itemAttributeDialog.h"
00040 
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 
00152 void KDGanttViewTaskItem::setEndTime( const QDateTime& end )
00153 {
00154   myEndTime = end;
00155   if ( myEndTime < startTime() )
00156       setStartTime( myEndTime );
00157   else
00158     updateCanvasItems();
00159 }
00160 
00161 
00171 void KDGanttViewTaskItem::setStartTime( const QDateTime& start )
00172 {
00173   if (! start.isValid() ) {
00174     qDebug("KDGanttViewTaskItem::setStartTime():Invalid parameter-no time set");
00175     return;
00176   }
00177     myStartTime = start;
00178     if ( myStartTime > endTime() )
00179       setEndTime( myStartTime );
00180     else
00181       updateCanvasItems();
00182 }
00183 
00184 
00189 void KDGanttViewTaskItem::hideMe()
00190 {
00191     startShape->hide();
00192     progressShape->hide();
00193     textCanvas->hide();
00194     floatStartShape->hide();
00195     floatEndShape->hide();
00196 }
00197 
00198 
00199 void KDGanttViewTaskItem::showItem(bool show, int coordY)
00200 {
00201 
00202   //qDebug("KDGanttViewTaskItem::showItem() %d %s ", (int) show, listViewText().latin1());
00203   isVisibleInGanttView = show;
00204   invalidateHeight () ;
00205   if (!show) {
00206     hideMe();
00207     return;
00208   }
00209   bool takedefaultHeight = true ; // pending: make configureable
00210   float prio = ((float) ( priority() - 100 )) / 100.0;
00211   startShape->setZ( prio );
00212   progressShape->setZ(startShape->z()+0.002); // less than textCanvas
00213   progressShape->hide();
00214   floatStartShape->setZ(startShape->z()+0.003); // less than textCanvas
00215   floatStartShape->hide();
00216   floatEndShape->setZ(startShape->z()+0.003); // less than textCanvas
00217   floatEndShape->hide();
00218   textCanvas->setZ( prio + 0.005 );
00219   if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) {
00220     hideMe();
00221     return;
00222   }
00223   if ( displaySubitemsAsGroup()  && ( firstChild() || myGanttView->calendarMode() )  ) {
00224     hideMe();//new
00225     return;//new
00226     myStartTime = myChildStartTime();
00227     myEndTime = myChildEndTime();
00228   }
00229   //setExpandable(false);
00230   KDCanvasRectangle* temp = (KDCanvasRectangle*) startShape;
00231   KDCanvasRectangle* progtemp = (KDCanvasRectangle*) progressShape;
00232   int startX, endX, midX = 0,allY, progX=0;
00233    if ( coordY )
00234     allY = coordY;
00235   else
00236     allY = getCoordY();
00237   startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
00238   endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
00239   midX = endX;
00240   if (myProgress > 0) {
00241     progX = (endX - startX) * myProgress / 100;
00242   }
00243   int hei = height();
00244   if ( ! isVisible() ) {
00245     KDGanttViewItem * par = parent();
00246     while ( par != 0 && !par->isVisible() )
00247       par = par->parent();
00248     if ( par )
00249       hei = par->height();
00250   }
00251   if (myGanttView->myListView->itemAt( QPoint(2, allY)))
00252      hei =  myGanttView->myListView->itemAt( QPoint(2, allY))->height();
00253   if ( takedefaultHeight )
00254     hei = 16;
00255   if ( myStartTime == myEndTime ) {
00256     textCanvas->hide();
00257     if ( showNoInformation() ) {
00258       startShape->hide();
00259     } else {
00260       startShape->setZ( 1.01 );
00261       if (myGanttView->displayEmptyTasksAsLine() ) {
00262     hei = myGanttView->myTimeTable->height();
00263     if (hei  < myGanttView->myTimeTable->pendingHeight )
00264       hei = myGanttView->myTimeTable->pendingHeight;
00265     temp->setSize(5,  hei  );
00266     temp->move(startX, 0);
00267     temp->show();
00268       } else {
00269     temp->setSize( 1,  hei -3 );
00270     temp->move(startX, allY-hei/2 +2);
00271     temp->show();
00272       }
00273     }
00274     return;
00275   }
00276   if ( startX +3 >= endX )
00277     temp->setSize( 3,  hei-3 );
00278   else
00279     temp->setSize(endX-startX,  hei-3 );
00280   temp->move(startX, allY-hei/2 +2);
00281   temp->show();
00282   if (progX > 0) {
00283     // FIXME: For now, just use inverted color for progress
00284     QColor c = temp->brush().color();
00285     int h, s, v;
00286     c.getHsv(&h, &s, &v);
00287     h > 359/2 ? h -= 359/2 : h += 359/2;
00288     c.setHsv(h, s, v);
00289     progtemp->setBrush(QBrush(c));
00290     
00291     progtemp->setSize(progX, hei-3);
00292     progtemp->move(temp->x(), temp->y());
00293     progtemp->show();
00294   }
00295   if (myFloatStartTime.isValid()) {
00296     KDCanvasRectangle* floatStartTemp = (KDCanvasRectangle*) floatStartShape;
00297     int floatStartX = myGanttView->myTimeHeader->getCoordX(myFloatStartTime);
00298     // FIXME: Configurable colors
00299     QBrush b(temp->brush().color(), Dense4Pattern);
00300     floatStartTemp->setBrush(b);
00301     floatStartTemp->setPen(QPen(gray));
00302     if (floatStartX < startX) {
00303         floatStartTemp->setSize(startX - floatStartX, temp->size().height()/2);
00304         floatStartTemp->move(floatStartX, temp->y() + temp->size().height()/4);
00305     } else {
00306         floatStartTemp->setSize(floatStartX - startX, temp->size().height()/2);
00307         floatStartTemp->move(startX, temp->y() + temp->size().height()/4);
00308     }
00309     floatStartTemp->show();    
00310   }
00311   if (myFloatEndTime.isValid()) {
00312     KDCanvasRectangle* floatEndTemp = (KDCanvasRectangle*) floatEndShape;
00313     int floatEndX = myGanttView->myTimeHeader->getCoordX(myFloatEndTime);
00314     // FIXME: Configurable colors
00315     QBrush b(temp->brush().color(), Dense4Pattern);
00316     floatEndTemp->setBrush(b);
00317     floatEndTemp->setPen(QPen(gray));
00318     int ex = startX + temp->size().width();
00319     if (floatEndX > ex) {
00320         floatEndTemp->setSize(floatEndX - ex, temp->size().height()/2);
00321         floatEndTemp->move(ex, temp->y() + temp->size().height()/4);
00322     } else {
00323         floatEndTemp->setSize(ex - floatEndX, temp->size().height()/2);
00324         floatEndTemp->move(floatEndX, temp->y() + temp->size().height()/4);
00325     }
00326     floatEndTemp->show();    
00327   }
00328   
00329   int wid = endX-startX - 4;
00330   if ( !displaySubitemsAsGroup() && !myGanttView->calendarMode()) {
00331     moveTextCanvas(endX,allY);
00332     textCanvas->show();
00333   } else {
00334     if ( textCanvasText.isEmpty()  || wid < 5)
00335       textCanvas->hide();
00336     else {
00337       textCanvas->move(startX+3, allY-textCanvas->boundingRect().height()/2);
00338       QString temp = textCanvasText;
00339       textCanvas->setText(temp);
00340       int len =  temp.length();
00341       while ( textCanvas->boundingRect().width() > wid ) {
00342     temp.truncate(--len);
00343     textCanvas->setText(temp);
00344       }
00345       if ( temp.isEmpty())
00346     textCanvas->hide();
00347       else {
00348     textCanvas->show();
00349       }
00350     }
00351   }
00352 }
00353 
00354 
00355 void KDGanttViewTaskItem::initItem()
00356 {
00357   isVisibleInGanttView = false;
00358 
00359   if ( myGanttView->calendarMode() && parent() ) {
00360     setVisible( false );
00361     parent()->setVisible( true );
00362   } else
00363     showItem(true);
00364   //qDebug("initItem  %s %s", listViewText().latin1(),startShape->brush().color().name().latin1() );
00365   myGanttView->myTimeTable->updateMyContent();
00366   setDragEnabled( myGanttView->dragEnabled() );
00367   setDropEnabled( myGanttView->dropEnabled() );
00368 }
00369 
KDE Home | KDE Accessibility Home | Description of Access Keys