11/* **************************************************************************
22 coordinatecapture.cpp
3- Capture mouse coordinates in different CRS
3+ // Capture mouse coordinates in different CRS
44 -------------------
55 begin : [PluginDate]
66 copyright : [(C) Your Name and Date]
2222
2323#include < qgisinterface.h>
2424#include < qgisgui.h>
25+ #include " qgsapplication.h"
2526#include < qgspoint.h>
2627#include < qgsmapcanvas.h>
2728#include < qgsmaprenderer.h>
4546#include < QClipboard>
4647#include < QPushButton>
4748#include < QToolButton>
49+ #include < QFile>
4850
4951static const char * const sIdent = " $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $" ;
5052static const QString sName = QObject::tr( " Coordinate Capture" );
@@ -90,7 +92,7 @@ void CoordinateCapture::initGui()
9092 mUserCrsDisplayPrecision = ( mCrs .mapUnits () == QGis::Degrees ) ? 3 : 5 ; // precision depends on CRS units
9193
9294 // 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 );
9496 // Set the what's this text
9597 mQActionPointer ->setWhatsThis ( tr ( " Click on the map to view coordinates and capture to clipboard." ) );
9698 // Connect the action to the run
@@ -109,13 +111,11 @@ void CoordinateCapture::initGui()
109111 mypLayout->setColumnMinimumWidth ( 0 , 36 );
110112 mypWidget->setLayout ( mypLayout );
111113
112- QToolButton * mypUserCrsToolButton = new QToolButton ( mypWidget );
113- mypUserCrsToolButton->setIcon ( QIcon ( " :/coordinatecapture/geographic.png" ) );
114+ mypUserCrsToolButton = new QToolButton ( mypWidget );
114115 mypUserCrsToolButton->setToolTip ( tr ( " Click to select the CRS to use for coordinate display" ) );
115116 connect ( mypUserCrsToolButton, SIGNAL ( clicked () ), this , SLOT ( setCRS () ) );
116117
117- QLabel * mypCRSLabel = new QLabel ( mypWidget );
118- mypCRSLabel->setPixmap ( QPixmap ( " :/coordinatecapture/transformed.png" ) );
118+ mypCRSLabel = new QLabel ( mypWidget );
119119 mypCRSLabel->setGeometry ( mypUserCrsToolButton->geometry () );
120120
121121 mpUserCrsEdit = new QLineEdit ( mypWidget );
@@ -134,16 +134,18 @@ void CoordinateCapture::initGui()
134134 mpTrackMouseButton->setCheckable ( true );
135135 mpTrackMouseButton->setToolTip ( tr ( " Click to enable mouse tracking. Click the canvas to stop" ) );
136136 mpTrackMouseButton->setChecked ( false );
137- mpTrackMouseButton->setIcon ( QIcon ( " :/coordinatecapture/tracking.png" ) );
138137
139138 // Create the action for tool
140139 mpCaptureButton = new QPushButton ( mypWidget );
141140 mpCaptureButton->setText ( tr ( " Start capture" ) );
142141 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" ));
144143 mpCaptureButton->setWhatsThis ( tr ( " Click on the map to view coordinates and capture to clipboard." ) );
145144 connect ( mpCaptureButton, SIGNAL ( clicked () ), this , SLOT ( run () ) );
146145
146+ // Set the icons
147+ setCurrentTheme ( " " );
148+
147149 mypLayout->addWidget ( mypUserCrsToolButton, 0 , 0 );
148150 mypLayout->addWidget ( mpUserCrsEdit, 0 , 1 );
149151 mypLayout->addWidget ( mypCRSLabel, 1 , 0 );
@@ -259,12 +261,41 @@ void CoordinateCapture::unload()
259261 delete mQActionPointer ;
260262}
261263
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 )
263276{
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+ }
266296}
267297
298+
268299// ////////////////////////////////////////////////////////////////////////
269300//
270301//
0 commit comments