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@10403 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty committed Mar 22, 2009
1 parent 3f146e0 commit b8889a9
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
@@ -1,6 +1,6 @@
/***************************************************************************
coordinatecapture.cpp
Capture mouse coordinates in different CRS
// Capture mouse coordinates in different CRS
-------------------
begin : [PluginDate]
copyright : [(C) Your Name and Date]
Expand All @@ -22,6 +22,7 @@

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

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

// 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
mQActionPointer->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) );
// Connect the action to the run
Expand All @@ -109,13 +111,11 @@ void CoordinateCapture::initGui()
mypLayout->setColumnMinimumWidth( 0, 36 );
mypWidget->setLayout( mypLayout );

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

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

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

// Create the action for tool
mpCaptureButton = new QPushButton( mypWidget );
mpCaptureButton->setText( tr( "Start 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." ) );
connect( mpCaptureButton, SIGNAL( clicked() ), this, SLOT( run() ) );

// Set the icons
setCurrentTheme( "" );

mypLayout->addWidget( mypUserCrsToolButton, 0, 0 );
mypLayout->addWidget( mpUserCrsEdit, 0, 1 );
mypLayout->addWidget( mypCRSLabel, 1, 0 );
Expand Down Expand Up @@ -259,12 +261,41 @@ void CoordinateCapture::unload()
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" );
mQActionPointer->setIcon( QIcon());
QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/coordinate_capture/" + theName;
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
Expand Up @@ -53,6 +53,8 @@ class QToolButton;
class QPushButton;
class QDockWidget;
class QLineEdit;
class QIcon;
class QLabel;

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

//!A toolbutton to keep track whether mouse tracking is enabled
//!A two buttons to track and capture coordinates
QToolButton * mpTrackMouseButton;
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
QgsCoordinateTransform mTransform;

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

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

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

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

//non qt includes
#include <cmath>
Expand Down Expand Up @@ -74,7 +76,8 @@ QgsCopyrightLabelPlugin::~QgsCopyrightLabelPlugin()
void QgsCopyrightLabelPlugin::initGui()
{
// 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." ) );
// Connect the action to the 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
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
qGisInterface->addToolBarIcon( myQActionPointer );
qGisInterface->addPluginToMenu( tr( "&Decorations" ), myQActionPointer );
Expand Down Expand Up @@ -251,9 +257,29 @@ void QgsCopyrightLabelPlugin::setEnable( bool theBool )
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
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/copyright_label/plugin.h
Expand Up @@ -70,6 +70,8 @@ class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
void setPlacement( int );
//! set copyright label enabled
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
Expand Up @@ -24,12 +24,14 @@

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


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

//non qt includes
#include <iostream>
Expand Down Expand Up @@ -96,8 +98,8 @@ void QgsDelimitedTextPlugin::help()
void QgsDelimitedTextPlugin::initGui()
{
// 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. "
"The file must have a header row containing the field names. "
"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
qGisInterface->addToolBarIcon( 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 );
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
* These functions can be called prior to creating an instance
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/delimited_text/qgsdelimitedtextplugin.h
Expand Up @@ -68,6 +68,8 @@ class QgsDelimitedTextPlugin: public QObject, public QgisPlugin, private Ui::Qgs
void unload();
//! show the help document
void help();
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme ( QString theThemeName );
private:


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

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

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

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

static const char *const sIdent =
Expand Down Expand Up @@ -66,7 +68,10 @@ dxf2shpConverter::~dxf2shpConverter()
void dxf2shpConverter::initGui()
{
// 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
mQActionPointer->setWhatsThis( tr( "Converts DXF files in Shapefile format" ) );
Expand All @@ -77,6 +82,9 @@ void dxf2shpConverter::initGui()
// Add the icon to the toolbar
mQGisIface->addToolBarIcon( 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
Expand Down Expand Up @@ -115,6 +123,30 @@ void dxf2shpConverter::addMyLayer( QString myfname, QString mytitle )
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
Expand Up @@ -61,6 +61,8 @@ class dxf2shpConverter: public QObject, public QgisPlugin
void unload();
//! show the help document
void help();
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme ( QString theThemeName );

void addMyLayer( QString, QString );

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

0 comments on commit b8889a9

Please sign in to comment.