1 #include "XGUI_ViewBackground.h"
5 \brief Default constructor.
6 Creates invalid background data.
8 XGUI_ViewBackground::XGUI_ViewBackground()
9 : myTextureMode( XGUI::CenterTexture ),
10 myGradientType( XGUI::NoGradient ),
11 myTextureShown( false )
13 setMode( XGUI::NoBackground );
18 Creates background data initialized with the specified color
21 XGUI_ViewBackground::XGUI_ViewBackground( const QColor& theColor )
22 : myTextureMode( XGUI::CenterTexture ),
23 myGradientType( XGUI::NoGradient ),
24 myTextureShown( false )
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
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 )
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 ),
53 myTextureShown( false )
61 XGUI_ViewBackground::~XGUI_ViewBackground()
66 \brief Compares two background data objects
68 bool XGUI_ViewBackground::operator==( const XGUI_ViewBackground& other ) const
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 );
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
85 bool XGUI_ViewBackground::isValid() const
87 return myMode != XGUI::NoBackground;
92 \brief Get file name used as a texture image
93 \return path to the texture image file
94 \sa setTexture(), setTextureShown()
96 XGUI::TextureMode XGUI_ViewBackground::texture( QString& fileName ) const
98 fileName = myFileName;
103 \brief Set file name to be used as a texture image.
105 \note To show texture image on the background it is necessary to call additionally
106 setTextureShown() method.
108 \param fileName path to the texture image file name
109 \param m texture mode (CenterTexture by default)
110 \sa texture(), setTextureShown()
112 void XGUI_ViewBackground::setTexture( const QString& fileName, const XGUI::TextureMode m )
114 myFileName = fileName;
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()
123 bool XGUI_ViewBackground::isTextureShown() const
125 return myTextureShown;
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()
133 void XGUI_ViewBackground::setTextureShown( bool on )
139 \brief Get background color. Returns null QColor if color is not set
140 \return solid background color
141 \sa setColor(), mode()
143 QColor XGUI_ViewBackground::color() const
145 return myColors.count() > 0 ? myColors[0] : QColor();
149 \brief Set background color and switch to the ColorBackground mode
153 void XGUI_ViewBackground::setColor( const QColor& c )
157 setMode( XGUI::ColorBackground );
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()
169 int XGUI_ViewBackground::gradient( QColor& c1, QColor& c2 ) const
171 c1 = myColors.count() > 0 ? myColors[0] : QColor();
172 c2 = myColors.count() > 1 ? myColors[1] : ( myColors.count() > 0 ? myColors[0] : QColor() );
173 return myGradientType;
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()
184 void XGUI_ViewBackground::setGradient( XGUI::GradientType type, const QColor& c1, const QColor& c2 )
187 myColors << c1 << c2;
188 myGradientType = type;
189 setMode( XGUI::SimpleGradientBackground );
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()
200 const QGradient* XGUI_ViewBackground::gradient() const
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()
210 void XGUI_ViewBackground::setGradient( const QGradient& grad )
213 setMode( XGUI::CustomGradientBackground );