Exemplo n.º 1
0
std::vector<QGraphicsLineItem*> GraphRenderer::addLines(
        const repo::core::model::RepoNode *node,
        const QGraphicsItem *nodeItem)
{
    std::vector<QGraphicsLineItem*> lines(node->getParentIDs().size());
    if (node)
    {
        QPen pen(Qt::lightGray);
        pen.setWidthF(penWidth);

        qreal halfDiameter = nodeDiameter/2;
        qreal halfPen = penWidth/2;

        int i = 0;
        for (repo::lib::RepoUUID parentID : node->getParentIDs())
        {
            QGraphicsItem *parentItem = painted[uuidToQString(parentID)];
            QGraphicsLineItem *line = addLine(
                        parentItem->scenePos().x() + halfDiameter,
                        parentItem->scenePos().y() + halfDiameter + halfPen,
                        nodeItem->scenePos().x() + halfDiameter,
                        nodeItem->scenePos().y() + halfDiameter + halfPen,
                        pen);
            line->setZValue(0.0f);
            lines[i++] = line;
        }
    }
    return lines;
}
Exemplo n.º 2
0
void DocumentView::moveSelectedItems (int x, int y, Qt::KeyboardModifiers keyModifiers)
{
    double xfactor = 1; 
    double yfactor = 1; 

    ReportGridOptions *rgo = _ds->gridOptions();
    if(rgo)
    {
        xfactor = 100 * rgo->xInterval();
        yfactor = 100 * rgo->yInterval();
    }

	QGraphicsItem *firstItem = NULL;
	QPointF lastPos;

    foreach(QGraphicsItem *item, items()) 
    {
        if(item->isSelected())
		{
			if(!firstItem)
			{
				firstItem = item;
				lastPos = item->scenePos();
			}
			item->moveBy(xfactor * x, yfactor * y);
		}
    }

	if(firstItem) 
	{
		_ds->setModified(true);
		if(y != 0)
			_ds->setSectionsColors(firstItem, lastPos, firstItem->scenePos(), keyModifiers);
	}
}
Exemplo n.º 3
0
void AirGunTurret::removeExtraShells()
{
    QMutableListIterator<QGraphicsItem *> i(*shellList);

     while (i.hasNext())
     {
         QGraphicsItem* shell = i.next();
         if ((shell->scenePos().x() > 800) || (shell->scene() == NULL))
         {
             i.remove();
             delete shell;
         }
     }
}
Exemplo n.º 4
0
void AreaWidget::doubleClickInit(AnimationItem *pItem)
{
    if(!pItem)
        return;
    QList <QGraphicsItem *> items = pItem->childItems();
    QGraphicsItem *group = NULL;
    int nCount = items.size();
    int i = 0;
    QString sName = "";
    int ikey = 0;
    m_Tinfo.clear();

    QRectF rc;
    for(i  = 0;i < nCount;i++)
    {
        group = items.at(i);
        sName = group->data(GROUP_NAME_KEY).toString();
        ikey = group->type();

        if(sName == tr("mMain")) //向量图控件
        {
//            rc = group->boundingRect();
//            ui->m_width->setValue(rc.width()); //初始化向量图的的宽度
//            ui->m_height->setValue(rc.height());//初始化向量图的的高度
//            iWidth = rc.width();
//            iHeight = rc.height();
        }
        else if(ikey == SAM_DRAW_OBJECT_ELIPSE) //记录每个点的位置
        {
            QPointF pos = group->boundingRect().topLeft()+group->scenePos();
            TrackPointInfo TrackPoint;
            TrackPoint.nXPos = pos.x();
            TrackPoint.nYPos = pos.y();
            m_Tinfo.append(TrackPoint);
        }
    }//end for

    if(2 != m_Tinfo.size())
    {
        return;
    }

    ui->m_XlineEdit->setText(QString::number(m_Tinfo[0].nXPos));
    ui->M_YlineEdit->setText(QString::number(m_Tinfo[0].nYPos));
    ui->m_WlineEdit->setText(QString::number(qAbs(m_Tinfo[1].nXPos - m_Tinfo[0].nXPos)));
    ui->m_HlineEdit->setText(QString::number(qAbs(m_Tinfo[1].nYPos - m_Tinfo[0].nYPos)));
}
Exemplo n.º 5
0
void ScatterWidget::doubleClickInit(AnimationItem *pItem)
{
    if(!pItem)
        return;
    QList <QGraphicsItem *> items = pItem->childItems();
    QGraphicsItem *group = NULL;
    int nCount = items.size();
    int i = 0;
    QString sName = "";
    int ikey = 0;
    m_Tinfo.clear();

    QRectF rc;
    for(i  = 0;i < nCount;i++)
    {
        group = items.at(i);
        sName = group->data(GROUP_NAME_KEY).toString();
        ikey = group->type();

        if(sName == tr("mMain")) //向量图控件
        {
//            rc = group->boundingRect();
//            ui->m_width->setValue(rc.width()); //初始化向量图的的宽度
//            ui->m_height->setValue(rc.height());//初始化向量图的的高度
//            iWidth = rc.width();
//            iHeight = rc.height();
        }
        else if(ikey == SAM_DRAW_OBJECT_ELIPSE) //记录每个点的位置
        {
            QPointF pos = group->boundingRect().topLeft()+group->scenePos();
            TrackPointInfo TrackPoint;
            TrackPoint.nXPos = pos.x();
            TrackPoint.nYPos = pos.y();
            m_Tinfo.append(TrackPoint);
        }
    }//end for

    ui->m_TrackspBox->setRange(0,m_Tinfo.size() - 1);
    for(i  = 0;i < m_Tinfo.size();i++)
    {
        m_Tinfo[i].nOrbitId = i;
    }
    ui->m_TrackspBox->setValue(0); //初始化轨迹点
    ui->m_xTracklineEdit->setText(QString::number(m_Tinfo.at(0).nXPos)); //初始化位置0的x坐标
    ui->m_yTracklineEdit->setText(QString::number(m_Tinfo.at(0).nYPos));//初始化位置1的y坐标
}
Exemplo n.º 6
0
void DocumentView::moveSelectedItems (int x, int y, Qt::KeyboardModifiers keyModifiers)
{
    double xfactor = 1; 
    double yfactor = 1; 

    ReportGridOptions *rgo = _ds->gridOptions();
    if(rgo)
    {
        xfactor = 100 * rgo->xInterval();
        yfactor = 100 * rgo->yInterval();
    }

	QGraphicsItem *firstItem = NULL;
	QPointF lastPos;

    foreach(QGraphicsItem *item, items()) 
    {
        if(item->isSelected())
		{
			if(!firstItem)
			{
				firstItem = item;
				lastPos = item->scenePos();
			}
			QPointF p = item->pos();
			QRectF sceneRec = item->sceneBoundingRect();
			item->setPos(	xfactor * qRound((sceneRec.left() + xfactor * x) / xfactor) + p.x() - sceneRec.left(),
							yfactor * qRound((sceneRec.top() + yfactor * y) / yfactor) + p.y() - sceneRec.top());
		}
    }

	if(firstItem) 
	{
		_ds->setModified(true);
		if(y != 0)
			_ds->setSectionsColors(firstItem, lastPos, firstItem->scenePos(), keyModifiers);
	}
}
Exemplo n.º 7
0
void DocumentView::moveSelectedItems (int x, int y, Qt::KeyboardModifiers keyModifiers)
{
    ReportGridOptions *rgo = _ds->gridOptions();
    QGraphicsItem *firstItem = NULL;
	QPointF lastPos;

    foreach(QGraphicsItem *item, items()) 
    {
        if(item->isSelected())
		{
			if(!firstItem)
			{
				firstItem = item;
				lastPos = item->scenePos();
			}
            QPointF p = item->pos();
            if(rgo && rgo->isSnap())
            {
                p += QPointF(x*100*rgo->xInterval(), y*100*rgo->yInterval());
                p = rgo->snapPoint(p);
            }
            else
            {
                p += QPointF(x, y);
            }
            item->setPos(p);
		}
    }

	if(firstItem) 
	{
		_ds->setModified(true);
		if(y != 0)
			_ds->setSectionsColors(firstItem, lastPos, firstItem->scenePos(), keyModifiers);
	}
}
Exemplo n.º 8
0
bool QNodeGraph::eventFilter(QObject *o, QEvent *e)
{
	QGraphicsSceneMouseEvent *me = (QGraphicsSceneMouseEvent*) e;

	switch ((int) e->type())
	{
        case QEvent::KeyPress:
            {
                QKeyEvent *k = static_cast<QKeyEvent *>(e);
                switch(k->key())
                {
                    case Qt::Key_P:
                        {
                            parseGraph();

                            break;
                        }
                    case Qt::Key_X:
                        {
                            BaseSDFOP* op = new Mandelbulb_SDFOP();
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                    case Qt::Key_C:
                        {
                            BaseSDFOP* op = new Union_SDFOP();
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                    case Qt::Key_V:
                        {
                            BaseSDFOP* op = new Sphere_SDFOP(1.0);
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                }
                break;
            }
        case QEvent::GraphicsSceneMousePress:
            {
                switch ((int) me->button())
                {
                    case Qt::LeftButton:
                        {
                            QGraphicsItem *item = itemAt(me->scenePos());
                            if (item && item->type() == QNEPort::Type)
                            {
                                conn = new QNEConnection(0);
                                scene->addItem(conn);
                                conn->setPort1((QNEPort*) item);
                                conn->setPos1(item->scenePos());
                                conn->setPos2(me->scenePos());
                                conn->updatePath();

//                                emit graphChanged();

                                return true;
                            } else if (item && item->type() == QNEBlock::Type)
                            {
                                /* if (selBlock)
                    selBlock->setSelected(); */
                                // selBlock = (QNEBlock*) item;


                            }
                            break;
                        }
                    case Qt::RightButton:
                        {
                            QGraphicsItem *item = itemAt(me->scenePos());
                            if (item && (item->type() == QNEConnection::Type || item->type() == QNEBlock::Type))
                            {
                                delete item;
                                emit graphChanged();
                            }
                            // if (selBlock == (QNEBlock*) item)
                            // selBlock = 0;

                            break;
                        }
                }
            }
        case QEvent::GraphicsSceneMouseMove:
            {
                if (conn)
                {
                    conn->setPos2(me->scenePos());
                    conn->updatePath();
                    return true;
                }
                break;
            }
        case QEvent::GraphicsSceneMouseRelease:
            {
                if (conn && me->button() == Qt::LeftButton)
                {
                    QGraphicsItem *item = itemAt(me->scenePos());
                    if (item && item->type() == QNEPort::Type)
                    {
                        QNEPort *port1 = conn->port1();
                        QNEPort *port2 = (QNEPort*) item;

                        if (port1->block() != port2->block() && port1->isOutput() != port2->isOutput() && !port1->isConnected(port2))
                        {
                            conn->setPos2(port2->scenePos());
                            conn->setPort2(port2);
                            conn->updatePath();
                            conn = 0;

                            emit graphChanged();

                            return true;
                        }
                    }

                    delete conn;
                    conn = 0;
                    return true;
                }
                break;
            }
    }
    return QObject::eventFilter(o, e);
}
Exemplo n.º 9
0
void NodeElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
	if (event->button() == Qt::RightButton) {
		event->accept();
		return;
	}

	// Folded elements can't be resized.
	// So drag state isn't important.
	if (mIsFolded) {
		mDragState = None;
	}

	QRectF newContents = mContents;
	QPointF newPos = mPos;

	// expanding containers are turned off
	// TODO: bring them back (but not their bugs =))
	bool needResizeParent = false;

	if (mDragState == None) {
		if (!(flags() & ItemIsMovable)) {
			return;
		}

		recalculateHighlightedNode(event->scenePos());

		// it is needed for sendEvent() to every isSelected element thro scene
		event->setPos(event->lastPos());

		Element::mouseMoveEvent(event);

		mGrid->mouseMoveEvent(event);
		newPos = pos();
	} else if (mElementImpl->isResizeable()) {
		setVisibleEmbeddedLinkers(false);

		needResizeParent = true;

		QPointF parentPos = QPointF(0, 0);
		QGraphicsItem *parItem = parentItem();
		if (parItem) {
			parentPos = parItem->scenePos();
		}

		qreal newX = event->pos().x();
		qreal newY = event->pos().y();

		switch (mDragState) {
		case TopLeft: {
			newContents.setTopLeft(event->pos() - event->lastPos());
			newPos = event->scenePos() - parentPos;
			break;
		}
		case Top: {
			newContents.setTop(newY);
			newPos = QPoint(pos().x(), event->scenePos().y() - parentPos.y());
			break;
		}
		case TopRight: {
			newContents.setTopRight(QPoint(newX, event->pos().y() - event->lastPos().y()));
			newPos = QPoint(newPos.x(), event->scenePos().y() - parentPos.y());
			break;
		}
		case Left: {
			newContents.setLeft(newX);
			newPos = QPoint(event->scenePos().x() - parentPos.x(), pos().y());
			break;
		}
		case Right: {
			newContents.setRight(newX);
			break;
		}
		case BottomLeft: {
			newContents.setBottomLeft(QPoint(event->pos().x() - event->lastPos().x(), newY));
			newPos = QPoint(event->scenePos().x() - parentPos.x(), pos().y());
			break;
		}
		case Bottom: {
			newContents.setBottom(newY);
			break;
		}
		case BottomRight: {
			newContents.setBottomRight(QPoint(newX, newY));
			break;
		}
		case None:
			break;
		}

		if (event->modifiers() & Qt::ShiftModifier) {
			const qreal size = qMax(newContents.width(), newContents.height());
			newContents.setWidth(size);
			newContents.setHeight(size);
		}
	}

	resize(newContents, newPos, needResizeParent);
}
Exemplo n.º 10
0
bool QNodesEditor::eventFilter(QObject *o, QEvent *e)
{
	QGraphicsSceneMouseEvent *me = (QGraphicsSceneMouseEvent*) e;

	switch ((int) e->type())
	{
	case QEvent::GraphicsSceneMousePress:
	{

		switch ((int) me->button())
		{
		case Qt::LeftButton:
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && item->type() == QNEPort::Type)
			{
                conn = new QNEConnection(0);
                scene->addItem(conn);
				conn->setPort1((QNEPort*) item);
				conn->setPos1(item->scenePos());
				conn->setPos2(me->scenePos());
				conn->updatePath();

				return true;
			} else if (item && item->type() == QNEBlock::Type)
			{
				/* if (selBlock)
					selBlock->setSelected(); */
				// selBlock = (QNEBlock*) item;
			}
			break;
		}
		case Qt::RightButton:
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && (item->type() == QNEConnection::Type))
			{
				QNEConnection *conn = (QNEConnection *) item;
				QNEBlock *node1 = (QNEBlock *) conn->port1()->parentItem();
				QNEBlock *node2 = (QNEBlock *) conn->port2()->parentItem();

				for(INodesEditorListener *listener : listeners)
				{
					listener->connectionDeleted(node1, node2);
				}

				delete item;
			}
			else if(item && (item->type() == QNEBlock::Type))
			{
				QNEBlock *block = (QNEBlock *) item;
				for(INodesEditorListener *listener : listeners)
				{
					listener->nodeDeleted(block->id(), block->type());
				}


				delete item;
			}

			// if (selBlock == (QNEBlock*) item)
				// selBlock = 0;

			break;
		}
		}
		break;
	}
	case QEvent::GraphicsSceneMouseMove:
	{
		if (conn)
		{
			conn->setPos2(me->scenePos());
			conn->updatePath();
			return true;
		}
		break;
	}
	case QEvent::GraphicsSceneMouseRelease:
	{
		if (conn && me->button() == Qt::LeftButton)
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && item->type() == QNEPort::Type)
			{
				QNEPort *port1 = conn->port1();
				QNEPort *port2 = (QNEPort*) item;

				if (port1->block() != port2->block() && port1->isOutput() != port2->isOutput() && !port1->isConnected(port2))
				{
					conn->setPos2(port2->scenePos());
					conn->setPort2(port2);
					conn->updatePath();
					conn = 0;

					QNEBlock *node1 = (QNEBlock *) port1->parentItem();
					QNEBlock *node2 = (QNEBlock *) port2->parentItem();

					for(INodesEditorListener *listener : listeners)
					{
						listener->connectionMade(node1, node2);
					}

					return true;
				}
			}

			delete conn;
			conn = 0;
			return true;
		}
		break;
	}
	}
	return QObject::eventFilter(o, e);
}
Exemplo n.º 11
0
bool QNodeViewEditor::eventFilter(QObject* object, QEvent* event)
{
    QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);

    switch (static_cast<qint32>(event->type()))
    {
    case QEvent::GraphicsSceneMousePress:
    {
        switch (static_cast<qint32>(mouseEvent->button()))
        {
        case Qt::LeftButton:
        {
            QGraphicsItem* item = itemAt(mouseEvent->scenePos());
            if (!item)
                break;

            if (item->type() == QNodeViewType_Port)
            {
                m_connection = new QNodeViewConnection(NULL);
                m_scene->addItem(m_connection);
                m_connection->setStartPort(static_cast<QNodeViewPort*>(item));
                m_connection->setStartPosition(item->scenePos());
                m_connection->setEndPosition(mouseEvent->scenePos());
                m_connection->updatePath();
                return true;
            }
            else if (item->type() == QNodeViewType_Block)
            {
                // GW-TODO: Some form of property editor callback?
            }

            break;
        }

        case Qt::RightButton:
        {
            QGraphicsItem* item = itemAt(mouseEvent->scenePos());
            if (!item)
                break;

            const QPoint menuPosition = mouseEvent->screenPos();

            if (item->type() == QNodeViewType_Connection)
            {
                showConnectionMenu(menuPosition, static_cast<QNodeViewConnection*>(item));
            }
            else if (item->type() == QNodeViewType_Block)
            {
                showBlockMenu(menuPosition, static_cast<QNodeViewBlock*>(item));
            }
            else if (item->type() == QNodeViewType_ConnectionSplit)
            {
                QNodeViewConnectionSplit* split = static_cast<QNodeViewConnectionSplit*>(item);
                QNodeViewConnection* connection = split->connection();
                connection->splits().removeAll(split);
                delete split;
                connection->updatePath();
            }

            break;
        }
        }
    }

    case QEvent::GraphicsSceneMouseMove:
    {
        if (m_connection)
        {
            m_connection->setEndPosition(mouseEvent->scenePos());
            m_connection->updatePath();
            return true;
        }

        break;
    }

    case QEvent::GraphicsSceneMouseRelease:
    {
        if (m_connection && mouseEvent->button() == Qt::LeftButton)
        {
            QGraphicsItem* item = itemAt(mouseEvent->scenePos());
            if (item && item->type() == QNodeViewType_Port)
            {
                QNodeViewPort* startPort = m_connection->startPort();
                QNodeViewPort* endPort = static_cast<QNodeViewPort*>(item);

                if (startPort->block()    != endPort->block() &&
                        startPort->isOutput() != endPort->isOutput() &&
                        !startPort->isConnected(endPort))
                {
                    m_connection->setEndPosition(endPort->scenePos());
                    m_connection->setEndPort(endPort);
                    m_connection->updatePath();
                    m_connection = NULL;
                    return true;
                }
            }

            delete m_connection;
            m_connection = NULL;
            return true;
        }

        break;
    }
    }

    return QObject::eventFilter(object, event);
}