Skip to content

Commit

Permalink
Fix restoring selection color from project and allow alpha values for…
Browse files Browse the repository at this point in the history
… selection color

git-svn-id: http://svn.osgeo.org/qgis/trunk@14710 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 18, 2010
1 parent d1bb517 commit 07a3f62
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3163,10 +3163,12 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt(); int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
int myGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt(); int myGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt();
int myBlue = settings.value( "/qgis/default_selection_color_blue", 0 ).toInt(); int myBlue = settings.value( "/qgis/default_selection_color_blue", 0 ).toInt();
int myAlpha = settings.value( "/qgis/default_selection_color_alpha", 255 ).toInt();
prj->writeEntry( "Gui", "/SelectionColorRedPart", myRed ); prj->writeEntry( "Gui", "/SelectionColorRedPart", myRed );
prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen ); prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen );
prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue ); prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue );
QgsRenderer::setSelectionColor( QColor( myRed, myGreen, myBlue ) ); prj->writeEntry( "Gui", "/SelectionColorAlphaPart", myAlpha );
QgsRenderer::setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );


//set the canvas to the default background color //set the canvas to the default background color
//the default can be set in qgisoptions //the default can be set in qgisoptions
Expand Down Expand Up @@ -3429,6 +3431,18 @@ bool QgisApp::addProject( QString projectFile )
mMapCanvas->setCanvasColor( myColor ); //this is fill color before rendering starts mMapCanvas->setCanvasColor( myColor ); //this is fill color before rendering starts
QgsDebugMsg( "Canvas background color restored..." ); QgsDebugMsg( "Canvas background color restored..." );


//set the color for selections
QSettings settings;
int defaultRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
int defaultGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt();
int defaultBlue = settings.value( "/qgis/default_selection_color_blue", 0 ).toInt();
int defaultAlpha = settings.value( "/qgis/default_selection_color_alpha", 255 ).toInt();
int myRed = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", defaultRed );
int myGreen = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", defaultGreen );
int myBlue = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", defaultBlue );
int myAlpha = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", defaultAlpha );
QgsRenderer::setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );

mMapCanvas->updateScale(); mMapCanvas->updateScale();
QgsDebugMsg( "Scale restored..." ); QgsDebugMsg( "Scale restored..." );


Expand All @@ -3437,7 +3451,6 @@ bool QgisApp::addProject( QString projectFile )
// specific plug-in state // specific plug-in state


// add this to the list of recently used project files // add this to the list of recently used project files
QSettings settings;
saveRecentProjectPath( projectFile, settings ); saveRecentProjectPath( projectFile, settings );


QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
Expand Down
11 changes: 9 additions & 2 deletions src/app/qgsoptions.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt(); int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
int myGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt(); int myGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt();
int myBlue = settings.value( "/qgis/default_selection_color_blue", 0 ).toInt(); int myBlue = settings.value( "/qgis/default_selection_color_blue", 0 ).toInt();
pbnSelectionColor->setColor( QColor( myRed, myGreen, myBlue ) ); int myAlpha = settings.value( "/qgis/default_selection_color_alpha", 255 ).toInt();
pbnSelectionColor->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );


//set the default color for canvas background //set the default color for canvas background
myRed = settings.value( "/qgis/default_canvas_color_red", 255 ).toInt(); myRed = settings.value( "/qgis/default_canvas_color_red", 255 ).toInt();
Expand Down Expand Up @@ -403,7 +404,12 @@ QgsOptions::~QgsOptions()


void QgsOptions::on_pbnSelectionColor_clicked() void QgsOptions::on_pbnSelectionColor_clicked()
{ {
QColor color = QColorDialog::getColor( pbnSelectionColor->color(), this ); #if QT_VERSION >= 0x040500
QColor color = QColorDialog::getColor( pbnSelectionColor->color(), 0, tr( "Selection color" ), QColorDialog::ShowAlphaChannel );
#else
QColor color = QColorDialog::getColor( pbnSelectionColor->color() );
#endif

if ( color.isValid() ) if ( color.isValid() )
{ {
pbnSelectionColor->setColor( color ); pbnSelectionColor->setColor( color );
Expand Down Expand Up @@ -612,6 +618,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/default_selection_color_red", myColor.red() ); settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
settings.setValue( "/qgis/default_selection_color_green", myColor.green() ); settings.setValue( "/qgis/default_selection_color_green", myColor.green() );
settings.setValue( "/qgis/default_selection_color_blue", myColor.blue() ); settings.setValue( "/qgis/default_selection_color_blue", myColor.blue() );
settings.setValue( "/qgis/default_selection_color_alpha", myColor.alpha() );


//set the default color for canvas background //set the default color for canvas background
myColor = pbnCanvasColor->color(); myColor = pbnCanvasColor->color();
Expand Down
15 changes: 11 additions & 4 deletions src/app/qgsprojectproperties.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
if ( automaticPrecision ) if ( automaticPrecision )
{ {
radAutomatic->setChecked( true ); radAutomatic->setChecked( true );
spinBoxDP->setDisabled( true ); spinBoxDP->setDisabled( true );
labelDP->setDisabled( true ); labelDP->setDisabled( true );
} }
else else
{ {
Expand All @@ -96,7 +96,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 ); int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 ); int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", 0 ); int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt ); int myAlphaInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt, myAlphaInt );
pbnSelectionColor->setColor( myColor ); pbnSelectionColor->setColor( myColor );


//get the color for map canvas background and set button color accordingly (default white) //get the color for map canvas background and set button color accordingly (default white)
Expand Down Expand Up @@ -315,6 +316,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorRedPart", myColor.red() ); QgsProject::instance()->writeEntry( "Gui", "/SelectionColorRedPart", myColor.red() );
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorGreenPart", myColor.green() ); QgsProject::instance()->writeEntry( "Gui", "/SelectionColorGreenPart", myColor.green() );
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorBluePart", myColor.blue() ); QgsProject::instance()->writeEntry( "Gui", "/SelectionColorBluePart", myColor.blue() );
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorAlphaPart", myColor.alpha() );
QgsRenderer::setSelectionColor( myColor ); QgsRenderer::setSelectionColor( myColor );


//set the color for canvas //set the color for canvas
Expand Down Expand Up @@ -366,7 +368,12 @@ void QgsProjectProperties::showProjectionsTab()


void QgsProjectProperties::on_pbnSelectionColor_clicked() void QgsProjectProperties::on_pbnSelectionColor_clicked()
{ {
QColor color = QColorDialog::getColor( pbnSelectionColor->color(), this ); #if QT_VERSION >= 0x040500
QColor color = QColorDialog::getColor( pbnSelectionColor->color(), 0, tr( "Selection color" ), QColorDialog::ShowAlphaChannel );
#else
QColor color = QColorDialog::getColor( pbnSelectionColor->color() );
#endif

if ( color.isValid() ) if ( color.isValid() )
{ {
pbnSelectionColor->setColor( color ); pbnSelectionColor->setColor( color );
Expand Down

0 comments on commit 07a3f62

Please sign in to comment.