]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewBackground.h
Salome HOME
1906001da9f1f7454ce6f47847621fe9838ac90f
[modules/shaper.git] / src / XGUI / XGUI_ViewBackground.h
1
2 #ifndef XGUI_ViewBackground_H
3 #define XGUI_ViewBackground_H
4
5 #include "XGUI_Constants.h"
6
7 #include <QColor>
8 #include <QGradient>
9 #include <QString>
10 #include <QCompleter>
11
12 typedef QList<QColor> QColorList;     //!< list of colors
13
14 /*!
15   \class XGUI_ViewBackground
16   \brief Stores background data
17
18   This class is used to store background data. Depending on the mode,
19   the background can be specified by:
20   - image (by assigning the file name to be used as background texture), see setTexture(), setTextureShown()
21   - single color (by assigning any color), see setColor()
22   - simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& )
23   - complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& )
24
25   The class stores all the data passed to it, so switching between different modes can be done
26   just by calling setMode() function.
27
28   \note Texture is used with combination of the background mode.
29
30   \note Two-color gradient is specified by two colors and integer identifier. The interpretation of 
31   this identifier should be done in the calling code.
32
33   \code
34   XGUI_ViewBackground bg;
35   bg.setColor( QColor(100, 100, 100) );                  // bg is switched to ColorBackground mode
36   bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to ColorBackground mode
37   QLinearGradient grad( 0,0,1,1 ); 
38   grad.setColorAt( 0.0, Qt::gray ); 
39   grad.setColorAt( 0.5, Qt::white );
40   grad.setColorAt( 1.0, Qt::green );
41   grad.setSpread( QGradient::PadSpread );
42   bg.setGradient( grad );                                // bg is switched to CustomGradientBackground mode
43   bg.setMode( ColorBackground );                    // bg is switched back to ColorBackground mode
44   bg.setTexture( "/data/images/background.png" );        // specify texture (in the centered mode by default)
45   bg.setTextureShown( true );                            // draw texture on the solid color background
46   \endcode
47 */
48 class XGUI_ViewBackground
49 {
50 public:
51     XGUI_ViewBackground();
52     XGUI_ViewBackground( const QColor& theColor );
53     XGUI_ViewBackground( XGUI::GradientType type, const QColor& theColor1, const QColor& theColor2);
54     XGUI_ViewBackground( const QGradient& );
55     virtual ~XGUI_ViewBackground();
56
57     bool operator==( const XGUI_ViewBackground&) const;
58     inline bool operator!=( const XGUI_ViewBackground& other ) const
59     { return !operator==( other ); }
60
61     bool             isValid() const;
62     
63     /*!
64       \brief Get background mode
65       \return current background mode
66       \sa setMode()
67     */
68     XGUI::BackgroundMode  mode() const { return myMode; }
69
70     /*!
71       \brief Set background mode
72       \param m background mode being set
73       \sa mode()
74     */
75     void             setMode( const XGUI::BackgroundMode m ) { myMode = m; }
76     
77     XGUI::TextureMode texture( QString& ) const;
78     void             setTexture( const QString&, XGUI::TextureMode = XGUI::CenterTexture );
79     bool             isTextureShown() const;
80     void             setTextureShown( bool );
81
82     QColor           color() const;
83     void             setColor( const QColor& );
84
85     int              gradient( QColor&, QColor& ) const;
86     void             setGradient( XGUI::GradientType, const QColor&, const QColor& );
87
88     const QGradient* gradient() const;
89     void             setGradient( const QGradient& );
90   
91 private:
92     XGUI::BackgroundMode   myMode;
93     XGUI::TextureMode      myTextureMode;
94     QString          myFileName;
95     QColorList       myColors;
96     XGUI::GradientType  myGradientType;
97     QGradient        myGradient;
98     bool             myTextureShown;
99 };
100
101 #endif