38 mPageSizeComboBox->addItem( size.displayName, size.name );
40 mPageSizeComboBox->addItem( tr(
"Custom" ) );
47 mPageOrientationComboBox->setCurrentIndex( mPageOrientationComboBox->findData( mPage->
orientation() ) );
49 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
50 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
53 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
54 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
59 connect( mPageSizeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::pageSizeChanged );
60 connect( mPageOrientationComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::orientationChanged );
62 connect( mWidthSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
63 connect( mHeightSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
64 connect( mWidthSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
65 connect( mHeightSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
66 connect( mExcludePageCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPagePropertiesWidget::excludeExportsToggled );
80 mExcludePageDDBtn->registerEnabledWidget( mExcludePageCheckBox,
false );
82 mSymbolButton->registerExpressionContextGenerator( mPage );
89 showCurrentPageSize();
92 void QgsLayoutPagePropertiesWidget::pageSizeChanged(
int )
94 mBlockPageUpdate =
true;
95 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
98 mLockAspectRatio->setEnabled(
true );
99 mSizeUnitsComboBox->setEnabled(
true );
100 mPageOrientationComboBox->setEnabled(
false );
104 mLockAspectRatio->setEnabled(
false );
105 mLockAspectRatio->setLocked(
false );
106 mSizeUnitsComboBox->setEnabled(
false );
107 mPageOrientationComboBox->setEnabled(
true );
109 const QgsLayoutSize convertedSize = mConverter.convert( size.
size, mSizeUnitsComboBox->unit() );
110 mSettingPresetSize =
true;
111 switch ( mPageOrientationComboBox->currentData().toInt() )
114 mWidthSpin->setValue( convertedSize.
height() );
115 mHeightSpin->setValue( convertedSize.
width() );
119 mWidthSpin->setValue( convertedSize.
width() );
120 mHeightSpin->setValue( convertedSize.
height() );
123 mSettingPresetSize =
false;
125 mBlockPageUpdate =
false;
129 void QgsLayoutPagePropertiesWidget::orientationChanged(
int )
131 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
134 const double width = mWidthSpin->value();
135 const double height = mHeightSpin->value();
136 switch ( mPageOrientationComboBox->currentData().toInt() )
139 if ( width < height )
147 if ( width > height )
158 void QgsLayoutPagePropertiesWidget::updatePageSize()
160 if ( mBlockPageUpdate )
163 mPage->layout()->undoStack()->beginMacro( tr(
"Change Page Size" ) );
164 mPage->layout()->pageCollection()->beginPageSizeChange();
165 mPage->layout()->undoStack()->beginCommand( mPage, tr(
"Change Page Size" ), 1 + mPage->layout()->pageCollection()->pageNumber( mPage ) );
166 mPage->setPageSize(
QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() ) );
167 mPage->layout()->undoStack()->endCommand();
168 mPage->layout()->pageCollection()->reflow();
169 mPage->layout()->pageCollection()->endPageSizeChange();
170 mPage->layout()->undoStack()->endMacro();
173 emit pageOrientationChanged();
176 void QgsLayoutPagePropertiesWidget::setToCustomSize()
178 if ( mSettingPresetSize )
180 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
181 mPageOrientationComboBox->setEnabled(
false );
182 pageSizeChanged( mPageSizeComboBox->currentIndex() );
185 void QgsLayoutPagePropertiesWidget::symbolChanged()
188 mPage->setPageStyleSymbol(
static_cast< QgsFillSymbol *
>( mSymbolButton->symbol() )->
clone() );
189 mPage->layout()->undoStack()->endCommand();
192 void QgsLayoutPagePropertiesWidget::excludeExportsToggled(
bool checked )
194 mPage->beginCommand( !checked ? tr(
"Include Page in Exports" ) : tr(
"Exclude Page from Exports" ) );
195 mPage->setExcludeFromExports( checked );
199 void QgsLayoutPagePropertiesWidget::refreshLayout()
201 mPage->layout()->refresh();
204 void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
208 if ( !pageSize.isEmpty() )
210 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
211 mLockAspectRatio->setEnabled(
false );
212 mLockAspectRatio->setLocked(
false );
213 mSizeUnitsComboBox->setEnabled(
false );
214 mPageOrientationComboBox->setEnabled(
true );
219 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
220 mLockAspectRatio->setEnabled(
true );
221 mSizeUnitsComboBox->setEnabled(
true );
222 mPageOrientationComboBox->setEnabled(
false );