1 #include "XGUI_ViewBackground.h"
4 \brief Default constructor.
5 Creates invalid background data.
7 XGUI_ViewBackground::XGUI_ViewBackground()
8 : myTextureMode(XGUI::CenterTexture),
9 myGradientType(XGUI::NoGradient),
12 setMode(XGUI::NoBackground);
17 Creates background data initialized with the specified color
20 XGUI_ViewBackground::XGUI_ViewBackground(const QColor& theColor)
21 : myTextureMode(XGUI::CenterTexture),
22 myGradientType(XGUI::NoGradient),
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
36 XGUI_ViewBackground::XGUI_ViewBackground(XGUI::GradientType type, const QColor& c1,
38 : myTextureMode(XGUI::CenterTexture),
39 myGradientType(XGUI::NoGradient),
42 setGradient(type, c1, c2);
47 Creates background data initialized with the arbirtary gradient data
48 \param grad gradient data
50 XGUI_ViewBackground::XGUI_ViewBackground(const QGradient& grad)
51 : myTextureMode(XGUI::CenterTexture),
52 myGradientType(XGUI::NoGradient),
61 XGUI_ViewBackground::~XGUI_ViewBackground()
66 \brief Compares two background data objects
68 bool XGUI_ViewBackground::operator==(const XGUI_ViewBackground& other) const
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);
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
81 bool XGUI_ViewBackground::isValid() const
83 return myMode != XGUI::NoBackground;
87 \brief Get file name used as a texture image
88 \return path to the texture image file
89 \sa setTexture(), setTextureShown()
91 XGUI::TextureMode XGUI_ViewBackground::texture(QString& fileName) const
93 fileName = myFileName;
98 \brief Set file name to be used as a texture image.
100 \note To show texture image on the background it is necessary to call additionally
101 setTextureShown() method.
103 \param fileName path to the texture image file name
104 \param m texture mode (CenterTexture by default)
105 \sa texture(), setTextureShown()
107 void XGUI_ViewBackground::setTexture(const QString& fileName, const XGUI::TextureMode m)
109 myFileName = fileName;
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()
118 bool XGUI_ViewBackground::isTextureShown() const
120 return myTextureShown;
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()
128 void XGUI_ViewBackground::setTextureShown(bool on)
134 \brief Get background color. Returns null QColor if color is not set
135 \return solid background color
136 \sa setColor(), mode()
138 QColor XGUI_ViewBackground::color() const
140 return myColors.count() > 0 ? myColors[0] : QColor();
144 \brief Set background color and switch to the ColorBackground mode
148 void XGUI_ViewBackground::setColor(const QColor& c)
152 setMode(XGUI::ColorBackground);
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()
164 int XGUI_ViewBackground::gradient(QColor& c1, QColor& c2) const
166 c1 = myColors.count() > 0 ? myColors[0] : QColor();
167 c2 = myColors.count() > 1 ? myColors[1] : (myColors.count() > 0 ? myColors[0] : QColor());
168 return myGradientType;
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()
179 void XGUI_ViewBackground::setGradient(XGUI::GradientType type, const QColor& c1, const QColor& c2)
182 myColors << c1 << c2;
183 myGradientType = type;
184 setMode(XGUI::SimpleGradientBackground);
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()
195 const QGradient* XGUI_ViewBackground::gradient() const
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()
205 void XGUI_ViewBackground::setGradient(const QGradient& grad)
208 setMode(XGUI::CustomGradientBackground);