From: nds Date: Fri, 5 Dec 2014 16:51:49 +0000 (+0300) Subject: Issues #267, #280 (To store and represent the errors, Status icons in Object Browser ) X-Git-Tag: V_0.6.0^2~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b80cc27cc8d8d4a7b73eace275e486ee79f81a8;p=modules%2Fshaper.git Issues #267, #280 (To store and represent the errors, Status icons in Object Browser ) --- diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index f246677ce..b95b5bc9f 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -5,6 +5,8 @@ #include "ModuleBase_Tools.h" #include #include +#include +#include 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); +} } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 1d5a448c6..3f9ca0219 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -7,6 +7,8 @@ #include "ModuleBase.h" +#include + 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 diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 1ed348e1c..fb6a66a30 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -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: diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 2e95a24aa..b1ec5e745 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -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(aObject); if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + return XGUI_Workshop::featureIcon(aFeature); } } break; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 31c283e5d..8a696e67e 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -76,12 +76,41 @@ QMap 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) diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 886c78476..54e9f26fd 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -6,11 +6,12 @@ #include #include #include +#include #include #include -#include #include +#include 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 diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 6aaa26762..1e001dc7c 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -55,6 +55,10 @@ pictures/tile_views.png pictures/new_view.png pictures/edit.png + + pictures/exec_state_failed.png + pictures/exec_state_invalid_parameters.png + pictures/assembly.png pictures/activate.png pictures/delete.png diff --git a/src/XGUI/pictures/exec_state_failed.png b/src/XGUI/pictures/exec_state_failed.png new file mode 100644 index 000000000..738f30371 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 index 000000000..c34340c9c Binary files /dev/null and b/src/XGUI/pictures/exec_state_invalid_parameters.png differ