QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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#include "qgslogger.h"
19#include "qgspainteffect.h"
20#include "qgsshadoweffect.h"
21#include "qgsblureffect.h"
22#include "qgsgloweffect.h"
23#include "qgstransformeffect.h"
24#include "qgscoloreffect.h"
25#include "qgsstyle.h"
26#include "qgscolorramp.h"
27#include "qgscolorrampbutton.h"
28
29//
30// draw source
31//
32
34 : QgsPaintEffectWidget( parent )
35
36{
37 setupUi( this );
38 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged );
39 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged );
40 initGui();
41}
42
43
45{
46 if ( !effect || effect->type() != QLatin1String( "drawSource" ) )
47 return;
48
49 mEffect = static_cast<QgsDrawSourceEffect *>( effect );
50 initGui();
51
52 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsDrawSourceWidget::opacityChanged );
53}
54
55void QgsDrawSourceWidget::initGui()
56{
57 if ( !mEffect )
58 {
59 return;
60 }
61
62 blockSignals( true );
63
64 mOpacityWidget->setOpacity( mEffect->opacity() );
65 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
66 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
67
68 blockSignals( false );
69}
70
71void QgsDrawSourceWidget::blockSignals( const bool block )
72{
73 mOpacityWidget->blockSignals( block );
74 mBlendCmbBx->blockSignals( block );
75 mDrawModeComboBox->blockSignals( block );
76}
77
78void QgsDrawSourceWidget::opacityChanged( double value )
79{
80 if ( !mEffect )
81 return;
82
83 mEffect->setOpacity( value );
84 emit changed();
85}
86
87void QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged( int index )
88{
89 Q_UNUSED( index )
90
91 if ( !mEffect )
92 return;
93
94 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
95 emit changed();
96}
97
98void QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged( int index )
99{
100 Q_UNUSED( index )
101
102 if ( !mEffect )
103 return;
104
105 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
106 emit changed();
107}
108
109
110//
111// blur
112//
113
115 : QgsPaintEffectWidget( parent )
116
117{
118 setupUi( this );
119 connect( mBlurTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlurTypeCombo_currentIndexChanged );
120 connect( mBlurStrengthSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsBlurWidget::mBlurStrengthSpnBx_valueChanged );
121 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsBlurWidget::mBlurUnitWidget_changed );
122 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mDrawModeComboBox_currentIndexChanged );
123 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlendCmbBx_currentIndexChanged );
124
125 mBlurTypeCombo->addItem( tr( "Stack Blur (fast, doesn't support high dpi)" ), QgsBlurEffect::StackBlur );
126 mBlurTypeCombo->addItem( tr( "Gaussian Blur (quality, supports high dpi)" ), QgsBlurEffect::GaussianBlur );
127
130
131 initGui();
132 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsBlurWidget::opacityChanged );
133}
134
135
137{
138 if ( !effect || effect->type() != QLatin1String( "blur" ) )
139 return;
140
141 mEffect = static_cast<QgsBlurEffect *>( effect );
142 initGui();
143}
144
145void QgsBlurWidget::initGui()
146{
147 if ( !mEffect )
148 {
149 return;
150 }
151
152 blockSignals( true );
153
154 mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
155 mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
156 mOpacityWidget->setOpacity( mEffect->opacity() );
157 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
158 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
159
160 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
161 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
162
163 blockSignals( false );
164}
165
166void QgsBlurWidget::blockSignals( const bool block )
167{
168 mBlurTypeCombo->blockSignals( block );
169 mBlurStrengthSpnBx->blockSignals( block );
170 mOpacityWidget->blockSignals( block );
171 mBlendCmbBx->blockSignals( block );
172 mDrawModeComboBox->blockSignals( block );
173}
174
175void QgsBlurWidget::mBlurTypeCombo_currentIndexChanged( int index )
176{
177 if ( !mEffect )
178 return;
179
180 const QgsBlurEffect::BlurMethod method = ( QgsBlurEffect::BlurMethod ) mBlurTypeCombo->itemData( index ).toInt();
181 mEffect->setBlurMethod( method );
182
183 //also update max radius
184 switch ( method )
185 {
187 mBlurStrengthSpnBx->setMaximum( 16 );
188 break;
190 mBlurStrengthSpnBx->setMaximum( 200 );
191 break;
192 }
193
194 emit changed();
195}
196
197void QgsBlurWidget::mBlurStrengthSpnBx_valueChanged( double value )
198{
199 if ( !mEffect )
200 return;
201
202 mEffect->setBlurLevel( value );
203 emit changed();
204}
205
206void QgsBlurWidget::mBlurUnitWidget_changed()
207{
208 if ( !mEffect )
209 {
210 return;
211 }
212
213 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
214 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
215 emit changed();
216}
217
218void QgsBlurWidget::opacityChanged( double value )
219{
220 if ( !mEffect )
221 return;
222
223 mEffect->setOpacity( value );
224 emit changed();
225}
226
227void QgsBlurWidget::mDrawModeComboBox_currentIndexChanged( int index )
228{
229 Q_UNUSED( index )
230
231 if ( !mEffect )
232 return;
233
234 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
235 emit changed();
236}
237
238void QgsBlurWidget::mBlendCmbBx_currentIndexChanged( int index )
239{
240 Q_UNUSED( index )
241
242 if ( !mEffect )
243 return;
244
245 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
246 emit changed();
247}
248
249
250//
251// Drop Shadow
252//
253
255 : QgsPaintEffectWidget( parent )
256
257{
258 setupUi( this );
259 connect( mShadowOffsetAngleSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged );
260 connect( mShadowOffsetAngleDial, &QDial::valueChanged, this, &QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged );
261 connect( mShadowOffsetSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged );
262 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mOffsetUnitWidget_changed );
263 connect( mShadowColorBtn, &QgsColorButton::colorChanged, this, &QgsShadowEffectWidget::mShadowColorBtn_colorChanged );
264 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged );
265 connect( mShadowBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged );
266 connect( mShadowRadiuSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged );
267 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mBlurUnitWidget_changed );
268
269 mShadowColorBtn->setAllowOpacity( false );
270 mShadowColorBtn->setColorDialogTitle( tr( "Select Shadow Color" ) );
271 mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
272 mShadowOffsetAngleSpnBx->setClearValue( 0 );
273
278
279 initGui();
280
281 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsShadowEffectWidget::opacityChanged );
282}
283
285{
286 if ( !effect || ( effect->type() != QLatin1String( "dropShadow" ) && effect->type() != QLatin1String( "innerShadow" ) ) )
287 return;
288
289 mEffect = static_cast<QgsShadowEffect *>( effect );
290 initGui();
291}
292
293void QgsShadowEffectWidget::initGui()
294{
295 if ( !mEffect )
296 {
297 return;
298 }
299
300 blockSignals( true );
301
302 mShadowOffsetAngleSpnBx->setValue( mEffect->offsetAngle() );
303 mShadowOffsetAngleDial->setValue( mEffect->offsetAngle() );
304 mShadowOffsetSpnBx->setValue( mEffect->offsetDistance() );
305 mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
306 mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
307 mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
308 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
309 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
310 mOpacityWidget->setOpacity( mEffect->opacity() );
311 mShadowColorBtn->setColor( mEffect->color() );
312 mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
313 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
314
315 blockSignals( false );
316}
317
318void QgsShadowEffectWidget::blockSignals( const bool block )
319{
320 mShadowOffsetAngleSpnBx->blockSignals( block );
321 mShadowOffsetAngleDial->blockSignals( block );
322 mShadowOffsetSpnBx->blockSignals( block );
323 mOffsetUnitWidget->blockSignals( block );
324 mShadowRadiuSpnBx->blockSignals( block );
325 mBlurUnitWidget->blockSignals( block );
326 mOpacityWidget->blockSignals( block );
327 mShadowColorBtn->blockSignals( block );
328 mShadowBlendCmbBx->blockSignals( block );
329 mDrawModeComboBox->blockSignals( block );
330}
331
332void QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged( int value )
333{
334 mShadowOffsetAngleDial->blockSignals( true );
335 mShadowOffsetAngleDial->setValue( value );
336 mShadowOffsetAngleDial->blockSignals( false );
337
338 if ( !mEffect )
339 return;
340
341 mEffect->setOffsetAngle( value );
342 emit changed();
343}
344
345void QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged( int value )
346{
347 mShadowOffsetAngleSpnBx->setValue( value );
348}
349
350void QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged( double value )
351{
352 if ( !mEffect )
353 return;
354
355 mEffect->setOffsetDistance( value );
356 emit changed();
357}
358
359void QgsShadowEffectWidget::mOffsetUnitWidget_changed()
360{
361 if ( !mEffect )
362 {
363 return;
364 }
365
366 mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
367 mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
368 emit changed();
369}
370
371void QgsShadowEffectWidget::opacityChanged( double value )
372{
373 if ( !mEffect )
374 return;
375
376 mEffect->setOpacity( value );
377 emit changed();
378}
379
380void QgsShadowEffectWidget::mShadowColorBtn_colorChanged( const QColor &color )
381{
382 if ( !mEffect )
383 return;
384
385 mEffect->setColor( color );
386 emit changed();
387}
388
389void QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged( double value )
390{
391 if ( !mEffect )
392 return;
393
394 mEffect->setBlurLevel( value );
395 emit changed();
396}
397
398void QgsShadowEffectWidget::mBlurUnitWidget_changed()
399{
400 if ( !mEffect )
401 {
402 return;
403 }
404
405 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
406 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
407 emit changed();
408}
409
410void QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
411{
412 Q_UNUSED( index )
413
414 if ( !mEffect )
415 return;
416
417 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
418 emit changed();
419}
420
421void QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged( int index )
422{
423 Q_UNUSED( index )
424
425 if ( !mEffect )
426 return;
427
428 mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
429 emit changed();
430}
431
432
433
434//
435// glow
436//
437
439 : QgsPaintEffectWidget( parent )
440
441{
442 setupUi( this );
443 connect( mSpreadSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mSpreadSpnBx_valueChanged );
444 connect( mSpreadUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mSpreadUnitWidget_changed );
445 connect( mColorBtn, &QgsColorButton::colorChanged, this, &QgsGlowWidget::mColorBtn_colorChanged );
446 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mBlendCmbBx_currentIndexChanged );
447 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mDrawModeComboBox_currentIndexChanged );
448 connect( mBlurRadiusSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mBlurRadiusSpnBx_valueChanged );
449 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mBlurUnitWidget_changed );
450
451 mColorBtn->setAllowOpacity( false );
452 mColorBtn->setColorDialogTitle( tr( "Select Glow Color" ) );
453 mColorBtn->setContext( QStringLiteral( "symbology" ) );
454
459
460 btnColorRamp->setShowGradientOnly( true );
461
462 initGui();
463
464 connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsGlowWidget::applyColorRamp );
465 connect( radioSingleColor, &QAbstractButton::toggled, this, &QgsGlowWidget::colorModeChanged );
466 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsGlowWidget::opacityChanged );
467}
468
470{
471 if ( !effect || ( effect->type() != QLatin1String( "outerGlow" ) && effect->type() != QLatin1String( "innerGlow" ) ) )
472 return;
473
474 mEffect = static_cast<QgsGlowEffect *>( effect );
475 initGui();
476}
477
478void QgsGlowWidget::initGui()
479{
480 if ( !mEffect )
481 {
482 return;
483 }
484
485 blockSignals( true );
486
487 mSpreadSpnBx->setValue( mEffect->spread() );
488 mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
489 mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
490 mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
491 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
492 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
493 mOpacityWidget->setOpacity( mEffect->opacity() );
494 mColorBtn->setColor( mEffect->color() );
495 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
496
497 if ( mEffect->ramp() )
498 {
499 btnColorRamp->setColorRamp( mEffect->ramp() );
500 }
501
502 radioSingleColor->setChecked( mEffect->colorType() == QgsGlowEffect::SingleColor );
503 mColorBtn->setEnabled( mEffect->colorType() == QgsGlowEffect::SingleColor );
504 radioColorRamp->setChecked( mEffect->colorType() == QgsGlowEffect::ColorRamp );
505 btnColorRamp->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
506 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
507
508 blockSignals( false );
509}
510
511void QgsGlowWidget::blockSignals( const bool block )
512{
513 mSpreadSpnBx->blockSignals( block );
514 mSpreadUnitWidget->blockSignals( block );
515 mBlurRadiusSpnBx->blockSignals( block );
516 mOpacityWidget->blockSignals( block );
517 mColorBtn->blockSignals( block );
518 mBlendCmbBx->blockSignals( block );
519 btnColorRamp->blockSignals( block );
520 radioSingleColor->blockSignals( block );
521 radioColorRamp->blockSignals( block );
522 mDrawModeComboBox->blockSignals( block );
523}
524
525void QgsGlowWidget::colorModeChanged()
526{
527 if ( !mEffect )
528 {
529 return;
530 }
531
532 if ( radioSingleColor->isChecked() )
533 {
535 }
536 else
537 {
539 mEffect->setRamp( btnColorRamp->colorRamp() );
540 }
541 emit changed();
542}
543
544void QgsGlowWidget::mSpreadSpnBx_valueChanged( double value )
545{
546 if ( !mEffect )
547 return;
548
549 mEffect->setSpread( value );
550 emit changed();
551}
552
553void QgsGlowWidget::mSpreadUnitWidget_changed()
554{
555 if ( !mEffect )
556 {
557 return;
558 }
559
560 mEffect->setSpreadUnit( mSpreadUnitWidget->unit() );
561 mEffect->setSpreadMapUnitScale( mSpreadUnitWidget->getMapUnitScale() );
562 emit changed();
563}
564
565void QgsGlowWidget::opacityChanged( double value )
566{
567 if ( !mEffect )
568 return;
569
570 mEffect->setOpacity( value );
571 emit changed();
572}
573
574void QgsGlowWidget::mColorBtn_colorChanged( const QColor &color )
575{
576 if ( !mEffect )
577 return;
578
579 mEffect->setColor( color );
580 emit changed();
581}
582
583void QgsGlowWidget::mBlurRadiusSpnBx_valueChanged( double value )
584{
585 if ( !mEffect )
586 return;
587
588 mEffect->setBlurLevel( value );
589 emit changed();
590}
591
592void QgsGlowWidget::mBlurUnitWidget_changed()
593{
594 if ( !mEffect )
595 {
596 return;
597 }
598
599 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
600 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
601 emit changed();
602}
603
604void QgsGlowWidget::mBlendCmbBx_currentIndexChanged( int index )
605{
606 Q_UNUSED( index )
607
608 if ( !mEffect )
609 return;
610
611 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
612 emit changed();
613}
614
615void QgsGlowWidget::mDrawModeComboBox_currentIndexChanged( int index )
616{
617 Q_UNUSED( index )
618
619 if ( !mEffect )
620 return;
621
622 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
623 emit changed();
624}
625
626void QgsGlowWidget::applyColorRamp()
627{
628 if ( !mEffect )
629 {
630 return;
631 }
632
633 QgsColorRamp *ramp = btnColorRamp->colorRamp();
634 if ( !ramp )
635 return;
636
637 mEffect->setRamp( ramp );
638 emit changed();
639}
640
641//
642// transform
643//
644
646 : QgsPaintEffectWidget( parent )
647
648{
649 setupUi( this );
650 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsTransformWidget::mDrawModeComboBox_currentIndexChanged );
651 connect( mSpinTranslateX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateX_valueChanged );
652 connect( mSpinTranslateY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateY_valueChanged );
653 connect( mTranslateUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsTransformWidget::mTranslateUnitWidget_changed );
654 connect( mReflectXCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectXCheckBox_stateChanged );
655 connect( mReflectYCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectYCheckBox_stateChanged );
656 connect( mSpinShearX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearX_valueChanged );
657 connect( mSpinShearY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearY_valueChanged );
658 connect( mSpinScaleX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleX_valueChanged );
659 connect( mSpinScaleY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleY_valueChanged );
660 connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mRotationSpinBox_valueChanged );
661
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() != QLatin1String( "transform" ) )
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() != QLatin1String( "color" ) )
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.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
A paint effect which blurs a source picture, using a number of different blur methods.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the blur level (radius).
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the blur strength (radius).
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Qgis::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
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.
double opacity() const
Returns the opacity for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
double blurLevel() const
Returns the blur level (radius)
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setBlurLevel(const double level)
Sets blur level (radius)
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.
bool colorizeOn() const
Returns whether the effect will colorize a picture.
QgsImageOperation::GrayscaleMode grayscaleMode() const
Returns whether the effect will convert a picture to grayscale.
double opacity() const
Returns the opacity for the effect.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setSaturation(double saturation)
Sets the saturation modification for the effect.
void setColorizeStrength(int colorizeStrength)
Sets the strength for colorizing a picture.
int colorizeStrength() const
Returns the strength used for colorizing a picture.
void setColorizeColor(const QColor &colorizeColor)
Sets the color used for colorizing a picture.
void setColorizeOn(bool colorizeOn)
Sets whether the effect should colorize a picture.
int contrast() const
Returns the contrast modification for the effect.
int brightness() const
Returns the brightness modification for the effect.
void setContrast(int contrast)
Sets the contrast modification for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double saturation() const
Returns the saturation modification for the effect.
void setBrightness(int brightness)
Sets the brightness modification for the effect.
QColor colorizeColor() const
Returns the color used for colorizing a picture.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setGrayscaleMode(QgsImageOperation::GrayscaleMode grayscaleMode)
Sets whether the effect should convert a picture to grayscale.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
Abstract base class for color ramps.
A paint effect which draws the source picture with minor or no alterations.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double opacity() const
Returns the opacity for the effect.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
QgsDrawSourceWidget(QWidget *parent=nullptr)
Base class for paint effect which draw a glow inside or outside a picture.
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
Qgis::RenderUnit blurUnit() const
Returns the units used for the glow blur level (radius).
void setOpacity(const double opacity)
Sets the opacity for the effect.
double spread() const
Returns the spread distance used for drawing the glow effect.
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
@ SingleColor
Use a single color and fade the color to totally transparent.
@ ColorRamp
Use colors from a color ramp.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
double blurLevel() const
Returns the blur level (radius) for the glow.
double opacity() const
Returns the opacity for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QColor color() const
Returns the color for the glow.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the glow blur strength (radius).
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the glow blur level (radius).
void setBlurLevel(const double level)
Sets blur level (radius) for the glow.
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
Qgis::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
void setRamp(QgsColorRamp *ramp)
Sets the color ramp for the glow.
void setSpreadUnit(const Qgis::RenderUnit unit)
Sets the units used for the glow spread distance.
void setColor(const QColor &color)
Sets the color for the glow.
GlowColorType colorType() const
Returns the color mode used for the glow.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the glow blur strength (radius).
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....
Base class for effect properties widgets.
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.
void setDrawMode(DrawMode drawMode)
Sets the draw mode for the effect.
DrawMode drawMode() const
Returns the draw mode for the effect.
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 offset, blurred shadows.
int offsetAngle() const
Returns the angle used for offsetting the shadow.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setColor(const QColor &color)
Sets the color for the shadow.
double opacity() const
Returns the opacity for the effect.
Qgis::RenderUnit offsetUnit() const
Returns the units used for the shadow offset distance.
QColor color() const
Returns the color used for the shadow.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Qgis::RenderUnit blurUnit() const
Returns the units used for the shadow blur level (radius).
void setBlurLevel(const double level)
Sets blur level (radius) for the shadow.
void setOffsetUnit(const Qgis::RenderUnit unit)
Sets the units used for the shadow offset distance.
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
double blurLevel() const
Returns the blur level (radius) for the shadow.
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the shadow blur level (radius).
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale used for the shadow offset distance.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow offset distance.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double offsetDistance() const
Returns the distance used for offsetting the shadow.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the shadow blur strength (radius).
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow blur strength (radius).
A paint effect which applies transformations (such as move, scale and rotate) to a picture.
void setTranslateX(const double translateX)
Sets the transform x translation.
void setReflectX(const bool reflectX)
Sets whether to reflect along the x-axis.
void setReflectY(const bool reflectY)
Sets whether to reflect along the y-axis.
double translateX() const
Returns the transform x translation.
void setScaleX(const double scaleX)
Sets the x axis scaling factor.
const QgsMapUnitScale & translateMapUnitScale() const
Returns the map unit scale used for the transform translation.
void setShearY(const double shearY)
Sets the y axis shearing factor.
double translateY() const
Returns the transform y translation.
void setScaleY(const double scaleY)
Sets the y axis scaling factor.
void setTranslateUnit(const Qgis::RenderUnit unit)
Sets the units used for the transform translation.
double rotation() const
Returns the transform rotation, in degrees clockwise.
double shearY() const
Returns the y axis shearing factor.
void setRotation(const double rotation)
Sets the transform rotation, in degrees clockwise.
void setShearX(const double shearX)
Sets the x axis shearing factor.
double shearX() const
Returns the x axis shearing factor.
bool reflectY() const
Returns whether transform will be reflected along the y-axis.
Qgis::RenderUnit translateUnit() const
Returns the units used for the transform translation.
void setTranslateMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the transform translation.
double scaleY() const
Returns the y axis scaling factor.
bool reflectX() const
Returns whether transform will be reflected along the x-axis.
double scaleX() const
Returns the x axis scaling factor.
void setTranslateY(const double translateY)
Sets the transform y translation.
QgsTransformWidget(QWidget *parent=nullptr)
void setPaintEffect(QgsPaintEffect *effect) override
Sets the paint effect to modify with the widget.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.