Skip to content

Commit

Permalink
Make the rubber band color configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner authored and m-kuhn committed Dec 15, 2015
1 parent 02fcaca commit dad7aa7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 17 deletions.
13 changes: 12 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -360,7 +360,16 @@ void QgsMapToolNodeTool::updateSelectFeature()

mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
mSelectRubberBand->setFillColor( QColor( 255, 0, 0, 50 ) );

QSettings settings;
QColor color(
settings.value( "/qgis/digitizing/select_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/select_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/select_color_blue", 0 ).toInt() );
double myAlpha = settings.value( "/qgis/digitizing/select_color_alpha", 30 ).toInt() / 255.0 ;
color.setAlphaF( myAlpha );
mSelectRubberBand->setFillColor( color );

QgsAbstractGeometryV2* rbGeom = mSelectedFeature->geometry()->geometry()->clone();
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
Expand Down Expand Up @@ -489,6 +498,8 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )

mDeselectOnRelease = -1;
}

updateSelectFeature();
}

void QgsMapToolNodeTool::deactivate()
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -794,6 +794,15 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
mLineColorToolButton->setContext( "gui" );
mLineColorToolButton->setDefaultColor( QColor( 255, 0, 0, 200 ) );

myRed = settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt();
myGreen = settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt();
myBlue = settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt();
myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt();
mFillColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
mFillColorToolButton->setAllowAlpha( true );
mFillColorToolButton->setContext( "gui" );
mFillColorToolButton->setDefaultColor( QColor( 255, 0, 0, 30 ) );

//default snap mode
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), "to vertex" );
mDefaultSnapModeComboBox->insertItem( 1, tr( "To segment" ), "to segment" );
Expand Down Expand Up @@ -1288,6 +1297,12 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/digitizing/line_color_blue", digitizingColor.blue() );
settings.setValue( "/qgis/digitizing/line_color_alpha", digitizingColor.alpha() );

digitizingColor = mFillColorToolButton->color();
settings.setValue( "/qgis/digitizing/fill_color_red", digitizingColor.red() );
settings.setValue( "/qgis/digitizing/fill_color_green", digitizingColor.green() );
settings.setValue( "/qgis/digitizing/fill_color_blue", digitizingColor.blue() );
settings.setValue( "/qgis/digitizing/fill_color_alpha", digitizingColor.alpha() );

//default snap mode
QString defaultSnapModeString = mDefaultSnapModeComboBox->itemData( mDefaultSnapModeComboBox->currentIndex() ).toString();
settings.setValue( "/qgis/digitizing/default_snap_mode", defaultSnapModeString );
Expand Down
16 changes: 13 additions & 3 deletions src/gui/qgsmaptooledit.cpp
Expand Up @@ -39,9 +39,10 @@ QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType
QSettings settings;
QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
QColor color(
settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0;
if ( alternativeBand )
{
Expand All @@ -54,6 +55,15 @@ QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType
}
color.setAlphaF( myAlpha );
rb->setColor( color );

QColor fillColor(
settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt() );
myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt() / 255.0 ;
fillColor.setAlphaF( myAlpha );
rb->setFillColor( fillColor );

rb->show();
return rb;
}
Expand Down
64 changes: 51 additions & 13 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -3558,6 +3558,32 @@
<string>Rubberband</string>
</property>
<layout class="QGridLayout" name="_9">
<item row="0" column="9">
<spacer name="horizontalSpacer_33">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mLineWidthTextLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="mLineColorTextLabel">
<property name="sizePolicy">
Expand All @@ -3581,31 +3607,43 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mLineWidthTextLabel">
<item row="0" column="5">
<widget class="QgsColorButtonV2" name="mFillColorToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Line width</string>
<string/>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_33">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="mSelectColorTextLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="text">
<string>Fill color</string>
</property>
</spacer>
</widget>
</item>
<item row="0" column="3">
<widget class="QgsColorButtonV2" name="mLineColorToolButton">
Expand Down

0 comments on commit dad7aa7

Please sign in to comment.