1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_Tools.cpp
4 // Created: 11 July 2014
5 // Author: Vitaly Smetannikov
7 #include "ModuleBase_Tools.h"
9 #include <ModelAPI_Result.h>
10 #include <ModelAPI_Data.h>
16 #include <QDoubleSpinBox>
18 namespace ModuleBase_Tools {
20 //******************************************************************
22 //******************************************************************
24 void adjustMargins(QWidget* theWidget)
28 adjustMargins(theWidget->layout());
31 void adjustMargins(QLayout* theLayout)
35 theLayout->setContentsMargins(2, 5, 2, 5);
36 theLayout->setSpacing(4);
39 void zeroMargins(QWidget* theWidget)
43 zeroMargins(theWidget->layout());
46 void zeroMargins(QLayout* theLayout)
50 theLayout->setContentsMargins(0, 0, 0, 0);
51 theLayout->setSpacing(5);
54 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
56 QImage anIcon(theIcon);
57 QImage anAditional(theAdditionalIcon);
62 int anAddWidth = anAditional.width();
63 int anAddHeight = anAditional.height();
65 int aWidth = anIcon.width();
66 int aHeight = anIcon.height();
68 int aStartWidthPos = aWidth - anAddWidth - 1;
69 int aStartHeightPos = aHeight - anAddHeight - 1;
71 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
73 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
75 if (qAlpha(anAditional.pixel(i, j)) > 0)
76 anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
79 return QPixmap::fromImage(anIcon);
82 QPixmap lighter(const QString& theIcon, const int theLighterValue)
84 QImage anIcon(theIcon);
88 QImage aResult(theIcon);
89 for ( int i = 0; i < anIcon.width(); i++ )
91 for ( int j = 0; j < anIcon.height(); j++ )
93 QRgb anRgb = anIcon.pixel( i, j );
94 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
95 qAlpha( aResult.pixel( i, j ) ));
97 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
98 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
99 aLighterColor.blue(), aLighterColor.alpha() ) );
102 return QPixmap::fromImage(aResult);
105 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
107 bool isBlocked = theSpin->blockSignals(true);
108 theSpin->setValue(theValue);
109 theSpin->blockSignals(isBlocked);
112 QString objectInfo(const ObjectPtr& theObj)
114 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
115 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
116 QString aFeatureStr = "feature";
118 aFeatureStr.append("(Result)");
119 aFeature = ModelAPI_Feature::feature(aRes);
121 if (aFeature.get()) {
122 aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
123 if (aFeature->data().get() && aFeature->data()->isValid())
124 aFeatureStr.append(QString("(name=%1)").arg(aFeature->data()->name().c_str()).toStdString().c_str());