]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Tools.cpp
Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
1 // File:        ModuleBase_Tools.cpp
2 // Created:     11 July 2014
3 // Author:      Vitaly Smetannikov
4
5 #include "ModuleBase_Tools.h"
6 #include <QWidget>
7 #include <QLayout>
8 #include <QPainter>
9 #include <QBitmap>
10
11 namespace ModuleBase_Tools {
12
13 //******************************************************************
14
15 //******************************************************************
16
17 void adjustMargins(QWidget* theWidget)
18 {
19   if(!theWidget)
20     return;
21   adjustMargins(theWidget->layout());
22 }
23
24 void adjustMargins(QLayout* theLayout)
25 {
26   if(!theLayout)
27     return;
28   theLayout->setContentsMargins(2, 5, 5, 2);
29   theLayout->setSpacing(4);
30 }
31
32 void zeroMargins(QWidget* theWidget)
33 {
34   if(!theWidget)
35     return;
36   zeroMargins(theWidget->layout());
37 }
38
39 void zeroMargins(QLayout* theLayout)
40 {
41   if(!theLayout)
42     return;
43   theLayout->setContentsMargins(0, 0, 0, 0);
44   theLayout->setSpacing(5);
45 }
46
47 QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
48                   const int theYShift, const QString& theIcon)
49 {
50   QImage anIcon(theIcon);
51   QImage anAditional(theAdditionalIcon);
52
53   if (anIcon.isNull())
54     return QPixmap();
55
56   for (int i = theXShift; i < anAditional.width() + theXShift && i < anIcon.width(); i++)
57   {
58     for (int j = theYShift; j < anAditional.height() + theYShift && j < anIcon.height(); j++)
59     {
60       if (qAlpha(anAditional.pixel(i - theXShift, j - theYShift)) > 0)
61         anIcon.setPixel(i, j, anAditional.pixel(i - theXShift, j - theYShift));
62     }
63   }
64   return QPixmap::fromImage(anIcon);
65 }
66
67 QPixmap lighter(const QString& theIcon, const int theLighterValue)
68 {
69   QImage anIcon(theIcon);
70   if (anIcon.isNull())
71     return QPixmap();
72
73   QImage aResult(theIcon);
74   for ( int i = 0; i < anIcon.width(); i++ )
75   {
76     for ( int j = 0; j < anIcon.height(); j++ )
77     {
78       QRgb anRgb = anIcon.pixel( i, j );
79       QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
80                          qAlpha( aResult.pixel( i, j ) ));
81
82       QColor aLighterColor = aPixelColor.lighter(theLighterValue);
83       aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
84                                     aLighterColor.blue(), aLighterColor.alpha() ) );
85     }
86   }
87   return QPixmap::fromImage(aResult);
88 }
89
90 }
91
92