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"
13 namespace ModuleBase_Tools {
15 //******************************************************************
17 //******************************************************************
19 void adjustMargins(QWidget* theWidget)
23 adjustMargins(theWidget->layout());
26 void adjustMargins(QLayout* theLayout)
30 theLayout->setContentsMargins(2, 5, 5, 2);
31 theLayout->setSpacing(4);
34 void zeroMargins(QWidget* theWidget)
38 zeroMargins(theWidget->layout());
41 void zeroMargins(QLayout* theLayout)
45 theLayout->setContentsMargins(0, 0, 0, 0);
46 theLayout->setSpacing(5);
49 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
51 QImage anIcon(theIcon);
52 QImage anAditional(theAdditionalIcon);
57 int anAddWidth = anAditional.width();
58 int anAddHeight = anAditional.height();
60 int aWidth = anIcon.width();
61 int aHeight = anIcon.height();
63 int aStartWidthPos = aWidth - anAddWidth - 1;
64 int aStartHeightPos = aHeight - anAddHeight - 1;
66 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
68 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
70 if (qAlpha(anAditional.pixel(i, j)) > 0)
71 anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
74 return QPixmap::fromImage(anIcon);
77 QPixmap lighter(const QString& theIcon, const int theLighterValue)
79 QImage anIcon(theIcon);
83 QImage aResult(theIcon);
84 for ( int i = 0; i < anIcon.width(); i++ )
86 for ( int j = 0; j < anIcon.height(); j++ )
88 QRgb anRgb = anIcon.pixel( i, j );
89 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
90 qAlpha( aResult.pixel( i, j ) ));
92 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
93 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
94 aLighterColor.blue(), aLighterColor.alpha() ) );
97 return QPixmap::fromImage(aResult);