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