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