Esempio n. 1
0
void WidgetStyle::WidgetScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    if(m_mouseButton == Qt::LeftButton)
    {
        QRectF rect = m_rectItem->rect();
        QPointF point = event->scenePos();

        if(point.x() >= m_topLeftRect.x() && point.y() >= m_topLeftRect.y())
        {
            rect.setTopLeft(m_topLeftRect);
            rect.setBottomRight(point);
        }
        else if(point.x() >= m_topLeftRect.x() && point.y() <= m_topLeftRect.y())
        {
            rect.setBottomLeft(m_topLeftRect);
            rect.setTopRight(point);
        }
        else if(point.x() <= m_topLeftRect.x() && point.y() >= m_topLeftRect.y())
        {
            rect.setTopRight(m_topLeftRect);
            rect.setBottomLeft(point);
        }
        else if(point.x() <= m_topLeftRect.x() && point.y() <= m_topLeftRect.y())
        {
            rect.setBottomRight(m_topLeftRect);
            rect.setTopLeft(point);
        }
        m_rectItem->setRect(rect);
        m_wgtStyle->distinguishRect(rect);
    }
    QGraphicsScene::mouseMoveEvent(event);
}
Esempio n. 2
0
void eraseRegionObjectGroup(MapDocument *mapDocument,
                            ObjectGroup *layer,
                            const QRegion &where)
{
    QUndoStack *undo = mapDocument->undoStack();

    const auto objects = layer->objects();
    for (MapObject *obj : objects) {
        // TODO: we are checking bounds, which is only correct for rectangles and
        // tile objects. polygons and polylines are not covered correctly by this
        // erase method (we are in fact deleting too many objects)
        // TODO2: toAlignedRect may even break rects.

        // Convert the boundary of the object into tile space
        const QRectF objBounds = obj->boundsUseTile();
        QPointF tl = mapDocument->renderer()->pixelToTileCoords(objBounds.topLeft());
        QPointF tr = mapDocument->renderer()->pixelToTileCoords(objBounds.topRight());
        QPointF br = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomRight());
        QPointF bl = mapDocument->renderer()->pixelToTileCoords(objBounds.bottomLeft());

        QRectF objInTileSpace;
        objInTileSpace.setTopLeft(tl);
        objInTileSpace.setTopRight(tr);
        objInTileSpace.setBottomRight(br);
        objInTileSpace.setBottomLeft(bl);

        const QRect objAlignedRect = objInTileSpace.toAlignedRect();
        if (where.intersects(objAlignedRect))
            undo->push(new RemoveMapObject(mapDocument, obj));
    }
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
bool core::Connector::eventFilter(QObject *sender, QEvent *event)
{
//	qDebug () << event->type();
	if(event->type() == QEvent::MouseMove){
		QMouseEvent *hEvent = (QMouseEvent*)event;

		GraphicDetailedView *gdv = (GraphicDetailedView*)sender;

		QPointF pos = mapFromScene(gdv->mapToScene(hEvent->pos()));
		currentMousePos = pos;

//		qDebug() << currentMousePos << "<< currentMousePos";

		QRectF container = getContainerRect();

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

		setContainerRect(container);

		if(isBuildingConector){
			updateConectorLine(beginPoint, pos);
		}

		return true;
	}

	return GraphicObject::eventFilter(sender, event);
}
Esempio n. 5
0
void PrintTool::updateDragging(MapCoordF mouse_pos_map)
{
	QPointF delta = QPointF(mouse_pos_map - click_pos_map);
	QRectF area = map_printer->getPrintArea();
	switch (region)
	{
		case Inside:
			area.moveTopLeft(area.topLeft() + delta);
			break;
		case LeftBorder:
			area.setLeft(area.left() + delta.rx());
			break;
		case TopLeftCorner:
			area.setTopLeft(area.topLeft() + delta);
			break;
		case TopBorder:
			area.setTop(area.top() + delta.ry());
			break;
		case TopRightCorner:
			area.setTopRight(area.topRight() + delta);
			break;
		case RightBorder:
			area.setRight(area.right() + delta.rx());
			break;
		case BottomRightCorner:
			area.setBottomRight(area.bottomRight() + delta);
			break;
		case BottomBorder:
			area.setBottom(area.bottom() + delta.ry());
			break;
		case BottomLeftCorner:
			area.setBottomLeft(area.bottomLeft() + delta);
			break;
		case Outside:
			Q_ASSERT(false); // Handled outside.
		case Unknown:
			; // Nothing
	}
	
	if (area.left() < area.right() && area.top() < area.bottom())
	{
		map_printer->setPrintArea(area);
		click_pos_map = mouse_pos_map;
	}
}
Esempio n. 6
0
void ResizingGrip::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    // ==========================================================================================
    // VERSION 1: Resize AreaItem and then move it to 0,0
    // ==========================================================================================

    QRectF  resizableZone = _areaItem->getRect().translated(_areaItem->scenePos());
    QPointF scenePos = event->scenePos();

    switch(_position)
    {
        case TOPLEFT:
            resizableZone.setTopLeft(scenePos);
            break;
        case TOPCENTER:
            resizableZone.setTop(scenePos.y());
            break;
        case TOPRIGHT:
            resizableZone.setTopRight(scenePos);
            break;
        case LEFTCENTER:
            resizableZone.setLeft(scenePos.x());
            break;
        case RIGHTCENTER:
            resizableZone.setRight(scenePos.x());
            break;
        case BOTTOMLEFT:
            resizableZone.setBottomLeft(scenePos);
            break;
        case BOTTOMCENTER:
            resizableZone.setBottom(scenePos.y());
            break;
        case BOTTOMRIGHT:
            resizableZone.setBottomRight(scenePos);
            break;
        default:
            Q_ASSERT(false);
    }

    //resizableZone.moveTopLeft(QPointF(0, 0));
    _areaItem->updateMainDiagram(resizableZone);

    event->accept();
}
Esempio n. 7
0
void LensItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
	QRectF r = rect();
	double dx = (mousePoint.x() - event->screenPos().x()) / scaling;
	if (handle == 0)
	{
		QPointF tl = r.topLeft();
		tl = tl - QPointF(dx, dx);
		r.setTopLeft(tl);
		setRect(r.normalized());
	}
	else if (handle == 1)
	{
		QPointF tl = r.topRight();
		tl = tl - QPointF(dx, -dx);
		r.setTopRight(tl);
		setRect(r.normalized());
	}
	else if (handle == 2)
	{
		QPointF tl = r.bottomRight();
		tl = tl - QPointF(dx, dx);
		r.setBottomRight(tl);
		setRect(r.normalized());
	}
	else if (handle == 3)
	{
		QPointF tl = r.bottomLeft();
		tl = tl - QPointF(dx, -dx);
		r.setBottomLeft(tl);
		setRect(r.normalized());
	}
	else
		QGraphicsItem::mouseMoveEvent(event);
	mousePoint = event->screenPos();
	dialog->lensSelected(this);
}
Esempio n. 8
0
    //! Takes care of handle resizing on mouse move event.
    void Painting::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    {
        if(m_activeHandle == Caneda::NoHandle) {
            GraphicsItem::mouseMoveEvent(event);
            Q_ASSERT(scene()->mouseGrabberItem() == this);
            return;
        }

        if(event->buttons().testFlag(Qt::LeftButton)) {
            QRectF rect = m_paintingRect;
            QPointF point = event->pos();

            switch(m_activeHandle) {
            case Caneda::TopLeftHandle:
                rect.setTopLeft(point);
                break;

            case Caneda::TopRightHandle:
                rect.setTopRight(point);
                break;

            case Caneda::BottomLeftHandle:
                rect.setBottomLeft(point);
                break;

            case Caneda::BottomRightHandle:
                rect.setBottomRight(point);
                break;

            case Caneda::NoHandle:
                break;
            }

            setPaintingRect(rect);
        }
    }
