Commit 818cdda3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX #195] now using icon of meta file if available. Fallback is still the XPM.

parent 5ba5ae19
......@@ -93,6 +93,18 @@ boost::filesystem::path WModuleMetaInformation::getIcon() const
return m_localPath / m_metaData.getValue< boost::filesystem::path >( m_name + "/icon", boost::filesystem::path( "icon.png" ) );
}
bool WModuleMetaInformation::isIconAvailable() const
{
if( m_loaded )
{
return m_metaData.exists( m_name + "/icon", true );
}
else
{
return false;
}
}
std::string WModuleMetaInformation::getWebsite() const
{
// return a default if not meta data was loaded
......
......@@ -154,6 +154,13 @@ public:
*/
boost::filesystem::path getIcon() const;
/**
* Check whether the meta info contained an icon.
*
* \return true if icon is available. Does not check existence or validity of image file.
*/
bool isIconAvailable() const;
/**
* The URL to a module website. Can be empty.
*
......
......@@ -72,7 +72,6 @@
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WGERequirement.h"
#include "WMTemplate.xpm"
#include "icons/bier.xpm"
#include "icons/wurst.xpm"
#include "icons/steak.xpm"
......@@ -129,13 +128,11 @@ boost::shared_ptr< WModule > WMTemplate::factory() const
const char** WMTemplate::getXPMIcon() const
{
// The template_xpm char array comes from the template.xpm file as included above.
// Such char arrays, i.e. files, can be easily created using an image manipulation program
// like GIMP. Be aware that the xpm file is a simple header file. Thus it contains real
// code. This code can be manipulated by hand. Unfortunately, you really have to fix the
// xpm files produced by gimp. You need to make the char array const in order to prevent
// compiler warnings or even errors.
return template_xpm;
// This is deprecated! You can still use it as fallback if you do not specify a META file. If you return NULL here, a default icon is used.
//
// This was used to provide an icon for your module. You should use the META file in your resource directory. This file is commented and
// explains each entry in detail.
return NULL;
}
const std::string WMTemplate::getName() const
......
......@@ -33,8 +33,8 @@
"Template"
{
// Provide an icon. If the icon exists, it overrides the one provided by your
// getIcon method. This path is relative to your module's resource directory.
icon="WMTeamplate.png";
// getXPMIcon method. This path is relative to your module's resource directory.
icon="WMTeamplate.xpm";
// Where to find the module?
website = "http://www.openwalnut.org";
......
......@@ -66,7 +66,23 @@ QIcon WIconManager::getIcon( const std::string name )
}
else if( WModuleFactory::getModuleFactory()->getPrototypeByName( name ) )
{
icon = QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
// get module icon from meta info if available
WModuleMetaInformation::ConstSPtr meta = WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getMetaInformation();
if( meta->isIconAvailable() && boost::filesystem::exists( meta->getIcon() ) )
{
try
{
icon = QIcon( QPixmap( QString::fromStdString( meta->getIcon().string() ) ) );
}
catch( ... )
{
icon = QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
}
}
else
{
icon = QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
}
}
else
{
......@@ -84,7 +100,23 @@ QIcon WIconManager::getIcon( const std::string name, const QIcon& defaultIcon )
}
else if( WModuleFactory::getModuleFactory()->getPrototypeByName( name ) )
{
return QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
// get module icon from meta info if available
WModuleMetaInformation::ConstSPtr meta = WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getMetaInformation();
if( meta->isIconAvailable() && boost::filesystem::exists( meta->getIcon() ) )
{
try
{
return QIcon( QPixmap( QString::fromStdString( meta->getIcon().string() ) ) );
}
catch( ... )
{
return QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
}
}
else
{
return QIcon( QPixmap( WModuleFactory::getModuleFactory()->getPrototypeByName( name )->getXPMIcon() ) );
}
}
else
{
......
......@@ -245,18 +245,10 @@ WQtModuleConfig::WQtModuleConfig( QWidget* parent, Qt::WindowFlags f ):
QLabel* icon = new QLabel();
icon->setSizePolicy( sizePolicy );
// if there is an icon -> show it
if( ( *iter )->getXPMIcon() )
{
// we need to enforce some size
QPixmap qicon( ( *iter )->getXPMIcon() );
qicon = qicon.scaled( 32, 32, Qt::KeepAspectRatio );
icon->setPixmap( qicon );
}
else
{
icon->setPixmap( noIcon.pixmap( 32, 32 ) );
}
// we need to enforce some size
QPixmap qicon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( ( *iter )->getName(), noIcon ).pixmap( 32, 32 ) );
qicon = qicon.scaled( 32, 32, Qt::KeepAspectRatio );
icon->setPixmap( qicon );
layoutWidget->addWidget( icon, 0, column, 2, 1 );
++column;
......
......@@ -48,6 +48,9 @@
#include "core/common/WLogger.h"
#include "core/common/WPathHelper.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
#include "WQtModuleMetaInfo.h"
#include "WQtModuleMetaInfo.moc"
......@@ -226,7 +229,7 @@ WQtModuleMetaInfo::WQtModuleMetaInfo( WModule::SPtr module, QWidget* parent ):
toolbar->setLayout( tbLayout );
// we need a special home-action to set the html content again
QAction* homeAction = new QAction( QIcon( QPixmap( module->getXPMIcon() ) ),
QAction* homeAction = new QAction( WQt4Gui::getMainWindow()->getIconManager()->getIcon( module->getName() ),
QString( "Back to " ) + QString::fromStdString( module->getName() ),
toolbar );
homeAction->setIconText( QString( "Back to " ) + QString::fromStdString( module->getName() ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment