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 QString& theIcon)
49 QImage anIcon(theIcon);
50 QImage anAditional(theAdditionalIcon);
55 int anAddWidth = anAditional.width();
56 int anAddHeight = anAditional.height();
58 int aWidth = anIcon.width();
59 int aHeight = anIcon.height();
61 int aStartWidthPos = aWidth - anAddWidth - 1;
62 int aStartHeightPos = aHeight - anAddHeight - 1;
64 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
66 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
68 if (qAlpha(anAditional.pixel(i, j)) > 0)
69 anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
72 return QPixmap::fromImage(anIcon);
75 QPixmap lighter(const QString& theIcon, const int theLighterValue)
77 QImage anIcon(theIcon);
81 QImage aResult(theIcon);
82 for ( int i = 0; i < anIcon.width(); i++ )
84 for ( int j = 0; j < anIcon.height(); j++ )
86 QRgb anRgb = anIcon.pixel( i, j );
87 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
88 qAlpha( aResult.pixel( i, j ) ));
90 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
91 aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
92 aLighterColor.blue(), aLighterColor.alpha() ) );
95 return QPixmap::fromImage(aResult);