1
1
/* **************************************************************************
2
2
coordinatecapture.cpp
3
- Capture mouse coordinates in different CRS
3
+ // Capture mouse coordinates in different CRS
4
4
-------------------
5
5
begin : [PluginDate]
6
6
copyright : [(C) Your Name and Date]
22
22
23
23
#include < qgisinterface.h>
24
24
#include < qgisgui.h>
25
+ #include " qgsapplication.h"
25
26
#include < qgspoint.h>
26
27
#include < qgsmapcanvas.h>
27
28
#include < qgsmaprenderer.h>
45
46
#include < QClipboard>
46
47
#include < QPushButton>
47
48
#include < QToolButton>
49
+ #include < QFile>
48
50
49
51
static const char * const sIdent = " $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $" ;
50
52
static const QString sName = QObject::tr( " Coordinate Capture" );
@@ -90,7 +92,7 @@ void CoordinateCapture::initGui()
90
92
mUserCrsDisplayPrecision = ( mCrs .mapUnits () == QGis::Degrees ) ? 3 : 5 ; // precision depends on CRS units
91
93
92
94
// Create the action for tool
93
- mQActionPointer = new QAction ( QIcon ( " :/coordinatecapture/coordinate_capture.png " ), tr ( " Coordinate Capture" ), this );
95
+ mQActionPointer = new QAction ( QIcon (), tr ( " Coordinate Capture" ), this );
94
96
// Set the what's this text
95
97
mQActionPointer ->setWhatsThis ( tr ( " Click on the map to view coordinates and capture to clipboard." ) );
96
98
// Connect the action to the run
@@ -109,13 +111,11 @@ void CoordinateCapture::initGui()
109
111
mypLayout->setColumnMinimumWidth ( 0 , 36 );
110
112
mypWidget->setLayout ( mypLayout );
111
113
112
- QToolButton * mypUserCrsToolButton = new QToolButton ( mypWidget );
113
- mypUserCrsToolButton->setIcon ( QIcon ( " :/coordinatecapture/geographic.png" ) );
114
+ mypUserCrsToolButton = new QToolButton ( mypWidget );
114
115
mypUserCrsToolButton->setToolTip ( tr ( " Click to select the CRS to use for coordinate display" ) );
115
116
connect ( mypUserCrsToolButton, SIGNAL ( clicked () ), this , SLOT ( setCRS () ) );
116
117
117
- QLabel * mypCRSLabel = new QLabel ( mypWidget );
118
- mypCRSLabel->setPixmap ( QPixmap ( " :/coordinatecapture/transformed.png" ) );
118
+ mypCRSLabel = new QLabel ( mypWidget );
119
119
mypCRSLabel->setGeometry ( mypUserCrsToolButton->geometry () );
120
120
121
121
mpUserCrsEdit = new QLineEdit ( mypWidget );
@@ -134,16 +134,18 @@ void CoordinateCapture::initGui()
134
134
mpTrackMouseButton->setCheckable ( true );
135
135
mpTrackMouseButton->setToolTip ( tr ( " Click to enable mouse tracking. Click the canvas to stop" ) );
136
136
mpTrackMouseButton->setChecked ( false );
137
- mpTrackMouseButton->setIcon ( QIcon ( " :/coordinatecapture/tracking.png" ) );
138
137
139
138
// Create the action for tool
140
139
mpCaptureButton = new QPushButton ( mypWidget );
141
140
mpCaptureButton->setText ( tr ( " Start capture" ) );
142
141
mpCaptureButton->setToolTip ( tr ( " Click to enable coordinate capture" ) );
143
- mpCaptureButton->setIcon ( QIcon ( " :/coordinatecapture/coordinatecapture /coordinate_capture.png" ));
142
+ mpCaptureButton->setIcon ( QIcon ( " :/coordinate_capture /coordinate_capture.png" ));
144
143
mpCaptureButton->setWhatsThis ( tr ( " Click on the map to view coordinates and capture to clipboard." ) );
145
144
connect ( mpCaptureButton, SIGNAL ( clicked () ), this , SLOT ( run () ) );
146
145
146
+ // Set the icons
147
+ setCurrentTheme ( " " );
148
+
147
149
mypLayout->addWidget ( mypUserCrsToolButton, 0 , 0 );
148
150
mypLayout->addWidget ( mpUserCrsEdit, 0 , 1 );
149
151
mypLayout->addWidget ( mypCRSLabel, 1 , 0 );
@@ -259,12 +261,41 @@ void CoordinateCapture::unload()
259
261
delete mQActionPointer ;
260
262
}
261
263
262
- void CoordinateCapture::setCurrentTheme ( QString theThemeName )
264
+ // Set icons to the current theme
265
+ void CoordinateCapture::setCurrentTheme ( QString theThemeName )
266
+ {
267
+ mQActionPointer ->setIcon ( QIcon ( getIconPath ( " coordinate_capture.png" ) ) );
268
+ mpTrackMouseButton->setIcon ( QIcon ( getIconPath ( " tracking.png" ) ) );
269
+ mpCaptureButton->setIcon ( QIcon ( getIconPath ( " coordinate_capture.png" ) ) );
270
+ mypUserCrsToolButton->setIcon ( QIcon ( getIconPath ( " geographic.png" ) ) );
271
+ mypCRSLabel->setPixmap ( QPixmap ( getIconPath ( " transformed.png" ) ) );
272
+ }
273
+
274
+ // Get path to the best available icon file
275
+ QString CoordinateCapture::getIconPath ( const QString theName )
263
276
{
264
- qDebug (" Current theme changed \n\n\n\n\n " );
265
- mQActionPointer ->setIcon ( QIcon ());
277
+ QString myCurThemePath = QgsApplication::activeThemePath () + " /plugins/coordinate_capture/" + theName;
278
+ QString myDefThemePath = QgsApplication::defaultThemePath () + " /plugins/coordinate_capture/" + theName;
279
+ QString myQrcPath = " :/coordinate_capture/" + theName;
280
+ if ( QFile::exists ( myCurThemePath ) )
281
+ {
282
+ return myCurThemePath;
283
+ }
284
+ else if ( QFile::exists ( myDefThemePath ) )
285
+ {
286
+ return myDefThemePath;
287
+ }
288
+ else if ( QFile::exists ( myQrcPath ) )
289
+ {
290
+ return myQrcPath;
291
+ }
292
+ else
293
+ {
294
+ return " " ;
295
+ }
266
296
}
267
297
298
+
268
299
// ////////////////////////////////////////////////////////////////////////
269
300
//
270
301
//
0 commit comments