9 #include "KGanttItem.h"
12 TQBrush KGanttItem::_selectBrush(TQColor(255,0,0));
16 const TQDateTime& start,
const TQDateTime& end)
20 init(parentItem,text, start,end);
26 const TQDateTime& start,
long durationMin)
30 init(parentItem, text, start, start.addSecs( durationMin * 60));
36 KGanttItem::init(
KGanttItem* parentItem,
const TQString& text,
37 const TQDateTime& start,
const TQDateTime& end)
40 _style = DrawAll - DrawHandle;
47 _brush = TQBrush(TQColor(140,140,255));
48 _pen = TQPen(TQColor(100,100,100));
49 _textPen = TQPen(TQColor(black));
55 _start = start; _minDateTime = start;
56 _end = end; _maxDateTime = end;
58 _parentItem = parentItem;
61 _parentItem->registerItem(
this);
71 printf(
"-> delete %s \n",
getText().latin1() );
75 _parentItem->unregisterItem(
this);
77 _subitems.setAutoDelete(
true);
83 printf(
"<- delete %s \n",
getText().latin1() );
93 if(_subitems.containsRef(from) > 0 && _subitems.containsRef(to) >0) {
95 _relations.append(rel);
112 if( _relations.removeRef(rel) )
131 _subitems.append(item);
136 bool minChanged =
false;
137 bool maxChanged =
false;
141 if(_subitems.count() == 1) {
144 _maxDateTime = item->
getEnd();
152 if(item->
getEnd() > _maxDateTime) {
153 _maxDateTime = item->
getEnd();
157 if(_minDateTime > item->
getStart()) {
166 Change change = adjustStartEnd();
168 if(_mode == Rubberband) {
169 if(minChanged && !(change & StartChanged))
170 change = (
Change) (change + StartChanged);
171 if(maxChanged && !(change & EndChanged))
172 change = (
Change) (change + EndChanged);
180 if(change != NoChange)
190 _subitems.removeRef(item);
193 Change change = adjustMinMax();
200 if(change != NoChange)
210 if(_mode == Rubberband && _subitems.count()>0)
223 if(_mode == Rubberband && _subitems.count()>0)
234 if(!_editable)
return;
237 if(_subitems.count()==0) {
239 if(_start != start) {
241 _minDateTime = _start;
242 emit
changed(
this,StartChanged);
251 if(_mode != Rubberband) {
253 if(start < _minDateTime)
256 _start = _minDateTime;
258 emit
changed(
this,StartChanged);
271 if(!_editable)
return;
274 if(_subitems.count()==0) {
288 if(_mode != Rubberband) {
290 if(end > _maxDateTime)
307 KGanttItem::adjustStartEnd()
312 Change c = adjustMinMax();
314 if(_start > _minDateTime) {
315 _start = _minDateTime;
316 if(!(c & StartChanged))
317 c = (
Change) (c + StartChanged);
320 if(_end < _maxDateTime) {
322 if(!(c & EndChanged))
323 c = (
Change) (c + EndChanged);
333 KGanttItem::adjustMinMax()
342 TQDateTime min = _minDateTime;
343 TQDateTime max = _maxDateTime;
346 if(_subitems.count()==0) {
348 _minDateTime = _start;
351 if(min != _minDateTime) c = MinChanged;
352 if(max != _maxDateTime) c = (
Change) (c + MaxChanged);
362 _maxDateTime = item->
getEnd();
364 item = _subitems.next();
366 for(; item != 0; item = _subitems.next() ) {
368 if(_minDateTime > item->
getStart()) {
372 if(item->
getEnd() > _maxDateTime) {
373 _maxDateTime = item->
getEnd();
379 if(min != _minDateTime) c = MinChanged;
380 if(max != _maxDateTime) c = (
Change) (c + MaxChanged);
391 KGanttItem::subItemChanged(
KGanttItem* , Change change)
401 if( (change & StartChanged) ||
402 (change & EndChanged) ) {
404 Change c = adjustStartEnd();
406 if(_mode == Rubberband) {
407 if(c & MinChanged && !(c & StartChanged))
408 c = (
Change) (c + StartChanged);
409 if(c & MaxChanged && !(c & EndChanged))
410 c = (
Change) ( c +EndChanged);
425 if(!_editable)
return;
428 emit
changed(
this,TextChanged);
453 if(!_editable)
return;
469 if(!_editable)
return;
472 emit
changed(
this,ModeChanged);
483 if(!_editable)
return;
491 item = _subitems.next() )
524 if(!_editable)
return;
540 for(
KGanttItem* item = _subitems.first(); item != 0; item = _subitems.next() ) {
568 cout << pre <<
"<Item. text = [" << _text <<
"]>\n";
569 cout << pre <<
"| start : " <<
getStart().toString() <<
" ("
570 <<_start.toString() <<
")" << endl;
571 cout << pre <<
"| end : " <<
getEnd().toString() <<
" ("
572 <<_end.toString() <<
")" << endl;
574 cout << pre <<
"| - editable " << endl;
576 cout << pre <<
"| - not editable " << endl;
577 if(_mode == Rubberband)
578 cout << pre <<
"| mode = 'rubberband'" << endl;
580 cout << pre <<
"| mode = 'normal'" << endl;
582 cout << pre <<
"| min date/time : " << _minDateTime.toString() << endl;
583 cout << pre <<
"| max date/time : " << _maxDateTime.toString() << endl;
585 for(
KGanttItem* item = _subitems.first(); item != 0; item = _subitems.next() )
586 item->
dump(cout, pre +
"| ");
590 rel = _relations.next() )
591 rel->
dump(cout, pre +
"| ");
593 cout << pre <<
"</Item>\n";
604 if(c & StartChanged) ret +=
"StartChanged, ";
605 if(c & EndChanged) ret +=
"EndChanged, ";
609 if(c & TextChanged) ret +=
"TextChanged, ";
610 if(c & ModeChanged) ret +=
"ModeChanged, ";
611 if(c & MinChanged) ret +=
"MinChanged, ";
612 if(c & MaxChanged) ret +=
"MaxChanged, ";
613 if(c &
Opened) ret +=
"Opened, ";
614 if(c &
Closed) ret +=
"Closed, ";
615 if(c &
Selected) ret +=
"Selected, ";
617 if(c &
Unknown) ret +=
"Unknown, ";
621 #include "KGanttItem.moc"
TQDateTime getStart()
Get date of starting.
static TQString ChangeAsString(Change c)
Return a given change as a string.
void setEnd(const TQDateTime &end)
Set time/date of end.
void setBrush(const TQBrush &brush)
Set brush for filling.
void destroyed(KGanttItem *)
Item will be deleted.
void select(bool f)
Select/unselect item.
bool isOpen()
Returns true if item is open (subitems has to be drawn)
KGanttItem(KGanttItem *parentItem, const TQString &text, const TQDateTime &start, const TQDateTime &end)
Constructor.
TQDateTime getEnd()
Get date of ending.
void endTransaction()
End a transaction.
void setText(const TQString &text)
Set text.
TQString getText()
Get text.
int getWidth()
Get width in minutes.
@ HeightChanged
Height for this item has changed.
@ StyleChanged
Style for drawing has changed.
@ Unknown
Changes may occurred but the types are unknown.
@ Selected
Item has been selected.
@ Unselected
Item has been unselected.
@ RelationRemoved
Relation between two subitems has been removed.
@ Closed
Draw item without subitems.
@ RelationAdded
Relation between two subitems has been added.
@ TotalHeightChanged
Total height has changed.
@ Opened
Draw item including subitems.
void changed(KGanttItem *, KGanttItem::Change)
Item has changed.
void dump(TQTextOStream &cout, const TQString &pre)
Dump to cout.
KGanttRelation * addRelation(KGanttItem *from, KGanttItem *to, const TQString &text)
Add relation between two subitems.
void setMode(Mode flag)
Set mode.
void setStyle(int flag, bool includeSubitems=false)
Set drawing style.
void setHeight(int h)
Set height.
void setPen(const TQPen &pen)
Set pen for border.
void setStart(const TQDateTime &start)
Set time/date of start.
void open(bool f)
Open / Close item.
int getTotalHeight()
Get total height.
void dump(TQTextOStream &cout, const TQString &pre)
Dump to cout.