Skip to content

Commit

Permalink
Theme related fixes:
Browse files Browse the repository at this point in the history
 - implemented 'fall back' support so that if a theme is missing icons, the default theme icons will be used instead.
 - use a static function in qgisapp to get theme icons and pixmaps
 - updated all icon fetching code to use the new methods above
 - updated qgsapplication so that it differentiates between active and default themes
 - fixed a bug in qgsoptions that prevented themes being changed in some cases.
This is a part fix for #1054 - still need to do some work to make GRASS theming work properly


git-svn-id: http://svn.osgeo.org/qgis/trunk@8937 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jul 28, 2008
1 parent 2e43667 commit ddd934f
Show file tree
Hide file tree
Showing 34 changed files with 2,532 additions and 1,543 deletions.
11 changes: 7 additions & 4 deletions python/core/qgsapplication.sip
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)

virtual ~QgsApplication();

//! Set the theme path to the specified theme.
static void selectTheme(const QString theThemeName);
//! Set the active theme path to the specified theme.
static void setTheme(const QString theThemeName);

//! Returns the path to the authors file.
static const QString authorsFilePath();
Expand Down Expand Up @@ -130,8 +130,11 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
//! Returns the common root path of all application data directories.
static const QString pkgDataPath();

//! Returns the path to the current theme directory.
static const QString themePath();
//! Returns the path to the currently active theme directory.
static const QString activeThemePath();

//! Returns the path to the default theme directory.
static const QString defaultThemePath();

//! Alters prefix path - used by 3rd party apps
static void setPrefixPath(const QString thePrefixPath, bool useDefaultPaths = FALSE);
Expand Down
34 changes: 15 additions & 19 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,22 @@ QgsComposer::~QgsComposer()

void QgsComposer::setupTheme()
{
//calculate the active theme path
QString myThemePath= QgsApplication::themePath();


//now set all the icons
mActionOpenTemplate->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
mActionSaveTemplateAs->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSaveAs.png")));
mActionExportAsImage->setIcon(QIcon(QPixmap(myThemePath + "/mActionExportMapServer.png")));
mActionExportAsSVG->setIcon(QIcon(QPixmap(myThemePath + "/mActionSaveAsSVG.png")));
mActionPrint->setIcon(QIcon(QPixmap(myThemePath + "/mActionFilePrint.png")));
mActionZoomAll->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomFullExtent.png")));
mActionZoomIn->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomIn.png")));
mActionZoomOut->setIcon(QIcon(QPixmap(myThemePath + "/mActionZoomOut.png")));
mActionRefreshView->setIcon(QIcon(QPixmap(myThemePath + "/mActionDraw.png")));
mActionAddImage->setIcon(QIcon(QPixmap(myThemePath + "/mActionSaveMapAsImage.png")));
mActionAddNewMap->setIcon(QIcon(QPixmap(myThemePath + "/mActionAddRasterLayer.png")));
mActionAddNewLabel->setIcon(QIcon(QPixmap(myThemePath + "/mActionLabel.png")));
mActionAddNewVectLegend->setIcon(QIcon(QPixmap(myThemePath + "/mActionAddLegend.png")));
mActionAddNewScalebar->setIcon(QIcon(QPixmap(myThemePath + "/mActionScaleBar.png")));
mActionSelectMoveItem->setIcon(QIcon(QPixmap(myThemePath + "/mActionPan.png")));
mActionOpenTemplate->setIcon(QgisApp::getThemeIcon("/mActionFileOpen.png"));
mActionSaveTemplateAs->setIcon(QgisApp::getThemeIcon("/mActionFileSaveAs.png"));
mActionExportAsImage->setIcon(QgisApp::getThemeIcon("/mActionExportMapServer.png"));
mActionExportAsSVG->setIcon(QgisApp::getThemeIcon("/mActionSaveAsSVG.png"));
mActionPrint->setIcon(QgisApp::getThemeIcon("/mActionFilePrint.png"));
mActionZoomAll->setIcon(QgisApp::getThemeIcon("/mActionZoomFullExtent.png"));
mActionZoomIn->setIcon(QgisApp::getThemeIcon("/mActionZoomIn.png"));
mActionZoomOut->setIcon(QgisApp::getThemeIcon("/mActionZoomOut.png"));
mActionRefreshView->setIcon(QgisApp::getThemeIcon("/mActionDraw.png"));
mActionAddImage->setIcon(QgisApp::getThemeIcon("/mActionSaveMapAsImage.png"));
mActionAddNewMap->setIcon(QgisApp::getThemeIcon("/mActionAddRasterLayer.png"));
mActionAddNewLabel->setIcon(QgisApp::getThemeIcon("/mActionLabel.png"));
mActionAddNewVectLegend->setIcon(QgisApp::getThemeIcon("/mActionAddLegend.png"));
mActionAddNewScalebar->setIcon(QgisApp::getThemeIcon("/mActionScaleBar.png"));
mActionSelectMoveItem->setIcon(QgisApp::getThemeIcon("/mActionPan.png"));
}

