コード例 #1
0
void CornerHandler::resize(const QPointF &mousePos) {
    QRectF rect = m_parent->owner()->boundingRect();

    double oldX1 = rect.x();
    double oldY1 = rect.y();
    double oldX2 = oldX1+rect.width();
    double oldY2 = oldY1+rect.height();
    double newX = mapToItem(m_parent->owner(),mousePos).x();
    double newY = mapToItem(m_parent->owner(),mousePos).y();

    switch(m_corner) {
    case Qt::TopLeftCorner:
        m_parent->resizeRect(newX,newY,oldX2,oldY2);
        break;
    case Qt::TopRightCorner:
        m_parent->resizeRect(oldX1,newY,newX,oldY2);
        break;
    case Qt::BottomRightCorner:
        m_parent->resizeRect(oldX1,oldY1,newX,newY);
        break;
    case Qt::BottomLeftCorner:
        m_parent->resizeRect(newX,oldY1,oldX2,newY);
        break;
    default:
        break;
    }
}
コード例 #2
0
ファイル: node.cpp プロジェクト: LuckJC/qt_project
 foreach (Link *edge, links) {
     QPointF vec;
     if (edge->getSourceNode() == this)
         vec = mapToItem(edge->getDestNode(), 0, 0);
     else
         vec = mapToItem(edge->getSourceNode(), 0, 0);
     xvel -= vec.x() / weight;
     yvel -= vec.y() / weight;
 }
コード例 #3
0
ファイル: GNode.cpp プロジェクト: MIPT-ILab/ICDV
 foreach (GEdge *edge, edgeList) {
     QPointF vec;
     if (edge->sourceNode() == this)
         vec = mapToItem(edge->destNode(), 0, 0);
     else
         vec = mapToItem(edge->sourceNode(), 0, 0);
     xvel -= vec.x() / weight;
     yvel -= vec.y() / weight;
 }
コード例 #4
0
ファイル: node.cpp プロジェクト: richelbilderbeek/CppTests
 foreach (Edge *edge, m_edges)
 {
   const QPointF vec
     = edge->sourceNode() == this
     ? mapToItem(edge->destNode(), 0, 0)
     : mapToItem(edge->sourceNode(), 0, 0)
   ;
   xvel -= vec.x() / weight;
   yvel -= vec.y() / weight;
 }
