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)28QgsBlendModeComboBox::QgsBlendModeComboBox( QWidget *parent ) : QComboBox( parent ) 29 { 30 setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 31 updateModes(); 32 } 33 blendModesList() const34QStringList 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 updateModes()55void QgsBlendModeComboBox::updateModes() 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 blendMode()91QPainter::CompositionMode QgsBlendModeComboBox::blendMode() 92 { 93 return QgsPainting::getCompositionMode( ( QgsPainting::BlendMode ) mListIndexToBlendMode[ currentIndex()] ); 94 } 95 setBlendMode(QPainter::CompositionMode blendMode)96void QgsBlendModeComboBox::setBlendMode( QPainter::CompositionMode blendMode ) 97 { 98 setCurrentIndex( mBlendModeToListIndex[( int ) QgsPainting::getBlendModeEnum( blendMode )] ); 99 } 100 101