}
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;
}
#include "ModuleBase.h"
#include <ModelAPI_Object.h>
+
+#include <QPixmap>
#include <QIcon>
+#include <QImage>
/**\class ModuleBase_IconFactory
* \ingroup GUI
/// \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();
#include <ModuleBase_WidgetFactory.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_IconFactory.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeRefAttr.h>
QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
{
- QImage anIcon(theIcon);
+ QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
QImage anAditional(theAdditionalIcon);
if (anIcon.isNull())
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++)
// 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>
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());
*/
#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_IconFactory.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
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());
switch(aState) {
case ModelAPI_StateDone:
case ModelAPI_StateNothing: {
- anIcon = QIcon(anIconString);
+ anIcon = loadIcon(anIconString);
}
break;
case ModelAPI_StateMustBeUpdated: {
<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>
"${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)
<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>
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"/>
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>
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();
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();
<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>