31#include "moc_qgslayoutimageexportoptionsdialog.cpp"
33using namespace Qt::StringLiterals;
36 : QDialog( parent, flags )
37 , mFileExtension( fileExtension )
40 connect( mWidthSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged );
41 connect( mHeightSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged );
42 connect( mResolutionSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged );
44 connect( mClipToContentGroupBox, &QGroupBox::toggled,
this, &QgsLayoutImageExportOptionsDialog::clipToContentsToggled );
45 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayoutImageExportOptionsDialog::showHelp );
47 const bool showQuality = shouldShowQuality();
48 mQualitySpinBox->setVisible( showQuality );
49 mQualitySlider->setVisible( showQuality );
50 mQualityLabel->setVisible( showQuality );
51 mQualityLabel->setText( tr(
"%1 quality",
"Image format" ).arg( mFileExtension.toUpper() ) );
53 connect( mQualitySpinBox, qOverload<int>( &QSpinBox::valueChanged ), mQualitySlider, &QSlider::setValue );
54 connect( mQualitySlider, &QSlider::valueChanged, mQualitySpinBox, &QSpinBox::setValue );
63 if ( mImageSize.isValid() )
65 mWidthSpinBox->blockSignals(
true );
66 mHeightSpinBox->blockSignals(
true );
67 if ( mClipToContentGroupBox->isChecked() )
69 mWidthSpinBox->setValue( 0 );
70 mHeightSpinBox->setValue( 0 );
74 mWidthSpinBox->setValue( mImageSize.width() *
resolution / 25.4 );
75 mHeightSpinBox->setValue( mImageSize.height() *
resolution / 25.4 );
77 mWidthSpinBox->blockSignals(
false );
78 mHeightSpinBox->blockSignals(
false );
84 return mResolutionSpinBox->value();
90 mWidthSpinBox->blockSignals(
true );
91 mHeightSpinBox->blockSignals(
true );
92 mWidthSpinBox->setValue( size.width() * mResolutionSpinBox->value() / 25.4 );
93 mHeightSpinBox->setValue( size.height() * mResolutionSpinBox->value() / 25.4 );
94 mWidthSpinBox->blockSignals(
false );
95 mHeightSpinBox->blockSignals(
false );
100 return mWidthSpinBox->value();
105 return mHeightSpinBox->value();
110 mClipToContentGroupBox->setChecked( crop );
115 return mClipToContentGroupBox->isChecked();
120 mGenerateWorldFile->setChecked( generate );
125 return mGenerateWorldFile->isChecked();
130 mAntialiasingCheckBox->setChecked( antialias );
135 return mAntialiasingCheckBox->isChecked();
140 topMargin = mTopMarginSpinBox->value();
141 rightMargin = mRightMarginSpinBox->value();
142 bottomMargin = mBottomMarginSpinBox->value();
143 leftMargin = mLeftMarginSpinBox->value();
148 mTopMarginSpinBox->setValue( topMargin );
149 mRightMarginSpinBox->setValue( rightMargin );
150 mBottomMarginSpinBox->setValue( bottomMargin );
151 mLeftMarginSpinBox->setValue( leftMargin );
156 return mOpenAfterExportingCheckBox->isChecked();
161 mOpenAfterExportingCheckBox->setChecked( enabled );
166 if ( !shouldShowQuality() )
170 return mQualitySpinBox->value();
175 mQualitySpinBox->setValue(
quality );
178void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged(
int value )
180 mHeightSpinBox->blockSignals(
true );
181 mResolutionSpinBox->blockSignals(
true );
182 mHeightSpinBox->setValue( mImageSize.height() * value / mImageSize.width() );
183 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.width() );
184 mHeightSpinBox->blockSignals(
false );
185 mResolutionSpinBox->blockSignals(
false );
188void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged(
int value )
190 mWidthSpinBox->blockSignals(
true );
191 mResolutionSpinBox->blockSignals(
true );
192 mWidthSpinBox->setValue( mImageSize.width() * value / mImageSize.height() );
193 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.height() );
194 mWidthSpinBox->blockSignals(
false );
195 mResolutionSpinBox->blockSignals(
false );
198void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged(
int value )
200 mWidthSpinBox->blockSignals(
true );
201 mHeightSpinBox->blockSignals(
true );
202 if ( mClipToContentGroupBox->isChecked() )
204 mWidthSpinBox->setValue( 0 );
205 mHeightSpinBox->setValue( 0 );
209 mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
210 mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
212 mWidthSpinBox->blockSignals(
false );
213 mHeightSpinBox->blockSignals(
false );
216void QgsLayoutImageExportOptionsDialog::clipToContentsToggled(
bool state )
218 mWidthSpinBox->setEnabled( !state );
219 mHeightSpinBox->setEnabled( !state );
228 whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
229 whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
233void QgsLayoutImageExportOptionsDialog::showHelp()
238bool QgsLayoutImageExportOptionsDialog::shouldShowQuality()
const
240 const QStringList validExtensions = {
"jpeg",
"jpg" };
241 for (
const QString &ext : validExtensions )
243 if ( mFileExtension.toLower() == ext )
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
bool antialiasing() const
Returns whether antialiasing should be used in the export.
void setQuality(int quality)
Sets the image quality (for JPEG).
void setCropToContents(bool crop)
Sets whether the crop to contents option should be checked in the dialog.
void setImageSize(QSizeF size)
Sets the target image size.
void setAntialiasing(bool antialias)
Sets whether antialiasing should be used in the export.
int quality() const
Returns the image quality.
double resolution() const
Returns the selected resolution from the dialog.
QgsLayoutImageExportOptionsDialog(QWidget *parent=nullptr, const QString &fileExtension=QString(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutImageExportOptionsDialog.
int imageWidth() const
Returns the user-set image width in pixels.
bool cropToContents() const
Returns whether the crop to contents option is checked in the dialog.
void setOpenAfterExporting(bool enabled)
Sets whether to open the pdf after exporting it.
bool generateWorldFile() const
Returns whether the generate world file option is checked in the dialog.
void setCropMargins(int topMargin, int rightMargin, int bottomMargin, int leftMargin)
Sets the current crop to contents margin values, in pixels.
void setResolution(double resolution)
Sets the initial resolution displayed in the dialog.
void getCropMargins(int &topMargin, int &rightMargin, int &bottomMargin, int &leftMargin) const
Fetches the current crop to contents margin values, in pixels.
int imageHeight() const
Returns the user-set image height in pixels.
void setGenerateWorldFile(bool generate)
Sets whether the generate world file option should be checked.
bool openAfterExporting() const
Returns whether the pdf should be opened after exporting it.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.