Salome HOME
Issue #1309 Management of icons - corrections for PythonAddons plugin, to load icons...
[modules/shaper.git] / src / ModuleBase / ModuleBase_IconFactory.cpp
index f87fa91f3c0b65b0b147056e0bbd633b06564901..4b6355377c4ffeef60adc672ea98aeee15c922f1 100644 (file)
@@ -4,12 +4,20 @@
 // Created:     28 Jul 2015
 // Author:      Vitaly SMETANNIKOV
 
-
 #include "ModuleBase_IconFactory.h"
 
+#include "Config_XMLReader.h"
+
+#include <QDir>
+
 ModuleBase_IconFactory* MYIconFactory = 0;
 
 
+ModuleBase_IconFactory::ModuleBase_IconFactory()
+{
+  setFactory(this);
+}
+
 void ModuleBase_IconFactory::setFactory(ModuleBase_IconFactory* theFactory)
 {
   if (MYIconFactory)
@@ -29,3 +37,34 @@ QIcon ModuleBase_IconFactory::getIcon(ObjectPtr theIcon)
 {
   return QIcon();
 }
+
+QIcon ModuleBase_IconFactory::loadIcon(const QString& theValue)
+{
+  return QIcon(loadPixmap(theValue));
+}
+
+QPixmap ModuleBase_IconFactory::loadPixmap(const QString& theValue)
+{
+  QPixmap aPixmap(theValue);
+
+  if (aPixmap.isNull()) {
+    std::string aPluginPath = Config_XMLReader::pluginConfigFile();
+    QString aPath = QString::fromStdString(aPluginPath) + QDir::separator() + theValue;
+    if (QFile::exists(aPath))
+      aPixmap = QPixmap(aPath);
+  }
+  return aPixmap;
+}
+
+QImage ModuleBase_IconFactory::loadImage(const QString& theValue)
+{
+  QImage anImage(theValue);
+
+  if (anImage.isNull()) {
+    std::string aPluginPath = Config_XMLReader::pluginConfigFile();
+    QString aPath = QString::fromStdString(aPluginPath) + QDir::separator() + theValue;
+    if (QFile::exists(aPath))
+      anImage = QImage(aPath);
+  }
+  return anImage;
+}