31 #include "core/common/WAssert.h"
32 #include "core/common/WPathHelper.h"
33 #include "core/common/WLogger.h"
34 #include "core/common/exceptions/WFileNotFound.h"
35 #include "core/kernel/WModuleFactory.h"
37 #include "WIconManager.h"
38 #include "WNoIconDefault.xpm"
56 WAssert( boost::filesystem::exists( fallback ),
"Found no icon named: " + name +
" and no fallback icon. Installation broken?" );
57 return getIcon( name, QIcon( QPixmap( QString::fromStdString( fallback.string() ) ) ) );
62 std::string iconFile = name;
73 boost::filesystem::path pAlt =
WPathHelper::getPathHelper()->getSharePath() /
".." /
"pixmaps" / std::string( iconFile +
".png" );
74 if( boost::filesystem::exists( p ) )
78 return QIcon( QPixmap( QString::fromStdString( p.string() ) ) );
85 else if( boost::filesystem::exists( pAlt ) )
89 return QIcon( QPixmap( QString::fromStdString( pAlt.string() ) ) );
103 if( meta->isIconAvailable() && boost::filesystem::exists( meta->getIcon() ) )
107 return QIcon( QPixmap( QString::fromStdString( meta->getIcon().string() ) ) );
113 return QIcon( QPixmap( xpm ) );
125 return QIcon( QPixmap( xpm ) );
136 wlog::debug(
"WIconManager" ) <<
"Icon \"" << name <<
"\" not found. Falling back to default.";
149 if( ( image->getDepth() != 1 ) || ( image->getHeight() == 1 ) )
151 wlog::error(
"WIconManager" ) <<
"Cannot use specified image as icon. It has to be 2D.";
156 QImage img = QImage( image->getWidth(), image->getHeight(), QImage::Format_ARGB32 );
162 for(
int y = 0; y < image->getHeight(); ++y )
164 for(
int x = 0; x < image->getWidth(); ++x )
166 WColor col = image->getColor( x, y );
167 QColor qcol = QColor( 255 * col.r(), 255 * col.g(), 255 * col.b(), 255 * col.a() );
168 img.setPixel( x, y, qcol.rgba() );
175 img = img.mirrored(
false,
true );
178 return QIcon( QPixmap::fromImage( img ) );
183 return QIcon( QPixmap( WNoIconDefault_xpm ) );
@ BOTTOM_LEFT
bottom left origin
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
void addMapping(const std::string &newName, const std::string &mapToThis)
Add a mapping for icons.
std::map< std::string, std::string > m_iconMappingList
A map storing icons and the names used to identify them.
static QIcon getNoIconDefault()
Return an icon representing a default "No Icon" icon.
static QIcon convertToIcon(WGEImage::SPtr image)
Convert a WGEImage to an QIcon.
QIcon getIcon(const std::string name)
Searches icons in the internal map and all modules for the given icon name.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
static std::shared_ptr< WPathHelper > getPathHelper()
Returns instance of the path helper.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger error(const std::string &source)
Logging an error message.