QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsBlurWidget::mBlurStrengthSpnBx_valueChanged );
121  connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsBlurWidget::mBlurUnitWidget_changed );
122  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mDrawModeComboBox_currentIndexChanged );
123  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlendCmbBx_currentIndexChanged );
124 
125  mBlurTypeCombo->addItem( tr( "Stack blur (fast, doesn't support high dpi)" ), QgsBlurEffect::StackBlur );
126  mBlurTypeCombo->addItem( tr( "Gaussian blur (quality, supports high dpi)" ), QgsBlurEffect::GaussianBlur );
127 
130 
131  initGui();
132  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsBlurWidget::opacityChanged );
133 }
134 
135 
137 {
138  if ( !effect || effect->type() != QLatin1String( "blur" ) )
139  return;
140 
141  mEffect = static_cast<QgsBlurEffect *>( effect );
142  initGui();
143 }
144 
145 void QgsBlurWidget::initGui()
146 {
147  if ( !mEffect )
148  {
149  return;
150  }
151 
152  blockSignals( true );
153 
154  mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
155  mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
156  mOpacityWidget->setOpacity( mEffect->opacity() );
157  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
158  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
159 
160  blockSignals( false );
161 }
162 
163 void QgsBlurWidget::blockSignals( const bool block )
164 {
165  mBlurTypeCombo->blockSignals( block );
166  mBlurStrengthSpnBx->blockSignals( block );
167  mOpacityWidget->blockSignals( block );
168  mBlendCmbBx->blockSignals( block );
169  mDrawModeComboBox->blockSignals( block );
170 }
171 
172 void QgsBlurWidget::mBlurTypeCombo_currentIndexChanged( int index )
173 {
174  if ( !mEffect )
175  return;
176 
177  QgsBlurEffect::BlurMethod method = ( QgsBlurEffect::BlurMethod ) mBlurTypeCombo->itemData( index ).toInt();
178  mEffect->setBlurMethod( method );
179 
180  //also update max radius
181  switch ( method )
182  {
184  mBlurStrengthSpnBx->setMaximum( 16 );
185  break;
187  mBlurStrengthSpnBx->setMaximum( 200 );
188  break;
189  }
190 
191  emit changed();
192 }
193 
194 void QgsBlurWidget::mBlurStrengthSpnBx_valueChanged( double value )
195 {
196  if ( !mEffect )
197  return;
198 
199  mEffect->setBlurLevel( value );
200  emit changed();
201 }
202 
203 void QgsBlurWidget::mBlurUnitWidget_changed()
204 {
205  if ( !mEffect )
206  {
207  return;
208  }
209 
210  mEffect->setBlurUnit( mBlurUnitWidget->unit() );
211  mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
212  emit changed();
213 }
214 
215 void QgsBlurWidget::opacityChanged( double value )
216 {
217  if ( !mEffect )
218  return;
219 
220  mEffect->setOpacity( value );
221  emit changed();
222 }
223 
224 void QgsBlurWidget::mDrawModeComboBox_currentIndexChanged( int index )
225 {
226  Q_UNUSED( index )
227 
228  if ( !mEffect )
229  return;
230 
231  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
232  emit changed();
233 }
234 
235 void QgsBlurWidget::mBlendCmbBx_currentIndexChanged( int index )
236 {
237  Q_UNUSED( index )
238 
239  if ( !mEffect )
240  return;
241 
242  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
243  emit changed();
244 }
245 
246 
247 //
248 // Drop Shadow
249 //
250 
252  : QgsPaintEffectWidget( parent )
253 
254 {
255  setupUi( this );
256  connect( mShadowOffsetAngleSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged );
257  connect( mShadowOffsetAngleDial, &QDial::valueChanged, this, &QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged );
258  connect( mShadowOffsetSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged );
259  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mOffsetUnitWidget_changed );
260  connect( mShadowColorBtn, &QgsColorButton::colorChanged, this, &QgsShadowEffectWidget::mShadowColorBtn_colorChanged );
261  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged );
262  connect( mShadowBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged );
263  connect( mShadowRadiuSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged );
264  connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mBlurUnitWidget_changed );
265 
266  mShadowColorBtn->setAllowOpacity( false );
267  mShadowColorBtn->setColorDialogTitle( tr( "Select Shadow Color" ) );
268  mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
269  mShadowOffsetAngleSpnBx->setClearValue( 0 );
270 
275 
276  initGui();
277 
278  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsShadowEffectWidget::opacityChanged );
279 }
280 
282 {
283  if ( !effect || ( effect->type() != QLatin1String( "dropShadow" ) && effect->type() != QLatin1String( "innerShadow" ) ) )
284  return;
285 
286  mEffect = static_cast<QgsShadowEffect *>( effect );
287  initGui();
288 }
289 
290 void QgsShadowEffectWidget::initGui()
291 {
292  if ( !mEffect )
293  {
294  return;
295  }
296 
297  blockSignals( true );
298 
299  mShadowOffsetAngleSpnBx->setValue( mEffect->offsetAngle() );
300  mShadowOffsetAngleDial->setValue( mEffect->offsetAngle() );
301  mShadowOffsetSpnBx->setValue( mEffect->offsetDistance() );
302  mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
303  mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
304  mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
305  mBlurUnitWidget->setUnit( mEffect->blurUnit() );
306  mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
307  mOpacityWidget->setOpacity( mEffect->opacity() );
308  mShadowColorBtn->setColor( mEffect->color() );
309  mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
310  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
311 
312  blockSignals( false );
313 }
314 
315 void QgsShadowEffectWidget::blockSignals( const bool block )
316 {
317  mShadowOffsetAngleSpnBx->blockSignals( block );
318  mShadowOffsetAngleDial->blockSignals( block );
319  mShadowOffsetSpnBx->blockSignals( block );
320  mOffsetUnitWidget->blockSignals( block );
321  mShadowRadiuSpnBx->blockSignals( block );
322  mBlurUnitWidget->blockSignals( block );
323  mOpacityWidget->blockSignals( block );
324  mShadowColorBtn->blockSignals( block );
325  mShadowBlendCmbBx->blockSignals( block );
326  mDrawModeComboBox->blockSignals( block );
327 }
328 
329 void QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged( int value )
330 {
331  mShadowOffsetAngleDial->blockSignals( true );
332  mShadowOffsetAngleDial->setValue( value );
333  mShadowOffsetAngleDial->blockSignals( false );
334 
335  if ( !mEffect )
336  return;
337 
338  mEffect->setOffsetAngle( value );
339  emit changed();
340 }
341 
342 void QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged( int value )
343 {
344  mShadowOffsetAngleSpnBx->setValue( value );
345 }
346 
347 void QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged( double value )
348 {
349  if ( !mEffect )
350  return;
351 
352  mEffect->setOffsetDistance( value );
353  emit changed();
354 }
355 
356 void QgsShadowEffectWidget::mOffsetUnitWidget_changed()
357 {
358  if ( !mEffect )
359  {
360  return;
361  }
362 
363  mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
364  mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
365  emit changed();
366 }
367 
368 void QgsShadowEffectWidget::opacityChanged( double value )
369 {
370  if ( !mEffect )
371  return;
372 
373  mEffect->setOpacity( value );
374  emit changed();
375 }
376 
377 void QgsShadowEffectWidget::mShadowColorBtn_colorChanged( const QColor &color )
378 {
379  if ( !mEffect )
380  return;
381 
382  mEffect->setColor( color );
383  emit changed();
384 }
385 
386 void QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged( double value )
387 {
388  if ( !mEffect )
389  return;
390 
391  mEffect->setBlurLevel( value );
392  emit changed();
393 }
394 
395 void QgsShadowEffectWidget::mBlurUnitWidget_changed()
396 {
397  if ( !mEffect )
398  {
399  return;
400  }
401 
402  mEffect->setBlurUnit( mBlurUnitWidget->unit() );
403  mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
404  emit changed();
405 }
406 
407 void QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
408 {
409  Q_UNUSED( index )
410 
411  if ( !mEffect )
412  return;
413 
414  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
415  emit changed();
416 }
417 
418 void QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged( int index )
419 {
420  Q_UNUSED( index )
421 
422  if ( !mEffect )
423  return;
424 
425  mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
426  emit changed();
427 }
428 
429 
430 
431 //
432 // glow
433 //
434 
436  : QgsPaintEffectWidget( parent )
437 
438 {
439  setupUi( this );
440  connect( mSpreadSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mSpreadSpnBx_valueChanged );
441  connect( mSpreadUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mSpreadUnitWidget_changed );
442  connect( mColorBtn, &QgsColorButton::colorChanged, this, &QgsGlowWidget::mColorBtn_colorChanged );
443  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mBlendCmbBx_currentIndexChanged );
444  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mDrawModeComboBox_currentIndexChanged );
445  connect( mBlurRadiusSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mBlurRadiusSpnBx_valueChanged );
446  connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mBlurUnitWidget_changed );
447 
448  mColorBtn->setAllowOpacity( false );
449  mColorBtn->setColorDialogTitle( tr( "Select Glow Color" ) );
450  mColorBtn->setContext( QStringLiteral( "symbology" ) );
451 
456 
457  btnColorRamp->setShowGradientOnly( true );
458 
459  initGui();
460 
461  connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsGlowWidget::applyColorRamp );
462  connect( radioSingleColor, &QAbstractButton::toggled, this, &QgsGlowWidget::colorModeChanged );
463  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsGlowWidget::opacityChanged );
464 }
465 
467 {
468  if ( !effect || ( effect->type() != QLatin1String( "outerGlow" ) && effect->type() != QLatin1String( "innerGlow" ) ) )
469  return;
470 
471  mEffect = static_cast<QgsGlowEffect *>( effect );
472  initGui();
473 }
474 
475 void QgsGlowWidget::initGui()
476 {
477  if ( !mEffect )
478  {
479  return;
480  }
481 
482  blockSignals( true );
483 
484  mSpreadSpnBx->setValue( mEffect->spread() );
485  mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
486  mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
487  mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
488  mOpacityWidget->setOpacity( mEffect->opacity() );
489  mColorBtn->setColor( mEffect->color() );
490  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
491 
492  if ( mEffect->ramp() )
493  {
494  btnColorRamp->setColorRamp( mEffect->ramp() );
495  }
496 
497  radioSingleColor->setChecked( mEffect->colorType() == QgsGlowEffect::SingleColor );
498  mColorBtn->setEnabled( mEffect->colorType() == QgsGlowEffect::SingleColor );
499  radioColorRamp->setChecked( mEffect->colorType() == QgsGlowEffect::ColorRamp );
500  btnColorRamp->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
501  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
502 
503  blockSignals( false );
504 }
505 
506 void QgsGlowWidget::blockSignals( const bool block )
507 {
508  mSpreadSpnBx->blockSignals( block );
509  mSpreadUnitWidget->blockSignals( block );
510  mBlurRadiusSpnBx->blockSignals( block );
511  mOpacityWidget->blockSignals( block );
512  mColorBtn->blockSignals( block );
513  mBlendCmbBx->blockSignals( block );
514  btnColorRamp->blockSignals( block );
515  radioSingleColor->blockSignals( block );
516  radioColorRamp->blockSignals( block );
517  mDrawModeComboBox->blockSignals( block );
518 }
519 
520 void QgsGlowWidget::colorModeChanged()
521 {
522  if ( !mEffect )
523  {
524  return;
525  }
526 
527  if ( radioSingleColor->isChecked() )
528  {
530  }
531  else
532  {
534  mEffect->setRamp( btnColorRamp->colorRamp() );
535  }
536  emit changed();
537 }
538 
539 void QgsGlowWidget::mSpreadSpnBx_valueChanged( double value )
540 {
541  if ( !mEffect )
542  return;
543 
544  mEffect->setSpread( value );
545  emit changed();
546 }
547 
548 void QgsGlowWidget::mSpreadUnitWidget_changed()
549 {
550  if ( !mEffect )
551  {
552  return;
553  }
554 
555  mEffect->setSpreadUnit( mSpreadUnitWidget->unit() );
556  mEffect->setSpreadMapUnitScale( mSpreadUnitWidget->getMapUnitScale() );
557  emit changed();
558 }
559 
560 void QgsGlowWidget::opacityChanged( double value )
561 {
562  if ( !mEffect )
563  return;
564 
565  mEffect->setOpacity( value );
566  emit changed();
567 }
568 
569 void QgsGlowWidget::mColorBtn_colorChanged( const QColor &color )
570 {
571  if ( !mEffect )
572  return;
573 
574  mEffect->setColor( color );
575  emit changed();
576 }
577 
578 void QgsGlowWidget::mBlurRadiusSpnBx_valueChanged( double value )
579 {
580  if ( !mEffect )
581  return;
582 
583  mEffect->setBlurLevel( value );
584  emit changed();
585 }
586 
587 void QgsGlowWidget::mBlurUnitWidget_changed()
588 {
589  if ( !mEffect )
590  {
591  return;
592  }
593 
594  mEffect->setBlurUnit( mBlurUnitWidget->unit() );
595  mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
596  emit changed();
597 }
598 
599 void QgsGlowWidget::mBlendCmbBx_currentIndexChanged( int index )
600 {
601  Q_UNUSED( index )
602 
603  if ( !mEffect )
604  return;
605 
606  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
607  emit changed();
608 }
609 
610 void QgsGlowWidget::mDrawModeComboBox_currentIndexChanged( int index )
611 {
612  Q_UNUSED( index )
613 
614  if ( !mEffect )
615  return;
616 
617  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
618  emit changed();
619 }
620 
621 void QgsGlowWidget::applyColorRamp()
622 {
623  if ( !mEffect )
624  {
625  return;
626  }
627 
628  QgsColorRamp *ramp = btnColorRamp->colorRamp();
629  if ( !ramp )
630  return;
631 
632  mEffect->setRamp( ramp );
633  emit changed();
634 }
635 
636 //
637 // transform
638 //
639 
641  : QgsPaintEffectWidget( parent )
642 
643 {
644  setupUi( this );
645  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsTransformWidget::mDrawModeComboBox_currentIndexChanged );
646  connect( mSpinTranslateX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateX_valueChanged );
647  connect( mSpinTranslateY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateY_valueChanged );
648  connect( mTranslateUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsTransformWidget::mTranslateUnitWidget_changed );
649  connect( mReflectXCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectXCheckBox_stateChanged );
650  connect( mReflectYCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectYCheckBox_stateChanged );
651  connect( mSpinShearX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearX_valueChanged );
652  connect( mSpinShearY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearY_valueChanged );
653  connect( mSpinScaleX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleX_valueChanged );
654  connect( mSpinScaleY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleY_valueChanged );
655  connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mRotationSpinBox_valueChanged );
656 
659  mSpinTranslateX->setClearValue( 0 );
660  mSpinTranslateY->setClearValue( 0 );
661  mRotationSpinBox->setClearValue( 0 );
662  mSpinShearX->setClearValue( 0 );
663  mSpinShearY->setClearValue( 0 );
664  mSpinScaleX->setClearValue( 100.0 );
665  mSpinScaleY->setClearValue( 100.0 );
666 
667  initGui();
668 }
669 
670 
672 {
673  if ( !effect || effect->type() != QLatin1String( "transform" ) )
674  return;
675 
676  mEffect = static_cast<QgsTransformEffect *>( effect );
677  initGui();
678 }
679 
680 void QgsTransformWidget::initGui()
681 {
682  if ( !mEffect )
683  {
684  return;
685  }
686 
687  blockSignals( true );
688 
689  mReflectXCheckBox->setChecked( mEffect->reflectX() );
690  mReflectYCheckBox->setChecked( mEffect->reflectY() );
691  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
692  mSpinTranslateX->setValue( mEffect->translateX() );
693  mSpinTranslateY->setValue( mEffect->translateY() );
694  mTranslateUnitWidget->setUnit( mEffect->translateUnit() );
695  mTranslateUnitWidget->setMapUnitScale( mEffect->translateMapUnitScale() );
696  mSpinShearX->setValue( mEffect->shearX() );
697  mSpinShearY->setValue( mEffect->shearY() );
698  mSpinScaleX->setValue( mEffect->scaleX() * 100.0 );
699  mSpinScaleY->setValue( mEffect->scaleY() * 100.0 );
700  mRotationSpinBox->setValue( mEffect->rotation() );
701 
702  blockSignals( false );
703 }
704 
705 void QgsTransformWidget::blockSignals( const bool block )
706 {
707  mDrawModeComboBox->blockSignals( block );
708  mTranslateUnitWidget->blockSignals( block );
709  mSpinTranslateX->blockSignals( block );
710  mSpinTranslateY->blockSignals( block );
711  mReflectXCheckBox->blockSignals( block );
712  mReflectYCheckBox->blockSignals( block );
713  mSpinShearX->blockSignals( block );
714  mSpinShearY->blockSignals( block );
715  mSpinScaleX->blockSignals( block );
716  mSpinScaleY->blockSignals( block );
717  mRotationSpinBox->blockSignals( block );
718 }
719 
720 
721 void QgsTransformWidget::mDrawModeComboBox_currentIndexChanged( int index )
722 {
723  Q_UNUSED( index )
724 
725  if ( !mEffect )
726  return;
727 
728  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
729  emit changed();
730 }
731 
732 void QgsTransformWidget::mSpinTranslateX_valueChanged( double value )
733 {
734  if ( !mEffect )
735  return;
736 
737  mEffect->setTranslateX( value );
738  emit changed();
739 }
740 
741 void QgsTransformWidget::mSpinTranslateY_valueChanged( double value )
742 {
743  if ( !mEffect )
744  return;
745 
746  mEffect->setTranslateY( value );
747  emit changed();
748 }
749 
750 void QgsTransformWidget::mTranslateUnitWidget_changed()
751 {
752  if ( !mEffect )
753  {
754  return;
755  }
756 
757  mEffect->setTranslateUnit( mTranslateUnitWidget->unit() );
758  mEffect->setTranslateMapUnitScale( mTranslateUnitWidget->getMapUnitScale() );
759  emit changed();
760 }
761 
762 void QgsTransformWidget::mReflectXCheckBox_stateChanged( int state )
763 {
764  if ( !mEffect )
765  return;
766 
767  mEffect->setReflectX( state == Qt::Checked );
768  emit changed();
769 }
770 
771 void QgsTransformWidget::mReflectYCheckBox_stateChanged( int state )
772 {
773  if ( !mEffect )
774  return;
775 
776  mEffect->setReflectY( state == Qt::Checked );
777  emit changed();
778 }
779 
780 void QgsTransformWidget::mSpinShearX_valueChanged( double value )
781 {
782  if ( !mEffect )
783  return;
784 
785  mEffect->setShearX( value );
786  emit changed();
787 }
788 
789 void QgsTransformWidget::mSpinShearY_valueChanged( double value )
790 {
791  if ( !mEffect )
792  return;
793 
794  mEffect->setShearY( value );
795  emit changed();
796 }
797 
798 void QgsTransformWidget::mSpinScaleX_valueChanged( double value )
799 {
800  if ( !mEffect )
801  return;
802 
803  mEffect->setScaleX( value / 100.0 );
804  emit changed();
805 }
806 
807 void QgsTransformWidget::mSpinScaleY_valueChanged( double value )
808 {
809  if ( !mEffect )
810  return;
811 
812  mEffect->setScaleY( value / 100.0 );
813  emit changed();
814 }
815 
816 void QgsTransformWidget::mRotationSpinBox_valueChanged( double value )
817 {
818  if ( !mEffect )
819  return;
820 
821  mEffect->setRotation( value );
822  emit changed();
823 }
824 
825 
826 //
827 // color effect
828 //
829 
831  : QgsPaintEffectWidget( parent )
832 
833 {
834  setupUi( this );
835  connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged );
836  connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged );
837  connect( mBrightnessSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mBrightnessSpinBox_valueChanged );
838  connect( mContrastSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mContrastSpinBox_valueChanged );
839  connect( mSaturationSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mSaturationSpinBox_valueChanged );
840  connect( mColorizeStrengthSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged );
841  connect( mColorizeCheck, &QCheckBox::stateChanged, this, &QgsColorEffectWidget::mColorizeCheck_stateChanged );
842  connect( mColorizeColorButton, &QgsColorButton::colorChanged, this, &QgsColorEffectWidget::mColorizeColorButton_colorChanged );
843  connect( mGrayscaleCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged );
844 
845  mBrightnessSpinBox->setClearValue( 0 );
846  mContrastSpinBox->setClearValue( 0 );
847  mSaturationSpinBox->setClearValue( 0 );
848  mColorizeColorButton->setAllowOpacity( false );
849 
850  mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
851  mGrayscaleCombo->addItem( tr( "By lightness" ), QgsImageOperation::GrayscaleLightness );
852  mGrayscaleCombo->addItem( tr( "By luminosity" ), QgsImageOperation::GrayscaleLuminosity );
853  mGrayscaleCombo->addItem( tr( "By average" ), QgsImageOperation::GrayscaleAverage );
854 
855  initGui();
856 
857  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsColorEffectWidget::opacityChanged );
858 }
859 
861 {
862  if ( !effect || effect->type() != QLatin1String( "color" ) )
863  return;
864 
865  mEffect = static_cast<QgsColorEffect *>( effect );
866  initGui();
867 }
868 
869 void QgsColorEffectWidget::initGui()
870 {
871  if ( !mEffect )
872  {
873  return;
874  }
875 
876  blockSignals( true );
877 
878  mSliderBrightness->setValue( mEffect->brightness() );
879  mSliderContrast->setValue( mEffect->contrast() );
880  mSliderSaturation->setValue( ( mEffect->saturation() - 1.0 ) * 100.0 );
881  mColorizeCheck->setChecked( mEffect->colorizeOn() );
882  mSliderColorizeStrength->setValue( mEffect->colorizeStrength() );
883  mColorizeColorButton->setColor( mEffect->colorizeColor() );
884  int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
885  mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
886  mOpacityWidget->setOpacity( mEffect->opacity() );
887  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
888  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
889  enableColorizeControls( mEffect->colorizeOn() );
890 
891  blockSignals( false );
892 }
893 
894 void QgsColorEffectWidget::blockSignals( const bool block )
895 {
896  mBrightnessSpinBox->blockSignals( block );
897  mContrastSpinBox->blockSignals( block );
898  mSaturationSpinBox->blockSignals( block );
899  mColorizeStrengthSpinBox->blockSignals( block );
900  mColorizeCheck->blockSignals( block );
901  mColorizeColorButton->blockSignals( block );
902  mGrayscaleCombo->blockSignals( block );
903  mOpacityWidget->blockSignals( block );
904  mBlendCmbBx->blockSignals( block );
905  mDrawModeComboBox->blockSignals( block );
906 }
907 
908 void QgsColorEffectWidget::enableColorizeControls( const bool enable )
909 {
910  mSliderColorizeStrength->setEnabled( enable );
911  mColorizeStrengthSpinBox->setEnabled( enable );
912  mColorizeColorButton->setEnabled( enable );
913 }
914 
915 void QgsColorEffectWidget::opacityChanged( double value )
916 {
917  if ( !mEffect )
918  return;
919 
920  mEffect->setOpacity( value );
921  emit changed();
922 }
923 
924 void QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged( int index )
925 {
926  Q_UNUSED( index )
927 
928  if ( !mEffect )
929  return;
930 
931  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
932  emit changed();
933 }
934 
935 void QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
936 {
937  Q_UNUSED( index )
938 
939  if ( !mEffect )
940  return;
941 
942  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
943  emit changed();
944 }
945 
946 void QgsColorEffectWidget::mBrightnessSpinBox_valueChanged( int value )
947 {
948  if ( !mEffect )
949  return;
950 
951  mEffect->setBrightness( value );
952  emit changed();
953 }
954 
955 void QgsColorEffectWidget::mContrastSpinBox_valueChanged( int value )
956 {
957  if ( !mEffect )
958  return;
959 
960  mEffect->setContrast( value );
961  emit changed();
962 }
963 
964 void QgsColorEffectWidget::mSaturationSpinBox_valueChanged( int value )
965 {
966  if ( !mEffect )
967  return;
968 
969  mEffect->setSaturation( value / 100.0 + 1 );
970  emit changed();
971 }
972 
973 void QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged( int value )
974 {
975  if ( !mEffect )
976  return;
977 
978  mEffect->setColorizeStrength( value );
979  emit changed();
980 }
981 
982 void QgsColorEffectWidget::mColorizeCheck_stateChanged( int state )
983 {
984  if ( !mEffect )
985  return;
986 
987  mEffect->setColorizeOn( state == Qt::Checked );
988  enableColorizeControls( state == Qt::Checked );
989  emit changed();
990 }
991 
992 void QgsColorEffectWidget::mColorizeColorButton_colorChanged( const QColor &color )
993 {
994  if ( !mEffect )
995  return;
996 
997  mEffect->setColorizeColor( color );
998  emit changed();
999 }
1000 
1001 void QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged( int index )
1002 {
1003  Q_UNUSED( index )
1004 
1005  if ( !mEffect )
1006  return;
1007 
1008  mEffect->setGrayscaleMode( ( QgsImageOperation::GrayscaleMode ) mGrayscaleCombo->currentData().toInt() );
1009  emit changed();
1010 }
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.
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the shadow blur level (radius).
double opacity() const
Returns the opacity for the effect.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
double blurLevel() const
Returns the blur level (radius) for the shadow.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the blur level (radius).
Definition: qgsblureffect.h:93
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 setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow blur strength (radius).
void setColorizeColor(const QColor &colorizeColor)
Sets the color used for colorizing a picture.
double offsetDistance() const
Returns the distance used for offsetting the shadow.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the shadow blur strength (radius).
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.
void setBlurLevel(const double level)
Sets blur level (radius)
Definition: qgsblureffect.h:72
Gaussian blur, a slower but high quality blur. Blur level values are the distance in pixels for the b...
Definition: qgsblureffect.h:43
double opacity() const
Returns the opacity for the effect.
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow blur level (radius).
double scaleX() const
Returns the x axis scaling factor.
DrawMode drawMode() const
Returns the draw mode for the effect.
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:184
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 setBlurLevel(const double level)
Sets blur level (radius) for the shadow.
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
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.
double translateX() const
Returns the transform x translation.
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.
void setBlurLevel(const double level)
Sets blur level (radius) for the glow.
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.
double blurLevel() const
Returns the blur level (radius) for the glow.
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)
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)
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.
Points (e.g., for font sizes)
Definition: qgsunittypes.h:117
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow blur level (radius).
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.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the blur strength (radius).
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.
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:83
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.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the glow blur strength (radius).
int brightness() const
Returns the brightness modification for the effect.
QColor color() const
Returns the color for the glow.