Skip to content

Commit

Permalink
Note: This is a commit of work in progress...
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timlinux committed Jan 12, 2006
1 parent dec7024 commit 297cbba
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 234 deletions.
24 changes: 18 additions & 6 deletions src/gui/qgisapp.cpp
Expand Up @@ -3004,6 +3004,12 @@ void QgisApp::openProject(int pathIndex)
#else
addProject(mRecentProjectPaths.at(pathIndex));
#endif
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
mMapCanvas->setCanvasColor(myColor);

}
//set the projections enabled icon in the status bar
int myProjectionEnabledFlag =
Expand Down Expand Up @@ -5142,13 +5148,19 @@ void QgisApp::projectProperties()
bool wasProjected = pp->isProjected();

// Display the modal dialog box.
pp->exec();

// If the canvas projection settings changed, we need to recalculate the extents in the
// new coordinate system
if(pp->isProjected() != wasProjected)
if (pp->exec())
{
mMapCanvas->recalculateExtents();
// If the canvas projection settings changed, we need to recalculate the extents in the
// new coordinate system
if(pp->isProjected() != wasProjected)
{
mMapCanvas->recalculateExtents();
}
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
mMapCanvas->setCanvasColor(myColor);
}
// Set the window title.
setTitleBarText_( *this );
Expand Down
15 changes: 12 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -124,7 +124,12 @@ QgsMapCanvas::QgsMapCanvas()

mIsOverviewCanvas = false;

setEraseColor(mCanvasProperties->bgColor);
int myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
int myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
int myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
mCanvasProperties->bgColor=myColor;
setEraseColor(myColor);

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


/** Write property of QColor bgColor. */
void QgsMapCanvas::setbgColor(const QColor & _newVal)
void QgsMapCanvas::setCanvasColor(const QColor & _newVal)
{
mCanvasProperties->bgColor = _newVal;
setEraseColor(_newVal);
} // setbgColor
} // setCanvasColor


/** Updates the full extent to include the mbr of the rectangle r */
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -123,7 +123,7 @@ class QgsMapCanvas : public QWidget
int mapTool();

/** Write property of QColor bgColor. */
virtual void setbgColor(const QColor & _newVal);
virtual void setCanvasColor(const QColor & _newVal);

/** Updates the full extent to include the mbr of the rectangle r */
void updateFullExtent(QgsRect const & r);
Expand Down
22 changes: 22 additions & 0 deletions src/gui/qgsprojectproperties.cpp
Expand Up @@ -114,11 +114,19 @@
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorBluePart",0);
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
pbnSelectionColour->setPaletteBackgroundColor (myColour);
//get the colour for map canvas background and set button colour accordingly (default white)
myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
pbnCanvasColor->setPaletteBackgroundColor (myColour);
}

QgsProjectProperties::~QgsProjectProperties()
{}



// return the map units
QGis::units QgsProjectProperties::mapUnits() const
{
Expand Down Expand Up @@ -268,6 +276,12 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry("Gui","/SelectionColorBluePart",myColour.blue());
QgsRenderer::mSelectionColor=myColour;

//set the colour for canvas
myColour = pbnCanvasColor->paletteBackgroundColor();
QgsProject::instance()->writeEntry("Gui","/CanvasColorRedPart",myColour.red());
QgsProject::instance()->writeEntry("Gui","/CanvasColorGreenPart",myColour.green());
QgsProject::instance()->writeEntry("Gui","/CanvasColorBluePart",myColour.blue());
//todo XXX set canvas colour
emit refresh();
}

Expand Down Expand Up @@ -306,6 +320,14 @@ void QgsProjectProperties::on_pbnSelectionColour_clicked()
}
}

void QgsProjectProperties::on_pbnCanvasColor_clicked()
{
QColor color = QColorDialog::getColor(pbnCanvasColor->paletteBackgroundColor(),this);
if (color.isValid())
{
pbnCanvasColor->setPaletteBackgroundColor(color);
}
}
void QgsProjectProperties::on_pbnHelp_clicked()
{
std::cout << "running help" << std::endl;
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsprojectproperties.h
Expand Up @@ -20,7 +20,7 @@

#include "ui_qgsprojectpropertiesbase.h"
#include "qgis.h"
class QColor;

/*! Dialog to set project level properties
Expand Down Expand Up @@ -55,7 +55,7 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
/*! Accessor for projection */
QString projectionWKT();
/*! Indicates that the projection switch is on */
bool QgsProjectProperties::isProjected();
bool isProjected();
public slots:
/*!
* Slot called when a new button (unit) is selected
Expand Down Expand Up @@ -85,6 +85,11 @@ public slots:
* Slot to select the map selection colour
*/
void on_pbnSelectionColour_clicked();

/*!
* Slot to select the map selection colour
*/
void on_pbnCanvasColor_clicked();

/*!
* Slot to show the context help for this dialog
Expand Down
13 changes: 12 additions & 1 deletion src/gui/qgsvectorlayer.cpp
Expand Up @@ -736,6 +736,18 @@ std::cerr << i << ": " << ring->first[i]
std::cerr << "Smallest Y coordinate was " << smallestY << '\n';
*/

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

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

ringDetailType::const_iterator ri = ringDetails.begin();
Expand Down

0 comments on commit 297cbba

Please sign in to comment.