void QgsComposer::open ( void )
Expand Down
31 changes: 15 additions & 16 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* $Id$ */

#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgslegend.h"
#include "qgslegendgroup.h"
Expand Down Expand Up @@ -87,8 +88,9 @@ QgsLegend::QgsLegend(QWidget * parent, const char *name)
setColumnCount(1);
header()->setHidden(1);
setRootIsDecorated(true);

initPixmaps();


}


Expand Down Expand Up @@ -400,8 +402,6 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit

QMenu theMenu;

QString iconsPath = QgsApplication::themePath();

QgsLegendItem* li = dynamic_cast<QgsLegendItem*>(item);
if (li)
{
Expand All @@ -422,7 +422,7 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
}
else if(li->type() == QgsLegendItem::LEGEND_GROUP)
{
theMenu.addAction(QPixmap(iconsPath+QString("/mActionRemove.png")),
theMenu.addAction(QgisApp::getThemeIcon("/mActionRemove.png"),
tr("&Remove"), this, SLOT(legendGroupRemove()));
}

Expand All @@ -433,9 +433,9 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit

}

theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/folder_new.png"))), tr("&Add group"), this, SLOT(addGroup()));
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionExpandTree.png"))), tr("&Expand all"), this, SLOT(expandAll()));
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionCollapseTree.png"))), tr("&Collapse all"), this, SLOT(collapseAll()));
theMenu.addAction(QgisApp::getThemeIcon("/folder_new.png"), tr("&Add group"), this, SLOT(addGroup()));
theMenu.addAction(QgisApp::getThemeIcon("/mActionExpandTree.png"), tr("&Expand all"), this, SLOT(expandAll()));
theMenu.addAction(QgisApp::getThemeIcon("/mActionCollapseTree.png"), tr("&Collapse all"), this, SLOT(collapseAll()));

QAction* showFileGroupsAction = theMenu.addAction(tr("Show file groups"), this, SLOT(showLegendLayerFileGroups()));
showFileGroupsAction->setCheckable(true);
Expand All @@ -445,6 +445,14 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
theMenu.exec(position);
}

void QgsLegend::initPixmaps()
{
mPixmaps.mOriginalPixmap = QgisApp::getThemePixmap("/mActionFileSmall.png");
mPixmaps.mInOverviewPixmap = QgisApp::getThemePixmap("/mActionInOverview.png");
mPixmaps.mEditablePixmap = QgisApp::getThemePixmap("/mIconEditable.png");
mPixmaps.mProjectionErrorPixmap = QgisApp::getThemePixmap("/mIconProjectionProblem.png");
}

int QgsLegend::getItemPos(QTreeWidgetItem* item)
{
int counter = 1;
Expand Down Expand Up @@ -1828,15 +1836,6 @@ void QgsLegend::legendLayerAttributeTable()
tr("To open an attribute table, you must select a vector layer in the legend"));
}

void QgsLegend::initPixmaps()
{
QString myThemePath = QgsApplication::themePath();
mPixmaps.mOriginalPixmap.load(myThemePath + "/mActionFileSmall.png");
mPixmaps.mInOverviewPixmap.load(myThemePath + "/mActionInOverview.png");
mPixmaps.mEditablePixmap.load(myThemePath + "/mIconEditable.png");
mPixmaps.mProjectionErrorPixmap.load(myThemePath + "/mIconProjectionProblem.png");
}

void QgsLegend::readProject(const QDomDocument & doc)
{
QDomNodeList nodes = doc.elementsByTagName("legend");
Expand Down
25 changes: 14 additions & 11 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class QgsLegend : public QTreeWidget

/**Returns structure with legend pixmaps*/
QgsLegendPixmaps& pixmaps() { return mPixmaps; }



void updateCheckStates(QTreeWidgetItem* item, Qt::CheckState state) {mStateOfCheckBoxes[item] = state;}

public slots:
Expand Down Expand Up @@ -400,21 +401,23 @@ this item may be moved back to the original position with resetToInitialPosition
/** structure which holds pixmap which are used in legend */
class QgsLegendPixmaps
{
public:
//! Pixmap which is shown by default
QPixmap mOriginalPixmap;

//! Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only)
QPixmap mProjectionErrorPixmap;
public:
//! Pixmap which is shown by default
QPixmap mOriginalPixmap;

//! Pixmap to show if this layer is represented in overview or now
QPixmap mInOverviewPixmap;
//! Pixmap to show a bogus vertex was encoutnered in this layer (applies to vector layers only)
QPixmap mProjectionErrorPixmap;

//! Pixmap to show it this layer has currently editing turned on
QPixmap mEditablePixmap;
//! Pixmap to show if this layer is represented in overview or now
QPixmap mInOverviewPixmap;

//! Pixmap to show it this layer has currently editing turned on
QPixmap mEditablePixmap;

} mPixmaps;



signals:
void zOrderChanged(QgsLegend * lv);

Expand Down
7 changes: 4 additions & 3 deletions src/app/legend/qgslegendgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgslegendgroup.h"
#include "qgslegendlayer.h"
#include "qgslegendlayerfile.h"
Expand All @@ -30,7 +31,7 @@ QgsLegendGroup::QgsLegendGroup(QTreeWidgetItem * theItem ,QString theName)
mType=LEGEND_GROUP;
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
setCheckState (0, Qt::Checked);
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
QIcon myIcon = QgisApp::getThemeIcon("/mActionFolder.png");
setIcon(0, myIcon);
}
QgsLegendGroup::QgsLegendGroup(QTreeWidget* theListView, QString theString)
Expand All @@ -39,7 +40,7 @@ QgsLegendGroup::QgsLegendGroup(QTreeWidget* theListView, QString theString)
mType=LEGEND_GROUP;
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
setCheckState (0, Qt::Checked);
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
QIcon myIcon = QgisApp::getThemeIcon("/mActionFolder.png");
setIcon(0, myIcon);
}

