QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
131
132 initGui();
133 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsBlurWidget::opacityChanged );
134}
135
136
138{
139 if ( !effect || effect->type() != QLatin1String( "blur" ) )
140 return;
141
142 mEffect = static_cast<QgsBlurEffect *>( effect );
143 initGui();
144}
145
146void QgsBlurWidget::initGui()
147{
148 if ( !mEffect )
149 {
150 return;
151 }
152
153 blockSignals( true );
154
155 mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
156 mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
157 mOpacityWidget->setOpacity( mEffect->opacity() );
158 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
159 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
160
161 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
162 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
163
164 blockSignals( false );
165}
166
167void QgsBlurWidget::blockSignals( const bool block )
168{
169 mBlurTypeCombo->blockSignals( block );
170 mBlurStrengthSpnBx->blockSignals( block );
171 mOpacityWidget->blockSignals( block );
172 mBlendCmbBx->blockSignals( block );
173 mDrawModeComboBox->blockSignals( block );
174}
175
176void QgsBlurWidget::mBlurTypeCombo_currentIndexChanged( int index )
177{
178 if ( !mEffect )
179 return;
180
181 const QgsBlurEffect::BlurMethod method = ( QgsBlurEffect::BlurMethod ) mBlurTypeCombo->itemData( index ).toInt();
182 mEffect->setBlurMethod( method );
183
184 //also update max radius
185 switch ( method )
186 {
188 mBlurStrengthSpnBx->setMaximum( 16 );
189 break;
191 mBlurStrengthSpnBx->setMaximum( 200 );
192 break;
193 }
194
195 emit changed();
196}
197
198void QgsBlurWidget::mBlurStrengthSpnBx_valueChanged( double value )
199{
200 if ( !mEffect )
201 return;
202
203 mEffect->setBlurLevel( value );
204 emit changed();
205}
206
207void QgsBlurWidget::mBlurUnitWidget_changed()
208{
209 if ( !mEffect )
210 {
211 return;
212 }
213
214 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
215 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
216 emit changed();
217}
218
219void QgsBlurWidget::opacityChanged( double value )
220{
221 if ( !mEffect )
222 return;
223
224 mEffect->setOpacity( value );
225 emit changed();
226}
227
228void QgsBlurWidget::mDrawModeComboBox_currentIndexChanged( int index )
229{
230 Q_UNUSED( index )
231
232 if ( !mEffect )
233 return;
234
235 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
236 emit changed();
237}
238
239void QgsBlurWidget::mBlendCmbBx_currentIndexChanged( int index )
240{
241 Q_UNUSED( index )
242
243 if ( !mEffect )
244 return;
245
246 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
247 emit changed();
248}
249
250
251//
252// Drop Shadow
253//
254
256 : QgsPaintEffectWidget( parent )
257
258{
259 setupUi( this );
260 connect( mShadowOffsetAngleSpnBx, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged );
261 connect( mShadowOffsetAngleDial, &QDial::valueChanged, this, &QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged );
262 connect( mShadowOffsetSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged );
263 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mOffsetUnitWidget_changed );
264 connect( mShadowColorBtn, &QgsColorButton::colorChanged, this, &QgsShadowEffectWidget::mShadowColorBtn_colorChanged );
265 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged );
266 connect( mShadowBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged );
267 connect( mShadowRadiuSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged );
268 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShadowEffectWidget::mBlurUnitWidget_changed );
269
270 mShadowColorBtn->setAllowOpacity( false );
271 mShadowColorBtn->setColorDialogTitle( tr( "Select Shadow Color" ) );
272 mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
273 mShadowOffsetAngleSpnBx->setClearValue( 0 );
274
279
280 initGui();
281
282 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsShadowEffectWidget::opacityChanged );
283}
284
286{
287 if ( !effect || ( effect->type() != QLatin1String( "dropShadow" ) && effect->type() != QLatin1String( "innerShadow" ) ) )
288 return;
289
290 mEffect = static_cast<QgsShadowEffect *>( effect );
291 initGui();
292}
293
294void QgsShadowEffectWidget::initGui()
295{
296 if ( !mEffect )
297 {
298 return;
299 }
300
301 blockSignals( true );
302
303 mShadowOffsetAngleSpnBx->setValue( mEffect->offsetAngle() );
304 mShadowOffsetAngleDial->setValue( mEffect->offsetAngle() );
305 mShadowOffsetSpnBx->setValue( mEffect->offsetDistance() );
306 mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
307 mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
308 mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
309 mBlurUnitWidget->setUnit( mEffect->blurUnit() );
310 mBlurUnitWidget->setMapUnitScale( mEffect->blurMapUnitScale() );
311 mOpacityWidget->setOpacity( mEffect->opacity() );
312 mShadowColorBtn->setColor( mEffect->color() );
313 mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
314 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
315
316 blockSignals( false );
317}
318
319void QgsShadowEffectWidget::blockSignals( const bool block )
320{
321 mShadowOffsetAngleSpnBx->blockSignals( block );
322 mShadowOffsetAngleDial->blockSignals( block );
323 mShadowOffsetSpnBx->blockSignals( block );
324 mOffsetUnitWidget->blockSignals( block );
325 mShadowRadiuSpnBx->blockSignals( block );
326 mBlurUnitWidget->blockSignals( block );
327 mOpacityWidget->blockSignals( block );
328 mShadowColorBtn->blockSignals( block );
329 mShadowBlendCmbBx->blockSignals( block );
330 mDrawModeComboBox->blockSignals( block );
331}
332
333void QgsShadowEffectWidget::mShadowOffsetAngleSpnBx_valueChanged( int value )
334{
335 mShadowOffsetAngleDial->blockSignals( true );
336 mShadowOffsetAngleDial->setValue( value );
337 mShadowOffsetAngleDial->blockSignals( false );
338
339 if ( !mEffect )
340 return;
341
342 mEffect->setOffsetAngle( value );
343 emit changed();
344}
345
346void QgsShadowEffectWidget::mShadowOffsetAngleDial_valueChanged( int value )
347{
348 mShadowOffsetAngleSpnBx->setValue( value );
349}
350
351void QgsShadowEffectWidget::mShadowOffsetSpnBx_valueChanged( double value )
352{
353 if ( !mEffect )
354 return;
355
356 mEffect->setOffsetDistance( value );
357 emit changed();
358}
359
360void QgsShadowEffectWidget::mOffsetUnitWidget_changed()
361{
362 if ( !mEffect )
363 {
364 return;
365 }
366
367 mEffect->setOffsetUnit( mOffsetUnitWidget->unit() );
368 mEffect->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
369 emit changed();
370}
371
372void QgsShadowEffectWidget::opacityChanged( double value )
373{
374 if ( !mEffect )
375 return;
376
377 mEffect->setOpacity( value );
378 emit changed();
379}
380
381void QgsShadowEffectWidget::mShadowColorBtn_colorChanged( const QColor &color )
382{
383 if ( !mEffect )
384 return;
385
386 mEffect->setColor( color );
387 emit changed();
388}
389
390void QgsShadowEffectWidget::mShadowRadiuSpnBx_valueChanged( double value )
391{
392 if ( !mEffect )
393 return;
394
395 mEffect->setBlurLevel( value );
396 emit changed();
397}
398
399void QgsShadowEffectWidget::mBlurUnitWidget_changed()
400{
401 if ( !mEffect )
402 {
403 return;
404 }
405
406 mEffect->setBlurUnit( mBlurUnitWidget->unit() );
407 mEffect->setBlurMapUnitScale( mBlurUnitWidget->getMapUnitScale() );
408 emit changed();
409}
410
411void QgsShadowEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
412{
413 Q_UNUSED( index )
414
415 if ( !mEffect )
416 return;
417
418 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
419 emit changed();
420}
421
422void QgsShadowEffectWidget::mShadowBlendCmbBx_currentIndexChanged( int index )
423{
424 Q_UNUSED( index )
425
426 if ( !mEffect )
427 return;
428
429 mEffect->setBlendMode( mShadowBlendCmbBx->blendMode() );
430 emit changed();
431}
432
433
434
435//
436// glow
437//
438
440 : QgsPaintEffectWidget( parent )
441
442{
443 setupUi( this );
444 connect( mSpreadSpnBx, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mSpreadSpnBx_valueChanged );
445 connect( mSpreadUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mSpreadUnitWidget_changed );
446 connect( mColorBtn, &QgsColorButton::colorChanged, this, &QgsGlowWidget::mColorBtn_colorChanged );
447 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mBlendCmbBx_currentIndexChanged );
448 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGlowWidget::mDrawModeComboBox_currentIndexChanged );
449 connect( mBlurRadiusSpnBx, static_cast< void ( QDoubleSpinBox::* )( double ) >( &QDoubleSpinBox::valueChanged ), this, &QgsGlowWidget::mBlurRadiusSpnBx_valueChanged );
450 connect( mBlurUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGlowWidget::mBlurUnitWidget_changed );
451
452 mColorBtn->setAllowOpacity( false );
453 mColorBtn->setColorDialogTitle( tr( "Select Glow Color" ) );
454 mColorBtn->setContext( QStringLiteral( "symbology" ) );
455
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() != QLatin1String( "outerGlow" ) && effect->type() != QLatin1String( "innerGlow" ) ) )
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 {
536 }
537 else
538 {
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
665 mSpinTranslateX->setClearValue( 0 );
666 mSpinTranslateY->setClearValue( 0 );
667 mRotationSpinBox->setClearValue( 0 );
668 mSpinShearX->setClearValue( 0 );
669 mSpinShearY->setClearValue( 0 );
670 mSpinScaleX->setClearValue( 100.0 );
671 mSpinScaleY->setClearValue( 100.0 );
672
673 initGui();
674}
675
676
678{
679 if ( !effect || effect->type() != QLatin1String( "transform" ) )
680 return;
681
682 mEffect = static_cast<QgsTransformEffect *>( effect );
683 initGui();
684}
685
686void QgsTransformWidget::initGui()
687{
688 if ( !mEffect )
689 {
690 return;
691 }
692
693 blockSignals( true );
694
695 mReflectXCheckBox->setChecked( mEffect->reflectX() );
696 mReflectYCheckBox->setChecked( mEffect->reflectY() );
697 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
698 mSpinTranslateX->setValue( mEffect->translateX() );
699 mSpinTranslateY->setValue( mEffect->translateY() );
700 mTranslateUnitWidget->setUnit( mEffect->translateUnit() );
701 mTranslateUnitWidget->setMapUnitScale( mEffect->translateMapUnitScale() );
702 mSpinShearX->setValue( mEffect->shearX() );
703 mSpinShearY->setValue( mEffect->shearY() );
704 mSpinScaleX->setValue( mEffect->scaleX() * 100.0 );
705 mSpinScaleY->setValue( mEffect->scaleY() * 100.0 );
706 mRotationSpinBox->setValue( mEffect->rotation() );
707
708 blockSignals( false );
709}
710
711void QgsTransformWidget::blockSignals( const bool block )
712{
713 mDrawModeComboBox->blockSignals( block );
714 mTranslateUnitWidget->blockSignals( block );
715 mSpinTranslateX->blockSignals( block );
716 mSpinTranslateY->blockSignals( block );
717 mReflectXCheckBox->blockSignals( block );
718 mReflectYCheckBox->blockSignals( block );
719 mSpinShearX->blockSignals( block );
720 mSpinShearY->blockSignals( block );
721 mSpinScaleX->blockSignals( block );
722 mSpinScaleY->blockSignals( block );
723 mRotationSpinBox->blockSignals( block );
724}
725
726
727void QgsTransformWidget::mDrawModeComboBox_currentIndexChanged( int index )
728{
729 Q_UNUSED( index )
730
731 if ( !mEffect )
732 return;
733
734 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
735 emit changed();
736}
737
738void QgsTransformWidget::mSpinTranslateX_valueChanged( double value )
739{
740 if ( !mEffect )
741 return;
742
743 mEffect->setTranslateX( value );
744 emit changed();
745}
746
747void QgsTransformWidget::mSpinTranslateY_valueChanged( double value )
748{
749 if ( !mEffect )
750 return;
751
752 mEffect->setTranslateY( value );
753 emit changed();
754}
755
756void QgsTransformWidget::mTranslateUnitWidget_changed()
757{
758 if ( !mEffect )
759 {
760 return;
761 }
762
763 mEffect->setTranslateUnit( mTranslateUnitWidget->unit() );
764 mEffect->setTranslateMapUnitScale( mTranslateUnitWidget->getMapUnitScale() );
765 emit changed();
766}
767
768void QgsTransformWidget::mReflectXCheckBox_stateChanged( int state )
769{
770 if ( !mEffect )
771 return;
772
773 mEffect->setReflectX( state == Qt::Checked );
774 emit changed();
775}
776
777void QgsTransformWidget::mReflectYCheckBox_stateChanged( int state )
778{
779 if ( !mEffect )
780 return;
781
782 mEffect->setReflectY( state == Qt::Checked );
783 emit changed();
784}
785
786void QgsTransformWidget::mSpinShearX_valueChanged( double value )
787{
788 if ( !mEffect )
789 return;
790
791 mEffect->setShearX( value );
792 emit changed();
793}
794
795void QgsTransformWidget::mSpinShearY_valueChanged( double value )
796{
797 if ( !mEffect )
798 return;
799
800 mEffect->setShearY( value );
801 emit changed();
802}
803
804void QgsTransformWidget::mSpinScaleX_valueChanged( double value )
805{
806 if ( !mEffect )
807 return;
808
809 mEffect->setScaleX( value / 100.0 );
810 emit changed();
811}
812
813void QgsTransformWidget::mSpinScaleY_valueChanged( double value )
814{
815 if ( !mEffect )
816 return;
817
818 mEffect->setScaleY( value / 100.0 );
819 emit changed();
820}
821
822void QgsTransformWidget::mRotationSpinBox_valueChanged( double value )
823{
824 if ( !mEffect )
825 return;
826
827 mEffect->setRotation( value );
828 emit changed();
829}
830
831
832//
833// color effect
834//
835
837 : QgsPaintEffectWidget( parent )
838
839{
840 setupUi( this );
841 connect( mBlendCmbBx, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged );
842 connect( mDrawModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged );
843 connect( mBrightnessSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mBrightnessSpinBox_valueChanged );
844 connect( mContrastSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mContrastSpinBox_valueChanged );
845 connect( mSaturationSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mSaturationSpinBox_valueChanged );
846 connect( mColorizeStrengthSpinBox, static_cast< void ( QSpinBox::* )( int ) >( &QSpinBox::valueChanged ), this, &QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged );
847 connect( mColorizeCheck, &QCheckBox::stateChanged, this, &QgsColorEffectWidget::mColorizeCheck_stateChanged );
848 connect( mColorizeColorButton, &QgsColorButton::colorChanged, this, &QgsColorEffectWidget::mColorizeColorButton_colorChanged );
849 connect( mGrayscaleCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged );
850
851 mBrightnessSpinBox->setClearValue( 0 );
852 mContrastSpinBox->setClearValue( 0 );
853 mSaturationSpinBox->setClearValue( 0 );
854 mColorizeStrengthSpinBox->setClearValue( 100 );
855 mColorizeColorButton->setAllowOpacity( false );
856
857 mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
858 mGrayscaleCombo->addItem( tr( "By Lightness" ), QgsImageOperation::GrayscaleLightness );
859 mGrayscaleCombo->addItem( tr( "By Luminosity" ), QgsImageOperation::GrayscaleLuminosity );
860 mGrayscaleCombo->addItem( tr( "By Average" ), QgsImageOperation::GrayscaleAverage );
861
862 initGui();
863
864 connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsColorEffectWidget::opacityChanged );
865}
866
868{
869 if ( !effect || effect->type() != QLatin1String( "color" ) )
870 return;
871
872 mEffect = static_cast<QgsColorEffect *>( effect );
873 initGui();
874}
875
876void QgsColorEffectWidget::initGui()
877{
878 if ( !mEffect )
879 {
880 return;
881 }
882
883 blockSignals( true );
884
885 mSliderBrightness->setValue( mEffect->brightness() );
886 mSliderContrast->setValue( mEffect->contrast() );
887 mSliderSaturation->setValue( ( mEffect->saturation() - 1.0 ) * 100.0 );
888 mColorizeCheck->setChecked( mEffect->colorizeOn() );
889 mSliderColorizeStrength->setValue( mEffect->colorizeStrength() );
890 mColorizeColorButton->setColor( mEffect->colorizeColor() );
891 const int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
892 mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
893 mOpacityWidget->setOpacity( mEffect->opacity() );
894 mBlendCmbBx->setBlendMode( mEffect->blendMode() );
895 mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
896 enableColorizeControls( mEffect->colorizeOn() );
897
898 blockSignals( false );
899}
900
901void QgsColorEffectWidget::blockSignals( const bool block )
902{
903 mBrightnessSpinBox->blockSignals( block );
904 mContrastSpinBox->blockSignals( block );
905 mSaturationSpinBox->blockSignals( block );
906 mColorizeStrengthSpinBox->blockSignals( block );
907 mColorizeCheck->blockSignals( block );
908 mColorizeColorButton->blockSignals( block );
909 mGrayscaleCombo->blockSignals( block );
910 mOpacityWidget->blockSignals( block );
911 mBlendCmbBx->blockSignals( block );
912 mDrawModeComboBox->blockSignals( block );
913}
914
915void QgsColorEffectWidget::enableColorizeControls( const bool enable )
916{
917 mSliderColorizeStrength->setEnabled( enable );
918 mColorizeStrengthSpinBox->setEnabled( enable );
919 mColorizeColorButton->setEnabled( enable );
920}
921
922void QgsColorEffectWidget::opacityChanged( double value )
923{
924 if ( !mEffect )
925 return;
926
927 mEffect->setOpacity( value );
928 emit changed();
929}
930
931void QgsColorEffectWidget::mBlendCmbBx_currentIndexChanged( int index )
932{
933 Q_UNUSED( index )
934
935 if ( !mEffect )
936 return;
937
938 mEffect->setBlendMode( mBlendCmbBx->blendMode() );
939 emit changed();
940}
941
942void QgsColorEffectWidget::mDrawModeComboBox_currentIndexChanged( int index )
943{
944 Q_UNUSED( index )
945
946 if ( !mEffect )
947 return;
948
949 mEffect->setDrawMode( mDrawModeComboBox->drawMode() );
950 emit changed();
951}
952
953void QgsColorEffectWidget::mBrightnessSpinBox_valueChanged( int value )
954{
955 if ( !mEffect )
956 return;
957
958 mEffect->setBrightness( value );
959 emit changed();
960}
961
962void QgsColorEffectWidget::mContrastSpinBox_valueChanged( int value )
963{
964 if ( !mEffect )
965 return;
966
967 mEffect->setContrast( value );
968 emit changed();
969}
970
971void QgsColorEffectWidget::mSaturationSpinBox_valueChanged( int value )
972{
973 if ( !mEffect )
974 return;
975
976 mEffect->setSaturation( value / 100.0 + 1 );
977 emit changed();
978}
979
980void QgsColorEffectWidget::mColorizeStrengthSpinBox_valueChanged( int value )
981{
982 if ( !mEffect )
983 return;
984
985 mEffect->setColorizeStrength( value );
986 emit changed();
987}
988
989void QgsColorEffectWidget::mColorizeCheck_stateChanged( int state )
990{
991 if ( !mEffect )
992 return;
993
994 mEffect->setColorizeOn( state == Qt::Checked );
995 enableColorizeControls( state == Qt::Checked );
996 emit changed();
997}
998
999void QgsColorEffectWidget::mColorizeColorButton_colorChanged( const QColor &color )
1000{
1001 if ( !mEffect )
1002 return;
1003
1004 mEffect->setColorizeColor( color );
1005 emit changed();
1006}
1007
1008void QgsColorEffectWidget::mGrayscaleCombo_currentIndexChanged( int index )
1009{
1010 Q_UNUSED( index )
1011
1012 if ( !mEffect )
1013 return;
1014
1015 mEffect->setGrayscaleMode( ( QgsImageOperation::GrayscaleMode ) mGrayscaleCombo->currentData().toInt() );
1016 emit changed();
1017}
@ 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.