kgantt

xQGanttBarView.cpp
1//
2// file : xQGanttBarView.C
3// date : 26 oct 2000
4// changed : 28 nov 2000
5// author : jh
6//
7
8
9#include "xQGanttBarView.h"
10#include "KGanttBarConfig.h"
11
12
13
15 TQWidget* parent,
16 const char * name, WFlags f)
17 : TQScrollView(parent,name,f)
18{
19 _config = NULL;
20
21 _toplevelitem = toplevelitem;
22
23 setFrameStyle(TQFrame::Sunken);
24 setLineWidth(1);
25
26 _headerBackBrush = TQBrush(TQColor(250,250,250));
27
28 setMargins( 1, TOPMARGIN , 1, 1 );
29
30 _viewport = new xQGanttBarViewPort(toplevelitem, this );
31
32 addChild(_viewport);
33
34 _viewport->setMode(xQGanttBarViewPort::Select);
35
36 connect(_viewport, TQ_SIGNAL(scroll(int,int)),
37 this, TQ_SLOT(scrollBy(int,int)) );
38
39 connect(_viewport, TQ_SIGNAL(recalculated()),
40 this, TQ_SLOT(drawHeader()) );
41
42 connect(horizontalScrollBar(), TQ_SIGNAL(valueChanged(int)),
43 this, TQ_SLOT(horizontalScrollBarChanged(int)) );
44
45}
46
47
48
51{
52}
53
54
55
56void
57xQGanttBarView::horizontalScrollBarChanged(int /*x*/)
59{
60 printf("xQGanttBarView::horizontalScrollBarChanged()\n");
61 drawHeader();
62}
63
64
65
66void
67xQGanttBarView::drawHeader()
69{
70 static TQPen _dotPen( TQColor(35,35,35), 0, DotLine);
71 static TQPen _normalPen(TQColor(0,0,0));
72 static TQPen _redPen(TQColor(254,0,0));
73 static TQPen _greyPen(TQColor(150,150,150));
74
75 TQPainter p(this);
76 p.setPen( _normalPen );
77
78 p.fillRect(0,0,width(),TOPMARGIN, _headerBackBrush );
79
80 static int top = 1;
81 static int height = 20;
82 static int skip = 1;
83
84 int a,e,tmp;
85 bool drawDays = false;
86 double dayWidth = (double) ((_viewport->screenX(144000) - _viewport->screenX(0))/100.);
87
88 int wx = _viewport->worldX(contentsX());
89
90 TQDate startDate = _toplevelitem->getStart().addSecs( wx * 60 ).date();
91
92 wx = _viewport->worldX(contentsX()+width());
93 TQDate endDate = _toplevelitem->getStart().addSecs( wx * 60 ).date();
94 endDate = endDate.addDays(1);
95
96 int end = (int) startDate.daysTo(endDate);
97 drawDays = (end < 12);
98
99 // draw week, which first day is not visible
100
101 TQDate t = startDate.addDays(-startDate.dayOfWeek()+1);
102
103 tmp = _toplevelitem->getStart().secsTo(TQDateTime(t))/60;
104 a = _viewport->screenX(tmp) - contentsX();
105
106 p.fillRect(a, top, (int) (5. * dayWidth), height, TQBrush(TQColor(240,240,240)));
107 p.drawRect(a, top, (int) (5. * dayWidth), height );
108
109 // draw month, which first day is not visible
110
111 t = startDate.addDays(-startDate.day()+1);
112
113 tmp = _toplevelitem->getStart().secsTo(TQDateTime(t))/60;
114 a = _viewport->screenX(tmp) - contentsX();
115
116 e = t.daysInMonth();
117 p.fillRect(a, top + height + skip, (int) (e*dayWidth), height, TQBrush(TQColor(240,240,240)));
118 p.drawRect(a, top + height + skip, (int) (e*dayWidth), height );
119
120 if(a<0) a = 0;
121 p.drawText(a+5, int( top + height + skip + (0.8*height) ),
122 t.shortMonthName(t.month()) + " " + TQString::number(t.year()) );
123
124
125 // draw snapgrid for first month
126
127 tmp = _toplevelitem->getStart().secsTo(TQDateTime(startDate))/60;
128 a = _viewport->screenX(tmp) - contentsX()+1;
129 double dx = (double)
130 ((_viewport->screenX(_viewport->_snapgrid*1000) - _viewport->screenX(0))/1000.);
131 double limit = ((1+e-startDate.day()) * 1440)/_viewport->_snapgrid;
132
133 for(double k=1.; k<limit; k++) {
134 p.setPen(_greyPen);
135 p.drawLine(a + (int)(k * dx + 0.5), top + skip + 2 * height + 1,
136 a + (int)(k * dx + 0.5), top + skip + 2 * height + 2);
137 }
138
139
140 // draw from start to end
141
142 t = startDate;
143
144 for(int i=0; i<end; i++, t = t.addDays(1) ) {
145
146 tmp = _toplevelitem->getStart().secsTo(TQDateTime(t))/60;
147 a = _viewport->screenX(tmp) - contentsX();
148
149 p.setPen( TQPen(TQColor(black)) );
150
151 if(t.dayOfWeek() == 1) {
152
153 p.fillRect(a, top, (int) (5. * dayWidth), height, TQBrush(TQColor(240,240,240)));
154 p.drawRect(a, top, (int) (5. * dayWidth), height );
155
156 if(!drawDays)
157 p.drawText(a+5, (int) (top + (0.8*height)), TQString::number(t.day()) );
158
159 }
160
161 if(drawDays) {
162
163 if(a<0) a = 0;
164
165 TQString str = t.shortDayName(t.dayOfWeek()) + " " + TQString::number(t.day());
166 TQRect rect = p.boundingRect(a+5, (int)(0.8 * height),
167 (int) dayWidth, height, AlignLeft, str );
168
169 if(t.dayOfWeek() > 5)
170 p.fillRect(rect.x(), rect.y(), rect.width(), -rect.height(), _headerBackBrush );
171 else
172 p.fillRect(rect.x(), rect.y(),
173 rect.width(), -rect.height(), TQBrush(TQColor(240,240,240)));
174
175 p.drawText(a+5, (int)(0.8 * height), str );
176
177 if(t.dayOfWeek()>1 && t.dayOfWeek()<6) {
178 p.setPen(_dotPen);
179 p.drawLine(a, top, a, height);
180 }
181
182 }
183
184 if(t.day()==1) {
185
186 e = t.daysInMonth();
187
188 p.setPen(_normalPen);
189
190 p.fillRect(a, top + height + skip,
191 (int) (e * dayWidth), height, TQBrush(TQColor(240,240,240)));
192 p.drawRect(a, top + height + skip, (int) (e * dayWidth), height );
193
194 p.drawText(a+5,
195 top + (int)(1.8 * height) + skip,
196 t.shortMonthName(t.month()) + " " + TQString::number(t.year()) );
197
198 // draw snapgrid
199
200 double limit = (e * 1440)/_viewport->_snapgrid;
201 for(double k=1.; k<limit; k++) {
202 p.setPen(_greyPen);
203 p.drawLine(a + 1 + (int)(k * dx + 0.5), top + skip + 2 * height + 1,
204 a + 1 + (int)(k * dx + 0.5), top + skip + 2 * height + 2);
205 }
206
207
208 }
209
210 }
211
212}
213
214
215
216void
217xQGanttBarView::paintEvent(TQPaintEvent * /*e*/)
218{
219 drawHeader();
220}
221
222
223
224KGanttBarConfig*
226{
227 if(_config)
228 return _config;
229 else {
230 _config = new KGanttBarConfig(this);
231 return _config;
232 }
233
234}
235
236
237
238void
239xQGanttBarView::showConfig()
240{
241 getConfig()->show();
242}
243
244
245
246void
247xQGanttBarView::hideConfig()
248{
249 if(_config)
250 _config->hide();
251}
252#include "xQGanttBarView.moc"
KGanttItem.
Definition: KGanttItem.h:56
TQDateTime getStart()
Get date of starting.
Definition: KGanttItem.cpp:208
GanttBarViewPort Widget.
KGanttBarConfig * getConfig()
Get config widget.
xQGanttBarView(KGanttItem *toplevelitem, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructor.
~xQGanttBarView()
Destructor.