void QgsLayoutItemPicture::setPictureRotation( double rotation ) { double oldRotation = mPictureRotation; mPictureRotation = rotation; if ( mResizeMode == Zoom ) { //find largest scaling of picture with this rotation which fits in item QSizeF currentPictureSize = pictureSize(); QRectF rotatedImageRect = QgsLayoutUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); update(); } else if ( mResizeMode == ZoomResizeFrame ) { QSizeF currentPictureSize = pictureSize(); QRectF oldRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() ); //calculate actual size of image inside frame QRectF rotatedImageRect = QgsLayoutUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), oldRotation ); //rotate image rect by new rotation and get bounding box QTransform tr; tr.rotate( mPictureRotation ); QRectF newRect = tr.mapRect( QRectF( 0, 0, rotatedImageRect.width(), rotatedImageRect.height() ) ); //keep the center in the same location newRect.moveCenter( oldRect.center() ); attemptSetSceneRect( newRect ); emit changed(); } emit pictureRotationChanged( mPictureRotation ); }
void QgsLayoutItemLabel::adjustSizeToText() { QSizeF newSize = sizeForText(); //keep alignment point constant double xShift = 0; double yShift = 0; itemShiftAdjustSize( newSize.width(), newSize.height(), xShift, yShift ); //update rect for data defined size and position attemptSetSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, newSize.width(), newSize.height() ) ); }
void QgsLayoutItemPicture::recalculateSize() { //call set scene rect with current position/size, as this will trigger the //picture item to recalculate its frame and image size attemptSetSceneRect( QRectF( pos().x(), pos().y(), rect().width(), rect().height() ) ); }