Salome HOME
Issue #1309 Management of icons - corrections for PythonAddons plugin, to load icons...
authornds <nds@opencascade.com>
Mon, 18 Apr 2016 11:00:54 +0000 (14:00 +0300)
committernds <nds@opencascade.com>
Mon, 18 Apr 2016 11:01:41 +0000 (14:01 +0300)
19 files changed:
src/ModuleBase/ModuleBase_IconFactory.cpp
src/ModuleBase/ModuleBase_IconFactory.h
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/PartSet/PartSet_IconFactory.cpp
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/plane_view.png [new file with mode: 0644]
src/PartSet/icons/rectangle.png [deleted file]
src/PythonAddons/CMakeLists.txt
src/PythonAddons/macros/box/icons/box_ico.png [new file with mode: 0644]
src/PythonAddons/macros/box/widget.xml
src/PythonAddons/macros/rectangle/icons/rectangle.png [new file with mode: 0644]
src/PythonAddons/macros/rectangle/widget.xml
src/SketchPlugin/icons/plane_view.png [deleted file]
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/box_ico.png [deleted file]

index 2e8311e523940c4cffed70404601dc48a820ffad..4b6355377c4ffeef60adc672ea98aeee15c922f1 100644 (file)
@@ -39,15 +39,32 @@ QIcon ModuleBase_IconFactory::getIcon(ObjectPtr theIcon)
 }
 
 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 anIconPath = QString::fromStdString(aPluginPath) + QDir::separator() +
-                         theValue;
-    if (QFile::exists(anIconPath))
-      aPixmap = QPixmap(anIconPath);
+    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 QIcon(aPixmap);
+  return anImage;
 }
index 5ea4c4273ac9669ee17f0569c18f6aff19a43cfa..716007160657210cce893e7ba62c81d16dda246d 100644 (file)
@@ -9,7 +9,10 @@
 
 #include "ModuleBase.h"
 #include <ModelAPI_Object.h>
+
+#include <QPixmap>
 #include <QIcon>
