Skip to content

Commit 86be11e

Browse files
author
borysiasty
committed
Support for icon themes for the core plugins
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10403 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 615e97d commit 86be11e

47 files changed

Lines changed: 516 additions & 1399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/plugins/coordinate_capture/coordinatecapture.cpp‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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]
@@ -22,6 +22,7 @@
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>
@@ -45,6 +46,7 @@
4546
#include <QClipboard>
4647
#include <QPushButton>
4748
#include <QToolButton>
49+
#include <QFile>
4850

4951
static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $";
5052
static 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
//

‎src/plugins/coordinate_capture/coordinatecapture.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class QToolButton;
5353
class QPushButton;
5454
class QDockWidget;
5555
class QLineEdit;
56+
class QIcon;
57+
class QLabel;
5658

5759
class QgisInterface;
5860
class QgsPoint;
@@ -120,10 +122,16 @@ class CoordinateCapture: public QObject, public QgisPlugin
120122
//!Our custom map tool to capture clicks
121123
CoordinateCaptureMapTool * mpMapTool;
122124

123-
//!A toolbutton to keep track whether mouse tracking is enabled
125+
//!A two buttons to track and capture coordinates
124126
QToolButton * mpTrackMouseButton;
125127
QPushButton * mpCaptureButton;
126128

129+
//! A toolbutton to select crs to display the coordinates
130+
QToolButton * mypUserCrsToolButton;
131+
132+
//! A label for coordinates in the project crs
133+
QLabel * mypCRSLabel;
134+
127135
//! transform object
128136
QgsCoordinateTransform mTransform;
129137

@@ -136,6 +144,9 @@ class CoordinateCapture: public QObject, public QgisPlugin
136144
//! user coordinate display precision
137145
int mUserCrsDisplayPrecision;
138146

147+
//! Get the path to the icon from the best available theme
148+
QString getIconPath( const QString theName );
149+
139150
////////////////////////////////////////////////////////////////////
140151
//
141152
// MANDATORY PLUGIN PROPERTY DECLARATIONS .....

‎src/plugins/coordinate_capture/coordinatecapture.qrc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/coordinatecapture/" >
2+
<qresource prefix="/coordinate_capture/" >
33
<file>coordinate_capture.png</file>
44
<file>geographic.png</file>
55
<file>transformed.png</file>

‎src/plugins/copyright_label/plugin.cpp‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ email : tim@linfiniti.com
2424

2525
#include "qgisinterface.h"
2626
#include "qgisgui.h"
27+
#include "qgsapplication.h"
2728
#include "qgsmapcanvas.h"
2829
#include "qgsmaplayer.h"
2930
#include "qgsproject.h"
@@ -35,6 +36,7 @@ email : tim@linfiniti.com
3536
#include <QDate>
3637
#include <QTextDocument>
3738
#include <QMatrix>
39+
#include <QFile>
3840

