9 #include "xQGanttBarViewPort.h"
10 #include "xQGanttBarView.h"
17 static int _currentMButton;
18 static bool _Mousemoved;
19 static bool _selectItem;
23 static bool _changeEnd, _changeStart;
24 static int oldw = -1, oldx = -1;
26 TQDateTime _tmpStartDateTime, _tmpEndDateTime;
30 xQGanttBarViewPort::mousePressEvent(TQMouseEvent* e)
33 _currentMButton = e->button();
36 _startPoint->setX( e->x() );
37 _startPoint->setY( e->y() );
39 _endPoint->setX( e->x() );
40 _endPoint->setY( e->y() );
43 _itemTextEdit->hide();
46 if(e->button() == TQt::RightButton && e->state() == ControlButton ) {
47 _menu->popup(e->globalPos());
56 Position pos = check(&_currentItem, e->x(), e->y());
67 if(e->button() == TQt::MidButton && _mode == Select) {
69 xTQTaskPosition* tp = _gItemList.find(_currentItem);
72 TQRect rect = p.boundingRect(tp->_textPosX,
74 tp->_screenH, AlignLeft, _currentItem->
getText() );
76 _itemTextEdit->setText(_currentItem->
getText());
77 _itemTextEdit->move(tp->_textPosX, tp->_screenY + _margin + 1);
78 _itemTextEdit->setFixedWidth(rect.width()+40);
79 _itemTextEdit->setFixedHeight(tp->_screenH - 2 * _margin - 2);
80 _itemTextEdit->setFocus();
84 _itemTextEdit->setReadOnly(!_currentItem->
isEditable());
86 _itemTextEdit->show();
94 if(e->button() == TQt::LeftButton && _mode == Select) {
102 _currentItem->
open( !_currentItem->
isOpen() );
110 if(e->state() == ShiftButton) {
112 TQString tmp; tmp.sprintf(
"%s\n", _currentItem->
getText().latin1() );
114 tmp += _currentItem->
getStart().toString();
116 tmp += _currentItem->
getEnd().toString();
118 _itemInfo->setText( tmp );
119 _itemInfo->adjustSize();
121 _itemInfo->move(e->x() + 25, _gItemList.find(_currentItem)->_screenY - 50 );
133 _changeStart =
false;
157 xQGanttBarViewPort::mouseReleaseEvent(TQMouseEvent* e)
163 if(_Mousemoved ==
true) {
167 if(_changeStart ==
true || _changeEnd ==
true) {
169 if(_changeStart ==
true) {
170 _currentItem->
setStart( _tmpStartDateTime );
172 if(_changeEnd ==
true) {
173 _currentItem->
setEnd( _tmpEndDateTime );
176 oldx = -1; oldw = -1;
184 if(_currentItem && _selectItem) {
187 if(e->state() & ControlButton) {
193 _currentItem->
select( !state );
203 _changeStart =
false;
213 if(e->button() == TQt::LeftButton)
214 zoom(1.4, e->x(), e->y() );
217 if(e->button() == TQt::RightButton)
218 zoom(0.7, e->x(), e->y() );
221 if(e->button() == TQt::MidButton)
227 if(_currentMButton == TQt::LeftButton) {
232 p.setRasterOp(XorROP);
235 p.drawRect(_startPoint->x(),
237 _endPoint->x()-_startPoint->x(),
238 _endPoint->y() - _startPoint->y());
240 double x1 = _startPoint->x();
241 double y1 = _startPoint->y();
243 double x2 = _endPoint->x();
244 double y2 = _endPoint->y();
246 double sys_width = fabs(x2 - x1);
248 double mass = (_parent->visibleWidth()/ sys_width);
250 zoom(mass, (
int) (x1+(x2-x1)/2), (
int) (y1+(y2-y1)/2) );
272 xQGanttBarViewPort::mouseMoveEvent(TQMouseEvent* e)
274 if(fabs((
float)(_startPoint->x() - e->x())) < 2 &&
275 fabs((
float)(_startPoint->y() - e->y())) < 2 )
278 static TQPen _dashPen(TQColor(255,0,0),DashLine);
279 static TQPen _solidPen(TQColor(200,200,200));
287 if(_currentMButton == TQt::LeftButton && _currentItem) {
290 p.setRasterOp(XorROP);
293 p.setPen( _dashPen );
296 stmp.sprintf(
"%s\n", _currentItem->
getText().latin1() );
298 int pixeldiff = e->x() - _startPoint->x();
299 _timediff = (int) ((
double) pixeldiff / _scaleX + 0.5 );
301 xTQTaskPosition* tpos = _gItemList[_currentItem];
303 int x = tpos->_screenX;
int w = tpos->_screenW;
305 if(_changeStart && _changeEnd) {
306 double tmp = (double) _timediff/(
double) _snapgrid;
307 _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid;
308 stmp += _currentItem->
getStart().addSecs(_timediff*60).toString();
310 stmp += _currentItem->
getEnd().addSecs(_timediff*60).toString();
311 x += (int) (_timediff * _scaleX);
313 _tmpStartDateTime = _currentItem->
getStart().addSecs(_timediff*60);
314 _tmpEndDateTime = _currentItem->
getEnd().addSecs(_timediff*60);
321 TQDateTime movedStart( _currentItem->
getStart().addSecs(_timediff*60) );
323 _tmpStartDateTime.setDate( movedStart.date() );
324 _tmpStartDateTime.setTime(TQTime(0,0,0,0));
326 double diff = _tmpStartDateTime.secsTo(movedStart)/60;
328 double tmp = diff/(double) _snapgrid;
329 _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid;
331 _tmpStartDateTime = _tmpStartDateTime.addSecs(_timediff*60);
332 _timediff = _currentItem->
getStart().secsTo(_tmpStartDateTime)/60;
334 stmp += _tmpStartDateTime.toString().latin1();
336 stmp += _currentItem->
getEnd().toString();
338 x += (int) (_timediff * _scaleX);
339 w -= (int) (_timediff * _scaleX);
344 TQDateTime movedEnd( _currentItem->
getEnd().addSecs(_timediff*60) );
346 _tmpEndDateTime.setDate( movedEnd.date() );
347 _tmpEndDateTime.setTime(TQTime(0,0,0,0));
349 double diff = _tmpEndDateTime.secsTo(movedEnd)/60;
351 double tmp = diff/(double) _snapgrid;
352 _timediff = ((int) (tmp + sgn(tmp) * 0.5)) * _snapgrid;
354 _tmpEndDateTime = _tmpEndDateTime.addSecs(_timediff*60);
355 _timediff = _currentItem->
getEnd().secsTo(_tmpEndDateTime)/60;
357 stmp += _currentItem->
getStart().toString();
359 stmp += _tmpEndDateTime.toString().latin1();
361 w += (int) (_timediff * _scaleX);
367 _itemInfo->setText( stmp );
368 _itemInfo->adjustSize();
369 _itemInfo->move(e->x() + 25, _gItemList.find(_currentItem)->_screenY - 50);
373 p.fillRect(oldx, _gItemList.find(_currentItem)->_screenY,
374 oldw, _gItemList.find(_currentItem)->_screenH,
375 TQBrush(TQColor(50,50,50), Dense4Pattern));
376 p.drawRect(oldx, _gItemList.find(_currentItem)->_screenY,
377 oldw, _gItemList.find(_currentItem)->_screenH);
381 p.drawLine(oldx, 0, oldx, height());
384 p.drawLine(oldx + oldw, 0, oldx + oldw, height());
389 p.fillRect(x, _gItemList.find(_currentItem)->_screenY,
390 w, _gItemList.find(_currentItem)->_screenH,
391 TQBrush(TQColor(50,50,50), Dense4Pattern) );
392 p.drawRect(x, _gItemList.find(_currentItem)->_screenY,
393 w, _gItemList.find(_currentItem)->_screenH);
397 p.drawLine(x, 0, x, height());
401 p.drawLine(x + w, 0, x + w, height());
408 static Position _pos = Outside;
412 Position pos = check(&item, e->x(), e->y());
418 if(pos == West || pos == East) {
419 setCursor( splitHCursor );
422 if(pos == North || pos == South) {
423 setCursor( splitVCursor );
427 setCursor( upArrowCursor);
431 setCursor(pointingHandCursor);
435 setCursor(arrowCursor);
445 if(_currentMButton == TQt::LeftButton) {
447 static TQString strpos;
451 int s = worldX(_startPoint->x());
452 TQDateTime d1 = _toplevelitem->
getStart().addSecs(s*60);
455 TQDateTime d2 = _toplevelitem->
getStart().addSecs(s*60);
457 strpos += d1.date().toString();
459 strpos += d2.date().toString();
461 emit message(strpos);
467 p.setRasterOp(XorROP);
471 p.drawRect(_startPoint->x(),
473 _endPoint->x()-_startPoint->x(),
474 _endPoint->y() - _startPoint->y());
476 TQBrush _selectedbrush( TQColor(50,50,50), Dense4Pattern );
478 p.fillRect( _startPoint->x(), _startPoint->y(),
479 _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y(),
482 _endPoint->setX( e->x() );
483 _endPoint->setY( e->y() );
486 p.drawRect(_startPoint->x(), _startPoint->y(),
487 _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y());
489 p.fillRect( _startPoint->x(), _startPoint->y(),
490 _endPoint->x()-_startPoint->x(), _endPoint->y() - _startPoint->y(),
499 emit scroll(_startPoint->x() - e->x(), _startPoint->y() - e->y() );
512 xQGanttBarViewPort::keyPressEvent(TQKeyEvent* e)
515 printf(
"xQGanttBarViewPort::keyPressEvent() key = %d \n", e->key() );
519 if(e->state() == ControlButton)
556 deleteSelectedItems();
561 insertIntoSelectedItem();
566 emit scroll(0, dx*15);
571 emit scroll(0,-dx*15);
580 xQGanttBarViewPort::paintEvent(TQPaintEvent * e)
583 update(e->rect().left(), e->rect().top(),
584 e->rect().right(), e->rect().bottom() );
TQDateTime getStart()
Get date of starting.
void setEnd(const TQDateTime &end)
Set time/date of end.
void select(bool f)
Select/unselect item.
bool isOpen()
Returns true if item is open (subitems has to be drawn)
TQDateTime getEnd()
Get date of ending.
bool isEditable()
Returns if item is editable.
TQString getText()
Get text.
void setStart(const TQDateTime &start)
Set time/date of start.
void open(bool f)
Open / Close item.
bool isSelected()
Returns true if item is selected.
void update(int x1, int y1, int x2, int y2)
Update widget.