Skip to content

Commit

Permalink
Show rubber band on coordinate click position.
Browse files Browse the repository at this point in the history
Make cursor hotspot the center of the cursor
Added some icons & changed to grid layout


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9001 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 6, 2008
1 parent 3c83558 commit 5befedc
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 16 deletions.
17 changes: 12 additions & 5 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Expand Up @@ -76,7 +76,7 @@ void CoordinateCapture::initGui()
{

// Create the action for tool
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinatecapture.png"),tr("Coordinate Capture"), this);
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinate_capture.png"),tr("Coordinate Capture"), this);
// Set the what's this text
mQActionPointer->setWhatsThis(tr("Click on the map to view coordinates and capture to clipboard."));
// Connect the action to the run
Expand All @@ -92,18 +92,25 @@ void CoordinateCapture::initGui()

// create a little widget with x and y display to put into our dock widget
QWidget * mypWidget = new QWidget();
QLayout * mypLayout = new QVBoxLayout();
QGridLayout *mypLayout = new QGridLayout ( mypWidget );
mypLayout->setColumnMinimumWidth( 0, 36 );
mypWidget->setLayout(mypLayout);

QLabel * mypGeoLabel = new QLabel(mypWidget);
mypGeoLabel->setPixmap(QPixmap(":/coordinatecapture/geographic.png"));
QLabel * mypCRSLabel = new QLabel(mypWidget);
mypCRSLabel->setPixmap(QPixmap(":/coordinatecapture/transformed.png"));
mpXEdit = new QLineEdit(mypWidget);
mpYEdit = new QLineEdit(mypWidget);
QPushButton * mypCopyButton = new QPushButton(mypWidget);
mypCopyButton->setText(tr("Copy to clipboard"));
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));

mypLayout->addWidget(mpXEdit);
mypLayout->addWidget(mpYEdit);
mypLayout->addWidget(mypCopyButton);
mypLayout->addWidget(mypGeoLabel, 0,0);
mypLayout->addWidget(mpXEdit, 0,1);
mypLayout->addWidget(mypCRSLabel, 1,0);
mypLayout->addWidget(mpYEdit, 1,1);
mypLayout->addWidget(mypCopyButton, 2,1);


//create the dock widget
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/coordinate_capture/coordinatecapture.qrc
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/coordinatecapture/" >
<file>coordinatecapture.png</file>
<file>coordinate_capture.png</file>
<file>geographic.png</file>
<file>transformed.png</file>
</qresource>
</RCC>
33 changes: 23 additions & 10 deletions src/plugins/coordinate_capture/coordinatecapturemaptool.cpp
Expand Up @@ -31,12 +31,12 @@ CoordinateCaptureMapTool::CoordinateCaptureMapTool(QgsMapCanvas* thepCanvas)
: QgsMapTool(thepCanvas)
{
// set cursor
QPixmap myIdentifyCursor = QPixmap((const char **) capture_point_cursor);
mCursor = QCursor(myIdentifyCursor, 1, 1);
QPixmap myCursor = QPixmap((const char **) capture_point_cursor);
mCursor = QCursor(myCursor, 8, 8); //8,8 is the point in the cursor where clicks register
mpMapCanvas = thepCanvas;
mpRubberBand = new QgsRubberBand(mpMapCanvas,false); //false - not a polygon
mpRubberBand = new QgsRubberBand(mpMapCanvas,true); //true - its a polygon
mpRubberBand->setColor(Qt::red);
mpRubberBand->setWidth(3);
mpRubberBand->setWidth(1);
}

CoordinateCaptureMapTool::~CoordinateCaptureMapTool()
Expand All @@ -60,14 +60,27 @@ void CoordinateCaptureMapTool::canvasReleaseEvent(QMouseEvent * thepEvent)
return;
}

QgsPoint myPoint =
QgsPoint myOriginalPoint =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
emit pointCaptured(myPoint);
mpRubberBand->reset(false);
emit pointCaptured(myOriginalPoint);

//make a little box for display

QgsPoint myPoint1 =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() - 1, thepEvent->y()-1);
QgsPoint myPoint2 =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() + 1, thepEvent->y()-1);
QgsPoint myPoint3 =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() + 1, thepEvent->y() + 1);
QgsPoint myPoint4 =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() - 1, thepEvent->y() + 1);

mpRubberBand->reset(true);
// convert screen coordinates to map coordinates
mpRubberBand->addPoint(myPoint,false); //true - update canvas
mpRubberBand->addPoint(myPoint,false); //true - update canvas
mpRubberBand->addPoint(myPoint,false); //true - update canvas
mpRubberBand->addPoint(myPoint1,false); //true - update canvas
mpRubberBand->addPoint(myPoint2,false); //true - update canvas
mpRubberBand->addPoint(myPoint3,false); //true - update canvas
mpRubberBand->addPoint(myPoint4,true); //true - update canvas
mpRubberBand->show();
}

Expand Down
Binary file added src/plugins/coordinate_capture/geographic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions src/plugins/coordinate_capture/geographic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/plugins/coordinate_capture/transformed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5befedc

Please sign in to comment.