kgantt

xQGanttListViewPort.cpp
1 //
2 // file : xQGanttListViewPort.C
3 // date : 26 oct 2000
4 // changed : 29 nov 2000
5 // author : jh
6 //
7 
8 #include "xQGanttListViewPort.h"
9 
10 #include <tqcolor.h>
11 
12 
13 int xQGanttListViewPort::_ListViewCounter = 0;
14 
15 
16 xQGanttListViewPort::xQGanttListViewPort(KGanttItem* toplevelitem, TQWidget* parent,
17  const char * name, WFlags f )
18  : TQFrame(parent,name,f)
19 {
20  _toplevelitem = toplevelitem;
21 
22  setBackgroundColor(TQColor(white));
23 
24  _barviewport = NULL;
25 
26  _width = 1000;
27 
28  brush1 = TQBrush(TQColor(200,200,230));
29  brush2 = TQBrush(TQColor(240,240,240));
30 
31 }
32 
33 
34 
37 {
38 }
39 
40 
41 
42 void
43 xQGanttListViewPort::setBarViewPort(xQGanttBarViewPort* v)
44 {
45  _barviewport = v;
46 
47  // printf("setBarViewPort()\n");
48 
49  resize(500, _barviewport->height());
50 
51  printf("setBarViewPort()\n");
52 
53  connect(_barviewport, TQ_SIGNAL(resized()),
54  this, TQ_SLOT(barViewResized()));
55 
56 
57  connect(_barviewport, TQ_SIGNAL(recalculated()),
58  this, TQ_SLOT(update()));
59 
60  /*
61  connect(_barviewport, TQ_SIGNAL(contentsRepainted()),
62  this, TQ_SLOT(barViewRepainted()));
63  */
64 }
65 
66 
67 
68 void
69 xQGanttListViewPort::barViewResized()
71 {
72  printf("xQGanttListViewPort::barViewResized()\n");
73 
74  static int _h = 0;
75 
76  int h = _barviewport->height();
77 
78  if(h!=_h) {
79  _h = h;
80  resize(_width, _h);
81  }
82 
83 }
84 
85 
86 
87 void
88 xQGanttListViewPort::drawContents(TQPainter* p, int x1, int y1, int x2, int y2)
90 {
91  /*printf("\nxQGanttListViewPort::drawContents(%d,%d,%d,%d)\n",
92  x1, y1, x2, y2 );
93  */
94 
95  _ListViewCounter = 0;
96 
97  if(_barviewport) {
98  drawItem(_toplevelitem, p, TQRect(x1, y1, x2-x1, y2-y1), 5 );
99  }
100 
101 }
102 
103 
104 
105 void
106 xQGanttListViewPort::drawItem(KGanttItem* item, TQPainter* p, const TQRect& rect,
107  int offsetX )
109 {
110  static int margin = 2;
111 
112  xTQTaskPosition* tpos = _barviewport->_gItemList[item];
113 
114  if(!tpos) return;
115 
116  if( (tpos->_screenY+5 >= rect.y() &&
117  tpos->_screenY-5 <= rect.y() + rect.height()) ||
118  ((tpos->_screenY + tpos->_screenH)+5 >= rect.y() &&
119  (tpos->_screenY + tpos->_screenH)-5 <= rect.y() + rect.height() ) ) {
120 
121  p->setPen(TQPen(TQColor(black)));
122 
123  int y = tpos->_screenY;
124  int h = tpos->_screenH;
125 
126  if(tpos->_nr % 2 == 0)
127  p->fillRect(0 + margin, y + margin ,
128  _width - 2 * margin, h - 2 * margin, brush1);
129  else
130  p->fillRect(0 + margin, y + margin,
131  _width - 2* margin, h - 2* margin, brush2);
132 
133  TQString str = item->getText() + " [" +
134  item->getStart().toString() + " / " +
135  item->getEnd().toString() + "]";
136 
137  p->drawText(offsetX, tpos->_textPosY, str );
138 
139  }
140 
141 
142  if(item->isOpen() && item->getSubItems().count()>0) {
143 
144  for(KGanttItem* subitem = item->getSubItems().first();
145  subitem != 0;
146  subitem = item->getSubItems().next() ) {
147 
148  drawItem(subitem, p, rect, offsetX + 20);
149 
150  }
151 
152  p->setPen(TQPen(TQColor(blue),2));
153  p->drawLine(offsetX + 3, tpos->_textPosY + 3,
154  offsetX + 3, tpos->_screenY + tpos->_screenHS - 3);
155 
156  }
157 
158 }
159 
160 
161 void
162 xQGanttListViewPort::update(int x1, int y1, int x2, int y2)
164 {
165  TQPainter p(this);
166 
167  /*
168  printf("\nxQGanttListViewPort::update(%d,%d,%d,%d)\n",
169  x1, y1, x2, y2 );
170  */
171  drawContents(&p, x1, y1, x2, y2);
172 
173 }
174 
175 #include "xQGanttListViewPort.moc"
KGanttItem.
Definition: KGanttItem.h:56
TQDateTime getStart()
Get date of starting.
Definition: KGanttItem.cpp:208
TQPtrList< KGanttItem > & getSubItems()
Get list of subitems.
Definition: KGanttItem.h:421
bool isOpen()
Returns true if item is open (subitems has to be drawn)
Definition: KGanttItem.h:178
TQDateTime getEnd()
Get date of ending.
Definition: KGanttItem.cpp:220
TQString getText()
Get text.
Definition: KGanttItem.h:340
GanttBarViewPort Widget.
~xQGanttListViewPort()
Destructor.
xQGanttListViewPort(KGanttItem *toplevelitem, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructor.
void update(int x1, int y1, int x2, int y2)
Update widget.