]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issues #267, #280 (To store and represent the errors, Status icons in Object Browser )
authornds <natalia.donis@opencascade.com>
Fri, 5 Dec 2014 16:51:49 +0000 (19:51 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 5 Dec 2014 16:51:49 +0000 (19:51 +0300)
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/exec_state_failed.png [new file with mode: 0644]
src/XGUI/pictures/exec_state_invalid_parameters.png [new file with mode: 0644]

index f246677ce22ad2e8a0aaff7dbac4d01854c3c991..b95b5bc9f41eeb8144c94bec40dbc92b9f21e3cc 100644 (file)
@@ -5,6 +5,8 @@
 #include "ModuleBase_Tools.h"
 #include <QWidget>
 #include <QLayout>
+#include <QPainter>
+#include <QBitmap>
 
 namespace ModuleBase_Tools {
 
@@ -42,7 +44,48 @@ void zeroMargins(QLayout* theLayout)
   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);
+}
 
 }
 
index 1d5a448c66fd48634ba1ec5d94fc2e45b3f14cc4..3f9ca02191d0d3d9facbe797ece0bbe608b30b38 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "ModuleBase.h"
 
+#include <QPixmap>
+
 class QWidget;
 class QLayout;
 
@@ -22,6 +24,31 @@ MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
 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
index 1ed348e1c3d0d3c2347661c529b9582b96de8122..fb6a66a30806546d151734337bb957f7ea2d4930 100644 (file)
@@ -214,7 +214,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
               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:
index 2e95a24aa7b85abd5e01e0eb02e2e032893d76ce..b1ec5e74521d67bb486d046c37af56c791d0faa1 100644 (file)
@@ -329,7 +329,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
           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;
index 31c283e5d74bb63db4ebb1f1a94c0d7fdf179a2a..8a696e67ed365e7e3c8004604963703a743ce482 100644 (file)
 
 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)
index 886c78476b9f266ba9e9f78ec17744d2a5dffe9c..54e9f26fdcae4f213a317f5c4893691f00e2b0c9 100644 (file)
@@ -6,11 +6,12 @@
 #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;
@@ -143,7 +144,7 @@ Q_OBJECT
   }
 
   //! 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
index 6aaa267620b50aa984e140184e5c97758566d091..1e001dc7c0961e672414bce65b61f71fba64134d 100644 (file)
      <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>
diff --git a/src/XGUI/pictures/exec_state_failed.png b/src/XGUI/pictures/exec_state_failed.png
new file mode 100644 (file)
index 0000000..738f303
Binary files /dev/null and b/src/XGUI/pictures/exec_state_failed.png differ
diff --git a/src/XGUI/pictures/exec_state_invalid_parameters.png b/src/XGUI/pictures/exec_state_invalid_parameters.png
new file mode 100644 (file)
index 0000000..c34340c
Binary files /dev/null and b/src/XGUI/pictures/exec_state_invalid_parameters.png differ