30#include <QDoubleValidator>
33#include <QImageReader>
36#include <QProgressDialog>
37#include <QSvgRenderer>
39#include "moc_qgslayoutpicturewidget.cpp"
47 mSvgSelectorWidget->setAllowParameters(
true );
48 mSvgSelectorWidget->sourceLineEdit()->setPropertyOverrideToolButtonVisible(
true );
49 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastSVGMarkerDir" ) );
68 connect( mPictureRotationSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged );
69 connect( mRotationFromComposerMapCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged );
70 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged );
71 connect( mAnchorPointComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged );
74 connect( mStrokeWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged );
75 connect( mPictureRotationOffsetSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged );
76 connect( mNorthTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged );
80 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
81 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
83 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastComposerPictureDir" ) );
87 mFillColorButton->setAllowOpacity(
true );
88 mFillColorButton->setColorDialogTitle( tr(
"Select Fill Color" ) );
89 mFillColorButton->setContext( QStringLiteral(
"composer" ) );
90 mStrokeColorButton->setAllowOpacity(
true );
91 mStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
92 mStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
94 mFillColorDDBtn->registerLinkedWidget( mFillColorButton );
95 mStrokeColorDDBtn->registerLinkedWidget( mStrokeColorButton );
97 mNorthTypeComboBox->blockSignals(
true );
100 mNorthTypeComboBox->blockSignals(
false );
101 mPictureRotationOffsetSpinBox->setClearValue( 0.0 );
102 mPictureRotationSpinBox->setClearValue( 0.0 );
106 mainLayout->addWidget( mItemPropertiesWidget );
108 if ( mPicture->layout() )
110 mComposerMapComboBox->setCurrentLayout( mPicture->layout() );
115 setGuiElementValues();
129 if ( mItemPropertiesWidget )
130 mItemPropertiesWidget->setMasterLayout( masterLayout );
133void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged(
double d )
138 mPicture->setPictureRotation( d );
139 mPicture->endCommand();
143void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged(
int )
150 mPicture->beginCommand( tr(
"Change Resize Mode" ) );
152 mPicture->endCommand();
160 mAnchorPointComboBox->setEnabled(
true );
164 mAnchorPointComboBox->setEnabled(
false );
168void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged(
int )
175 mPicture->beginCommand( tr(
"Change Placement" ) );
177 mPicture->endCommand();
191 mPicture = qobject_cast<QgsLayoutItemPicture *>( item );
192 mItemPropertiesWidget->setItem( mPicture );
200 setGuiElementValues();
205void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged(
int state )
212 mPicture->beginCommand( tr(
"Toggle Rotation Sync" ) );
213 if ( state == Qt::Unchecked )
215 mPicture->setLinkedMap(
nullptr );
216 mPictureRotationSpinBox->setEnabled(
true );
217 mComposerMapComboBox->setEnabled(
false );
218 mNorthTypeComboBox->setEnabled(
false );
219 mPictureRotationOffsetSpinBox->setEnabled(
false );
220 mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
224 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( mComposerMapComboBox->currentItem() );
225 mPicture->setLinkedMap( map );
226 mPictureRotationSpinBox->setEnabled(
false );
227 mNorthTypeComboBox->setEnabled(
true );
228 mPictureRotationOffsetSpinBox->setEnabled(
true );
229 mComposerMapComboBox->setEnabled(
true );
231 mPicture->endCommand();
234void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
242 const QgsLayout *layout = mPicture->layout();
248 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
254 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
255 mPicture->setLinkedMap( map );
257 mPicture->endCommand();
260void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
262 mPictureRotationSpinBox->blockSignals(
true );
263 mPictureRotationSpinBox->setValue( r );
264 mPictureRotationSpinBox->blockSignals(
false );
267void QgsLayoutPictureWidget::setGuiElementValues()
272 mPictureRotationSpinBox->blockSignals(
true );
273 mComposerMapComboBox->blockSignals(
true );
274 mRotationFromComposerMapCheckBox->blockSignals(
true );
275 mNorthTypeComboBox->blockSignals(
true );
276 mPictureRotationOffsetSpinBox->blockSignals(
true );
277 mResizeModeComboBox->blockSignals(
true );
278 mAnchorPointComboBox->blockSignals(
true );
279 mFillColorButton->blockSignals(
true );
280 mStrokeColorButton->blockSignals(
true );
281 mStrokeWidthSpinBox->blockSignals(
true );
283 mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
285 mComposerMapComboBox->setItem( mPicture->linkedMap() );
287 if ( mPicture->linkedMap() )
289 mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
290 mPictureRotationSpinBox->setEnabled(
false );
291 mComposerMapComboBox->setEnabled(
true );
292 mNorthTypeComboBox->setEnabled(
true );
293 mPictureRotationOffsetSpinBox->setEnabled(
true );
297 mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
298 mPictureRotationSpinBox->setEnabled(
true );
299 mComposerMapComboBox->setEnabled(
false );
300 mNorthTypeComboBox->setEnabled(
false );
301 mPictureRotationOffsetSpinBox->setEnabled(
false );
303 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
304 mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
306 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
310 mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
314 mAnchorPointComboBox->setEnabled(
true );
318 mAnchorPointComboBox->setEnabled(
false );
321 switch ( mPicture->originalMode() )
325 mRadioSVG->setChecked(
true );
328 mRadioRaster->setChecked(
true );
332 mSvgSelectorWidget->setSvgPath( mPicture->picturePath() );
333 mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
335 updateSvgParamGui(
false );
336 mFillColorButton->setColor( mPicture->svgFillColor() );
337 mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
338 mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
340 mRotationFromComposerMapCheckBox->blockSignals(
false );
341 mPictureRotationSpinBox->blockSignals(
false );
342 mComposerMapComboBox->blockSignals(
false );
343 mNorthTypeComboBox->blockSignals(
false );
344 mPictureRotationOffsetSpinBox->blockSignals(
false );
345 mResizeModeComboBox->blockSignals(
false );
346 mAnchorPointComboBox->blockSignals(
false );
347 mFillColorButton->blockSignals(
false );
348 mStrokeColorButton->blockSignals(
false );
349 mStrokeWidthSpinBox->blockSignals(
false );
355void QgsLayoutPictureWidget::updateSvgParamGui(
bool resetValues )
360 const QString picturePath = mPicture->picturePath();
363 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
364 QColor defaultFill, defaultStroke;
365 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
366 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
367 QgsApplication::svgCache()->
containsParams( picturePath, hasFillParam, hasDefaultFillColor, defaultFill, hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity, hasStrokeParam, hasDefaultStrokeColor, defaultStroke, hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth, hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
371 QColor fill = mFillColorButton->color();
372 const double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
373 if ( hasDefaultFillColor )
377 fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
378 mFillColorButton->setColor( fill );
380 mFillColorButton->setEnabled( hasFillParam );
381 mFillColorDDBtn->setEnabled( hasFillParam );
382 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
385 QColor stroke = mStrokeColorButton->color();
386 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
387 if ( hasDefaultStrokeColor )
389 stroke = defaultStroke;
391 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
392 mStrokeColorButton->setColor( stroke );
394 mStrokeColorButton->setEnabled( hasStrokeParam );
395 mStrokeColorDDBtn->setEnabled( hasStrokeParam );
396 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
397 if ( hasDefaultStrokeWidth && resetValues )
399 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
401 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
402 mStrokeWidthDDBtn->setEnabled( hasStrokeWidthParam );
405void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
408 mPicture->setSvgFillColor( color );
409 mPicture->endCommand();
413void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
416 mPicture->setSvgStrokeColor( color );
417 mPicture->endCommand();
421void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
424 mPicture->setSvgStrokeWidth( d );
425 mPicture->endCommand();
429void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
432 mPicture->setNorthOffset( d );
433 mPicture->endCommand();
437void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
439 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
441 mPicture->endCommand();
445void QgsLayoutPictureWidget::modeChanged(
bool checked )
450 const bool svg = mRadioSVG->isChecked();
458 mSvgSelectorWidget->setBrowserVisible( svg );
459 mSvgSelectorWidget->setAllowParameters( svg );
460 mSVGParamsGroupBox->setVisible( svg );
462 if ( mPicture && mPicture->mode() != newFormat )
464 mPicture->beginCommand( tr(
"Change Picture Type" ) );
465 mPicture->setMode( newFormat );
466 mPicture->endCommand();
470void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
474 mPicture->beginCommand( tr(
"Change Picture" ) );
477 mPicture->endCommand();
482void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
484 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
485 mPicture->setSvgDynamicParameters( parameters );
487 mPicture->endCommand();
PictureFormat
Picture formats.
@ Unknown
Invalid or unknown image type.
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
void pictureRotationChanged(double newRotation)
Emitted on picture rotation change.
NorthMode
Method for syncing rotation to a map's North direction.
@ GridNorth
Align to grid north.
@ TrueNorth
Align to true north.
ResizeMode
Controls how pictures are scaled within the item's frame.
@ FrameToImageSize
Sets size of frame to match original size of image without scaling.
@ ZoomResizeFrame
Enlarges image to fit frame, then resizes frame to fit resultant image.
@ Clip
Draws image at original size and clips any portion which falls outside frame.
@ Stretch
Stretches image to fit frame, ignores aspect ratio.
@ Zoom
Enlarges image to fit frame while maintaining aspect ratio of picture.
@ LayoutPicture
Picture item.
Base class for graphical items within a QgsLayout.
@ UndoPictureStrokeWidth
Picture stroke width.
@ UndoPictureRotation
Picture rotation.
@ UndoPictureFillColor
Picture fill color.
@ UndoPictureNorthOffset
Picture north offset.
@ UndoPictureStrokeColor
Picture stroke color.
ReferencePoint
Fixed position reference point.
@ LowerMiddle
Lower center of item.
@ MiddleLeft
Middle left of item.
@ UpperRight
Upper right corner of item.
@ LowerLeft
Lower left corner of item.
@ UpperLeft
Upper left corner of item.
@ UpperMiddle
Upper center of item.
@ MiddleRight
Middle right of item.
@ LowerRight
Lower right corner of item.
int type() const override
Returns a unique graphics item type identifier.
void changed()
Emitted when the object's properties change.
@ PictureSvgStrokeColor
SVG stroke color.
@ PictureSvgBackgroundColor
SVG background color.
@ PictureSource
Picture source url.
@ PictureSvgStrokeWidth
SVG stroke width.
Interface for master layout type objects, such as print layouts and reports.
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const
Tests if an SVG file contains parameters for fill, stroke color, stroke width.