QRectF ObjectGroup::objectsBoundingRect() const { QRectF boundingRect; foreach (const MapObject *object, mObjects) boundingRect = boundingRect.united(object->bounds()); return boundingRect; }
static QRectF calculate_extent(QRectF r) { // 确保image的大小,从左上角的(0,0)位置位起点。 return r.united(QRectF(0, 0, 1, 1)); // 测试的范围 //return QRectF(0, 0, 1000, 10000); }
void TemplateSCgObjectsBuilder::buildObjects(const TypeToObjectsMap& objects) { mDecoratedBuilder->buildObjects(objects); QList<SCgObject*> l = mDecoratedBuilder->objects(); foreach(SCgObject* obj, l) if(! obj->parentItem()) obj->setDead(true); QRectF bounds; foreach(SCgObject* obj, l) bounds = bounds.united(obj->sceneBoundingRect()); foreach(SCgObject* obj, l) { if(! obj->parentItem()) obj->setPos(obj->scenePos() - bounds.topLeft()); } foreach(SCgObject* obj, l) { if( obj->type() == QGraphicsItem::UserType + 3 ) // type SCgPair obj->positionChanged(); } }
void QgsComposerArrow::setSceneRect( const QRectF& rectangle ) { //update rect for data defined size and position QRectF evaluatedRect = evalItemRect( rectangle ); if ( evaluatedRect.width() < 0 ) { mStartXIdx = 1 - mStartXIdx; } if ( evaluatedRect.height() < 0 ) { mStartYIdx = 1 - mStartYIdx; } double margin = computeMarkerMargin(); // Ensure the rectangle is at least as large as needed to include the markers QRectF rect = rectangle.united( QRectF( evaluatedRect.x(), evaluatedRect.y(), 2. * margin, 2. * margin ) ); // Compute new start and stop positions double x[2] = {rect.x(), rect.x() + rect.width()}; double y[2] = {rect.y(), rect.y() + rect.height()}; double xsign = x[mStartXIdx] < x[1 - mStartXIdx] ? 1.0 : -1.0; double ysign = y[mStartYIdx] < y[1 - mStartYIdx] ? 1.0 : -1.0; mStartPoint = QPointF( x[mStartXIdx] + xsign * margin, y[mStartYIdx] + ysign * margin ); mStopPoint = QPointF( x[1 - mStartXIdx] - xsign * margin, y[1 - mStartYIdx] - ysign * margin ); QgsComposerItem::setSceneRect( rect ); }
void MFreestyleLayoutPolicy::relayout() { Q_D(MFreestyleLayoutPolicy); QPointF topLeft = contentsArea().topLeft(); QList<QRectF> new_geometries; const int size = count(); for (int i = 0; i < size; ++i) { new_geometries << itemGeometry(i); d->placeItem(i, new_geometries, topLeft, contentsArea().width()); } QRectF area = contentsArea(); for (int i = 0; i < size; ++i) { area = area.united(new_geometries.at(i)); setItemGeometry(i, new_geometries.at(i)); } //if we have moved items outside of the bounding box, we need to invalidate the layout //causing another relayout, but we have to be careful that we don't end up in an //infinite loop because of this. if (area.isValid() && !contentsArea().adjusted(-0.0000001, -0.0000001, 0.0000001, 0.0000001).contains(area)) //adjust for rounding errors updateGeometry(); }
QSizeF MFreestyleLayoutPolicy::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_D(const MFreestyleLayoutPolicy); if (which == Qt::MaximumSize) { // maximum size is the QWIDGETSIZE_MAX QSizeF new_size = constraint; if (new_size.width() < 0) new_size.setWidth(QWIDGETSIZE_MAX); if (new_size.height() < 0) new_size.setHeight(QWIDGETSIZE_MAX); return new_size; } // minimum and preferred size of a layout is the bounding box of the children int i = count(); QRectF boundingBox; while (--i >= 0) { // iterate through children boundingBox = boundingBox.united(itemGeometry(i)); } qreal right, bottom; d->layout->getContentsMargins(NULL, NULL, &right, &bottom); return QSizeF(boundingBox.right() + right - d->layout->geometry().left(), boundingBox.bottom() + bottom - d->layout->geometry().top()); }
QRectF QgsLayout::pageItemBounds( int page, bool visibleOnly ) const { //start with an empty rectangle QRectF bounds; //add all QgsLayoutItems on page const QList<QGraphicsItem *> itemList = items(); for ( QGraphicsItem *item : itemList ) { const QgsLayoutItem *layoutItem = dynamic_cast<const QgsLayoutItem *>( item ); if ( layoutItem && layoutItem->type() != QgsLayoutItemRegistry::LayoutPage && layoutItem->page() == page ) { if ( visibleOnly && !layoutItem->isVisible() ) continue; //expand bounds with current item's bounds if ( bounds.isValid() ) bounds = bounds.united( item->sceneBoundingRect() ); else bounds = item->sceneBoundingRect(); } } return bounds; }
QRectF ShadowEffect::boundingRectFor(const QRectF &rect) const { qreal padding = m_blurRadius * 2; return rect.united( rect.translated(m_xOffset, m_yOffset) .adjusted(-padding, -padding, padding, padding) ); }
QRectF CopyFilterGUIConnectionItem::boundingRect() const { QRectF rect = QGraphicsLineItem::boundingRect(); QPointF p2 = line().p2(); QRectF rect2 = QRectF(p2.x() - maxArrowSize, p2.y() - maxArrowSize, 2 * maxArrowSize, 2 * maxArrowSize); return rect.united(rect2); }
void RuntimeController::Private::updateActiveRegion() { Configuration configuration = q->activeConfiguration(); // Calculate the bounding rect of all states in that are currently active QRectF activeRegion; foreach (State* state, configuration) { activeRegion = activeRegion.united(state->boundingRect()); }
void StitcherWorkspace::onStitchClicked() { QList<QGraphicsItem *> it = _stitcherView->items(); if(it.size() < 2) { return; } QRectF combined; for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { /* we have an image item */ ImageItem * ii = qgraphicsitem_cast<ImageItem *>(it[i]); combined = combined.united(ii->sceneBoundingRect()); } } /* we're gonna assume they all have the same scaling */ combined = _stitcherView->selectedImage()->mapRectFromScene(combined); qDebug("Combined with relative positions:"); Image * a = sp_image_alloc(combined.width(),combined.height(),1); for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { QPointF p = it[i]->mapToScene(0,0); QPointF local_p = _stitcherView->selectedImage()->mapFromScene(p); qDebug("x = %f y = %f",local_p.x()-combined.x(),local_p.y()-combined.y()); } } for(int x = 0; x<sp_image_x(a); x++) { for(int y = 0; y<sp_image_y(a); y++) { int mask = 0; Complex value = sp_cinit(0,0); QPointF p = _stitcherView->selectedImage()->mapToScene(QPointF(combined.x()+x,combined.y()+y)); for(int i = 0; i < it.size(); i++) { if(QString("ImageItem") == it[i]->data(0)) { /* we have an image item */ ImageItem * ii = qgraphicsitem_cast<ImageItem *>(it[i]); QPointF local_p = it[i]->mapFromScene(p); if(it[i]->contains(local_p)) { /* we're in business */ value = sp_cadd(value,sp_image_get(ii->getImage(),local_p.x(),local_p.y(),0)); mask++; } } } if(mask) { sp_cscale(value,1.0/mask); } a->detector->image_center[0] = -combined.x(); a->detector->image_center[1] = -combined.y(); a->detector->image_center[2] = 0; sp_image_set(a,x,y,0,value); sp_image_mask_set(a,x,y,0,mask); } } ImageItem * item = new ImageItem(a,QString(),_stitcherView,NULL); _stitcherView->addImage(item); item->update(); }
void ChatLog::updateMultiSelectionRect() { if (selectionMode == Multi && selFirstRow >= 0 && selLastRow >= 0) { QRectF selBBox; selBBox = selBBox.united(lines[selFirstRow]->sceneBoundingRect()); selBBox = selBBox.united(lines[selLastRow]->sceneBoundingRect()); if (selGraphItem->rect() != selBBox) scene->invalidate(selGraphItem->rect()); selGraphItem->setRect(selBBox); selGraphItem->show(); } else { selGraphItem->hide(); } }
QRectF PolyQtAnnotation::boundingRect() const { QRectF bRect; if (_annotation) { QRectF cpRect = _currentPath.controlPointRect(); QPointF tl = cpRect.topLeft() - QPointF(3 * _lineAnnotationSelectedThickness, 3 * _lineAnnotationSelectedThickness); QPointF br = cpRect.bottomRight() + QPointF(3 * _lineAnnotationSelectedThickness, 3 * _lineAnnotationSelectedThickness); bRect = bRect.united(QRectF(tl, br)); } return bRect; }
QRectF UBGraphicsProtractor::boundingRect() const { QPointF center = rect().center(); qreal centerX = center.x(); qreal centerY = center.y(); QRectF bounds = resizeButtonRect().adjusted(centerX, centerY, centerX, centerY); bounds = bounds.united(closeButtonRect().adjusted(centerX, centerY, centerX, centerY)); bounds = bounds.united(resetButtonRect().adjusted(centerX, centerY, centerX, centerY)); QTransform t; t.translate(centerX, centerY); t.rotate(-mStartAngle); t.translate(-centerX, -centerY); bounds = t.mapRect(bounds); bounds = bounds.united(QGraphicsEllipseItem::boundingRect()); return bounds; }
QRectF NonPdfCropping::frameRect () const { // The x(), y(), pos(), rect() and boundingRect() will return coordinates assuming origin at the initial position of // each handle. So to get the coordinates in the window reference frame it takes a two step process like // QGraphicsRectItem::mapRectToScene (QGraphicsRectItem::rect()) QRectF rectTL = m_handleTL->mapRectToScene (m_handleTL->boundingRect()); QRectF rectBR = m_handleBR->mapRectToScene (m_handleBR->boundingRect()); QRectF rectUnited = rectTL.united (rectBR); return rectUnited; }
QRectF KoShapeLayer::boundingRect() const { QRectF bb; Q_FOREACH (KoShape* shape, shapes()) { if (bb.isEmpty()) bb = shape->boundingRect(); else bb = bb.united(shape->boundingRect()); } return bb; }
QRectF QgsFillSymbolV2::polygonBounds( const QPolygonF& points, const QList<QPolygonF>* rings ) const { QRectF bounds = points.boundingRect(); if ( rings ) { QList<QPolygonF>::const_iterator it = rings->constBegin(); for ( ; it != rings->constEnd(); ++it ) { bounds = bounds.united(( *it ).boundingRect() ); } } return bounds; }
QRectF DrawViewCollection::getRect() const { QRectF result; for (auto& v:Views.getValues()) { TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v); if (!view) { throw Base::Exception("DrawViewCollection::getRect bad View\n"); } result = result.united(view->getRect().translated(view->X.getValue(),view->Y.getValue())); } return QRectF(0,0,Scale.getValue() * result.width(),Scale.getValue() * result.height()); }
//! //! Changes the viewing transformation so that the selected items are visible //! at maximum zoom level. //! void BaseGraphicsView::frameSelected () { // make sure there is a selection QList<QGraphicsItem *> selectedItems = scene()->selectedItems(); if (selectedItems.size() == 0) return; // obtain the bounding rectangle that encompasses all selected items QRectF boundingRect; foreach (QGraphicsItem *item, selectedItems) boundingRect = boundingRect.united(item->sceneBoundingRect()); frame(boundingRect); }
FlipMapObjects::FlipMapObjects(MapDocument *mapDocument, const QList<MapObject *> &mapObjects, FlipDirection flipDirection) : mMapDocument(mapDocument) , mMapObjects(mapObjects) , mFlipDirection(flipDirection) { setText(QCoreApplication::translate("Undo Commands", "Flip %n Object(s)", nullptr, mapObjects.size())); //computing objects center QRectF boundaryObjectsRect; for (MapObject *object : mMapObjects) { QTransform objectTransform; objectTransform.translate(object->x(), object->y()); objectTransform.rotate(object->rotation()); objectTransform.translate(-object->x(), -object->y()); if (!object->cell().isEmpty()) { //computing bound rect for cell QRectF cellRect = QRectF(object->x(), object->y(), object->width(), -object->height()).normalized(); boundaryObjectsRect = boundaryObjectsRect.united(objectTransform.mapRect(cellRect)); } else if (!object->polygon().empty()) { //computing bound rect for polygon const QPolygonF &objectPolygon = object->polygon(); QTransform polygonToMapTransform; polygonToMapTransform.translate(object->x(), object->y()); polygonToMapTransform.rotate(object->rotation()); boundaryObjectsRect = boundaryObjectsRect.united(polygonToMapTransform.mapRect(QRectF(objectPolygon.boundingRect()))); } else { //computing bound rect for other boundaryObjectsRect = boundaryObjectsRect.united(objectTransform.mapRect(object->bounds())); } } mObjectsCenter = boundaryObjectsRect.center(); }
QRectF QGIView::customChildrenBoundingRect() { QList<QGraphicsItem*> children = childItems(); int dimItemType = QGraphicsItem::UserType + 106; // TODO: Magic number warning. int borderItemType = QGraphicsItem::UserType + 136; // TODO: Magic number warning int labelItemType = QGraphicsItem::UserType + 135; // TODO: Magic number warning QRectF result; for (QList<QGraphicsItem*>::iterator it = children.begin(); it != children.end(); ++it) { if ( ((*it)->type() != dimItemType) && ((*it)->type() != borderItemType) && ((*it)->type() != labelItemType) ) { result = result.united((*it)->boundingRect()); } } return result; }
void KateTextAnimation::nextFrame(qreal value) { // cache previous rect for update const QRectF prevRect = rectForText(); m_value = value; // next rect is used to draw the text const QRectF nextRect = rectForText(); // due to rounding errors, increase the rect 1px to avoid artifacts const QRect updateRect = nextRect.united(prevRect).adjusted(-1, -1, 1, 1).toRect(); // request repaint m_view->update(updateRect); }
void RotationWidgetItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { if (d->elipse_pressed) { QPointF dif = event->scenePos() - event->lastScenePos(); moveBy(dif.x(), dif.y()); d->rotation_point_offset += dif; d->rotated_shape.translate(-dif); } else { // Calculate movement parameters QRectF refreshRect = this->boundingRect(); QPointF itemPos = d->viewportToItemPosition(event->screenPos(), event->widget()); QPointF currentPos = d->viewportToItemPosition(event->buttonDownScreenPos(Qt::LeftButton), event->widget()); qreal currentLength = qSqrt(currentPos.rx()*currentPos.rx()+currentPos.ry()*currentPos.ry()); qreal newLength = qSqrt(itemPos.rx()*itemPos.rx()+itemPos.ry()*itemPos.ry()); qreal scalar = currentPos.rx()*itemPos.rx()+currentPos.ry()*itemPos.ry(); // Calculate angle qreal cos = scalar/(currentLength*newLength); qreal prev_rotation_angle = d->rotation_angle; if (currentPos.rx()*itemPos.ry()-currentPos.ry()*itemPos.rx()>0) d->rotation_angle = 180*qAcos(cos)/M_PI; else d->rotation_angle = -180*qAcos(cos)/M_PI; // Rotation with 15 deegres step - Shift modifier if (event->modifiers() & Qt::ShiftModifier) d->rotation_angle = qRound(d->rotation_angle / 15) * 15.0; if (d->rotation_angle == prev_rotation_angle) return; QTransform transform; transform.rotate(d->rotation_angle-prev_rotation_angle); d->rotated_shape = transform.map(d->rotated_shape); // Updates widgets view refreshRect = refreshRect.united(this->boundingRect()); this->scene()->invalidate(d->itemToViewportRect(refreshRect, event->widget())); // Emits rotation signal emit rotationChanged(d->rotation_point+d->rotation_point_offset, d->rotation_angle-prev_rotation_angle); } event->accept(); }
void KisShapeSelectionModel::childChanged(KoShape * child, KoShape::ChangeType type) { if (!m_shapeSelection) return; if (type == KoShape::ParentChanged) return; QRectF changedRect = m_shapeMap[child]; changedRect = changedRect.united(child->boundingRect()); m_shapeMap[child] = child->boundingRect(); if (m_image.isValid()) { QTransform matrix; matrix.scale(m_image->xRes(), m_image->yRes()); changedRect = matrix.mapRect(changedRect); } requestUpdate(changedRect.toAlignedRect()); }
void CanvasMode_EditPolygon::applyValues(int polyC, double polyF, bool polyUseCF, double polyR, double polyCur, double polyIRot, double polyOCur) { PageItem *currItem = m_doc->m_Selection->itemAt(0); PageItem_RegularPolygon* item = currItem->asRegularPolygon(); QRectF oldRect = item->getBoundingRect(); polyCorners = polyC; polyFactor = polyF; polyRotation = polyR; polyCurvature = polyCur; polyInnerRot = polyIRot; polyOuterCurvature = polyOCur; if (UndoManager::undoEnabled()) { SimpleState *ss = new SimpleState(Um::EditPolygon,"",Um::IPolygon); ss->set("POLYGON","polygon"); ss->set("NEW_CORNER",polyC); ss->set("NEW_USEFACTOR",polyUseCF); ss->set("NEW_FACTOR",polyFactor); ss->set("NEW_ROTATION",polyRotation); ss->set("NEW_CURV",polyCurvature); ss->set("NEW_INNER",polyInnerRot); ss->set("NEW_OUTER",polyOuterCurvature); ss->set("OLD_CORNER",item->polyCorners); ss->set("OLD_USEFACTOR",item->polyUseFactor); ss->set("OLD_FACTOR",item->polyFactor); ss->set("OLD_ROTATION",item->polyRotation); ss->set("OLD_CURV",item->polyCurvature); ss->set("OLD_INNER",item->polyInnerRot); ss->set("OLD_OUTER",item->polyOuterCurvature); undoManager->action(currItem,ss); } item->polyCorners = polyC; item->polyUseFactor = polyUseCF; item->polyFactor = polyFactor; item->polyRotation = polyRotation; item->polyCurvature = polyCurvature; item->polyInnerRot = polyInnerRot; item->polyOuterCurvature = polyOuterCurvature; item->recalcPath(); updateFromItem(); QTransform itemMatrix = currItem->getTransform(); QPainterPath path = itemMatrix.map(RegularPolygonPath(item->width(), item->height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature)); QRectF updateRect = oldRect.united(path.boundingRect()); m_doc->regionsChanged()->update(updateRect.adjusted(-5, -5, 10, 10)); }
QRectF DSBBranch::getBbox() { // layout should have already been called QRectF rect = QRectF(0,0,0,0); QList<DSBNode*> own = getOwnNodes(); if (!own.empty()) { DSBNode *n = own.first(); rect = n->getBbox(); for (int i = 1; i < own.size(); i++) { n = own.at(i); QRectF r = n->getBbox(); rect = rect.united(r); } } return rect; }
QRectF QgsGCPCanvasItem::boundingRect() const { double residualLeft, residualRight, residualTop, residualBottom; QPointF residual; if ( mDataPoint ) { residual = mDataPoint->residual(); } //only considering screen resolution is ok for the bounding box function double rf = residualToScreenFactor(); if ( residual.x() > 0 ) { residualRight = residual.x() * rf + mResidualPen.widthF(); residualLeft = -mResidualPen.widthF(); } else { residualLeft = residual.x() * rf - mResidualPen.widthF(); residualRight = mResidualPen.widthF(); } if ( residual.y() > 0 ) { residualBottom = residual.y() * rf + mResidualPen.widthF(); residualTop = -mResidualPen.widthF(); } else { residualBottom = mResidualPen.widthF(); residualTop = residual.y() * rf - mResidualPen.widthF(); } QRectF residualArrowRect( QPointF( residualLeft, residualTop ), QPointF( residualRight, residualBottom ) ); QRectF markerRect( -2, -2, mTextBounds.width() + 6, mTextBounds.height() + 6 ); QRectF boundingRect = residualArrowRect.united( markerRect ); if ( !mTextBoxRect.isNull() ) { boundingRect = boundingRect.united( mTextBoxRect ); } return boundingRect; }
QRectF QgsLayout::layoutBounds( bool ignorePages, double margin ) const { //start with an empty rectangle QRectF bounds; //add all layout items and pages which are in the layout Q_FOREACH ( const QGraphicsItem *item, items() ) { const QgsLayoutItem *layoutItem = dynamic_cast<const QgsLayoutItem *>( item ); if ( !layoutItem ) continue; bool isPage = layoutItem->type() == QgsLayoutItemRegistry::LayoutPage; if ( !isPage || !ignorePages ) { //expand bounds with current item's bounds QRectF itemBounds; if ( isPage ) { // for pages we only consider the item's rect - not the bounding rect // as the bounding rect contains extra padding itemBounds = layoutItem->mapToScene( layoutItem->rect() ).boundingRect(); } else itemBounds = item->sceneBoundingRect(); if ( bounds.isValid() ) bounds = bounds.united( itemBounds ); else bounds = itemBounds; } } if ( bounds.isValid() && margin > 0.0 ) { //finally, expand bounds out by specified margin of page size double maxWidth = mPageCollection->maximumPageWidth(); bounds.adjust( -maxWidth * margin, -maxWidth * margin, maxWidth * margin, maxWidth * margin ); } return bounds; }
void Selection::finalize() { QRectF boundingRect; for (int i = 0; i < m_strokes.size(); ++i) { boundingRect = boundingRect.united(m_strokes[i].boundingRectSansPenWidth()); } // boundingRect.adjust(-m_ad, -m_ad, m_ad, m_ad); boundingRect.adjust(-m_x_padding, -m_y_padding, m_x_padding, m_y_padding); m_selectionPolygon = QPolygonF(boundingRect); setWidth(boundingRect.width()); setHeight(boundingRect.height()); m_angle = 0.0; m_finalized = true; }
void SGI_NetLabel::updateCacheAndRepaint() noexcept { prepareGeometryChange(); mRotate180 = (mNetLabel.getRotation().mappedTo180deg() <= -Angle::deg90() || mNetLabel.getRotation().mappedTo180deg() > Angle::deg90()); mStaticText.setText(mNetLabel.getNetSignal().getName()); mStaticText.prepare(QTransform(), mFont); mTextOrigin.setX(mRotate180 ? -mStaticText.size().width() : 0); mTextOrigin.setY(mRotate180 ? 0 : -0.5-mStaticText.size().height()); mStaticText.prepare(QTransform().rotate(mRotate180 ? 180 : 0) .translate(mTextOrigin.x(), mTextOrigin.y()), mFont); QRectF rect = QRectF(0, 0, mStaticText.size().width(), -mStaticText.size().height()).normalized(); qreal len = sOriginCrossLines[0].length(); mBoundingRect = rect.united(QRectF(-len/2, -len/2, len, len)).normalized(); update(); }