4343#include < QLineEdit>
4444#include < QClipboard>
4545#include < QPushButton>
46+ #include < QToolButton>
4647
4748static const char * const sIdent = " $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $" ;
4849static const QString sName = QObject::tr(" Coordinate Capture" );
@@ -91,7 +92,8 @@ void CoordinateCapture::initGui()
9192
9293 // create our map tool
9394 mpMapTool = new CoordinateCaptureMapTool (mQGisIface ->getMapCanvas ());
94- connect (mpMapTool, SIGNAL (pointCaptured (QgsPoint)), this , SLOT (update (QgsPoint)));
95+ connect (mpMapTool, SIGNAL (mouseMoved (QgsPoint)), this , SLOT (mouseMoved (QgsPoint)));
96+ connect (mpMapTool, SIGNAL (mouseClicked (QgsPoint)), this , SLOT (mouseClicked (QgsPoint)));
9597
9698
9799 // create a little widget with x and y display to put into our dock widget
@@ -102,22 +104,33 @@ void CoordinateCapture::initGui()
102104
103105 QLabel * mypGeoLabel = new QLabel (mypWidget);
104106 mypGeoLabel->setPixmap (QPixmap (" :/coordinatecapture/geographic.png" ));
105- mypGeoLabel-> setToolTip ( tr ( " Coordinate in lat/long WGS84 " ));
107+
106108 QLabel * mypCRSLabel = new QLabel (mypWidget);
107109 mypCRSLabel->setPixmap (QPixmap (" :/coordinatecapture/transformed.png" ));
108- mypGeoLabel-> setToolTip ( tr ( " Coordinate in map canvas coordinate reference system " ));
110+
109111 mpGeoEdit = new QLineEdit (mypWidget);
110112 mpGeoEdit->setReadOnly (true );
113+ mpGeoEdit->setToolTip (tr (" Coordinate in lat/long WGS84" ));
114+
111115 mpTransformedEdit = new QLineEdit (mypWidget);
112116 mpTransformedEdit->setReadOnly (true );
117+ mpTransformedEdit->setToolTip (tr (" Coordinate in map canvas coordinate reference system" ));
118+
113119 QPushButton * mypCopyButton = new QPushButton (mypWidget);
114120 mypCopyButton->setText (tr (" Copy to clipboard" ));
115121 connect (mypCopyButton, SIGNAL (clicked ()), this , SLOT (copy ()));
116122
123+ mpTrackMouseButton = new QToolButton (mypWidget);
124+ mpTrackMouseButton->setCheckable (true );
125+ mpTrackMouseButton->setToolTip (tr (" Click to enable mouse tracking. Click the canvas to stop" ));
126+ mpTrackMouseButton->setChecked (false );
127+ mpTrackMouseButton->setIcon (QIcon (" :/coordinatecapture/tracking.png" ));
128+
117129 mypLayout->addWidget (mypGeoLabel, 0 ,0 );
118130 mypLayout->addWidget (mpGeoEdit, 0 ,1 );
119131 mypLayout->addWidget (mypCRSLabel, 1 ,0 );
120132 mypLayout->addWidget (mpTransformedEdit, 1 ,1 );
133+ mypLayout->addWidget (mpTrackMouseButton, 2 ,0 );
121134 mypLayout->addWidget (mypCopyButton, 2 ,1 );
122135
123136
@@ -130,14 +143,29 @@ void CoordinateCapture::initGui()
130143 // now add our custom widget to the dock - ownership of the widget is passed to the dock
131144 mpDockWidget->setWidget (mypWidget);
132145
133-
134146}
147+
135148// method defined in interface
136149void CoordinateCapture::help ()
137150{
138151 // implement me!
139152}
140-
153+ void CoordinateCapture::mouseClicked (QgsPoint thePoint)
154+ {
155+ // clicking on the canvas will update the widgets and then disable
156+ // tracking so the user can copy the click point coords
157+ mpTrackMouseButton->setChecked (false );
158+ update (thePoint);
159+ }
160+ void CoordinateCapture::mouseMoved (QgsPoint thePoint)
161+ {
162+ // mouse movements will only update the widgets if the
163+ // tracking button is checked
164+ if (mpTrackMouseButton->isChecked ())
165+ {
166+ update (thePoint);
167+ }
168+ }
141169void CoordinateCapture::update (QgsPoint thePoint)
142170{
143171 // this is the coordinate resolved back to lat / lon
0 commit comments