kgantt

xQGanttBarViewPort.cpp
1//
2// file : xQGanttBarViewPort.C
3// date : 26 oct 2000
4// changed : 09 jan 2001
5// author : jh
6//
7
8#include "xQGanttBarViewPort.h"
9#include "xQGanttBarView.h"
10
11#include <tqcolor.h>
12#include <tqtoolbutton.h>
13
14#include "lupe.xpm"
15#include "open.xpm"
16#include "close.xpm"
17
18#include <tdetoolbarbutton.h>
19#include <kiconloader.h>
20#include <tdelocale.h>
21
22
23
25 xQGanttBarView* parent,
26 const char * name, WFlags f)
27 : TQFrame(parent,name,f)
29{
30 _parent = parent;
31
32 closedIcon = TQPixmap(open_xpm);
33 openedIcon = TQPixmap(close_xpm);
34
35 _observedList = NULL;
36 _toolbar = NULL;
37
38 _gItemList = TQPtrDict<xTQTaskPosition>(449);
39 _gItemList.setAutoDelete(true);
40
41 _toplevelitem = toplevelitem;
42
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);
48 _itemInfo->hide();
49
50
51 _itemTextEdit = new TQLineEdit(this);
52 _itemTextEdit->hide();
53 _itemTextEdit->setFrame(false);
54
55 connect(_itemTextEdit, TQ_SIGNAL(returnPressed ()),
56 this, TQ_SLOT(textEdited()));
57
58 _iconloader = new TDEIconLoader();
59
60 initMenu();
61
62 setBackgroundColor(TQColor(white));
63 /*
64 TQPixmap back("background.png");
65 setBackgroundPixmap ( back );
66 */
67
68 _grid = 1440;
69 _snapgrid = 360;
70
71 _drawGrid = true;
72 _drawHeader = false;
73
74 _marginX = 10 * 1440;
75 _marginY = 50;
76
77 _scaleX = 0.1;
78 _scaleY = 1;
79
80 _margin = 4; // margin item in pixel
81
82 _startPoint = new TQPoint(); _endPoint = new TQPoint();
83
84 _cursor_lupe = new TQCursor( TQPixmap(lupe) );
85
86 connect(_toplevelitem, TQ_SIGNAL(changed(KGanttItem*, KGanttItem::Change)),
87 this, TQ_SLOT(toplevelitemChanged(KGanttItem*, KGanttItem::Change)) );
88
89 recalc(); adjustSize();
90
91 setFocusPolicy(TQWidget::StrongFocus);
92 _mode = Init;
93
94}
95
96
97
100{
101}
102
103
104
105TDEToolBar*
106xQGanttBarViewPort::toolbar(TQMainWindow* mw)
107{
108 if(_toolbar || mw == 0) return _toolbar;
109
110 _toolbar = new TDEToolBar(mw,TQMainWindow::TQt::DockTop);
111
112 mw->addToolBar(_toolbar);
113
114
115 // TDEIconLoader* iconloader = new TDEIconLoader("kgantt");
116
117
118 _toolbar->insertButton("ganttSelect.png", 0,
119 TQ_SIGNAL(clicked()),
120 this, TQ_SLOT(setSelect()),
121 true, i18n("Select") );
122
123 TDEPopupMenu *selectMenu = new TDEPopupMenu(_toolbar);
124
125
126 /*
127 select all items
128 */
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()) );
132
133
134 /*
135 unselect all items
136 */
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()) );
140
141
142 TDEToolBarButton* b = _toolbar->getButton(0);
143 b->setDelayedPopup(selectMenu);
144
145
146 _toolbar->insertButton("viewmag.png", 1,
147 TQ_SIGNAL(clicked()),
148 this, TQ_SLOT(setZoom()),
149 true, i18n("Zoom") );
150
151 TDEPopupMenu* zoomMenu = new TDEPopupMenu(_toolbar);
152
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();
157
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()) );
161
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()) );
165
166 b = _toolbar->getButton(1);
167 b->setDelayedPopup(zoomMenu);
168
169 _toolbar->insertButton("move.png", 2,
170 TQ_SIGNAL(clicked()),
171 this, TQ_SLOT(setMove()),
172 true, i18n("Move") );
173
174 return _toolbar;
175
176}
177
178
179
180void
181xQGanttBarViewPort::initMenu()
183{
184 _menu = new TDEPopupMenu(this);
185
186 /*
187 select
188 */
189
190 _selectMenu = new TDEPopupMenu(_menu);
191
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()));
195
196 _selectMenu->insertSeparator();
197
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()) );
201
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()) );
205
206 _menu->insertItem( i18n("Select"), _selectMenu);
207
208
209 /*
210 zoom
211 */
212
213 TDEPopupMenu* _zoomMenu = new TDEPopupMenu(_menu);
214
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()) );
218
219 _zoomMenu->insertSeparator();
220
221 _zoomMenu->insertItem(pix, i18n("Zoom All"), this, TQ_SLOT(zoomAll()) );
222 _zoomMenu->insertSeparator();
223
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()) );
227
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()) );
231
232 _menu->insertItem( "Zoom", _zoomMenu);
233
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()) );
237
238 _menu->insertSeparator();
239
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()));
243
244}
245
246
247
248void
249xQGanttBarViewPort::toplevelitemChanged(KGanttItem* /*item*/, KGanttItem::Change /*c*/)
251{
252 recalc();
253 adjustSize();
254}
255
256
257
258void
259xQGanttBarViewPort::adjustSize()
261{
262 // printf("xQGanttBarViewPort::adjustSize()\n");
263
264 static int sw = 0;
265 static int sh = 0;
266
267 int w = screenX(_toplevelitem->getWidth() + _marginX);
268 int h = screenY(_toplevelitem->getTotalHeight() + _marginY);
269
270 if(sw != w || sh !=h) {
271
272 sw = w;
273 sh = h;
274
275 resize(w,h);
276
277 emit resized();
278
279 }
280
281}
282
283
284
285void
286xQGanttBarViewPort::update(int x1, int y1, int x2, int y2)
288{
289 TQPainter p(this);
290
291 // TQTime time1 = TQTime::currentTime();
292
293 if(_drawGrid)
294 drawGrid(&p, x1, y1, x2, y2);
295
296 // TQTime time2 = TQTime::currentTime();
297 // printf("%d msec for drawing grid.\n", time1.msecsTo( time2 ) );
298
299 // drawContents(&p, x1, y1, x2, y2);
300 drawItem(_toplevelitem, &p, TQRect(x1, y1, x2-x1, y2-y1) );
301
302 // time1 = TQTime::currentTime();
303 // printf("%d msec for drawing contents.\n", time2.msecsTo( time1 ) );
304
305 if(_drawHeader)
306 drawHeader(&p, x1, y1, x2, y2);
307
308 // time2 = TQTime::currentTime();<
309 // printf("%d msec for drawing header.\n", time1.msecsTo( time2 ) );
310
311}
312
313
314
315void
316xQGanttBarViewPort::drawGrid(TQPainter* p, int x1, int y1, int x2, int y2)
318{
319 y2 += 5; // avoid white lines at bottom of redrawn region
320
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);
328
329 TQDate start( _toplevelitem->getStart().addSecs(worldX(x1)*60).date() );
330
331 end = (int) ((x2-x1)/(1440.*_scaleX))+1;
332 w = (int) (1440. * _scaleX + 0.5);
333
334 // draw holydays
335
336 TQDate* ptrDate;
337 TQDate cmp(start.addDays(-1));
338
339 for(ptrDate = _holidays.first(); ptrDate != 0; ptrDate = _holidays.next() ) {
340 if(*ptrDate > cmp) {
341 tmp = _toplevelitem->getStart().secsTo(TQDateTime(*ptrDate))/60;
342 a = screenX( tmp );
343 p->fillRect( a, y1, w, y2, _hol );
344 }
345
346 }
347
348 // draw grid
349
350 for(int i=0; i<=end; i++, start = start.addDays(1) ) {
351
352 int dayOfWeek = start.dayOfWeek();
353 tmp = _toplevelitem->getStart().secsTo(TQDateTime(start))/60;
354 a = screenX( tmp );
355
356 // draw saturday
357 if(dayOfWeek == 6) {
358
359 p->fillRect( a, y1, w, y2, _sat );
360
361 if(start.day() == 1) {
362 p->setPen( penMonth );
363 p->drawLine( a, y1, a, y2);
364 }
365
366 // continue;
367 }
368
369 // sunday
370 if(dayOfWeek == 7) {
371
372 p->fillRect( a, y1, w, y2, _sun );
373
374 if(start.day() == 1) {
375 p->setPen( penMonth );
376 p->drawLine( a, y1, a, y2);
377 }
378
379 // continue;
380 }
381
382 if(start.day() == 1)
383 p->setPen( penMonth );
384 else {
385 if(dayOfWeek == 1 || dayOfWeek == 6 || dayOfWeek == 7)
386 continue;
387 p->setPen( penDay );
388 }
389
390 p->drawLine( a, y1, a, y2);
391
392 }
393}
394
395
396
397void
398xQGanttBarViewPort::recalc()
399{
400 // printf("xQGanttBarViewPort::recalc()\n");
401 _gItemList.clear();
402 recalc(_toplevelitem, screenX(0), screenY(0), 0, 0 );
403 emit recalculated();
404}
405
406
407
408void
409xQGanttBarViewPort::recalc(KGanttItem* item, int xPos, int yPos,
410 int depth, int nr)
411{
412 int tmpTotalHeight = item->getTotalHeight();
413 int tmpHeight = item->getHeight();
414
415 int dd = (int) (0.25 * (double) tmpHeight * _scaleY);
416
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;
422
423 xTQTaskPosition* tpos =
424 new xTQTaskPosition(nr, xPos, yPos, _screenW, _screenH, _screenHS,
425 _textPosX, _textPosY, depth);
426
427 _gItemList.replace(item, tpos );
428
429 tpos->_screenHandleX = xPos + dd;
430 tpos->_screenHandleW = 2 * dd;
431 tpos->_screenHandleY = yPos + dd;
432 tpos->_screenHandleH = 2 * dd;
433
434
435 // recalc subitems
436
437 if(item->isOpen()) {
438
439 int h = tmpHeight;
440
441 for(KGanttItem* subitem = item->getSubItems().first();
442 subitem != 0;
443 subitem = item->getSubItems().next() ) {
444
445 recalc(subitem,
446 xPos + (int)(item->getStart().secsTo(subitem->getStart())/60 * _scaleX),
447 yPos + (int)( h * _scaleY ), depth + 1, ++nr );
448
449 h += subitem->getTotalHeight();
450
451 }
452 }
453
454}
455
456
457
458void
459xQGanttBarViewPort::drawItem(KGanttItem* item, TQPainter* p,
460 const TQRect& rect )
461{
462 xTQTaskPosition* tpos = _gItemList[item];
463
464 if(!tpos) return;
465
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;
470
471 p->setPen(item->getPen());
472 p->setBrush(item->getBrush());
473
474 int style = item->getStyle();
475
476 if(item->getWidth()==0) {
477
478 p->drawLine(tpos->_screenX, tpos->_screenY,
479 tpos->_screenX, tpos->_screenY + tpos->_screenH );
480
481 TQPointArray a(4);
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 );
488 p->drawPolygon(a);
489
490 }
491 else {
492
493 if(style & KGanttItem::DrawFilled ) {
494
495 p->fillRect(tpos->_screenX, tpos->_screenY + _margin,
496 tpos->_screenW, tpos->_screenHS - 2 * _margin,
497 item->getBrush() );
498
499 }
500
501 if(style & KGanttItem::DrawBorder ) {
502
503 p->setBrush(NoBrush);
504 p->drawRect(tpos->_screenX, tpos->_screenY + _margin,
505 tpos->_screenW, tpos->_screenHS - 2 * _margin );
506
507 }
508
509 if(item->isOpen()) {
510
511 // draw relations
512 for(KGanttRelation* rel = item->getRelations().first();
513 rel != 0;
514 rel = item->getRelations().next() ) {
515
516 drawRelation(p, rel);
517
518 }
519
520 // draw subitems
521 for(KGanttItem* subitem = item->getSubItems().first();
522 subitem != 0;
523 subitem = item->getSubItems().next() ) {
524
525 drawItem(subitem, p, rect );
526
527 }
528 }
529
530 p->setPen(item->getPen());
531 p->setBrush(item->getBrush());
532
533 if(style & KGanttItem::DrawHandle ||
534 ((style & KGanttItem::DrawHandleWSubitems) && item->getSubItems().count()>0) ) {
535
536 /*
537 p->setBrush(TQColor("steelblue"));
538 p->drawRect(tpos->_screenHandleX, tpos->_screenHandleY,
539 tpos->_screenHandleW, tpos->_screenHandleH);
540 */
541 if(item->isOpen())
542 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, openedIcon );
543 else
544 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, closedIcon );
545
546 }
547 }
548
549 if(style & KGanttItem::DrawText ) {
550 p->setPen(item->getTextPen());
551 p->drawText(tpos->_textPosX, tpos->_textPosY, item->getText() );
552 }
553
554 if(item->isSelected()) {
555
556 p->setPen( TQPen(TQColor(red),1));
557
558 p->setBrush(NoBrush);
559 p->drawRect(tpos->_screenX - 2, tpos->_screenY,
560 tpos->_screenW + 4, tpos->_screenHS );
561
562 p->fillRect(tpos->_screenX, tpos->_screenY, 6, 6,
563 item->getSelectBrush() );
564
565 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
566 tpos->_screenY, 6, 6,
567 item->getSelectBrush() );
568
569 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
570 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
571 item->getSelectBrush() );
572
573 p->fillRect(tpos->_screenX,
574 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
575 item->getSelectBrush() );
576 }
577
578}
579
580
581
582void
583xQGanttBarViewPort::drawRelation(TQPainter* p,
584 KGanttRelation* rel)
585{
586 static int hw = 20;
587 static int margin = 2;
588
589 KGanttItem* from = rel->getFrom();
590 KGanttItem* to = rel->getTo();
591
592 xTQTaskPosition* tpos_from = _gItemList[from];
593 xTQTaskPosition* tpos_to = _gItemList[to];
594
595 p->setPen(rel->getPen());
596
597 TQPointArray a(6);
598
599 int x,y;
600 int i=0;
601
602 // 1
603 x = tpos_from->_screenX + tpos_from->_screenW + margin;
604 y = tpos_from->_screenY + tpos_from->_screenH / 2;
605 a.setPoint(i++, x, y );
606
607
608 // 2
609 x = x + hw;
610 a.setPoint(i++, x, y);
611
612
613 // 3
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);
617
618
619 // 4
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 );
623
624 a.setPoint(i++, x, y);
625
626
627 // 5
628 y = tpos_to->_screenY + tpos_to->_screenH / 2;
629 a.setPoint(i++, x, y);
630
631
632 // 6
633 x = tpos_to->_screenX - margin;
634 a.setPoint(i++, x, y);
635
636 p->drawPolyline(a);
637
638 p->drawChord( a.point(0).x()-3, a.point(0).y()-3, 6, 6, 0, 5760 );
639
640
641 TQPointArray b(3);
642
643 b.setPoint(0, x,y);
644 b.setPoint(1, x -5, y - 5);
645 b.setPoint(2, x - 5, y + 5);
646
647 p->drawPolygon(b);
648
649}
650
651
652
653void
654xQGanttBarViewPort::drawHeader(TQPainter* p, int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/)
656{
657 bool drawDays = false;
658 int a,e,tmp;
659
660 TQDate start( _toplevelitem->getStart().addSecs(-_marginX * 60 ).date() );
661
662 // subtract 1 month to draw first month
663 TQDate t(start.year(), start.month()-1, start.day() );
664
665 TQDateTime itemstart = _toplevelitem->getStart();
666
667 int end = (int) (width()/(1440*_scaleX));
668
669 if(end < 12) drawDays = true;
670
671 end += 30; // add 30 days to draw last month
672
673 p->setPen( TQPen(TQColor(black)) );
674
675 for(int i=0; i<=end; i++, t = t.addDays(1) ) {
676
677 tmp = itemstart.secsTo(TQDateTime(t))/60;
678 a = screenX( tmp );
679
680 if(t.dayOfWeek() == 1) {
681
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 );
684
685 if(!drawDays)
686 p->drawText(a+5, 15, TQString::number(t.day()) );
687 }
688
689 if(drawDays) {
690 p->drawText(a+5, 15, t.shortDayName(t.dayOfWeek()) + " " + TQString::number(t.day()) );
691 }
692
693 if(t.day()==1) {
694
695 e = t.daysInMonth();
696
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 );
699
700 if(a<0) a = 0;
701 p->drawText(a+5, 36, t.shortMonthName(t.month()) );
702
703 }
704
705 }
706}
707
708
709
710void
711xQGanttBarViewPort::setMode(int mode)
712
713{
714 if(_mode == (Mode) mode) {
715 return;
716 }
717
718 switch(_mode) {
719
720 case Select:
721
722 setSelect();
723 break;
724
725
726 case Zoom:
727
728 setZoom();
729 break;
730
731
732 case Move:
733
734 setMove();
735 break;
736
737
738 default:
739
740 setCursor(arrowCursor);
741 setMouseTracking(false);
742 break;
743
744 }
745
746 emit modeChanged(_mode);
747
748}
749
750
751
752void
753xQGanttBarViewPort::setSelect()
755{
756 _mode = Select;
757 setCursor(arrowCursor);
758 setMouseTracking(true);
759}
760
761
762
763void
764xQGanttBarViewPort::setZoom()
766{
767 _mode = Zoom;
768 setCursor( *_cursor_lupe );
769 setMouseTracking(false);
770}
771
772
773
774void
775xQGanttBarViewPort::setMove()
777{
778 _mode = Move;
779 setCursor( sizeAllCursor );
780 setMouseTracking(false);
781}
782
783
784void
785xQGanttBarViewPort::zoomIn()
786{
787 zoom(1.2);
788}
789
790
791void
792xQGanttBarViewPort::zoomOut()
793{
794 zoom(0.7);
795}
796
797
798void
799xQGanttBarViewPort::popup(int index)
801{
802
803 switch(index) {
804
805 case Select:
806 case Zoom:
807 case Move:
808
809 setMode(index);
810 break;
811
812 case 10: // configure
813
814 // setConfigDialog();
815 // _config->show();
816
817 break;
818
819 }
820
821
822}
823
824
825
826void
827xQGanttBarViewPort::zoom(double sfactor, int sx, int sy)
829{
830 printf("zoom %f, (%d,%d) \n", sfactor, sx, sy );
831
832 int wx = worldX(sx);
833 int wy = worldY(sy);
834
835 _scaleX *= sfactor;
836
837 printf("recalc ... \n");
838
839 recalc();
840 adjustSize();
841
842 _parent->center(screenX(wx), screenY(wy) );
843
844 TQWidget::update();
845
846 printf("zoom ok.\n");
847
848}
849
850
851
852void
853xQGanttBarViewPort::zoom(double sfactor)
854{
855 printf("zoom %f \n", sfactor );
856
857 int x = (int) (_parent->visibleWidth()/2 + 0.5);
858 int y = (int) (_parent->visibleHeight()/2 + 0.5);
859
860 printf("dx/2 = %d, dy/2 = %d \n", x,y);
861
862 zoom(sfactor, x + _parent->contentsX(), y + _parent->contentsY() );
863
864}
865
866
867
868void
869xQGanttBarViewPort::zoomAll()
870{
871#ifdef _DEBUG_
872 printf("zoom all. scaleX = %f\n", _scaleX );
873#endif
874
875 _scaleX = ((double) _parent->visibleWidth()*60)/
876 ((double) (_toplevelitem->getStart().secsTo(_toplevelitem->getEnd()) + _marginX*120));
877
878 recalc();
879 adjustSize();
880
881}
882
883
884
885void
887{
888 TQDate* date = new TQDate(y,m,d);
889
890 TQDate* ptrDate;
891 int i=0;
892
893 for(ptrDate = _holidays.first();
894 ptrDate != 0;
895 ptrDate = _holidays.next() ) {
896
897 if(*ptrDate > *date)
898 break;
899
900 i++;
901
902 }
903
904 _holidays.insert(i,date);
905
906}
907
908
909
910xQGanttBarViewPort::Position
911xQGanttBarViewPort::check(KGanttItem** founditem, int x, int y)
912{
913 TQPtrDictIterator<xTQTaskPosition> it(_gItemList);
914
915 static int ty, ty2, tx, tx2, hx, hx2, hy, hy2;
916 bool increased;
917
918 while(it.current()) {
919
920 ty = it.current()->_screenY;
921 ty2 = ty + it.current()->_screenH;
922 tx = it.current()->_screenX;
923 tx2 = tx + it.current()->_screenW;
924
925 hx = it.current()->_screenHandleX;
926 hx2 = hx + it.current()->_screenHandleW;
927 hy = it.current()->_screenHandleY;
928 hy2 = hy + it.current()->_screenHandleH;
929
930 increased = false;
931
932 if(tx2-tx<12) {
933 tx -= 12;
934 tx2 += 12;
935 increased = true;
936 }
937
938 if(x>tx && x < tx2) {
939 if(y > ty && y < ty2) {
940
941 *founditem = (KGanttItem*) it.currentKey();
942
943 if(!increased)
944 if(x > hx && x < hx2 &&
945 y > hy && y < hy2 )
946 return Handle;
947
948 if(x < (tx + 5))
949 return West;
950
951 if(x > (tx2 - 5))
952 return East;
953
954 return Center;
955 }
956
957 }
958
959 ++it;
960
961 }
962
963 return Outside;
964
965}
966
967
968
969void
970xQGanttBarViewPort::unselectAll()
971{
972 selectItem(_toplevelitem, false);
973 TQWidget::update();
974}
975
976
977
978void
979xQGanttBarViewPort::selectAll()
980{
981 selectItem(_toplevelitem, true);
982 TQWidget::update();
983}
984
985
986
987void
988xQGanttBarViewPort::selectItem(KGanttItem* item, bool f)
989{
990 item->select(f);
991
992 for(KGanttItem* subitem = item->getSubItems().first();
993 subitem != 0;
994 subitem = item->getSubItems().next() ) {
995 selectItem(subitem, f);
996 }
997
998}
999
1000
1001
1002void
1003xQGanttBarViewPort::deleteSelectedItems()
1004{
1005#ifdef _DEBUG_
1006 printf("-> xQGanttBarViewPort::deleteSelectedItems()\n");
1007#endif
1008
1009 TQPtrList<KGanttItem> list;
1010 observeList(&list);
1011
1012 getSelectedItems(_toplevelitem,list);
1013
1014 for(KGanttItem* subitem = list.first();
1015 subitem != 0;
1016 subitem =list.next() ) {
1017#ifdef _DEBUG_
1018 printf(" : %s \n", subitem->getText().latin1() );
1019#endif
1020 connect(subitem, TQ_SIGNAL(destroyed(KGanttItem*)),
1021 this, TQ_SLOT(itemDestroyed(KGanttItem*)));
1022 }
1023
1024 list.remove(_toplevelitem);
1025
1026 while(list.count()>0) {
1027 KGanttItem* item = list.getFirst();
1028 delete item;
1029 }
1030
1031#ifdef _DEBUG_
1032 printf("<- xQGanttBarViewPort::deleteSelectedItems()\n");
1033#endif
1034}
1035
1036
1037
1038void
1039xQGanttBarViewPort::observeList(TQPtrList<KGanttItem> *list)
1040{
1041 _observedList = list;
1042}
1043
1044
1045
1046void
1047xQGanttBarViewPort::itemDestroyed(KGanttItem* item)
1048{
1049 _observedList->remove(item);
1050}
1051
1052
1053
1054void
1055xQGanttBarViewPort::getSelectedItems (KGanttItem* item,
1056 TQPtrList<KGanttItem>& list)
1057{
1058 if(item->isSelected()) list.append(item);
1059
1060 for(KGanttItem* subitem = item->getSubItems().first();
1061 subitem != 0;
1062 subitem = item->getSubItems().next() ) {
1063
1064 getSelectedItems(subitem,list);
1065
1066 }
1067
1068}
1069
1070
1071void
1072xQGanttBarViewPort::insertIntoSelectedItem()
1073{
1074 TQPtrList<KGanttItem> list;
1075
1076 getSelectedItems(_toplevelitem,list);
1077
1078 for(KGanttItem* subitem = list.first();
1079 subitem != 0;
1080 subitem =list.next() ) {
1081#ifdef _DEBUG_
1082 printf(" : %s \n", subitem->getText().latin1() );
1083#endif
1084 new KGanttItem(subitem, subitem->getText() + "_subitem",
1085 subitem->getStart(), subitem->getEnd());
1086 }
1087
1088}
1089
1090
1091
1092void
1093xQGanttBarViewPort::textEdited()
1094{
1095 if(_currentItem) {
1096 _currentItem->setText(_itemTextEdit->text());
1097 setFocus();
1098 _itemTextEdit->hide();
1099 }
1100}
1101#include "xQGanttBarViewPort.moc"
KGanttItem.
Definition: KGanttItem.h:56
TQDateTime getStart()
Get date of starting.
Definition: KGanttItem.cpp:208
@ DrawBorder
Draw border.
Definition: KGanttItem.h:116
@ DrawHandleWSubitems
Draw handle only if item contains subitems.
Definition: KGanttItem.h:126
TQPtrList< KGanttItem > & getSubItems()
Get list of subitems.
Definition: KGanttItem.h:421
void select(bool f)
Select/unselect item.
Definition: KGanttItem.cpp:450
TQBrush & getSelectBrush()
Get brush which has to be used for drawing this item as selected.
Definition: KGanttItem.h:284
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
int getHeight()
Get height.
Definition: KGanttItem.h:393
TQPtrList< KGanttRelation > & getRelations()
Get list of relations.
Definition: KGanttItem.h:431
void setText(const TQString &text)
Set text.
Definition: KGanttItem.cpp:422
TQString getText()
Get text.
Definition: KGanttItem.h:340
int getWidth()
Get width in minutes.
Definition: KGanttItem.cpp:550
TQBrush & getBrush()
Get brush that is used for filling the item.
Definition: KGanttItem.h:274
bool isSelected()
Returns true if item is selected.
Definition: KGanttItem.h:219
int getTotalHeight()
Get total height.
Definition: KGanttItem.cpp:534
int getStyle()
Get drawing style.
Definition: KGanttItem.h:256
KGanttRelation.
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.
Gantt view.