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