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