Skip to content
Permalink
Browse files

[FEATURE] Blend modes for labels and label buffers

  • Loading branch information
nyalldawson committed Mar 27, 2013
1 parent 4b1b2fb commit 8793d388b1fd0f315f55b0f56f5ee8462ea6df13
Showing with 75 additions and 25 deletions.
  1. +4 −0 src/app/qgslabelinggui.cpp
  2. +20 −1 src/core/qgspallabeling.cpp
  3. +2 −0 src/core/qgspallabeling.h
  4. +49 −24 src/ui/qgslabelingguibase.ui
@@ -250,6 +250,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
mBufferJoinStyleComboBox->setPenJoinStyle( lyr.bufferJoinStyle );
mBufferTranspFillChbx->setChecked( !lyr.bufferNoFill );
comboBufferBlendMode->setBlendMode( lyr.bufferBlendMode );
}
else
{
@@ -290,6 +291,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
mFontSizeSpinBox->setValue( lyr.textFont.pointSizeF() );
btnTextColor->setColor( lyr.textColor );
mFontTranspSpinBox->setValue( lyr.textTransp );
comboBlendMode->setBlendMode( lyr.blendMode );

mFontWordSpacingSpinBox->setValue( lyr.textFont.wordSpacing() );
mFontLetterSpacingSpinBox->setValue( lyr.textFont.letterSpacing() );
@@ -446,6 +448,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.textFont = mRefFont;
lyr.textNamedStyle = mFontStyleComboBox->currentText();
lyr.textTransp = mFontTranspSpinBox->value();
lyr.blendMode = ( QgsMapRenderer::BlendMode ) comboBlendMode->blendMode();
lyr.previewBkgrdColor = mPreviewBackgroundBtn->color();
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
@@ -470,6 +473,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.bufferSizeInMapUnits = ( mBufferUnitComboBox->currentIndex() == 1 );
lyr.bufferJoinStyle = mBufferJoinStyleComboBox->penJoinStyle();
lyr.bufferNoFill = !mBufferTranspFillChbx->isChecked();
lyr.bufferBlendMode = ( QgsMapRenderer::BlendMode ) comboBufferBlendMode->blendMode();
}
else
{
@@ -202,6 +202,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
textNamedStyle = QString( "" );
textColor = Qt::black;
textTransp = 0;
blendMode = QgsMapRenderer::BlendNormal;
previewBkgrdColor = Qt::white;
enabled = false;
priority = 5;
@@ -212,6 +213,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
bufferSize = 1;
bufferColor = Qt::white;
bufferTransp = 0;
bufferBlendMode = QgsMapRenderer::BlendNormal;
bufferNoFill = false;
bufferJoinStyle = Qt::BevelJoin;
formatNumbers = false;
@@ -286,6 +288,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
textNamedStyle = s.textNamedStyle;
textColor = s.textColor;
textTransp = s.textTransp;
blendMode = s.blendMode;
previewBkgrdColor = s.previewBkgrdColor;
enabled = s.enabled;
priority = s.priority;
@@ -296,6 +299,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
bufferSize = s.bufferSize;
bufferColor = s.bufferColor;
bufferTransp = s.bufferTransp;
bufferBlendMode = s.bufferBlendMode;
bufferJoinStyle = s.bufferJoinStyle;
bufferNoFill = s.bufferNoFill;
formatNumbers = s.formatNumbers;
@@ -524,6 +528,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
textFont.setWordSpacing( layer->customProperty( "labeling/fontWordSpacing", QVariant( 0.0 ) ).toDouble() );
textColor = _readColor( layer, "labeling/textColor" );
textTransp = layer->customProperty( "labeling/textTransp" ).toInt();
blendMode = ( QgsMapRenderer::BlendMode ) layer->customProperty( "labeling/blendMode" ).toInt();
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", QVariant( "#ffffff" ) ).toString() );
enabled = layer->customProperty( "labeling/enabled" ).toBool();
priority = layer->customProperty( "labeling/priority" ).toInt();
@@ -534,6 +539,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
bufferSize = layer->customProperty( "labeling/bufferSize" ).toDouble();
bufferColor = _readColor( layer, "labeling/bufferColor" );
bufferTransp = layer->customProperty( "labeling/bufferTransp" ).toInt();
bufferBlendMode = ( QgsMapRenderer::BlendMode ) layer->customProperty( "labeling/bufferBlendMode" ).toInt();
bufferJoinStyle = ( Qt::PenJoinStyle ) layer->customProperty( "labeling/bufferJoinStyle", QVariant( Qt::BevelJoin ) ).toUInt();
bufferNoFill = layer->customProperty( "labeling/bufferNoFill", QVariant( false ) ).toBool();
formatNumbers = layer->customProperty( "labeling/formatNumbers" ).toBool();
@@ -596,6 +602,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )

