QGIS API Documentation  3.2.0-Bonn (bc43194)
qgspainteffectwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspainteffectwidget.cpp
3  ------------------------
4  begin : January 2015
5  copyright : (C) 2015 by Nyall Dawson
6  email : nyall dot dawson at gmail.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #include "qgspainteffectwidget.h"
18 #include "qgslogger.h"
19 #include "qgspainteffect.h"
20 #include "qgsshadoweffect.h"
21 #include "qgsblureffect.h"
22 #include "qgsgloweffect.h"
23 #include "qgstransformeffect.h"
24 #include "qgscoloreffect.h"
25 #include "qgsstyle.h"
26 #include "qgscolorramp.h"
27 #include "qgscolorrampbutton.h"
28 
29 //
30 // draw source
31 //
32 
34  : QgsPaintEffectWidget( parent )
35 
36 {
37  setupUi( this );
38  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged );
39  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged );
40  initGui();
41 }
42 
43 
45 {
46  if ( !effect || effect->type() != QLatin1String( "drawSource" ) )
47  return;
48 
49  mEffect = static_cast<QgsDrawSourceEffect *>( effect );
50  initGui();
51 
52  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsDrawSourceWidget::opacityChanged );
53 }
54 
55 void QgsDrawSourceWidget::initGui()
56 {
57  if ( !mEffect )
58  {
59  return;
60  }
61 
62  blockSignals( true );
63 
64  mOpacityWidget->setOpacity( mEffect->opacity() );
65  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
66  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
67 
68  blockSignals( false );
69 }
70 
71 void QgsDrawSourceWidget::blockSignals( const bool block )
72 {
73  mOpacityWidget->blockSignals( block );
74  mBlendCmbBx->blockSignals( block );
75  mDrawModeComboBox->blockSignals( block );
76 }
77 
78 void QgsDrawSourceWidget::opacityChanged( double value )
79 {
80  if ( !mEffect )
81  return;
82 
83  mEffect->setOpacity( value );
84  emit changed();
85 }
86 
87 void QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged( int index )
88 {
89  Q_UNUSED( index );
90 
91  if ( !mEffect )
92  return;
93 
94  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
95  emit changed();
96 }
97 
98 void QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged( int index )
99 {
100  Q_UNUSED( index );
101 
102  if ( !mEffect )
103  return;
104 
105  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
106  emit changed();
107 }
108 
109 
110 //
111 // blur
112 //
113 
115  : QgsPaintEffectWidget( parent )
116 
117 {
118  setupUi( this );
119  connect( mBlurTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlurTypeCombo_currentIndexChanged );
120  connect( mBlurStrengthSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsBlurWidget::mBlurStrengthSpnBx_valueChanged );
121  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mDrawModeComboBox_currentIndexChanged );
122  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlendCmbBx_currentIndexChanged );
123 
124  mBlurTypeCombo->addItem( tr( "Stack blur (fast)" ), QgsBlurEffect::StackBlur );
125  mBlurTypeCombo->addItem( tr( "Gaussian blur (quality)" ), QgsBlurEffect::GaussianBlur );
126 
127  initGui();
128  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsBlurWidget::opacityChanged );
129 }
130 
131 
133 {
134  if ( !effect || effect->type() != QLatin1String( "blur" ) )
135  return;
136 
137  mEffect = static_cast<QgsBlurEffect *>( effect );
138  initGui();
139 }
140 
141 void QgsBlurWidget::initGui()
142 {
143  if ( !mEffect )
144  {
145  return;
146  }
147 
148  blockSignals( true );
149 
150  mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
151  mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
152  mOpacityWidget->setOpacity( mEffect->opacity() );
153  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
154  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
155 
156  blockSignals( false );
157 }
158 
159 void QgsBlurWidget::blockSignals( const bool block )
160 {
161  mBlurTypeCombo->blockSignals( block );
162  mBlurStrengthSpnBx->blockSignals( block );
163  mOpacityWidget->blockSignals( block );
164  mBlendCmbBx->blockSignals( block );
165  mDrawModeComboBox->blockSignals( block );
166 }
167 
168 void QgsBlurWidget::mBlurTypeCombo_currentIndexChanged( int index )
169 {
170  if ( !mEffect )
171  return;
172 
173  QgsBlurEffect::BlurMethod method = ( QgsBlurEffect::BlurMethod ) mBlurTypeCombo->itemData( index ).toInt();
174  mEffect->setBlurMethod( method );
175 
176  //also update max radius
177  switch ( method )
178  {
180  mBlurStrengthSpnBx->setMaximum( 16 );
181  break;
183  mBlurStrengthSpnBx->setMaximum( 200 );
184  break;
185  }
186 
187  emit changed();
188 }
189 
190 void QgsBlurWidget::mBlurStrengthSpnBx_valueChanged( int value )
191 {
192  if ( !mEffect )
193  return;
194 
195  mEffect->setBlurLevel( value );
196  emit changed();
197 }
198 
199 void QgsBlurWidget::opacityChanged( double value )
200 {
201  if ( !mEffect )
202  return;
203 
204  mEffect->setOpacity( value );
205  emit changed();
206 }
207 
208 void QgsBlurWidget::mDrawModeComboBox_currentIndexChanged( int index )
209 {
210  Q_UNUSED( index );
211 
212  if ( !mEffect )
213  return;
214 
215  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
216  emit changed();
217 }
218 
219 void QgsBlurWidget::mBlendCmbBx_currentIndexChanged( int index )
220 {
221  Q_UNUSED( index );
222 
223  if ( !mEffect )
224  return;
225 
226  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
227  emit changed();
228 }
229 
230 
231 //
232 // Drop Shadow
233 //
234 
236  : QgsPaintEffectWidget( parent )
237 
238 {
239  setupUi( this );
240  connect( mShadowOffsetAngleSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged );
241  connect( mShadowOffsetAngleDial, &QDial::valueChanged, this, &QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged );
242  connect( mShadowOffsetSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged );
243  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mOffsetUnitWidget_changed );
244  connect( mShadowColorBtn, &QgsColorButton::colorChanged, this, &QgsShadowEffectWidget::mShadowColorBtn_colorChanged );
245  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged );
246  connect( mShadowBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged );
247  connect( mShadowRadiuSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged );
248 
249  mShadowColorBtn->setAllowOpacity( false );
250  mShadowColorBtn->setColorDialogTitle( tr( "Select Shadow Color" ) );
251  mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
252  mShadowOffsetAngleSpnBx->setClearValue( 0 );
253 
256 
257  initGui();
258 
259  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsShadowEffectWidget::opacityChanged );
260 }
261 
263 {
264  if ( !effect || ( effect->type() != QLatin1String( "dropShadow" ) && effect->type() != QLatin1String( "innerShadow" ) ) )
265  return;
266 
267  mEffect = static_cast<QgsShadowEffect *>( effect );
268  initGui();
269 }
270 
271 void QgsShadowEffectWidget::initGui()
272 {
273  if ( !mEffect )
274  {
275  return;
276  }
277 
278  blockSignals( true );
279 
280  mShadowOffsetAngleSpnBx->setValue( mEffect->offsetAngle() );
281  mShadowOffsetAngleDial->setValue( mEffect->offsetAngle() );
282  mShadowOffsetSpnBx->setValue( mEffect->offsetDistance() );
283  mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
284  mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
285  mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
286  mOpacityWidget->setOpacity( mEffect->opacity() );
287  mShadowColorBtn->setColor( mEffect->color() );
288  mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
289  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
290 
291  blockSignals( false );
292 }
293 
294 void QgsShadowEffectWidget::blockSignals( const bool block )
295 {
296  mShadowOffsetAngleSpnBx->blockSignals( block );
297  mShadowOffsetAngleDial->blockSignals( block );
298  mShadowOffsetSpnBx->blockSignals( block );
299  mOffsetUnitWidget->blockSignals( block );
300  mShadowRadiuSpnBx->blockSignals( block );
301  mOpacityWidget->blockSignals( block );
302  mShadowColorBtn->blockSignals( block );
303  mShadowBlendCmbBx->blockSignals( block );
304  mDrawModeComboBox->blockSignals( block );
305 }
306 
307 void QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged( int value )
308 {
309  mShadowOffsetAngleDial->blockSignals( true );
310  mShadowOffsetAngleDial->setValue( value );
311  mShadowOffsetAngleDial->blockSignals( false );
312 
313  if ( !mEffect )
314  return;
315 
316  mEffect->setOffsetAngle( value );
317  emit changed();
318 }
319 
320 void QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged( int value )
321 {
322  mShadowOffsetAngleSpnBx->setValue( value );
323 }
324 
325 void QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged( double value )
326 {
327  if ( !mEffect )
328  return;
329 
330  mEffect->setOffsetDistance( value );
331  emit changed();
332 }
333 
334 void QgsShadowEffectWidget::mOffsetUnitWidget_changed()
335 {
336  if ( !mEffect )
337  {
338  return;
339  }
340 
341  mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
342  mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
343  emit changed();
344 }
345 
346 void QgsShadowEffectWidget::opacityChanged( double value )
347 {
348  if ( !mEffect )
349  return;
350 
351  mEffect->setOpacity( value );
352  emit changed();
353 }
354 
355 void QgsShadowEffectWidget::mShadowColorBtn_colorChanged( const QColor &color )
356 {
357  if ( !mEffect )
358  return;
359 
360  mEffect->setColor( color );
361  emit changed();
362 }
363 
364 void QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged( int value )
365 {
366  if ( !mEffect )
367  return;
368 
369  mEffect->setBlurLevel( value );
370  emit changed();
371 }
372 
373 void QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
374 {
375  Q_UNUSED( index );
376 
377  if ( !mEffect )
378  return;
379 
380  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
381  emit changed();
382 }
383 
384 void QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged( int index )
385 {
386  Q_UNUSED( index );
387 
388  if ( !mEffect )
389  return;
390 
391  mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
392  emit changed();
393 }
394 
395 
396 
397 //
398 // glow
399 //
400 
402  : QgsPaintEffectWidget( parent )
403 
404 {
405  setupUi( this );
406  connect( mSpreadSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mSpreadSpnBx_valueChanged );
407  connect( mSpreadUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mSpreadUnitWidget_changed );
408  connect( mColorBtn, &QgsColorButton::colorChanged, this, &QgsGlowWidget::mColorBtn_colorChanged );
409  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mBlendCmbBx_currentIndexChanged );
410  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mDrawModeComboBox_currentIndexChanged );
411  connect( mBlurRadiusSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsGlowWidget::mBlurRadiusSpnBx_valueChanged );
412 
413  mColorBtn->setAllowOpacity( false );
414  mColorBtn->setColorDialogTitle( tr( "Select Glow Color" ) );
415  mColorBtn->setContext( QStringLiteral( "symbology" ) );
416 
419 
420  btnColorRamp->setShowGradientOnly( true );
421 
422  initGui();
423 
424  connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsGlowWidget::applyColorRamp );
425  connect( radioSingleColor, &QAbstractButton::toggled, this, &QgsGlowWidget::colorModeChanged );
426  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsGlowWidget::opacityChanged );
427 }
428 
430 {
431  if ( !effect || ( effect->type() != QLatin1String( "outerGlow" ) && effect->type() != QLatin1String( "innerGlow" ) ) )
432  return;
433 
434  mEffect = static_cast<QgsGlowEffect *>( effect );
435  initGui();
436 }
437 
438 void QgsGlowWidget::initGui()
439 {
440  if ( !mEffect )
441  {
442  return;
443  }
444 
445  blockSignals( true );
446 
447  mSpreadSpnBx->setValue( mEffect->spread() );
448  mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
449  mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
450  mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
451  mOpacityWidget->setOpacity( mEffect->opacity() );
452  mColorBtn->setColor( mEffect->color() );
453  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
454 
455  if ( mEffect->ramp() )
456  {
457  btnColorRamp->setColorRamp( mEffect->ramp() );
458  }
459 
460  radioSingleColor->setChecked( mEffect->colorType() == QgsGlowEffect::SingleColor );
461  mColorBtn->setEnabled( mEffect->colorType() == QgsGlowEffect::SingleColor );
462  radioColorRamp->setChecked( mEffect->colorType() == QgsGlowEffect::ColorRamp );
463  btnColorRamp->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
464  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
465 
466  blockSignals( false );
467 }
468 
469 void QgsGlowWidget::blockSignals( const bool block )
470 {
471  mSpreadSpnBx->blockSignals( block );
472  mSpreadUnitWidget->blockSignals( block );
473  mBlurRadiusSpnBx->blockSignals( block );
474  mOpacityWidget->blockSignals( block );
475  mColorBtn->blockSignals( block );
476  mBlendCmbBx->blockSignals( block );
477  btnColorRamp->blockSignals( block );
478  radioSingleColor->blockSignals( block );
479  radioColorRamp->blockSignals( block );
480  mDrawModeComboBox->blockSignals( block );
481 }
482 
483 void QgsGlowWidget::colorModeChanged()
484 {
485  if ( !mEffect )
486  {
487  return;
488  }
489 
490  if ( radioSingleColor->isChecked() )
491  {
493  }
494  else
495  {
497  mEffect->setRamp( btnColorRamp->colorRamp() );
498  }
499  emit changed();
500 }
501 
502 void QgsGlowWidget::mSpreadSpnBx_valueChanged( double value )
503 {
504  if ( !mEffect )
505  return;
506 
507  mEffect->setSpread( value );
508  emit changed();
509 }
510 
511 void QgsGlowWidget::mSpreadUnitWidget_changed()
512 {
513  if ( !mEffect )
514  {
515  return;
516  }
517 
518  mEffect->setSpreadUnit( mSpreadUnitWidget->unit() );
519  mEffect->setSpreadMapUnitScale( mSpreadUnitWidget->getMapUnitScale() );
520  emit changed();
521 }
522 
523 void QgsGlowWidget::opacityChanged( double value )
524 {
525  if ( !mEffect )
526  return;
527 
528  mEffect->setOpacity( value );
529  emit changed();
530 }
531 
532 void QgsGlowWidget::mColorBtn_colorChanged( const QColor &color )
533 {
534  if ( !mEffect )
535  return;
536 
537  mEffect->setColor( color );
538  emit changed();
539 }
540 
541 void QgsGlowWidget::mBlurRadiusSpnBx_valueChanged( int value )
542 {
543  if ( !mEffect )
544  return;
545 
546  mEffect->setBlurLevel( value );
547  emit changed();
548 }
549 
550 void QgsGlowWidget::mBlendCmbBx_currentIndexChanged( int index )
551 {
552  Q_UNUSED( index );
553 
554  if ( !mEffect )
555  return;
556 
557  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
558  emit changed();
559 }
560 
561 void QgsGlowWidget::mDrawModeComboBox_currentIndexChanged( int index )
562 {
563  Q_UNUSED( index );
564 
565  if ( !mEffect )
566  return;
567 
568  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
569  emit changed();
570 }
571 
572 void QgsGlowWidget::applyColorRamp()
573 {
574  if ( !mEffect )
575  {
576  return;
577  }
578 
579  QgsColorRamp *ramp = btnColorRamp->colorRamp();
580  if ( !ramp )
581  return;
582 
583  mEffect->setRamp( ramp );
584  emit changed();
585 }
586 
587 //
588 // transform
589 //
590 
592  : QgsPaintEffectWidget( parent )
593 
594 {
595  setupUi( this );
596  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsTransformWidget::mDrawModeComboBox_currentIndexChanged );
597  connect( mSpinTranslateX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateX_valueChanged );
598  connect( mSpinTranslateY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateY_valueChanged );
599  connect( mTranslateUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsTransformWidget::mTranslateUnitWidget_changed );
600  connect( mReflectXCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectXCheckBox_stateChanged );
601  connect( mReflectYCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectYCheckBox_stateChanged );
602  connect( mSpinShearX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearX_valueChanged );
603  connect( mSpinShearY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearY_valueChanged );
604  connect( mSpinScaleX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleX_valueChanged );
605  connect( mSpinScaleY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleY_valueChanged );
606  connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mRotationSpinBox_valueChanged );
607 
610  mSpinTranslateX->setClearValue( 0 );
611  mSpinTranslateY->setClearValue( 0 );
612  mRotationSpinBox->setClearValue( 0 );
613  mSpinShearX->setClearValue( 0 );
614  mSpinShearY->setClearValue( 0 );
615  mSpinScaleX->setClearValue( 100.0 );
616  mSpinScaleY->setClearValue( 100.0 );
617 
618  initGui();
619 }
620 
621 
623 {
624  if ( !effect || effect->type() != QLatin1String( "transform" ) )
625  return;
626 
627  mEffect = static_cast<QgsTransformEffect *>( effect );
628  initGui();
629 }
630 
631 void QgsTransformWidget::initGui()
632 {
633  if ( !mEffect )
634  {
635  return;
636  }
637 
638  blockSignals( true );
639 
640  mReflectXCheckBox->setChecked( mEffect->reflectX() );
641  mReflectYCheckBox->setChecked( mEffect->reflectY() );
642  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
643  mSpinTranslateX->setValue( mEffect->translateX() );
644  mSpinTranslateY->setValue( mEffect->translateY() );
645  mTranslateUnitWidget->setUnit( mEffect->translateUnit() );
646  mTranslateUnitWidget->setMapUnitScale( mEffect->translateMapUnitScale() );
647  mSpinShearX->setValue( mEffect->shearX() );
648  mSpinShearY->setValue( mEffect->shearY() );
649  mSpinScaleX->setValue( mEffect->scaleX() * 100.0 );
650  mSpinScaleY->setValue( mEffect->scaleY() * 100.0 );
651  mRotationSpinBox->setValue( mEffect->rotation() );
652 
653  blockSignals( false );
654 }
655 
656 void QgsTransformWidget::blockSignals( const bool block )
657 {
658  mDrawModeComboBox->blockSignals( block );
659  mTranslateUnitWidget->blockSignals( block );
660  mSpinTranslateX->blockSignals( block );
661  mSpinTranslateY->blockSignals( block );
662  mReflectXCheckBox->blockSignals( block );
663  mReflectYCheckBox->blockSignals( block );
664  mSpinShearX->blockSignals( block );
665  mSpinShearY->blockSignals( block );
666  mSpinScaleX->blockSignals( block );
667  mSpinScaleY->blockSignals( block );
668  mRotationSpinBox->blockSignals( block );
669 }
670 
671 
672 void QgsTransformWidget::mDrawModeComboBox_currentIndexChanged( int index )
673 {
674  Q_UNUSED( index );
675 
676  if ( !mEffect )
677  return;
678 
679  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
680  emit changed();
681 }
682 
683 void QgsTransformWidget::mSpinTranslateX_valueChanged( double value )
684 {
685  if ( !mEffect )
686  return;
687 
688  mEffect->setTranslateX( value );
689  emit changed();
690 }
691 
692 void QgsTransformWidget::mSpinTranslateY_valueChanged( double value )
693 {
694  if ( !mEffect )
695  return;
696 
697  mEffect->setTranslateY( value );
698  emit changed();
699 }
700 
701 void QgsTransformWidget::mTranslateUnitWidget_changed()
702 {
703  if ( !mEffect )
704  {
705  return;
706  }
707 
708  mEffect->setTranslateUnit( mTranslateUnitWidget->unit() );
709  mEffect->setTranslateMapUnitScale( mTranslateUnitWidget->getMapUnitScale() );
710  emit changed();
711 }
712 
713 void QgsTransformWidget::mReflectXCheckBox_stateChanged( int state )
714 {
715  if ( !mEffect )
716  return;
717 
718  mEffect->setReflectX( state == Qt::Checked );
719  emit changed();
720 }
721 
722 void QgsTransformWidget::mReflectYCheckBox_stateChanged( int state )
723 {
724  if ( !mEffect )
725  return;
726 
727  mEffect->setReflectY( state == Qt::Checked );
728  emit changed();
729 }
730 
731 void QgsTransformWidget::mSpinShearX_valueChanged( double value )
732 {
733  if ( !mEffect )
734  return;
735 
736  mEffect->setShearX( value );
737  emit changed();
738 }
739 
740 void QgsTransformWidget::mSpinShearY_valueChanged( double value )
741 {
742  if ( !mEffect )
743  return;
744 
745  mEffect->setShearY( value );
746  emit changed();
747 }
748 
749 void QgsTransformWidget::mSpinScaleX_valueChanged( double value )
750 {
751  if ( !mEffect )
752  return;
753 
754  mEffect->setScaleX( value / 100.0 );
755  emit changed();
756 }
757 
758 void QgsTransformWidget::mSpinScaleY_valueChanged( double value )
759 {
760  if ( !mEffect )
761  return;
762 
763  mEffect->setScaleY( value / 100.0 );
764  emit changed();
765 }
766 
767 void QgsTransformWidget::mRotationSpinBox_valueChanged( double value )
768 {
769  if ( !mEffect )
770  return;
771 
772  mEffect->setRotation( value );
773  emit changed();
774 }
775 
776 
777 //
778 // color effect
779 //
780 
782  : QgsPaintEffectWidget( parent )
783 
784 {
785  setupUi( this );
786  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged );
787  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged );
788  connect( mBrightnessSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mBrightnessSpinBox_valueChanged );
789  connect( mContrastSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mContrastSpinBox_valueChanged );
790  connect( mSaturationSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mSaturationSpinBox_valueChanged );
791  connect( mColorizeStrengthSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged );
792  connect( mColorizeCheck, &QCheckBox::stateChanged, this, &QgsColorEffectWidget::mColorizeCheck_stateChanged );
793  connect( mColorizeColorButton, &QgsColorButton::colorChanged, this, &QgsColorEffectWidget::mColorizeColorButton_colorChanged );
794  connect( mGrayscaleCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged );
795 
796  mBrightnessSpinBox->setClearValue( 0 );
797  mContrastSpinBox->setClearValue( 0 );
798  mSaturationSpinBox->setClearValue( 0 );
799  mColorizeColorButton->setAllowOpacity( false );
800 
801  mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
802  mGrayscaleCombo->addItem( tr( "By lightness" ), QgsImageOperation::GrayscaleLightness );
803  mGrayscaleCombo->addItem( tr( "By luminosity" ), QgsImageOperation::GrayscaleLuminosity );
804  mGrayscaleCombo->addItem( tr( "By average" ), QgsImageOperation::GrayscaleAverage );
805 
806  initGui();
807 
808  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsColorEffectWidget::opacityChanged );
809 }
810 
812 {
813  if ( !effect || effect->type() != QLatin1String( "color" ) )
814  return;
815 
816  mEffect = static_cast<QgsColorEffect *>( effect );
817  initGui();
818 }
819 
820 void QgsColorEffectWidget::initGui()
821 {
822  if ( !mEffect )
823  {
824  return;
825  }
826 
827  blockSignals( true );
828 
829  mSliderBrightness->setValue( mEffect->brightness() );
830  mSliderContrast->setValue( mEffect->contrast() );
831  mSliderSaturation->setValue( ( mEffect->saturation() - 1.0 ) * 100.0 );
832  mColorizeCheck->setChecked( mEffect->colorizeOn() );
833  mSliderColorizeStrength->setValue( mEffect->colorizeStrength() );
834  mColorizeColorButton->setColor( mEffect->colorizeColor() );
835  int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
836  mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
837  mOpacityWidget->setOpacity( mEffect->opacity() );
838  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
839  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
840  enableColorizeControls( mEffect->colorizeOn() );
841 
842  blockSignals( false );
843 }
844 
845 void QgsColorEffectWidget::blockSignals( const bool block )
846 {
847  mBrightnessSpinBox->blockSignals( block );
848  mContrastSpinBox->blockSignals( block );
849  mSaturationSpinBox->blockSignals( block );
850  mColorizeStrengthSpinBox->blockSignals( block );
851  mColorizeCheck->blockSignals( block );
852  mColorizeColorButton->blockSignals( block );
853  mGrayscaleCombo->blockSignals( block );
854  mOpacityWidget->blockSignals( block );
855  mBlendCmbBx->blockSignals( block );
856  mDrawModeComboBox->blockSignals( block );
857 }
858 
859 void QgsColorEffectWidget::enableColorizeControls( const bool enable )
860 {
861  mSliderColorizeStrength->setEnabled( enable );
862  mColorizeStrengthSpinBox->setEnabled( enable );
863  mColorizeColorButton->setEnabled( enable );
864 }
865 
866 void QgsColorEffectWidget::opacityChanged( double value )
867 {
868  if ( !mEffect )
869  return;
870 
871  mEffect->setOpacity( value );
872  emit changed();
873 }
874 
875 void QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged( int index )
876 {
877  Q_UNUSED( index );
878 
879  if ( !mEffect )
880  return;
881 
882  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
883  emit changed();
884 }
885 
886 void QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
887 {
888  Q_UNUSED( index );
889 
890  if ( !mEffect )
891  return;
892 
893  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
894  emit changed();
895 }
896 
897 void QgsColorEffectWidget::mBrightnessSpinBox_valueChanged( int value )
898 {
899  if ( !mEffect )
900  return;
901 
902  mEffect->setBrightness( value );
903  emit changed();
904 }
905 
906 void QgsColorEffectWidget::mContrastSpinBox_valueChanged( int value )
907 {
908  if ( !mEffect )
909  return;
910 
911  mEffect->setContrast( value );
912  emit changed();
913 }
914 
915 void QgsColorEffectWidget::mSaturationSpinBox_valueChanged( int value )
916 {
917  if ( !mEffect )
918  return;
919 
920  mEffect->setSaturation( value / 100.0 + 1 );
921  emit changed();
922 }
923 
924 void QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged( int value )
925 {
926  if ( !mEffect )
927  return;
928 
929  mEffect->setColorizeStrength( value );
930  emit changed();
931 }
932 
933 void QgsColorEffectWidget::mColorizeCheck_stateChanged( int state )
934 {
935  if ( !mEffect )
936  return;
937 
938  mEffect->setColorizeOn( state == Qt::Checked );
939  enableColorizeControls( state == Qt::Checked );
940  emit changed();
941 }
942 
943 void QgsColorEffectWidget::mColorizeColorButton_colorChanged( const QColor &color )
944 {
945  if ( !mEffect )
946  return;
947 
948  mEffect->setColorizeColor( color );
949  emit changed();
950 }
951 
952 void QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged( int index )
953 {
954  Q_UNUSED( index );
955 
956  if ( !mEffect )
957  return;
958 
959  mEffect->setGrayscaleMode( ( QgsImageOperation::GrayscaleMode ) mGrayscaleCombo->currentData().toInt() );
960  emit changed();
961 }
void setShearY(const double shearY)
Sets the y axis shearing factor.
double opacity() const
Returns the opacity for the effect.
QgsGlowWidget(QWidget *parent=nullptr)
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
void setShearX(const double shearX)
Sets the x axis shearing factor.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setOpacity(const double opacity)
Sets the opacity for the effect.
QgsDrawSourceWidget(QWidget *parent=nullptr)
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
Definition: qgsblureffect.h:86
double opacity() const
Returns the opacity for the effect.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
void setOpacity(const double opacity)
Sets the opacity for the effect.
Base class for effect properties widgets.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
void setOpacity(const double opacity)
Sets the opacity for the effect.
bool reflectX() const
Returns whether transform will be reflected along the x-axis.
Keep the lightness of the color, drops the saturation.
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
void setColorizeColor(const QColor &colorizeColor)
Sets the color used for colorizing a picture.
double offsetDistance() const
Returns the distance used for offsetting the shadow.
Base class for visual effects which can be applied to QPicture drawings.
void setColorizeStrength(int colorizeStrength)
Sets the strength for colorizing a picture.
double shearY() const
Returns the y axis shearing factor.
Gaussian blur, a slower but high quality blur. Blur level values are the distance in pixels for the b...
Definition: qgsblureffect.h:43
void setBlurLevel(const int level)
Sets blur level (strength) for the shadow.
double opacity() const
Returns the opacity for the effect.
double scaleX() const
Returns the x axis scaling factor.
DrawMode drawMode() const
Returns the draw mode for the effect.
void setBlurLevel(const int level)
Sets blur level (strength)
Definition: qgsblureffect.h:70
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
Definition: qgsblureffect.h:93
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:173
Base class for paint effect which draw a glow inside or outside a picture.
Definition: qgsgloweffect.h:38
void setTranslateY(const double translateY)
Sets the transform y translation.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
Grayscale by perceptual luminosity (weighted sum of color RGB components)
Grayscale by taking average of color RGB components.
void setGrayscaleMode(QgsImageOperation::GrayscaleMode grayscaleMode)
Sets whether the effect should convert a picture to grayscale.
void setBrightness(int brightness)
Sets the brightness modification for the effect.
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:42
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:40
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
void setBlurLevel(const int level)
Sets blur level (strength) for the glow.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
double opacity() const
Returns the opacity for the effect.
void setScaleY(const double scaleY)
Sets the y axis scaling factor.
QColor color() const
Returns the color used for the shadow.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
void changed()
Emitted when properties of the effect are changed through the widget.
void setTranslateMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the transform translation.
virtual QString type() const =0
Returns the effect type.
QgsUnitTypes::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
Definition: qgsgloweffect.h:91
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1...
void setSpreadUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow spread distance.
Definition: qgsgloweffect.h:82
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
int blurLevel() const
Returns the blur level (strength)
Definition: qgsblureffect.h:79
double translateX() const
Returns the transform x translation.
points (e.g., for font sizes)
Definition: qgsunittypes.h:107
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
QgsBlurWidget(QWidget *parent=nullptr)
double scaleY() const
Returns the y axis scaling factor.
bool reflectY() const
Returns whether transform will be reflected along the y-axis.
void setColorizeOn(bool colorizeOn)
Sets whether the effect should colorize a picture.
void setContrast(int contrast)
Sets the contrast modification for the effect.
QgsColorEffectWidget(QWidget *parent=nullptr)
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
Definition: qgsgloweffect.h:64
QgsShadowEffectWidget(QWidget *parent=nullptr)
int blurLevel() const
Returns the blur level (strength) for the shadow.
double rotation() const
Returns the transform rotation, in degrees clockwise.
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:34
GlowColorType colorType() const
Returns the color mode used for the glow.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsImageOperation::GrayscaleMode grayscaleMode() const
Returns whether the effect will convert a picture to grayscale.
A paint effect which applies transformations (such as move, scale and rotate) to a picture...
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void colorChanged(const QColor &color)
Is emitted whenever a new color is set for the button.
double shearX() const
Returns the x axis shearing factor.
void setTranslateUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the transform translation.
QgsUnitTypes::RenderUnit translateUnit() const
Returns the units used for the transform translation.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow offset distance.
Use a single color and fade the color to totally transparent.
Definition: qgsgloweffect.h:46
void setScaleX(const double scaleX)
Sets the x axis scaling factor.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setSaturation(double saturation)
Sets the saturation modification for the effect.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
Use colors from a color ramp.
Definition: qgsgloweffect.h:47
double spread() const
Returns the spread distance used for drawing the glow effect.
Definition: qgsgloweffect.h:73
int colorizeStrength() const
Returns the strength used for colorizing a picture.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double saturation() const
Returns the saturation modification for the effect.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setTranslateX(const double translateX)
Sets the transform x translation.
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.
void setReflectY(const bool reflectY)
Sets whether to reflect along the y-axis.
QgsTransformWidget(QWidget *parent=nullptr)
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shadow offset distance.
void setOffsetUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow offset distance.
Base class for paint effects which offset, blurred shadows.
const QgsMapUnitScale & translateMapUnitScale() const
Returns the map unit scale used for the transform translation.
void setRotation(const double rotation)
Sets the transform rotation, in degrees clockwise.
void setRamp(QgsColorRamp *ramp)
Sets the color ramp for the glow.
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
void setReflectX(const bool reflectX)
Sets whether to reflect along the x-axis.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double opacity() const
Returns the opacity for the effect.
A paint effect which draws the source picture with minor or no alterations.
GrayscaleMode
Modes for converting a QImage to grayscale.
bool colorizeOn() const
Returns whether the effect will colorize a picture.
int contrast() const
Returns the contrast modification for the effect.
void setColor(const QColor &color)
Sets the color for the shadow.
int offsetAngle() const
Returns the angle used for offsetting the shadow.
void setColor(const QColor &color)
Sets the color for the glow.
double translateY() const
Returns the transform y translation.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale used for the shadow offset distance.
QColor colorizeColor() const
Returns the color used for colorizing a picture.
void setDrawMode(DrawMode drawMode)
Sets the draw mode for the effect.
int brightness() const
Returns the brightness modification for the effect.
int blurLevel() const
Returns the blur level (strength) for the glow.
QColor color() const
Returns the color for the glow.