Esempio 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);
}
Esempio n. 10
0
void AbstractGraphicsRectItem::updateTopRight(const QPointF &newPos)
{
    QRectF r = rect();
    r.setTopRight(mapFromScene(newPos));
    updateRect(r);
}
Esempio n. 11
0
void OverlayEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
	QGraphicsScene::mouseMoveEvent(e);

	if (e->isAccepted())
		return;

	if (qgpiSelected && (e->buttons() & Qt::LeftButton)) {
		e->accept();

		if (wfsHover == Qt::NoSection)
			return;

		QPointF delta = e->scenePos() - e->buttonDownScenePos(Qt::LeftButton);

		bool square = e->modifiers() & Qt::ShiftModifier;

		QRectF orig = selectedRect();
		switch (wfsHover) {
			case Qt::TitleBarArea:
				orig.translate(delta);
				break;
			case Qt::TopSection:
				orig.setTop(orig.top() + delta.y());
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (square)
					orig.setRight(orig.left() + orig.height());
				break;
			case Qt::BottomSection:
				orig.setBottom(orig.bottom() + delta.y());
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (square)
					orig.setRight(orig.left() + orig.height());
				break;
			case Qt::LeftSection:
				orig.setLeft(orig.left() + delta.x());
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square)
					orig.setBottom(orig.top() + orig.width());
				break;
			case Qt::RightSection:
				orig.setRight(orig.right() + delta.x());
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square)
					orig.setBottom(orig.top() + orig.width());
				break;
			case Qt::TopLeftSection:
				orig.setTopLeft(orig.topLeft() + delta);
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(-size, -size);
					orig.setTopLeft(orig.bottomRight() + sz);
				}
				break;
			case Qt::TopRightSection:
				orig.setTopRight(orig.topRight() + delta);
				if (orig.height() < 8.0f)
					orig.setTop(orig.bottom() - 8.0f);
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(size, -size);
					orig.setTopRight(orig.bottomLeft() + sz);
				}
				break;
			case Qt::BottomLeftSection:
				orig.setBottomLeft(orig.bottomLeft() + delta);
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (orig.width() < 8.0f)
					orig.setLeft(orig.right() - 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(-size, size);
					orig.setBottomLeft(orig.topRight() + sz);
				}
				break;
			case Qt::BottomRightSection:
				orig.setBottomRight(orig.bottomRight() + delta);
				if (orig.height() < 8.0f)
					orig.setBottom(orig.top() + 8.0f);
				if (orig.width() < 8.0f)
					orig.setRight(orig.left() + 8.0f);
				if (square) {
					qreal size = qMin(orig.width(), orig.height());
					QPointF sz(size, size);
					orig.setBottomRight(orig.topLeft() + sz);
				}
				break;
			case Qt::NoSection:
				// Handled above, but this makes the compiler happy.
				return;
		}

		qgriSelected->setRect(orig);
	} else {
		updateCursorShape(e->scenePos());
	}
}
Esempio n. 12
0
File: node.cpp Progetto: nanox/tupi
void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    QPointF newPos(event->scenePos());

    if (k->notChange) {
        k->notChange = false;
    } else {
        if (k->action == Scale) {
            QRectF rect = k->parent->sceneBoundingRect();
            QRectF parentRect  = k->parent->sceneBoundingRect();
            QRectF parentSquare  = k->parent->boundingRect();
            
            // SQA: Lines for debugging purposes
            /*
            scene()->addRect(rect, QPen(Qt::red));
            scene()->addRect(parentRect, QPen(Qt::green));
            */
            
            switch (k->typeNode) {
                    case TopLeft:
                    {
                         k->manager->setAnchor(parentSquare.bottomRight());
                         rect.setTopLeft(newPos);
                         break;
                    }
                    case TopRight:
                    {
                         k->manager->setAnchor(parentSquare.bottomLeft());
                         rect.setTopRight(newPos);
                         break;
                    }
                    case BottomRight:
                    {
                         k->manager->setAnchor(parentSquare.topLeft());
                         rect.setBottomRight(newPos);
                         break;
                    }
                    case BottomLeft:
                    {
                         k->manager->setAnchor(parentSquare.topRight());
                         rect.setBottomLeft(newPos);
                         break;
                    }
                    case Center:
                    {
                         break;
                    }
            };
            
            float sx = 1, sy = 1;
            sx = static_cast<float>(rect.width()) / static_cast<float>(parentRect.width());
            sy = static_cast<float>(rect.height()) / static_cast<float>(parentRect.height());

            if (k->manager->proportionalScale()) {
                k->manager->scale(sx, sx);
            } else {
                if (sx > 0 && sy > 0) {
                    k->manager->scale(sx, sy);
                } else {
                    if (sx > 0)
                        k->manager->scale(sx, 1);

                    if (sy > 0)
                        k->manager->scale(1, sy);
                }
            }
        } else if (k->action == Rotate) {
                   QPointF p1 = newPos;
                   QPointF p2 = k->parent->sceneBoundingRect().center();
                   k->manager->setAnchor(k->parent->boundingRect().center());
                
                   double a = (180 * TupGraphicalAlgorithm::angleForPos(p1, p2)) / M_PI;
                   k->manager->rotate(a-45);
        }
    }

    if (k->typeNode == Center) {
        k->parent->moveBy(event->scenePos().x() - scenePos().x() , event->scenePos().y() - scenePos().y());
        event->accept();
    }
}
Esempio n. 13
0
void EnvRoomTemplate::LoadData(const QString & filename)
{

    QFile file( filename );
    if (!file.open( QIODevice::ReadOnly | QIODevice::Text )) {
        return;
    }

    //set base path (for loading resources in same dir)
    QTextStream ifs(&file);

    //get num colliders
    QStringList eachline = ifs.readLine().split(" ");
    const int nColliders = eachline.last().toInt();

    //read rectangular colliders
    for (int i=0; i<nColliders; ++i) {

        eachline = ifs.readLine().split(" ");

        if (eachline[0].compare("CIRCLE") == 0) {

            CircCollider c;

            c.pos = QPointF(eachline[1].toFloat(), eachline[2].toFloat());
            c.rad = eachline[3].toFloat();
            if (eachline[4].compare("IN") == 0) {
                c.rad -= 1.0f;
                c.stay_inside = true;
            }
            else {
                c.rad += 1.0f;
                c.stay_inside = false;
            }

            circ_colliders.push_back(c);

        }
        else {

            const float x1 = eachline[0].toFloat();
            const float y1 = eachline[1].toFloat();
            const float x2 = eachline[2].toFloat();
            const float y2 = eachline[3].toFloat();

            //NOTE: colliders are padded by 1 unit to enforce player's size and prevent viewplane clipping
            QRectF c;
            c.setBottomLeft(QPointF(qMin(x1, x2) - 1, qMin(y1, y2) - 1));
            c.setTopRight(QPointF(qMax(x1, x2) + 1, qMax(y1, y2) + 1));
            colliders.push_back(c);

        }

    }

    //read mount points
    eachline = ifs.readLine().split(" ");
    const int nMounts = eachline.last().toInt();

    for (int i=0; i<nMounts; ++i) {

        eachline = ifs.readLine().split(" ");

        const float px = eachline[0].toFloat();
        const float py = eachline[1].toFloat();
        const float pz = eachline[2].toFloat();

        const float dx = eachline[3].toFloat();
        const float dy = eachline[4].toFloat();
        const float dz = eachline[5].toFloat();

        mount_pts.push_back(QVector3D(px, py, pz));
        mount_dirs.push_back(QVector3D(dx, dy, dz));

    }

    file.close();
}
Esempio n. 14
0
void KUnitItem::slotMouseMove(QGraphicsSceneMouseEvent *event)
{
    if (myMode == MouseMode_RESIZE)
    {
        QPointF curPoint(event->scenePos());
        QPointF curPointItem = this->mapFromScene(curPoint);

        bool flagx = lastPoint.x() > oppositePos.x();
        bool flagx1 = curPointItem.x() > oppositePos.x();
        bool flagy = lastPoint.y() > oppositePos.y();
        bool flagy1 = curPointItem.y() > oppositePos.y();


        qreal dist = 0;

        QRectF rectf;
        rectf.setRect(m_frame.x()
                      , m_frame.y()
                      , m_frame.width()
                      , m_frame.height());


        KResizeFocus::PosInHost pos = curResizeFocus->getInHost();
        if (pos == KResizeFocus::NORTH_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setY(curPointItem.y());
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::SOUTH_MIDDLE)
        {
            QPointF br = dashRect->rect().topRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::EAST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomLeft();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setWidth(dist);
        }
        else if(pos == KResizeFocus::WEST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setX(curPointItem.x());
            rectf.setWidth(dist);
        }
        else if(pos == KResizeFocus::NORTH_WEST)
        {
            QPointF topRight = dashRect->rect().topRight();
            QPointF bottomLeft = dashRect->rect().bottomLeft();

            qreal distx = Util::GetPointDistLine(oppositePos,topRight,curPointItem);
            qreal disty = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setTopLeft(curPointItem);
        }
        else if(pos == KResizeFocus::NORTH_EAST)
        {
            QPointF topLeft = dashRect->rect().topLeft();
            QPointF bottomRight = dashRect->rect().bottomRight();

            qreal distx = Util::GetPointDistLine(oppositePos,topLeft,curPointItem);
            qreal disty = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setTopRight(curPointItem);
        }
        else if(pos == KResizeFocus::SOUTH_EAST)
        {
            QPointF topRight = dashRect->rect().topRight();
            QPointF bottomLeft = dashRect->rect().bottomLeft();

            qreal disty = Util::GetPointDistLine(oppositePos,topRight,curPointItem);
            qreal distx = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setBottomRight(curPointItem);
        }
        else if(pos == KResizeFocus::SOUTH_WEST)
        {
            QPointF topLeft = dashRect->rect().topLeft();
            QPointF bottomRight = dashRect->rect().bottomRight();

            qreal disty = Util::GetPointDistLine(oppositePos,topLeft,curPointItem);
            qreal distx = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }
            rectf.setBottomLeft(curPointItem);
        }

        dashRect->setRect(rectf);
    }
    else if(myMode == MouseMode_ROTATE)
    {
        QPointF curPos = event->scenePos();
        QPointF cpos = this->mapToScene(frame().center());
//        qDebug()<<cpos;
		qreal angleLast = Util::ComputeAngle(mLastRotatePoint, cpos);
		qreal angleCur = Util::ComputeAngle(curPos, cpos);
        qreal angle = angleCur - angleLast;

        setAngle(angle);
        mLastRotatePoint = curPos;
        onRotate();
    }
    else if(myMode == MouseMode_MOVE)
    {
        onMoving();
    }
    else
    {
        QGraphicsItem::mouseMoveEvent(event);
    }
}
Esempio n. 15
0
void Level::rubeB2DLevel(b2dJson& mBox2dJson)
{
    if(mJsonFilePath.isEmpty()){
        qDebug() << " mJsonFilePath is empty ";
    }

    if(!Util::fileExists(mJsonFilePath)){
        qDebug() << " Level: "  << mJsonFilePath << " does not exists. ";
        return;
    }
    std::string worldJson = Util::readFileAsStdString(mJsonFilePath);

    std::string errorstring;
    b2World* w = mBox2dJson.readFromString(worldJson,errorstring,mWorld.get());

    if(w){
        //custom properties to be read
        int useWorldGravity = mBox2dJson.getCustomInt(w,"use_world_gravity",0);
        float grav_x ;
        float grav_y ;
        if(useWorldGravity){
            grav_x = mBox2dJson.getCustomFloat(w,"world_gravity_x",0);
            grav_y = mBox2dJson.getCustomFloat(w,"world_gravity_y",0);
             w->SetGravity(b2Vec2(grav_x,grav_y));
        }

        qDebug() << " Reading jsonfile Complete!  \n\t ";


        //check if there is a camera body
        //used for camera bounds. (Square body)
        b2Body* cam_body = mBox2dJson.getBodyByName("camera");
        if(cam_body){
            b2Fixture* cam_fixture = cam_body->GetFixtureList();
            if(cam_fixture){
                QRectF bbox = Box2dUtil::toQRectF(cam_fixture->GetAABB(0));
                this->setCameraBoundary(bbox);
                cam_body->SetActive(false);
#ifdef D_PARSE
                qDebug() << "Bounding box "<< bbox;
#endif
            }
#ifdef D_PARSE
            qDebug() << "camera found!";
#endif
        }

        //TODO: this is sooooo lazy,
        for(QVariant v:mLevelActorMapping){
            QMap<QString,QVariant> tmp = v.toMap();
            qDebug() << " Mapped LevelActorrr  " << tmp;

            mLevelActorMap.insert(tmp.firstKey(),tmp.first().toString());
        }


        Engine* engine = Engine::getInstance();
        QQmlEngine* qmlEngine = engine->getQmlEngine();

        // Check if bodies are referenced in the Actor Mapping Category
        Body* b = nullptr;
        std::string actorTypeString;
        b2Body* body = mWorld->GetBodyList();
        while(body){
            actorTypeString = mBox2dJson.getCustomString(body,"actorType");
            if(actorTypeString.empty() || actorTypeString == "none"){
                b = Body::BodyFromb2Body(body);
                if(b) b->setParent(this);
            }else{
                actorFromMapping(body,actorTypeString,qmlEngine);
            }
            body = body->GetNext();
        }

        // Use Nodes for parsing the specific type of node
        //QList<LevelNode*> nodes = findChildren<LevelNode*>();
        for(LevelNode* node: findChildren<LevelNode*>())  {
            switch(node->type())  {
                case LevelNode::BODY_REFERENCE:{
                    actorReferenceBody(node);
                }break;
                case LevelNode::ACTOR_COMPONENT_W_BODY:{
                    actorComponentWithBody(node,qmlEngine);
                }break;
                default:{
                    qDebug() << " unknown LevelNode type = " << node->type();
                }
            }
        }

       //check for images associated with the body.
       int imageCount = 0;
       body = nullptr;
       b = nullptr;
       QString image_path;
       Actor* actor = nullptr;
       ImageRenderer* img_renderer = nullptr;
       std::vector<b2dJsonImage*> world_images;
       imageCount = mBox2dJson.getAllImages(world_images);

       for(b2dJsonImage* img: world_images)
       {
           if((body = img->body))
           {
               b = static_cast<Body*>(img->body->GetUserData());
               if(b)
               {
                   image_path = Util::getPathToLevel(QString::fromStdString(img->file));
                   actor = new Actor(b);
                   actor->setPosition(b->getPosition());
                   actor->setParent(this);
                   actor->setParentItem(this);
                   img_renderer = new ImageRenderer(actor);
                   img_renderer->setSource(image_path);
                   img_renderer->setSizeScale(img->scale);
                   img_renderer->setVisible(true);
                   img_renderer->setCacheRenderParams(body->GetType() == Body::StaticBody);

                   QRectF c;
                   c.setTopLeft(Box2dUtil::toQPointF(img->corners[0]));
                   c.setTopRight(Box2dUtil::toQPointF(img->corners[1]));
                   c.setBottomRight(Box2dUtil::toQPointF(img->corners[2]));
                   c.setBottomLeft(Box2dUtil::toQPointF(img->corners[3]));
                   img_renderer->setCustomLocalBox(c);

#ifdef D_PARSE
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[0]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[1]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[2]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[3]);
                   qDebug() << image_path << " render localbox " << c;
                   //TODO: fixe the scale ratio, to match box2d.
                   b2AABB aabb = img->getAABB();
                   qDebug() <<"Image aabb = " << Box2dUtil::toQRectF(aabb);
                  // img_renderer->setPosition(QPointF(img->center.x,img->center.y ));
                   qDebug() << "Image pos = " <<img_renderer->position();
#endif
               }
           }
       }
    }else{
        qDebug() << "World null, Error Reading jsonfile: \n\t " << errorstring.c_str();
    }
    w = nullptr;
}
Esempio n. 16
0
void SchemaView::configureObject(void)
{
	Schema *schema=dynamic_cast<Schema *>(this->getSourceObject());

	this->fetchChildren();

	/* Only configures the schema view if the rectangle is visible and there are
		children objects. Otherwise the schema view is hidden */
	if(schema->isRectVisible() && !children.isEmpty())
	{
		QColor color;
		QRectF rect;
		QFont font;
		float sp_h=0, sp_v=0, txt_h=0;
    float x1=1000000, y1=1000000, x2=-1000000, y2=-1000000, width=0;
		QList<BaseObjectView *>::Iterator itr=children.begin();

		//Configures the bounding rect based upon the children dimension
		while(itr!=children.end())
		{
			rect.setTopLeft((*itr)->pos());
			rect.setSize((*itr)->boundingRect().size());

			if(rect.left() < x1)
				x1 = rect.left();
			if(rect.right() > x2)
				x2 = rect.right();

			if(rect.top() < y1)
				y1 = rect.top();
			if(rect.bottom() > y2)
				y2 = rect.bottom();

			itr++;
		}

    //Configures the schema name at the top
    sch_name->setText(/*Utf8String::create(*/schema->getName());
		font=BaseObjectView::getFontStyle(ParsersAttributes::GLOBAL).font();
		font.setItalic(true);
		font.setBold(true);
		font.setPointSizeF(font.pointSizeF() * 1.3f);

		sch_name->setFont(font);
    sch_name->setPos(HORIZ_SPACING, VERT_SPACING);
		txt_h=sch_name->boundingRect().height() + (2 * VERT_SPACING);

		//Configures the box with the points calculated above
    sp_h=(3 * HORIZ_SPACING);
    sp_v=(3 * VERT_SPACING) + txt_h;

    width=(x2-x1) + 1;

    if(width < sch_name->boundingRect().width())
      width=sch_name->boundingRect().width();

    rect.setTopLeft(QPointF(-sp_h, 0));
    rect.setTopRight(QPointF(width + sp_h, 0));
    rect.setBottomRight(QPointF(width + sp_h, y2-y1 + sp_v));
    rect.setBottomLeft(QPointF(-sp_h, y2-y1 + sp_v));
    box->setRect(rect);

		//Sets the schema view position
		this->setFlag(ItemSendsGeometryChanges, false);
		this->moveBy(-this->pos().x(),-this->pos().y());
		this->setPos(QPointF(x1, y1 - txt_h));
    schema->setPosition(this->mapToScene(rect.topLeft()));
		this->setFlag(ItemSendsGeometryChanges, true);

		color=schema->getFillColor();
    color.setAlpha(80);
		box->setBrush(color);

    color=QColor(color.red()/3,color.green()/3,color.blue()/3, 80);
		box->setPen(QPen(color, 1, Qt::DashLine));

		this->bounding_rect=rect;
		this->setVisible(true);

    this->setToolTip(/*Utf8String::create(*/schema->getName(true) +  QString(" (") + schema->getTypeName() + QString(")"));
		sch_name->setToolTip(this->toolTip());

    this->protected_icon->setPos(QPointF( sch_name->boundingRect().width() + sp_h,
                                          sch_name->pos().y() + VERT_SPACING ));

    this->configureObjectSelection();
    this->configureProtectedIcon();
    this->configurePositionInfo(this->pos());
    this->configureSQLDisabledInfo();
	}
	else
    this->setVisible(false);
}
Esempio n. 17
0
void ItemHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
    QGraphicsItem::mouseMoveEvent( e );
    if (!(m_itemView && m_active && e->buttons() & Qt::LeftButton))
        return;

    const QPointF rp = e->scenePos();
    const QPointF d = rp - m_origPressPos;

    switch (m_type) {

    case LeftTop: {
        m_geom.setTopLeft(m_origGeom.topLeft() + d);
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setTopLeft(absoluteGeometry.topLeft() + (rect.topLeft() - orig.topLeft()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.topLeft();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HVDirection);

            orig.setTopLeft(rect.topLeft() + point);
        } else
            orig.setTopLeft(rect.topLeft());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);

    } break;

    case Top: {
        m_geom.setTop(m_origGeom.top() + d.y());
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setTop(absoluteGeometry.top() + (rect.top() - orig.top()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.topLeft();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::VDirection);

            orig.setTop(rect.top()+ point.y());
        } else
            orig.setTop(rect.top());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);
    } break;

    case RightTop: {
        m_geom.setTopRight(m_origGeom.topRight() + d);
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setTopRight(absoluteGeometry.topRight() + (rect.topRight() - orig.topRight()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.topRight();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HVDirection);

            orig.setTopRight(rect.topRight()+ point);
        } else
            orig.setTopRight(rect.topRight());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);

    } break;

    case Right: {
        m_geom.setWidth(m_origGeom.width() + d.x());
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setRight(absoluteGeometry.right() + (rect.right() - orig.right()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.bottomRight();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HDirection);

            orig.setRight(rect.right()+ point.x());
        } else
            orig.setRight(rect.right());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);    } break;

    case RightBottom: {
        m_geom.setBottomRight(m_origGeom.bottomRight() + d);
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setBottomRight(absoluteGeometry.bottomRight() + (rect.bottomRight() - orig.bottomRight()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.bottomRight();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HVDirection);

            orig.setBottomRight(rect.bottomRight() +point);
        } else
            orig.setBottomRight(rect.bottomRight());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);
    } break;

    case Bottom: {
        m_geom.setHeight(m_origGeom.height() + d.y());
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setBottom(absoluteGeometry.bottom() + (rect.bottom() - orig.bottom()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.bottomLeft();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::VDirection);

            orig.setBottom(rect.bottom()+ point.y());
        } else
            orig.setBottom(rect.bottom());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);
    } break;

    case LeftBottom: {
        m_geom.setBottomLeft(m_origGeom.bottomLeft()+ d);
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setBottomLeft(absoluteGeometry.bottomLeft() + (rect.bottomLeft() - orig.bottomLeft()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.bottomLeft();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HVDirection);

            orig.setBottomLeft(rect.bottomLeft() + point);
        } else
            orig.setBottomLeft(rect.bottomLeft());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);
    } break;

    case Left: {
        m_geom.setLeft(m_origGeom.left() + d.x());
        QRectF rect = convertUnit(m_geom, Pixel, m_itemView->coreItem()->page()->unit(), m_itemView->coreItem()->page()->dpi());
        QRectF orig = m_itemView->coreItem()->geometry();

        // TODO: optimize
        if (m_useMagnets) {
            QRectF absoluteGeometry = m_itemView->coreItem()->absoluteGeometry();
            absoluteGeometry.setLeft(absoluteGeometry.left() + (rect.left() - orig.left()));
            QList<QPointF> pointsList;
            QList<CuteReport::BaseItemInterface*> excludeItems;
            pointsList << absoluteGeometry.bottomLeft();
            excludeItems << m_itemView->coreItem();
            QPointF point = m_sel->pageGUI()->magnets()->delta(pointsList, excludeItems, Magnets::HDirection);

            orig.setLeft(rect.left()+ point.x());
        } else
            orig.setLeft(rect.left());

        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);

        //        orig.setLeft(rect.left());
        //        m_sel->pageGUI()->setItemAjustedGeometry(m_itemView->coreItem(), orig);
    } break;

    default: break;

    } // end switch

}