Skip to content

Commit

Permalink
Support for icon themes for the core plugins
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10403 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty committed Mar 22, 2009
1 parent 615e97d commit 86be11e
Show file tree
Hide file tree
Showing 47 changed files with 516 additions and 1,399 deletions.
53 changes: 42 additions & 11 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
coordinatecapture.cpp coordinatecapture.cpp
Capture mouse coordinates in different CRS // Capture mouse coordinates in different CRS
------------------- -------------------
begin : [PluginDate] begin : [PluginDate]
copyright : [(C) Your Name and Date] copyright : [(C) Your Name and Date]
Expand All @@ -22,6 +22,7 @@


#include <qgisinterface.h> #include <qgisinterface.h>
#include <qgisgui.h> #include <qgisgui.h>
#include "qgsapplication.h"
#include <qgspoint.h> #include <qgspoint.h>
#include <qgsmapcanvas.h> #include <qgsmapcanvas.h>
#include <qgsmaprenderer.h> #include <qgsmaprenderer.h>
Expand All @@ -45,6 +46,7 @@
#include <QClipboard> #include <QClipboard>
#include <QPushButton> #include <QPushButton>
#include <QToolButton> #include <QToolButton>
#include <QFile>


static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $"; static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $";
static const QString sName = QObject::tr( "Coordinate Capture" ); static const QString sName = QObject::tr( "Coordinate Capture" );
Expand Down Expand Up @@ -90,7 +92,7 @@ void CoordinateCapture::initGui()
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 3 : 5; // precision depends on CRS units mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 3 : 5; // precision depends on CRS units


// Create the action for tool // Create the action for tool
mQActionPointer = new QAction( QIcon( ":/coordinatecapture/coordinate_capture.png" ), tr( "Coordinate Capture" ), this ); mQActionPointer = new QAction( QIcon(), tr( "Coordinate Capture" ), this );
// Set the what's this text // Set the what's this text
mQActionPointer->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) ); mQActionPointer->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) );
// Connect the action to the run // Connect the action to the run
Expand All @@ -109,13 +111,11 @@ void CoordinateCapture::initGui()
mypLayout->setColumnMinimumWidth( 0, 36 ); mypLayout->setColumnMinimumWidth( 0, 36 );
mypWidget->setLayout( mypLayout ); mypWidget->setLayout( mypLayout );


QToolButton * mypUserCrsToolButton = new QToolButton( mypWidget ); mypUserCrsToolButton = new QToolButton( mypWidget );
mypUserCrsToolButton->setIcon( QIcon( ":/coordinatecapture/geographic.png" ) );
mypUserCrsToolButton->setToolTip( tr( "Click to select the CRS to use for coordinate display" ) ); mypUserCrsToolButton->setToolTip( tr( "Click to select the CRS to use for coordinate display" ) );
connect( mypUserCrsToolButton, SIGNAL( clicked() ), this, SLOT( setCRS() ) ); connect( mypUserCrsToolButton, SIGNAL( clicked() ), this, SLOT( setCRS() ) );


QLabel * mypCRSLabel = new QLabel( mypWidget ); mypCRSLabel = new QLabel( mypWidget );
mypCRSLabel->setPixmap( QPixmap( ":/coordinatecapture/transformed.png" ) );
mypCRSLabel->setGeometry( mypUserCrsToolButton->geometry() ); mypCRSLabel->setGeometry( mypUserCrsToolButton->geometry() );


mpUserCrsEdit = new QLineEdit( mypWidget ); mpUserCrsEdit = new QLineEdit( mypWidget );
Expand All @@ -134,16 +134,18 @@ void CoordinateCapture::initGui()
mpTrackMouseButton->setCheckable( true ); mpTrackMouseButton->setCheckable( true );
mpTrackMouseButton->setToolTip( tr( "Click to enable mouse tracking. Click the canvas to stop" ) ); mpTrackMouseButton->setToolTip( tr( "Click to enable mouse tracking. Click the canvas to stop" ) );
mpTrackMouseButton->setChecked( false ); mpTrackMouseButton->setChecked( false );
mpTrackMouseButton->setIcon( QIcon( ":/coordinatecapture/tracking.png" ) );


