Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Add outline and color opacity settings for scale bar decora…
…tion
  • Loading branch information
nirvn committed May 9, 2017
1 parent 1445505 commit 83e8ece
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
18 changes: 8 additions & 10 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -33,6 +33,7 @@ email : sbr00pwb@users.sourceforge.net
#include "qgsproject.h"
#include "qgsunittypes.h"
#include "qgssettings.h"
#include "qgssymbollayerutils.h"

#include <QPainter>
#include <QAction>
Expand Down Expand Up @@ -75,10 +76,8 @@ void QgsDecorationScaleBar::projectRead()
mPreferredSize = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/PreferredSize" ), 30 );
mStyleIndex = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/Style" ), 0 );
mSnapping = QgsProject::instance()->readBoolEntry( mNameConfig, QStringLiteral( "/Snapping" ), true );
int myRedInt = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/ColorRedPart" ), 0 );
int myGreenInt = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/ColorGreenPart" ), 0 );
int myBlueInt = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/ColorBluePart" ), 0 );
mColor = QColor( myRedInt, myGreenInt, myBlueInt );
mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) );
mOutlineColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) );
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/MarginH" ), 0 );
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/MarginV" ), 0 );
}
Expand All @@ -89,9 +88,8 @@ void QgsDecorationScaleBar::saveToProject()
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/PreferredSize" ), mPreferredSize );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Snapping" ), mSnapping );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Style" ), mStyleIndex );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/ColorRedPart" ), mColor.red() );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/ColorGreenPart" ), mColor.green() );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/ColorBluePart" ), mColor.blue() );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/OutlineColor" ), QgsSymbolLayerUtils::encodeColor( mOutlineColor ) );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/MarginH" ), mMarginHorizontal );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/MarginV" ), mMarginVertical );
}
Expand Down Expand Up @@ -311,7 +309,7 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender

//Set pen to draw with
QPen myForegroundPen( mColor, 2 );
QPen myBackgroundPen( Qt::white, 4 );
QPen myBackgroundPen( mOutlineColor, 4 );

//Cast myScaleBarWidth to int for drawing
int myScaleBarWidthInt = static_cast< int >( myScaleBarWidth );
Expand Down Expand Up @@ -434,8 +432,8 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
//Do drawing of scale bar text
//

QColor myBackColor = Qt::white;
QColor myForeColor = Qt::black;
QColor myBackColor = mOutlineColor;
QColor myForeColor = mColor;

//Draw the minimum label buffer
context.painter()->setPen( myBackColor );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsdecorationscalebar.h
Expand Up @@ -58,8 +58,12 @@ class APP_EXPORT QgsDecorationScaleBar: public QgsDecorationItem
//! Style of scale bar. An index and the translated text
int mStyleIndex;
QStringList mStyleLabels;

//! The scale bar color
QColor mColor;
//! The scale bar otuline color
QColor mOutlineColor;

//! Margin percentage values
int mMarginHorizontal;
int mMarginVertical;
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgsdecorationscalebardialog.cpp
Expand Up @@ -71,9 +71,15 @@ QgsDecorationScaleBarDialog::QgsDecorationScaleBarDialog( QgsDecorationScaleBar

cboStyle->setCurrentIndex( mDeco.mStyleIndex );

pbnChangeColor->setAllowAlpha( true );
pbnChangeColor->setColor( mDeco.mColor );
pbnChangeColor->setContext( QStringLiteral( "gui" ) );
pbnChangeColor->setColorDialogTitle( tr( "Select scalebar color" ) );
pbnChangeColor->setColorDialogTitle( tr( "Select scale bar fill color" ) );

pbnChangeOutlineColor->setAllowAlpha( true );
pbnChangeOutlineColor->setColor( mDeco.mOutlineColor );
pbnChangeOutlineColor->setContext( QStringLiteral( "gui" ) );
pbnChangeOutlineColor->setColorDialogTitle( tr( "Select scale bar outline color" ) );
}

QgsDecorationScaleBarDialog::~QgsDecorationScaleBarDialog()
Expand All @@ -98,6 +104,7 @@ void QgsDecorationScaleBarDialog::apply()
mDeco.setEnabled( grpEnable->isChecked() );
mDeco.mStyleIndex = cboStyle->currentIndex();
mDeco.mColor = pbnChangeColor->color();
mDeco.mOutlineColor = pbnChangeOutlineColor->color();
mDeco.update();
}

Expand Down
36 changes: 28 additions & 8 deletions src/ui/qgsdecorationscalebardialog.ui
Expand Up @@ -53,7 +53,14 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="colorLayout">
<item>
<widget class="QLabel" name="fillLabel">
<property name="text">
<string>Fill</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="pbnChangeColor">
<property name="minimumSize">
Expand All @@ -74,17 +81,30 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="outlineLabel">
<property name="text">
<string>Outline</string>
</property>
<property name="sizeHint" stdset="0">
</widget>
</item>
<item>
<widget class="QgsColorButton" name="pbnChangeOutlineColor">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
<width>150</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
Expand Down

0 comments on commit 83e8ece

Please sign in to comment.