Salome HOME
Split PyConsole in order to be used easily outside GUI of SALOME.
[modules/gui.git] / src / Qtx / QtxSplash.h
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
23 // File   : QtxSplash.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #ifndef QTXSPLASH_H
27 #define QTXSPLASH_H
28
29 #include "Qtx.h"
30
31 #include <QWidget>
32 #include <QPixmap>
33 #include <QGradient>
34 #include <QMap>
35
36 #ifdef WIN32
37 #pragma warning( disable:4251 )
38 #endif
39
40 class QtxResourceMgr;
41
42 class QTX_EXPORT QtxSplash : public QWidget
43 {
44   Q_OBJECT
45
46 private:
47   QtxSplash( const QPixmap& );
48
49 public:
50   //! Progress bar position and direction
51   typedef enum {
52     LeftSide     = 0x0001,      //!< progress bar is displayed at the left side
53     RightSide    = 0x0002,      //!< progress bar is displayed at the right side
54     TopSide      = 0x0004,      //!< progress bar is displayed at the top side
55     BottomSide   = 0x0008,      //!< progress bar is displayed at the bottom side
56     LeftToRight  = 0x0010,      //!< show progress from left to right (from top to bottom)
57     RightToLeft  = 0x0020       //!< show progress from right to left (from bottom to top)
58   } ProgressBarFlags;
59   
60   virtual ~QtxSplash();
61   
62   static QtxSplash* splash( const QPixmap& = QPixmap() );
63   
64   static void       setStatus( const QString&, const int = -1 );
65   static void       setError( const QString&, const QString& = QString(), const int = -1 );
66   
67   void              setPixmap( const QPixmap& );
68   QPixmap           pixmap() const;
69   
70   void              setHideOnClick( const bool );
71   bool              hideOnClick() const;
72
73   void              setProgressVisible( const bool );
74   bool              progressVisible() const;
75
76   void              setMessageVisible( const bool );
77   bool              messageVisible() const;
78
79   void              setPercentageVisible( const bool );
80   bool              percentageVisible() const;
81
82   void              setTotalSteps( const int );
83   int               totalSteps() const;
84   
85   void              setProgress( const int );
86   void              setProgress( const int, const int );
87   int               progress() const;
88   
89   void              setMargin( const int );
90   int               margin() const;
91   
92   void              setProgressWidth( const int );
93   int               progressWidth() const; 
94
95   void              setProgressFlags( const int );
96   int               progressFlags() const;
97   
98   void              setProgressColors( const QColor&, 
99                                        const QColor& = QColor(),
100                                        const Qt::Orientation = Qt::Vertical );
101   void              setProgressColors( const QGradient& );
102   const QGradient*  progressColors() const;
103   
104   void              setOpacity( const double );
105   double            opacity() const;
106   
107   void              setTextAlignment( const int );
108   int               textAlignment() const;
109   
110   void              setTextColors( const QColor&, const QColor& = QColor() );
111   void              textColors( QColor&, QColor& ) const;
112   
113   void              setConstantInfo( const QString& info );
114   QString           constantInfo() const;
115
116   void              setOption( const QString&, const QString& );
117   QString           option( const QString& ) const;
118
119   QString           message() const;
120   
121   int               error() const;
122   
123   void              finish( QWidget* );
124   void              repaint();
125   
126   void              readSettings( QtxResourceMgr*, const QString& = QString() );
127
128 public slots:
129   void              setMessage( const QString&, 
130                                 const int,
131                                 const QColor& = QColor() );
132   void              setMessage( const QString& );
133   void              clear();
134   
135 protected:
136   virtual void      mousePressEvent( QMouseEvent* );
137   virtual void      customEvent( QEvent* );
138   virtual void      paintEvent( QPaintEvent* );
139
140   virtual void      drawContents( QPainter* );
141   
142   virtual void      drawProgressBar( QPainter* );
143   virtual void      drawMessage( QPainter* );
144
145 private:
146   void              drawContents();
147   void              setError( const int );
148   QString           fullMessage() const;
149
150 private:
151   typedef QMap<QString, QString> OptMap;
152       
153 private:
154   static QtxSplash* mySplash;
155   
156   QPixmap           myPixmap;           //!< splash pixmap
157   QString           myInfo;             //!< constant info
158   QString           myMessage;          //!< current status message
159   int               myAlignment;        //!< text alignment flags (Qt::Alignment)
160   QColor            myColor;            //!< text color
161   QColor            myShadowColor;      //!< text shadow color
162   bool              myHideOnClick;      //!< 'hide on click' flag
163   int               myProgress;         //!< current progress
164   int               myTotal;            //!< total progress steps
165   QGradient         myGradient;         //!< progress bar custom gradient
166   int               myProgressWidth;    //!< progress bar width
167   int               myProgressFlags;    //!< progress bar flags (QtxSplash::ProgressBarFlags)
168   int               myMargin;           //!< margin (for progress bar and status message)
169   double            myOpacity;          //!< progress bar / status message opacity
170   int               myError;            //!< error code
171   OptMap            myOptions;          //!< constant info options
172   bool              myShowProgress;     //!< 'show progress bar' flag
173   bool              myShowMessage;      //!< 'show status message' flag
174   bool              myShowPercent;      //!< 'show percentage' flag
175 };
176
177 #endif