QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsblendmodecombobox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsblendmodecombobox.cpp
3 ------------------------
4 begin : March 21, 2013
5 copyright : (C) 2013 by Nyall Dawson
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgis.h"
19#include "qgslogger.h"
21#include "qgspainting.h"
22
23#include <QAbstractItemView>
24#include <QLocale>
25#include <QSettings>
26#include <QLineEdit>
27
29 : QComboBox( parent )
30{
31 setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
33}
34
36{
37 blockSignals( true );
38 clear();
39
40 // This list is designed to emulate GIMP's layer modes, where
41 // blending modes are grouped by their effect (lightening, darkening, etc)
42
43 addItem( tr( "Normal" ), static_cast< int >( QgsPainting::BlendMode::BlendNormal ) );
44 insertSeparator( count() );
45 addItem( tr( "Lighten" ), static_cast< int >( QgsPainting::BlendMode::BlendLighten ) );
46 addItem( tr( "Screen" ), static_cast< int >( QgsPainting::BlendMode::BlendScreen ) );
47 addItem( tr( "Dodge" ), static_cast< int >( QgsPainting::BlendMode::BlendDodge ) );
48 addItem( tr( "Addition" ), static_cast< int >( QgsPainting::BlendMode::BlendAddition ) );
49 insertSeparator( count() );
50 addItem( tr( "Darken" ), static_cast< int >( QgsPainting::BlendMode::BlendDarken ) );
51 addItem( tr( "Multiply" ), static_cast< int >( QgsPainting::BlendMode::BlendMultiply ) );
52 addItem( tr( "Burn" ), static_cast< int >( QgsPainting::BlendMode::BlendBurn ) );
53 insertSeparator( count() );
54 addItem( tr( "Overlay" ), static_cast< int >( QgsPainting::BlendMode::BlendOverlay ) );
55 addItem( tr( "Soft Light" ), static_cast< int >( QgsPainting::BlendMode::BlendSoftLight ) );
56 addItem( tr( "Hard Light" ), static_cast< int >( QgsPainting::BlendMode::BlendHardLight ) );
57 insertSeparator( count() );
58 addItem( tr( "Difference" ), static_cast< int >( QgsPainting::BlendMode::BlendDifference ) );
59 addItem( tr( "Subtract" ), static_cast< int >( QgsPainting::BlendMode::BlendSubtract ) );
60
61 if ( mShowClipModes )
62 {
63 insertSeparator( count() );
64 addItem( tr( "Masked By Below" ), static_cast< int >( QgsPainting::BlendMode::BlendSourceIn ) );
65 addItem( tr( "Mask Below" ), static_cast< int >( QgsPainting::BlendMode::BlendDestinationIn ) );
66 addItem( tr( "Inverse Masked By Below" ), static_cast< int >( QgsPainting::BlendMode::BlendSourceOut ) );
67 addItem( tr( "Inverse Mask Below" ), static_cast< int >( QgsPainting::BlendMode::BlendDestinationOut ) );
68 addItem( tr( "Paint Inside Below" ), static_cast< int >( QgsPainting::BlendMode::BlendSourceAtop ) );
69 addItem( tr( "Paint Below Inside" ), static_cast< int >( QgsPainting::BlendMode::BlendDestinationAtop ) );
70 }
71
72 blockSignals( false );
73}
74
75QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
76{
77 return QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( currentData().toInt() ) );
78}
79
80void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
81{
82 setCurrentIndex( findData( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode ) ) ) );
83}
84
86{
87 mShowClipModes = show;
88 const QPainter::CompositionMode mode = blendMode();
90
91 setBlendMode( mode );
92}
93
95{
96 return mShowClipModes;
97}
98
void setBlendMode(QPainter::CompositionMode blendMode)
Sets the selected blend mode.
void setShowClippingModes(bool show)
Sets whether composition modes which cause clipping are shown in the combo box.
QgsBlendModeComboBox(QWidget *parent=nullptr)
Constructor for QgsBlendModeComboBox.
void updateModes()
Populates the blend mode combo box, and sets up mapping for blend modes to combo box indexes.
bool showClippingModes() const
Returns true if composition modes which cause clipping are shown in the combo box.
QPainter::CompositionMode blendMode()
Returns the selected blend mode.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:37