8 #include "xQGanttBarViewPort.h"
9 #include "xQGanttBarView.h"
12 #include <tqtoolbutton.h>
18 #include <tdetoolbarbutton.h>
19 #include <kiconloader.h>
20 #include <tdelocale.h>
26 const char * name, WFlags f)
27 : TQFrame(parent,name,f)
32 closedIcon = TQPixmap(open_xpm);
33 openedIcon = TQPixmap(close_xpm);
38 _gItemList = TQPtrDict<xTQTaskPosition>(449);
39 _gItemList.setAutoDelete(
true);
41 _toplevelitem = toplevelitem;
43 _itemInfo =
new TQLabel(
this);
44 _itemInfo->setBackgroundColor(TQColor(235,235,255));
45 _itemInfo->setFrameStyle( Panel | Sunken );
46 _itemInfo->setMargin( 5 );
47 _itemInfo->setLineWidth(1);
51 _itemTextEdit =
new TQLineEdit(
this);
52 _itemTextEdit->hide();
53 _itemTextEdit->setFrame(
false);
55 connect(_itemTextEdit, TQ_SIGNAL(returnPressed ()),
56 this, TQ_SLOT(textEdited()));
58 _iconloader =
new TDEIconLoader();
62 setBackgroundColor(TQColor(white));
82 _startPoint =
new TQPoint(); _endPoint =
new TQPoint();
84 _cursor_lupe =
new TQCursor( TQPixmap(lupe) );
89 recalc(); adjustSize();
91 setFocusPolicy(TQWidget::StrongFocus);
106 xQGanttBarViewPort::toolbar(TQMainWindow* mw)
108 if(_toolbar || mw == 0)
return _toolbar;
110 _toolbar =
new TDEToolBar(mw,TQMainWindow::TQt::DockTop);
112 mw->addToolBar(_toolbar);
118 _toolbar->insertButton(
"ganttSelect.png", 0,
119 TQ_SIGNAL(clicked()),
120 this, TQ_SLOT(setSelect()),
121 true, i18n(
"Select") );
123 TDEPopupMenu *selectMenu =
new TDEPopupMenu(_toolbar);
129 TQPixmap pix = _iconloader->loadIcon(
"ganttSelecttask.png", TDEIcon::Toolbar , 16 );
130 if(pix.isNull()) printf(
"ganttSelecttask.png not found !\n");
131 selectMenu->insertItem(pix, i18n(
"Select All"),
this, TQ_SLOT(selectAll()) );
137 pix = _iconloader->loadIcon(
"ganttUnselecttask", TDEIcon::Toolbar , 16 );
138 if(pix.isNull()) printf(
"ganttUnselecttask.png not found !\n");
139 selectMenu->insertItem(pix, i18n(
"Unselect All"),
this, TQ_SLOT(unselectAll()) );
142 TDEToolBarButton* b = _toolbar->getButton(0);
143 b->setDelayedPopup(selectMenu);
146 _toolbar->insertButton(
"viewmag.png", 1,
147 TQ_SIGNAL(clicked()),
148 this, TQ_SLOT(setZoom()),
149 true, i18n(
"Zoom") );
151 TDEPopupMenu* zoomMenu =
new TDEPopupMenu(_toolbar);
153 pix = _iconloader->loadIcon(
"viewmag.png", TDEIcon::Toolbar , 16 );
154 if(pix.isNull()) printf(
"viewmag.png not found !\n");
155 zoomMenu->insertItem(pix, i18n(
"Zoom All"),
this, TQ_SLOT(zoomAll()) );
156 zoomMenu->insertSeparator();
158 pix = _iconloader->loadIcon(
"viewmag+.png", TDEIcon::Toolbar , 16 );
159 if(pix.isNull()) printf(
"viewmag+.png not found !\n");
160 zoomMenu->insertItem(pix, i18n(
"Zoom In +"),
this, TQ_SLOT(zoomIn()) );
162 pix = _iconloader->loadIcon(
"viewmag-.png", TDEIcon::Toolbar , 16 );
163 if(pix.isNull()) printf(
"viewmag-.png not found !\n");
164 zoomMenu->insertItem(pix, i18n(
"Zoom Out -"),
this, TQ_SLOT(zoomOut()) );
166 b = _toolbar->getButton(1);
167 b->setDelayedPopup(zoomMenu);
169 _toolbar->insertButton(
"move.png", 2,
170 TQ_SIGNAL(clicked()),
171 this, TQ_SLOT(setMove()),
172 true, i18n(
"Move") );
181 xQGanttBarViewPort::initMenu()
184 _menu =
new TDEPopupMenu(
this);
190 _selectMenu =
new TDEPopupMenu(_menu);
192 TQPixmap pix = _iconloader->loadIcon(
"ganttSelect.png", TDEIcon::Toolbar , 16 );
193 if(pix.isNull()) printf(
"ganttSelect.png not found !\n");
194 _selectMenu->insertItem(pix, i18n(
"Select Mode"),
this, TQ_SLOT(setSelect()));
196 _selectMenu->insertSeparator();
198 pix = _iconloader->loadIcon(
"ganttSelecttask.png", TDEIcon::Toolbar , 16 );
199 if(pix.isNull()) printf(
"ganttSelecttask.png not found !\n");
200 _selectMenu->insertItem(pix, i18n(
"Select All"),
this, TQ_SLOT(selectAll()) );
202 pix = _iconloader->loadIcon(
"ganttUnselecttask", TDEIcon::Toolbar , 16 );
203 if(pix.isNull()) printf(
"ganttUnselecttask.png not found !\n");
204 _selectMenu->insertItem(pix, i18n(
"Unselect All"),
this, TQ_SLOT(unselectAll()) );
206 _menu->insertItem( i18n(
"Select"), _selectMenu);
213 TDEPopupMenu* _zoomMenu =
new TDEPopupMenu(_menu);
215 pix = _iconloader->loadIcon(
"viewmag.png", TDEIcon::Toolbar , 16 );
216 if(pix.isNull()) printf(
"viewmag.png not found !\n");
217 _zoomMenu->insertItem(i18n(
"Zoom Mode"),
this, TQ_SLOT(setZoom()) );
219 _zoomMenu->insertSeparator();
221 _zoomMenu->insertItem(pix, i18n(
"Zoom All"),
this, TQ_SLOT(zoomAll()) );
222 _zoomMenu->insertSeparator();
224 pix = _iconloader->loadIcon(
"viewmag+.png", TDEIcon::Toolbar , 16 );
225 if(pix.isNull()) printf(
"viewmag+.png not found !\n");
226 _zoomMenu->insertItem(pix, i18n(
"Zoom In +"),
this, TQ_SLOT(zoomIn()) );
228 pix = _iconloader->loadIcon(
"viewmag-.png", TDEIcon::Toolbar , 16 );
229 if(pix.isNull()) printf(
"viewmag-.png not found !\n");
230 _zoomMenu->insertItem(pix, i18n(
"Zoom Out -"),
this, TQ_SLOT(zoomOut()) );
232 _menu->insertItem(
"Zoom", _zoomMenu);
234 pix = _iconloader->loadIcon(
"move.png", TDEIcon::Toolbar , 16 );
235 if(pix.isNull()) printf(
"move.png not found !\n");
236 _menu->insertItem(pix, i18n(
"Move Mode"),
this, TQ_SLOT(setMove()) );
238 _menu->insertSeparator();
240 pix = _iconloader->loadIcon(
"configure.png", TDEIcon::Toolbar , 16 );
241 if(pix.isNull()) printf(
"configure.png not found !\n");
242 _menu->insertItem(pix, i18n(
"Configure Gantt..."), _parent, TQ_SLOT(showConfig()));
259 xQGanttBarViewPort::adjustSize()
267 int w = screenX(_toplevelitem->
getWidth() + _marginX);
270 if(sw != w || sh !=h) {
294 drawGrid(&p, x1, y1, x2, y2);
300 drawItem(_toplevelitem, &p, TQRect(x1, y1, x2-x1, y2-y1) );
306 drawHeader(&p, x1, y1, x2, y2);
316 xQGanttBarViewPort::drawGrid(TQPainter* p,
int x1,
int y1,
int x2,
int y2)
321 static int a, w, end, tmp;
322 static TQBrush _sat( TQColor(200,200,200));
323 static TQBrush _sun( TQColor(255,110,110));
324 static TQBrush _hol( TQColor(200,200,250));
325 static TQPen penDay( TQColor(235,235,235), 0, DotLine);
326 static TQPen penMonth( TQColor(0,150,0), 3, DashDotLine);
327 static TQPen penHour( TQColor(0,0,150), 0, DashDotLine);
329 TQDate start( _toplevelitem->
getStart().addSecs(worldX(x1)*60).date() );
331 end = (int) ((x2-x1)/(1440.*_scaleX))+1;
332 w = (int) (1440. * _scaleX + 0.5);
337 TQDate cmp(start.addDays(-1));
339 for(ptrDate = _holidays.first(); ptrDate != 0; ptrDate = _holidays.next() ) {
341 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(*ptrDate))/60;
343 p->fillRect( a, y1, w, y2, _hol );
350 for(
int i=0; i<=end; i++, start = start.addDays(1) ) {
352 int dayOfWeek = start.dayOfWeek();
353 tmp = _toplevelitem->
getStart().secsTo(TQDateTime(start))/60;
359 p->fillRect( a, y1, w, y2, _sat );
361 if(start.day() == 1) {
362 p->setPen( penMonth );
363 p->drawLine( a, y1, a, y2);
372 p->fillRect( a, y1, w, y2, _sun );
374 if(start.day() == 1) {
375 p->setPen( penMonth );
376 p->drawLine( a, y1, a, y2);
383 p->setPen( penMonth );
385 if(dayOfWeek == 1 || dayOfWeek == 6 || dayOfWeek == 7)
390 p->drawLine( a, y1, a, y2);
398 xQGanttBarViewPort::recalc()
402 recalc(_toplevelitem, screenX(0), screenY(0), 0, 0 );
409 xQGanttBarViewPort::recalc(
KGanttItem* item,
int xPos,
int yPos,
415 int dd = (int) (0.25 * (
double) tmpHeight * _scaleY);
417 int _screenW = (int) ((
double) item->
getWidth() * _scaleX);
418 int _screenHS = (int) ((
double) tmpTotalHeight * _scaleY);
419 int _screenH = (int) (tmpHeight * _scaleY);
420 int _textPosY = yPos + (int) (0.7 * (
double) tmpHeight * _scaleY);
421 int _textPosX = xPos + dd + 18;
423 xTQTaskPosition* tpos =
424 new xTQTaskPosition(nr, xPos, yPos, _screenW, _screenH, _screenHS,
425 _textPosX, _textPosY, depth);
427 _gItemList.replace(item, tpos );
429 tpos->_screenHandleX = xPos + dd;
430 tpos->_screenHandleW = 2 * dd;
431 tpos->_screenHandleY = yPos + dd;
432 tpos->_screenHandleH = 2 * dd;
446 xPos + (
int)(item->
getStart().secsTo(subitem->getStart())/60 * _scaleX),
447 yPos + (
int)( h * _scaleY ), depth + 1, ++nr );
449 h += subitem->getTotalHeight();
459 xQGanttBarViewPort::drawItem(
KGanttItem* item, TQPainter* p,
462 xTQTaskPosition* tpos = _gItemList[item];
466 if(tpos->_screenX > (rect.x() + rect.width()))
return;
467 if((tpos->_screenX + tpos->_screenW) < rect.x())
return;
468 if(tpos->_screenY > (rect.y() + rect.height()) )
return;
469 if((tpos->_screenY + tpos->_screenHS) < rect.y())
return;
471 p->setPen(item->getPen());
478 p->drawLine(tpos->_screenX, tpos->_screenY,
479 tpos->_screenX, tpos->_screenY + tpos->_screenH );
482 a.setPoint(0, tpos->_screenX, tpos->_screenY + _margin );
483 a.setPoint(1, tpos->_screenX - tpos->_screenH / 2 + _margin,
484 tpos->_screenY + tpos->_screenH / 2 );
485 a.setPoint(2, tpos->_screenX, tpos->_screenY + tpos->_screenH - _margin );
486 a.setPoint(3, tpos->_screenX + tpos->_screenH / 2 - _margin,
487 tpos->_screenY + tpos->_screenH / 2 );
493 if(style & KGanttItem::DrawFilled ) {
495 p->fillRect(tpos->_screenX, tpos->_screenY + _margin,
496 tpos->_screenW, tpos->_screenHS - 2 * _margin,
503 p->setBrush(NoBrush);
504 p->drawRect(tpos->_screenX, tpos->_screenY + _margin,
505 tpos->_screenW, tpos->_screenHS - 2 * _margin );
516 drawRelation(p, rel);
525 drawItem(subitem, p, rect );
530 p->setPen(item->getPen());
533 if(style & KGanttItem::DrawHandle ||
542 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, openedIcon );
544 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, closedIcon );
549 if(style & KGanttItem::DrawText ) {
550 p->setPen(item->getTextPen());
551 p->drawText(tpos->_textPosX, tpos->_textPosY, item->
getText() );
556 p->setPen( TQPen(TQColor(red),1));
558 p->setBrush(NoBrush);
559 p->drawRect(tpos->_screenX - 2, tpos->_screenY,
560 tpos->_screenW + 4, tpos->_screenHS );
562 p->fillRect(tpos->_screenX, tpos->_screenY, 6, 6,
565 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
566 tpos->_screenY, 6, 6,
569 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
570 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
573 p->fillRect(tpos->_screenX,
574 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
583 xQGanttBarViewPort::drawRelation(TQPainter* p,
587 static int margin = 2;
592 xTQTaskPosition* tpos_from = _gItemList[from];
593 xTQTaskPosition* tpos_to = _gItemList[to];
595 p->setPen(rel->getPen());
603 x = tpos_from->_screenX + tpos_from->_screenW + margin;
604 y = tpos_from->_screenY + tpos_from->_screenH / 2;
605 a.setPoint(i++, x, y );
610 a.setPoint(i++, x, y);
614 y = (int)( (tpos_from->_screenY + tpos_from->_screenH/2) * 0.8 +
615 (tpos_to->_screenY + tpos_to->_screenH/2) * 0.2 );
616 a.setPoint(i++, x, y);
620 x = tpos_to->_screenX - hw;
621 y = (int)( (tpos_from->_screenY + tpos_from->_screenH/2) * 0.2 +
622 (tpos_to->_screenY + tpos_to->_screenH/2) * 0.8 );
624 a.setPoint(i++, x, y);
628 y = tpos_to->_screenY + tpos_to->_screenH / 2;
629 a.setPoint(i++, x, y);
633 x = tpos_to->_screenX - margin;
634 a.setPoint(i++, x, y);
638 p->drawChord( a.point(0).x()-3, a.point(0).y()-3, 6, 6, 0, 5760 );
644 b.setPoint(1, x -5, y - 5);
645 b.setPoint(2, x - 5, y + 5);
654 xQGanttBarViewPort::drawHeader(TQPainter* p,
int ,
int ,
int ,
int )
657 bool drawDays =
false;
660 TQDate start( _toplevelitem->
getStart().addSecs(-_marginX * 60 ).date() );
663 TQDate t(start.year(), start.month()-1, start.day() );
665 TQDateTime itemstart = _toplevelitem->
getStart();
667 int end = (int) (width()/(1440*_scaleX));
669 if(end < 12) drawDays =
true;
673 p->setPen( TQPen(TQColor(black)) );
675 for(
int i=0; i<=end; i++, t = t.addDays(1) ) {
677 tmp = itemstart.secsTo(TQDateTime(t))/60;
680 if(t.dayOfWeek() == 1) {
682 p->fillRect(a, 0, (
int)( 1440*5*_scaleX ), 20, TQBrush(TQColor(240,240,240)));
683 p->drawRect(a, 0, (
int)( 1440*5*_scaleX ), 20 );
686 p->drawText(a+5, 15, TQString::number(t.day()) );
690 p->drawText(a+5, 15, t.shortDayName(t.dayOfWeek()) +
" " + TQString::number(t.day()) );
697 p->fillRect(a, 21, (
int)( 1440*e*_scaleX ), 20, TQBrush(TQColor(240,240,240)));
698 p->drawRect(a, 21, (
int)( 1440*e*_scaleX ), 20 );
701 p->drawText(a+5, 36, t.shortMonthName(t.month()) );
711 xQGanttBarViewPort::setMode(
int mode)
714 if(_mode == (Mode) mode) {
740 setCursor(arrowCursor);
741 setMouseTracking(
false);
746 emit modeChanged(_mode);
753 xQGanttBarViewPort::setSelect()
757 setCursor(arrowCursor);
758 setMouseTracking(
true);
764 xQGanttBarViewPort::setZoom()
768 setCursor( *_cursor_lupe );
769 setMouseTracking(
false);
775 xQGanttBarViewPort::setMove()
779 setCursor( sizeAllCursor );
780 setMouseTracking(
false);
785 xQGanttBarViewPort::zoomIn()
792 xQGanttBarViewPort::zoomOut()
799 xQGanttBarViewPort::popup(
int index)
827 xQGanttBarViewPort::zoom(
double sfactor,
int sx,
int sy)
830 printf(
"zoom %f, (%d,%d) \n", sfactor, sx, sy );
837 printf(
"recalc ... \n");
842 _parent->center(screenX(wx), screenY(wy) );
846 printf(
"zoom ok.\n");
853 xQGanttBarViewPort::zoom(
double sfactor)
855 printf(
"zoom %f \n", sfactor );
857 int x = (int) (_parent->visibleWidth()/2 + 0.5);
858 int y = (int) (_parent->visibleHeight()/2 + 0.5);
860 printf(
"dx/2 = %d, dy/2 = %d \n", x,y);
862 zoom(sfactor, x + _parent->contentsX(), y + _parent->contentsY() );
869 xQGanttBarViewPort::zoomAll()
872 printf(
"zoom all. scaleX = %f\n", _scaleX );
875 _scaleX = ((double) _parent->visibleWidth()*60)/
876 ((
double) (_toplevelitem->
getStart().secsTo(_toplevelitem->
getEnd()) + _marginX*120));
888 TQDate* date =
new TQDate(y,m,d);
893 for(ptrDate = _holidays.first();
895 ptrDate = _holidays.next() ) {
904 _holidays.insert(i,date);
910 xQGanttBarViewPort::Position
911 xQGanttBarViewPort::check(
KGanttItem** founditem,
int x,
int y)
913 TQPtrDictIterator<xTQTaskPosition> it(_gItemList);
915 static int ty, ty2, tx, tx2, hx, hx2, hy, hy2;
918 while(it.current()) {
920 ty = it.current()->_screenY;
921 ty2 = ty + it.current()->_screenH;
922 tx = it.current()->_screenX;
923 tx2 = tx + it.current()->_screenW;
925 hx = it.current()->_screenHandleX;
926 hx2 = hx + it.current()->_screenHandleW;
927 hy = it.current()->_screenHandleY;
928 hy2 = hy + it.current()->_screenHandleH;
938 if(x>tx && x < tx2) {
939 if(y > ty && y < ty2) {
944 if(x > hx && x < hx2 &&
970 xQGanttBarViewPort::unselectAll()
972 selectItem(_toplevelitem,
false);
979 xQGanttBarViewPort::selectAll()
981 selectItem(_toplevelitem,
true);
988 xQGanttBarViewPort::selectItem(
KGanttItem* item,
bool f)
995 selectItem(subitem, f);
1003 xQGanttBarViewPort::deleteSelectedItems()
1006 printf(
"-> xQGanttBarViewPort::deleteSelectedItems()\n");
1009 TQPtrList<KGanttItem> list;
1012 getSelectedItems(_toplevelitem,list);
1016 subitem =list.next() ) {
1018 printf(
" : %s \n", subitem->getText().latin1() );
1020 connect(subitem, TQ_SIGNAL(destroyed(
KGanttItem*)),
1024 list.remove(_toplevelitem);
1026 while(list.count()>0) {
1032 printf(
"<- xQGanttBarViewPort::deleteSelectedItems()\n");
1039 xQGanttBarViewPort::observeList(TQPtrList<KGanttItem> *list)
1041 _observedList = list;
1047 xQGanttBarViewPort::itemDestroyed(
KGanttItem* item)
1049 _observedList->remove(item);
1055 xQGanttBarViewPort::getSelectedItems (
KGanttItem* item,
1056 TQPtrList<KGanttItem>& list)
1064 getSelectedItems(subitem,list);
1072 xQGanttBarViewPort::insertIntoSelectedItem()
1074 TQPtrList<KGanttItem> list;
1076 getSelectedItems(_toplevelitem,list);
1080 subitem =list.next() ) {
1082 printf(
" : %s \n", subitem->getText().latin1() );
1084 new KGanttItem(subitem, subitem->getText() +
"_subitem",
1085 subitem->getStart(), subitem->getEnd());
1093 xQGanttBarViewPort::textEdited()
1096 _currentItem->
setText(_itemTextEdit->text());
1098 _itemTextEdit->hide();
1101 #include "xQGanttBarViewPort.moc"
TQDateTime getStart()
Get date of starting.
@ DrawHandleWSubitems
Draw handle only if item contains subitems.
TQPtrList< KGanttItem > & getSubItems()
Get list of subitems.
void select(bool f)
Select/unselect item.
bool isOpen()
Returns true if item is open (subitems has to be drawn)
TQBrush & getSelectBrush()
Get brush which has to be used for drawing this item as selected.
TQDateTime getEnd()
Get date of ending.
int getHeight()
Get height.
void setText(const TQString &text)
Set text.
TQString getText()
Get text.
int getWidth()
Get width in minutes.
TQBrush & getBrush()
Get brush that is used for filling the item.
TQPtrList< KGanttRelation > & getRelations()
Get list of relations.
bool isSelected()
Returns true if item is selected.
int getTotalHeight()
Get total height.
int getStyle()
Get drawing style.
KGanttItem * getFrom()
Get date of starting.
KGanttItem * getTo()
Get date of ending.
void update(int x1, int y1, int x2, int y2)
Update widget.
~xQGanttBarViewPort()
Destructor.
xQGanttBarViewPort(KGanttItem *toplevelitem, xQGanttBarView *parent=0, const char *name=0, WFlags f=0)
Constructor.
void addHoliday(int y, int m, int d)
Add holiday.