QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 "moc_qgspainteffectwidget.cpp"
19#include "qgslogger.h"
20#include "qgspainteffect.h"
21#include "qgsshadoweffect.h"
22#include "qgsblureffect.h"
23#include "qgsgloweffect.h"
24#include "qgstransformeffect.h"
25#include "qgscoloreffect.h"
26#include "qgsstyle.h"
27#include "qgscolorramp.h"
28#include "qgscolorrampbutton.h"
29
30//
31// draw source
32//
33
35 : QgsPaintEffectWidget( parent )
36
37{
38 setupUi( this );
39 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged );
40 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged );
41 initGui();
42}
43
44
46{
47 if ( !effect || effect->type() != QLatin1String( "drawSource" ) )
48 return;
49
50 mEffect = static_cast<QgsDrawSourceEffect *>( effect );
51 initGui();
52
53 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsDrawSourceWidget::opacityChanged );
54}
55
56void QgsDrawSourceWidget::initGui()
57{
58 if ( !mEffect )
59 {
60 return;
61 }
62
63 blockSignals( true );
64
65 mOpacityWidget->setOpacity( mEffect->opacity() );
66 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
67 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
68
69 blockSignals( false );
70}
71
72void QgsDrawSourceWidget::blockSignals( const bool block )
73{
74 mOpacityWidget->blockSignals( block );
75 mBlendCmbBx->blockSignals( block );
76 mDrawModeComboBox->blockSignals( block );
77}
78
79void QgsDrawSourceWidget::opacityChanged( double value )
80{
81 if ( !mEffect )
82 return;
83
84 mEffect->setOpacity( value );
85 emit changed();
86}
87
88void QgsDrawSourceWidget::mDrawModeComboBox_currentIndexChanged( int index )
89{
90 Q_UNUSED( index )
91
92 if ( !mEffect )
93 return;
94
95 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
96 emit changed();
97}
98
99void QgsDrawSourceWidget::mBlendCmbBx_currentIndexChanged( int index )
100{
101 Q_UNUSED( index )
102
103 if ( !mEffect )
104 return;
105
106 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
107 emit changed();
108}
109
110
111//
112// blur
113//
114
116 : QgsPaintEffectWidget( parent )
117
118{
119 setupUi( this );
120 connect( mBlurTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlurTypeCombo_currentIndexChanged );
121 connect( mBlurStrengthSpnBx, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsBlurWidget::mBlurStrengthSpnBx_valueChanged );
122 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsBlurWidget::mBlurUnitWidget_changed );
123 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mDrawModeComboBox_currentIndexChanged );
124 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsBlurWidget::mBlendCmbBx_currentIndexChanged );
125
126 mBlurTypeCombo->addItem( tr( "Stack Blur (fast, doesn't support high dpi)" ), QgsBlurEffect::StackBlur );
127 mBlurTypeCombo->addItem( tr( "Gaussian Blur (quality, supports high dpi)" ), QgsBlurEffect::GaussianBlur );
128
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
276
277 initGui();
278
279 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsShadowEffectWidget::opacityChanged );
280}
281
283{
284 if ( !effect || ( effect->type() != QLatin1String( "dropShadow" ) && effect->type() != QLatin1String( "innerShadow" ) ) )
285 return;
286
287 mEffect = static_cast<QgsShadowEffect *>( effect );
288 initGui();
289}
290
291void QgsShadowEffectWidget::initGui()
292{
293 if ( !mEffect )
294 {
295 return;
296 }
297
298 blockSignals( true );
299
300 mShadowOffsetAngleSpnBx->setValue( mEffect->offsetAngle() );
301 mShadowOffsetAngleDial->setValue( mEffect->offsetAngle() );
302 mShadowOffsetSpnBx->setValue( mEffect->offsetDistance() );
303 mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
304 mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
305 mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
306 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
307 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
308 mOpacityWidget->setOpacity( mEffect->opacity() );
309 mShadowColorBtn->setColor( mEffect->color() );
310 mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
311 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
312
313 blockSignals( false );
314}
315
316void QgsShadowEffectWidget::blockSignals( const bool block )
317{
318 mShadowOffsetAngleSpnBx->blockSignals( block );
319 mShadowOffsetAngleDial->blockSignals( block );
320 mShadowOffsetSpnBx->blockSignals( block );
321 mOffsetUnitWidget->blockSignals( block );
322 mShadowRadiuSpnBx->blockSignals( block );
323 mBlurUnitWidget->blockSignals( block );
324 mOpacityWidget->blockSignals( block );
325 mShadowColorBtn->blockSignals( block );
326 mShadowBlendCmbBx->blockSignals( block );
327 mDrawModeComboBox->blockSignals( block );
328}
329
330void QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged( int value )
331{
332 mShadowOffsetAngleDial->blockSignals( true );
333 mShadowOffsetAngleDial->setValue( value );
334 mShadowOffsetAngleDial->blockSignals( false );
335
336 if ( !mEffect )
337 return;
338
339 mEffect->setOffsetAngle( value );
340 emit changed();
341}
342
343void QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged( int value )
344{
345 mShadowOffsetAngleSpnBx->setValue( value );
346}
347
348void QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged( double value )
349{
350 if ( !mEffect )
351 return;
352
353 mEffect->setOffsetDistance( value );
354 emit changed();
355}
356
357void QgsShadowEffectWidget::mOffsetUnitWidget_changed()
358{
359 if ( !mEffect )
360 {
361 return;
362 }
363
364 mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
365 mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
366 emit changed();
367}
368
369void QgsShadowEffectWidget::opacityChanged( double value )
370{
371 if ( !mEffect )
372 return;
373
374 mEffect->setOpacity( value );
375 emit changed();
376}
377
378void QgsShadowEffectWidget::mShadowColorBtn_colorChanged( const QColor &color )
379{
380 if ( !mEffect )
381 return;
382
383 mEffect->setColor( color );
384 emit changed();
385}
386
387void QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged( double value )
388{
389 if ( !mEffect )
390 return;
391
392 mEffect->setBlurLevel( value );
393 emit changed();
394}
395
396void QgsShadowEffectWidget::mBlurUnitWidget_changed()
397{
398 if ( !mEffect )
399 {
400 return;
401 }
402
403 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
404 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
405 emit changed();
406}
407
408void QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
409{
410 Q_UNUSED( index )
411
412 if ( !mEffect )
413 return;
414
415 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
416 emit changed();
417}
418
419void QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged( int index )
420{
421 Q_UNUSED( index )
422
423 if ( !mEffect )
424 return;
425
426 mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
427 emit changed();
428}
429
430
431//
432// glow
433//
434
436 : QgsPaintEffectWidget( parent )
437
438{
439 setupUi( this );
440 connect( mSpreadSpnBx, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mSpreadSpnBx_valueChanged );
441 connect( mSpreadUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mSpreadUnitWidget_changed );
442 connect( mColorBtn, &QgsColorButton::colorChanged, this, &QgsGlowWidget::mColorBtn_colorChanged );
443 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mBlendCmbBx_currentIndexChanged );
444 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mDrawModeComboBox_currentIndexChanged );
445 connect( mBlurRadiusSpnBx, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mBlurRadiusSpnBx_valueChanged );
446 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mBlurUnitWidget_changed );
447
448 mColorBtn->setAllowOpacity( false );
449 mColorBtn->setColorDialogTitle( tr( "Select Glow Color" ) );
450 mColorBtn->setContext( QStringLiteral( "symbology" ) );
451
454
455 btnColorRamp->setShowGradientOnly( true );
456
457 initGui();
458
459 connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsGlowWidget::applyColorRamp );
460 connect( radioSingleColor, &QAbstractButton::toggled, this, &QgsGlowWidget::colorModeChanged );
461 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsGlowWidget::opacityChanged );
462}
463
465{
466 if ( !effect || ( effect->type() != QLatin1String( "outerGlow" ) && effect->type() != QLatin1String( "innerGlow" ) ) )
467 return;
468
469 mEffect = static_cast<QgsGlowEffect *>( effect );
470 initGui();
471}
472
473void QgsGlowWidget::initGui()
474{
475 if ( !mEffect )
476 {
477 return;
478 }
479
480 blockSignals( true );
481
482 mSpreadSpnBx->setValue( mEffect->spread() );
483 mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
484 mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
485 mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
486 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
487 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
488 mOpacityWidget->setOpacity( mEffect->opacity() );
489 mColorBtn->setColor( mEffect->color() );
490 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
491
492 if ( mEffect->ramp() )
493 {
494 btnColorRamp->setColorRamp( mEffect->ramp() );
495 }
496
497 radioSingleColor->setChecked( mEffect->colorType() == QgsGlowEffect::SingleColor );
498 mColorBtn->setEnabled( mEffect->colorType() == QgsGlowEffect::SingleColor );
499 radioColorRamp->setChecked( mEffect->colorType() == QgsGlowEffect::ColorRamp );
500 btnColorRamp->setEnabled( mEffect->colorType() == QgsGlowEffect::ColorRamp );
501 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
502
503 blockSignals( false );
504}
505
506void QgsGlowWidget::blockSignals( const bool block )
507{
508 mSpreadSpnBx->blockSignals( block );
509 mSpreadUnitWidget->blockSignals( block );
510 mBlurRadiusSpnBx->blockSignals( block );
511 mOpacityWidget->blockSignals( block );
512 mColorBtn->blockSignals( block );
513 mBlendCmbBx->blockSignals( block );
514 btnColorRamp->blockSignals( block );
515 radioSingleColor->blockSignals( block );
516 radioColorRamp->blockSignals( block );
517 mDrawModeComboBox->blockSignals( block );
518}
519
520void QgsGlowWidget::colorModeChanged()
521{
522 if ( !mEffect )
523 {
524 return;
525 }
526
527 if ( radioSingleColor->isChecked() )
528 {
530 }
531 else
532 {
534 mEffect->setRamp( btnColorRamp->colorRamp() );
535 }
536 emit changed();
537}
538
539void QgsGlowWidget::mSpreadSpnBx_valueChanged( double value )
540{
541 if ( !mEffect )
542 return;
543
544 mEffect->setSpread( value );
545 emit changed();
546}
547
548void QgsGlowWidget::mSpreadUnitWidget_changed()
549{
550 if ( !mEffect )
551 {
552 return;
553 }
554
555 mEffect->setSpreadUnit( mSpreadUnitWidget->unit() );
556 mEffect->setSpreadMapUnitScale( mSpreadUnitWidget->getMapUnitScale() );
557 emit changed();
558}
559
560void QgsGlowWidget::opacityChanged( double value )
561{
562 if ( !mEffect )
563 return;
564
565 mEffect->setOpacity( value );
566 emit changed();
567}
568
569void QgsGlowWidget::mColorBtn_colorChanged( const QColor &color )
570{
571 if ( !mEffect )
572 return;
573
574 mEffect->setColor( color );
575 emit changed();
576}
577
578void QgsGlowWidget::mBlurRadiusSpnBx_valueChanged( double value )
579{
580 if ( !mEffect )
581 return;
582
583 mEffect->setBlurLevel( value );
584 emit changed();
585}
586
587void QgsGlowWidget::mBlurUnitWidget_changed()
588{
589 if ( !mEffect )
590 {
591 return;
592 }
593
594 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
595 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
596 emit changed();
597}
598
599void QgsGlowWidget::mBlendCmbBx_currentIndexChanged( int index )
600{
601 Q_UNUSED( index )
602
603 if ( !mEffect )
604 return;
605
606 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
607 emit changed();
608}
609
610void QgsGlowWidget::mDrawModeComboBox_currentIndexChanged( int index )
611{
612 Q_UNUSED( index )
613
614 if ( !mEffect )
615 return;
616
617 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
618 emit changed();
619}
620
621void QgsGlowWidget::applyColorRamp()
622{
623 if ( !mEffect )
624 {
625 return;
626 }
627
628 QgsColorRamp *ramp = btnColorRamp->colorRamp();
629 if ( !ramp )
630 return;
631
632 mEffect->setRamp( ramp );
633 emit changed();
634}
635
636//
637// transform
638//
639
641 : QgsPaintEffectWidget( parent )
642
643{
644 setupUi( this );
645 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsTransformWidget::mDrawModeComboBox_currentIndexChanged );
646 connect( mSpinTranslateX, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateX_valueChanged );
647 connect( mSpinTranslateY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinTranslateY_valueChanged );
648 connect( mTranslateUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsTransformWidget::mTranslateUnitWidget_changed );
649 connect( mReflectXCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectXCheckBox_stateChanged );
650 connect( mReflectYCheckBox, &QCheckBox::stateChanged, this, &QgsTransformWidget::mReflectYCheckBox_stateChanged );
651 connect( mSpinShearX, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearX_valueChanged );
652 connect( mSpinShearY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinShearY_valueChanged );
653 connect( mSpinScaleX, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleX_valueChanged );
654 connect( mSpinScaleY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mSpinScaleY_valueChanged );
655 connect( mRotationSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTransformWidget::mRotationSpinBox_valueChanged );
656
658 mSpinTranslateX->setClearValue( 0 );
659 mSpinTranslateY->setClearValue( 0 );
660 mRotationSpinBox->setClearValue( 0 );
661 mSpinShearX->setClearValue( 0 );
662 mSpinShearY->setClearValue( 0 );
663 mSpinScaleX->setClearValue( 100.0 );
664 mSpinScaleY->setClearValue( 100.0 );
665
666 initGui();
667}
668
669
671{
672 if ( !effect || effect->type() != QLatin1String( "transform" ) )
673 return;
674
675 mEffect = static_cast<QgsTransformEffect *>( effect );
676 initGui();
677}
678
679void QgsTransformWidget::initGui()
680{
681 if ( !mEffect )
682 {
683 return;
684 }
685
686 blockSignals( true );
687
688 mReflectXCheckBox->setChecked( mEffect->reflectX() );
689 mReflectYCheckBox->setChecked( mEffect->reflectY() );
690 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
691 mSpinTranslateX->setValue( mEffect->translateX() );
692 mSpinTranslateY->setValue( mEffect->translateY() );
693 mTranslateUnitWidget->setUnit( mEffect->translateUnit() );
694 mTranslateUnitWidget->setMapUnitScale( mEffect->translateMapUnitScale() );
695 mSpinShearX->setValue( mEffect->shearX() );
696 mSpinShearY->setValue( mEffect->shearY() );
697 mSpinScaleX->setValue( mEffect->scaleX() * 100.0 );
698 mSpinScaleY->setValue( mEffect->scaleY() * 100.0 );
699 mRotationSpinBox->setValue( mEffect->rotation() );
700
701 blockSignals( false );
702}
703
704void QgsTransformWidget::blockSignals( const bool block )
705{
706 mDrawModeComboBox->blockSignals( block );
707 mTranslateUnitWidget->blockSignals( block );
708 mSpinTranslateX->blockSignals( block );
709 mSpinTranslateY->blockSignals( block );
710 mReflectXCheckBox->blockSignals( block );
711 mReflectYCheckBox->blockSignals( block );
712 mSpinShearX->blockSignals( block );
713 mSpinShearY->blockSignals( block );
714 mSpinScaleX->blockSignals( block );
715 mSpinScaleY->blockSignals( block );
716 mRotationSpinBox->blockSignals( block );
717}
718
719
720void QgsTransformWidget::mDrawModeComboBox_currentIndexChanged( int index )
721{
722 Q_UNUSED( index )
723
724 if ( !mEffect )
725 return;
726
727 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
728 emit changed();
729}
730
731void QgsTransformWidget::mSpinTranslateX_valueChanged( double value )
732{
733 if ( !mEffect )
734 return;
735
736 mEffect->setTranslateX( value );
737 emit changed();
738}
739
740void QgsTransformWidget::mSpinTranslateY_valueChanged( double value )
741{
742 if ( !mEffect )
743 return;
744
745 mEffect->setTranslateY( value );
746 emit changed();
747}
748
749void QgsTransformWidget::mTranslateUnitWidget_changed()
750{
751 if ( !mEffect )
752 {
753 return;
754 }
755
756 mEffect->setTranslateUnit( mTranslateUnitWidget->unit() );
757 mEffect->setTranslateMapUnitScale( mTranslateUnitWidget->getMapUnitScale() );
758 emit changed();
759}
760
761void QgsTransformWidget::mReflectXCheckBox_stateChanged( int state )
762{
763 if ( !mEffect )
764 return;
765
766 mEffect->setReflectX( state == Qt::Checked );
767 emit changed();
768}
769
770void QgsTransformWidget::mReflectYCheckBox_stateChanged( int state )
771{
772 if ( !mEffect )
773 return;
774
775 mEffect->setReflectY( state == Qt::Checked );
776 emit changed();
777}
778
779void QgsTransformWidget::mSpinShearX_valueChanged( double value )
780{
781 if ( !mEffect )
782 return;
783
784 mEffect->setShearX( value );
785 emit changed();
786}
787
788void QgsTransformWidget::mSpinShearY_valueChanged( double value )
789{
790 if ( !mEffect )
791 return;
792
793 mEffect->setShearY( value );
794 emit changed();
795}
796
797void QgsTransformWidget::mSpinScaleX_valueChanged( double value )
798{
799 if ( !mEffect )
800 return;
801
802 mEffect->setScaleX( value / 100.0 );
803 emit changed();
804}
805
806void QgsTransformWidget::mSpinScaleY_valueChanged( double value )
807{
808 if ( !mEffect )
809 return;
810
811 mEffect->setScaleY( value / 100.0 );
812 emit changed();
813}
814
815void QgsTransformWidget::mRotationSpinBox_valueChanged( double value )
816{
817 if ( !mEffect )
818 return;
819
820 mEffect->setRotation( value );
821 emit changed();
822}
823
824
825//
826// color effect
827//
828
830 : QgsPaintEffectWidget( parent )
831
832{
833 setupUi( this );
834 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged );
835 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged );
836 connect( mBrightnessSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mBrightnessSpinBox_valueChanged );
837 connect( mContrastSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mContrastSpinBox_valueChanged );
838 connect( mSaturationSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mSaturationSpinBox_valueChanged );
839 connect( mColorizeStrengthSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged );
840 connect( mColorizeCheck, &QCheckBox::stateChanged, this, &QgsColorEffectWidget::mColorizeCheck_stateChanged );
841 connect( mColorizeColorButton, &QgsColorButton::colorChanged, this, &QgsColorEffectWidget::mColorizeColorButton_colorChanged );
842 connect( mGrayscaleCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged );
843
844 mBrightnessSpinBox->setClearValue( 0 );
845 mContrastSpinBox->setClearValue( 0 );
846 mSaturationSpinBox->setClearValue( 0 );
847 mColorizeStrengthSpinBox->setClearValue( 100 );
848 mColorizeColorButton->setAllowOpacity( false );
849
850 mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
851 mGrayscaleCombo->addItem( tr( "By Lightness" ), QgsImageOperation::GrayscaleLightness );
852 mGrayscaleCombo->addItem( tr( "By Luminosity" ), QgsImageOperation::GrayscaleLuminosity );
853 mGrayscaleCombo->addItem( tr( "By Average" ), QgsImageOperation::GrayscaleAverage );
854
855 initGui();
856
857 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsColorEffectWidget::opacityChanged );
858}
859
861{
862 if ( !effect || effect->type() != QLatin1String( "color" ) )
863 return;
864
865 mEffect = static_cast<QgsColorEffect *>( effect );
866 initGui();
867}
868
869void QgsColorEffectWidget::initGui()
870{
871 if ( !mEffect )
872 {
873 return;
874 }
875
876 blockSignals( true );
877
878 mSliderBrightness->setValue( mEffect->brightness() );
879 mSliderContrast->setValue( mEffect->contrast() );
880 mSliderSaturation->setValue( ( mEffect->saturation() - 1.0 ) * 100.0 );
881 mColorizeCheck->setChecked( mEffect->colorizeOn() );
882 mSliderColorizeStrength->setValue( mEffect->colorizeStrength() );
883 mColorizeColorButton->setColor( mEffect->colorizeColor() );
884 const int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
885 mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
886 mOpacityWidget->setOpacity( mEffect->opacity() );
887 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
888 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
889 enableColorizeControls( mEffect->colorizeOn() );
890
891 blockSignals( false );
892}
893
894void QgsColorEffectWidget::blockSignals( const bool block )
895{
896 mBrightnessSpinBox->blockSignals( block );
897 mContrastSpinBox->blockSignals( block );
898 mSaturationSpinBox->blockSignals( block );
899 mColorizeStrengthSpinBox->blockSignals( block );
900 mColorizeCheck->blockSignals( block );
901 mColorizeColorButton->blockSignals( block );
902 mGrayscaleCombo->blockSignals( block );
903 mOpacityWidget->blockSignals( block );
904 mBlendCmbBx->blockSignals( block );
905 mDrawModeComboBox->blockSignals( block );
906}
907
908void QgsColorEffectWidget::enableColorizeControls( const bool enable )
909{
910 mSliderColorizeStrength->setEnabled( enable );
911 mColorizeStrengthSpinBox->setEnabled( enable );
912 mColorizeColorButton->setEnabled( enable );
913}
914
915void QgsColorEffectWidget::opacityChanged( double value )
916{
917 if ( !mEffect )
918 return;
919
920 mEffect->setOpacity( value );
921 emit changed();
922}
923
924void QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged( int index )
925{
926 Q_UNUSED( index )
927
928 if ( !mEffect )
929 return;
930
931 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
932 emit changed();
933}
934
935void QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
936{
937 Q_UNUSED( index )
938
939 if ( !mEffect )
940 return;
941
942 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
943 emit changed();
944}
945
946void QgsColorEffectWidget::mBrightnessSpinBox_valueChanged( int value )
947{
948 if ( !mEffect )
949 return;
950
951 mEffect->setBrightness( value );
952 emit changed();
953}
954
955void QgsColorEffectWidget::mContrastSpinBox_valueChanged( int value )
956{
957 if ( !mEffect )
958 return;
959
960 mEffect->setContrast( value );
961 emit changed();
962}
963
964void QgsColorEffectWidget::mSaturationSpinBox_valueChanged( int value )
965{
966 if ( !mEffect )
967 return;
968
969 mEffect->setSaturation( value / 100.0 + 1 );
970 emit changed();
971}
972
973void QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged( int value )
974{
975 if ( !mEffect )
976 return;
977
978 mEffect->setColorizeStrength( value );
979 emit changed();
980}
981
982void QgsColorEffectWidget::mColorizeCheck_stateChanged( int state )
983{
984 if ( !mEffect )
985 return;
986
987 mEffect->setColorizeOn( state == Qt::Checked );
988 enableColorizeControls( state == Qt::Checked );
989 emit changed();
990}
991
992void QgsColorEffectWidget::mColorizeColorButton_colorChanged( const QColor &color )
993{
994 if ( !mEffect )
995 return;
996
997 mEffect->setColorizeColor( color );
998 emit changed();
999}
1000
1001void QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged( int index )
1002{
1003 Q_UNUSED( index )
1004
1005 if ( !mEffect )
1006 return;
1007
1008 mEffect->setGrayscaleMode( ( QgsImageOperation::GrayscaleMode ) mGrayscaleCombo->currentData().toInt() );
1009 emit changed();
1010}
@ 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.
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.