コード例 #5
0
ファイル: node.cpp プロジェクト: richelbilderbeek/CppTests
void Node::calculateForces() noexcept
{
  if (!scene() || scene()->mouseGrabberItem() == this)
  {
    m_new_pos = pos();
    return;
  }

  // Sum up all forces pushing this item
  double xvel = 0.0;
  double yvel = 0.0;
  foreach (QGraphicsItem *item, scene()->items())
  {
    Node * const node = qgraphicsitem_cast<Node *>(item);

    if (!node) continue;
    if (node == this) continue;

    const QPointF vec{mapToItem(node, 0.0, 0.0)};
    const double dx{vec.x()};
    const double dy{vec.y()};
    const double distance{std::sqrt( (dx*dx) + (dy*dy) )};
    if (distance < this->GetRay() + node->GetRay())
    {
      xvel -= (0.1 * (10.0 - dx));
      yvel -= (0.1 * (10.0 - dy));
    }
  }
コード例 #6
0
ファイル: connector.cpp プロジェクト: VARPERTecnology/INSYDE
void core::Connector::setEndObject(GraphicObject *end)
{
	if(!end) return;

	endObject = end;

//	qDebug() << currentMousePos;
	//we use currentMousePos instead internal currentMousePos from "end" object due update mouse position problems
	//there are conflicts when moving mouse so using this currentMousePos ensures mouse pos is always updated

//	qDebug() << portRect;
	endPoint = mapFromItem(end, end->getCurrentPortPos(mapToItem(end, currentMousePos)));
	isBuildingConector = false;
//	qDebug() << portCenter;

	QRectF container = getContainerRect();


	if(currentMousePos.x() < 0 && currentMousePos.y() < 0){
		container.setTopLeft(endPoint );
	}else if(currentMousePos.x() < 0 && currentMousePos.y() >= 0){
		container.setBottomLeft(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() < 0){
		container.setTopRight(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() >= 0){
		container.setBottomRight(endPoint );
	}else{
		container= QRectF(0, 0, 0, 0);
	}

	setContainerRect(container);
}
コード例 #7
0
ファイル: sg_editor.cpp プロジェクト: mottosso/feather
void SceneGraphNode::outConnectionPoint(unsigned int fid, QPointF& point)
{
    for(auto c : m_pOutConns) {
        if(c->fid() == fid)
            point = mapToItem(parentItem(),QPoint(c->x()+(NODE_WIDTH/2)+CONNECTION_WIDTH,c->y()+(CONNECTION_WIDTH/2)));
    }
}
コード例 #8
0
ファイル: node.cpp プロジェクト: LuckJC/qt_project
void Node::calculateForces()
{
    //对于接收到鼠标事件或已经禁止的Node不改变其位置
    if (!scene() || scene()->mouseGrabberItem() == this || statue == 1)
    {
        newPos = pos();
        return;
    }

    //计算所有推动item运动的力
    qreal xvel = 0;
    qreal yvel = 0;
    foreach (QGraphicsItem *item, scene()->items()) {
        Node *node = dynamic_cast<Node *>(item);
        if (!node)
            continue;

        QPointF vec = mapToItem(node, 0, 0);
        //qDebug()<<vec.x()<<endl<<vec.y()<<endl;
        qreal dx = vec.x();
        qreal dy = vec.y();
        double l = 2.0 * (dx * dx + dy * dy);
        //double l = sqrt(dx * dx + dy * dy);
        if (l > 0) {
            //xvel += (dx * 150.0) / l;
            //yvel += (dy * 150.0) / l;

            xvel += (dx * ELLIPSE_SIZE*10) / l;
            yvel += (dy * ELLIPSE_SIZE*10) / l;
        }
    }
コード例 #9
0
ファイル: node.cpp プロジェクト: sepiropht/caltopo
//! [2]
void Node::calculateForces()
{
    if (!scene() || scene()->mouseGrabberItem() == this) {
        newPos = pos();
        return;
    }
//! [2]

//! [3]
    // Sum up all forces pushing this item away
    qreal xvel = 0;
    qreal yvel = 0;
    foreach (QGraphicsItem *item, scene()->items()) {
        Node *node = qgraphicsitem_cast<Node *>(item);
        if (!node)
            continue;

        QPointF vec = mapToItem(node, 0, 0);
        qreal dx = vec.x();
        qreal dy = vec.y();
        double l = 2.0 * (dx * dx + dy * dy);
        if (l > 0) {
            xvel += (dx * 150.0) / l;
            yvel += (dy * 150.0) / l;
        }
    }
コード例 #10
0
ファイル: node.cpp プロジェクト: richelbilderbeek/CppTests
void Node::calculateForces()
{
  if (!scene() || scene()->mouseGrabberItem() == this)
  {
    m_new_pos = pos();
    return;
  }

  // Sum up all forces pushing this item away
  double xvel = 0.0;
  double yvel = 0.0;
  foreach (QGraphicsItem *item, scene()->items())
  {
    Node * const node = qgraphicsitem_cast<Node *>(item);

    if (!node) continue;

    const QPointF vec{mapToItem(node, 0.0, 0.0)};
    const double dx{vec.x()};
    const double dy{vec.y()};
    const double l{2.0 * (dx * dx + dy * dy)};
    if (l > 0.0)
    {
      xvel += (dx * 150.0) / l;
      yvel += (dy * 150.0) / l;
    }
  }
コード例 #11
0
void MachineItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{

    if (event->button() == Qt::LeftButton) {
        setColor(Qt::cyan);
        // force my box to snap to grid, just truncate the pixel number and
        // snap to the next lowest grid value

        if (fmod(_location.x(),_gridSpace) >_gridSpace/2)
            _location.setX( ( static_cast<int>(_location.x()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setX( ( static_cast<int>(_location.x()) / _gridSpace) * _gridSpace );
        if (fmod(_location.y(),_gridSpace) >_gridSpace/2)
            _location.setY( ( static_cast<int>(_location.y()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setY( ( static_cast<int>(_location.y()) / _gridSpace) * _gridSpace );


        foreach (QGraphicsItem *item, collidingItems()) {

                if (item->type() ==GroupItem::Type){

                    this->setPos(mapToItem(item,0,0));
                        setParentItem(item);

                } else {
                    this->setPos(mapToScene(0,0));
                    this->setParentItem(0);
                }
            }

        event->setAccepted(true);// tell the base class we are handling this event

    }
コード例 #12
0
ファイル: SGItem.cpp プロジェクト: Canadadry/luaSFML
void SGItem::recursivePick(std::vector<SGItem*>& items,  sf::Vector2f point)
{
    if(containPoint(point)) items.push_back(this);

    for(unsigned int i=0;i<m_childrensItem.size();i++)
    {
	SGItem* item = m_childrensItem[i];
	item->recursivePick(items,mapToItem(item,point));
    }
}
コード例 #13
0
ファイル: node.cpp プロジェクト: Edgar324/WrfAnalysisPlatform
    foreach (Edge *edge, edgeList) {
		if ( is_fixed_pos_ ) continue;
		QPointF vec;
		if (edge->sourceNode() == this)
			vec = mapToItem(edge->destNode(), 0, 0);
		else
			vec = mapToItem(edge->sourceNode(), 0, 0);
		qreal dx = vec.x();
		qreal dy = vec.y();
		/*double l = sqrt(dx * dx + dy * dy);
		if ( l != 0 ){
		xvel += dx * l / k_value;
		yvel += dy * l / k_value;
		}*/

		double l = sqrt(dx * dx + dy * dy);
		xvel -= vec.x() / weight / (0.1 + graph->item_forces_[edge->sourceNode()->id()][edge->destNode()->id()]);
		yvel -= vec.y() / weight / (0.1 + graph->item_forces_[edge->sourceNode()->id()][edge->destNode()->id()]);
    }
コード例 #14
0
/*

void NodeItem::mouseMoveEvent(QGraphicsSceneDragDropEvent *event)
{
    event->setAccepted(true);
}


void ParameterItem::mousePressEvent(QGraphicsSceneDragDropEvent *event)
{

    event->setAccepted(false);

}
*/
void ParameterItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{

    if (event->button() == Qt::LeftButton) {
        setColor(Qt::darkCyan);
        // force my box to snap to grid, just truncate the pixel number and
        // snap to the next lowest grid value
        if (fmod(_location.x(),_gridSpace) >_gridSpace/2)
            _location.setX( ( static_cast<int>(_location.x()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setX( ( static_cast<int>(_location.x()) / _gridSpace) * _gridSpace );
        if (fmod(_location.y(),_gridSpace) >_gridSpace/2)
            _location.setY( ( static_cast<int>(_location.y()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setY( ( static_cast<int>(_location.y()) / _gridSpace) * _gridSpace );

        foreach (QGraphicsItem *item, collidingItems()) {

                if (item->type() ==GroupItem::Type){

                    this->setPos(mapToItem(item,0,0));
                        setParentItem(item);

                } else {
                    this->setPos(mapToScene(0,0));
                    this->setParentItem(0);
                }
            }

        if (scene()->itemAt(_location)){

            switch (scene()->itemAt(_location)->type()){
            case GroupItem::Type:                                                         //Group
                setParentItem(scene()->itemAt(_location));
                this->setPos(_location-(this->parentItem()->pos()));
                break;
            case NodeItem::Type:                                                         //Node or Test
                NodeItem *node;
                node=qgraphicsitem_cast<NodeItem *>(scene()->itemAt(_location));
                node->addParamItem(this);
                scene()->removeItem(this);
                break;
            case 8:                                                             //TextItem -> check for parent
                if (scene()->itemAt(_location)->parentItem()->type() ==NodeItem::Type){  //Node or Test
                    NodeItem *node;
                    node=qgraphicsitem_cast<NodeItem *>(scene()->itemAt(_location)->parentItem());
                    node->addParamItem(this);
                    scene()->removeItem(this);
                }
                break;
            }
       }
        event->setAccepted(true);// tell the base class we are handling this event

    }
コード例 #15
0
ファイル: alphabetpage.cpp プロジェクト: 22350/luna-sysmgr
//virtual
bool AlphabetPage::detectAndHandleSpecialReleaseAreas(int id,const QPointF& pageCoordinate)
{
	//TODO: IMPLEMENT (unfinished)

	PageAreas::Enum pageAreaOfIcon = classifyPageLocation(pageCoordinate);
	bool queryLauncher = false;
	switch (pageAreaOfIcon)
	{
	case PageAreas::LeftBorder:
//		qDebug() << __FUNCTION__ << ": Left Border";
		return false;
	case PageAreas::RightBorder:
//		qDebug() << __FUNCTION__ << ": Right Border";
		return false;
	case PageAreas::TopBorder:
//		qDebug() << __FUNCTION__ << ": Top Border";
		return false;
	case PageAreas::BottomBorder:
//		qDebug() << __FUNCTION__ << ": Bottom Border";
		return false;
	case PageAreas::Content:
//		qDebug() << __FUNCTION__ << ": Warm, chewy center!";
		return false;
	default:
		queryLauncher = true;
//		qDebug() << __FUNCTION__ << ": Nuthin'!";
		break;
	}
	if ((queryLauncher) && (m_qp_currentUIOwner))
	{
		LauncherAreas::Enum launcherArea = m_qp_currentUIOwner->classifyPageLocation(mapToItem(m_qp_currentUIOwner,pageCoordinate));
		switch (launcherArea)
		{
		case LauncherAreas::PageTabBar:
//			qDebug() << __FUNCTION__ << ": Page Tab Bar";
			return false;
			break;
		case LauncherAreas::QuickLaunchBar:
//			qDebug() << __FUNCTION__ << ": Quick Launch Bar";
//			return handleQuickLaunchSpecialReleaseArea(id,pageCoordinate);
			return false;
			break;
		case LauncherAreas::PageInner:
//			qDebug() << __FUNCTION__ << ": Launcher claims it's in the Page";
			return false;
		default:
//			qDebug() << __FUNCTION__ << ": Launcher Nuthin'!";
			return false;
		}
	}

	return true;
}
コード例 #16
0
ファイル: arrowlinkitem.cpp プロジェクト: Daylie/Totem
void ArrowLinkItem::updateGeometory()
{
    prepareGeometryChange();
    

    QPointF c1;
    QPointF c2;
    QPointF startPoint = getStartPoint();
    QPointF endPoint = getEndPoint();
	int controlDeltaWidth = qAbs(startPoint.x() - endPoint.x()) / 2;
	controlDeltaWidth = qMax(controlDeltaWidth, 50);
	c1.setY(startPoint.y());
	c2.setY(endPoint.y());

	c1.setX(startPoint.x() + controlDeltaWidth);
	c2.setX(endPoint.x() - controlDeltaWidth);
    m_controlPoint_1->setPos(mapToItem(m_controlPoint_1->parentItem(), c1));
    m_controlPoint_2->setPos(mapToItem(m_controlPoint_2->parentItem(), c2));

    update();
}
コード例 #17
0
ファイル: doc_block.cpp プロジェクト: fejo/TrollEdit-1
Block *DocBlock::addTextCursorAt(QPointF pos)
{
    pos = mapToItem(myTextItem, pos);   //! map to my TextItem
    int cursorPos;
    // find cursor position
    cursorPos = myTextItem->document()->documentLayout()->hitTest(pos, Qt::FuzzyHit);
    // set cursor position

    if (cursorPos < 0 || !myTextItem->setTextCursorPos(cursorPos))
        myTextItem->setTextCursorPos(0);

    return this;                        //! return block with cursor
}
コード例 #18
0
void QmlWebViewWidget::updateGeometry()
{
    QPointF newPos(0, 0);
    newPos = mapToItem(0, newPos);
    qDebug() << "QmlWebViewWidget::updateGeometry, top left mapped to window: " << newPos;

    if(this->window()){
    newPos += this->window()->position();
    qDebug() << "QmlWebViewWidget::updateGeometry, top left mapped to screen: " << newPos;
    }
    QRectF absRect(newPos, contentsBoundingRect().size());
    m_widget->setGeometry(absRect.toRect());
}
コード例 #19
0
ファイル: kmaskimageitem.cpp プロジェクト: kxtry/kxfw
bool KMaskImageItem::getBatchRandomPoint( QList<QPoint>& pts, int count, QGraphicsItem *toItem )
{
	Q_D(KMaskImageItem);

	int seed = GetTickCount();
	qsrand(seed);
	pts.clear();
	if(d->m_maskRegion.isEmpty())
	{
		QRect br = rect().toRect();
		if(br.isEmpty())
			return false;
		int i = 0;
		while(i < count)
		{
			int x = qrand() % br.width();
			int y = qrand() % br.height();
			pts.push_back(QPoint(x,y));
			i++;
		}		
	}
	else
	{
		QRect br = d->m_maskRegion.boundingRect();
		if(br.isEmpty())
			return false;
		int i = 0;
		while(i < count)
		{
			int x = qrand() % br.width();
			int y = qrand() % br.height();
			if(d->m_maskRegion.contains(QPoint(x,y)))
			{
				pts.push_back(QPoint(x,y));
				i++;
			}
		}
	}

	if(toItem)
	{
		for(int i = 0; i < count; i++)
		{
			QPoint pt = pts[i];
			pts[i] = mapToItem(toItem, pt).toPoint();
		}
	}
	return true;
}
コード例 #20
0
/*!
    Check whether \a position is inside the selection area of the given selectionAreaType in the view item.

    Default selection areas are for
    \li HbAbstractViewItem::SingleSelection mode: whole item
    \li HbAbstractViewItem::MultiSelection mode: whole item.
    \li HbAbstractViewItem::ContiguousSelection mode: area of HbStyle::P_ItemViewItem_touchmultiselection icon.

    The \a selectionAreaType tells what kind of selection area is requested.  The parameter value ContiguousSelection returns 
    the area where mouse movement will extend the selection to new items. By default this contiguous selection area is 
    the HbStyle::P_ItemViewItem_touchmultiselection.
    
*/
bool HbAbstractViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const
{
    Q_D(const HbAbstractViewItem);
    bool contains = false;
    if (selectionAreaType == ContiguousSelection) {
        if(     d->mMultiSelectionTouchArea 
            &&  !d->mMultiSelectionTouchArea->boundingRect().isEmpty()) {
                contains = d->mMultiSelectionTouchArea->boundingRect().contains(mapToItem(d->mMultiSelectionTouchArea, position));
            } else if (d->mSelectionItem) {
                contains = d->mSelectionItem->boundingRect().contains(mapToItem(d->mMultiSelectionTouchArea, position));
            }
    } else {
        switch (selectionAreaType) {
            case SingleSelection: 
            case MultiSelection: 
            case ContiguousSelection: 
                contains = true;
                break;
            default:
                break;
        }
    }
    return contains;
}
コード例 #21
0
ファイル: SGItem.cpp プロジェクト: Canadadry/luaSFML
void SGItem::pick(  sf::Vector2f point)
{
    if(pickedItem != nullptr) return;
    if(root != nullptr)
    {
	root->pick(mapToItem(*root,point));
    }
    else
    {
	std::vector<SGItem* > pickable;
	root->recursivePick(pickable,point);
	if(!pickable.empty())
	{
	    pickedItem = pickable.back();
	    pickedItem->m_debugContent->setOutlineColor(sf::Color::Red);
	}
    }
}
コード例 #22
0
ファイル: node.cpp プロジェクト: Edgar324/WrfAnalysisPlatform
//! [2]
void Node::calculateForces(int t)
{
    if ( !scene() || scene()->mouseGrabberItem() == this || graph == NULL ) {
        newPos = pos();
        return;
    }

//! [2]

//! [3]
    // Sum up all forces pushing this item away
	float k_value = 100.0;

    qreal xvel = 0;
    qreal yvel = 0;
	double total_weight = 0;
    foreach (QGraphicsItem *item, scene()->items()) {
        Node *node = qgraphicsitem_cast<Node *>(item);
        if (!node || node->id() == id_ )
            continue;
		if ( is_fixed_pos_ && (!this->collidesWithItem(node) || (this->collidesWithItem(node) && node->level() > 0)) ) continue;
		
		if ( this->level() > 0 && !this->collidesWithItem(node) && node->level() == 0 ) continue;

        QPointF vec = mapToItem(node, 0, 0);
        qreal dx = vec.x();
        qreal dy = vec.y();

		float scale = 2.0;
		if ( this->level() > 0 ) scale = 1.5;

		double l = dx * dx + dy * dy;
		if (l > 0) {
			if ( is_only_pull_ ){
				if ( l < 400 ){
					xvel += (dx * k_value * k_value) / l;
					yvel += (dy * k_value * k_value) / l;
				}
			} else {
				xvel += (dx * k_value * k_value) / l * scale;
				yvel += (dy * k_value * k_value) / l * scale;
			}
		}
    }
コード例 #23
0
void RelationStarter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    m_currentPreviewArrow = 0;
    foreach (ArrowItem *item, m_arrows) {
        if (item->boundingRect().contains(mapToItem(item, event->pos()))) {
            prepareGeometryChange();
            m_currentPreviewArrowIntermediatePoints.clear();
            m_currentPreviewArrowId = m_arrowIds.value(item);
            QMT_CHECK(!m_currentPreviewArrowId.isEmpty());
            m_currentPreviewArrow = new ArrowItem(*item);
            m_currentPreviewArrow->setPoints(QList<QPointF>() << m_owner->relationStartPos() << mapToScene(event->pos()));
            m_currentPreviewArrow->update(m_diagramSceneModel->styleController()->relationStarterStyle());
            m_currentPreviewArrow->setZValue(PREVIEW_RELATION_ZVALUE);
            scene()->addItem(m_currentPreviewArrow);
            setFocus(); // receive keyboard events
            break;
        }
    }
}
コード例 #24
0
ファイル: Canvas.cpp プロジェクト: cadet/UberQuick
QString Canvas::getTypeOfChildAt(int x, int y)
{
    QQuickItem *item = childAt(x,y);
    if ( item )
    {
        QString tp = item->metaObject()->className();
        if ( tp=="QQuickLoader")
        {
            QPointF p = mapToItem(item, QPointF(x, y));
            QQuickItem *childItem = item->childAt(p.x(), p.y() );
            tp = childItem->metaObject()->className();
            Item* castItem = dynamic_cast<Item*>(childItem);
            if ( castItem )
            {
                tp = castItem->getClassName();
            }
        }
        return tp;
    }
    return QString("notDefined");
}
コード例 #25
0
void KoReportDesignerItemLine::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
    int x;
    int y;

    QPointF p = dynamic_cast<ReportScene*>(scene())->gridPoint(event->scenePos());

    kDebug() << p;
    
    x = p.x();
    y = p.y();

    if (x < 0) x = 0;
    if (y < 0) y = 0;
    if (x > scene()->width()) x = scene()->width();
    if (y > scene()->height()) y = scene()->height();

    switch (m_grabAction) {
    case 1:
	m_start.setScenePos(QPointF(x,y));
        break;
    case 2:
	m_end.setScenePos(QPointF(x,y));
        break;
    default:
        QPointF d = mapToItem(this, dynamic_cast<ReportScene*>(scene())->gridPoint(event->scenePos())) - mapToItem(this, dynamic_cast<ReportScene*>(scene())->gridPoint(event->lastScenePos()));

        if (((line().p1() + d).x() >= 0) &&
                ((line().p2() + d).x() >= 0) &&
                ((line().p1() + d).y() >= 0) &&
                ((line().p2() + d).y() >= 0)  &&
                ((line().p1() + d).x() <= scene()->width()) &&
                ((line().p2() + d).x() <= scene()->width()) &&
                ((line().p1() + d).y() <= scene()->height()) &&
                ((line().p2() + d).y() <= scene()->height()))
            setLineScene(QLineF(line().p1() + d, line().p2() + d));
        break;
    }
}
コード例 #26
0
/**
  Caller's child items will be reparented to the newParent
  */
void SN_LayoutWidget::reparentMyChildBasewidgets(SN_LayoutWidget *newParent) {
	if (_bar) {
		_firstChildLayout->reparentMyChildBasewidgets(newParent);
		_secondChildLayout->reparentMyChildBasewidgets(newParent);
	}
	else {
		foreach(QGraphicsItem *item, childItems()) {
			// exclude all the child but user application
//			if (item == _bar || item == _tileButton || item == _hButton || item == _vButton || item == _xButton || item==_firstChildLayout || item==_secondChildLayout) continue;
			if (item->type() < QGraphicsItem::UserType + BASEWIDGET_USER) continue;

			//
			// this item's pos() which is in this layoutWidget's coordinate to newParent's coordinate
			//
			QPointF newPos = mapToItem(newParent, item->pos());

			// reparent
			item->setParentItem(newParent);

			item->setPos(newPos);
		}
	}
}
コード例 #27
0
ファイル: NodeGui.cpp プロジェクト: dstoeckel/causaltrail
void NodeGui::calculateForces()
{
    if (!scene() || scene()->mouseGrabberItem() == this) {
        newPos = pos();
        return;
    }

    qreal xvel = 0;
    qreal yvel = 0;
    foreach (QGraphicsItem *item, scene()->items()) {
        NodeGui* node = dynamic_cast<NodeGui*> (item);
        if (!node)
            continue;

        QPointF vec = mapToItem(node, 0, 0);
        qreal dx = vec.x();
        qreal dy = vec.y();
        double l = 2.0 * (dx * dx + dy * dy);
        if (l > 0) {
            xvel += (dx * 200.0) / l;
            yvel += (dy * 200.0) / l;
        }
    }
コード例 #28
0
ファイル: canvas.cpp プロジェクト: Andreas665/qt
void BouncyLogo::advance(int stage)
{
    switch ( stage ) {
      case 0: {
	double vx = xvel;
	double vy = yvel;

	if ( vx == 0.0 && vy == 0.0 ) {
	    // stopped last turn
	    initSpeed();
	    vx = xvel;
	    vy = yvel;
	}

	double nx = x() + vx;
	double ny = y() + vy;

	if ( nx < 0 || nx >= scene()->width() )
	    vx = -vx;
	if ( ny < 0 || ny >= scene()->height() )
	    vy = -vy;

	for (int bounce=0; bounce<4; bounce++) {
	    QList<QGraphicsItem *> l=scene()->collidingItems(this);
            for (QList<QGraphicsItem *>::Iterator it=l.begin(); it!=l.end(); ++it) {
                QGraphicsItem *hit = *it;
                QPainterPath advancedShape = QMatrix().translate(xvel, yvel).map(shape());
                if ( hit->type()==logo_rtti && hit->collidesWithPath(mapToItem(hit, advancedShape)) ) {
		    switch ( bounce ) {
		      case 0:
			vx = -vx;
			break;
		      case 1:
			vy = -vy;
			vx = -vx;
			break;
		      case 2:
			vx = -vx;
			break;
		      case 3:
			// Stop for this turn
			vx = 0;
			vy = 0;
			break;
		    }
		    xvel = vx;
                    yvel = vy;
		    break;
		}
	    }
        }

	if ( x()+vx < 0 || x()+vx >= scene()->width() )
	    vx = 0;
	if ( y()+vy < 0 || y()+vy >= scene()->height() )
	    vy = 0;

	xvel = vx;
        yvel = vy;
      } break;
      case 1:
        moveBy(xvel, yvel);
	break;
    }
}
コード例 #29
0
ファイル: connector.cpp プロジェクト: VARPERTecnology/INSYDE
void core::Connector::updateConectorLine(const QPointF &begin, const QPointF &end)
{

	const double MIN_LENGHT = 10;

//	QLineF line(begin, end);

	QList<QGraphicsItem*>
			collidingItemsEndOfLine,
			collidingItemsMiddleLine,
			fullList;

//	QGraphicsItem *closerItem;
//	QRectF closerItemRect;

//	QPointF
//			correctedEnd = end,
//			midPoint,
//			mappedMidPoint;

	if(composedLine.isEmpty()){

		Port p = beginObject->getCurrentPort(mapToItem(beginObject, begin));

		RestrictedLineF *firstLine = new RestrictedLineF(begin, end);

		switch(p){
			case GraphicObject::portBottom:
				firstLine->setConstrain(RestrictedLineF::VerticalDown);
				break;
			case GraphicObject::portTop:
				firstLine->setConstrain(RestrictedLineF::VerticalUp);
				break;
			case GraphicObject::portLeft:
				firstLine->setConstrain(RestrictedLineF::HorizontalLeft);
				break;
			case GraphicObject::portRight:
				firstLine->setConstrain(RestrictedLineF::HorizontalRight);
				break;
				
			case GraphicObject::portNone:
			default:
				firstLine->setConstrain(RestrictedLineF::None);
				break;
		}
		composedLine.push_back(firstLine);

		shapeForm.push_back(firstLine->p1());
		shapeForm.push_back(firstLine->p2());
	}

	QGraphicsScene *env = scene();

	QList<CollidingResult> colItems = collidingObjects(composedLine);

//	for(int i = 0; i < colItems.size(); i++){
//		colItems[i].line->setConstrain(RestrictedLineF::Both);
//	}

	RestrictedLineF
			temptativeLine,
			*curLine;
	for(auto i = composedLine.size()-1; i >= 0; i--){
		curLine = composedLine[i];
		temptativeLine = *curLine;
		if(i == composedLine.size() - 1){

			if(env){
				fullList = env->items(mapToScene(end));
				collidingItemsEndOfLine = removeIgnoredObjects(fullList);

				if(composedLine.size() > 1){
					fullList = env->items(mapToScene(composedLine[i - 1]->getCorrectedP2(end)));
					collidingItemsMiddleLine = removeIgnoredObjects(fullList);
				}

				if(collidingItemsEndOfLine.isEmpty() && collidingItemsMiddleLine.isEmpty()){
					if(composedLine.size() > 1){
						composedLine[i - 1]->setP2(end);
						curLine->setP1(composedLine[i - 1]->p2());
						shapeForm[i] = composedLine[i - 1]->p2();
					}


					//Set the point p2 to curLine (it will be corrected against restrictions)
					curLine->setP2(end);
					shapeForm[i + 1] = curLine->p2();

					//calculates the distance between corrected p2 of curLine and current end point
					if(math::distance(curLine->p2(), end) >= MIN_LENGHT &&
							!curLine->isNull() &&
							!(i = 1 && composedLine[0]->isNull())){

						RestrictedLineF::Constrain restriction;

						switch (curLine->getConstrain()) {
							case RestrictedLineF::HorizontalRight:
							case RestrictedLineF::HorizontalLeft:
							case RestrictedLineF::Horizontal:
								restriction = RestrictedLineF::Vertical;
								break;

							case RestrictedLineF::VerticalUp:
							case RestrictedLineF::VerticalDown:
							case RestrictedLineF::Vertical:
								restriction = RestrictedLineF::Horizontal;
								break;
							case RestrictedLineF::Both:
								if(fabs(curLine->p2().x() - end.x()) >= fabs(curLine->p2().y() - end.y())){
									restriction = RestrictedLineF::Horizontal;
								}else{
									restriction = RestrictedLineF::Vertical;
								}
								break;
							case RestrictedLineF::None:
							default:
								restriction = RestrictedLineF::None;
								break;
						}

						RestrictedLineF *newLine = new RestrictedLineF(curLine->p2(), end, restriction);

						composedLine.push_back(newLine);
						//use in case shapeForm be QPainterPath
//						shapeForm.lineTo(newLine->p2());

						//use in case shapeForm be QPolygonF
//						shapeForm[i + 1]
						shapeForm.push_back(newLine->p2());
					}
				}
			}
		}else if(i == composedLine.size() - 2){

		}

		if(curLine->length() < MIN_LENGHT && i != 0){
			composedLine.remove(i);
			shapeForm.remove(i+1);
		}else if(i == 1){
			if(composedLine[i - 1]->isNull()){
				composedLine.remove(i);
				shapeForm.remove(i+1);
			}
		}
	}

//	shapeForm = QPainterPath(begin);

////	shapeForm
//	for(auto i = 0; i < composedLine.size(); i++){
//		shapeForm.lineTo(composedLine[i]->p2());
//	}
//	//Only for debug process. Can be simplified
//	midPoint = QPointF(end.x(), 0);
//	mappedMidPoint = mapToScene(midPoint);

//	fullList = collidingItems(Qt::IntersectsItemShape);
//	itemListAt = removeIgnoredObjects(fullList);

//	if(fabs(line.dx()) >= fabs(line.dy())){
//		if(itemListAt.size() > 0){
//			if(midPoint.x() >= 0){
//				closerItem = closerItemPerif(midPoint, portLeft, itemListAt);

//				closerItemRect = mapFromItem(closerItem, closerItem->boundingRect()).boundingRect();

//				midPoint.setX(closerItemRect.left()/* - clearance*/);
//				correctedEnd.setX(closerItemRect.left());
//			}else{
//				closerItem = closerItemPerif(midPoint, portRight, itemListAt);

//				closerItemRect = mapFromItem(closerItem, closerItem->boundingRect()).boundingRect();

//				midPoint.setX(closerItemRect.right()/* + clearance*/);
//				correctedEnd.setX(closerItemRect.right());
//			}
//		}
////		composedLine.push_back(QLineF(begin, midPoint));
////		composedLine.push_back(QLineF(midPoint, correctedEnd));
//	}else{
//		if(itemListAt.size() > 0){
//			if(midPoint.y() >= 0){
//				closerItem = closerItemPerif(midPoint, portTop, itemListAt);

//				closerItemRect = mapFromItem(closerItem, closerItem->boundingRect()).boundingRect();

//				midPoint.setY(closerItemRect.top()/* - clearance*/);
//				correctedEnd.setY(closerItemRect.top());
//			}else{
//				closerItem = closerItemPerif(midPoint, portBottom, itemListAt);

//				closerItemRect = mapFromItem(closerItem, closerItem->boundingRect()).boundingRect();

//				midPoint.setY(closerItemRect.bottom()/* + clearance*/);
//				correctedEnd.setY(closerItemRect.bottom());
//			}
//		}
//	}

//	composedLine.clear();
//	composedLine.push_back(QLineF(begin, midPoint));
//	composedLine.push_back(QLineF(midPoint, correctedEnd));
}
コード例 #30
0
ファイル: ligacao.cpp プロジェクト: silasgtcs/BahiaDBM
void Ligacao::conectarObjetos()
{
    if (( castItem1P != NULL ) && ( castItem2P != NULL ))
    {
        //Adiciona no vector dessa entidade que esse relacionamento e esta linha pertence-a.

        //Nao precisa verificar tipo de cada item,  funcao addPoligonoAssociado ja trata internamente
        castItem1P->addPoligonoAssociado(castItem2P);
        castItem2P->addPoligonoAssociado(castItem1P);
        castItem2P->addLinhasAssociadas(this);
        castItem1P->addLinhasAssociadas(this);
        this->addPoligonoAssociado(castItem1P);
        this->addPoligonoAssociado(castItem2P);
        castItem1P->setConectado(true);
        castItem2P->setConectado(true);
    }
    else if ((( castItem1P != NULL ) || ( castItem2P != NULL )) && ( castItemA != NULL ))
    {
        Poligono * properPoligono = (castItem1P != NULL) ? castItem1P : castItem2P;
        if ( properPoligono != NULL )
        {
            //Adiciona no vector dessa entidade que esta linha pertence-a.
            properPoligono->addLinhasAssociadas(this);
            properPoligono->addAtributosAssociados(castItemA);

            if(castItemA->parentItem() == NULL) {
                temp = mapToItem(properPoligono, castItemA->scenePos());
                castItemA->setPos(temp); //Seta atributo como filho e atualiza posição
            }
            castItemA->setParentItem(properPoligono);

            castItemA->addPoligonoAssociado(properPoligono);
            this->addPoligonoAssociado(properPoligono);
        }

        this->addAtributoAssociado(castItemA);
        castItemA->addLinhaAssociada(this);
        castItemA->setConectado(true);
    }
    else
        castItem1P = castItem2P = NULL;

    //Verifica se a ligação é entre entidade/relacionamento, entidade associativa/relacionamento ou relacionamento/entidade associativa.
    //Em caso afirmativo, permite a colocação de cardinalidade.
    if (( castItem1P != NULL ) && ( castItem2P != NULL ))
    {
        if ((((( castItem1P->getTipo() == Poligono::entidade ) && ( castItem2P->getTipo() == Poligono::relacionamento ))
              || (( castItem1P->getTipo() == Poligono::relacionamento ) && ( castItem2P->getTipo() == Poligono::entidade )))
             || ((( castItem1P->getTipo() == Poligono::entidade ) && ( castItem2P->getTipo() == Poligono::ent_associativa ))
                 || (( castItem1P->getTipo() == Poligono::ent_associativa ) && ( castItem2P->getTipo() == Poligono::entidade ))))
                || ((( castItem1P->getTipo() == Poligono::relacionamento ) && ( castItem2P->getTipo() == Poligono::ent_associativa ))
                    || (( castItem1P->getTipo() == Poligono::ent_associativa ) && ( castItem2P->getTipo() == Poligono::relacionamento ))))
        {
            this->addCardinalidadeAssociada(cardItem);

            cardItem->addPoligonoAssociado(castItem1P);
            cardItem->addPoligonoAssociado(castItem2P);
        }
    }
    //Altera posição do item para que slot seja ativado e linha seja atualizada.
    Poligono * properPoligono = (castItem1P != NULL) ? castItem1P : castItem2P;
    if ( properPoligono != NULL )
    {
        properPoligono->moveBy(0.1, 0.1);
        properPoligono->moveBy(-0.1, -0.1);
    }
    if(castItemA){
        castItemA->moveBy(0.1, 0.1);
        castItemA->moveBy(-0.1, -0.1);
    }
    if ( castItem1T )
    {
        castItem1T->moveBy(0.1, 0.1);
        castItem1T->moveBy(-0.1, -0.1);
    }
}