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"
12 #include <QDoubleSpinBox>
14 namespace ModuleBase_Tools {
16 //******************************************************************
18 //******************************************************************
20 void adjustMargins(QWidget* theWidget)
24 adjustMargins(theWidget->layout());
27 void adjustMargins(QLayout* theLayout)
31 theLayout->setContentsMargins(2, 5, 2, 5);
32 theLayout->setSpacing(4);
35 void zeroMargins(QWidget* theWidget)
39 zeroMargins(theWidget->layout());
42 void zeroMargins(QLayout* theLayout)
46 theLayout->setContentsMargins(0, 0, 0, 0);
47 theLayout->setSpacing(5);
50 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
52 QImage anIcon(theIcon);
53 QImage anAditional(theAdditionalIcon);
58 int anAddWidth = anAditional.width();
59 int anAddHeight = anAditional.height();
61 int aWidth = anIcon.width();
62 int aHeight = anIcon.height();
64 int aStartWidthPos = aWidth - anAddWidth - 1;
65 int aStartHeightPos = aHeight - anAddHeight - 1;
67 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
69 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
71 if (qAlpha(anAditional.pixel(i, j)) > 0)
72 anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
75 return QPixmap::fromImage(anIcon);
78 QPixmap lighter(const QString& theIcon, const int theLighterValue)
80 QImage anIcon(theIcon);
84 QImage aResult(theIcon);
85 for ( int i = 0; i < anIcon.width(); i++ )
87 for ( int j = 0; j < anIcon.height(); j++ )
89 QRgb anRgb = anIcon.pixel( i, j );
90 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
91 qAlpha( aResult.pixel( i, j ) ));
93 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
94 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
95 aLighterColor.blue(), aLighterColor.alpha() ) );
98 return QPixmap::fromImage(aResult);
101 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
103 bool isBlocked = theSpin->blockSignals(true);
104 theSpin->setValue(theValue);
105 theSpin->blockSignals(isBlocked);