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