Salome HOME
Functionality for dynamic libraries loading is assigned to Config_ModuleReader
[modules/shaper.git] / src / XGUI / XGUI_ViewBackground.h
1 #ifndef XGUI_ViewBackground_H
2 #define XGUI_ViewBackground_H
3
4 #include "XGUI.h"
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_EXPORT 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   {
60     return !operator==(other);
61   }
62
63   bool isValid() const;
64
65   /*!
66    \brief Get background mode
67    \return current background mode
68    \sa setMode()
69    */
70   XGUI::BackgroundMode mode() const
71   {
72     return myMode;
73   }
74
75   /*!
76    \brief Set background mode
77    \param m background mode being set
78    \sa mode()
79    */
80   void setMode(const XGUI::BackgroundMode m)
81   {
82     myMode = m;
83   }
84
85   XGUI::TextureMode texture(QString&) const;
86   void setTexture(const QString&, XGUI::TextureMode = XGUI::CenterTexture);
87   bool isTextureShown() const;
88   void setTextureShown(bool);
89
90   QColor color() const;
91   void setColor(const QColor&);
92
93   int gradient(QColor&, QColor&) const;
94   void setGradient(XGUI::GradientType, const QColor&, const QColor&);
95
96   const QGradient* gradient() const;
97   void setGradient(const QGradient&);
98
99 private:
100   XGUI::BackgroundMode myMode;
101   XGUI::TextureMode myTextureMode;
102   QString myFileName;
103   QColorList myColors;
104   XGUI::GradientType myGradientType;
105   QGradient myGradient;
106   bool myTextureShown;
107 };
108
109 #endif