QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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  updateModes();
31 }
32 
33 QStringList QgsBlendModeComboBox::blendModesList() const
34 {
35  return QStringList() << tr( "Normal" )
36  << QStringLiteral( "-" )
37  << tr( "Lighten" )
38  << tr( "Screen" )
39  << tr( "Dodge" )
40  << tr( "Addition" )
41  << QStringLiteral( "-" )
42  << tr( "Darken" )
43  << tr( "Multiply" )
44  << tr( "Burn" )
45  << QStringLiteral( "-" )
46  << tr( "Overlay" )
47  << tr( "Soft light" )
48  << tr( "Hard light" )
49  << QStringLiteral( "-" )
50  << tr( "Difference" )
51  << tr( "Subtract" );
52 }
53 
55 {
56  blockSignals( true );
57  clear();
58 
59  QStringList myBlendModesList = blendModesList();
60  QStringList::const_iterator blendModeIt = myBlendModesList.constBegin();
61 
62  mBlendModeToListIndex.resize( myBlendModesList.count() );
63  mListIndexToBlendMode.resize( myBlendModesList.count() );
64 
65  // Loop through blend modes
66  int index = 0;
67  int blendModeIndex = 0;
68  for ( ; blendModeIt != myBlendModesList.constEnd(); ++blendModeIt )
69  {
70  if ( *blendModeIt == QLatin1String( "-" ) )
71  {
72  // Add separator
73  insertSeparator( index );
74  }
75  else
76  {
77  // Not a separator, so store indexes for translation
78  // between blend modes and combo box item index
79  addItem( *blendModeIt );
80  mListIndexToBlendMode[ index ] = blendModeIndex;
81  mBlendModeToListIndex[ blendModeIndex ] = index;
82  blendModeIndex++;
83  }
84  index++;
85  }
86 
87  blockSignals( false );
88 }
89 
90 QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
91 {
92  return QgsPainting::getCompositionMode( ( QgsPainting::BlendMode ) mListIndexToBlendMode[ currentIndex()] );
93 }
94 
95 void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
96 {
97  setCurrentIndex( mBlendModeToListIndex[( int ) QgsPainting::getBlendModeEnum( blendMode )] );
98 }
99 
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
void updateModes()
Populates the blend mode combo box, and sets up mapping for blend modes to combo box indexes...
void setBlendMode(QPainter::CompositionMode blendMode)
Function to set the selected blend mode from QPainter::CompositionMode.
QPainter::CompositionMode blendMode()
Function to read the selected blend mode as QPainter::CompositionMode.
QgsBlendModeComboBox(QWidget *parent=nullptr)
Constructor for QgsBlendModeComboBox.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
Definition: qgspainting.h:36