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

[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 ...@@ -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" ) ); 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 std::string WModuleMetaInformation::getWebsite() const
{ {
// return a default if not meta data was loaded // return a default if not meta data was loaded
......
...@@ -154,6 +154,13 @@ public: ...@@ -154,6 +154,13 @@ public:
*/ */
boost::filesystem::path getIcon() const; 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. * The URL to a module website. Can be empty.
* *
......
...@@ -72,7 +72,6 @@ ...@@ -72,7 +72,6 @@
#include "core/graphicsEngine/WGEUtils.h" #include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WGERequirement.h" #include "core/graphicsEngine/WGERequirement.h"
#include "WMTemplate.xpm"
#include "icons/bier.xpm" #include "icons/bier.xpm"
#include "icons/wurst.xpm" #include "icons/wurst.xpm"
#include "icons/steak.xpm" #include "icons/steak.xpm"
...@@ -129,13 +128,11 @@ boost::shared_ptr< WModule > WMTemplate::factory() const ...@@ -129,13 +128,11 @@ boost::shared_ptr< WModule > WMTemplate::factory() const
const char** WMTemplate::getXPMIcon() const const char** WMTemplate::getXPMIcon() const
{ {
// The template_xpm char array comes from the template.xpm file as included above. // 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.
// 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 // 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
// code. This code can be manipulated by hand. Unfortunately, you really have to fix the // explains each entry in detail.
// xpm files produced by gimp. You need to make the char array const in order to prevent return NULL;
// compiler warnings or even errors.
return template_xpm;
} }
const std::string WMTemplate::getName() const const std::string WMTemplate::getName() const
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
"Template" "Template"
{ {
// Provide an icon. If the icon exists, it overrides the one provided by your // 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. // getXPMIcon method. This path is relative to your module's resource directory.
icon="WMTeamplate.png"; icon="WMTeamplate.xpm";
// Where to find the module? // Where to find the module?
website = "http://www.openwalnut.org"; website = "http://www.openwalnut.org";
......
...@@ -66,7 +66,23 @@ QIcon WIconManager::getIcon( const std::string name ) ...@@ -66,7 +66,23 @@ QIcon WIconManager::getIcon( const std::string name )
} }
else if( WModuleFactory::getModuleFactory()->getPrototypeByName( 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 else
{ {
...@@ -84,7 +100,23 @@ QIcon WIconManager::getIcon( const std::string name, const QIcon& defaultIcon ) ...@@ -84,7 +100,23 @@ QIcon WIconManager::getIcon( const std::string name, const QIcon& defaultIcon )
} }
else if( WModuleFactory::getModuleFactory()->getPrototypeByName( name ) ) 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 else
{ {
......
...@@ -245,18 +245,10 @@ WQtModuleConfig::WQtModuleConfig( QWidget* parent, Qt::WindowFlags f ): ...@@ -245,18 +245,10 @@ WQtModuleConfig::WQtModuleConfig( QWidget* parent, Qt::WindowFlags f ):
QLabel* icon = new QLabel(); QLabel* icon = new QLabel();
icon->setSizePolicy( sizePolicy ); icon->setSizePolicy( sizePolicy );
// if there is an icon -> show it // we need to enforce some size
if( ( *iter )->getXPMIcon() ) QPixmap qicon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( ( *iter )->getName(), noIcon ).pixmap( 32, 32 ) );
{ qicon = qicon.scaled( 32, 32, Qt::KeepAspectRatio );
// we need to enforce some size icon->setPixmap( qicon );
QPixmap qicon( ( *iter )->getXPMIcon() );
qicon = qicon.scaled( 32, 32, Qt::KeepAspectRatio );
icon->setPixmap( qicon );
}
else
{
icon->setPixmap( noIcon.pixmap( 32, 32 ) );
}
layoutWidget->addWidget( icon, 0, column, 2, 1 ); layoutWidget->addWidget( icon, 0, column, 2, 1 );
++column; ++column;
......
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
#include "core/common/WLogger.h" #include "core/common/WLogger.h"
#include "core/common/WPathHelper.h" #include "core/common/WPathHelper.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
#include "WQtModuleMetaInfo.h" #include "WQtModuleMetaInfo.h"
#include "WQtModuleMetaInfo.moc" #include "WQtModuleMetaInfo.moc"
...@@ -226,7 +229,7 @@ WQtModuleMetaInfo::WQtModuleMetaInfo( WModule::SPtr module, QWidget* parent ): ...@@ -226,7 +229,7 @@ WQtModuleMetaInfo::WQtModuleMetaInfo( WModule::SPtr module, QWidget* parent ):
toolbar->setLayout( tbLayout ); toolbar->setLayout( tbLayout );
// we need a special home-action to set the html content again // 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() ), QString( "Back to " ) + QString::fromStdString( module->getName() ),
toolbar ); toolbar );
homeAction->setIconText( QString( "Back to " ) + QString::fromStdString( module->getName() ) ); 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