1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
28
#include <QtGui/QPixmap>
30
#include "core/common/WAssert.h"
31
#include "core/common/WPathHelper.h"
32
#include "core/common/WLogger.h"
33
#include "core/common/exceptions/WFileNotFound.h"
34
#include "core/kernel/WModuleFactory.h"
36
#include "WIconManager.h"
38
void WIconManager::addMapping( const std::string& newName, const std::string& mapToThis )
40
if( m_iconMappingList.count( newName ) == 0 )
42
m_iconMappingList.insert( std::make_pair( newName, mapToThis ) );
46
m_iconMappingList[ newName ] = mapToThis;
50
QIcon WIconManager::getIcon( const std::string name )
52
// ensure we have a fallback icon
53
boost::filesystem::path fallback = WPathHelper::getPathHelper()->getSharePath() / "qt4gui" / "default.png";
54
WAssert( boost::filesystem::exists( fallback ), "Found no icon named: " + name + " and no fallback icon. Installation broken?" );
55
return getIcon( name, QIcon( QPixmap( QString::fromStdString( fallback.string() ) ) ) );
58
QIcon WIconManager::getIcon( const std::string name, const QIcon& defaultIcon )
60
std::string iconFile = name;
62
// is there a mapping for this icon name?
63
if( m_iconMappingList.count( name ) > 0 )
65
iconFile = m_iconMappingList[ name ];
69
boost::filesystem::path p = WPathHelper::getPathHelper()->getSharePath() / "qt4gui" / std::string( iconFile + ".png" );
70
// and an alternative path
71
boost::filesystem::path pAlt = WPathHelper::getPathHelper()->getSharePath() / ".." / "pixmaps" / std::string( iconFile + ".png" );
72
if( boost::filesystem::exists( p ) )
76
return QIcon( QPixmap( QString::fromStdString( p.string() ) ) );
83
else if( boost::filesystem::exists( pAlt ) )
87
return QIcon( QPixmap( QString::fromStdString( pAlt.string() ) ) );
94
else if( WModuleFactory::getModuleFactory()->isPrototypeAvailable( name ) )
96
// get module icon from meta info if available
97
WModuleMetaInformation::ConstSPtr meta = WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getMetaInformation();
98
const char** xpm = WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon();
100
// prefer meta info icon
101
if( meta->isIconAvailable() && boost::filesystem::exists( meta->getIcon() ) )
105
return QIcon( QPixmap( QString::fromStdString( meta->getIcon().string() ) ) );
111
return QIcon( QPixmap( xpm ) );
123
return QIcon( QPixmap( xpm ) );
133
wlog::debug( "WIconManager" ) << pAlt.string();
134
wlog::debug( "WIconManager" ) << "Icon \"" << name << "\" not found. Falling back to default.";