// Create the action for tool // Create the action for tool
mpCaptureButton = new QPushButton( mypWidget ); mpCaptureButton = new QPushButton( mypWidget );
mpCaptureButton->setText( tr( "Start capture" ) ); mpCaptureButton->setText( tr( "Start capture" ) );
mpCaptureButton->setToolTip( tr( "Click to enable coordinate capture" ) ); mpCaptureButton->setToolTip( tr( "Click to enable coordinate capture" ) );
mpCaptureButton->setIcon( QIcon( ":/coordinatecapture/coordinatecapture/coordinate_capture.png" )); mpCaptureButton->setIcon( QIcon( ":/coordinate_capture/coordinate_capture.png" ));
mpCaptureButton->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) ); mpCaptureButton->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) );
connect( mpCaptureButton, SIGNAL( clicked() ), this, SLOT( run() ) ); connect( mpCaptureButton, SIGNAL( clicked() ), this, SLOT( run() ) );


// Set the icons
setCurrentTheme( "" );

mypLayout->addWidget( mypUserCrsToolButton, 0, 0 ); mypLayout->addWidget( mypUserCrsToolButton, 0, 0 );
mypLayout->addWidget( mpUserCrsEdit, 0, 1 ); mypLayout->addWidget( mpUserCrsEdit, 0, 1 );
mypLayout->addWidget( mypCRSLabel, 1, 0 ); mypLayout->addWidget( mypCRSLabel, 1, 0 );
Expand Down Expand Up @@ -259,12 +261,41 @@ void CoordinateCapture::unload()
delete mQActionPointer; delete mQActionPointer;
} }


void CoordinateCapture::setCurrentTheme ( QString theThemeName ) // Set icons to the current theme
void CoordinateCapture::setCurrentTheme( QString theThemeName )
{
mQActionPointer->setIcon( QIcon( getIconPath( "coordinate_capture.png" ) ) );
mpTrackMouseButton->setIcon( QIcon( getIconPath( "tracking.png" ) ) );
mpCaptureButton->setIcon( QIcon( getIconPath( "coordinate_capture.png" ) ) );
mypUserCrsToolButton->setIcon( QIcon( getIconPath( "geographic.png" ) ) );
mypCRSLabel->setPixmap( QPixmap( getIconPath( "transformed.png" ) ) );
}

// Get path to the best available icon file
QString CoordinateCapture::getIconPath( const QString theName )
{ {
qDebug (" Current theme changed \n\n\n\n\n" ); QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/coordinate_capture/" + theName;
mQActionPointer->setIcon( QIcon()); QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/coordinate_capture/" + theName;
QString myQrcPath = ":/coordinate_capture/" + theName;
if ( QFile::exists( myCurThemePath ) )
{
return myCurThemePath;
}
else if ( QFile::exists( myDefThemePath ) )
{
return myDefThemePath;
}
else if ( QFile::exists( myQrcPath ) )
{
return myQrcPath;
}
else
{
return "";
}
} }



////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// //
// //
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/coordinate_capture/coordinatecapture.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class QToolButton;
class QPushButton; class QPushButton;
class QDockWidget; class QDockWidget;
class QLineEdit; class QLineEdit;
class QIcon;
class QLabel;


class QgisInterface; class QgisInterface;
class QgsPoint; class QgsPoint;
Expand Down Expand Up @@ -120,10 +122,16 @@ class CoordinateCapture: public QObject, public QgisPlugin
//!Our custom map tool to capture clicks //!Our custom map tool to capture clicks
CoordinateCaptureMapTool * mpMapTool; CoordinateCaptureMapTool * mpMapTool;


//!A toolbutton to keep track whether mouse tracking is enabled //!A two buttons to track and capture coordinates
QToolButton * mpTrackMouseButton; QToolButton * mpTrackMouseButton;
QPushButton * mpCaptureButton; QPushButton * mpCaptureButton;


//! A toolbutton to select crs to display the coordinates
QToolButton * mypUserCrsToolButton;

//! A label for coordinates in the project crs
QLabel * mypCRSLabel;

//! transform object //! transform object
QgsCoordinateTransform mTransform; QgsCoordinateTransform mTransform;


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


//! Get the path to the icon from the best available theme
QString getIconPath( const QString theName );

//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// MANDATORY PLUGIN PROPERTY DECLARATIONS ..... // MANDATORY PLUGIN PROPERTY DECLARATIONS .....
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/coordinate_capture/coordinatecapture.qrc
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/coordinatecapture/" > <qresource prefix="/coordinate_capture/" >
<file>coordinate_capture.png</file> <file>coordinate_capture.png</file>
<file>geographic.png</file> <file>geographic.png</file>
<file>transformed.png</file> <file>transformed.png</file>
Expand Down
34 changes: 30 additions & 4 deletions src/plugins/copyright_label/plugin.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ email : tim@linfiniti.com


