00001
00002
00003
00004
00005
00006
00007
00008 #include "xQGanttBarViewPort.h"
00009 #include "xQGanttBarView.h"
00010
00011 #include <qcolor.h>
00012 #include <qtoolbutton.h>
00013
00014 #include "lupe.xpm"
00015 #include "open.xpm"
00016 #include "close.xpm"
00017
00018 #include <ktoolbarbutton.h>
00019 #include <kiconloader.h>
00020 #include <klocale.h>
00021
00022
00023
00024 xQGanttBarViewPort::xQGanttBarViewPort(KGanttItem* toplevelitem,
00025 xQGanttBarView* parent,
00026 const char * name, WFlags f)
00027 : QFrame(parent,name,f)
00029 {
00030 _parent = parent;
00031
00032 closedIcon = QPixmap(open_xpm);
00033 openedIcon = QPixmap(close_xpm);
00034
00035 _observedList = NULL;
00036 _toolbar = NULL;
00037
00038 _gItemList = QPtrDict<xQTaskPosition>(449);
00039 _gItemList.setAutoDelete(true);
00040
00041 _toplevelitem = toplevelitem;
00042
00043 _itemInfo = new QLabel(this);
00044 _itemInfo->setBackgroundColor(QColor(235,235,255));
00045 _itemInfo->setFrameStyle( Panel | Sunken );
00046 _itemInfo->setMargin( 5 );
00047 _itemInfo->setLineWidth(1);
00048 _itemInfo->hide();
00049
00050
00051 _itemTextEdit = new QLineEdit(this);
00052 _itemTextEdit->hide();
00053 _itemTextEdit->setFrame(false);
00054
00055 connect(_itemTextEdit, SIGNAL(returnPressed ()),
00056 this, SLOT(textEdited()));
00057
00058 _iconloader = new KIconLoader();
00059
00060 initMenu();
00061
00062 setBackgroundColor(QColor(white));
00063
00064
00065
00066
00067
00068 _grid = 1440;
00069 _snapgrid = 360;
00070
00071 _drawGrid = true;
00072 _drawHeader = false;
00073
00074 _marginX = 10 * 1440;
00075 _marginY = 50;
00076
00077 _scaleX = 0.1;
00078 _scaleY = 1;
00079
00080 _margin = 4;
00081
00082 _startPoint = new QPoint(); _endPoint = new QPoint();
00083
00084 _cursor_lupe = new QCursor( QPixmap(lupe) );
00085
00086 connect(_toplevelitem, SIGNAL(changed(KGanttItem*, KGanttItem::Change)),
00087 this, SLOT(toplevelitemChanged(KGanttItem*, KGanttItem::Change)) );
00088
00089 recalc(); adjustSize();
00090
00091 setFocusPolicy(QWidget::StrongFocus);
00092 _mode = Init;
00093
00094 }
00095
00096
00097
00098 xQGanttBarViewPort::~xQGanttBarViewPort()
00100 {
00101 }
00102
00103
00104
00105 KToolBar*
00106 xQGanttBarViewPort::toolbar(QMainWindow* mw)
00107 {
00108 if(_toolbar || mw == 0) return _toolbar;
00109
00110 _toolbar = new KToolBar(mw,QMainWindow::DockTop);
00111
00112 mw->addToolBar(_toolbar);
00113
00114
00115
00116
00117
00118 _toolbar->insertButton("ganttSelect.png", 0,
00119 SIGNAL(clicked()),
00120 this, SLOT(setSelect()),
00121 true, i18n("Select") );
00122
00123 KPopupMenu *selectMenu = new KPopupMenu(_toolbar);
00124
00125
00126
00127
00128
00129 QPixmap pix = _iconloader->loadIcon("ganttSelecttask.png", KIcon::Toolbar , 16 );
00130 if(pix.isNull()) printf("ganttSelecttask.png not found !\n");
00131 selectMenu->insertItem(pix, i18n("Select All"), this, SLOT(selectAll()) );
00132
00133
00134
00135
00136
00137 pix = _iconloader->loadIcon("ganttUnselecttask", KIcon::Toolbar , 16 );
00138 if(pix.isNull()) printf("ganttUnselecttask.png not found !\n");
00139 selectMenu->insertItem(pix, i18n("Unselect All"), this, SLOT(unselectAll()) );
00140
00141
00142 KToolBarButton* b = _toolbar->getButton(0);
00143 b->setDelayedPopup(selectMenu);
00144
00145
00146 _toolbar->insertButton("viewmag.png", 1,
00147 SIGNAL(clicked()),
00148 this, SLOT(setZoom()),
00149 true, i18n("Zoom") );
00150
00151 KPopupMenu* zoomMenu = new KPopupMenu(_toolbar);
00152
00153 pix = _iconloader->loadIcon("viewmag.png", KIcon::Toolbar , 16 );
00154 if(pix.isNull()) printf("viewmag.png not found !\n");
00155 zoomMenu->insertItem(pix, i18n("Zoom All"), this, SLOT(zoomAll()) );
00156 zoomMenu->insertSeparator();
00157
00158 pix = _iconloader->loadIcon("viewmag+.png", KIcon::Toolbar , 16 );
00159 if(pix.isNull()) printf("viewmag+.png not found !\n");
00160 zoomMenu->insertItem(pix, i18n("Zoom In +"), this, SLOT(zoomIn()) );
00161
00162 pix = _iconloader->loadIcon("viewmag-.png", KIcon::Toolbar , 16 );
00163 if(pix.isNull()) printf("viewmag-.png not found !\n");
00164 zoomMenu->insertItem(pix, i18n("Zoom Out -"), this, SLOT(zoomOut()) );
00165
00166 b = _toolbar->getButton(1);
00167 b->setDelayedPopup(zoomMenu);
00168
00169 _toolbar->insertButton("move.png", 2,
00170 SIGNAL(clicked()),
00171 this, SLOT(setMove()),
00172 true, i18n("Move") );
00173
00174 return _toolbar;
00175
00176 }
00177
00178
00179
00180 void
00181 xQGanttBarViewPort::initMenu()
00183 {
00184 _menu = new KPopupMenu(this);
00185
00186
00187
00188
00189
00190 _selectMenu = new KPopupMenu(_menu);
00191
00192 QPixmap pix = _iconloader->loadIcon("ganttSelect.png", KIcon::Toolbar , 16 );
00193 if(pix.isNull()) printf("ganttSelect.png not found !\n");
00194 _selectMenu->insertItem(pix, i18n("Select Mode"), this, SLOT(setSelect()));
00195
00196 _selectMenu->insertSeparator();
00197
00198 pix = _iconloader->loadIcon("ganttSelecttask.png", KIcon::Toolbar , 16 );
00199 if(pix.isNull()) printf("ganttSelecttask.png not found !\n");
00200 _selectMenu->insertItem(pix, i18n("Select All"), this, SLOT(selectAll()) );
00201
00202 pix = _iconloader->loadIcon("ganttUnselecttask", KIcon::Toolbar , 16 );
00203 if(pix.isNull()) printf("ganttUnselecttask.png not found !\n");
00204 _selectMenu->insertItem(pix, i18n("Unselect All"), this, SLOT(unselectAll()) );
00205
00206 _menu->insertItem( i18n("Select"), _selectMenu);
00207
00208
00209
00210
00211
00212
00213 KPopupMenu* _zoomMenu = new KPopupMenu(_menu);
00214
00215 pix = _iconloader->loadIcon("viewmag.png", KIcon::Toolbar , 16 );
00216 if(pix.isNull()) printf("viewmag.png not found !\n");
00217 _zoomMenu->insertItem(i18n("Zoom Mode"), this, SLOT(setZoom()) );
00218
00219 _zoomMenu->insertSeparator();
00220
00221 _zoomMenu->insertItem(pix, i18n("Zoom All"), this, SLOT(zoomAll()) );
00222 _zoomMenu->insertSeparator();
00223
00224 pix = _iconloader->loadIcon("viewmag+.png", KIcon::Toolbar , 16 );
00225 if(pix.isNull()) printf("viewmag+.png not found !\n");
00226 _zoomMenu->insertItem(pix, i18n("Zoom In +"), this, SLOT(zoomIn()) );
00227
00228 pix = _iconloader->loadIcon("viewmag-.png", KIcon::Toolbar , 16 );
00229 if(pix.isNull()) printf("viewmag-.png not found !\n");
00230 _zoomMenu->insertItem(pix, i18n("Zoom Out -"), this, SLOT(zoomOut()) );
00231
00232 _menu->insertItem( "Zoom", _zoomMenu);
00233
00234 pix = _iconloader->loadIcon("move.png", KIcon::Toolbar , 16 );
00235 if(pix.isNull()) printf("move.png not found !\n");
00236 _menu->insertItem(pix, i18n("Move Mode"), this, SLOT(setMove()) );
00237
00238 _menu->insertSeparator();
00239
00240 pix = _iconloader->loadIcon("configure.png", KIcon::Toolbar , 16 );
00241 if(pix.isNull()) printf("configure.png not found !\n");
00242 _menu->insertItem(pix, i18n("Configure Gantt..."), _parent, SLOT(showConfig()));
00243
00244 }
00245
00246
00247
00248 void
00249 xQGanttBarViewPort::toplevelitemChanged(KGanttItem* item, KGanttItem::Change c)
00251 {
00252 recalc();
00253 adjustSize();
00254 }
00255
00256
00257
00258 void
00259 xQGanttBarViewPort::adjustSize()
00261 {
00262
00263
00264 static int sw = 0;
00265 static int sh = 0;
00266
00267 int w = screenX(_toplevelitem->getWidth() + _marginX);
00268 int h = screenY(_toplevelitem->getTotalHeight() + _marginY);
00269
00270 if(sw != w || sh !=h) {
00271
00272 sw = w;
00273 sh = h;
00274
00275 resize(w,h);
00276
00277 emit resized();
00278
00279 }
00280
00281 }
00282
00283
00284
00285 void
00286 xQGanttBarViewPort::update(int x1, int y1, int x2, int y2)
00288 {
00289 QPainter p(this);
00290
00291
00292
00293 if(_drawGrid)
00294 drawGrid(&p, x1, y1, x2, y2);
00295
00296
00297
00298
00299
00300 drawItem(_toplevelitem, &p, QRect(x1, y1, x2-x1, y2-y1) );
00301
00302
00303
00304
00305 if(_drawHeader)
00306 drawHeader(&p, x1, y1, x2, y2);
00307
00308
00309
00310
00311 }
00312
00313
00314
00315 void
00316 xQGanttBarViewPort::drawGrid(QPainter* p, int x1, int y1, int x2, int y2)
00318 {
00319 y2 += 5;
00320
00321 static int a, w, end, tmp;
00322 static QBrush _sat( QColor(200,200,200));
00323 static QBrush _sun( QColor(255,110,110));
00324 static QBrush _hol( QColor(200,200,250));
00325 static QPen penDay( QColor(235,235,235), 0, DotLine);
00326 static QPen penMonth( QColor(0,150,0), 3, DashDotLine);
00327 static QPen penHour( QColor(0,0,150), 0, DashDotLine);
00328
00329 QDate start( _toplevelitem->getStart().addSecs(worldX(x1)*60).date() );
00330
00331 end = (int) ((x2-x1)/(1440.*_scaleX))+1;
00332 w = (int) (1440. * _scaleX + 0.5);
00333
00334
00335
00336 QDate* ptrDate;
00337 QDate cmp(start.addDays(-1));
00338
00339 for(ptrDate = _holidays.first(); ptrDate != 0; ptrDate = _holidays.next() ) {
00340 if(*ptrDate > cmp) {
00341 tmp = _toplevelitem->getStart().secsTo(*ptrDate)/60;
00342 a = screenX( tmp );
00343 p->fillRect( a, y1, w, y2, _hol );
00344 }
00345
00346 }
00347
00348
00349
00350 for(int i=0; i<=end; i++, start = start.addDays(1) ) {
00351
00352 int dayOfWeek = start.dayOfWeek();
00353 tmp = _toplevelitem->getStart().secsTo(start)/60;
00354 a = screenX( tmp );
00355
00356
00357 if(dayOfWeek == 6) {
00358
00359 p->fillRect( a, y1, w, y2, _sat );
00360
00361 if(start.day() == 1) {
00362 p->setPen( penMonth );
00363 p->drawLine( a, y1, a, y2);
00364 }
00365
00366
00367 }
00368
00369
00370 if(dayOfWeek == 7) {
00371
00372 p->fillRect( a, y1, w, y2, _sun );
00373
00374 if(start.day() == 1) {
00375 p->setPen( penMonth );
00376 p->drawLine( a, y1, a, y2);
00377 }
00378
00379
00380 }
00381
00382 if(start.day() == 1)
00383 p->setPen( penMonth );
00384 else {
00385 if(dayOfWeek == 1 || dayOfWeek == 6 || dayOfWeek == 7)
00386 continue;
00387 p->setPen( penDay );
00388 }
00389
00390 p->drawLine( a, y1, a, y2);
00391
00392 }
00393 }
00394
00395
00396
00397 void
00398 xQGanttBarViewPort::recalc()
00399 {
00400
00401 _gItemList.clear();
00402 recalc(_toplevelitem, screenX(0), screenY(0), 0, 0 );
00403 emit recalculated();
00404 }
00405
00406
00407
00408 void
00409 xQGanttBarViewPort::recalc(KGanttItem* item, int xPos, int yPos,
00410 int depth, int nr)
00411 {
00412 int tmpTotalHeight = item->getTotalHeight();
00413 int tmpHeight = item->getHeight();
00414
00415 int dd = (int) (0.25 * (double) tmpHeight * _scaleY);
00416
00417 int _screenW = (int) ((double) item->getWidth() * _scaleX);
00418 int _screenHS = (int) ((double) tmpTotalHeight * _scaleY);
00419 int _screenH = (int) (tmpHeight * _scaleY);
00420 int _textPosY = yPos + (int) (0.7 * (double) tmpHeight * _scaleY);
00421 int _textPosX = xPos + dd + 18;
00422
00423 xQTaskPosition* tpos =
00424 new xQTaskPosition(nr, xPos, yPos, _screenW, _screenH, _screenHS,
00425 _textPosX, _textPosY, depth);
00426
00427 _gItemList.replace(item, tpos );
00428
00429 tpos->_screenHandleX = xPos + dd;
00430 tpos->_screenHandleW = 2 * dd;
00431 tpos->_screenHandleY = yPos + dd;
00432 tpos->_screenHandleH = 2 * dd;
00433
00434
00435
00436
00437 if(item->isOpen()) {
00438
00439 int h = tmpHeight;
00440
00441 for(KGanttItem* subitem = item->getSubItems().first();
00442 subitem != 0;
00443 subitem = item->getSubItems().next() ) {
00444
00445 recalc(subitem,
00446 xPos + (item->getStart().secsTo(subitem->getStart())/60 * _scaleX),
00447 yPos + h * _scaleY, depth + 1, ++nr );
00448
00449 h += subitem->getTotalHeight();
00450
00451 }
00452 }
00453
00454 }
00455
00456
00457
00458 void
00459 xQGanttBarViewPort::drawItem(KGanttItem* item, QPainter* p,
00460 const QRect& rect )
00461 {
00462 xQTaskPosition* tpos = _gItemList[item];
00463
00464 if(!tpos) return;
00465
00466 if(tpos->_screenX > (rect.x() + rect.width())) return;
00467 if((tpos->_screenX + tpos->_screenW) < rect.x()) return;
00468 if(tpos->_screenY > (rect.y() + rect.height()) ) return;
00469 if((tpos->_screenY + tpos->_screenHS) < rect.y()) return;
00470
00471 p->setPen(item->getPen());
00472 p->setBrush(item->getBrush());
00473
00474 int style = item->getStyle();
00475
00476 if(item->getWidth()==0) {
00477
00478 p->drawLine(tpos->_screenX, tpos->_screenY,
00479 tpos->_screenX, tpos->_screenY + tpos->_screenH );
00480
00481 QPointArray a(4);
00482 a.setPoint(0, tpos->_screenX, tpos->_screenY + _margin );
00483 a.setPoint(1, tpos->_screenX - 0.5 * tpos->_screenH + _margin,
00484 tpos->_screenY + 0.5 * tpos->_screenH );
00485 a.setPoint(2, tpos->_screenX, tpos->_screenY + tpos->_screenH - _margin );
00486 a.setPoint(3, tpos->_screenX + 0.5 * tpos->_screenH - _margin,
00487 tpos->_screenY + 0.5 * tpos->_screenH );
00488 p->drawPolygon(a);
00489
00490 }
00491 else {
00492
00493 if(style & KGanttItem::DrawFilled ) {
00494
00495 p->fillRect(tpos->_screenX, tpos->_screenY + _margin,
00496 tpos->_screenW, tpos->_screenHS - 2 * _margin,
00497 item->getBrush() );
00498
00499 }
00500
00501 if(style & KGanttItem::DrawBorder ) {
00502
00503 p->setBrush(NoBrush);
00504 p->drawRect(tpos->_screenX, tpos->_screenY + _margin,
00505 tpos->_screenW, tpos->_screenHS - 2 * _margin );
00506
00507 }
00508
00509 if(item->isOpen()) {
00510
00511
00512 for(KGanttRelation* rel = item->getRelations().first();
00513 rel != 0;
00514 rel = item->getRelations().next() ) {
00515
00516 drawRelation(p, rel);
00517
00518 }
00519
00520
00521 for(KGanttItem* subitem = item->getSubItems().first();
00522 subitem != 0;
00523 subitem = item->getSubItems().next() ) {
00524
00525 drawItem(subitem, p, rect );
00526
00527 }
00528 }
00529
00530 p->setPen(item->getPen());
00531 p->setBrush(item->getBrush());
00532
00533 if(style & KGanttItem::DrawHandle ||
00534 ((style & KGanttItem::DrawHandleWSubitems) && item->getSubItems().count()>0) ) {
00535
00536
00537
00538
00539
00540
00541 if(item->isOpen())
00542 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, openedIcon );
00543 else
00544 p->drawPixmap(tpos->_screenHandleX, tpos->_screenHandleY, closedIcon );
00545
00546 }
00547 }
00548
00549 if(style & KGanttItem::DrawText ) {
00550 p->setPen(item->getTextPen());
00551 p->drawText(tpos->_textPosX, tpos->_textPosY, item->getText() );
00552 }
00553
00554 if(item->isSelected()) {
00555
00556 p->setPen( QPen(QColor(red),1));
00557
00558 p->setBrush(NoBrush);
00559 p->drawRect(tpos->_screenX - 2, tpos->_screenY,
00560 tpos->_screenW + 4, tpos->_screenHS );
00561
00562 p->fillRect(tpos->_screenX, tpos->_screenY, 6, 6,
00563 item->getSelectBrush() );
00564
00565 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
00566 tpos->_screenY, 6, 6,
00567 item->getSelectBrush() );
00568
00569 p->fillRect(tpos->_screenX + tpos->_screenW - 6,
00570 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
00571 item->getSelectBrush() );
00572
00573 p->fillRect(tpos->_screenX,
00574 tpos->_screenY + tpos->_screenHS - 6, 6, 6,
00575 item->getSelectBrush() );
00576 }
00577
00578 }
00579
00580
00581
00582 void
00583 xQGanttBarViewPort::drawRelation(QPainter* p,
00584 KGanttRelation* rel)
00585 {
00586 static int hw = 20;
00587 static int margin = 2;
00588
00589 KGanttItem* from = rel->getFrom();
00590 KGanttItem* to = rel->getTo();
00591
00592 xQTaskPosition* tpos_from = _gItemList[from];
00593 xQTaskPosition* tpos_to = _gItemList[to];
00594
00595 p->setPen(rel->getPen());
00596
00597 QPointArray a(6);
00598
00599 int x,y;
00600 int i=0;
00601
00602
00603 x = tpos_from->_screenX + tpos_from->_screenW + margin;
00604 y = tpos_from->_screenY + tpos_from->_screenH / 2;
00605 a.setPoint(i++, x, y );
00606
00607
00608
00609 x = x + hw;
00610 a.setPoint(i++, x, y);
00611
00612
00613
00614 y = (tpos_from->_screenY + tpos_from->_screenH/2) * 0.8 +
00615 (tpos_to->_screenY + tpos_to->_screenH/2) * 0.2;
00616 a.setPoint(i++, x, y);
00617
00618
00619
00620 x = tpos_to->_screenX - hw;
00621 y = (tpos_from->_screenY + tpos_from->_screenH/2) * 0.2 +
00622 (tpos_to->_screenY + tpos_to->_screenH/2) * 0.8;
00623
00624 a.setPoint(i++, x, y);
00625
00626
00627
00628 y = tpos_to->_screenY + tpos_to->_screenH / 2;
00629 a.setPoint(i++, x, y);
00630
00631
00632
00633 x = tpos_to->_screenX - margin;
00634 a.setPoint(i++, x, y);
00635
00636 p->drawPolyline(a);
00637
00638 p->drawChord( a.point(0).x()-3, a.point(0).y()-3, 6, 6, 0, 5760 );
00639
00640
00641 QPointArray b(3);
00642
00643 b.setPoint(0, x,y);
00644 b.setPoint(1, x -5, y - 5);
00645 b.setPoint(2, x - 5, y + 5);
00646
00647 p->drawPolygon(b);
00648
00649 }
00650
00651
00652
00653 void
00654 xQGanttBarViewPort::drawHeader(QPainter* p, int x1, int y1, int x2, int y2)
00656 {
00657 bool drawDays = false;
00658 int a,e,tmp;
00659
00660 QDate start( _toplevelitem->getStart().addSecs(-_marginX * 60 ).date() );
00661
00662
00663 QDate t(start.year(), start.month()-1, start.day() );
00664
00665 QDateTime itemstart = _toplevelitem->getStart();
00666
00667 int end = (int) (width()/(1440*_scaleX));
00668
00669 if(end < 12) drawDays = true;
00670
00671 end += 30;
00672
00673 p->setPen( QPen(QColor(black)) );
00674
00675 for(int i=0; i<=end; i++, t = t.addDays(1) ) {
00676
00677 tmp = itemstart.secsTo(t)/60;
00678 a = screenX( tmp );
00679
00680 if(t.dayOfWeek() == 1) {
00681
00682 p->fillRect(a, 0, 1440*5*_scaleX, 20, QBrush(QColor(240,240,240)));
00683 p->drawRect(a, 0, 1440*5*_scaleX, 20 );
00684
00685 if(!drawDays)
00686 p->drawText(a+5, 15, QString::number(t.day()) );
00687 }
00688
00689 if(drawDays) {
00690 p->drawText(a+5, 15, t.shortDayName(t.dayOfWeek()) + " " + QString::number(t.day()) );
00691 }
00692
00693 if(t.day()==1) {
00694
00695 e = t.daysInMonth();
00696
00697 p->fillRect(a, 21, 1440*e*_scaleX, 20, QBrush(QColor(240,240,240)));
00698 p->drawRect(a, 21, 1440*e*_scaleX, 20 );
00699
00700 if(a<0) a = 0;
00701 p->drawText(a+5, 36, t.shortMonthName(t.month()) );
00702
00703 }
00704
00705 }
00706 }
00707
00708
00709
00710 void
00711 xQGanttBarViewPort::setMode(int mode)
00713 {
00714 if(_mode == (Mode) mode) {
00715 return;
00716 }
00717
00718 switch(_mode) {
00719
00720 case Select:
00721
00722 setSelect();
00723 break;
00724
00725
00726 case Zoom:
00727
00728 setZoom();
00729 break;
00730
00731
00732 case Move:
00733
00734 setMove();
00735 break;
00736
00737
00738 default:
00739
00740 setCursor(arrowCursor);
00741 setMouseTracking(false);
00742 break;
00743
00744 }
00745
00746 emit modeChanged(_mode);
00747
00748 }
00749
00750
00751
00752 void
00753 xQGanttBarViewPort::setSelect()
00755 {
00756 _mode = Select;
00757 setCursor(arrowCursor);
00758 setMouseTracking(true);
00759 }
00760
00761
00762
00763 void
00764 xQGanttBarViewPort::setZoom()
00766 {
00767 _mode = Zoom;
00768 setCursor( *_cursor_lupe );
00769 setMouseTracking(false);
00770 }
00771
00772
00773
00774 void
00775 xQGanttBarViewPort::setMove()
00777 {
00778 _mode = Move;
00779 setCursor( sizeAllCursor );
00780 setMouseTracking(false);
00781 }
00782
00783
00784 void
00785 xQGanttBarViewPort::zoomIn()
00786 {
00787 zoom(1.2);
00788 }
00789
00790
00791 void
00792 xQGanttBarViewPort::zoomOut()
00793 {
00794 zoom(0.7);
00795 }
00796
00797
00798 void
00799 xQGanttBarViewPort::popup(int index)
00801 {
00802
00803 switch(index) {
00804
00805 case Select:
00806 case Zoom:
00807 case Move:
00808
00809 setMode(index);
00810 break;
00811
00812 case 10:
00813
00814
00815
00816
00817 break;
00818
00819 }
00820
00821
00822 }
00823
00824
00825
00826 void
00827 xQGanttBarViewPort::zoom(double sfactor, int sx, int sy)
00829 {
00830 printf("zoom %f, (%d,%d) \n", sfactor, sx, sy );
00831
00832 int wx = worldX(sx);
00833 int wy = worldY(sy);
00834
00835 _scaleX *= sfactor;
00836
00837 printf("recalc ... \n");
00838
00839 recalc();
00840 adjustSize();
00841
00842 _parent->center(screenX(wx), screenY(wy) );
00843
00844 QWidget::update();
00845
00846 printf("zoom ok.\n");
00847
00848 }
00849
00850
00851
00852 void
00853 xQGanttBarViewPort::zoom(double sfactor)
00854 {
00855 printf("zoom %f \n", sfactor );
00856
00857 int x = (int) (_parent->visibleWidth()/2 + 0.5);
00858 int y = (int) (_parent->visibleHeight()/2 + 0.5);
00859
00860 printf("dx/2 = %d, dy/2 = %d \n", x,y);
00861
00862 zoom(sfactor, x + _parent->contentsX(), y + _parent->contentsY() );
00863
00864 }
00865
00866
00867
00868 void
00869 xQGanttBarViewPort::zoomAll()
00870 {
00871 #ifdef _DEBUG_
00872 printf("zoom all. scaleX = %f\n", _scaleX );
00873 #endif
00874
00875 _scaleX = ((double) _parent->visibleWidth()*60)/
00876 ((double) (_toplevelitem->getStart().secsTo(_toplevelitem->getEnd()) + _marginX*120));
00877
00878 recalc();
00879 adjustSize();
00880
00881 }
00882
00883
00884
00885 void
00886 xQGanttBarViewPort::addHoliday(int y, int m, int d)
00887 {
00888 QDate* date = new QDate(y,m,d);
00889
00890 QDate* ptrDate;
00891 int i=0;
00892
00893 for(ptrDate = _holidays.first();
00894 ptrDate != 0;
00895 ptrDate = _holidays.next() ) {
00896
00897 if(*ptrDate > *date)
00898 break;
00899
00900 i++;
00901
00902 }
00903
00904 _holidays.insert(i,date);
00905
00906 }
00907
00908
00909
00910 xQGanttBarViewPort::Position
00911 xQGanttBarViewPort::check(KGanttItem** founditem, int x, int y)
00912 {
00913 QPtrDictIterator<xQTaskPosition> it(_gItemList);
00914
00915 static int ty, ty2, tx, tx2, hx, hx2, hy, hy2;
00916 bool increased;
00917
00918 while(it.current()) {
00919
00920 ty = it.current()->_screenY;
00921 ty2 = ty + it.current()->_screenH;
00922 tx = it.current()->_screenX;
00923 tx2 = tx + it.current()->_screenW;
00924
00925 hx = it.current()->_screenHandleX;
00926 hx2 = hx + it.current()->_screenHandleW;
00927 hy = it.current()->_screenHandleY;
00928 hy2 = hy + it.current()->_screenHandleH;
00929
00930 increased = false;
00931
00932 if(tx2-tx<12) {
00933 tx -= 12;
00934 tx2 += 12;
00935 increased = true;
00936 }
00937
00938 if(x>tx && x < tx2) {
00939 if(y > ty && y < ty2) {
00940
00941 *founditem = (KGanttItem*) it.currentKey();
00942
00943 if(!increased)
00944 if(x > hx && x < hx2 &&
00945 y > hy && y < hy2 )
00946 return Handle;
00947
00948 if(x < (tx + 5))
00949 return West;
00950
00951 if(x > (tx2 - 5))
00952 return East;
00953
00954 return Center;
00955 }
00956
00957 }
00958
00959 ++it;
00960
00961 }
00962
00963 return Outside;
00964
00965 }
00966
00967
00968
00969 void
00970 xQGanttBarViewPort::unselectAll()
00971 {
00972 selectItem(_toplevelitem, false);
00973 QWidget::update();
00974 }
00975
00976
00977
00978 void
00979 xQGanttBarViewPort::selectAll()
00980 {
00981 selectItem(_toplevelitem, true);
00982 QWidget::update();
00983 }
00984
00985
00986
00987 void
00988 xQGanttBarViewPort::selectItem(KGanttItem* item, bool f)
00989 {
00990 item->select(f);
00991
00992 for(KGanttItem* subitem = item->getSubItems().first();
00993 subitem != 0;
00994 subitem = item->getSubItems().next() ) {
00995 selectItem(subitem, f);
00996 }
00997
00998 }
00999
01000
01001
01002 void
01003 xQGanttBarViewPort::deleteSelectedItems()
01004 {
01005 #ifdef _DEBUG_
01006 printf("-> xQGanttBarViewPort::deleteSelectedItems()\n");
01007 #endif
01008
01009 QPtrList<KGanttItem> list;
01010 observeList(&list);
01011
01012 getSelectedItems(_toplevelitem,list);
01013
01014 for(KGanttItem* subitem = list.first();
01015 subitem != 0;
01016 subitem =list.next() ) {
01017 #ifdef _DEBUG_
01018 printf(" : %s \n", subitem->getText().latin1() );
01019 #endif
01020 connect(subitem, SIGNAL(destroyed(KGanttItem*)),
01021 this, SLOT(itemDestroyed(KGanttItem*)));
01022 }
01023
01024 list.remove(_toplevelitem);
01025
01026 while(list.count()>0) {
01027 KGanttItem* item = list.getFirst();
01028 delete item;
01029 }
01030
01031 #ifdef _DEBUG_
01032 printf("<- xQGanttBarViewPort::deleteSelectedItems()\n");
01033 #endif
01034 }
01035
01036
01037
01038 void
01039 xQGanttBarViewPort::observeList(QPtrList<KGanttItem> *list)
01040 {
01041 _observedList = list;
01042 }
01043
01044
01045
01046 void
01047 xQGanttBarViewPort::itemDestroyed(KGanttItem* item)
01048 {
01049 _observedList->remove(item);
01050 }
01051
01052
01053
01054 void
01055 xQGanttBarViewPort::getSelectedItems (KGanttItem* item,
01056 QPtrList<KGanttItem>& list)
01057 {
01058 if(item->isSelected()) list.append(item);
01059
01060 for(KGanttItem* subitem = item->getSubItems().first();
01061 subitem != 0;
01062 subitem = item->getSubItems().next() ) {
01063
01064 getSelectedItems(subitem,list);
01065
01066 }
01067
01068 }
01069
01070
01071 void
01072 xQGanttBarViewPort::insertIntoSelectedItem()
01073 {
01074 QPtrList<KGanttItem> list;
01075
01076 getSelectedItems(_toplevelitem,list);
01077
01078 for(KGanttItem* subitem = list.first();
01079 subitem != 0;
01080 subitem =list.next() ) {
01081 #ifdef _DEBUG_
01082 printf(" : %s \n", subitem->getText().latin1() );
01083 #endif
01084 new KGanttItem(subitem, subitem->getText() + "_subitem",
01085 subitem->getStart(), subitem->getEnd());
01086 }
01087
01088 }
01089
01090
01091
01092 void
01093 xQGanttBarViewPort::textEdited()
01094 {
01095 if(_currentItem) {
01096 _currentItem->setText(_itemTextEdit->text());
01097 setFocus();
01098 _itemTextEdit->hide();
01099 }
01100 }
01101 #include "xQGanttBarViewPort.moc"