void QgsLayoutAddPagesDialog::pageSizeChanged( int ) { if ( mPageSizeComboBox->currentData().toString().isEmpty() ) { //custom size mLockAspectRatio->setEnabled( true ); mSizeUnitsComboBox->setEnabled( true ); mPageOrientationComboBox->setEnabled( false ); } else { mLockAspectRatio->setEnabled( false ); mLockAspectRatio->setLocked( false ); mSizeUnitsComboBox->setEnabled( false ); mPageOrientationComboBox->setEnabled( true ); QgsPageSize size = QgsApplication::pageSizeRegistry()->find( mPageSizeComboBox->currentData().toString() ).value( 0 ); QgsLayoutSize convertedSize = mConverter.convert( size.size, mSizeUnitsComboBox->unit() ); mSettingPresetSize = true; switch ( mPageOrientationComboBox->currentData().toInt() ) { case QgsLayoutItemPage::Landscape: mWidthSpin->setValue( convertedSize.height() ); mHeightSpin->setValue( convertedSize.width() ); break; case QgsLayoutItemPage::Portrait: mWidthSpin->setValue( convertedSize.width() ); mHeightSpin->setValue( convertedSize.height() ); break; } mSettingPresetSize = false; } }
void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements() { if ( !mItem ) { return; } auto block = [ = ]( bool blocked ) { mXPosSpin->blockSignals( blocked ); mYPosSpin->blockSignals( blocked ); mPosUnitsComboBox->blockSignals( blocked ); mWidthSpin->blockSignals( blocked ); mHeightSpin->blockSignals( blocked ); mSizeUnitsComboBox->blockSignals( blocked ); mUpperLeftRadioButton->blockSignals( blocked ); mUpperMiddleRadioButton->blockSignals( blocked ); mUpperRightRadioButton->blockSignals( blocked ); mMiddleLeftRadioButton->blockSignals( blocked ); mMiddleRadioButton->blockSignals( blocked ); mMiddleRightRadioButton->blockSignals( blocked ); mLowerLeftRadioButton->blockSignals( blocked ); mLowerMiddleRadioButton->blockSignals( blocked ); mLowerRightRadioButton->blockSignals( blocked ); mPageSpinBox->blockSignals( blocked ); }; block( true ); QgsLayoutPoint point = mItem->pagePositionWithUnits(); if ( !mFreezeXPosSpin ) mXPosSpin->setValue( point.x() ); if ( !mFreezeYPosSpin ) mYPosSpin->setValue( point.y() ); mPosUnitsComboBox->setUnit( point.units() ); switch ( mItem->referencePoint() ) { case QgsLayoutItem::UpperLeft: { mUpperLeftRadioButton->setChecked( true ); break; } case QgsLayoutItem::UpperMiddle: { mUpperMiddleRadioButton->setChecked( true ); break; } case QgsLayoutItem::UpperRight: { mUpperRightRadioButton->setChecked( true ); break; } case QgsLayoutItem::MiddleLeft: { mMiddleLeftRadioButton->setChecked( true ); break; } case QgsLayoutItem::Middle: { mMiddleRadioButton->setChecked( true ); break; } case QgsLayoutItem::MiddleRight: { mMiddleRightRadioButton->setChecked( true ); break; } case QgsLayoutItem::LowerLeft: { mLowerLeftRadioButton->setChecked( true ); break; } case QgsLayoutItem::LowerMiddle: { mLowerMiddleRadioButton->setChecked( true ); break; } case QgsLayoutItem::LowerRight: { mLowerRightRadioButton->setChecked( true ); break; } } QgsLayoutSize size = mItem->sizeWithUnits(); if ( !mFreezeWidthSpin ) mWidthSpin->setValue( size.width() ); if ( !mFreezeHeightSpin ) mHeightSpin->setValue( size.height() ); mSizeUnitsComboBox->setUnit( size.units() ); mSizeLockAspectRatio->resetRatio(); mPosLockAspectRatio->resetRatio(); if ( !mFreezePageSpin ) mPageSpinBox->setValue( mItem->page() + 1 ); block( false ); }
void QgsLayoutItemPropertiesDialog::setItemSize( QgsLayoutSize size ) { mWidthSpin->setValue( size.width() ); mHeightSpin->setValue( size.height() ); whileBlocking( mSizeUnitsComboBox )->setUnit( size.units() ); }
QSizeF QgsLayoutItemPicture::applyItemSizeConstraint( const QSizeF &targetSize ) { QSizeF currentPictureSize = pictureSize(); QSizeF newSize = targetSize; if ( mResizeMode == QgsLayoutItemPicture::Clip ) { mPictureWidth = targetSize.width(); mPictureHeight = targetSize.height(); } else { if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) ) { QSizeF targetImageSize; if ( qgsDoubleNear( mPictureRotation, 0.0 ) ) { targetImageSize = currentPictureSize; } else { //calculate aspect ratio of bounds of rotated image QTransform tr; tr.rotate( mPictureRotation ); QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) ); targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() ); } //if height has changed more than width, then fix width and set height correspondingly //else, do the opposite if ( std::fabs( rect().width() - targetSize.width() ) < std::fabs( rect().height() - targetSize.height() ) ) { newSize.setHeight( targetImageSize.height() * newSize.width() / targetImageSize.width() ); } else { newSize.setWidth( targetImageSize.width() * newSize.height() / targetImageSize.height() ); } } else if ( mResizeMode == FrameToImageSize ) { if ( !( currentPictureSize.isEmpty() ) ) { QgsLayoutSize sizeMM = mLayout->convertFromLayoutUnits( currentPictureSize, QgsUnitTypes::LayoutMillimeters ); newSize.setWidth( sizeMM.width() * 25.4 / mLayout->context().dpi() ); newSize.setHeight( sizeMM.height() * 25.4 / mLayout->context().dpi() ); } } //find largest scaling of picture with this rotation which fits in item if ( mResizeMode == Zoom || mResizeMode == ZoomResizeFrame ) { QRectF rotatedImageRect = QgsLayoutUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), QRectF( 0, 0, newSize.width(), newSize.height() ), mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); } else { mPictureWidth = newSize.width(); mPictureHeight = newSize.height(); } if ( newSize != targetSize ) { emit changed(); } } return newSize; }