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 #include "qgspainting.h"
22 
23 #include <QAbstractItemView>
24 #include <QLocale>
25 #include <QSettings>
26 #include <QLineEdit>
27 
QgsBlendModeComboBox(QWidget * parent)28 QgsBlendModeComboBox::QgsBlendModeComboBox( QWidget *parent ) : QComboBox( parent )
29 {
30   updateModes();
31 }
32 
blendModesList() const33 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 
updateModes()54 void QgsBlendModeComboBox::updateModes()
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 
blendMode()90 QPainter::CompositionMode QgsBlendModeComboBox::blendMode()
91 {
92   return QgsPainting::getCompositionMode( ( QgsPainting::BlendMode ) mListIndexToBlendMode[ currentIndex()] );
93 }
94 
setBlendMode(QPainter::CompositionMode blendMode)95 void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode )
96 {
97   setCurrentIndex( mBlendModeToListIndex[( int ) QgsPainting::getBlendModeEnum( blendMode )] );
98 }
99 
100