Skip to content

Commit

Permalink
Modify QgsRubberBand to use digitizing color and linewidth fromn proj…
Browse files Browse the repository at this point in the history
…ect properties.

git-svn-id: http://svn.osgeo.org/qgis/trunk@4682 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Jan 14, 2006
1 parent fdaa4f7 commit 51c488b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -2095,6 +2095,14 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
if (mCaptureList.size() == 0)
{
mRubberBand2 = new QgsRubberBand(this, mPolygonEditing);
QgsProject * project = QgsProject::instance();
QColor color(
project->readNumEntry("Digitizing", "/LineColorRedPart", 255),
project->readNumEntry("Digitizing", "/LineColorGreenPart", 0),
project->readNumEntry("Digitizing", "/LineColorBluePart", 0));
mRubberBand2->setColor(color);
int width = project->readNumEntry("Digitizing", "/LineWidth", 1);
mRubberBand2->setWidth(width);
mRubberBand2->show();
}
#endif
Expand Down
24 changes: 22 additions & 2 deletions src/gui/qgsrubberband.cpp
Expand Up @@ -27,11 +27,31 @@ QgsRubberBand::QgsRubberBand(QWidget * parent, bool isPolygon)
{
setGeometry(parent->rect()); // this widget is same size as parent
mPoints.append(QPoint()); // addPoint assumes an initial allocated point
setColor(QColor(Qt::lightGray));
}

QgsRubberBand::~QgsRubberBand()
{}

/*!
Set the outline and fill color.
*/
void QgsRubberBand::setColor(const QColor & color)
{
mPen.setColor(color);
QColor fillColor(color.red(), color.green(), color.blue(), 63);
mBrush.setColor(fillColor);
mBrush.setStyle(Qt::SolidPattern);
}

/*!
Set the outline width.
*/
void QgsRubberBand::setWidth(int width)
{
mPen.setWidth(width);
}

/*!
Remove all points from the shape being created.
*/
Expand Down Expand Up @@ -69,8 +89,8 @@ void QgsRubberBand::paintEvent(QPaintEvent * event)
if (mPoints.count() > 1)
{
QPainter p(this);
p.setPen(Qt::lightGray);
p.setBrush(QBrush(Qt::lightGray, Qt::Dense6Pattern));
p.setPen(mPen);
p.setBrush(mBrush);
if (mIsPolygon)
{
p.drawPolygon(mPoints);
Expand Down
9 changes: 8 additions & 1 deletion src/gui/qgsrubberband.h
Expand Up @@ -17,6 +17,8 @@
#define QGSRUBBERBAND_H

#include <QWidget>
#include <QBrush>
#include <QPen>
#include <QPolygon>
class QPaintEvent;

Expand All @@ -25,7 +27,10 @@ class QgsRubberBand: public QWidget
public:
QgsRubberBand(QWidget * parent, bool isPolygon = false);
~QgsRubberBand();


void setColor(const QColor & color);
void setWidth(int width);

void reset(bool isPolygon = false);
void addPoint(const QPoint & p);
void movePoint(const QPoint & p);
Expand All @@ -34,6 +39,8 @@ class QgsRubberBand: public QWidget
virtual void paintEvent(QPaintEvent * event);

private:
QBrush mBrush;
QPen mPen;
QPolygon mPoints;
bool mIsPolygon;
};
Expand Down

0 comments on commit 51c488b

Please sign in to comment.