29 #include <QDoubleValidator>
30 #include <QFileDialog>
32 #include <QImageReader>
33 #include <QMessageBox>
35 #include <QProgressDialog>
36 #include <QSvgRenderer>
44 mSvgSelectorWidget->setAllowParameters(
true );
45 mSvgSelectorWidget->sourceLineEdit()->setPropertyOverrideToolButtonVisible(
true );
46 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastSVGMarkerDir" ) );
65 connect( mPictureRotationSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged );
66 connect( mRotationFromComposerMapCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged );
67 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged );
68 connect( mAnchorPointComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged );
71 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged );
72 connect( mPictureRotationOffsetSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged );
73 connect( mNorthTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged );
77 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
78 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
80 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastComposerPictureDir" ) );
84 mFillColorButton->setAllowOpacity(
true );
85 mFillColorButton->setColorDialogTitle( tr(
"Select Fill Color" ) );
86 mFillColorButton->setContext( QStringLiteral(
"composer" ) );
87 mStrokeColorButton->setAllowOpacity(
true );
88 mStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
89 mStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
91 mFillColorDDBtn->registerLinkedWidget( mFillColorButton );
92 mStrokeColorDDBtn->registerLinkedWidget( mStrokeColorButton );
94 mNorthTypeComboBox->blockSignals(
true );
97 mNorthTypeComboBox->blockSignals(
false );
98 mPictureRotationOffsetSpinBox->setClearValue( 0.0 );
99 mPictureRotationSpinBox->setClearValue( 0.0 );
103 mainLayout->addWidget( mItemPropertiesWidget );
105 if ( mPicture->layout() )
107 mComposerMapComboBox->setCurrentLayout( mPicture->layout() );
112 setGuiElementValues();
126 if ( mItemPropertiesWidget )
130 void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged(
double d )
135 mPicture->setPictureRotation( d );
136 mPicture->endCommand();
140 void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged(
int )
147 mPicture->beginCommand( tr(
"Change Resize Mode" ) );
149 mPicture->endCommand();
159 mAnchorPointComboBox->setEnabled(
true );
163 mAnchorPointComboBox->setEnabled(
false );
167 void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged(
int )
174 mPicture->beginCommand( tr(
"Change Placement" ) );
176 mPicture->endCommand();
190 mPicture = qobject_cast< QgsLayoutItemPicture * >( item );
191 mItemPropertiesWidget->
setItem( mPicture );
199 setGuiElementValues();
204 void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged(
int state )
211 mPicture->beginCommand( tr(
"Toggle Rotation Sync" ) );
212 if ( state == Qt::Unchecked )
214 mPicture->setLinkedMap(
nullptr );
215 mPictureRotationSpinBox->setEnabled(
true );
216 mComposerMapComboBox->setEnabled(
false );
217 mNorthTypeComboBox->setEnabled(
false );
218 mPictureRotationOffsetSpinBox->setEnabled(
false );
219 mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
223 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mComposerMapComboBox->currentItem() );
224 mPicture->setLinkedMap( map );
225 mPictureRotationSpinBox->setEnabled(
false );
226 mNorthTypeComboBox->setEnabled(
true );
227 mPictureRotationOffsetSpinBox->setEnabled(
true );
228 mComposerMapComboBox->setEnabled(
true );
230 mPicture->endCommand();
233 void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
241 const QgsLayout *layout = mPicture->layout();
253 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
254 mPicture->setLinkedMap( map );
256 mPicture->endCommand();
259 void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
261 mPictureRotationSpinBox->blockSignals(
true );
262 mPictureRotationSpinBox->setValue( r );
263 mPictureRotationSpinBox->blockSignals(
false );
266 void QgsLayoutPictureWidget::setGuiElementValues()
271 mPictureRotationSpinBox->blockSignals(
true );
272 mComposerMapComboBox->blockSignals(
true );
273 mRotationFromComposerMapCheckBox->blockSignals(
true );
274 mNorthTypeComboBox->blockSignals(
true );
275 mPictureRotationOffsetSpinBox->blockSignals(
true );
276 mResizeModeComboBox->blockSignals(
true );
277 mAnchorPointComboBox->blockSignals(
true );
278 mFillColorButton->blockSignals(
true );
279 mStrokeColorButton->blockSignals(
true );
280 mStrokeWidthSpinBox->blockSignals(
true );
282 mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
284 mComposerMapComboBox->setItem( mPicture->linkedMap() );
286 if ( mPicture->linkedMap() )
288 mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
289 mPictureRotationSpinBox->setEnabled(
false );
290 mComposerMapComboBox->setEnabled(
true );
291 mNorthTypeComboBox->setEnabled(
true );
292 mPictureRotationOffsetSpinBox->setEnabled(
true );
296 mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
297 mPictureRotationSpinBox->setEnabled(
true );
298 mComposerMapComboBox->setEnabled(
false );
299 mNorthTypeComboBox->setEnabled(
false );
300 mPictureRotationOffsetSpinBox->setEnabled(
false );
302 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
303 mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
305 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
310 mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
315 mAnchorPointComboBox->setEnabled(
true );
319 mAnchorPointComboBox->setEnabled(
false );
322 switch ( mPicture->mode() )
326 mRadioSVG->setChecked(
true );
329 mRadioRaster->setChecked(
true );
333 mSvgSelectorWidget->setSvgPath( mPicture->picturePath() );
334 mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
336 updateSvgParamGui(
false );
337 mFillColorButton->setColor( mPicture->svgFillColor() );
338 mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
339 mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
341 mRotationFromComposerMapCheckBox->blockSignals(
false );
342 mPictureRotationSpinBox->blockSignals(
false );
343 mComposerMapComboBox->blockSignals(
false );
344 mNorthTypeComboBox->blockSignals(
false );
345 mPictureRotationOffsetSpinBox->blockSignals(
false );
346 mResizeModeComboBox->blockSignals(
false );
347 mAnchorPointComboBox->blockSignals(
false );
348 mFillColorButton->blockSignals(
false );
349 mStrokeColorButton->blockSignals(
false );
350 mStrokeWidthSpinBox->blockSignals(
false );
356 void QgsLayoutPictureWidget::updateSvgParamGui(
bool resetValues )
361 const QString picturePath = mPicture->picturePath();
364 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
365 QColor defaultFill, defaultStroke;
366 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
367 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
369 hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
370 hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
371 hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
372 hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
376 QColor fill = mFillColorButton->color();
377 const double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
378 if ( hasDefaultFillColor )
382 fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
383 mFillColorButton->setColor( fill );
385 mFillColorButton->setEnabled( hasFillParam );
386 mFillColorDDBtn->setEnabled( hasFillParam );
387 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
390 QColor stroke = mStrokeColorButton->color();
391 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
392 if ( hasDefaultStrokeColor )
394 stroke = defaultStroke;
396 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
397 mStrokeColorButton->setColor( stroke );
399 mStrokeColorButton->setEnabled( hasStrokeParam );
400 mStrokeColorDDBtn->setEnabled( hasStrokeParam );
401 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
402 if ( hasDefaultStrokeWidth && resetValues )
404 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
406 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
407 mStrokeWidthDDBtn->setEnabled( hasStrokeWidthParam );
410 void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
413 mPicture->setSvgFillColor( color );
414 mPicture->endCommand();
418 void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
421 mPicture->setSvgStrokeColor( color );
422 mPicture->endCommand();
426 void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
429 mPicture->setSvgStrokeWidth( d );
430 mPicture->endCommand();
434 void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
437 mPicture->setNorthOffset( d );
438 mPicture->endCommand();
442 void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
444 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
446 mPicture->endCommand();
450 void QgsLayoutPictureWidget::modeChanged(
bool checked )
455 const bool svg = mRadioSVG->isChecked();
463 mSvgSelectorWidget->setBrowserVisible( svg );
464 mSvgSelectorWidget->setAllowParameters( svg );
465 mSVGParamsGroupBox->setVisible( svg );
467 if ( mPicture && mPicture->mode() != newFormat )
469 mPicture->beginCommand( tr(
"Change Picture Type" ) );
470 mPicture->setMode( newFormat );
471 mPicture->endCommand();
475 void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
479 mPicture->beginCommand( tr(
"Change Picture" ) );
482 mPicture->endCommand();
487 void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
489 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
490 mPicture->setSvgDynamicParameters( parameters );
492 mPicture->endCommand();