_writeColor( layer, "labeling/textColor", textColor );
layer->setCustomProperty( "labeling/textTransp", textTransp );
layer->setCustomProperty( "labeling/blendMode", ( unsigned int )blendMode );
layer->setCustomProperty( "labeling/previewBkgrdColor", previewBkgrdColor.name() );
layer->setCustomProperty( "labeling/enabled", enabled );
layer->setCustomProperty( "labeling/priority", priority );
@@ -606,6 +613,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/bufferSize", bufferSize );
_writeColor( layer, "labeling/bufferColor", bufferColor );
layer->setCustomProperty( "labeling/bufferTransp", bufferTransp );
layer->setCustomProperty( "labeling/bufferBlendMode", ( unsigned int )bufferBlendMode );
layer->setCustomProperty( "labeling/bufferJoinStyle", ( unsigned int )bufferJoinStyle );
layer->setCustomProperty( "labeling/bufferNoFill", bufferNoFill );
layer->setCustomProperty( "labeling/formatNumbers", formatNumbers );
@@ -1645,9 +1653,11 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
QFont fontForLabel = lyr.textFont;
QColor fontColor = lyr.textColor;
int fontTransp = lyr.textTransp;
QgsMapRenderer::BlendMode blendMode = lyr.blendMode;
double bufferSize = lyr.bufferSize;
QColor bufferColor = lyr.bufferColor;
int bufferTransp = lyr.bufferTransp;
QgsMapRenderer::BlendMode bufferBlendMode = lyr.bufferBlendMode;

//apply data defined settings for the label
//font size
@@ -1741,10 +1751,16 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )

if ( lyr.bufferSize != 0 )
{
// Set the painter composition mode for the buffer
painter->setCompositionMode( mMapRenderer->getCompositionMode( bufferBlendMode ) );

int bufferPixelSize = lyr.sizeToPixel( bufferSize, context, true );
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferPixelSize, bufferColor, true );
}


// Set the painter composition mode before rendering the label
painter->setCompositionMode( mMapRenderer->getCompositionMode( blendMode ) );

drawLabel( *it, painter, fontForLabel, fontColor, xform );

if ( mLabelSearchTree )
@@ -1754,6 +1770,9 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
}
}

// Reset composition mode for further drawing operations
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );

QgsDebugMsg( QString( "LABELING draw: %1 ms" ).arg( t.elapsed() ) );

delete problem;
@@ -154,6 +154,7 @@ class CORE_EXPORT QgsPalLayerSettings
QString textNamedStyle;
QColor textColor;
int textTransp;
QgsMapRenderer::BlendMode blendMode;
QColor previewBkgrdColor;
bool enabled;
int priority; // 0 = low, 10 = high
@@ -168,6 +169,7 @@ class CORE_EXPORT QgsPalLayerSettings
double bufferSize; //buffer size (in mm)
QColor bufferColor;
int bufferTransp;
QgsMapRenderer::BlendMode bufferBlendMode;
Qt::PenJoinStyle bufferJoinStyle;
bool bufferNoFill; //set interior of buffer to 100% transparent
bool formatNumbers;
@@ -217,7 +217,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>678</width>
<width>683</width>
<height>300</height>
</rect>
</property>
@@ -429,8 +429,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>689</width>
<height>826</height>
<width>693</width>
<height>709</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
@@ -1082,6 +1082,16 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsBlendModeComboBox" name="comboBlendMode"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelBlendMode">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
@@ -1100,39 +1110,39 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mFontColorLabel">
<item row="2" column="0">
<widget class="QLabel" name="mFontSizeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Color</string>
<string>Size</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</widget>
</item>
<item row="0" column="2" rowspan="5">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mFontSizeLabel">
<item row="3" column="0">
<widget class="QLabel" name="mFontColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size</string>
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="5">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
@@ -1260,6 +1270,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsBlendModeComboBox" name="comboBufferBlendMode"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelBufferBlend">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
@@ -1911,8 +1931,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>686</width>
<height>618</height>
<width>604</width>
<height>622</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
@@ -2360,12 +2380,12 @@
<item>
<widget class="QFrame" name="mMaxCharAngleFrame">
<layout class="QGridLayout" name="gridLayout_22">
<property name="verticalSpacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="1" column="4">
<widget class="QDoubleSpinBox" name="mMaxCharAngleOutDSpinBox">
<property name="sizePolicy">
@@ -2988,8 +3008,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>686</width>
<height>981</height>
<width>520</width>
<height>1043</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_11">
@@ -3484,6 +3504,11 @@
<extends>QComboBox</extends>
<header>qgspenstylecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 8793d38

Please sign in to comment.
You can’t perform that action at this time.