QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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
6  email : [email protected]
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"
20 #include "qgsblendmodecombobox.h"
21 #include "qgspainting.h"
22 
23 #include <QAbstractItemView>
24 #include <QLocale>
25 #include <QSettings>
26 #include <QLineEdit>
27 
28 QgsBlendModeComboBox::QgsBlendModeComboBox( QWidget *parent ) : QComboBox( parent )
29 {
30  setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
31  updateModes();
32 }
33 
34 QStringList QgsBlendModeComboBox::blendModesList() const
35 {
36  return QStringList() << tr( "Normal" )
37  << QStringLiteral( "-" )
38  << tr( "Lighten" )
39  << tr( "Screen" )
40  << tr( "Dodge" )
41  << tr( "Addition" )
42  << QStringLiteral( "-" )
43  << tr( "Darken" )
44  << tr( "Multiply" )
45  << tr( "Burn" )
46  << QStringLiteral( "-" )
47  << tr( "Overlay" )
48  << tr( "Soft light" )
49  << tr( "Hard light" )
50  << QStringLiteral( "-" )
51  << tr( "Difference" )
52  << tr( "Subtract" );
53 }
54 
56 {
57  blockSignals( true );
58  clear();
59 
60  const QStringList myBlendModesList = blendModesList();
61  QStringList::const_iterator blendModeIt = myBlendModesList.constBegin();
62 
63  mBlendModeToListIndex.resize( myBlendModesList.count() );
64  mListIndexToBlendMode.resize( myBlendModesList.count() );
65 
66  // Loop through blend modes
67  int index = 0;
68  int blendModeIndex = 0;
69  for ( ; blendModeIt != myBlendModesList.constEnd(); ++blendModeIt )
70  {
71  if ( *blendModeIt == QLatin1String( "-" ) )
72  {
73  // Add separator
74  insertSeparator( index );
75  }
76  else
77  {
78  // Not a separator, so store indexes for translation
79  // between blend modes and combo box item index
80  addItem( *blendModeIt );
81  mListIndexToBlendMode[ index ] = blendModeIndex;
82  mBlendModeToListIndex[ blendModeIndex ] = index;
83  blendModeIndex++;
84  }
85  index++;
86  }
87 
88  blockSignals( false );
89 }
90 
91 QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
92 {
93  return QgsPainting::getCompositionMode( ( QgsPainting::BlendMode ) mListIndexToBlendMode[ currentIndex()] );
94 }
95 
96 void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
97 {
98  setCurrentIndex( mBlendModeToListIndex[( int ) QgsPainting::getBlendModeEnum( blendMode )] );
99 }
100 
void setBlendMode(QPainter::CompositionMode blendMode)
Function to set the selected blend mode from QPainter::CompositionMode.
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.
QPainter::CompositionMode blendMode()
Function to read the selected blend mode as QPainter::CompositionMode.
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