Shape2DRing::Shape2DRing(const Shape2DRing& ring): Shape2D(), m_outer_shape(ring.m_outer_shape->clone()), m_inner_shape(ring.m_inner_shape->clone()), m_xWidth(ring.m_xWidth), m_yWidth(ring.m_yWidth) { resetBoundingRect(); }
Shape2DRing::Shape2DRing(Shape2D* shape, double xWidth, double yWidth): m_outer_shape(shape), m_xWidth(xWidth), m_yWidth(yWidth) { m_inner_shape = m_outer_shape->clone(); m_inner_shape->getBoundingRect(); m_inner_shape->adjustBoundingRect(m_xWidth,m_yWidth,-m_xWidth,-m_yWidth); resetBoundingRect(); m_outer_shape->setFillColor(QColor()); m_inner_shape->setFillColor(QColor()); }
void QgsLayoutItemGroup::attemptResize( const QgsLayoutSize &size, bool includesFrame ) { if ( !mLayout ) return; if ( !shouldBlockUndoCommands() ) mLayout->undoStack()->beginMacro( tr( "Resize Group" ) ); QRectF oldRect = rect(); QSizeF newSizeLayoutUnits = mLayout->convertToLayoutUnits( size ); QRectF newRect; newRect.setSize( newSizeLayoutUnits ); //also resize all items within the group for ( QgsLayoutItem *item : qgis::as_const( mItems ) ) { if ( !item ) continue; std::unique_ptr< QgsAbstractLayoutUndoCommand > command; if ( !shouldBlockUndoCommands() ) { command.reset( createCommand( QString(), 0 ) ); command->saveBeforeState(); } QRectF itemRect = mapRectFromItem( item, item->rect() ); QgsLayoutUtils::relativeResizeRect( itemRect, oldRect, newRect ); itemRect = itemRect.normalized(); QPointF newPos = mapToScene( itemRect.topLeft() ); QgsLayoutSize itemSize = mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() ); item->attemptResize( itemSize, includesFrame ); // translate new position to current item units QgsLayoutPoint itemPos = mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() ); item->attemptMove( itemPos, false ); if ( command ) { command->saveAfterState(); mLayout->undoStack()->push( command.release() ); } } QgsLayoutItem::attemptResize( size ); if ( !shouldBlockUndoCommands() ) mLayout->undoStack()->endMacro(); resetBoundingRect(); }
void Shape2D::setControlPoint(size_t i, const QPointF& pos) { if (i >= getNControlPoints()) { throw std::range_error("Control point index is out of range"); } if (i < 4) { m_boundingRect.setVertex(i, pos); refit(); } // else ? else setShapeControlPoint(i - NCommonCP, pos); resetBoundingRect(); }
SelectItem::SelectItem(QGraphicsItem *parent) : QGraphicsObject(parent), courses_(this), selectArrow_(this), song_(0), isChoosed_(false) { barLeftPixmap_ = PixmapManager::get(Ts::resSelectBarLeft); barMidPixmap_ = PixmapManager::get(Ts::resSelectBarMid); barRightPixmap_ = PixmapManager::get(Ts::resSelectBarRight); resetBoundingRect(); setCacheMode(DeviceCoordinateCache); selectArrow_.hide(); }
void QgsLayoutItemGroup::attemptMove( const QgsLayoutPoint &point, bool useReferencePoint, bool includesFrame, int page ) { Q_UNUSED( useReferencePoint ); //groups should always have reference point in top left if ( !mLayout ) return; if ( !shouldBlockUndoCommands() ) mLayout->undoStack()->beginMacro( tr( "Move group" ) ); QPointF scenePoint; if ( page < 0 ) scenePoint = mLayout->convertToLayoutUnits( point ); else scenePoint = mLayout->pageCollection()->pagePositionToLayoutPosition( page, point ); double deltaX = scenePoint.x() - pos().x(); double deltaY = scenePoint.y() - pos().y(); //also move all items within the group for ( QgsLayoutItem *item : qgis::as_const( mItems ) ) { if ( !item ) continue; std::unique_ptr< QgsAbstractLayoutUndoCommand > command; if ( !shouldBlockUndoCommands() ) { command.reset( createCommand( QString(), 0 ) ); command->saveBeforeState(); } item->attemptMoveBy( deltaX, deltaY ); if ( command ) { command->saveAfterState(); mLayout->undoStack()->push( command.release() ); } } //lastly move group item itself QgsLayoutItem::attemptMove( point, includesFrame ); if ( !shouldBlockUndoCommands() ) mLayout->undoStack()->endMacro(); resetBoundingRect(); }
void QgsLayoutItemGroup::finalizeRestoreFromXml() { QList<QgsLayoutItem *> items; mLayout->layoutItems( items ); for ( const QString &uuid : qgis::as_const( mItemUuids ) ) { for ( QgsLayoutItem *item : qgis::as_const( items ) ) { if ( item && ( item->mUuid == uuid /* TODO || item->mTemplateUuid == uuid */ ) ) { addItem( item ); break; } } } resetBoundingRect(); }
/// Rescale polygon's verices to fit to the new bounding rect. void Shape2DFree::refit() { auto brOld = getPolygonBoundingRect(); auto &brNew = m_boundingRect; if (brNew.xSpan() < 0.0) brNew.xFlip(); if (brNew.ySpan() < 0.0) brNew.yFlip(); auto xs0 = brNew.x0(); auto x0 = brOld.x0(); auto xScale = brNew.width() / brOld.width(); auto ys0 = brNew.y0(); auto y0 = brOld.y0(); auto yScale = brNew.height() / brOld.height(); for (int i = 0; i < m_polygon.size(); ++i) { auto &p = m_polygon[i]; p.rx() = xs0 + xScale * (p.x() - x0); p.ry() = ys0 + yScale * (p.y() - y0); } resetBoundingRect(); }
/// Subtract a polygon from this shape. void Shape2DFree::subtractPolygon(const QPolygonF& polygon) { m_polygon = m_polygon.subtracted(polygon); resetBoundingRect(); }
/// Add a polygon to this shape. void Shape2DFree::addPolygon(const QPolygonF& polygon) { m_polygon = m_polygon.united(polygon); resetBoundingRect(); }
/// Construct a zero-sized shape. Shape2DFree::Shape2DFree(const QPointF& p) : m_polygon(QRectF(p, p)) { resetBoundingRect(); }