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 int anAddWidth = anAditional.width();
57 int anAddHeight = anAditional.height();
59 int aWidth = anIcon.width();
60 int aHeight = anIcon.height();
62 int aStartWidthPos = aWidth-anAddWidth-1;
63 int aStartHeightPos = aHeight-anAddHeight-1;
65 for (int i = 0; i < anAddWidth; i++)
67 for (int j = 0; j < anAddHeight; j++)
69 if (qAlpha(anAditional.pixel(i, j)) > 0)
70 anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
73 return QPixmap::fromImage(anIcon);
76 QPixmap lighter(const QString& theIcon, const int theLighterValue)
78 QImage anIcon(theIcon);
82 QImage aResult(theIcon);
83 for ( int i = 0; i < anIcon.width(); i++ )
85 for ( int j = 0; j < anIcon.height(); j++ )
87 QRgb anRgb = anIcon.pixel( i, j );
88 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
89 qAlpha( aResult.pixel( i, j ) ));
91 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
92 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
93 aLighterColor.blue(), aLighterColor.alpha() ) );
96 return QPixmap::fromImage(aResult);