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