QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgsstylev2.h"
26 #include "qgsvectorcolorrampv2.h"
27 
28 //
29 // draw source
30 //
31 
33  : QgsPaintEffectWidget( parent )
34  , mEffect( nullptr )
35 {
36  setupUi( this );
37  initGui();
38 }
39 
40 
42 {
43  if ( !effect || effect->type() != "drawSource" )
44  return;
45 
46  mEffect = static_cast<QgsDrawSourceEffect*>( effect );
47  initGui();
48 }
49 
50 void QgsDrawSourceWidget::initGui()
51 {
52  if ( !mEffect )
53  {
54  return;
55  }
56 
57  blockSignals( true );
58 
59  mTransparencySpnBx->setValue( mEffect->transparency() * 100.0 );
60  mTransparencySlider->setValue( mEffect->transparency() * 1000.0 );
61  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
62  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
63 
64  blockSignals( false );
65 }
66 
67 void QgsDrawSourceWidget::blockSignals( const bool block )
68 {
69  mTransparencySlider->blockSignals( block );
70  mTransparencySpnBx->blockSignals( block );
71  mBlendCmbBx->blockSignals( block );
72  mDrawModeComboBox->blockSignals( block );
73 }
74 
75 void QgsDrawSourceWidget::on_mTransparencySpnBx_valueChanged( double value )
76 {
77  if ( !mEffect )
78  return;
79 
80  mTransparencySlider->blockSignals( true );
81  mTransparencySlider->setValue( value * 10.0 );
82  mTransparencySlider->blockSignals( false );
83 
84  mEffect->setTransparency( value / 100.0 );
85  emit changed();
86 }
87 
88 void QgsDrawSourceWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
89 {
90  Q_UNUSED( index );
91 
92  if ( !mEffect )
93  return;
94 
95  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
96  emit changed();
97 }
98 
99 void QgsDrawSourceWidget::on_mBlendCmbBx_currentIndexChanged( int index )
100 {
101  Q_UNUSED( index );
102 
103  if ( !mEffect )
104  return;
105 
106  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
107  emit changed();
108 }
109 
110 void QgsDrawSourceWidget::on_mTransparencySlider_valueChanged( int value )
111 {
112  mTransparencySpnBx->setValue( value / 10.0 );
113 }
114 
115 
116 //
117 // blur
118 //
119 
121  : QgsPaintEffectWidget( parent )
122  , mEffect( nullptr )
123 {
124  setupUi( this );
125 
126  mBlurTypeCombo->addItem( tr( "Stack blur (fast)" ), QgsBlurEffect::StackBlur );
127  mBlurTypeCombo->addItem( tr( "Gaussian blur (quality)" ), QgsBlurEffect::GaussianBlur );
128 
129  initGui();
130 }
131 
132 
134 {
135  if ( !effect || effect->type() != "blur" )
136  return;
137 
138  mEffect = static_cast<QgsBlurEffect*>( effect );
139  initGui();
140 }
141 
142 void QgsBlurWidget::initGui()
143 {
144  if ( !mEffect )
145  {
146  return;
147  }
148 
149  blockSignals( true );
150 
151  mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
152  mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
153  mTransparencySpnBx->setValue( mEffect->transparency() * 100.0 );
154  mTransparencySlider->setValue( mEffect->transparency() * 1000.0 );
155  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
156  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
157 
158  blockSignals( false );
159 }
160 
161 void QgsBlurWidget::blockSignals( const bool block )
162 {
163  mBlurTypeCombo->blockSignals( block );
164  mBlurStrengthSpnBx->blockSignals( block );
165  mTransparencySlider->blockSignals( block );
166  mTransparencySpnBx->blockSignals( block );
167  mBlendCmbBx->blockSignals( block );
168  mDrawModeComboBox->blockSignals( block );
169 }
170 
171 void QgsBlurWidget::on_mBlurTypeCombo_currentIndexChanged( int index )
172 {
173  if ( !mEffect )
174  return;
175 
176  QgsBlurEffect::BlurMethod method = ( QgsBlurEffect::BlurMethod ) mBlurTypeCombo->itemData( index ).toInt();
177  mEffect->setBlurMethod( method );
178 
179  //also update max radius
180  switch ( method )
181  {
183  mBlurStrengthSpnBx->setMaximum( 16 );
184  break;
186  mBlurStrengthSpnBx->setMaximum( 200 );
187  break;
188  }
189 
190  emit changed();
191 }
192 
193 void QgsBlurWidget::on_mBlurStrengthSpnBx_valueChanged( int value )
194 {
195  if ( !mEffect )
196  return;
197 
198  mEffect->setBlurLevel( value );
199  emit changed();
200 }
201 
202 void QgsBlurWidget::on_mTransparencySpnBx_valueChanged( double value )
203 {
204  if ( !mEffect )
205  return;
206 
207  mTransparencySlider->blockSignals( true );
208  mTransparencySlider->setValue( value * 10.0 );
209  mTransparencySlider->blockSignals( false );
210 
211  mEffect->setTransparency( value / 100.0 );
212  emit changed();
213 }
214 
215 void QgsBlurWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
216 {
217  Q_UNUSED( index );
218 
219  if ( !mEffect )
220  return;
221 
222  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
223  emit changed();
224 }
225 
226 void QgsBlurWidget::on_mBlendCmbBx_currentIndexChanged( int index )
227 {
228  Q_UNUSED( index );
229 
230  if ( !mEffect )
231  return;
232 
233  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
234  emit changed();
235 }
236 
237 void QgsBlurWidget::on_mTransparencySlider_valueChanged( int value )
238 {
239  mTransparencySpnBx->setValue( value / 10.0 );
240 }
241 
242 
243 //
244 // Drop Shadow
245 //
246 
248  : QgsPaintEffectWidget( parent )
249  , mEffect( nullptr )
250 {
251  setupUi( this );
252 
253  mShadowColorBtn->setAllowAlpha( false );
254  mShadowColorBtn->setColorDialogTitle( tr( "Select shadow color" ) );
255  mShadowColorBtn->setContext( "symbology" );
256 
258 
259  initGui();
260 }
261 
263 {
264  if ( !effect || ( effect->type() != "dropShadow" && effect->type() != "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  mShadowTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
287  mShadowTranspSlider->setValue( mEffect->transparency() * 1000.0 );
288  mShadowColorBtn->setColor( mEffect->color() );
289  mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
290  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
291 
292  blockSignals( false );
293 }
294 
295 void QgsShadowEffectWidget::blockSignals( const bool block )
296 {
297  mShadowOffsetAngleSpnBx->blockSignals( block );
298  mShadowOffsetAngleDial->blockSignals( block );
299  mShadowOffsetSpnBx->blockSignals( block );
300  mOffsetUnitWidget->blockSignals( block );
301  mShadowRadiuSpnBx->blockSignals( block );
302  mShadowTranspSpnBx->blockSignals( block );
303  mShadowColorBtn->blockSignals( block );
304  mShadowBlendCmbBx->blockSignals( block );
305  mShadowTranspSlider->blockSignals( block );
306  mDrawModeComboBox->blockSignals( block );
307 }
308 
309 void QgsShadowEffectWidget::on_mShadowOffsetAngleSpnBx_valueChanged( int value )
310 {
311  mShadowOffsetAngleDial->blockSignals( true );
312  mShadowOffsetAngleDial->setValue( value );
313  mShadowOffsetAngleDial->blockSignals( false );
314 
315  if ( !mEffect )
316  return;
317 
318  mEffect->setOffsetAngle( value );
319  emit changed();
320 }
321 
322 void QgsShadowEffectWidget::on_mShadowOffsetAngleDial_valueChanged( int value )
323 {
324  mShadowOffsetAngleSpnBx->setValue( value );
325 }
326 
327 void QgsShadowEffectWidget::on_mShadowOffsetSpnBx_valueChanged( double value )
328 {
329  if ( !mEffect )
330  return;
331 
332  mEffect->setOffsetDistance( value );
333  emit changed();
334 }
335 
336 void QgsShadowEffectWidget::on_mOffsetUnitWidget_changed()
337 {
338  if ( !mEffect )
339  {
340  return;
341  }
342 
343  mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
344  mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
345  emit changed();
346 }
347 
348 void QgsShadowEffectWidget::on_mShadowTranspSpnBx_valueChanged( double value )
349 {
350  if ( !mEffect )
351  return;
352 
353  mShadowTranspSlider->blockSignals( true );
354  mShadowTranspSlider->setValue( value * 10.0 );
355  mShadowTranspSlider->blockSignals( false );
356 
357  mEffect->setTransparency( value / 100.0 );
358  emit changed();
359 }
360 
361 void QgsShadowEffectWidget::on_mShadowColorBtn_colorChanged( const QColor &color )
362 {
363  if ( !mEffect )
364  return;
365 
366  mEffect->setColor( color );
367  emit changed();
368 }
369 
370 void QgsShadowEffectWidget::on_mShadowRadiuSpnBx_valueChanged( int value )
371 {
372  if ( !mEffect )
373  return;
374 
375  mEffect->setBlurLevel( value );
376  emit changed();
377 }
378 
379 void QgsShadowEffectWidget::on_mShadowTranspSlider_valueChanged( int value )
380 {
381  mShadowTranspSpnBx->setValue( value / 10.0 );
382 }
383 
384 void QgsShadowEffectWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
385 {
386  Q_UNUSED( index );
387 
388  if ( !mEffect )
389  return;
390 
391  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
392  emit changed();
393 }
394 
395 void QgsShadowEffectWidget::on_mShadowBlendCmbBx_currentIndexChanged( int index )
396 {
397  Q_UNUSED( index );
398 
399  if ( !mEffect )
400  return;
401 
402  mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
403  emit changed();
404 }
405 
406 
407 
408 //
409 // glow
410 //
411 
413  : QgsPaintEffectWidget( parent )
414  , mEffect( nullptr )
415 {
416  setupUi( this );
417 
418  mColorBtn->setAllowAlpha( false );
419  mColorBtn->setColorDialogTitle( tr( "Select glow color" ) );
420  mColorBtn->setContext( "symbology" );
421 
423 
424  mRampComboBox->populate( QgsStyleV2::defaultStyle() );
425  mRampComboBox->setShowGradientOnly( true );
426  connect( mRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
427  connect( mRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
428  connect( mButtonEditRamp, SIGNAL( clicked() ), mRampComboBox, SLOT( editSourceRamp() ) );
429 
430  connect( radioSingleColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
431 
432  initGui();
433 }
434 
436 {
437  if ( !effect || ( effect->type() != "outerGlow" && effect->type() != "innerGlow" ) )
438  return;
439 
440  mEffect = static_cast<QgsGlowEffect*>( effect );
441  initGui();
442 }
443 
444 void QgsGlowWidget::initGui()
445 {
446  if ( !mEffect )
447  {
448  return;
449  }
450 
451  blockSignals( true );
452 
453  mSpreadSpnBx->setValue( mEffect->spread() );
454  mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
455  mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
456  mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
457  mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
458  mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
459  mColorBtn->setColor( mEffect->color() );
460  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
461 
462  if ( mEffect->ramp() )
463  {
464  mRampComboBox->setSourceColorRamp( mEffect->ramp() );
465  }
466 
467  radioSingleColor->setChecked( mEffect->colorType() == QgsGlowEffect::SingleColor );
468  mColorBtn->setEnabled( mEffect->colorType() == QgsGlowEffect::SingleColor );
469  radioColorRamp->setChecked( mEffect->colorType() == QgsGlowEffect::ColorRamp );
470  mRampComboBox->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
471  mButtonEditRamp->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
472  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
473 
474  blockSignals( false );
475 }
476 
477 void QgsGlowWidget::blockSignals( const bool block )
478 {
479  mSpreadSpnBx->blockSignals( block );
480  mSpreadUnitWidget->blockSignals( block );
481  mBlurRadiusSpnBx->blockSignals( block );
482  mTranspSpnBx->blockSignals( block );
483  mTranspSlider->blockSignals( block );
484  mColorBtn->blockSignals( block );
485  mBlendCmbBx->blockSignals( block );
486  mRampComboBox->blockSignals( block );
487  radioSingleColor->blockSignals( block );
488  radioColorRamp->blockSignals( block );
489  mDrawModeComboBox->blockSignals( block );
490 }
491 
492 void QgsGlowWidget::colorModeChanged()
493 {
494  if ( !mEffect )
495  {
496  return;
497  }
498 
499  if ( radioSingleColor->isChecked() )
500  {
502  }
503  else
504  {
506  mEffect->setRamp( mRampComboBox->currentColorRamp() );
507  }
508  emit changed();
509 }
510 
511 void QgsGlowWidget::on_mSpreadSpnBx_valueChanged( double value )
512 {
513  if ( !mEffect )
514  return;
515 
516  mEffect->setSpread( value );
517  emit changed();
518 }
519 
520 void QgsGlowWidget::on_mSpreadUnitWidget_changed()
521 {
522  if ( !mEffect )
523  {
524  return;
525  }
526 
527  mEffect->setSpreadUnit( mSpreadUnitWidget->unit() );
528  mEffect->setSpreadMapUnitScale( mSpreadUnitWidget->getMapUnitScale() );
529  emit changed();
530 }
531 
532 void QgsGlowWidget::on_mTranspSpnBx_valueChanged( double value )
533 {
534  if ( !mEffect )
535  return;
536 
537  mTranspSlider->blockSignals( true );
538  mTranspSlider->setValue( value * 10.0 );
539  mTranspSlider->blockSignals( false );
540 
541  mEffect->setTransparency( value / 100.0 );
542  emit changed();
543 }
544 
545 void QgsGlowWidget::on_mColorBtn_colorChanged( const QColor &color )
546 {
547  if ( !mEffect )
548  return;
549 
550  mEffect->setColor( color );
551  emit changed();
552 }
553 
554 void QgsGlowWidget::on_mBlurRadiusSpnBx_valueChanged( int value )
555 {
556  if ( !mEffect )
557  return;
558 
559  mEffect->setBlurLevel( value );
560  emit changed();
561 }
562 
563 void QgsGlowWidget::on_mTranspSlider_valueChanged( int value )
564 {
565  mTranspSpnBx->setValue( value / 10.0 );
566 }
567 
568 void QgsGlowWidget::on_mBlendCmbBx_currentIndexChanged( int index )
569 {
570  Q_UNUSED( index );
571 
572  if ( !mEffect )
573  return;
574 
575  mEffect->setBlendMode( mBlendCmbBx->blendMode() );
576  emit changed();
577 }
578 
579 void QgsGlowWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
580 {
581  Q_UNUSED( index );
582 
583  if ( !mEffect )
584  return;
585 
586  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
587  emit changed();
588 }
589 
590 void QgsGlowWidget::applyColorRamp()
591 {
592  if ( !mEffect )
593  {
594  return;
595  }
596 
597  QgsVectorColorRampV2* ramp = mRampComboBox->currentColorRamp();
598  if ( !ramp )
599  return;
600 
601  mEffect->setRamp( ramp );
602  emit changed();
603 }
604 
605 //
606 // transform
607 //
608 
610  : QgsPaintEffectWidget( parent )
611  , mEffect( nullptr )
612 {
613  setupUi( this );
614 
615  mTranslateUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::Pixel << QgsSymbolV2::MapUnit );
616  mSpinTranslateX->setClearValue( 0 );
617  mSpinTranslateY->setClearValue( 0 );
618  mSpinShearX->setClearValue( 0 );
619  mSpinShearY->setClearValue( 0 );
620  mSpinScaleX->setClearValue( 100.0 );
621  mSpinScaleY->setClearValue( 100.0 );
622 
623  initGui();
624 }
625 
626 
628 {
629  if ( !effect || effect->type() != "transform" )
630  return;
631 
632  mEffect = static_cast<QgsTransformEffect*>( effect );
633  initGui();
634 }
635 
636 void QgsTransformWidget::initGui()
637 {
638  if ( !mEffect )
639  {
640  return;
641  }
642 
643  blockSignals( true );
644 
645  mReflectXCheckBox->setChecked( mEffect->reflectX() );
646  mReflectYCheckBox->setChecked( mEffect->reflectY() );
647  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
648  mSpinTranslateX->setValue( mEffect->translateX() );
649  mSpinTranslateY->setValue( mEffect->translateY() );
650  mTranslateUnitWidget->setUnit( mEffect->translateUnit() );
651  mTranslateUnitWidget->setMapUnitScale( mEffect->translateMapUnitScale() );
652  mSpinShearX->setValue( mEffect->shearX() );
653  mSpinShearY->setValue( mEffect->shearY() );
654  mSpinScaleX->setValue( mEffect->scaleX() * 100.0 );
655  mSpinScaleY->setValue( mEffect->scaleY() * 100.0 );
656  mRotationSpinBox->setValue( mEffect->rotation() );
657 
658  blockSignals( false );
659 }
660 
661 void QgsTransformWidget::blockSignals( const bool block )
662 {
663  mDrawModeComboBox->blockSignals( block );
664  mTranslateUnitWidget->blockSignals( block );
665  mSpinTranslateX->blockSignals( block );
666  mSpinTranslateY->blockSignals( block );
667  mReflectXCheckBox->blockSignals( block );
668  mReflectYCheckBox->blockSignals( block );
669  mSpinShearX->blockSignals( block );
670  mSpinShearY->blockSignals( block );
671  mSpinScaleX->blockSignals( block );
672  mSpinScaleY->blockSignals( block );
673  mRotationSpinBox->blockSignals( block );
674 }
675 
676 
677 void QgsTransformWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
678 {
679  Q_UNUSED( index );
680 
681  if ( !mEffect )
682  return;
683 
684  mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
685  emit changed();
686 }
687 
688 void QgsTransformWidget::on_mSpinTranslateX_valueChanged( double value )
689 {
690  if ( !mEffect )
691  return;
692 
693  mEffect->setTranslateX( value );
694  emit changed();
695 }
696 
697 void QgsTransformWidget::on_mSpinTranslateY_valueChanged( double value )
698 {
699  if ( !mEffect )
700  return;
701 
702  mEffect->setTranslateY( value );
703  emit changed();
704 }
705 
706 void QgsTransformWidget::on_mTranslateUnitWidget_changed()
707 {
708  if ( !mEffect )
709  {
710  return;
711  }
712 
713  mEffect->setTranslateUnit( mTranslateUnitWidget->unit() );
714  mEffect->setTranslateMapUnitScale( mTranslateUnitWidget->getMapUnitScale() );
715  emit changed();
716 }
717 
718 void QgsTransformWidget::on_mReflectXCheckBox_stateChanged( int state )
719 {
720  if ( !mEffect )
721  return;
722 
723  mEffect->setReflectX( state == Qt::Checked );
724  emit changed();
725 }
726 
727 void QgsTransformWidget::on_mReflectYCheckBox_stateChanged( int state )
728 {
729  if ( !mEffect )
730  return;
731 
732  mEffect->setReflectY( state == Qt::Checked );
733  emit changed();
734 }
735 
736 void QgsTransformWidget::on_mSpinShearX_valueChanged( double value )
737 {
738  if ( !mEffect )
739  return;
740 
741  mEffect->setShearX( value );
742  emit changed();
743 }
744 
745 void QgsTransformWidget::on_mSpinShearY_valueChanged( double value )
746 {
747  if ( !mEffect )
748  return;
749 
750  mEffect->setShearY( value );
751  emit changed();
752 }
753 
754 void QgsTransformWidget::on_mSpinScaleX_valueChanged( double value )
755 {
756  if ( !mEffect )
757  return;
758 
759  mEffect->setScaleX( value / 100.0 );
760  emit changed();
761 }
762 
763 void QgsTransformWidget::on_mSpinScaleY_valueChanged( double value )
764 {
765  if ( !mEffect )
766  return;
767 
768  mEffect->setScaleY( value / 100.0 );
769  emit changed();
770 }
771 
772 void QgsTransformWidget::on_mRotationSpinBox_valueChanged( double value )
773 {
774  if ( !mEffect )
775  return;
776 
777  mEffect->setRotation( value );
778  emit changed();
779 }
780 
781 
782 //
783 // color effect
784 //
785 
787  : QgsPaintEffectWidget( parent )
788  , mEffect( nullptr )
789 {
790  setupUi( this );
791 
792  mBrightnessSpinBox->setClearValue( 0 );
793  mContrastSpinBox->setClearValue( 0 );
794  mSaturationSpinBox->setClearValue( 0 );
795  mColorizeColorButton->setAllowAlpha( false );
796 
797  mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
798  mGrayscaleCombo->addItem( tr( "By lightness" ), QgsImageOperation::GrayscaleLightness );
799  mGrayscaleCombo->addItem( tr( "By luminosity" ), QgsImageOperation::GrayscaleLuminosity );
800  mGrayscaleCombo->addItem( tr( "By average" ), QgsImageOperation::GrayscaleAverage );
801 
802  initGui();
803 }
804 
806 {
807  if ( !effect || effect->type() != "color" )
808  return;
809 
810  mEffect = static_cast<QgsColorEffect*>( effect );
811  initGui();
812 }
813 
814 void QgsColorEffectWidget::initGui()
815 {
816  if ( !mEffect )
817  {
818  return;
819  }
820 
821  blockSignals( true );
822 
823  mSliderBrightness->setValue( mEffect->brightness() );
824  mSliderContrast->setValue( mEffect->contrast() );
825  mSliderSaturation->setValue(( mEffect->saturation() - 1.0 ) * 100.0 );
826  mColorizeCheck->setChecked( mEffect->colorizeOn() );
827  mSliderColorizeStrength->setValue( mEffect->colorizeStrength() );
828  mColorizeColorButton->setColor( mEffect->colorizeColor() );
829  int grayscaleIdx = mGrayscaleCombo->findData( QVariant(( int ) mEffect->grayscaleMode() ) );
830  mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
831  mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
832  mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
833  mBlendCmbBx->setBlendMode( mEffect->blendMode() );
834  mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
835  enableColorizeControls( mEffect->colorizeOn() );
836 
837  blockSignals( false );
838 }
839 
840 void QgsColorEffectWidget::blockSignals( const bool block )
841 {
842  mBrightnessSpinBox->blockSignals( block );
843  mContrastSpinBox->blockSignals( block );
844  mSaturationSpinBox->blockSignals( block );
845  mColorizeStrengthSpinBox->blockSignals( block );
846  mColorizeCheck->blockSignals( block );
847  mColorizeColorButton->blockSignals( block );
848  mGrayscaleCombo->blockSignals( block );
849  mTranspSpnBx->blockSignals( block );
850  mTranspSlider->blockSignals( block );
851  mBlendCmbBx->blockSignals( block );
852  mDrawModeComboBox->blockSignals( block );
853 }
854 
855 void QgsColorEffectWidget::enableColorizeControls( const bool enable )
856 {
857  mSliderColorizeStrength->setEnabled( enable );
858  mColorizeStrengthSpinBox->setEnabled( enable );
859  mColorizeColorButton->setEnabled( enable );
860 }
861 
862 void QgsColorEffectWidget::on_mTranspSpnBx_valueChanged( double value )
863 {
864  if ( !mEffect )
865  return;
866 
867  mTranspSlider->blockSignals( true );
868  mTranspSlider->setValue( value * 10.0 );
869  mTranspSlider->blockSignals( false );
870 
871  mEffect->setTransparency( value / 100.0 );
872  emit changed();
873 }
874 
875 void QgsColorEffectWidget::on_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::on_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::on_mTranspSlider_valueChanged( int value )
898 {
899  mTranspSpnBx->setValue( value / 10.0 );
900 }
901 
902 void QgsColorEffectWidget::on_mBrightnessSpinBox_valueChanged( int value )
903 {
904  if ( !mEffect )
905  return;
906 
907  mEffect->setBrightness( value );
908  emit changed();
909 }
910 
911 void QgsColorEffectWidget::on_mContrastSpinBox_valueChanged( int value )
912 {
913  if ( !mEffect )
914  return;
915 
916  mEffect->setContrast( value );
917  emit changed();
918 }
919 
920 void QgsColorEffectWidget::on_mSaturationSpinBox_valueChanged( int value )
921 {
922  if ( !mEffect )
923  return;
924 
925  mEffect->setSaturation( value / 100.0 + 1 );
926  emit changed();
927 }
928 
929 void QgsColorEffectWidget::on_mColorizeStrengthSpinBox_valueChanged( int value )
930 {
931  if ( !mEffect )
932  return;
933 
934  mEffect->setColorizeStrength( value );
935  emit changed();
936 }
937 
938 void QgsColorEffectWidget::on_mColorizeCheck_stateChanged( int state )
939 {
940  if ( !mEffect )
941  return;
942 
943  mEffect->setColorizeOn( state == Qt::Checked );
944  enableColorizeControls( state == Qt::Checked );
945  emit changed();
946 }
947 
948 void QgsColorEffectWidget::on_mColorizeColorButton_colorChanged( const QColor &color )
949 {
950  if ( !mEffect )
951  return;
952 
953  mEffect->setColorizeColor( color );
954  emit changed();
955 }
956 
957 void QgsColorEffectWidget::on_mGrayscaleCombo_currentIndexChanged( int index )
958 {
959  Q_UNUSED( index );
960 
961  if ( !mEffect )
962  return;
963 
964  mEffect->setGrayscaleMode(( QgsImageOperation::GrayscaleMode ) mGrayscaleCombo->itemData( mGrayscaleCombo->currentIndex() ).toInt() );
965  emit changed();
966 }
void setShearY(const double shearY)
Sets the y axis shearing factor.
static unsigned index
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.
QgsDrawSourceWidget(QWidget *parent=nullptr)
void setupUi(QWidget *widget)
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
Definition: qgsblureffect.h:78
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
void setTranslateUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the transform translation.
Base class for effect properties widgets.
bool reflectX() const
Returns whether transform will be reflected along the x-axis.
void setSpreadUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the glow spread distance.
Definition: qgsgloweffect.h:75
void setTransparency(const double transparency)
Sets the transparency for the effect.
The output shall be in pixels.
Definition: qgssymbolv2.h:70
void setColorizeColor(const QColor &colorizeColor)
Sets the color used for colorizing a picture.
double offsetDistance() const
Returns the distance used for offsetting the shadow.
double transparency() const
Returns the transparency for the effect.
Definition: qgsblureffect.h:98
Base class for visual effects which can be applied to QPicture drawings.
void setDrawMode(const DrawMode drawMode)
Sets the draw mode for the effect.
void setColorizeStrength(int colorizeStrength)
Sets the strength for colorizing a picture.
double shearY() const
Returns the y axis shearing factor.
void setBlurLevel(const int level)
Sets blur level (strength) for the shadow.
double scaleX() const
Returns the x axis scaling factor.
DrawMode drawMode() const
Returns the draw mode for the effect.
QgsSymbolV2::OutputUnit spreadUnit() const
Returns the units used for the glow spread distance.
Definition: qgsgloweffect.h:83
void setBlurLevel(const int level)
Sets blur level (strength)
Definition: qgsblureffect.h:64
void setOffsetUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the shadow offset distance.
double transparency() const
Returns the transparency for the effect.
QString tr(const char *sourceText, const char *disambiguation, int n)
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
Definition: qgsblureffect.h:84
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Base class for paint effect which draw a glow inside or outside a picture.
Definition: qgsgloweffect.h:34
void setTranslateY(const double translateY)
Sets the transform y translation.
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
void setTransparency(const double transparency)
Sets the transparency for the effect.
void setTransparency(const double transparency)
Sets the transparency for the effect.
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.
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:38
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
Definition: qgsgloweffect.h:91
void setBlurLevel(const int level)
Sets blur level (strength) for the glow.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
The output shall be in millimeters.
Definition: qgssymbolv2.h:67
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.
static QgsStyleV2 * defaultStyle()
return default application-wide style
Definition: qgsstylev2.cpp:51
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
int blurLevel() const
Returns the blur level (strength)
Definition: qgsblureffect.h:72
double translateX() const
Returns the transform x translation.
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
Definition: qgsgloweffect.h:99
QgsBlurWidget(QWidget *parent=nullptr)
double scaleY() const
Returns the y axis scaling factor.
The output shall be in map unitx.
Definition: qgssymbolv2.h:68
QgsSymbolV2::OutputUnit translateUnit() const
Returns the units used for the transform translation.
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:59
QgsShadowEffectWidget(QWidget *parent=nullptr)
int blurLevel() const
Returns the blur level (strength) for the shadow.
double transparency() const
Returns the transparency for the effect.
double rotation() const
Returns the transform rotation.
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:32
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...
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
double shearX() const
Returns the x axis shearing factor.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow offset distance.
void setRamp(QgsVectorColorRampV2 *ramp)
Sets the color ramp for the glow.
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.
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
double spread() const
Returns the spread distance used for drawing the glow effect.
Definition: qgsgloweffect.h:67
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 (eg brightness, contrast) in a source picture.
void setReflectY(const bool reflectY)
Sets whether to reflect along the y-axis.
QgsTransformWidget(QWidget *parent=nullptr)
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.
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
virtual void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units used for the shadow offset distance.
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 transparency() const
Returns the transparency for the effect.
A paint effect which draws the source picture with minor or no alterations.
double transparency() const
Returns the transparency for the effect.
GrayscaleMode
Modes for converting a QImage to grayscale.
void setTransparency(const double transparency)
Sets the transparency for the effect.
Definition: qgsblureffect.h:91
bool colorizeOn() const
Returns whether the effect will colorize a picture.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
int contrast() const
Returns the contrast modification for the effect.
Abstract base class for color ramps.
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.
void setTransparency(const double transparency)
Sets the transparency for the effect.
QgsVectorColorRampV2 * ramp() const
Returns the color ramp used 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.
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.