void FloorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (isVertexMoving) {
        QPoint mousePos = event->lastScenePos().toPoint();
        float x = mousePos.x();
        float y = mousePos.y();

        //update the ellipse coordinate of the currently moving vertex
        QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse();
        ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f);

        //update the coordinate of the two edges of the currently moving vertex
        FloorVertex* neighbor1 = (FloorVertex*)currentlyMovingVertex->getNeighbor1();
        QGraphicsLineItem* edge1 = currentlyMovingVertex->getEdge1();
        edge1->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry());

        FloorVertex* neighbor2 = (FloorVertex*)currentlyMovingVertex->getNeighbor2();
        QGraphicsLineItem* edge2 = currentlyMovingVertex->getEdge2();
        edge2->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry());

        //update the coordinate of the currently moving vertex
        QRectF thisSize = this->sceneRect();
        Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height());
        currentlyMovingVertex->setX(x);
        currentlyMovingVertex->setY(y);

        //update the normals
        currentlyMovingVertex->computeNormal();
        neighbor1->computeNormal();
        neighbor2->computeNormal();
    }
}
Exemplo n.º 2
0
void SymbolDataEditor::rememberChanges()
{
    if (scene->items().isEmpty())
        return;

    if (itemToChange == Item::InPoint)
    {
        QGraphicsEllipseItem* inPointItem = static_cast<QGraphicsEllipseItem *>(scene->items(Qt::AscendingOrder).at(Item::InPoint));
        inPoint = inPointItem->rect().center();
    }

    if (itemToChange == Item::OutPoint)
    {
        QGraphicsEllipseItem* outPointItem = static_cast<QGraphicsEllipseItem *>(scene->items(Qt::AscendingOrder).at(Item::OutPoint));
        outPoint = outPointItem->rect().center();
    }

    if (itemToChange == Item::LimitsRect)
    {
        QGraphicsRectItem* limitsRectItem = static_cast<QGraphicsRectItem *>(scene->items(Qt::AscendingOrder).at(Item::LimitsRect));
        limits = limitsRectItem->rect();
    }

    correctLimits();
}
void ProfileScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (!isProfileSelected) {
        return;
    }

    if (isVertexMoving) {
        QPoint mousePos = event->lastScenePos().toPoint();
        float x = mousePos.x();
        float y = mousePos.y();


        QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse();
        ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f);

        Vertex* neighbor1 = currentlyMovingVertex->getNeighbor1();
        if (neighbor1 != 0){
            QGraphicsLineItem* edge1 = currentlyMovingVertex->getEdge1();
            edge1->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry());
        }

        Vertex* neighbor2 = currentlyMovingVertex->getNeighbor2();
        if (neighbor2 != 0) {
            QGraphicsLineItem* edge2 = currentlyMovingVertex->getEdge2();
            edge2->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry());
        }

        QRectF thisSize = this->sceneRect();
        Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height());
        currentlyMovingVertex->setX(x);
        currentlyMovingVertex->setY(y);
    }
}
void ProfileScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
    if (!isProfileSelected) {
        return;
    }

    if (isVertexMoving) {
        QPoint mousePos = event->lastScenePos().toPoint();
        float x = mousePos.x();
        float y = mousePos.y();

        // enforce the monotonicity constraints
        Vertex* neighbor1 = currentlyMovingVertex->getNeighbor1();
        if (neighbor1 != 0){
            if (neighbor1->getEllipse()->rect().center().ry() - 1 <= y) {
                return;
            }
        }

        // enforce the monotonicity constraints
        Vertex* neighbor2 = currentlyMovingVertex->getNeighbor2();
        if (neighbor2 != 0){
            if (neighbor2->getEllipse()->rect().center().ry() + 1 >= y) {
                return;
            }
        }

        //update the ellipse coordinate of the currently moving vertex
        QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse();
        ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f);

        //update the coordinate of the two edges of the currently moving vertex
        if (neighbor1 != 0){
            Edge* edge1 = currentlyMovingVertex->getEdge1();
            edge1->getLineItem()->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry());
        }

        if (neighbor2 != 0) {
            Edge* edge2 = currentlyMovingVertex->getEdge2();
            edge2->getLineItem()->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(),
                       neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry());
        }

        //update the coordinate of the currently moving vertex
        QRectF thisSize = this->sceneRect();
        Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height());
        currentlyMovingVertex->setX(x);
        currentlyMovingVertex->setY(y);
    }
}
Exemplo n.º 5
0
void GraphiItemCtrl::OnDrawEvent()
{

	switch(i_CurrentType)
	{
	case ITM_TYPE_LINE:
		{
			QGraphicsLineItem* pLine = o_ItemScene.addLine(o_PointA.x(),o_PointA.y(),
				o_PointB.x(), o_PointB.y(),o_CurrentPen);
			int iKey = GetNextItemKey();
			QLineF oLine = pLine->line();
			map_Lines.insert(iKey,oLine);
			map_LineItems.insert(iKey, pLine);
			pLine->setData(CUSTDATA_KEY,iKey);
			
			emit NotifyLineAdded(iKey,oLine);
			break;
		}
	case ITM_TYPE_RECTANGLE:
		{
			double dWidth = o_PointB.x() - o_PointA.x();
			double dHeight = o_PointB.y() - o_PointA.y();
			QGraphicsRectItem* pRect = o_ItemScene.addRect(o_PointA.x(),o_PointA.y(),
				dWidth ,dHeight,o_CurrentPen);
			int iKey = GetNextItemKey();
			QRectF oRect = pRect->rect();
			map_Rects.insert(iKey, oRect);
			pRect->setData(CUSTDATA_KEY,iKey);
			
			emit NotifyRectAdded(iKey,oRect);
		
			break;
		}
	case ITM_TYPE_ELIPSE:
		{
			double dWidth = o_PointB.x() - o_PointA.x();
			double dHeight = o_PointB.y() - o_PointA.y();
			QGraphicsEllipseItem* pElipse =	o_ItemScene.addEllipse(o_PointA.x(),o_PointA.y(),
				dWidth ,dHeight,o_CurrentPen);
			
			int iKey = GetNextItemKey();
			pElipse->setData(CUSTDATA_KEY, iKey);
			QRectF oRect = pElipse->rect();
			map_Elipses.insert(iKey,oRect);
			
			emit NotifyElipseAdded(iKey,oRect);
			break;
		}
	}



}
Exemplo n.º 6
0
void LVL_ModeCircle::mouseRelease(QGraphicsSceneMouseEvent *mouseEvent)
{
    Q_UNUSED(mouseEvent);

    if(!scene) return;
    LvlScene *s = dynamic_cast<LvlScene *>(scene);

    if(s->m_cursorItemImg)
    {
        QGraphicsEllipseItem * cur = dynamic_cast<QGraphicsEllipseItem *>(s->m_cursorItemImg);

        // /////////// Don't draw with zero width or height //////////////
        if( (cur->rect().width()==0) || (cur->rect().height()==0))
        {
            s->m_cursorItemImg->hide();
            dontCallEvent = true;
            return;
        }
        // ///////////////////////////////////////////////////////////////

        if( ((s->m_placingItemType==LvlScene::PLC_Block)&&(!LvlPlacingItems::sizableBlock))||
                (s->m_placingItemType==LvlScene::PLC_BGO))
        {
            item_rectangles::drawRound(s, QRect(cur->x(), cur->y(), cur->rect().width(), cur->rect().height()),
                                                QSize(LvlPlacingItems::itemW, LvlPlacingItems::itemH) );
        }

        switch(s->m_placingItemType)
        {
        case LvlScene::PLC_Block:
            {
                //LvlPlacingItems::waterSet.quicksand = (LvlPlacingItems::waterType==1);
                if(LvlPlacingItems::sizableBlock)
                {
                    LvlPlacingItems::blockSet.x = s->m_cursorItemImg->scenePos().x();
                    LvlPlacingItems::blockSet.y = s->m_cursorItemImg->scenePos().y();
                    LvlPlacingItems::blockSet.w = cur->rect().width();
                    LvlPlacingItems::blockSet.h = cur->rect().height();
                    //here define placing water item.
                    s->m_data->blocks_array_id++;

                    LvlPlacingItems::blockSet.meta.array_id = s->m_data->blocks_array_id;
                    s->m_data->blocks.push_back(LvlPlacingItems::blockSet);

                    s->placeBlock(LvlPlacingItems::blockSet, true);
                    LevelData plSzBlock;
                    plSzBlock.blocks.push_back(LvlPlacingItems::blockSet);
                    s->m_history->addPlace(plSzBlock);
                    s->Debugger_updateItemList();
                    break;
                }
                else
                {
                    s->placeItemsByRectArray();
                    //LogDebug("clear collision buffer");
                    s->m_emptyCollisionCheck = false;
                    s->collisionCheckBuffer.clear();
                    #ifdef _DEBUG_
                    LogDebug("Done");
                    #endif
                    s->Debugger_updateItemList();
                    break;
                }
            }
        case LvlScene::PLC_BGO:
            {
                s->placeItemsByRectArray();

                s->m_emptyCollisionCheck = false;
                s->collisionCheckBuffer.clear();

                s->Debugger_updateItemList();
             break;
            }
        }
        s->m_data->meta.modified = true;

        s->m_cursorItemImg->hide();
    }
}
Exemplo n.º 7
0
void StitcherView::mouseReleaseEvent( QMouseEvent *  event){
  ImageView::mouseReleaseEvent(event);
  if(mode == Line && event->button() & Qt::LeftButton){
    setMode(Default);
    QGraphicsLineItem * line = new QGraphicsLineItem(QLineF(mapToScene(lineOrigin),mapToScene(lineEnd)));
    line->setData(0,QString("Helper"));
    line->setZValue(11);    
    QPen pen = line->pen();  
    pen.setColor(Qt::white);
    pen.setStyle(Qt::SolidLine);
    line->setPen(pen);
    graphicsScene->addItem(line);    
  }else if(mode == Circle && event->button() & Qt::LeftButton){
    setMode(Default);
    QPointF lineOriginF = mapToScene(lineOrigin);
    QPointF lineEndF = mapToScene(lineEnd);
    QPointF circleCenter = (lineOriginF+lineEndF)/2;    
    qreal circleRadius = sqrt((lineOriginF-lineEndF).x()* (lineOriginF-lineEndF).x()+
			      (lineOriginF-lineEndF).y()* (lineOriginF-lineEndF).y())/2;
    if(QApplication::keyboardModifiers() & Qt::ShiftModifier){
      circleCenter =  mapFromScene(QPointF(0,0));
      circleRadius = sqrt((circleCenter-lineEnd).x()* (circleCenter-lineEnd).x()+
			      (circleCenter-lineEnd).y()* (circleCenter-lineEnd).y());
      circleCenter =  QPointF(0,0);

    }
    QGraphicsEllipseItem * circle = new QGraphicsEllipseItem(QRect(circleCenter.x()-circleRadius,circleCenter.y()-circleRadius,circleRadius*2,circleRadius*2));
    circle->setData(0,QString("Helper"));
    circle->setZValue(11);    
    QPen pen = circle->pen();  
    pen.setColor(Qt::white);
    pen.setStyle(Qt::SolidLine);
    circle->setPen(pen);
    graphicsScene->addItem(circle);    
  }else if(mode == AddPoint && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    for(int i = 0; i < it.size(); i++){
      if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){
	item->addControlPoint(item->mapFromScene(mapToScene(event->pos())));
      }
    }
  }else if(mode == DeletePoint && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    for(int i = 0; i < it.size(); i++){
      if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){
	item->deleteControlPoint(item->mapFromScene(mapToScene(event->pos())));
      }
    }
  }else if(mode == DeleteGuide && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    QPointF pos = mapToScene(event->pos());
    /* 10 px tolerance radius, delete the closest */
    for(int i = 0; i < it.size(); i++){
      if(QString("Helper") == it[i]->data(0)){
	QGraphicsEllipseItem * elipse = qgraphicsitem_cast<QGraphicsEllipseItem *>(it[i]);
	if(elipse){
	  // Check if click position close to the line
	  QPointF origin = elipse->rect().center();
	  qreal radius = elipse->rect().height()/2;
	  QPointF d = origin-pos;	  
	  if(abs(sqrt(d.x()*d.x()+d.y()*d.y())-radius) < 10){
	    delete elipse;
	  }
	}
	QGraphicsLineItem * line = qgraphicsitem_cast<QGraphicsLineItem *>(it[i]);
	if(line){
	  delete line;
	}

      }
    }
  }
}