9 #include "xQGanttBarView.h"
10 #include "KGanttBarConfig.h"
16 const char * name, WFlags f)
17 : TQScrollView(parent,name,f)
21 _toplevelitem = toplevelitem;
23 setFrameStyle(TQFrame::Sunken);
26 _headerBackBrush = TQBrush(TQColor(250,250,250));
28 setMargins( 1, TOPMARGIN , 1, 1 );
34 _viewport->setMode(xQGanttBarViewPort::Select);
36 connect(_viewport, TQ_SIGNAL(scroll(
int,
int)),
37 this, TQ_SLOT(scrollBy(
int,
int)) );
39 connect(_viewport, TQ_SIGNAL(recalculated()),
40 this, TQ_SLOT(drawHeader()) );
42 connect(horizontalScrollBar(), TQ_SIGNAL(valueChanged(
int)),
43 this, TQ_SLOT(horizontalScrollBarChanged(
int)) );
57 xQGanttBarView::horizontalScrollBarChanged(
int )
60 printf(
"xQGanttBarView::horizontalScrollBarChanged()\n");
67 xQGanttBarView::drawHeader()
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));
76 p.setPen( _normalPen );
78 p.fillRect(0,0,width(),TOPMARGIN, _headerBackBrush );
81 static int height = 20;
85 bool drawDays =
false;
86 double dayWidth = (double) ((_viewport->screenX(144000) - _viewport->screenX(0))/100.);
88 int wx = _viewport->worldX(contentsX());
90 TQDate startDate = _toplevelitem->
getStart().addSecs( wx * 60 ).date();
92 wx = _viewport->worldX(contentsX()+width());
93 TQDate endDate = _toplevelitem->
getStart().addSecs( wx * 60 ).date();
94 endDate = endDate.addDays(1);
96 int end = (int) startDate.daysTo(endDate);
97 drawDays = (end < 12);
101 TQDate t = startDate.addDays(-startDate.dayOfWeek()+1);
103 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(t))/60;
104 a = _viewport->screenX(tmp) - contentsX();
106 p.fillRect(a, top, (
int) (5. * dayWidth), height, TQBrush(TQColor(240,240,240)));
107 p.drawRect(a, top, (
int) (5. * dayWidth), height );
111 t = startDate.addDays(-startDate.day()+1);
113 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(t))/60;
114 a = _viewport->screenX(tmp) - contentsX();
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 );
121 p.drawText(a+5,
int( top + height + skip + (0.8*height) ),
122 t.shortMonthName(t.month()) +
" " + TQString::number(t.year()) );
127 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(startDate))/60;
128 a = _viewport->screenX(tmp) - contentsX()+1;
130 ((_viewport->screenX(_viewport->_snapgrid*1000) - _viewport->screenX(0))/1000.);
131 double limit = ((1+e-startDate.day()) * 1440)/_viewport->_snapgrid;
133 for(
double k=1.; k<limit; k++) {
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);
144 for(
int i=0; i<end; i++, t = t.addDays(1) ) {
146 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(t))/60;
147 a = _viewport->screenX(tmp) - contentsX();
149 p.setPen( TQPen(TQColor(black)) );
151 if(t.dayOfWeek() == 1) {
153 p.fillRect(a, top, (
int) (5. * dayWidth), height, TQBrush(TQColor(240,240,240)));
154 p.drawRect(a, top, (
int) (5. * dayWidth), height );
157 p.drawText(a+5, (
int) (top + (0.8*height)), TQString::number(t.day()) );
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 );
169 if(t.dayOfWeek() > 5)
170 p.fillRect(rect.x(), rect.y(), rect.width(), -rect.height(), _headerBackBrush );
172 p.fillRect(rect.x(), rect.y(),
173 rect.width(), -rect.height(), TQBrush(TQColor(240,240,240)));
175 p.drawText(a+5, (
int)(0.8 * height), str );
177 if(t.dayOfWeek()>1 && t.dayOfWeek()<6) {
179 p.drawLine(a, top, a, height);
188 p.setPen(_normalPen);
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 );
195 top + (
int)(1.8 * height) + skip,
196 t.shortMonthName(t.month()) +
" " + TQString::number(t.year()) );
200 double limit = (e * 1440)/_viewport->_snapgrid;
201 for(
double k=1.; k<limit; k++) {
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);
217 xQGanttBarView::paintEvent(TQPaintEvent * )
230 _config =
new KGanttBarConfig(
this);
239 xQGanttBarView::showConfig()
247 xQGanttBarView::hideConfig()
252 #include "xQGanttBarView.moc"
TQDateTime getStart()
Get date of starting.
KGanttBarConfig * getConfig()
Get config widget.
xQGanttBarView(KGanttItem *toplevelitem, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructor.
~xQGanttBarView()
Destructor.