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