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