kdgantt

KDGanttViewEventItem.cpp

00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewEventItem.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 "KDGanttViewEventItem.h"
00037 #include "KDGanttViewSubwidgets.h"
00038 #include "itemAttributeDialog.h"
00039 
00055 KDGanttViewEventItem::KDGanttViewEventItem( KDGanttView* view,
00056                                             const QString& lvtext,
00057                                             const QString& name ) :
00058     KDGanttViewItem( Event, view, lvtext, name )
00059 {
00060   initItem();
00061 }
00062 
00063 
00072 KDGanttViewEventItem::KDGanttViewEventItem( KDGanttViewItem* parent,
00073                                             const QString& lvtext,
00074                                             const QString& name ) :
00075     KDGanttViewItem( Event, parent, lvtext, name )
00076 {
00077  initItem();
00078 
00079 }
00080 
00081 
00091 KDGanttViewEventItem::KDGanttViewEventItem( KDGanttView* view,
00092                                             KDGanttViewItem* after,
00093                                             const QString& lvtext,
00094                                             const QString& name ) :
00095     KDGanttViewItem( Event, view, after, lvtext, name )
00096 {
00097 
00098   initItem();
00099 }
00100 
00101 
00111 KDGanttViewEventItem::KDGanttViewEventItem( KDGanttViewItem* parent,
00112                                             KDGanttViewItem* after,
00113                                             const QString& lvtext,
00114                                             const QString& name ) :
00115     KDGanttViewItem( Event, parent, after, lvtext, name )
00116 {
00117 
00118   initItem();
00119 }
00120 
00121 
00125 KDGanttViewEventItem::~KDGanttViewEventItem()
00126 {
00127 
00128 
00129 }
00139 void KDGanttViewEventItem::setStartTime( const QDateTime& start )
00140 {
00141   if (! start.isValid() ) {
00142     qDebug("KDGanttViewEventItem::setStartTime():Invalid parameter-no time set");
00143     return;
00144   }
00145     myStartTime = start;
00146     myEndTime = start;
00147     if ( myStartTime < leadTime() )
00148       setLeadTime( myStartTime );
00149     else {
00150       updateCanvasItems();
00151     }
00152 
00153 }
00154 
00155 
00167 void KDGanttViewEventItem::setLeadTime( const QDateTime& leadTimeStart )
00168 {
00169   if (!myLeadTime) myLeadTime = new QDateTime;
00170   *myLeadTime =  leadTimeStart;
00171   if ( startTime() < leadTime() )
00172       setStartTime( leadTimeStart );
00173   else {
00174     updateCanvasItems();
00175   }
00176 
00177 }
00178 
00179 
00189 QDateTime KDGanttViewEventItem::leadTime() const
00190 {
00191   if(myLeadTime)
00192     return *myLeadTime;
00193   return myStartTime;
00194 }
00195 
00196 
00197 void KDGanttViewEventItem::hideMe()
00198 {
00199     startShape->hide();
00200     startShapeBack->hide();
00201     startLine->hide();
00202     startLineBack->hide();
00203     textCanvas->hide();
00204     floatStartShape->hide();
00205     floatEndShape->hide();
00206 }
00207 
00208 
00209 void KDGanttViewEventItem::showItem(bool show, int coordY)
00210 {
00211   isVisibleInGanttView = show;
00212   invalidateHeight () ;
00213   if (!show) {
00214     hideMe();
00215     return;
00216   }
00217   float prio = ((float) ( priority() - 100 )) / 100.0;
00218   startShape->setZ( prio + 0.0055 );
00219   startShapeBack->setZ( prio + 0.003 );
00220   startLine->setZ( prio + 0.0015  );
00221   floatStartShape->setZ(prio + 0.004);
00222   floatStartShape->hide();
00223   floatEndShape->setZ(prio + 0.004);
00224   floatEndShape->hide();
00225   textCanvas->setZ( prio + 0.006 );
00226   startLineBack->setZ( prio );
00227 
00228   if ( displaySubitemsAsGroup() && firstChild() ) {
00229     myStartTime = myChildStartTime();
00230     myEndTime = myChildEndTime();
00231   }
00232   int startX, endX, allY;
00233   if ( coordY )
00234     allY = coordY;
00235   else
00236     allY = getCoordY();
00237   startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
00238   if (myLeadTime) {
00239     endX = myGanttView->myTimeHeader->getCoordX(*myLeadTime);
00240     startLine->setPoints(startX,allY,endX,allY);
00241     startLine->show();
00242     startLineBack->setPoints(startX+1,allY,endX-1,allY);
00243     startLineBack->show();
00244   }
00245   else {
00246     startLine->hide();
00247     startLineBack->hide();
00248   }
00249   startShape->move(startX,allY);
00250   startShape->show();
00251   startShapeBack->move(startX,allY);
00252   startShapeBack->show();
00253   if (myFloatStartTime.isValid()) {
00254     KDCanvasRectangle* floatStartTemp = (KDCanvasRectangle*) floatStartShape;
00255     int floatStartX = myGanttView->myTimeHeader->getCoordX(myFloatStartTime);
00256     int hei = startShape->boundingRect().height();
00257     // FIXME: Configurable colors
00258     QBrush b(startShape->brush().color(), Dense4Pattern);
00259     floatStartTemp->setBrush(b);
00260     floatStartTemp->setPen(QPen(gray));
00261     if (floatStartX < startX) {
00262         floatStartTemp->setSize(startX - floatStartX, hei/2);
00263         floatStartTemp->move(floatStartX, allY-hei/4);
00264     } else {
00265         floatStartTemp->setSize(floatStartX - startX, hei/2);
00266         floatStartTemp->move(startX, allY-hei/4);
00267     }
00268     floatStartShape->show();    
00269   }
00270   if (myFloatEndTime.isValid()) {
00271     KDCanvasRectangle* floatEndTemp = (KDCanvasRectangle*) floatEndShape;
00272     int floatEndX = myGanttView->myTimeHeader->getCoordX(myFloatEndTime);
00273     int hei = startShape->boundingRect().height();
00274     // FIXME: Configurable colors
00275     QBrush b(startShape->brush().color(), Dense4Pattern);
00276     floatEndTemp->setBrush(b);
00277     floatEndTemp->setPen(QPen(gray));
00278     if (floatEndX > startX) {
00279         floatEndTemp->setSize(floatEndX - startX, hei/2);
00280         floatEndTemp->move(startX, allY-hei/4);
00281     } else {
00282         floatEndTemp->setSize(startX - floatEndX, hei/2);
00283         floatEndTemp->move(floatEndX, allY-hei/4);
00284     }
00285     floatEndShape->show();    
00286    }
00287 
00288   moveTextCanvas(startX,allY);
00289   textCanvas->show();
00290   if (textCanvas->text().isEmpty())
00291     textCanvas->hide();
00292 }
00293 
00294 
00295 void KDGanttViewEventItem::initItem()
00296 {
00297   isVisibleInGanttView = false;
00298   myLeadTime = 0;
00299   showItem(true);
00300   myGanttView->myTimeTable->updateMyContent();
00301   setDragEnabled( myGanttView->dragEnabled() );
00302   setDropEnabled( myGanttView->dropEnabled() );
00303 }
00304 
00305 
00306 
KDE Home | KDE Accessibility Home | Description of Access Keys