kdgantt

KDGanttViewTaskItem.cpp
1/*
2 $Id$
3 KDGantt - a multi-platform charting engine
4*/
5
6/****************************************************************************
7 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
8 **
9 ** This file is part of the KDGantt library.
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.GPL included in the
14 ** packaging of this file.
15 **
16 ** Licensees holding valid commercial KDGantt licenses may use this file in
17 ** accordance with the KDGantt Commercial License Agreement provided with
18 ** the Software.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
24 ** information about KDGantt Commercial License Agreements.
25 **
26 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
27 ** licensing are not clear to you.
28 **
29 ** As a special exception, permission is given to link this program
30 ** with any edition of TQt, and distribute the resulting executable,
31 ** without including the source code for TQt in the source distribution.
32 **
33 **********************************************************************/
34
35
36#include "KDGanttViewTaskItem.h"
37#include "KDGanttViewSubwidgets.h"
38
39#include "itemAttributeDialog.h"
40
70 const TQString& lvtext,
71 const TQString& name ) :
72 KDGanttViewItem( Task, view, lvtext, name )
73{
74
75 initItem();
76}
77
78
88 const TQString& lvtext,
89 const TQString& name ) :
90 KDGanttViewItem( Task, parent, lvtext, name )
91{
92 initItem();
93}
94
95
106 KDGanttViewItem* after,
107 const TQString& lvtext,
108 const TQString& name ) :
109 KDGanttViewItem( Task, view, after, lvtext, name )
110{
111 initItem();
112}
113
114
125 KDGanttViewItem* after,
126 const TQString& lvtext,
127 const TQString& name ) :
128 KDGanttViewItem( Task, parent, after, lvtext, name )
129{
130 initItem();
131}
132
133
138{
139
140}
141
142
152void KDGanttViewTaskItem::setEndTime( const TQDateTime& end )
153{
154 myEndTime = end;
155 if ( myEndTime < startTime() )
157 else
159}
160
161
171void KDGanttViewTaskItem::setStartTime( const TQDateTime& start )
172{
173 if (! start.isValid() ) {
174 tqDebug("KDGanttViewTaskItem::setStartTime():Invalid parameter-no time set");
175 return;
176 }
177 myStartTime = start;
178 if ( myStartTime > endTime() )
180 else
182}
183
184
189void KDGanttViewTaskItem::hideMe()
190{
191 startShape->hide();
192 progressShape->hide();
193 textCanvas->hide();
194 floatStartShape->hide();
195 floatEndShape->hide();
196}
197
198
199void KDGanttViewTaskItem::showItem(bool show, int coordY)
200{
201
202 //tqDebug("KDGanttViewTaskItem::showItem() %d %s ", (int) show, listViewText().latin1());
204 invalidateHeight () ;
205 if (!show) {
206 hideMe();
207 return;
208 }
209 bool takedefaultHeight = true ; // pending: make configureable
210 float prio = ((float) ( priority() - 100 )) / 100.0;
211 startShape->setZ( prio );
212 progressShape->setZ(startShape->z()+0.002); // less than textCanvas
213 progressShape->hide();
214 floatStartShape->setZ(startShape->z()+0.003); // less than textCanvas
215 floatStartShape->hide();
216 floatEndShape->setZ(startShape->z()+0.003); // less than textCanvas
217 floatEndShape->hide();
218 textCanvas->setZ( prio + 0.005 );
219 if ( displaySubitemsAsGroup() && !parent() && !isOpen() ) {
220 hideMe();
221 return;
222 }
224 hideMe();//new
225 return;//new
228 }
229 //setExpandable(false);
230 KDCanvasRectangle* temp = (KDCanvasRectangle*) startShape;
231 KDCanvasRectangle* progtemp = (KDCanvasRectangle*) progressShape;
232 int startX, endX, midX = 0,allY, progX=0;
233 if ( coordY )
234 allY = coordY;
235 else
236 allY = getCoordY();
237 startX = myGanttView->myTimeHeader->getCoordX(myStartTime);
238 endX = myGanttView->myTimeHeader->getCoordX(myEndTime);
239 midX = endX;
240 if (myProgress > 0) {
241 progX = (endX - startX) * myProgress / 100;
242 }
243 int hei = height();
244 if ( ! isVisible() ) {
245 KDGanttViewItem * par = parent();
246 while ( par != 0 && !par->isVisible() )
247 par = par->parent();
248 if ( par )
249 hei = par->height();
250 }
251 if (myGanttView->myListView->itemAt( TQPoint(2, allY)))
252 hei = myGanttView->myListView->itemAt( TQPoint(2, allY))->height();
253 if ( takedefaultHeight )
254 hei = 16;
255 if ( myStartTime == myEndTime ) {
256 textCanvas->hide();
257 if ( showNoInformation() ) {
258 startShape->hide();
259 } else {
260 startShape->setZ( 1.01 );
262 hei = myGanttView->myTimeTable->height();
263 if (hei < myGanttView->myTimeTable->pendingHeight )
264 hei = myGanttView->myTimeTable->pendingHeight;
265 temp->setSize(5, hei );
266 temp->move(startX, 0);
267 temp->show();
268 } else {
269 temp->setSize( 1, hei -3 );
270 temp->move(startX, allY-hei/2 +2);
271 temp->show();
272 }
273 }
274 return;
275 }
276 if ( startX +3 >= endX )
277 temp->setSize( 3, hei-3 );
278 else
279 temp->setSize(endX-startX, hei-3 );
280 temp->move(startX, allY-hei/2 +2);
281 temp->show();
282 if (progX > 0) {
283 // FIXME: For now, just use inverted color for progress
284 TQColor c = temp->brush().color();
285 int h, s, v;
286 c.getHsv(&h, &s, &v);
287 h > 359/2 ? h -= 359/2 : h += 359/2;
288 c.setHsv(h, s, v);
289 progtemp->setBrush(TQBrush(c));
290
291 progtemp->setSize(progX, hei-3);
292 progtemp->move(temp->x(), temp->y());
293 progtemp->show();
294 }
295 if (myFloatStartTime.isValid()) {
296 KDCanvasRectangle* floatStartTemp = (KDCanvasRectangle*) floatStartShape;
297 int floatStartX = myGanttView->myTimeHeader->getCoordX(myFloatStartTime);
298 // FIXME: Configurable colors
299 TQBrush b(temp->brush().color(), Dense4Pattern);
300 floatStartTemp->setBrush(b);
301 floatStartTemp->setPen(TQPen(gray));
302 if (floatStartX < startX) {
303 floatStartTemp->setSize(startX - floatStartX, temp->size().height()/2);
304 floatStartTemp->move(floatStartX, temp->y() + temp->size().height()/4);
305 } else {
306 floatStartTemp->setSize(floatStartX - startX, temp->size().height()/2);
307 floatStartTemp->move(startX, temp->y() + temp->size().height()/4);
308 }
309 floatStartTemp->show();
310 }
311 if (myFloatEndTime.isValid()) {
312 KDCanvasRectangle* floatEndTemp = (KDCanvasRectangle*) floatEndShape;
313 int floatEndX = myGanttView->myTimeHeader->getCoordX(myFloatEndTime);
314 // FIXME: Configurable colors
315 TQBrush b(temp->brush().color(), Dense4Pattern);
316 floatEndTemp->setBrush(b);
317 floatEndTemp->setPen(TQPen(gray));
318 int ex = startX + temp->size().width();
319 if (floatEndX > ex) {
320 floatEndTemp->setSize(floatEndX - ex, temp->size().height()/2);
321 floatEndTemp->move(ex, temp->y() + temp->size().height()/4);
322 } else {
323 floatEndTemp->setSize(ex - floatEndX, temp->size().height()/2);
324 floatEndTemp->move(floatEndX, temp->y() + temp->size().height()/4);
325 }
326 floatEndTemp->show();
327 }
328
329 int wid = endX-startX - 4;
331 moveTextCanvas(endX,allY);
332 textCanvas->show();
333 } else {
334 if ( textCanvasText.isEmpty() || wid < 5)
335 textCanvas->hide();
336 else {
337 textCanvas->move(startX+3, allY-textCanvas->boundingRect().height()/2);
338 TQString temp = textCanvasText;
339 textCanvas->setText(temp);
340 int len = temp.length();
341 while ( textCanvas->boundingRect().width() > wid ) {
342 temp.truncate(--len);
343 textCanvas->setText(temp);
344 }
345 if ( temp.isEmpty())
346 textCanvas->hide();
347 else {
348 textCanvas->show();
349 }
350 }
351 }
352}
353
354
355void KDGanttViewTaskItem::initItem()
356{
357 isVisibleInGanttView = false;
358
359 if ( myGanttView->calendarMode() && parent() ) {
360 setVisible( false );
361 parent()->setVisible( true );
362 } else
363 showItem(true);
364 //tqDebug("initItem %s %s", listViewText().latin1(),startShape->brush().color().name().latin1() );
365 myGanttView->myTimeTable->updateMyContent();
366 setDragEnabled( myGanttView->dragEnabled() );
367 setDropEnabled( myGanttView->dropEnabled() );
368}
369
KDCanvasText * textCanvas
TQString textCanvasText
KDCanvasPolygonItem * startShape
TQDateTime myStartTime
void moveTextCanvas(int x, int y)
KDGanttViewItem * parent() const
TQDateTime myChildStartTime()
TQDateTime endTime() const
KDGanttView * myGanttView
bool displaySubitemsAsGroup() const
KDGanttViewItem * firstChild() const
TQDateTime myEndTime
TQDateTime myChildEndTime()
TQDateTime startTime() const
void setStartTime(const TQDateTime &start)
KDGanttViewTaskItem(KDGanttView *view, const TQString &lvtext=TQString(), const TQString &name=TQString())
void setEndTime(const TQDateTime &end)
bool dragEnabled() const
bool calendarMode() const
bool dropEnabled() const
bool displayEmptyTasksAsLine() const