Salome HOME
0c9d505434914733a9068b543c4cb00a19a2a20f
[modules/shaper.git] / src / XGUI / XGUI_ViewBackground.cpp
1 #include "XGUI_ViewBackground.h"
2
3
4 /*!
5   \brief Default constructor.
6   Creates invalid background data.
7 */
8 XGUI_ViewBackground::XGUI_ViewBackground()
9   : myTextureMode( XGUI::CenterTexture ), 
10   myGradientType( XGUI::NoGradient ), 
11   myTextureShown( false )
12 {
13   setMode( XGUI::NoBackground );
14 }
15
16 /*!
17   \brief Constructor.
18   Creates background data initialized with the specified color
19   \param c color
20 */
21 XGUI_ViewBackground::XGUI_ViewBackground( const QColor& theColor )
22   : myTextureMode( XGUI::CenterTexture ), 
23   myGradientType( XGUI::NoGradient ), 
24   myTextureShown( false )
25 {
26   setColor( theColor );
27 }
28
29 /*!
30   \brief Constructor.
31   Creates background data initialized with the specified two-color gradient
32   \param type gradient type identifier
33   \param c1 first gradient color
34   \param c2 second gradient color
35   \note the interpretation of the gradient identifier should be done in the calling code
36 */
37 XGUI_ViewBackground::XGUI_ViewBackground( XGUI::GradientType type, const QColor& c1, const QColor& c2 )
38   : myTextureMode( XGUI::CenterTexture ), 
39   myGradientType( XGUI::NoGradient ), 
40   myTextureShown( false )
41 {
42   setGradient( type, c1, c2 );
43 }
44
45 /*!
46   \brief Constructor.
47   Creates background data initialized with the arbirtary gradient data
48   \param grad gradient data
49 */
50 XGUI_ViewBackground::XGUI_ViewBackground( const QGradient& grad )
51   : myTextureMode( XGUI::CenterTexture ), 
52   myGradientType( XGUI::NoGradient ), 
53   myTextureShown( false )
54 {
55   setGradient( grad );
56 }
57
58 /*!
59   \brief Destructor.
60 */
61 XGUI_ViewBackground::~XGUI_ViewBackground()
62 {
63 }
64
65 /*!
66   \brief Compares two background data objects
67 */
68 bool XGUI_ViewBackground::operator==( const XGUI_ViewBackground& other ) const
69 {
70   return 
71     ( myMode         == other.myMode )         && 
72     ( myTextureMode  == other.myTextureMode )  &&
73     ( myFileName     == other.myFileName )     &&
74     ( myColors       == other.myColors )       &&
75     ( myGradientType == other.myGradientType ) &&
76     ( myGradient     == other.myGradient )     &&
77     ( myTextureShown == other.myTextureShown );
78 }
79
80 /*!
81   \brief Returns \c false if background data is not set (invalid)
82   \return \c true if background data is valid or \c false otherwise
83   \sa mode()
84 */
85 bool XGUI_ViewBackground::isValid() const
86 {
87   return myMode != XGUI::NoBackground;
88 }
89
90
91 /*!
92   \brief Get file name used as a texture image
93   \return path to the texture image file
94   \sa setTexture(), setTextureShown()
95 */
96 XGUI::TextureMode XGUI_ViewBackground::texture( QString& fileName ) const
97 {
98   fileName = myFileName;
99   return myTextureMode;
100 }
101
102 /*!
103   \brief Set file name to be used as a texture image.
104
105   \note To show texture image on the background it is necessary to call additionally
106   setTextureShown() method.
107
108   \param fileName path to the texture image file name
109   \param m texture mode (CenterTexture by default)
110   \sa texture(), setTextureShown()
111 */
112 void XGUI_ViewBackground::setTexture( const QString& fileName, const XGUI::TextureMode m )
113 {
114   myFileName = fileName;
115   myTextureMode = m;
116 }
117
118 /*!
119   \brief Check if "show texture" flag is switched on
120   \return \c true if "show texture" flag is set or \c false otherwise
121   \sa setTextureShown(), texture()
122 */
123 bool XGUI_ViewBackground::isTextureShown() const
124 {
125   return myTextureShown;
126 }
127
128 /*!
129   \brief Specify if texture should be shown on the background or no.
130   \param on \c true if texture should be shown or \c false otherwise
131   \sa isTextureShown(), texture()
132 */
133 void XGUI_ViewBackground::setTextureShown( bool on )
134 {
135   myTextureShown = on;
136 }
137
138 /*!
139   \brief Get background color. Returns null QColor if color is not set
140   \return solid background color
141   \sa setColor(), mode()
142 */
143 QColor XGUI_ViewBackground::color() const
144 {
145   return myColors.count() > 0 ? myColors[0] : QColor();
146 }
147
148 /*!
149   \brief Set background color and switch to the ColorBackground mode
150   \param c color
151   \sa color(), mode()
152 */
153 void XGUI_ViewBackground::setColor( const QColor& c )
154 {
155   myColors.clear();
156   myColors << c;
157   setMode( XGUI::ColorBackground );
158 }
159
160 /*!
161   \brief Get simple gradient data.
162   Returns -1 and null QColor for \a c1 and \a c2 if gradient data is not set
163   \param c1 first gradient color is returned via this parameter
164   \param c2 second gradient color is returned via this parameter
165   \return current two-colored gradient mode type identifier
166   \note the interpretation of the gradient identifier should be done in the calling code
167   \sa setGradient(int, const QColor&, const QColor&), mode()
168 */
169 int XGUI_ViewBackground::gradient( QColor& c1, QColor& c2 ) const
170 {
171   c1 = myColors.count() > 0 ? myColors[0] : QColor();
172   c2 = myColors.count() > 1 ? myColors[1] : ( myColors.count() > 0 ? myColors[0] : QColor() );
173   return myGradientType;
174 }
175
176 /*!
177   \brief Set simple background gradient data and switch to the SimpleGradientBackground mode
178   \param type two-colored gradient mode type identifier
179   \param c1 first gradient color is returned via this parameter
180   \param c2 second gradient color is returned via this parameter
181   \note the interpretation of the gradient identifier should be done in the calling code
182   \sa gradient(QColor&, QColor&), mode()
183 */
184 void XGUI_ViewBackground::setGradient( XGUI::GradientType type, const QColor& c1, const QColor& c2 )
185 {
186   myColors.clear();
187   myColors << c1 << c2;
188   myGradientType = type;
189   setMode( XGUI::SimpleGradientBackground );
190 }
191
192 /*!
193   \brief Get complex gradient data.
194   Returns QGradient of QGradient::NoGradient if gradient data is not set
195   \note This function does not transform simple gradient data set with 
196   setGradient( const QString&, const QColor&, const QColor& ) to QGradient class
197   \return gradient data
198   \sa setGradient(const QGradient&), mode()
199 */
200 const QGradient* XGUI_ViewBackground::gradient() const
201 {
202   return &myGradient;
203 }
204
205 /*!
206   \brief Set complex background gradient data and switch to the CustomGradientBackground mode
207   \param grad gradient data (QLinearGradient, QRadialGradient or QConicalGradient)
208   \sa gradient(), mode()
209 */
210 void XGUI_ViewBackground::setGradient( const QGradient& grad )
211 {
212   myGradient = grad;
213   setMode( XGUI::CustomGradientBackground );
214 }