1 // File: ModuleBase_Tools.cpp
2 // Created: 11 July 2014
3 // Author: Vitaly Smetannikov
5 #include "ModuleBase_Tools.h"
11 namespace ModuleBase_Tools {
13 //******************************************************************
15 //******************************************************************
17 void adjustMargins(QWidget* theWidget)
21 adjustMargins(theWidget->layout());
24 void adjustMargins(QLayout* theLayout)
28 theLayout->setContentsMargins(2, 5, 5, 2);
29 theLayout->setSpacing(4);
32 void zeroMargins(QWidget* theWidget)
36 zeroMargins(theWidget->layout());
39 void zeroMargins(QLayout* theLayout)
43 theLayout->setContentsMargins(0, 0, 0, 0);
44 theLayout->setSpacing(5);
47 QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
48 const int theYShift, const QString& theIcon)
50 QImage anIcon(theIcon);
51 QImage anAditional(theAdditionalIcon);
56 for (int i = theXShift; i < anAditional.width() + theXShift && i < anIcon.width(); i++)
58 for (int j = theYShift; j < anAditional.height() + theYShift && j < anIcon.height(); j++)
60 if (qAlpha(anAditional.pixel(i - theXShift, j - theYShift)) > 0)
61 anIcon.setPixel(i, j, anAditional.pixel(i - theXShift, j - theYShift));
64 return QPixmap::fromImage(anIcon);
67 QPixmap lighter(const QString& theIcon, const int theLighterValue)
69 QImage anIcon(theIcon);
73 QImage aResult(theIcon);
74 for ( int i = 0; i < anIcon.width(); i++ )
76 for ( int j = 0; j < anIcon.height(); j++ )
78 QRgb anRgb = anIcon.pixel( i, j );
79 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
80 qAlpha( aResult.pixel( i, j ) ));
82 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
83 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
84 aLighterColor.blue(), aLighterColor.alpha() ) );
87 return QPixmap::fromImage(aResult);