#include "ModuleBase_Tools.h"
#include <QWidget>
#include <QLayout>
+#include <QPainter>
+#include <QBitmap>
namespace ModuleBase_Tools {
theLayout->setSpacing(5);
}
+QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
+ const int theYShift, const QString& theIcon)
+{
+ QImage anIcon(theIcon);
+ QImage anAditional(theAdditionalIcon);
+
+ if (anIcon.isNull())
+ return QPixmap();
+
+ for (int i = theXShift; i < anAditional.width() + theXShift && i < anIcon.width(); i++)
+ {
+ for (int j = theYShift; j < anAditional.height() + theYShift && j < anIcon.height(); j++)
+ {
+ if (qAlpha(anAditional.pixel(i - theXShift, j - theYShift)) > 0)
+ anIcon.setPixel(i, j, anAditional.pixel(i - theXShift, j - theYShift));
+ }
+ }
+ return QPixmap::fromImage(anIcon);
+}
+QPixmap lighter(const QString& theIcon, const int theLighterValue)
+{
+ QImage anIcon(theIcon);
+ if (anIcon.isNull())
+ return QPixmap();
+
+ QImage aResult(theIcon);
+ for ( int i = 0; i < anIcon.width(); i++ )
+ {
+ for ( int j = 0; j < anIcon.height(); j++ )
+ {
+ QRgb anRgb = anIcon.pixel( i, j );
+ QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
+ qAlpha( aResult.pixel( i, j ) ));
+
+ QColor aLighterColor = aPixelColor.lighter(theLighterValue);
+ aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
+ aLighterColor.blue(), aLighterColor.alpha() ) );
+ }
+ }
+ return QPixmap::fromImage(aResult);
+}
}
#include "ModuleBase.h"
+#include <QPixmap>
+
class QWidget;
class QLayout;
MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
+/**
+ * Methods to modify a resource pixmap
+ */
+//! Create composite pixmap.
+//! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
+//! specified relatively to the upper left corner of \a theIcon.
+
+//! \param theAdditionalIcon resource text of the additional pixmap
+//! \param theXShift horizontal shift
+//! \param theYShift vertical shift
+//! \param theIcon resource text of the background pixmap
+//! \return resulting pixmap
+MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
+ const int theYShift, const QString& theIcon);
+
+//! Generates the pixmap lighter than the resources pixmap.
+//! Pixmap \a theIcon is lighted according to the given value.
+//! If the lighter value is greater than 100, this functions returns a lighter pixmap.
+//! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
+//! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
+
+//! \param resource text of the pixmap
+//! \param theLighterValue a lighter factor
+//! \return resulting pixmap
+MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
}
#endif
else
return QVariant();
case Qt::DecorationRole:
- return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
+ return XGUI_Workshop::featureIcon(aFeature);
case Qt::ToolTipRole:
return tr("Feature object");
case Qt::ForegroundRole:
ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber());
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
if (aFeature)
- return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
+ return XGUI_Workshop::featureIcon(aFeature);
}
}
break;
QMap<QString, QString> XGUI_Workshop::myIcons;
-QString XGUI_Workshop::featureIcon(const std::string& theId)
+QPixmap XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
{
- QString aId(theId.c_str());
- if (myIcons.contains(aId))
- return myIcons[aId];
- return QString();
+ QPixmap aPixmap;
+
+ std::string aKind = theFeature->getKind();
+ QString aId(aKind.c_str());
+ if (!myIcons.contains(aId))
+ return aPixmap;
+
+ QString anIconString = myIcons[aId];
+
+ ModelAPI_ExecState aState = theFeature->data()->execState();
+ switch(aState) {
+ case ModelAPI_StateDone:
+ case ModelAPI_StateNothing:
+ aPixmap = QPixmap(anIconString);
+ break;
+ case ModelAPI_StateMustBeUpdated: {
+ aPixmap = ModuleBase_Tools::lighter(anIconString);
+ }
+ break;
+ case ModelAPI_StateExecFailed: {
+ aPixmap = ModuleBase_Tools::composite(":pictures/exec_state_failed.png",
+ 12, 12, anIconString);
+ }
+ break;
+ case ModelAPI_StateInvalidArgument: {
+ aPixmap = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
+ 12, 12, anIconString);
+ }
+ break;
+ default: break;
+ }
+
+ return aPixmap;
}
XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
#include <Events_Listener.h>
#include <ModuleBase_Definitions.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
#include <QObject>
#include <QMap>
-#include <QIcon>
#include <QKeySequence>
+#include <QPixmap>
class XGUI_MainWindow;
class XGUI_Command;
}
//! Returns icon name according to feature Id
- static QString featureIcon(const std::string& theId);
+ static QPixmap featureIcon(const FeaturePtr& theFeature);
//! Activates or deactivates a part
//! If PartPtr is Null pointer then PartSet will be activated
<file>pictures/tile_views.png</file>
<file>pictures/new_view.png</file>
<file>pictures/edit.png</file>
+
+ <file>pictures/exec_state_failed.png</file>
+ <file>pictures/exec_state_invalid_parameters.png</file>
+
<file>pictures/assembly.png</file>
<file>pictures/activate.png</file>
<file>pictures/delete.png</file>