Exemple #1
0
void k9MenuEditor::contentsMouseMoveEvent(QMouseEvent* e) {
    updateCursor(e);
    if ( moving && (e->state() & Qt::LeftButton ==Qt::LeftButton) ) {
        if (moving->rtti() !=QCanvasItem::Rtti_Text || moving==m_menu->getText()) {
            QPoint p = inverseWorldMatrix().map(e->pos());
            int offsetX=p.x() - moving_start.x();
            int offsetY=p.y() - moving_start.y();
            moving_start = p;
            if (moving->rtti()==1000 || moving->rtti() == QCanvasItem::Rtti_Rectangle) {
                for (k9MenuButton *b=m_selection.first();b;b=m_selection.next()) {
                    k9CanvasSprite*spr=b->getSprite();
                    spr->moveBy(offsetX,offsetY);
                    spr->update();
                }

            } else
                moving->moveBy(offsetX,offsetY);

            if (moving->rtti() >2001 && moving->rtti() <2010) {
                k9CanvasSelectionRedim *ssr=(k9CanvasSelectionRedim*)moving;
                ssr->updateSelection();
            } else if (moving->rtti() != QCanvasItem::Rtti_Text ){
                //if selection not resized, move the selection
                m_canvasSelection->moveBy(offsetX,offsetY);
                m_canvasSelection->update();
            }

            if (moving==m_menu->getText())
                emit m_menu->updateTextPos(QPoint(moving->x(),moving->y()));
            canvas()->update();
        }
    } else if ((e->state() & Qt::LeftButton) ==Qt::LeftButton ) {
        m_canvasSelection->hide();
        canvas()->update();
        QPoint p = inverseWorldMatrix().map(e->pos());
        int offsetX=p.x() - moving_start.x();
        int offsetY=p.y() - moving_start.y();
        m_canvasSelection->setSize(offsetX,offsetY);
        m_canvasSelection->show();
        canvas()->update();
        clearSelection();
        QCanvasItemList l=canvas()->collisions(m_canvasSelection->getRect());
        for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
            QCanvasItem *item = *it;
            if (item->rtti()==1000) {
                addSelection(item);
            }
        }
    }
}
Exemple #2
0
void k9MenuEditor::updateCursor(QMouseEvent *e) {
   QPoint p = inverseWorldMatrix().map(e->pos());
   QCanvasItemList l=canvas()->collisions(p);
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
       QCanvasItem *item=*it; 
       switch (item->rtti()) {
            case QCanvasItem::Rtti_Rectangle :
                setCursor(KCursor::sizeAllCursor());
                return;
            case 2002 :
            case 2008:
                setCursor(KCursor::sizeFDiagCursor());
                return;
            case 2003:
            case 2007:
                setCursor(KCursor::sizeVerCursor());
                return;
            case 2004:
            case 2006:
                setCursor(KCursor::sizeBDiagCursor());
                return;
            case 2005:
            case 2009:
                setCursor(KCursor::sizeHorCursor());
                return;
            default:
                setCursor(KCursor::arrowCursor());
        }
    }
    setCursor(KCursor::arrowCursor());
}
Exemple #3
0
QRect DigitView::convertZoom(QRect r, bool to)
{
  qreal xTL, yTL, xBR, yBR;
  if (to)
  {
    worldMatrix().map((double) r.left(), (double) r.top(), &xTL, &yTL);
    worldMatrix().map((double) r.right(), (double) r.bottom(), &xBR, &yBR);
  }
  else
  {
    inverseWorldMatrix().map((double) r.left(), (double) r.top(), &xTL, &yTL);
    inverseWorldMatrix().map((double) r.right(), (double) r.bottom(), &xBR, &yBR);
  }

  return QRect(
    QPoint((int) (xTL + 0.5), (int) (yTL + 0.5)),
    QPoint((int) (xBR + 0.5), (int) (yBR + 0.5)));
}
Exemple #4
0
QPoint DigitView::convertZoom(QPoint p, bool to)
{
  qreal x, y;
  if (to)
    worldMatrix().map((double) p.x(), (double) p.y(), &x, &y);
  else
    inverseWorldMatrix().map((double) p.x(), (double) p.y(), &x, &y);

  return QPoint((int) (x + 0.5), (int) (y + 0.5));
}
Exemple #5
0
void FigureEditor::contentsMouseMoveEvent(QMouseEvent* e)
{
    if ( moving ) {
	QPoint p = inverseWorldMatrix().map(e->pos());
	moving->moveBy(p.x() - moving_start.x(),
		       p.y() - moving_start.y()); // 移動相對位置
	moving_start = p; // 重新設定起始位置
	canvas()->update(); // 更新canvas畫面
    }
}
void CanvasView::handleMouseClickEvent(QMouseEvent* event)
{
    QPoint p = inverseWorldMatrix().map(event->pos());
    QtCanvasItemList l = canvas()->collisions(p);
    moving = 0;
    if (!l.isEmpty())
        moving = l.first();
    moving_start = p;
    emit itemClicked(moving);
}
void CanvasView::contentsMouseMoveEvent(QMouseEvent* event)
{
    if (moving) {
	QPoint p = inverseWorldMatrix().map(event->pos());
	moving->moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
	moving_start = p;
	canvas()->update();
        emit itemMoved(moving);
    }
}
void CNavigationDiagramView::contentsMousePressEvent(QMouseEvent * e){
	QWMatrix matrix = inverseWorldMatrix();
	int xPos = matrix.m11() * e->pos().x() + matrix.m12() * e->pos().y();
	int yPos = matrix.m21() * e->pos().x() + matrix.m22() * e->pos().y();
	QPoint p(xPos, yPos);

	QCanvasItemList items = canvas()->collisions(p);
	if (items.empty()){
		setActiveItem(0);
	}else{
		setActiveItem(*items.begin());
	}
	m_qLastPos = e->pos();
}
Exemple #9
0
void FigureEditor::contentsMousePressEvent(QMouseEvent* e)
{
    QPoint p = inverseWorldMatrix().map(e->pos());
    QCanvasItemList l=canvas()->collisions(p);
    // 注意,it是指到容器的指標,而(*it)是放在容器內的指標
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
	if ( (*it)->rtti() == imageRTTI ) {
	    ImageItem *item= (ImageItem*)(*it); // 轉換回來ImageItem的指標
	    if ( !item->hit( p ) )
		 continue;
	}
	moving = *it; // 設定要移動的物件
	moving_start = p; // 設定起始位置
	return;
    }
    moving = 0; // 沒有要移動的物件
}
Exemple #10
0
void SchemaEditor::contentsMouseReleaseEvent(QMouseEvent *mouseEvent)
{
  QPoint p = inverseWorldMatrix().map(mouseEvent->pos());
  GearGui *gearGui = _schemaGui->testForGearCollision(p);
  PlugBox *selectedPlugBox=NULL;

  if (gearGui!=NULL)
  {
    //send mouse events
    gearGui->mouseEvent(p, mouseEvent->stateAfter());
  }
  switch (_state)
  {
  case IDLE:
    break;
  case MOVING_GEAR:
    _state=IDLE;
    break;
  case CONNECTING:
  
    if (gearGui!=NULL)
    {
      if ( ((selectedPlugBox = gearGui->plugHitted(p)) != 0))             
        if (_activeConnection->sourcePlugBox()->canConnectWith(selectedPlugBox))
          _schemaGui->connect(_activeConnection->sourcePlugBox(), selectedPlugBox);
    }

    //delete our temporary connectionItem
    delete _activeConnection;
    
    canvas()->update();
    
    _state=IDLE;
    break;
  case DRAGGING_SELECT_BOX:
    delete _selectBox;
    _selectBox=NULL;
    _state=IDLE;
    _schemaGui->update();
    break;

  }
}
Exemple #11
0
void ReportCanvas::contentsMouseMoveEvent( QMouseEvent* e ) {
	QPoint p = inverseWorldMatrix().map( e->pos() );

	/*    QCanvasItemList l=canvas()->collisions(p);
	  setCursor(QCursor(Qt::ArrowCursor));
	    unsetCursor();
	    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
	    { 
		if ((*it)->rtti() > 2000)
		{
		    CanvasReportItem *item = (CanvasReportItem*)(*it);
		    if (item->bottomRightResizableRect().contains(e->pos()))
			setCursor(QCursor(Qt::SizeFDiagCursor));
		}
	    }*/

	if ( moving ) {
		moving->moveBy( p.x() - moving_start.x(),
		                p.y() - moving_start.y() );
		/*	attempt to prevent item collisions
		        QCanvasItemList l=canvas()->collisions(moving->rect());
			if (l.count() > 2)
			{
			    moving->moveBy(-(p.x() - moving_start.x()),
					   -(p.y() - moving_start.y()));
			    canvas()->update();
			    return;
			}*/
		moving_start = p;
		moving->updateGeomProps();
		canvas() ->update();
	}
	if ( resizing ) {
		QCanvasRectangle * r = ( QCanvasRectangle * ) resizing;
		int w = r->width() + p.x() - moving_start.x();
		int h = r->height() + p.y() - moving_start.y();
		if ( ( w > 10 ) && ( h > 10 ) )
			r->setSize( w, h );
		moving_start = p;
		resizing->updateGeomProps();
		canvas() ->update();
	}
}
Exemple #12
0
void SchemaEditor::contentsMouseDoubleClickEvent(QMouseEvent *mouseEvent)
{    
  ConnectionItem *connectionItem;
  GearGui *gearGui;

  QPoint p = inverseWorldMatrix().map(mouseEvent->pos());
  gearGui = _schemaGui->testForGearCollision(p);

  switch (_state)
  {
  case IDLE:
  {  
    _schemaGui->unHilightAllConnections();
    connectionItem = _schemaGui->testForConnectionCollision(p);

    if (connectionItem!=NULL)
      _schemaGui->disconnect(connectionItem->sourcePlugBox(), connectionItem->destPlugBox());      
    
    //handle double-click on metagear
    if (gearGui!=NULL && (gearGui->gear()->kind() == Gear::METAGEAR))
    {
      QDialog metaGearEditorDialog(this);  
      Q3VBoxLayout layout(&metaGearEditorDialog, 1);
      metaGearEditorDialog.setCaption(gearGui->gear()->name().c_str());
      metaGearEditorDialog.resize(640,480);
      MetaGearEditor metaGearEditor(&metaGearEditorDialog, (MetaGear*)gearGui->gear(), _engine);
      layout.addWidget(&metaGearEditor);
      metaGearEditorDialog.exec();
      
      //todo : temp...
      ((MetaGear*)(gearGui->gear()))->createPlugs();
    }

    if (gearGui!=NULL && gearGui->titleBarHitted(p))
        selectOneGear(gearGui);
    
    break;
  }  
      
  default:
    break;
  }
}
Exemple #13
0
void SchemaEditor::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
{    
  QPoint p = inverseWorldMatrix().map(contextMenuEvent->pos());
  PlugBox *selectedPlugBox;

  GearGui *gearGui = _schemaGui->testForGearCollision(p);

  if (gearGui!=NULL)
  {
    _contextGear = gearGui;
    if(((selectedPlugBox = gearGui->plugHitted(p)) != 0))
    {
      if(selectedPlugBox->plug()->exposed())
      {
        _plugContextMenu->setItemVisible(EXPOSE, false);
        _plugContextMenu->setItemVisible(UNEXPOSE, true);
      } else
      {
        _plugContextMenu->setItemVisible(EXPOSE, true);
        _plugContextMenu->setItemVisible(UNEXPOSE, false);
      }
      _contextPlug = selectedPlugBox;
      _plugContextMenu->popup(QCursor::pos());
      
    } else
    {
      if (_contextGear->gear()->kind() == Gear::METAGEAR)
      {
        _metaGearContextMenu->popup(QCursor::pos());
      }
      else
        _gearContextMenu->popup(QCursor::pos());
    }
  } else
  {
    _contextGear = NULL; 
    _contextMenuPos = p;
    _contextMenu->popup(QCursor::pos());
  }


  Q3CanvasView::contextMenuEvent(contextMenuEvent);
}
Exemple #14
0
void SchemaEditor::zoom(float factor)
{
  _zoom+=factor;
  if (_zoom < 0.2f)
    _zoom = 0.2f;

  int oldcenterx = visibleWidth()/2;
  int oldcentery = visibleHeight()/2;
  int x, y;
  viewportToContents(oldcenterx, oldcentery, x, y);
  inverseWorldMatrix().map(x, y, &x, &y);
	
  QMatrix wm;
  wm.scale(_zoom, _zoom);
  setWorldMatrix(wm);

  
  //worldMatrix().map(x, y, &x, &y);
  //setContentsPos(x-oldcenterx, y-oldcentery);

}
Exemple #15
0
void k9MenuEditor::contentsMousePressEvent(QMouseEvent* e) {
    QPoint p = inverseWorldMatrix().map(e->pos());
    moving_start = p;
    QCanvasItemList l=canvas()->collisions(p);
    moving=0;
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
       QCanvasItem *item=*it; 
       if (item->rtti()==QCanvasItem::Rtti_Rectangle)
        moving = item;
       if (item->rtti()>2000) {
            moving=item;
            return;
        }
    }
    if (moving)
        return;
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
//        if ((*it)->rtti()==QCanvasItem::Rtti_Rectangle)
//            continue;
        moving = *it;
        if (moving->rtti()==1000) {
            if (e->state() & QMouseEvent::ControlButton)
                addSelection(moving);
            else {
                if (!isSelected(moving)) {
                    clearSelection();
                    addSelection(moving);
                }
            }
            m_canvasSelection->setPosition(p);
            m_canvasSelection->drawSelection();
        } else if (moving->rtti() <1001 )
            clearSelection();
        emit itemSelected();
        return;
    }
    m_canvasSelection->setPosition(p);
    clearSelection();
    emit itemSelected();
}
void CNavigationDiagramView::contentsMouseMoveEvent(QMouseEvent * e){
	QWMatrix matrix = inverseWorldMatrix();
	double x = matrix.m11() * e->x() + matrix.m12() * e->y();
	double y = matrix.m21() * e->x() + matrix.m22() * e->y();

	if (! canvas()->onCanvas(x, y)) return;

	if (m_pqActiveItem){
		

		double dxPosLokal = e->pos().x() - m_qLastPos.x();
		double dyPosLokal = e->pos().y() - m_qLastPos.y();

		double dxPos = matrix.m11() * dxPosLokal + matrix.m12() * dyPosLokal;
		double dyPos = matrix.m21() * dxPosLokal + matrix.m22() * dyPosLokal;

		//int newIntX = (int) (x() + dxPos);
		//int newIntY = (int) (y() + dyPos);
		//if (! canvas()->onCanvas(newIntX, newIntY)) return;

		m_pqActiveItem->moveBy(dxPos, dyPos);

		m_qLastPos = e->pos();
		canvas()->update();

		if (m_pqActiveItem->rtti() == CFromDiagramMarker::RTTI){
			CFromDiagramMarker *fromMarker = (CFromDiagramMarker*) m_pqActiveItem;
			float fXPos = (float) fromMarker->GetCenterX();
			float fYPos = (float) fromMarker->GetCenterY();
			CNavigationProjectController::Instance()->SetNewFromPosition(fXPos, fYPos);
		}else if (m_pqActiveItem->rtti() == CAtDiagramMarker::RTTI){
			CAtDiagramMarker *atMarker = (CAtDiagramMarker*) m_pqActiveItem;
			float fXPos = (float) atMarker->GetCenterX();
			float fYPos = (float) atMarker->GetCenterY();
			CNavigationProjectController::Instance()->SetNewAtPosition(fXPos, fYPos);
		}
	}
}
Exemple #17
0
void SchemaEditor::contentsMousePressEvent(QMouseEvent* mouseEvent)
{
  QPoint p = inverseWorldMatrix().map(mouseEvent->pos());
  GearGui *gearGui = _schemaGui->testForGearCollision(p);
  PlugBox *selectedPlugBox;


  if(_state==MOVING_GEAR)
  {
    _state=IDLE;
    return;
  }
  
  if (gearGui!=NULL)
  {    
    //send mouse events
    gearGui->mouseEvent(p, mouseEvent->button());

		//signal
		emit gearSelected(gearGui);

    if (gearGui->titleBarHitted(p))
    {
      // select only the clicked gear
      if(mouseEvent->state()&Qt::ControlModifier || mouseEvent->state()&Qt::ShiftModifier)
        toggleGearSelection(gearGui);
      else if(!gearGui->isSelected())
        selectOneGear(gearGui);
    }

    //on left button we...
    if (mouseEvent->button() == Qt::LeftButton)
    {      
      //plug collision to start connections ?
      if ( ((selectedPlugBox = gearGui->plugHitted(p)) != NULL))
      {        
        _state=CONNECTING;
        _activeConnection = new ConnectionItem(canvas());
        _activeConnection->setSourcePlugBox(selectedPlugBox);
        _activeConnection->show();        

      } else if (gearGui->titleBarHitted(p))
      {
        // start moving it (but only if it has not been unselected, in
        // which case it is weird to move remaining gears.. (well, in my opinion JK)
        if(gearGui->isSelected())
        {
          _state = MOVING_GEAR;            
          _movingGearStartPos = p;            
        }
      }
    }
  } 
  else if (mouseEvent->button() == Qt::LeftButton)
  {
    delete _selectBox;
    _selectBox=NULL;
    unselectAllGears();
    _state = DRAGGING_SELECT_BOX;
    _selectBoxStartPos = p;
  }

}
Exemple #18
0
void SchemaEditor::contentsMouseMoveEvent(QMouseEvent *mouseEvent)
{
  GearGui *gearGui;
  ConnectionItem *connectionItem;
  PlugBox *selectedPlugBox;

  QPoint p = inverseWorldMatrix().map(mouseEvent->pos());
  
  switch (_state)
  {
  case IDLE:

    //connection hilighting
    _schemaGui->unHilightAllConnections();
    connectionItem = _schemaGui->testForConnectionCollision(p);
    if (connectionItem!=NULL)
    {
      connectionItem->hiLight(true);
    } 

    //connection plugboxes hilighting
    gearGui = _schemaGui->testForGearCollision(p);   
    if (gearGui!=NULL)
    {
      gearGui->mouseEvent(p, mouseEvent->state());
      gearGui->performPlugHighligthing(p);
    }

    break;

  case MOVING_GEAR:
    moveSelectedGearsBy(p.x() -_movingGearStartPos.x(), p.y() - _movingGearStartPos.y());
    _movingGearStartPos = p;        
    break;

  case CONNECTING:    
    _activeConnection->setConnectionLineEndPoint(p);

    gearGui = _schemaGui->testForGearCollision(p);   

    if (gearGui!=NULL)
    {
      if ( ((selectedPlugBox = gearGui->plugHitted(p)) != 0))
      {      
        if (_activeConnection->sourcePlugBox()->canConnectWith(selectedPlugBox))
            gearGui->performPlugHighligthing(selectedPlugBox);
        else
            gearGui->unHilightAllPlugBoxes();
      }
      else
        gearGui->unHilightAllPlugBoxes();
    }

    break;           

  case DRAGGING_SELECT_BOX:
    //delete _selectBox;
    if(!_selectBox)
      _selectBox = new Q3CanvasRectangle(QRect(_selectBoxStartPos, p),_schemaGui);
    else 
      _selectBox->setSize(p.x()-_selectBoxStartPos.x(),p.y()-_selectBoxStartPos.y());
    _selectBox->setSelected(!_selectBox->isSelected());
    _selectBox->show();
    //_schemaGui->setUpdatePeriod(100);
    _schemaGui->update();
    selectGearsInRectangle(_selectBox->boundingRect());
    break;

  }
}
Exemple #19
0
void ReportCanvas::contentsMousePressEvent( QMouseEvent* e ) {
	QPoint p = inverseWorldMatrix().QWMatrix::map( e->pos() );
	QCanvasItemList l = canvas() ->collisions( p );
	//    QCanvasItemList::Iterator it=l.begin();
	//    QString str = QString("%1").arg((*it)->rtti());
	switch ( e->button() ) {
	case MidButton:
		for ( QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it ) {
			if ( ( *it ) ->rtti() > 2000 ) {
				( *it ) ->hide();
				( ( CanvasReportItem * ) ( *it ) ) ->section() ->items.remove( ( *it ) );
				delete ( *it );
				canvas() ->update();
				break;
			}
			if ( ( *it ) ->rtti() > 1800 ) {
				if ( ( *it ) ->rtti() == RttiDetail ) {
					CanvasDetail * det = ( CanvasDetail* ) ( *it );
					if ( det->props[ "Level" ].first.toInt() <
					        ( ( MyCanvas* ) ( canvas() ) ) ->templ->detailsCount - 1 )
						return ;
				}
				CanvasDetailHeader *header = 0;
				CanvasDetailFooter *footer = 0;
				( ( MyCanvas* ) ( canvas() ) ) ->templ->removeSection( ( CanvasBand * ) ( *it ),
				        &header, &footer );
				( *it ) ->hide();
				delete ( *it );
				if ( header ) {
					header->hide();
					delete header;
				}
				if ( footer ) {
					footer->hide();
					delete footer;
				}
				( ( MyCanvas* ) ( canvas() ) ) ->templ->arrangeSections();
				canvas() ->update();
				break;
			}
		}
		break;
	case RightButton:
		//display editor for report items or sections

		for ( QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it ) {
			if ( ( *it ) ->rtti() >= 1800 )  //for my own report items
			{
				CanvasBox * l = ( CanvasBox* ) ( *it );
				dlgItemOptions *dlgOpts = new dlgItemOptions( &( l->props ), this );
				dlgOpts->exec();
				delete dlgOpts;
				( *it ) ->hide();
				( *it ) ->show();
				if ( ( *it ) ->rtti() < 2000 )
					( ( MyCanvas * ) ( canvas() ) ) ->templ->arrangeSections();
				canvas() ->update();
				break;
			}
		}
		break;
	case LeftButton:
		if ( selectedItem ) {
			bool unused = true;
			for ( QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it ) {
				if ( ( ( *it ) ->rtti() > 1800 ) && ( ( ( *it ) ->rtti() < 2000 ) ) ) {
					selectedItem->setX( e->x() );
					selectedItem->setY( e->y() );
					selectedItem->setSection( ( CanvasBand * ) ( *it ) );
					selectedItem->updateGeomProps();
					selectedItem->show();
					( ( CanvasBand * ) ( *it ) ) ->items.append( selectedItem );
					unused = true;
				}
			}
			if ( !unused )
				delete selectedItem;
			selectedItem = 0;
			( ( fmMain * ) parent() ) ->reportAddNothing->toggle();
		} else {
			//allow user to move any item except for page rectangle
			for ( QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it ) {
				if ( ( *it ) ->rtti() > 2001 ) {
					CanvasReportItem * item = ( CanvasReportItem * ) ( *it );
					/*			    if (item->topLeftResizableRect().contains(e->pos()) ||
									item->bottomLeftResizableRect().contains(e->pos()) ||
									item->topRightResizableRect().contains(e->pos()) ||
									item->bottomRightResizableRect().contains(e->pos()))*/
					if ( item->bottomRightResizableRect().contains( e->pos() ) ) {
						moving = 0;
						resizing = item;
						moving_start = p;
						return ;
					} else {
						moving = item;
						resizing = 0;
						moving_start = p;
						return ;
					}
				}
			}
			moving = 0;
			resizing = 0;
			break;
		}
	}
}