From 731a35f1144ce2f1a9aa900d0d04e52bc8d62cbc Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 18 Apr 2016 14:00:54 +0300 Subject: [PATCH] Issue #1309 Management of icons - corrections for PythonAddons plugin, to load icons in OB and PropertyPanel. --- src/ModuleBase/ModuleBase_IconFactory.cpp | 27 ++++++++++++++---- src/ModuleBase/ModuleBase_IconFactory.h | 17 ++++++++++- src/ModuleBase/ModuleBase_Tools.cpp | 7 +++-- src/ModuleBase/ModuleBase_WidgetChoice.cpp | 5 ++-- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 +- src/PartSet/PartSet_IconFactory.cpp | 2 +- src/PartSet/PartSet_icons.qrc | 1 - .../icons/plane_view.png | Bin src/PythonAddons/CMakeLists.txt | 6 ++++ .../macros/box/icons}/box_ico.png | Bin src/PythonAddons/macros/box/widget.xml | 2 +- .../macros/rectangle}/icons/rectangle.png | Bin src/PythonAddons/macros/rectangle/widget.xml | 2 +- src/SketchPlugin/plugin-Sketch.xml | 2 +- src/XGUI/XGUI_DataModel.cpp | 4 +-- src/XGUI/XGUI_pictures.qrc | 1 - 16 files changed, 59 insertions(+), 20 deletions(-) rename src/{SketchPlugin => PartSet}/icons/plane_view.png (100%) rename src/{XGUI/pictures => PythonAddons/macros/box/icons}/box_ico.png (100%) rename src/{PartSet => PythonAddons/macros/rectangle}/icons/rectangle.png (100%) diff --git a/src/ModuleBase/ModuleBase_IconFactory.cpp b/src/ModuleBase/ModuleBase_IconFactory.cpp index 2e8311e52..4b6355377 100644 --- a/src/ModuleBase/ModuleBase_IconFactory.cpp +++ b/src/ModuleBase/ModuleBase_IconFactory.cpp @@ -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; } diff --git a/src/ModuleBase/ModuleBase_IconFactory.h b/src/ModuleBase/ModuleBase_IconFactory.h index 5ea4c4273..716007160 100644 --- a/src/ModuleBase/ModuleBase_IconFactory.h +++ b/src/ModuleBase/ModuleBase_IconFactory.h @@ -9,7 +9,10 @@ #include "ModuleBase.h" #include + +#include #include +#include /**\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(); diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 10dd13c0e..8643bf95a 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -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++) diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index e35f3c212..3d26909bf 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -5,7 +5,8 @@ // Author: Vitaly Smetannikov #include "ModuleBase_WidgetChoice.h" -#include +#include "ModuleBase_Tools.h" +#include "ModuleBase_IconFactory.h" #include #include @@ -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()); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 3052dae9f..c774f8952 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -122,7 +123,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) ModuleBase_PagedContainer* aContainer = qobject_cast(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()); diff --git a/src/PartSet/PartSet_IconFactory.cpp b/src/PartSet/PartSet_IconFactory.cpp index a76105434..45b5f19e3 100644 --- a/src/PartSet/PartSet_IconFactory.cpp +++ b/src/PartSet/PartSet_IconFactory.cpp @@ -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: { diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 4bf265160..270a9428f 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -9,7 +9,6 @@ icons/exec_state_invalid_parameters.png icons/hand_point.png icons/move_to_end.png - icons/rectangle.png icons/sketch_shape.png diff --git a/src/SketchPlugin/icons/plane_view.png b/src/PartSet/icons/plane_view.png similarity index 100% rename from src/SketchPlugin/icons/plane_view.png rename to src/PartSet/icons/plane_view.png diff --git a/src/PythonAddons/CMakeLists.txt b/src/PythonAddons/CMakeLists.txt index 881c75c85..4de9d6bcb 100644 --- a/src/PythonAddons/CMakeLists.txt +++ b/src/PythonAddons/CMakeLists.txt @@ -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/XGUI/pictures/box_ico.png b/src/PythonAddons/macros/box/icons/box_ico.png similarity index 100% rename from src/XGUI/pictures/box_ico.png rename to src/PythonAddons/macros/box/icons/box_ico.png diff --git a/src/PythonAddons/macros/box/widget.xml b/src/PythonAddons/macros/box/widget.xml index 6bd0d10f3..e977b3e8c 100644 --- a/src/PythonAddons/macros/box/widget.xml +++ b/src/PythonAddons/macros/box/widget.xml @@ -2,7 +2,7 @@ - + diff --git a/src/PartSet/icons/rectangle.png b/src/PythonAddons/macros/rectangle/icons/rectangle.png similarity index 100% rename from src/PartSet/icons/rectangle.png rename to src/PythonAddons/macros/rectangle/icons/rectangle.png diff --git a/src/PythonAddons/macros/rectangle/widget.xml b/src/PythonAddons/macros/rectangle/widget.xml index d60b44b6e..8bdf5010d 100644 --- a/src/PythonAddons/macros/rectangle/widget.xml +++ b/src/PythonAddons/macros/rectangle/widget.xml @@ -7,7 +7,7 @@ id="SketchRectangle" title="Rectangle" tooltip="Create rectangle" - icon=":icons/rectangle.png"> + icon="icons/Addons/rectangle.png"> diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 20c68b4d3..d60744f51 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -325,7 +325,7 @@ 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" /> diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index ce5ab3879..5e1c15d71 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -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(); diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 8cea28345..989cb501c 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -15,7 +15,6 @@ pictures/constr_object.png pictures/constr_object_modified.png pictures/part_ico.png - pictures/box_ico.png pictures/properties.png pictures/features.png pictures/point_ico.png -- 2.39.2