Skip to content

Commit 297cbba

Browse files
author
timlinux
committedJan 12, 2006
Note: This is a commit of work in progress...
Added ui components and code logic for user selectable canvas background colour. All infrastructure is in place but background is still rendering white for me thus this is a work in progress. This commit also includes preliminary code to render vector polygons semi transparently but it causes quite a slowdown in drawing so Ive hard coded it to be opague until I have implement a gui frontend for setting transparency levels. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4670 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dec7024 commit 297cbba

File tree

8 files changed

+260
-234
lines changed

8 files changed

+260
-234
lines changed
 

‎src/gui/qgisapp.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,6 +3004,12 @@ void QgisApp::openProject(int pathIndex)
30043004
#else
30053005
addProject(mRecentProjectPaths.at(pathIndex));
30063006
#endif
3007+
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
3008+
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
3009+
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
3010+
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
3011+
mMapCanvas->setCanvasColor(myColor);
3012+
30073013
}
30083014
//set the projections enabled icon in the status bar
30093015
int myProjectionEnabledFlag =
@@ -5142,13 +5148,19 @@ void QgisApp::projectProperties()
51425148
bool wasProjected = pp->isProjected();
51435149

51445150
// Display the modal dialog box.
5145-
pp->exec();
5146-
5147-
// If the canvas projection settings changed, we need to recalculate the extents in the
5148-
// new coordinate system
5149-
if(pp->isProjected() != wasProjected)
5151+
if (pp->exec())
51505152
{
5151-
mMapCanvas->recalculateExtents();
5153+
// If the canvas projection settings changed, we need to recalculate the extents in the
5154+
// new coordinate system
5155+
if(pp->isProjected() != wasProjected)
5156+
{
5157+
mMapCanvas->recalculateExtents();
5158+
}
5159+
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
5160+
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
5161+
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
5162+
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
5163+
mMapCanvas->setCanvasColor(myColor);
51525164
}
51535165
// Set the window title.
51545166
setTitleBarText_( *this );

‎src/gui/qgsmapcanvas.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ QgsMapCanvas::QgsMapCanvas()
124124

125125
mIsOverviewCanvas = false;
126126

127-
setEraseColor(mCanvasProperties->bgColor);
127+
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
128+
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
129+
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
130+
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
131+
mCanvasProperties->bgColor=myColor;
132+
setEraseColor(myColor);
128133

129134
setMouseTracking(true);
130135
setFocusPolicy(Qt::StrongFocus);
@@ -558,6 +563,10 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
558563
if ( ! theQPaintDevice ) //painting to mapCanvas->pixmap
559564
{
560565
mCanvasProperties->pmCanvas->fill(mCanvasProperties->bgColor);
566+
std::cout << (QString ("R: %i G: %i B: %i for canvas background").arg(
567+
mCanvasProperties->bgColor.red(),
568+
mCanvasProperties->bgColor.red(),
569+
mCanvasProperties->bgColor.red())).toLocal8Bit().data() << std::endl;
561570
paint->begin(mCanvasProperties->pmCanvas);
562571
if (mCanvasProperties->mAntiAliasFlag)
563572
{
@@ -2736,11 +2745,11 @@ void QgsMapCanvas::setMapTool(int tool)
27362745

27372746

27382747
/** Write property of QColor bgColor. */
2739-
void QgsMapCanvas::setbgColor(const QColor & _newVal)
2748+
void QgsMapCanvas::setCanvasColor(const QColor & _newVal)
27402749
{
27412750
mCanvasProperties->bgColor = _newVal;
27422751
setEraseColor(_newVal);
2743-
} // setbgColor
2752+
} // setCanvasColor
27442753

27452754

27462755
/** Updates the full extent to include the mbr of the rectangle r */

‎src/gui/qgsmapcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class QgsMapCanvas : public QWidget
123123
int mapTool();
124124

125125
/** Write property of QColor bgColor. */
126-
virtual void setbgColor(const QColor & _newVal);
126+
virtual void setCanvasColor(const QColor & _newVal);
127127

128128
/** Updates the full extent to include the mbr of the rectangle r */
129129
void updateFullExtent(QgsRect const & r);

‎src/gui/qgsprojectproperties.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@
114114
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorBluePart",0);
115115
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
116116
pbnSelectionColour->setPaletteBackgroundColor (myColour);
117+
//get the colour for map canvas background and set button colour accordingly (default white)
118+
myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
119+
myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
120+
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
121+
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
122+
pbnCanvasColor->setPaletteBackgroundColor (myColour);
117123
}
118124