3941
//non qt includes
4042
#include <cmath>
@@ -74,7 +76,8 @@ QgsCopyrightLabelPlugin::~QgsCopyrightLabelPlugin()
7476
void QgsCopyrightLabelPlugin::initGui()
7577
{
7678
// Create the action for tool
77-
myQActionPointer = new QAction( QIcon( ":/copyright_label.png" ), tr( "&Copyright Label" ), this );
79+
myQActionPointer = new QAction( QIcon(), tr( "&Copyright Label" ), this );
80+
setCurrentTheme( "" );
7881
myQActionPointer->setWhatsThis( tr( "Creates a copyright label that is displayed on the map canvas." ) );
7982
// Connect the action to the run
8083
connect( myQActionPointer, SIGNAL( activated() ), this, SLOT( run() ) );
@@ -83,6 +86,9 @@ void QgsCopyrightLabelPlugin::initGui()
8386
//this resets this plugin up if a project is loaded
8487
connect( qGisInterface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
8588

89+
// this is called when the icon theme is changed
90+
connect( qGisInterface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
91+
8692
// Add the icon to the toolbar
8793
qGisInterface->addToolBarIcon( myQActionPointer );
8894
qGisInterface->addPluginToMenu( tr( "&Decorations" ), myQActionPointer );
@@ -251,9 +257,29 @@ void QgsCopyrightLabelPlugin::setEnable( bool theBool )
251257
refreshCanvas();
252258
}
253259

254-
255-
256-
260+
//! Set icons to the current theme
261+
void QgsCopyrightLabelPlugin::setCurrentTheme( QString theThemeName )
262+
{
263+
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/copyright_label.png";
264+
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/copyright_label.png";
265+
QString myQrcPath = ":/copyright_label.png";
266+
if ( QFile::exists( myCurThemePath ) )
267+
{
268+
myQActionPointer->setIcon( QIcon( myCurThemePath ) );
269+
}
270+
else if ( QFile::exists( myDefThemePath ) )
271+
{
272+
myQActionPointer->setIcon( QIcon( myDefThemePath ) );
273+
}
274+
else if ( QFile::exists( myQrcPath ) )
275+
{
276+
myQActionPointer->setIcon( QIcon( myQrcPath ) );
277+
}
278+
else
279+
{
280+
myQActionPointer->setIcon( QIcon() );
281+
}
282+
}
257283

258284
/**
259285
* Required extern functions needed for every plugin

‎src/plugins/copyright_label/plugin.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
7070
void setPlacement( int );
7171
//! set copyright label enabled
7272
void setEnable( bool );
73+
//! update the plugins theme when the app tells us its theme is changed
74+
void setCurrentTheme ( QString theThemeName );
7375

7476

7577

‎src/plugins/delimited_text/qgsdelimitedtextplugin.cpp‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424

2525
#include "qgisinterface.h"
2626
#include "qgisgui.h"
27+
#include "qgsapplication.h"
2728
#include "qgsmaplayer.h"
2829
#include "qgsdelimitedtextplugin.h"
2930

3031

3132
#include <QMenu>
3233
#include <QAction>
34+
#include <QFile>
3335

3436
//non qt includes
3537
#include <iostream>
@@ -96,8 +98,8 @@ void QgsDelimitedTextPlugin::help()
9698
void QgsDelimitedTextPlugin::initGui()
9799
{
98100
// Create the action for tool
99-
myQActionPointer = new QAction( QIcon( ":/delimited_text.png" ), tr( "&Add Delimited Text Layer" ), this );
100-
101+
myQActionPointer = new QAction( QIcon(), tr( "&Add Delimited Text Layer" ), this );
102+
setCurrentTheme( "" );
101103
myQActionPointer->setWhatsThis( tr( "Add a delimited text file as a map layer. "
102104
"The file must have a header row containing the field names. "
103105
"X and Y fields are required and must contain coordinates in decimal units." ) );
@@ -106,6 +108,8 @@ void QgsDelimitedTextPlugin::initGui()
106108
// Add the icon to the toolbar
107109
qGisInterface->addToolBarIcon( myQActionPointer );
108110
qGisInterface->addPluginToMenu( tr( "&Delimited text" ), myQActionPointer );
111+
// this is called when the icon theme is changed
112+
connect( qGisInterface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
109113

110114
}
111115

@@ -141,6 +145,31 @@ void QgsDelimitedTextPlugin::unload()
141145
qGisInterface->removeToolBarIcon( myQActionPointer );
142146
delete myQActionPointer;
143147
}
148+
149+
//! Set icons to the current theme
150+
void QgsDelimitedTextPlugin::setCurrentTheme( QString theThemeName )
151+
{
152+
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/delimited_text.png";
153+
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/delimited_text.png";
154+
QString myQrcPath = ":/delimited_text.png";
155+
if ( QFile::exists( myCurThemePath ) )
156+
{
157+
myQActionPointer->setIcon( QIcon( myCurThemePath ) );
158+
}
159+
else if ( QFile::exists( myDefThemePath ) )
160+
{
161+
myQActionPointer->setIcon( QIcon( myDefThemePath ) );
162+
}
163+
else if ( QFile::exists( myQrcPath ) )
164+
{
165+
myQActionPointer->setIcon( QIcon( myQrcPath ) );
166+
}
167+
else
168+
{
169+
myQActionPointer->setIcon( QIcon() );
170+
}
171+
}
172+
144173
/**
145174
* Required extern functions needed for every plugin
146175
* These functions can be called prior to creating an instance

‎src/plugins/delimited_text/qgsdelimitedtextplugin.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class QgsDelimitedTextPlugin: public QObject, public QgisPlugin, private Ui::Qgs
6868
void unload();
6969
//! show the help document
7070
void help();
71+
//! update the plugins theme when the app tells us its theme is changed
72+
void setCurrentTheme ( QString theThemeName );
7173
private:
7274

7375

‎src/plugins/dxf2shp_converter/dxf2shpconverter.cpp‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <qgisinterface.h>
2222
#include <qgisgui.h>
23+
#include <qgsapplication.h>
2324
#include <qgsvectorlayer.h>
2425

2526
#include "dxf2shpconverter.h"
@@ -30,6 +31,7 @@
3031
//
3132

3233
#include <QAction>
34+
#include <QFile>
3335
#include <QToolBar>
3436

3537
static const char *const sIdent =
@@ -66,7 +68,10 @@ dxf2shpConverter::~dxf2shpConverter()
6668
void dxf2shpConverter::initGui()
6769
{
6870
// Create the action for tool
69-
mQActionPointer = new QAction( QIcon( ":/dxf2shpconverter/dxf2shp_converter.png" ), "Dxf2Shp Converter", this );
71+
mQActionPointer = new QAction( QIcon(), "Dxf2Shp Converter", this );
72+
73+
// Set the icon
74+
setCurrentTheme( "" );
7075

7176
// Set the what's this text
7277
mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) );
@@ -77,6 +82,9 @@ void dxf2shpConverter::initGui()
7782
// Add the icon to the toolbar
7883
mQGisIface->addToolBarIcon( mQActionPointer );
7984
mQGisIface->addPluginToMenu( tr( "&Dxf2Shp" ), mQActionPointer );
85+
86+
// this is called when the icon theme is changed
87+
connect( mQGisIface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
8088
}
8189

8290
//method defined in interface
@@ -115,6 +123,30 @@ void dxf2shpConverter::addMyLayer( QString myfname, QString mytitle )
115123
mQGisIface->addVectorLayer( myfname, mytitle, "ogr" );
116124
}
117125

126+
//! Set icons to the current theme
127+
void dxf2shpConverter::setCurrentTheme( QString theThemeName )
128+
{
129+
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/dxf2shp_converter.png";
130+
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/dxf2shp_converter.png";
131+
QString myQrcPath = ":/dxf2shp_converter.png";
132+
if ( QFile::exists( myCurThemePath ) )
133+
{
134+
mQActionPointer->setIcon( QIcon( myCurThemePath ) );
135+
}
136+
else if ( QFile::exists( myDefThemePath ) )
137+
{
138+
mQActionPointer->setIcon( QIcon( myDefThemePath ) );
139+
}
140+
else if ( QFile::exists( myQrcPath ) )
141+
{
142+
mQActionPointer->setIcon( QIcon( myQrcPath ) );
143+
}
144+
else
145+
{
146+
mQActionPointer->setIcon( QIcon() );
147+
}
148+
}
149+
118150
//////////////////////////////////////////////////////////////////////////
119151
//
120152
//

‎src/plugins/dxf2shp_converter/dxf2shpconverter.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class dxf2shpConverter: public QObject, public QgisPlugin
6161
void unload();
6262
//! show the help document
6363
void help();
64+
//! update the plugins theme when the app tells us its theme is changed
65+
void setCurrentTheme ( QString theThemeName );
6466

6567
void addMyLayer( QString, QString );
6668

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/dxf2shpconverter/" >
2+
<qresource prefix="/" >
33
<file>dxf2shp_converter.png</file>
44
</qresource>
55
</RCC>

0 commit comments

Comments
 (0)