Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New blend modes combo box widget
  • Loading branch information
nyalldawson committed Mar 21, 2013
1 parent 9e7943b commit d80ae2c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -48,6 +48,7 @@ qgisinterface.cpp
qgsannotationitem.cpp
qgsattributeeditor.cpp
qgslegendinterface.cpp
qgsblendmodecombobox.cpp
qgscharacterselectdialog.cpp
qgscolorbutton.cpp
qgscomposerview.cpp
Expand Down Expand Up @@ -153,6 +154,7 @@ attributetable/qgsattributetablememorymodel.h
attributetable/qgsattributetabledelegate.h

qgsattributeeditor.h
qgsblendmodecombobox.h
qgscharacterselectdialog.h
qgscomposerview.h
qgsdetaileditemdelegate.h
Expand Down Expand Up @@ -227,6 +229,7 @@ qgsrubberband.h
qgsvertexmarker.h
qgsmaptip.h
qgsscalecombobox.h
qgsblendmodecombobox.h
qgssearchquerybuilder.h
qgsattributeeditor.h
qgsfieldvalidator.h
Expand Down
112 changes: 112 additions & 0 deletions src/gui/qgsblendmodecombobox.cpp
@@ -0,0 +1,112 @@
/***************************************************************************
qgsblendmodecombobox.cpp
------------------------
begin : March 21, 2013
copyright : (C) 2013 by Nyall Dawson
email : nyall.dawson@gmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgis.h"
#include "qgslogger.h"
#include "qgsblendmodecombobox.h"

#include <QAbstractItemView>
#include <QLocale>
#include <QSettings>
#include <QLineEdit>

QgsBlendModeComboBox::QgsBlendModeComboBox( QWidget* parent ) : QComboBox( parent )
{
updateModes();
}

QgsBlendModeComboBox::~QgsBlendModeComboBox()
{
}

/* Returns a QStringList of the translated blend modes
* "-" is used to indicate the position of a seperator in the list
* This list is designed to emulate GIMP's layer modes, where
* blending modes are grouped by their effect (lightening, darkening, etc)
*/
QStringList QgsBlendModeComboBox::blendModesList() const
{
return QStringList() << tr( "Normal" )
<< "-"
<< tr( "Lighten" )
<< tr( "Screen" )
<< tr( "Dodge" )
<< tr( "Addition" )
<< "-"
<< tr( "Darken" )
<< tr( "Multiply" )
<< tr( "Burn" )
<< "-"
<< tr( "Overlay" )
<< tr( "Soft light" )
<< tr( "Hard light" )
<< "-"
<< tr( "Difference" )
<< tr( "Subtract" );
}

/* Populates the blend mode combo box, and sets up mapping for
* blend modes to combo box indexes
*/
void QgsBlendModeComboBox::updateModes()
{
blockSignals( true );
clear();

QStringList myBlendModesList = blendModesList();
QStringList::const_iterator blendModeIt = myBlendModesList.constBegin();

mBlendModeToListIndex.resize( myBlendModesList.count() );
mListIndexToBlendMode.resize( myBlendModesList.count() );

// Loop through blend modes
int index = 0;
int blendModeIndex = 0;
for ( ; blendModeIt != myBlendModesList.constEnd(); ++blendModeIt )
{
if ( *blendModeIt == "-" )
{
// Add seperator
insertSeparator( index );
}
else
{
// Not a seperator, so store indexes for translation
// between blend modes and combo box item index
addItem( *blendModeIt );
mListIndexToBlendMode[ index ] = blendModeIndex;
mBlendModeToListIndex[ blendModeIndex ] = index;
blendModeIndex++;
}
index++;
}

blockSignals( false );
}

//! Function to read the selected blend mode as int
int QgsBlendModeComboBox::blendMode()
{
return mListIndexToBlendMode[ currentIndex()];
}

//! Function to set the selected blend mode from int
void QgsBlendModeComboBox::setBlendMode( int blendMode )
{
setCurrentIndex( mBlendModeToListIndex[ blendMode ] );
}

51 changes: 51 additions & 0 deletions src/gui/qgsblendmodecombobox.h
@@ -0,0 +1,51 @@
/***************************************************************************
qgsblendmodecombobox.h
------------------------
begin : March 21, 2013
copyright : (C) 2013 by Nyall Dawson
email : nyall.dawson@gmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSBLENDMODECOMBOBOX_H
#define QGSBLENDMODECOMBOBOX_H

#include <QComboBox>

/** \ingroup gui
* A combobox which lets the user select blend modes from a predefined list
**/
class GUI_EXPORT QgsBlendModeComboBox : public QComboBox
{
Q_OBJECT
public:
QgsBlendModeComboBox( QWidget* parent = 0 );
virtual ~QgsBlendModeComboBox();

//! Function to read the selected blend mode as integer
int blendMode();
//! Function to set the selected blend mode from integer
void setBlendMode( int blendMode );
private:
//! Returns a list of grouped blend modes (with seperators)
QStringList blendModesList() const;

//! Used to map blend modes across to their corresponding
// index within the combo box
std::vector<int> mBlendModeToListIndex;
std::vector<int> mListIndexToBlendMode;

public slots:
void updateModes();

};

#endif // QGSBLENDMODECOMBOBOX_H

0 comments on commit d80ae2c

Please sign in to comment.