X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FModuleBase%2FModuleBase_Tools.cpp;h=06e8fb08dc8befc26ccd7f1dda8c3304313598eb;hb=074b1d850036614d4a08999c4bc4e8630db63d2b;hp=3f0069eca9640597f7c35a9033f82e48a6bc7d1d;hpb=141af0409801857d641e2bf61cd414b373e65b0b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 3f0069eca..06e8fb08d 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1,26 +1,110 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModuleBase_Tools.cpp // Created: 11 July 2014 // Author: Vitaly Smetannikov #include "ModuleBase_Tools.h" -#include -#include +#include +#include +#include +#include +#include -namespace ModuleBase_Tools -{ +namespace ModuleBase_Tools { + +//****************************************************************** //****************************************************************** -boost::shared_ptr shape(ResultPtr theResult) + +void adjustMargins(QWidget* theWidget) +{ + if(!theWidget) + return; + adjustMargins(theWidget->layout()); +} + +void adjustMargins(QLayout* theLayout) { - ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); - if (aBody) - return aBody->shape(); + if(!theLayout) + return; + theLayout->setContentsMargins(2, 5, 2, 5); + theLayout->setSpacing(4); +} - ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast(theResult); - if (aConstruct) - return aConstruct->shape(); +void zeroMargins(QWidget* theWidget) +{ + if(!theWidget) + return; + zeroMargins(theWidget->layout()); +} - return boost::shared_ptr(); +void zeroMargins(QLayout* theLayout) +{ + if(!theLayout) + return; + theLayout->setContentsMargins(0, 0, 0, 0); + theLayout->setSpacing(5); } -} \ No newline at end of file +QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon) +{ + QImage anIcon(theIcon); + QImage anAditional(theAdditionalIcon); + + if (anIcon.isNull()) + return QPixmap(); + + int anAddWidth = anAditional.width(); + int anAddHeight = anAditional.height(); + + int aWidth = anIcon.width(); + int aHeight = anIcon.height(); + + int aStartWidthPos = aWidth - anAddWidth - 1; + int aStartHeightPos = aHeight - anAddHeight - 1; + + for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++) + { + for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++) + { + if (qAlpha(anAditional.pixel(i, j)) > 0) + anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j)); + } + } + return QPixmap::fromImage(anIcon); +} + +QPixmap lighter(const QString& theIcon, const int theLighterValue) +{ + QImage anIcon(theIcon); + if (anIcon.isNull()) + return QPixmap(); + + QImage aResult(theIcon); + for ( int i = 0; i < anIcon.width(); i++ ) + { + for ( int j = 0; j < anIcon.height(); j++ ) + { + QRgb anRgb = anIcon.pixel( i, j ); + QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb), + qAlpha( aResult.pixel( i, j ) )); + + QColor aLighterColor = aPixelColor.lighter(theLighterValue); + aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(), + aLighterColor.blue(), aLighterColor.alpha() ) ); + } + } + return QPixmap::fromImage(aResult); +} + +void setSpinValue(QDoubleSpinBox* theSpin, double theValue) +{ + bool isBlocked = theSpin->blockSignals(true); + theSpin->setValue(theValue); + theSpin->blockSignals(isBlocked); +} + +} + +