#include "qgisinterface.h" #include "qgisinterface.h"
#include "qgisgui.h" #include "qgisgui.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
#include "qgsmaplayer.h" #include "qgsmaplayer.h"
#include "qgsproject.h" #include "qgsproject.h"
Expand All @@ -35,6 +36,7 @@ email : tim@linfiniti.com
#include <QDate> #include <QDate>
#include <QTextDocument> #include <QTextDocument>
#include <QMatrix> #include <QMatrix>
#include <QFile>


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


// this is called when the icon theme is changed
connect( qGisInterface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );

// Add the icon to the toolbar // Add the icon to the toolbar
qGisInterface->addToolBarIcon( myQActionPointer ); qGisInterface->addToolBarIcon( myQActionPointer );
qGisInterface->addPluginToMenu( tr( "&Decorations" ), myQActionPointer ); qGisInterface->addPluginToMenu( tr( "&Decorations" ), myQActionPointer );
Expand Down Expand Up @@ -251,9 +257,29 @@ void QgsCopyrightLabelPlugin::setEnable( bool theBool )
refreshCanvas(); refreshCanvas();
} }



//! Set icons to the current theme

void QgsCopyrightLabelPlugin::setCurrentTheme( QString theThemeName )

{
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/copyright_label.png";
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/copyright_label.png";
QString myQrcPath = ":/copyright_label.png";
if ( QFile::exists( myCurThemePath ) )
{
myQActionPointer->setIcon( QIcon( myCurThemePath ) );
}
else if ( QFile::exists( myDefThemePath ) )
{
myQActionPointer->setIcon( QIcon( myDefThemePath ) );
}
else if ( QFile::exists( myQrcPath ) )
{
myQActionPointer->setIcon( QIcon( myQrcPath ) );
}
else
{
myQActionPointer->setIcon( QIcon() );
}
}


