Skip to content

Commit d80ae2c

Browse files
committed
New blend modes combo box widget
1 parent 9e7943b commit d80ae2c

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

src/gui/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ qgisinterface.cpp
4848
qgsannotationitem.cpp
4949
qgsattributeeditor.cpp
5050
qgslegendinterface.cpp
51+
qgsblendmodecombobox.cpp
5152
qgscharacterselectdialog.cpp
5253
qgscolorbutton.cpp
5354
qgscomposerview.cpp
@@ -153,6 +154,7 @@ attributetable/qgsattributetablememorymodel.h
153154
attributetable/qgsattributetabledelegate.h
154155

155156
qgsattributeeditor.h
157+
qgsblendmodecombobox.h
156158
qgscharacterselectdialog.h
157159
qgscomposerview.h
158160
qgsdetaileditemdelegate.h
@@ -227,6 +229,7 @@ qgsrubberband.h
227229
qgsvertexmarker.h
228230
qgsmaptip.h
229231
qgsscalecombobox.h
232+
qgsblendmodecombobox.h
230233
qgssearchquerybuilder.h
231234
qgsattributeeditor.h
232235
qgsfieldvalidator.h

src/gui/qgsblendmodecombobox.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+

src/gui/qgsblendmodecombobox.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgsblendmodecombobox.h
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+
#ifndef QGSBLENDMODECOMBOBOX_H
19+
#define QGSBLENDMODECOMBOBOX_H
20+
21+
#include <QComboBox>
22+
23+
/** \ingroup gui
24+
* A combobox which lets the user select blend modes from a predefined list
25+
**/
26+
class GUI_EXPORT QgsBlendModeComboBox : public QComboBox
27+
{
28+
Q_OBJECT
29+
public:
30+
QgsBlendModeComboBox( QWidget* parent = 0 );
31+
virtual ~QgsBlendModeComboBox();
32+
33+
//! Function to read the selected blend mode as integer
34+
int blendMode();
35+
//! Function to set the selected blend mode from integer
36+
void setBlendMode( int blendMode );
37+
private:
38+
//! Returns a list of grouped blend modes (with seperators)
39+
QStringList blendModesList() const;
40+
41+
//! Used to map blend modes across to their corresponding
42+
// index within the combo box
43+
std::vector<int> mBlendModeToListIndex;
44+
std::vector<int> mListIndexToBlendMode;
45+
46+
public slots:
47+
void updateModes();
48+
49+
};
50+
51+
#endif // QGSBLENDMODECOMBOBOX_H

0 commit comments

Comments
 (0)