kdgantt

KDGanttViewSummaryItem.cpp
1 /*
2  $Id$
3  KDGantt - a multi-platform charting engine
4 */
5 /****************************************************************************
6  ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
7  **
8  ** This file is part of the KDGantt library.
9  **
10  ** This file may be distributed and/or modified under the terms of the
11  ** GNU General Public License version 2 as published by the Free Software
12  ** Foundation and appearing in the file LICENSE.GPL included in the
13  ** packaging of this file.
14  **
15  ** Licensees holding valid commercial KDGantt licenses may use this file in
16  ** accordance with the KDGantt Commercial License Agreement provided with
17  ** the Software.
18  **
19  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21  **
22  ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
23  ** information about KDGantt Commercial License Agreements.
24  **
25  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26  ** licensing are not clear to you.
27  **
28  ** As a special exception, permission is given to link this program
29  ** with any edition of TQt, and distribute the resulting executable,
30  ** without including the source code for TQt in the source distribution.
31  **
32  **********************************************************************/
33 
34 
35 #include "KDGanttViewSummaryItem.h"
36 #include "KDGanttViewSubwidgets.h"
37 
38 #include "itemAttributeDialog.h"
39 
57  const TQString& lvtext,
58  const TQString& name ) :
59  KDGanttViewItem( Summary, view, lvtext, name )
60 {
61  initItem();
62 }
63 
64 
74  const TQString& lvtext,
75  const TQString& name ) :
76  KDGanttViewItem( Summary, parent, lvtext, name )
77 {
78  initItem();
79 }
80 
81 
92  KDGanttViewItem* after,
93  const TQString& lvtext,
94  const TQString& name ) :
95  KDGanttViewItem( Summary, view, after, lvtext, name )
96 {
97  initItem();
98 }
99 
100 
111  KDGanttViewItem* after,
112  const TQString& lvtext,
113  const TQString& name ) :
114  KDGanttViewItem( Summary, parent, after, lvtext, name )
115 {
116 
117  initItem();
118 
119 }
120 
121 
126 {
127 
128 }
129 
130 
138 void KDGanttViewSummaryItem::setMiddleTime( const TQDateTime& dateTime )
139 {
140  if (! dateTime.isValid() ) {
141  tqDebug("KDGanttViewSummaryItem::setMiddleTime():Invalid parameter-no time set");
142  return;
143  }
144  if (!myMiddleTime) myMiddleTime = new TQDateTime;
145  *myMiddleTime = dateTime;
146  if ( myEndTime < middleTime() )
147  setEndTime( middleTime() );
148  if ( myStartTime > middleTime() )
151 }
152 
153 
162 {
163  if(myMiddleTime)
164  return *myMiddleTime;
165  return myStartTime;
166 }
167 
168 
177 void KDGanttViewSummaryItem::setEndTime( const TQDateTime& end )
178 {
179  if (! end.isValid() ) {
180  tqDebug("KDGanttViewSummaryItem::setEndTime():Invalid parameter-no time set");
181  return;
182  }
183  myEndTime = end;
184  if ( myEndTime < middleTime() )
186  else
188 }
189 
190 
200 void KDGanttViewSummaryItem::setStartTime( const TQDateTime& start )
201 {
202  if (! start.isValid() ) {
203  tqDebug("KDGanttViewSummaryItem::setStartTime():Invalid parameter-no time set");
204  return;
205  }
206  myStartTime = start;
207  if ( myStartTime > middleTime() ) {
209  }
210  else
212 }
213 
214 
224 void KDGanttViewSummaryItem::setActualEndTime( const TQDateTime& end )
225 {
226  if (!myActualEndTime) myActualEndTime = new TQDateTime;
227  *myActualEndTime = end;
228 
230 
231 }
232 
233 
242 {
243  if(myActualEndTime)
244  return *myActualEndTime;
245  return myEndTime;
246 }
247 
248 
249 void KDGanttViewSummaryItem::hideMe()
250 {
251  startShape->hide();
252  midShape->hide();
253  endShape->hide();
254  startShapeBack->hide();
255  midShapeBack->hide();
256  endShapeBack->hide();
257  startLine->hide();
258  endLine->hide();
259  textCanvas->hide();
260  startLineBack->hide();
261  endLineBack->hide();
262  actualEnd->hide();
263 }
264 
265 // shows the item
266 // if coordY >0, this is taken as the middle y-coordinate
267 void KDGanttViewSummaryItem::showItem( bool show, int coordY )
268 {
269  isVisibleInGanttView = show;
270  invalidateHeight () ;
271  if (!show) {
272  hideMe();
273  return;
274  }
275  if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) {
276  hideMe();
277  return;
278  }
279  float prio = ((float) ( priority() - 100 )) / 100.0;
280  startShape->setZ( prio + 0.0055 );
281  midShape->setZ( prio + 0.004 );
282  endShape->setZ( prio + 0.005 );
283  startShapeBack->setZ( prio + 0.003 );
284  midShapeBack->setZ( prio + 0.003 );
285  endShapeBack->setZ( prio + 0.003 );
286  startLine->setZ( prio + 0.0015 );
287  endLine->setZ( prio + 0.001 );
288  textCanvas->setZ( prio + 0.006 );
289  startLineBack->setZ( prio );
290  endLineBack->setZ( prio );
291  actualEnd->setZ( prio + 0.007 );
292  if ( displaySubitemsAsGroup() && firstChild() ) {
295  }
296  int startX, endX, midX = 0,allY;
297  if ( coordY )
298  allY = coordY;
299  else
300  allY = getCoordY();
301  startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
302  endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
303  if (myMiddleTime)
304  midX = myGanttView->myTimeHeader->getCoordX(*myMiddleTime);
305  else
306  midX = endX;
307 
308  startLine->setPoints(startX,allY,midX,allY);
309  startLine->show();
310  startLineBack->setPoints(startX-1,allY,midX+1,allY);
311  startLineBack->show();
312  startShape->move(startX,allY);
313  startShapeBack->move(startX,allY);
314 
315  endShape->move(endX,allY);
316  endShapeBack->move(endX,allY);
317  moveTextCanvas(endX,allY);
318  startShape->show();
319  startShapeBack->show();
320  endShape->show();
321  endShapeBack->show();
322  textCanvas->show();
323  if (myMiddleTime) {
324  endLine->setPoints(midX,allY,endX,allY);
325  endLine->show();
326  endLineBack->setPoints(midX,allY,endX+1,allY);
327  endLineBack->show();
328  midShape->move(midX,allY);
329  midShape->show();
330  midShapeBack->move(midX,allY);
331  midShapeBack->show();
332  }
333  else {
334  endLine->hide();
335  endLineBack->hide();
336  midShape->hide();
337  midShapeBack->hide();
338  }
339  if (myActualEndTime) {
340  if ( *myActualEndTime == myEndTime ) {
341  actualEnd->hide();
342  }
343  else {
344  int actendX = myGanttView->myTimeHeader->getCoordX(*myActualEndTime);
345  actualEnd->setPoints(actendX,allY-5,actendX,allY+5);
346  actualEnd->show();
347  }
348  }
349  else {
350  actualEnd->hide();
351  }
352  if(myStartTime == myEndTime)
353  {
354  endShape->moveBy(myItemSize+4,0);
355  endShapeBack->moveBy(myItemSize+4,0);
356  textCanvas->moveBy(myItemSize+4,0);
357  midShape->hide();
358  midShapeBack->hide();
359  startLine->hide();
360  endLine->hide();
361  startLineBack->hide();
362  endLineBack->hide();
363  }
364  if (textCanvas->text().isEmpty())
365  textCanvas->hide();
366 }
367 void KDGanttViewSummaryItem::initItem()
368 {
369  isVisibleInGanttView = false;
370  myActualEndTime = 0;
371  myMiddleTime = 0;
372  showItem(true);
373  myGanttView->myTimeTable->updateMyContent();
374  setDragEnabled( myGanttView->dragEnabled() );
375  setDropEnabled( myGanttView->dropEnabled() );
376 }
377 
KDCanvasPolygonItem * midShapeBack
KDCanvasLine * endLine
KDCanvasText * textCanvas
KDCanvasPolygonItem * startShape
KDCanvasPolygonItem * midShape
TQDateTime myStartTime
void moveTextCanvas(int x, int y)
KDCanvasLine * actualEnd
KDCanvasPolygonItem * endShapeBack
KDCanvasLine * endLineBack
KDCanvasPolygonItem * startShapeBack
KDGanttViewItem * parent() const
TQDateTime myChildStartTime()
KDGanttView * myGanttView
KDCanvasLine * startLineBack
bool displaySubitemsAsGroup() const
KDGanttViewItem * firstChild() const
TQDateTime myEndTime
KDCanvasLine * startLine
TQDateTime myChildEndTime()
KDCanvasPolygonItem * endShape
void setActualEndTime(const TQDateTime &end)
void setMiddleTime(const TQDateTime &)
void setStartTime(const TQDateTime &start)
void setEndTime(const TQDateTime &end)
KDGanttViewSummaryItem(KDGanttView *view, const TQString &lvtext=TQString(), const TQString &name=TQString())
bool dragEnabled() const
bool dropEnabled() const