/** /**
* Required extern functions needed for every plugin * Required extern functions needed for every plugin
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/copyright_label/plugin.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
void setPlacement( int ); void setPlacement( int );
//! set copyright label enabled //! set copyright label enabled
void setEnable( bool ); void setEnable( bool );
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme ( QString theThemeName );






Expand Down
33 changes: 31 additions & 2 deletions src/plugins/delimited_text/qgsdelimitedtextplugin.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@


#include "qgisinterface.h" #include "qgisinterface.h"
#include "qgisgui.h" #include "qgisgui.h"
#include "qgsapplication.h"
#include "qgsmaplayer.h" #include "qgsmaplayer.h"
#include "qgsdelimitedtextplugin.h" #include "qgsdelimitedtextplugin.h"




#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QFile>


//non qt includes //non qt includes
#include <iostream> #include <iostream>
Expand Down Expand Up @@ -96,8 +98,8 @@ void QgsDelimitedTextPlugin::help()
void QgsDelimitedTextPlugin::initGui() void QgsDelimitedTextPlugin::initGui()
{ {
// Create the action for tool // Create the action for tool
myQActionPointer = new QAction( QIcon( ":/delimited_text.png" ), tr( "&Add Delimited Text Layer" ), this ); myQActionPointer = new QAction( QIcon(), tr( "&Add Delimited Text Layer" ), this );

setCurrentTheme( "" );
myQActionPointer->setWhatsThis( tr( "Add a delimited text file as a map layer. " myQActionPointer->setWhatsThis( tr( "Add a delimited text file as a map layer. "
"The file must have a header row containing the field names. " "The file must have a header row containing the field names. "
"X and Y fields are required and must contain coordinates in decimal units." ) ); "X and Y fields are required and must contain coordinates in decimal units." ) );
Expand All @@ -106,6 +108,8 @@ void QgsDelimitedTextPlugin::initGui()
// Add the icon to the toolbar // Add the icon to the toolbar
qGisInterface->addToolBarIcon( myQActionPointer ); qGisInterface->addToolBarIcon( myQActionPointer );
qGisInterface->addPluginToMenu( tr( "&Delimited text" ), myQActionPointer ); qGisInterface->addPluginToMenu( tr( "&Delimited text" ), myQActionPointer );
// this is called when the icon theme is changed
connect( qGisInterface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );


} }


Expand Down Expand Up @@ -141,6 +145,31 @@ void QgsDelimitedTextPlugin::unload()
qGisInterface->removeToolBarIcon( myQActionPointer ); qGisInterface->removeToolBarIcon( myQActionPointer );
delete myQActionPointer; delete myQActionPointer;
} }

//! Set icons to the current theme
void QgsDelimitedTextPlugin::setCurrentTheme( QString theThemeName )
{
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/delimited_text.png";
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/delimited_text.png";
QString myQrcPath = ":/delimited_text.png";
if ( QFile::exists( myCurThemePath ) )
{
myQActionPointer->setIcon( QIcon( myCurThemePath ) );
}
else if ( QFile::exists( myDefThemePath ) )
{
myQActionPointer->setIcon( QIcon( myDefThemePath ) );
}
else if ( QFile::exists( myQrcPath ) )
{
myQActionPointer->setIcon( QIcon( myQrcPath ) );
}
else
{
myQActionPointer->setIcon( QIcon() );
}
}

/** /**
* Required extern functions needed for every plugin * Required extern functions needed for every plugin
* These functions can be called prior to creating an instance * These functions can be called prior to creating an instance
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/delimited_text/qgsdelimitedtextplugin.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class QgsDelimitedTextPlugin: public QObject, public QgisPlugin, private Ui::Qgs
void unload(); void unload();
//! show the help document //! show the help document
void help(); void help();
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme ( QString theThemeName );
private: private:




Expand Down
34 changes: 33 additions & 1 deletion src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


#include <qgisinterface.h> #include <qgisinterface.h>
#include <qgisgui.h> #include <qgisgui.h>
#include <qgsapplication.h>
#include <qgsvectorlayer.h> #include <qgsvectorlayer.h>


#include "dxf2shpconverter.h" #include "dxf2shpconverter.h"
Expand All @@ -30,6 +31,7 @@
// //


#include <QAction> #include <QAction>
#include <QFile>
#include <QToolBar> #include <QToolBar>


static const char *const sIdent = static const char *const sIdent =
Expand Down Expand Up @@ -66,7 +68,10 @@ dxf2shpConverter::~dxf2shpConverter()
void dxf2shpConverter::initGui() void dxf2shpConverter::initGui()
{ {
// Create the action for tool // Create the action for tool
mQActionPointer = new QAction( QIcon( ":/dxf2shpconverter/dxf2shp_converter.png" ), "Dxf2Shp Converter", this ); mQActionPointer = new QAction( QIcon(), "Dxf2Shp Converter", this );

// Set the icon
setCurrentTheme( "" );


// Set the what's this text // Set the what's this text
mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) ); mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) );
Expand All @@ -77,6 +82,9 @@ void dxf2shpConverter::initGui()
// Add the icon to the toolbar // Add the icon to the toolbar
mQGisIface->addToolBarIcon( mQActionPointer ); mQGisIface->addToolBarIcon( mQActionPointer );
mQGisIface->addPluginToMenu( tr( "&Dxf2Shp" ), mQActionPointer ); mQGisIface->addPluginToMenu( tr( "&Dxf2Shp" ), mQActionPointer );

// this is called when the icon theme is changed
connect( mQGisIface, SIGNAL( currentThemeChanged ( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
} }


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


//! Set icons to the current theme
void dxf2shpConverter::setCurrentTheme( QString theThemeName )
{
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/dxf2shp_converter.png";
QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/dxf2shp_converter.png";
QString myQrcPath = ":/dxf2shp_converter.png";
if ( QFile::exists( myCurThemePath ) )
{
mQActionPointer->setIcon( QIcon( myCurThemePath ) );
}
else if ( QFile::exists( myDefThemePath ) )
{
mQActionPointer->setIcon( QIcon( myDefThemePath ) );
}
else if ( QFile::exists( myQrcPath ) )
{
mQActionPointer->setIcon( QIcon( myQrcPath ) );
}
else
{
mQActionPointer->setIcon( QIcon() );
}
}

////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// //
// //
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/dxf2shp_converter/dxf2shpconverter.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class dxf2shpConverter: public QObject, public QgisPlugin
void unload(); void unload();
//! show the help document //! show the help document
void help(); void help();
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme ( QString theThemeName );


void addMyLayer( QString, QString ); void addMyLayer( QString, QString );


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dxf2shp_converter/dxf2shpconverter.qrc
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/dxf2shpconverter/" > <qresource prefix="/" >
<file>dxf2shp_converter.png</file> <file>dxf2shp_converter.png</file>
</qresource> </qresource>
</RCC> </RCC>
Loading

0 comments on commit 86be11e

Please sign in to comment.