Expand All @@ -48,7 +49,7 @@ QgsLegendGroup::QgsLegendGroup(QString name): QgsLegendItem()
mType=LEGEND_GROUP;
setFlags(Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
setCheckState (0, Qt::Checked);
QIcon myIcon(QgsApplication::themePath()+"/mActionFolder.png");
QIcon myIcon = QgisApp::getThemeIcon(+"/mActionFolder.png");
setText(0, name);
setIcon(0, myIcon);
}
Expand Down
68 changes: 27 additions & 41 deletions src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
***************************************************************************/

#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgslegend.h"
#include "qgslegendlayer.h"
#include "qgslegendlayerfile.h"
Expand Down Expand Up @@ -404,28 +405,27 @@ void QgsLegendLayer::updateIcon()
QgsLegendLayerFile* theFile = firstLayerFile();

if(mapLayers().size() == 1)
{
//overview
if(theFile->isInOverview())
{

//overview
if(theFile->isInOverview())
{
// Overlay the overview icon on the default icon
QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}

//editable
if(theLayer->isEditable())
{
// Overlay the editable icon on the default icon
QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}
// Overlay the overview icon on the default icon
QPixmap myPixmap = QgisApp::getThemePixmap(+"mIconOverview.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}

//editable
if(theLayer->isEditable())
{
// Overlay the editable icon on the default icon
QPixmap myPixmap = QgisApp::getThemePixmap(+"mIconEditable.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}
}

QIcon theIcon(newIcon);
setIcon(0, theIcon);
Expand All @@ -436,48 +436,34 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
QgsMapLayer* firstLayer = firstMapLayer();
if(firstLayer)
{
QString myThemePath = QgsApplication::themePath();
QString myPath;

if (firstLayer->type() == QgsMapLayer::VECTOR)
{
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(firstLayer);
switch(vlayer->vectorType())
{
case QGis::Point:
myPath = myThemePath+"/mIconPointLayer.png";
return QgisApp::getThemePixmap("/mIconPointLayer.png");
break;
case QGis::Line:
myPath = myThemePath+"/mIconLineLayer.png";
return QgisApp::getThemePixmap("/mIconLineLayer.png");
break;
case QGis::Polygon:
myPath = myThemePath+"/mIconPolygonLayer.png";
return QgisApp::getThemePixmap("/mIconPolygonLayer.png");
break;
default:
myPath = myThemePath+"/mIconLayer.png";
return QgisApp::getThemePixmap("/mIconLayer.png");
}
}
else // RASTER
{
myPath = myThemePath+"/mIconLayer.png";
}


QFileInfo file(myPath);
if(file.exists())
{
return QPixmap(file.absoluteFilePath());
return QgisApp::getThemePixmap("/mIconLayer.png");
}
}

QPixmap emptyPixmap;
return emptyPixmap;
}


void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
{
QString iconsPath = QgsApplication::themePath();
std::list<QgsLegendLayerFile*> files = legendLayerFiles();
QgsMapLayer* firstLayer = NULL;
if (files.size() > 0)
Expand All @@ -486,7 +472,7 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction
}

// zoom to layer extent
theMenu.addAction(QIcon(iconsPath+QString("/mActionZoomToLayer.png")),
theMenu.addAction(QgisApp::getThemeIcon("/mActionZoomToLayer.png"),
tr("&Zoom to layer extent"), legend(), SLOT(legendLayerZoom()));
if (firstLayer && firstLayer->type() == QgsMapLayer::RASTER)
{
Expand All @@ -499,7 +485,7 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction
showInOverviewAction->setChecked(isInOverview());

// remove from canvas
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionRemove.png"))),
theMenu.addAction(QgisApp::getThemeIcon("/mActionRemove.png"),
tr("&Remove"), legend(), SLOT(legendLayerRemove()));

theMenu.addSeparator();
Expand Down
Loading

0 comments on commit ddd934f

Please sign in to comment.