+#include <QImage>
 
 /**\class ModuleBase_IconFactory
  * \ingroup GUI
@@ -25,13 +28,25 @@ public:
   /// \param theObj an object
   virtual QIcon getIcon(ObjectPtr theObj);
 
-  /// Finds an icon for the given object. The icon is loaded: firstly from qrc file,
+  /// Finds an icon for the given value. The icon is loaded: firstly from qrc file,
   /// then by the icon path. If the path contains ":" , it will be treated as absolute path to
   /// the icon, or relative path from the plugin library
   /// \param theValue an icon information
   /// \return a loaded or empty icon
   static QIcon loadIcon(const QString& theValue);
 
+  /// Finds a pixmap for the given value. It is loaded: firstly from qrc file,
+  /// then by the absolute path. If the pixmap is not loaded, it is searched in relative plugin path
+  /// \param theValue a pixmap information
+  /// \return a loaded or empty pixmap
+  static QPixmap loadPixmap(const QString& theValue);
+
+  /// Finds an image for the given value. It is loaded: firstly from qrc file,
+  /// then by the absolute path. If the image is not loaded, it is searched in relative plugin path
+  /// \param theValue a image information
+  /// \return a loaded or empty pixmap
+  static QImage loadImage(const QString& theValue);
+
 protected:
   ModuleBase_IconFactory();
 
index 10dd13c0e74c94ce30c0b9f2886baba93b7b268e..8643bf95a6ab2d83f9b639986cee30ed2a87c689 100755 (executable)
@@ -11,6 +11,7 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_IconFactory.h>
 
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -126,7 +127,7 @@ void setShadowEffect(QWidget* theWidget, const bool isSetEffect)
 
 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
 {
-  QImage anIcon(theIcon);
+  QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
   QImage anAditional(theAdditionalIcon);
 
   if (anIcon.isNull())
@@ -154,11 +155,11 @@ QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
 
 QPixmap lighter(const QString& theIcon, const int theLighterValue)
 {
-  QImage anIcon(theIcon);
+  QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
   if (anIcon.isNull())
     return QPixmap();
 
-  QImage aResult(theIcon);
+  QImage aResult = ModuleBase_IconFactory::loadImage(theIcon);
   for (int i = 0; i < anIcon.width(); i++)
   {
     for (int j = 0; j < anIcon.height(); j++)
index e35f3c2128ca4cd19e6c6b2f65a10f8632e14335..3d26909bf73c3d03c6f7915314f9c8c9a7c591d0 100644 (file)
@@ -5,7 +5,8 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_WidgetChoice.h"
-#include <ModuleBase_Tools.h>
+#include "ModuleBase_Tools.h"
+#include "ModuleBase_IconFactory.h"
 
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Data.h>
@@ -62,7 +63,7 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
         aBtn->setCheckable(true);
         aBtn->setToolTip(aBtnTxt);
 
-        QPixmap aIcon(aIconList.at(aId));
+        QPixmap aIcon = ModuleBase_IconFactory::loadPixmap(aIconList.at(aId));
         aBtn->setIcon(aIcon);
         aBtn->setIconSize(aIcon.size());
         
index 3052dae9f594129a2551930805e4e6925edad684..c774f89521261c79ccc6e2bf171c31533074ec99 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_IconFactory.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
@@ -122,7 +123,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
               ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
 
               QString anIconPath = qs( myWidgetApi->getProperty( CONTAINER_PAGE_ICON ) );
-              QPixmap anIcon( anIconPath );
+              QPixmap anIcon = ModuleBase_IconFactory::loadPixmap( anIconPath );
               aContainer->addPage( aPage, aPageName, aCaseId, anIcon );
             }
           } while (myWidgetApi->toNextWidget());
index a76105434dffedb6ad0b52bbb33c39f105a366a5..45b5f19e380a8408e2b717d98cdcf553b0472976 100644 (file)
@@ -44,7 +44,7 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
     switch(aState) {
       case ModelAPI_StateDone:
       case ModelAPI_StateNothing: {
-        anIcon = QIcon(anIconString);
+        anIcon = loadIcon(anIconString);
       }
       break;
       case ModelAPI_StateMustBeUpdated: {
index 4bf265160dfc9a4e085b963d703f22220e21f2ce..270a9428fe5b213cbd4e21455904b45b8e2d052b 100644 (file)
@@ -9,7 +9,6 @@
      <file>icons/exec_state_invalid_parameters.png</file>
      <file>icons/hand_point.png</file>
      <file>icons/move_to_end.png</file>
-     <file>icons/rectangle.png</file>
      <file>icons/sketch_shape.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/plane_view.png b/src/PartSet/icons/plane_view.png
new file mode 100644 (file)
index 0000000..431f71a
Binary files /dev/null and b/src/PartSet/icons/plane_view.png differ
diff --git a/src/PartSet/icons/rectangle.png b/src/PartSet/icons/rectangle.png
deleted file mode 100644 (file)
index b98a991..0000000
Binary files a/src/PartSet/icons/rectangle.png and /dev/null differ
index 881c75c854e94ab4da8a96793700e650e92b50fa..4de9d6bcb9982a497e3d84f422137a17e7445e89 100644 (file)
@@ -15,8 +15,14 @@ CONFIGURE_FILE(
   "${CMAKE_CURRENT_BINARY_DIR}/addons_Features.xml"
   )
 
+SET(ICON_RESOURCES
+  macros/box/icons/box.png
+  macros/rectangle/icons/rectangle.png
+)
+
 INSTALL(FILES addons_Features.py DESTINATION ${SHAPER_INSTALL_ADDONS})
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/addons_Features.xml DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 
 INSTALL(FILES __init__.py DESTINATION ${SHAPER_INSTALL_ADDONS})
 INSTALL(DIRECTORY macros DESTINATION ${SHAPER_INSTALL_ADDONS})
+INSTALL(FILES ${ICON_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
diff --git a/src/PythonAddons/macros/box/icons/box_ico.png b/src/PythonAddons/macros/box/icons/box_ico.png
new file mode 100644 (file)
index 0000000..104a1ed
Binary files /dev/null and b/src/PythonAddons/macros/box/icons/box_ico.png differ
index 6bd0d10f391ce44826ea80ea77fc7d1a2408d384..e977b3e8cb34adf02f0fb09d2cf8247c2a40a1f5 100644 (file)
@@ -2,7 +2,7 @@
   <workbench id="Macros" document="Part">
     <group id="Samples">
 
-      <feature id="Box" title="Box" tooltip="Create a box parallel to xyz by extruding a rectangular" icon=":pictures/box_ico.png">
+      <feature id="Box" title="Box" tooltip="Create a box parallel to xyz by extruding a rectangular" icon="icons/Addons/box_ico.png">
         <doublevalue id="width"  label="Width: " min="0" step="1.0" default="50" tooltip="Box width">
           <validator id="GeomValidators_Positive"/>
         </doublevalue>
diff --git a/src/PythonAddons/macros/rectangle/icons/rectangle.png b/src/PythonAddons/macros/rectangle/icons/rectangle.png
new file mode 100644 (file)
index 0000000..b98a991
Binary files /dev/null and b/src/PythonAddons/macros/rectangle/icons/rectangle.png differ
index d60b44b6e61043c9e4cb21e645e7d8f50b1b4282..8bdf5010d6ff94be4838123104ed4b62d178423f 100644 (file)
@@ -7,7 +7,7 @@
         id="SketchRectangle"
         title="Rectangle"
         tooltip="Create rectangle"
-        icon=":icons/rectangle.png">
+        icon="icons/Addons/rectangle.png">
         <sketch-2dpoint_selector id="RectStartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"/>
         <sketch-2dpoint_selector id="RectEndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
diff --git a/src/SketchPlugin/icons/plane_view.png b/src/SketchPlugin/icons/plane_view.png
deleted file mode 100644 (file)
index 431f71a..0000000
Binary files a/src/SketchPlugin/icons/plane_view.png and /dev/null differ
index 20c68b4d33bd4702c4a1264d6afca0ea936e4b5e..d60744f516648573ae952c3cbbe210e95ddfc7e5 100644 (file)
           label="Angle type"
           tooltip="Type of angle"
           string_list="Direct Complementary Additional"
-          icons_list="icons/Sketch/angle_direct.png icons/angle_complementary.png icons/angle_backward.png"
+          icons_list="icons/Sketch/angle_direct.png icons/Sketch/angle_complementary.png icons/Sketch/angle_backward.png"
           default="0"
           />
       </feature>
index ce5ab3879a8eeef10a960f6db5ebdb3c582a4431..5e1c15d71bb7e3a3893948cbe5ce32ddb7cdf10a 100644 (file)
@@ -373,7 +373,7 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
         return QString(myXMLReader.rootFolderName(theIndexRow).c_str()) + 
           QString(" (%1)").arg(rowCount(theIndex));
       case Qt::DecorationRole:
-        return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
+        return ModuleBase_IconFactory::loadIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
       case Qt::ForegroundRole:
         {
           Qt::ItemFlags aFlags = theIndex.flags();
@@ -406,7 +406,7 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
           return QString(myXMLReader.subFolderName(aRow).c_str()) + 
             QString(" (%1)").arg(rowCount(theIndex));
         case Qt::DecorationRole:
-          return QIcon(myXMLReader.subFolderIcon(aRow).c_str());
+          return ModuleBase_IconFactory::loadIcon(myXMLReader.subFolderIcon(aRow).c_str());
       }
     } else {
       ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
index 8cea2834516542bc5c17d585b3218042fe594a7c..989cb501c822ee7fd33bb57ad5915949a4473c2a 100644 (file)
@@ -15,7 +15,6 @@
      <file>pictures/constr_object.png</file>
      <file>pictures/constr_object_modified.png</file>
      <file>pictures/part_ico.png</file>
-     <file>pictures/box_ico.png</file>
      <file>pictures/properties.png</file>
      <file>pictures/features.png</file>
      <file>pictures/point_ico.png</file>
diff --git a/src/XGUI/pictures/box_ico.png b/src/XGUI/pictures/box_ico.png
deleted file mode 100644 (file)
index 104a1ed..0000000
Binary files a/src/XGUI/pictures/box_ico.png and /dev/null differ