1 #include "XGUI_ViewBackground.h"
4 \brief Default constructor.
5 Creates invalid background data.
7 XGUI_ViewBackground::XGUI_ViewBackground()
8 : myTextureMode(XGUI::CenterTexture), myGradientType(XGUI::NoGradient), myTextureShown(false)
10 setMode(XGUI::NoBackground);
15 Creates background data initialized with the specified color
18 XGUI_ViewBackground::XGUI_ViewBackground(const QColor& theColor)
19 : myTextureMode(XGUI::CenterTexture), myGradientType(XGUI::NoGradient), myTextureShown(false)
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
32 XGUI_ViewBackground::XGUI_ViewBackground(XGUI::GradientType type, const QColor& c1,
34 : myTextureMode(XGUI::CenterTexture), myGradientType(XGUI::NoGradient), myTextureShown(false)
36 setGradient(type, c1, c2);
41 Creates background data initialized with the arbirtary gradient data
42 \param grad gradient data
44 XGUI_ViewBackground::XGUI_ViewBackground(const QGradient& grad)
45 : myTextureMode(XGUI::CenterTexture), myGradientType(XGUI::NoGradient), myTextureShown(false)
53 XGUI_ViewBackground::~XGUI_ViewBackground()
58 \brief Compares two background data objects
60 bool XGUI_ViewBackground::operator==(const XGUI_ViewBackground& other) const
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);
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
73 bool XGUI_ViewBackground::isValid() const
75 return myMode != XGUI::NoBackground;
79 \brief Get file name used as a texture image
80 \return path to the texture image file
81 \sa setTexture(), setTextureShown()
83 XGUI::TextureMode XGUI_ViewBackground::texture(QString& fileName) const
85 fileName = myFileName;
90 \brief Set file name to be used as a texture image.
92 \note To show texture image on the background it is necessary to call additionally
93 setTextureShown() method.
95 \param fileName path to the texture image file name
96 \param m texture mode (CenterTexture by default)
97 \sa texture(), setTextureShown()
99 void XGUI_ViewBackground::setTexture(const QString& fileName, const XGUI::TextureMode m)
101 myFileName = fileName;
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()
110 bool XGUI_ViewBackground::isTextureShown() const
112 return myTextureShown;
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()
120 void XGUI_ViewBackground::setTextureShown(bool on)
126 \brief Get background color. Returns null QColor if color is not set
127 \return solid background color
128 \sa setColor(), mode()
130 QColor XGUI_ViewBackground::color() const
132 return myColors.count() > 0 ? myColors[0] : QColor();
136 \brief Set background color and switch to the ColorBackground mode
140 void XGUI_ViewBackground::setColor(const QColor& c)
144 setMode(XGUI::ColorBackground);
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()
156 int XGUI_ViewBackground::gradient(QColor& c1, QColor& c2) const
158 c1 = myColors.count() > 0 ? myColors[0] : QColor();
159 c2 = myColors.count() > 1 ? myColors[1] : (myColors.count() > 0 ? myColors[0] : QColor());
160 return myGradientType;
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()
171 void XGUI_ViewBackground::setGradient(XGUI::GradientType type, const QColor& c1, const QColor& c2)
174 myColors << c1 << c2;
175 myGradientType = type;
176 setMode(XGUI::SimpleGradientBackground);
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()
187 const QGradient* XGUI_ViewBackground::gradient() const
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()
197 void XGUI_ViewBackground::setGradient(const QGradient& grad)
200 setMode(XGUI::CustomGradientBackground);