|
| 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 | + |
| 32 | +QgsBlendModeComboBox::~QgsBlendModeComboBox() |
| 33 | +{ |
| 34 | +} |
| 35 | + |
| 36 | +/* Returns a QStringList of the translated blend modes |
| 37 | +* "-" is used to indicate the position of a seperator 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 | +*/ |
| 41 | +QStringList QgsBlendModeComboBox::blendModesList() const |
| 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 | +*/ |
| 65 | +void QgsBlendModeComboBox::updateModes() |
| 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 seperator |
| 84 | + insertSeparator( index ); |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + // Not a seperator, 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 | + |
| 101 | +//! Function to read the selected blend mode as int |
| 102 | +int QgsBlendModeComboBox::blendMode() |
| 103 | +{ |
| 104 | + return mListIndexToBlendMode[ currentIndex()]; |
| 105 | +} |
| 106 | + |
| 107 | +//! Function to set the selected blend mode from int |
| 108 | +void QgsBlendModeComboBox::setBlendMode( int blendMode ) |
| 109 | +{ |
| 110 | + setCurrentIndex( mBlendModeToListIndex[ blendMode ] ); |
| 111 | +} |
| 112 | + |
0 commit comments