QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 : nyall.dawson@gmail.com
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 
22 #include <QAbstractItemView>
23 #include <QLocale>
24 #include <QSettings>
25 #include <QLineEdit>
26 
27 QgsBlendModeComboBox::QgsBlendModeComboBox( QWidget* parent ) : QComboBox( parent )
28 {
29  updateModes();
30 }
31 
33 {
34 }
35 
36 /* Returns a QStringList of the translated blend modes
37 * "-" is used to indicate the position of a separator in the list
38 * This list is designed to emulate GIMP's layer modes, where
39 * blending modes are grouped by their effect (lightening, darkening, etc)
40 */
42 {
43  return QStringList() << tr( "Normal" )
44  << "-"
45  << tr( "Lighten" )
46  << tr( "Screen" )
47  << tr( "Dodge" )
48  << tr( "Addition" )
49  << "-"
50  << tr( "Darken" )
51  << tr( "Multiply" )
52  << tr( "Burn" )
53  << "-"
54  << tr( "Overlay" )
55  << tr( "Soft light" )
56  << tr( "Hard light" )
57  << "-"
58  << tr( "Difference" )
59  << tr( "Subtract" );
60 }
61 
62 /* Populates the blend mode combo box, and sets up mapping for
63 * blend modes to combo box indexes
64 */
66 {
67  blockSignals( true );
68  clear();
69 
70  QStringList myBlendModesList = blendModesList();
71  QStringList::const_iterator blendModeIt = myBlendModesList.constBegin();
72 
73  mBlendModeToListIndex.resize( myBlendModesList.count() );
74  mListIndexToBlendMode.resize( myBlendModesList.count() );
75 
76  // Loop through blend modes
77  int index = 0;
78  int blendModeIndex = 0;
79  for ( ; blendModeIt != myBlendModesList.constEnd(); ++blendModeIt )
80  {
81  if ( *blendModeIt == "-" )
82  {
83  // Add separator
84  insertSeparator( index );
85  }
86  else
87  {
88  // Not a separator, so store indexes for translation
89  // between blend modes and combo box item index
90  addItem( *blendModeIt );
91  mListIndexToBlendMode[ index ] = blendModeIndex;
92  mBlendModeToListIndex[ blendModeIndex ] = index;
93  blendModeIndex++;
94  }
95  index++;
96  }
97 
98  blockSignals( false );
99 }
100 
102 QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
103 {
105 }
106 
108 void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
109 {
110  setCurrentIndex( mBlendModeToListIndex[( int ) QgsMapRenderer::getBlendModeEnum( blendMode )] );
111 }
112 
static unsigned index
std::vector< int > mBlendModeToListIndex
Used to map blend modes across to their corresponding.
QgsBlendModeComboBox(QWidget *parent=0)
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
void setBlendMode(QPainter::CompositionMode blendMode)
Function to set the selected blend mode from QPainter::CompositionMode.
QStringList blendModesList() const
Returns a list of grouped blend modes (with seperators)
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
QPainter::CompositionMode blendMode()
Function to read the selected blend mode as QPainter::CompositionMode.
std::vector< int > mListIndexToBlendMode
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode Added in 1.9.
#define tr(sourceText)