Salome HOME
Issue #412: Crash on delete sketch line with constraints
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index b95b5bc9f41eeb8144c94bec40dbc92b9f21e3cc..06e8fb08dc8befc26ccd7f1dda8c3304313598eb 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_Tools.cpp
 // Created:     11 July 2014
 // Author:      Vitaly Smetannikov
@@ -7,6 +9,7 @@
 #include <QLayout>
 #include <QPainter>
 #include <QBitmap>
+#include <QDoubleSpinBox>
 
 namespace ModuleBase_Tools {
 
@@ -25,7 +28,7 @@ void adjustMargins(QLayout* theLayout)
 {
   if(!theLayout)
     return;
-  theLayout->setContentsMargins(2, 5, 5, 2);
+  theLayout->setContentsMargins(2, 5, 2, 5);
   theLayout->setSpacing(4);
 }
 
@@ -44,8 +47,7 @@ void zeroMargins(QLayout* theLayout)
   theLayout->setSpacing(5);
 }
 
-QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
-                  const int theYShift, const QString& theIcon)
+QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
 {
   QImage anIcon(theIcon);
   QImage anAditional(theAdditionalIcon);
@@ -53,12 +55,21 @@ QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
   if (anIcon.isNull())
     return QPixmap();
 
-  for (int i = theXShift; i < anAditional.width() + theXShift && i < anIcon.width(); i++)
+  int anAddWidth = anAditional.width();
+  int anAddHeight = anAditional.height();
+
+  int aWidth = anIcon.width();
+  int aHeight = anIcon.height();
+
+  int aStartWidthPos = aWidth - anAddWidth - 1;
+  int aStartHeightPos = aHeight - anAddHeight - 1;
+
+  for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
   {
-    for (int j = theYShift; j < anAditional.height() + theYShift && j < anIcon.height(); j++)
+    for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
     {
-      if (qAlpha(anAditional.pixel(i - theXShift, j - theYShift)) > 0)
-        anIcon.setPixel(i, j, anAditional.pixel(i - theXShift, j - theYShift));
+      if (qAlpha(anAditional.pixel(i, j)) > 0)
+        anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
     }
   }
   return QPixmap::fromImage(anIcon);
@@ -87,6 +98,13 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue)
   return QPixmap::fromImage(aResult);
 }
 
+void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
+{
+  bool isBlocked = theSpin->blockSignals(true);
+  theSpin->setValue(theValue);
+  theSpin->blockSignals(isBlocked);
+}
+
 }