QGIS API Documentation  2.99.0-Master (08ee180)
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 
34 {
35 }
36 
37 /* Returns a QStringList of the translated blend modes
38 * "-" is used to indicate the position of a separator in the list
39 * This list is designed to emulate GIMP's layer modes, where
40 * blending modes are grouped by their effect (lightening, darkening, etc)
41 */
42 QStringList QgsBlendModeComboBox::blendModesList() const
43 {
44  return QStringList() << tr( "Normal" )
45  << QStringLiteral( "-" )
46  << tr( "Lighten" )
47  << tr( "Screen" )
48  << tr( "Dodge" )
49  << tr( "Addition" )
50  << QStringLiteral( "-" )
51  << tr( "Darken" )
52  << tr( "Multiply" )
53  << tr( "Burn" )
54  << QStringLiteral( "-" )
55  << tr( "Overlay" )
56  << tr( "Soft light" )
57  << tr( "Hard light" )
58  << QStringLiteral( "-" )
59  << tr( "Difference" )
60  << tr( "Subtract" );
61 }
62 
63 /* Populates the blend mode combo box, and sets up mapping for
64 * blend modes to combo box indexes
65 */
67 {
68  blockSignals( true );
69  clear();
70 
71  QStringList myBlendModesList = blendModesList();
72  QStringList::const_iterator blendModeIt = myBlendModesList.constBegin();
73 
74  mBlendModeToListIndex.resize( myBlendModesList.count() );
75  mListIndexToBlendMode.resize( myBlendModesList.count() );
76 
77  // Loop through blend modes
78  int index = 0;
79  int blendModeIndex = 0;
80  for ( ; blendModeIt != myBlendModesList.constEnd(); ++blendModeIt )
81  {
82  if ( *blendModeIt == QLatin1String( "-" ) )
83  {
84  // Add separator
85  insertSeparator( index );
86  }
87  else
88  {
89  // Not a separator, so store indexes for translation
90  // between blend modes and combo box item index
91  addItem( *blendModeIt );
92  mListIndexToBlendMode[ index ] = blendModeIndex;
93  mBlendModeToListIndex[ blendModeIndex ] = index;
94  blendModeIndex++;
95  }
96  index++;
97  }
98 
99  blockSignals( false );
100 }
101 
103 QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
104 {
105  return QgsPainting::getCompositionMode(( QgsPainting::BlendMode ) mListIndexToBlendMode[ currentIndex()] );
106 }
107 
109 void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
110 {
111  setCurrentIndex( mBlendModeToListIndex[( int ) QgsPainting::getBlendModeEnum( blendMode )] );
112 }
113 
static unsigned index
static BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:66
static QPainter::CompositionMode getCompositionMode(BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:6
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)
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
Definition: qgspainting.h:19