Salome HOME
porting to sketcher in GEOM
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PrsZone.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_PrsZone.h"
24
25 #include <QBrush>
26 #include <QPen>
27
28 //=======================================================================
29 // name    : HYDROGUI_PrsZone
30 // Purpose : Constructor
31 //=======================================================================
32 HYDROGUI_PrsZone::HYDROGUI_PrsZone( const Handle(HYDROData_Entity)& theObject )
33 : HYDROGUI_Prs( theObject ),
34   myZoneItem( 0 ),
35   myFillingColor( Qt::transparent ),
36   myBorderColor( Qt::transparent )
37 {
38 }
39
40 //=======================================================================
41 // name    : HYDROGUI_PrsZone
42 // Purpose : Destructor
43 //=======================================================================
44 HYDROGUI_PrsZone::~HYDROGUI_PrsZone()
45 {
46 }
47
48 //================================================================
49 // Function : setPath
50 // Purpose  : 
51 //================================================================
52 void HYDROGUI_PrsZone::setPath( const QPainterPath& thePath )
53 {
54   myPath = thePath;
55 }
56
57 //================================================================
58 // Function : getPath
59 // Purpose  : 
60 //================================================================
61 QPainterPath HYDROGUI_PrsZone::getPath() const
62 {
63   return myPath;
64 }
65
66 //================================================================
67 // Function : setFillingColor
68 // Purpose  : 
69 //================================================================
70 void HYDROGUI_PrsZone::setFillingColor( const QColor& theColor )
71 {
72   myFillingColor = theColor;
73 }
74
75 //================================================================
76 // Function : getFillingColor
77 // Purpose  : 
78 //================================================================
79 QColor HYDROGUI_PrsZone::getFillingColor() const
80 {
81   return myFillingColor;
82 }
83
84 //================================================================
85 // Function : setBorderColor
86 // Purpose  : 
87 //================================================================
88 void HYDROGUI_PrsZone::setBorderColor( const QColor& theColor )
89 {
90   myBorderColor = theColor;
91 }
92
93 //================================================================
94 // Function : getBorderColor
95 // Purpose  : 
96 //================================================================
97 QColor HYDROGUI_PrsZone::getBorderColor() const
98 {
99   return myBorderColor;
100 }
101
102 //================================================================
103 // Function : boundingRect
104 // Purpose  : 
105 //================================================================
106 QRectF HYDROGUI_PrsZone::boundingRect() const
107 {
108   return myZoneItem->boundingRect();
109 }
110
111 //================================================================
112 // Function : compute
113 // Purpose  : 
114 //================================================================
115 void HYDROGUI_PrsZone::compute()
116 {
117   if( !myZoneItem )
118   {
119     myZoneItem = new QGraphicsPathItem( this );
120     addToGroup( myZoneItem );
121   }
122   
123   QPainterPath aPath( myPath );
124   //aPath.setFillRule( Qt::WindingFill );
125   aPath.setFillRule( Qt::OddEvenFill ); // ouv: for correct drawing the paths with holes
126
127   myZoneItem->setPath( aPath );
128   myZoneItem->setBrush( QBrush( myFillingColor ) );
129   myZoneItem->setPen( QPen( myBorderColor ) );
130 }
131
132 //================================================================
133 // Function : checkHighlight
134 // Purpose  : 
135 //================================================================
136 bool HYDROGUI_PrsZone::checkHighlight( double theX, double theY, QCursor& theCursor ) const
137 {
138   // to do
139   return false;
140 }
141
142 //================================================================
143 // Function : select
144 // Purpose  : 
145 //================================================================
146 bool HYDROGUI_PrsZone::select( double theX, double theY, const QRectF& theRect )
147 {
148   return GraphicsView_Object::select( theX, theY, theRect );
149 }
150
151 //================================================================
152 // Function : unselect
153 // Purpose  : 
154 //================================================================
155 void HYDROGUI_PrsZone::unselect()
156 {
157   GraphicsView_Object::unselect();
158
159   // ouv: tmp
160   QPen aPen = myZoneItem->pen();
161   aPen.setColor( Qt::black );
162   aPen.setWidth( 1 );
163   myZoneItem->setPen( aPen );
164 }
165
166 //================================================================
167 // Function : setSelected
168 // Purpose  : 
169 //================================================================
170 void HYDROGUI_PrsZone::setSelected( bool theState )
171 {
172   GraphicsView_Object::setSelected( theState );
173
174   // ouv: tmp
175   QPen aPen = myZoneItem->pen();
176   aPen.setColor( theState ? Qt::red : Qt::black );
177   aPen.setWidth( theState ? 2 : 1 );
178   myZoneItem->setPen( aPen );
179 }