Salome HOME
07475c65a6688ff89ee19d53cfcb0efde8d361ce
[modules/gui.git] / src / Qtx / QtxSplash.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : QtxSplash.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 //
25 #ifndef QTXSPLASH_H
26 #define QTXSPLASH_H
27
28 #include "Qtx.h"
29
30 #include <QWidget>
31 #include <QPixmap>
32 #include <QGradient>
33 #include <QMap>
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 class QtxResourceMgr;
40
41 class QTX_EXPORT QtxSplash : public QWidget
42 {
43   Q_OBJECT
44
45 private:
46   QtxSplash( const QPixmap& );
47
48 public:
49   //! Progress bar position and direction
50   typedef enum {
51     LeftSide     = 0x0001,      //!< progress bar is displayed at the left side
52     RightSide    = 0x0002,      //!< progress bar is displayed at the right side
53     TopSide      = 0x0004,      //!< progress bar is displayed at the top side
54     BottomSide   = 0x0008,      //!< progress bar is displayed at the bottom side
55     LeftToRight  = 0x0010,      //!< show progress from left to right (from top to bottom)
56     RightToLeft  = 0x0020       //!< show progress from right to left (from bottom to top)
57   } ProgressBarFlags;
58   
59   virtual ~QtxSplash();
60   
61   static QtxSplash* splash( const QPixmap& = QPixmap() );
62   
63   static void       setStatus( const QString&, const int = -1 );
64   static void       setError( const QString&, const QString& = QString(), const int = -1 );
65   
66   void              setPixmap( const QPixmap& );
67   QPixmap           pixmap() const;
68   
69   void              setHideOnClick( const bool );
70   bool              hideOnClick() const;
71
72   void              setProgressVisible( const bool );
73   bool              progressVisible() const;
74
75   void              setMessageVisible( const bool );
76   bool              messageVisible() const;
77
78   void              setPercentageVisible( const bool );
79   bool              percentageVisible() const;
80
81   void              setTotalSteps( const int );
82   int               totalSteps() const;
83   
84   void              setProgress( const int );
85   void              setProgress( const int, const int );
86   int               progress() const;
87   
88   void              setMargin( const int );
89   int               margin() const;
90   
91   void              setProgressWidth( const int );
92   int               progressWidth() const; 
93
94   void              setProgressFlags( const int );
95   int               progressFlags() const;
96   
97   void              setProgressColors( const QColor&, 
98                                        const QColor& = QColor(),
99                                        const Qt::Orientation = Qt::Vertical );
100   void              setProgressColors( const QGradient& );
101   const QGradient*  progressColors() const;
102   
103   void              setOpacity( const double );
104   double            opacity() const;
105   
106   void              setTextAlignment( const int );
107   int               textAlignment() const;
108   
109   void              setTextColors( const QColor&, const QColor& = QColor() );
110   void              textColors( QColor&, QColor& ) const;
111   
112   void              setConstantInfo( const QString& info );
113   QString           constantInfo() const;
114
115   void              setOption( const QString&, const QString& );
116   QString           option( const QString& ) const;
117
118   QString           message() const;
119   
120   int               error() const;
121   
122   void              finish( QWidget* );
123   void              repaint();
124   
125   void              readSettings( QtxResourceMgr*, const QString& = QString() );
126
127 public slots:
128   void              setMessage( const QString&, 
129                                 const int,
130                                 const QColor& = QColor() );
131   void              setMessage( const QString& );
132   void              clear();
133   
134 protected:
135   virtual void      mousePressEvent( QMouseEvent* );
136   virtual void      customEvent( QEvent* );
137   virtual void      paintEvent( QPaintEvent* );
138
139   virtual void      drawContents( QPainter* );
140   
141   virtual void      drawProgressBar( QPainter* );
142   virtual void      drawMessage( QPainter* );
143
144 private:
145   void              drawContents();
146   void              setError( const int );
147   QString           fullMessage() const;
148
149 private:
150   typedef QMap<QString, QString> OptMap;
151       
152 private:
153   static QtxSplash* mySplash;
154   
155   QPixmap           myPixmap;           //!< splash pixmap
156   QString           myInfo;             //!< constant info
157   QString           myMessage;          //!< current status message
158   int               myAlignment;        //!< text alignment flags (Qt::Alignment)
159   QColor            myColor;            //!< text color
160   QColor            myShadowColor;      //!< text shadow color
161   bool              myHideOnClick;      //!< 'hide on click' flag
162   int               myProgress;         //!< current progress
163   int               myTotal;            //!< total progress steps
164   QGradient         myGradient;         //!< progress bar custom gradient
165   int               myProgressWidth;    //!< progress bar width
166   int               myProgressFlags;    //!< progress bar flags (QtxSplash::ProgressBarFlags)
167   int               myMargin;           //!< margin (for progress bar and status message)
168   double            myOpacity;          //!< progress bar / status message opacity
169   int               myError;            //!< error code
170   OptMap            myOptions;          //!< constant info options
171   bool              myShowProgress;     //!< 'show progress bar' flag
172   bool              myShowMessage;      //!< 'show status message' flag
173   bool              myShowPercent;      //!< 'show percentage' flag
174 };
175
176 #endif