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); }
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); }
QRectF coils::boundingRect() const { QRectF rect; rect.setTopLeft(QPointF(-15,-15)); rect.setBottomRight(QPointF(15,15)); return rect; }
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)); } }
void BlurItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QGraphicsRectItem::mouseMoveEvent(event); const QPointF pos = event->scenePos(); QRectF r; r.setTopLeft(m_point); r.setBottomRight(event->scenePos()); if (r.width() < 0) { r.setLeft(pos.x()); r.setRight(m_point.x()); } if (r.height() < 0) { r.setTop(pos.y()); r.setBottom(m_point.y()); } r = r.intersected(m_item->scene()->sceneRect()); setRect(r); setSelected(true); m_item->setOffset(r.topLeft()); reload(m_pixmap); }
//! \brief Return bounding rectangle arround a wireline QRectF WireLine::boundingRect() const { QRectF rect; rect.setTopLeft(p1()); rect.setBottomRight(p2()); rect = rect.normalized(); rect.adjust(-m_adjust, -m_adjust, +m_adjust, +m_adjust); return rect; }
void GraphDraw::drawSquare(QPointF pt, double w) { painter.setRenderHint(QPainter::Antialiasing, false); QRectF rect; rect.setTopLeft(pt + QPointF(-w,-w)); rect.setBottomRight(pt + QPointF(w,w)); painter.drawRect(rect); }
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); }
static QRectF buildReferenceRect( const PolarCoordinatePlane* plane ) { QRectF contentsRect; QPointF referencePointAtTop = plane->translate( QPointF( 1, 0 ) ); QPointF temp = plane->translate( QPointF( 0, 0 ) ) - referencePointAtTop; const double offset = temp.y(); referencePointAtTop.setX( referencePointAtTop.x() - offset ); contentsRect.setTopLeft( referencePointAtTop ); contentsRect.setBottomRight( referencePointAtTop + QPointF( 2*offset, 2*offset) ); return contentsRect; }
void ResizeHandler::resizeAccordingToChildren(QRectF &newContents, QPointF &newPos) const { // Vector of minimum negative XY child deflection from top left corner. const QPointF childDeflectionVector = childDeflection(); moveChildren(-childDeflectionVector); newPos += childDeflectionVector; newContents.setBottomRight(newContents.bottomRight() - childDeflectionVector); expandByChildren(newContents); }
void ContentWindowGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { // handle mouse movements differently depending on selected mode of item if(!selected()) { if(event->buttons().testFlag(Qt::LeftButton)) { if(resizing_) { QRectF r = boundingRect(); QPointF eventPos = event->pos(); r.setBottomRight(eventPos); QRectF sceneRect = mapRectToScene(r); double w = sceneRect.width(); double h = sceneRect.height(); setSize(w, h); } else { QPointF delta = event->pos() - event->lastPos(); double new_x = coordinates_.x() + delta.x(); double new_y = coordinates_.y() + delta.y(); setPosition(new_x, new_y); } } } else { ContentWindowManagerPtr contentWindow = getContentWindowManager(); if(contentWindow) { // Zoom or forward event depending on type contentWindow->getInteractionDelegate().mouseMoveEvent(event); // force a redraw to update window info label update(); } } }
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; } }
void CVisSystemCanvasNote::mouseMoveEvent(QGraphicsSceneMouseEvent* me) { if(d->resizing) { QPointF dp = me->scenePos() - d->mousePos; prepareGeometryChange(); QRectF r = noteRect(); r.setBottomRight( r.bottomRight()+dp ); if(d->minimumSize.width() > r.width() || d->minimumSize.height() > r.height()) return; setNoteRect(r); d->mousePos = me->scenePos(); } else QGraphicsRectItem::mouseMoveEvent(me); }
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(); }
int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect ) { QList<QgsComposerItem*> selectedItems = selectedComposerItems(); if ( selectedItems.size() < 1 ) { return 1; } //set the box to the first item QgsComposerItem* currentItem = selectedItems.at( 0 ); double minX = currentItem->transform().dx(); double minY = currentItem->transform().dy(); double maxX = minX + currentItem->rect().width(); double maxY = minY + currentItem->rect().height(); double currentMinX, currentMinY, currentMaxX, currentMaxY; for ( int i = 1; i < selectedItems.size(); ++i ) { currentItem = selectedItems.at( i ); currentMinX = currentItem->transform().dx(); currentMinY = currentItem->transform().dy(); currentMaxX = currentMinX + currentItem->rect().width(); currentMaxY = currentMinY + currentItem->rect().height(); if ( currentMinX < minX ) minX = currentMinX; if ( currentMaxX > maxX ) maxX = currentMaxX; if ( currentMinY < minY ) minY = currentMinY; if ( currentMaxY > maxY ) maxY = currentMaxY; } bRect.setTopLeft( QPointF( minX, minY ) ); bRect.setBottomRight( QPointF( maxX, maxY ) ); return 0; }
void QgsMapCanvasItem::setRect( const QgsRectangle& rect ) { mRect = rect; //updatePosition(); QRectF r; // empty rect by default if ( !mRect.isEmpty() ) { r.setTopLeft( toCanvasCoordinates( QgsPoint( mRect.xMinimum(), mRect.yMinimum() ) ) ); r.setBottomRight( toCanvasCoordinates( QgsPoint( mRect.xMaximum(), mRect.yMaximum() ) ) ); r = r.normalized(); } // set position in canvas where the item will have coordinate (0,0) prepareGeometryChange(); setPos( r.topLeft() ); mItemSize = QSizeF( r.width() + 2, r.height() + 2 ); // QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height())); update(); }
void ExampleView::setDropTarget(const Element* el) { if (dropTarget != el) { if (dropTarget) { dropTarget->setDropTarget(false); dropTarget = 0; } dropTarget = el; if (dropTarget) { dropTarget->setDropTarget(true); } } if (!dropAnchor.isNull()) { QRectF r; r.setTopLeft(dropAnchor.p1()); r.setBottomRight(dropAnchor.p2()); dropAnchor = QLineF(); } if (dropRectangle.isValid()) { dropRectangle = QRectF(); } update(); }
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); }
//! 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); } }
void QSanCommandProgressBar::paintEvent(QPaintEvent *e) { m_mutex.lock(); int val = this->m_val; int max = this->m_max; m_mutex.unlock(); int width = this->width(); int height = this->height(); QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); if (orientation() == Qt::Vertical) { painter.translate(0, height); qSwap(width, height); painter.rotate(-90); } painter.drawPixmap(0, 0, width, height, m_progBg); double percent = 1 - (double)val / (double)max; QRectF rect = QRectF(0, 0, percent * width, height); //ÒÔrectµÄÓÒ±ßΪÖÐÖᣬ7Ϊ°ë¾¶»Ò»¸öÍÖÔ² QRectF ellipseRect; ellipseRect.setTopLeft(QPointF(rect.right() - 7, rect.top())); ellipseRect.setBottomRight(QPointF(rect.right() + 7, rect.bottom())); QPainterPath rectPath; QPainterPath ellipsePath; rectPath.addRect(rect); ellipsePath.addEllipse(ellipseRect); QPainterPath polygonPath = rectPath.united(ellipsePath); painter.setClipPath(polygonPath); painter.drawPixmap(0, 0, width, height, m_prog); }
void DesktopSelectionRectangle::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { if(event->buttons().testFlag(Qt::LeftButton)) { if(resizing_) { QRectF r = rect(); QPointF eventPos = event->pos(); r.setBottomRight(eventPos); setRect(r); } else { QPointF delta = event->pos() - event->lastPos(); moveBy(delta.x(), delta.y()); } updateCoordinates(); emit coordinatesChanged(x_, y_, width_, height_); } }
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); } }
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); }
void PolarGrid::drawGrid( PaintContext* context ) { // if ( d->coordinateTransformations.size () <= 0 ) return; PolarCoordinatePlane* plane = dynamic_cast<PolarCoordinatePlane*>(context->coordinatePlane()); Q_ASSERT_X ( plane, "PolarGrid::drawGrid", "Bad function call: PaintContext::coodinatePlane() NOT a polar plane." ); const GridAttributes gridAttrsCircular( plane->gridAttributes( true ) ); const GridAttributes gridAttrsSagittal( plane->gridAttributes( false ) ); //qDebug() << "OK:"; if ( !gridAttrsCircular.isGridVisible() && !gridAttrsSagittal.isGridVisible() ) return; //qDebug() << "A"; // FIXME: we paint the rulers to the settings of the first diagram for now: AbstractPolarDiagram* dgr = dynamic_cast<AbstractPolarDiagram*> (plane->diagrams().first() ); Q_ASSERT ( dgr ); // only polar diagrams are allowed here // Do not draw a grid for pie diagrams if( dynamic_cast<PieDiagram*> (plane->diagrams().first() ) ) return; context->painter()->setPen ( PrintingParameters::scalePen( QColor ( Qt::lightGray ) ) ); const double min = dgr->dataBoundaries().first.y(); QPointF origin = plane->translate( QPointF( min, 0 ) ) + context->rectangle().topLeft(); //qDebug() << "origin" << origin; const double r = qAbs( min ) + dgr->dataBoundaries().second.y(); // use the full extents if ( gridAttrsSagittal.isGridVisible() ){ const int numberOfSpokes = ( int ) ( 360 / plane->angleUnit() ); for ( int i = 0; i < numberOfSpokes ; ++i ) { context->painter()->drawLine( origin, plane->translate( QPointF( r - qAbs( min ), i ) ) + context->rectangle().topLeft() ); } } if ( gridAttrsCircular.isGridVisible() ) { const qreal startPos = plane->startPosition(); plane->setStartPosition( 0.0 ); const int numberOfGridRings = ( int )dgr->numberOfGridRings(); for ( int j = 0; j < numberOfGridRings; ++j ) { const double rad = min - ( ( j + 1) * r / numberOfGridRings ); if ( rad == 0 ) continue; QRectF rect; QPointF topLeftPoint; QPointF bottomRightPoint; topLeftPoint = plane->translate( QPointF( rad, 0 ) ); topLeftPoint.setX( plane->translate( QPointF( rad, 90 / plane->angleUnit() ) ).x() ); bottomRightPoint = plane->translate( QPointF( rad, 180 / plane->angleUnit() ) ); bottomRightPoint.setX( plane->translate( QPointF( rad, 270 / plane->angleUnit() ) ).x() ); rect.setTopLeft( topLeftPoint + context->rectangle().topLeft() ); rect.setBottomRight( bottomRightPoint + context->rectangle().topLeft() ); context->painter()->drawEllipse( rect ); } plane->setStartPosition( startPos ); } }
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; }
// Update the painter path void GLEEllipse::updateEllipse() { QPointF p; QPair<QPointF,int> snap; double angle; // Only do this if both the centre and radius have been set if (isSet(CentrePoint) && isSet(RadiusX) && isSet(RadiusY) && isSet(Angle)) { // This is guaranteed to have been created in the constructor // of GLEDrawingObject delete(paintPath); // Create a new path starting at ellipseCentre paintPath = new QPainterPath(getQtPoint(CentrePoint)); // Add the ellipse based on the qrect // This needs to be modified to suit the angle! // CHECK: I think we only use this for bounding boxes, // so just make a rectangle of the bounding box angle = getGLEAngle(Angle); // Get the bounding box of the ellipse QRectF rect; rect.setTopLeft(getQtPoint(BBoxCornerA)); rect.setBottomRight(getQtPoint(BBoxCornerB)); paintPath->addRect(rect); // Update GLE object GLEEllipseDO* ellipse = (GLEEllipseDO*)getGLEObject(); if (ellipse != NULL) { ellipse->setCenter(QGLE::QPointFToGLEPoint(getGLEPoint(CentrePoint))); ellipse->setRadiusX(getGLELength(RadiusX)); ellipse->setRadiusY(getGLELength(RadiusY)); } // Update the calculated equation parameters updateEquationParameters(); // Now we add the osnap handles osnapHandles.clear(); p.setX(getQtLength(RadiusX)*cos(M_PI-angle)); p.setY(getQtLength(RadiusX)*sin(M_PI-angle)); p += getQtPoint(CentrePoint); snap.first = p; snap.second = QGLE::QuadrantSnap; osnapHandles.append(snap); p.setX(-getQtLength(RadiusX)*cos(M_PI-angle)); p.setY(-getQtLength(RadiusX)*sin(M_PI-angle)); p += getQtPoint(CentrePoint); snap.first = p; snap.second = QGLE::QuadrantSnap; osnapHandles.append(snap); p.setX(-getQtLength(RadiusY)*sin(angle)); p.setY(-getQtLength(RadiusY)*cos(angle)); p += getQtPoint(CentrePoint); snap.first = p; snap.second = QGLE::QuadrantSnap; osnapHandles.append(snap); p.setX(getQtLength(RadiusY)*sin(angle)); p.setY(getQtLength(RadiusY)*cos(angle)); p += getQtPoint(CentrePoint); snap.first = p; snap.second = QGLE::QuadrantSnap; osnapHandles.append(snap); snap.first = getQtPoint(CentrePoint); snap.second = QGLE::CentreSnap; osnapHandles.append(snap); } }
void ContentWindowGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { // handle mouse movements differently depending on selected mode of item if(windowState_ == UNSELECTED) { if(event->buttons().testFlag(Qt::LeftButton) == true) { if(resizing_ == true) { QRectF r = rect(); QPointF eventPos = event->pos(); r.setBottomRight(eventPos); QRectF sceneRect = mapRectToScene(r); double w = sceneRect.width(); double h = sceneRect.height(); setSize(w, h); } else { QPointF delta = event->pos() - event->lastPos(); double x = x_ + delta.x(); double y = y_ + delta.y(); setPosition(x, y); } } } else if(windowState_ == SELECTED) { // handle zooms / pans QPointF delta = event->scenePos() - event->lastScenePos(); if(event->buttons().testFlag(Qt::RightButton) == true) { // increment zoom // if this is a touch event, use cross-product for determining change in zoom (counterclockwise rotation == zoom in, etc.) // otherwise, use y as the change in zoom double zoomDelta; if(event->modifiers().testFlag(Qt::AltModifier) == true) { zoomDelta = (event->scenePos().x()-0.5) * delta.y() - (event->scenePos().y()-0.5) * delta.x(); zoomDelta *= 2.; } else { zoomDelta = delta.y(); } double zoom = zoom_ * (1. - zoomDelta); setZoom(zoom); } else if(event->buttons().testFlag(Qt::LeftButton) == true) { // pan (move center coordinates) double centerX = centerX_ + 2.*delta.x() / zoom_; double centerY = centerY_ + 2.*delta.y() / zoom_; setCenter(centerX, centerY); } // force a redraw to update window info label update(); } else if(windowState_ == INTERACTION) { QRectF r = rect(); QPointF eventPos = event->pos(); InteractionState interactionState = interactionState_; interactionState.mouseX_ = (eventPos.x() - r.x()) / r.width(); interactionState.mouseY_ = (eventPos.y() - r.y()) / r.height(); if(event->buttons().testFlag(Qt::LeftButton) == true) interactionState.mouseLeft_ = true; else interactionState.mouseLeft_ = false; if(event->buttons().testFlag(Qt::MiddleButton) == true) interactionState.mouseMiddle_ = true; else interactionState.mouseMiddle_ = false; if(event->buttons().testFlag(Qt::RightButton) == true) interactionState.mouseRight_ = true; else interactionState.mouseRight_ = false; setInteractionState(interactionState); // force a redraw to update window info label update(); } }
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()); } }
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); }
void AbstractGraphicsRectItem::updateBottomRight(const QPointF &newPos) { QRectF r = rect(); r.setBottomRight(mapFromScene(newPos)); updateRect(r); }