119125
QgsProjectProperties::~QgsProjectProperties()
120126
{}
121127

128+
129+
122130
// return the map units
123131
QGis::units QgsProjectProperties::mapUnits() const
124132
{
@@ -268,6 +276,12 @@ void QgsProjectProperties::apply()
268276
QgsProject::instance()->writeEntry("Gui","/SelectionColorBluePart",myColour.blue());
269277
QgsRenderer::mSelectionColor=myColour;
270278

279+
//set the colour for canvas
280+
myColour = pbnCanvasColor->paletteBackgroundColor();
281+
QgsProject::instance()->writeEntry("Gui","/CanvasColorRedPart",myColour.red());
282+
QgsProject::instance()->writeEntry("Gui","/CanvasColorGreenPart",myColour.green());
283+
QgsProject::instance()->writeEntry("Gui","/CanvasColorBluePart",myColour.blue());
284+
//todo XXX set canvas colour
271285
emit refresh();
272286
}
273287

@@ -306,6 +320,14 @@ void QgsProjectProperties::on_pbnSelectionColour_clicked()
306320
}
307321
}
308322

323+
void QgsProjectProperties::on_pbnCanvasColor_clicked()
324+
{
325+
QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
326+
if (color.isValid())
327+
{
328+
pbnCanvasColor->setPaletteBackgroundColor(color);
329+
}
330+
}
309331
void QgsProjectProperties::on_pbnHelp_clicked()
310332
{
311333
std::cout << "running help" << std::endl;

‎src/gui/qgsprojectproperties.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "ui_qgsprojectpropertiesbase.h"
2222
#include "qgis.h"
23-
23+
class QColor;
2424

2525
/*! Dialog to set project level properties
2626
@@ -55,7 +55,7 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
5555
/*! Accessor for projection */
5656
QString projectionWKT();
5757
/*! Indicates that the projection switch is on */
58-
bool QgsProjectProperties::isProjected();
58+
bool isProjected();
5959
public slots:
6060
/*!
6161
* Slot called when a new button (unit) is selected
@@ -85,6 +85,11 @@ public slots:
8585
* Slot to select the map selection colour
8686
*/
8787
void on_pbnSelectionColour_clicked();
88+
89+
/*!
90+
* Slot to select the map selection colour
91+
*/
92+
void on_pbnCanvasColor_clicked();
8893

8994
/*!
9095
* Slot to show the context help for this dialog

‎src/gui/qgsvectorlayer.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,18 @@ std::cerr << i << ": " << ring->first[i]
736736
std::cerr << "Smallest Y coordinate was " << smallestY << '\n';
737737
*/
738738

739+
//preserve a copy f the brush before we start fiddling with it
740+
QBrush brush = p->brush(); //to be kept as original
741+
QBrush myTransparentBrush = p->brush();
742+
QColor myColor = brush.color();
743+
//experimental alpha transparency
744+
//255 = opaque
745+
//I have hardcoded it to opaque out for now
746+
//until I make it user configurable
747+
//and hopefully work out how to improve performance
748+
myColor.setAlpha(255);
749+
myTransparentBrush.setColor(myColor);
750+
p->setBrush(myTransparentBrush);
739751
// draw the polygon fill
740752
QPen pen = p->pen(); // store current pen
741753
p->setPen ( Qt::NoPen ); // no boundary
@@ -744,7 +756,6 @@ std::cerr << i << ": " << ring->first[i]
744756

745757
// draw the polygon outline. Draw each ring as a separate
746758
// polygon to avoid the lines associated with the outerRingPt.
747-
QBrush brush = p->brush();
748759
p->setBrush ( Qt::NoBrush );
749760

750761
ringDetailType::const_iterator ri = ringDetails.begin();

0 commit comments

Comments
 (0)
Please sign in to comment.