1 // Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ImageComposer_Image.h"
21 #include "ImageComposer_CropOperator.h"
22 #include "ImageComposer_CutOperator.h"
23 #include "ImageComposer_FuseOperator.h"
24 #include "ImageComposer_MetaTypes.h"
28 QColor ImageComposer_Image::myDefaultBackground = TRANSPARENT;
33 ImageComposer_Image::ImageComposer_Image()
40 ImageComposer_Image::ImageComposer_Image( const ImageComposer_Image& theImage )
42 myTransform( theImage.myTransform )
49 ImageComposer_Image::ImageComposer_Image( const QImage& theImage )
57 ImageComposer_Image::~ImageComposer_Image()
62 Get current image transformation
63 @return current image transformation
65 QTransform ImageComposer_Image::transform() const
71 Change current image transformation
72 @param theTransform a new image transformation
74 void ImageComposer_Image::setTransform( const QTransform& theTransform )
76 myTransform = theTransform;
80 Change current image transformation
81 @param theDx the image translation along X axis of the global CS
82 @param theDy the image translation along Y axis of the global CS
83 @param theRotationDeg the image rotation in degrees around the image center
85 void ImageComposer_Image::setLocalTransform( qreal theDx, qreal theDy, qreal theRotationDeg )
88 aTr.translate( width()*0.5, height()*0.5 );
89 aTr.rotate( theRotationDeg );
90 aTr.translate( -width()*0.5, -height()*0.5 );
91 aTr.translate( theDx, theDy );
96 Get image's bounding rectangle in the global CS
97 @return image's bounding rectangle in the global CS
99 QRectF ImageComposer_Image::boundingRect() const
101 QRect aRect( 0, 0, width(), height() );
102 return myTransform.mapToPolygon( aRect ).boundingRect();
106 Draw the image using the given painter
107 @param thePainter the painter for image drawing
109 void ImageComposer_Image::draw( QPainter& thePainter ) const
112 thePainter.setTransform( myTransform, true );
113 thePainter.drawImage( 0, 0, *this );
114 thePainter.restore();
118 Operator of another image assignment
119 @param theImage the image to assign
120 @return the assigned image
122 const ImageComposer_Image& ImageComposer_Image::operator = ( const ImageComposer_Image& theImage )
124 myTransform = theImage.myTransform;
125 QImage::operator = ( ( const QImage& ) theImage );
130 Operator of another image assignment
131 @param theImage the image to assign
132 @return the assigned image
134 const QImage& ImageComposer_Image::operator = ( const QImage& theImage )
136 QImage::operator = ( ( const QImage& ) theImage );
141 Apply the given operator to the image
142 @param theOperator the operator to be applied
143 @param theImage the additional image to compose (optional)
144 @return the result image
146 ImageComposer_Image ImageComposer_Image::apply( const ImageComposer_Operator& theOperator,
147 const QVariant& theOtherObj ) const
150 aVarData.setValue<ImageComposer_Image>( *this );
152 return theOperator.process( aVarData, theOtherObj );
156 Get default background color used for image operators
157 @return default background color
159 QColor ImageComposer_Image::defaultBackground()
161 return myDefaultBackground;
165 Change default background color used for image operators
166 @param theDefaultBackground a new default background color
168 void ImageComposer_Image::setDefaultBackground( const QColor& theDefaultBackground )
170 myDefaultBackground = theDefaultBackground;
174 Operator of image cropping by a rectangle
175 @param theRect the rectangle for cropping
176 @return cropped image
178 ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) const
181 aPath.addRect( theRect );
182 return operator &( aPath );
186 Operator of image cropping by a path
187 @param thePath the path for cropping
188 @return cropped image
190 ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePath ) const
192 ImageComposer_CropOperator anOp;
193 anOp.setArgs( myDefaultBackground );
196 aVarData.setValue<QPainterPath>( thePath );
198 return apply( anOp, aVarData );
202 Operator of image cutting by another image
203 @param theImage the image for cutting
206 ImageComposer_Image ImageComposer_Image::operator & ( const ImageComposer_Image& theImage ) const
208 ImageComposer_CutOperator anOp;
209 anOp.setArgs( myDefaultBackground );
212 aVarData.setValue<ImageComposer_Image>( theImage );
214 return apply( anOp, aVarData );
218 Operator of image fusing with another image
219 @param theImage the image for fusing
222 ImageComposer_Image ImageComposer_Image::operator | ( const ImageComposer_Image& theImage ) const
224 ImageComposer_FuseOperator anOp;
225 anOp.setArgs( myDefaultBackground );
228 aVarData.setValue<ImageComposer_Image>( theImage );
230 return apply( anOp, aVarData );