From 3b80cc27cc8d8d4a7b73eace275e486ee79f81a8 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 5 Dec 2014 19:51:49 +0300 Subject: [PATCH] Issues #267, #280 (To store and represent the errors, Status icons in Object Browser ) --- src/ModuleBase/ModuleBase_Tools.cpp | 43 ++++++++++++++++++ src/ModuleBase/ModuleBase_Tools.h | 27 +++++++++++ src/XGUI/XGUI_DocumentDataModel.cpp | 2 +- src/XGUI/XGUI_PartDataModel.cpp | 2 +- src/XGUI/XGUI_Workshop.cpp | 39 ++++++++++++++-- src/XGUI/XGUI_Workshop.h | 5 +- src/XGUI/XGUI_pictures.qrc | 4 ++ src/XGUI/pictures/exec_state_failed.png | Bin 0 -> 276 bytes .../exec_state_invalid_parameters.png | Bin 0 -> 296 bytes 9 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 src/XGUI/pictures/exec_state_failed.png create mode 100644 src/XGUI/pictures/exec_state_invalid_parameters.png 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 0000000000000000000000000000000000000000..738f303716c7a97468004d9a8e5b9b5e096edf67 GIT binary patch literal 276 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3 zQ$0figD*u3fvTE4T^vI+f_?jTb2c~#xR{%mnCubKIn2kad+>tG1{Ozwqb_R>aQ)e1 znRm1`@%YT=cW>r~EqrKrT9?;u!dAn>Iy2gBwH#RM{3G9PVZYouso(xje@v){!|m{_ zA164f*&EW!et0$cv0j+y<+#i2#l)($O_O66$*ljatg_&vk=#j(lG&yDERIp0OP7jC Q0G-3&>FVdQ&MBb@0HaV|N&o-= literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c34340c9c64be3e0e73ee50af906b69329e2ee33 GIT binary patch literal 296 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3 zQ$0figD*u3fvTo^x;Tbt1c&w+axobSxXL$en7U-k9pwrZ@BW8@Ha!Us8FSX;tV!9p zS>W0^H-UqPj>-P-mp<4yJ>`?#$qNU4-Y^UO-zrqhE_L$7_o(SpZ*XkAvv-+L)uB|D z-Sb;IPsEnCzWt(|#9{7j+AR~Xlu>4D`@arj8=KkjTV=YB1#MxEh~D!slqpwV*30V3 lB=yrmAC5#$OXrr=v6qo?<5$&wWe;>BgQu&X%Q~loCIH-`XY>F7 literal 0 HcmV?d00001 -- 2.39.2