Salome HOME
GUI launcher: systematize run procedure
[modules/gui.git] / src / Qtx / Qtx.h
1 // Copyright (C) 2007-2019  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:      Qtx.h
24 // Author:    Sergey TELKOV
25 //
26 #ifndef QTX_H
27 #define QTX_H
28
29 #if defined WIN32
30 #  if defined QTX_EXPORTS || defined qtx_EXPORTS
31 #    define QTX_EXPORT _declspec( dllexport )
32 #  else
33 #    define QTX_EXPORT _declspec( dllimport )
34 #  endif
35 #else
36 #  define QTX_EXPORT  
37 #endif
38
39 #if defined SOLARIS
40 #define bool  int
41 #define false 0
42 #define true  1
43 #endif
44
45 #include <QString>
46 #include <QList>
47 #include <QFont>
48 #include <QColor>
49 #include <QImage>
50 #include <QPixmap>
51 #include <QGradient>
52
53 class QObject;
54 class QWidget;
55 class QCompleter;
56
57 typedef QList<int>    QIntList;       //!< list of int values
58 typedef QList<short>  QShortList;     //!< list of short int values
59 typedef QList<double> QDoubleList;    //!< list of double values
60 typedef QList<QColor> QColorList;     //!< list of colors
61
62 class QTX_EXPORT Qtx
63 {
64 public:
65   //! Widget alignment flags
66   typedef enum
67   {
68     AlignLeft            = Qt::AlignLeft,            //!< align left side of one widget to the left side of another widget
69     AlignLeading         = Qt::AlignLeading,         //!< synonim for AlignLeft
70     AlignRight           = Qt::AlignRight,           //!< align right side of one widget to the right side of another widget
71     AlignTrailing        = Qt::AlignTrailing,        //!< synonim for AlignRight
72     AlignHCenter         = Qt::AlignHCenter,         //!< align one widget to the center of another widget in horizontal dimension
73     AlignJustify         = Qt::AlignJustify,         //!< synonym of Qt::AlignJustify
74     AlignAbsolute        = Qt::AlignAbsolute,        //!< synonym of Qt::AlignAbsolute
75     AlignHorizontal_Mask = Qt::AlignHorizontal_Mask, //!< synonym of Qt::AlignHorizontal_Mask
76
77     AlignTop             = Qt::AlignTop,             //!< align top side of one widget to the top side of another widget
78     AlignBottom          = Qt::AlignBottom,          //!< align bottom side of one widget to the bottom side of another widget
79     AlignVCenter         = Qt::AlignVCenter,         //!< align one widget to the center of another widget in vertical dimension
80     AlignVertical_Mask   = Qt::AlignVertical_Mask,   //!< synonym of Qt::AlignVertical_Mask
81
82     AlignCenter          = Qt::AlignCenter,          //!< align one widget to the center of another widget in both dimensions
83
84     AlignOutLeft         = Qt::AlignVCenter  << 2,   //!< align right side of one widget to the left side of another widget
85     AlignOutRight        = AlignOutLeft      << 2,   //!< align left side of one widget to the right side of another widget
86     AlignOutTop          = AlignOutRight     << 2,   //!< align bottom side of one widget to the top side of another widget
87     AlignOutBottom       = AlignOutTop       << 2    //!< align top side of one widget to the bottom side of another widget
88   } AlignmentFlags;
89
90   //! Path type, indicates required directory/file operation
91   typedef enum { 
92     PT_OpenFile,      //!< the file is opened
93     PT_SaveFile,      //!< the file is saved
94     PT_Directory      //!< the directory path is required
95   } PathType;
96
97   //! Custom data roles
98   enum { 
99     AppropriateRole = Qt::UserRole + 100   //!< can be used to return \c true if data is appropriate
100   };
101
102   typedef enum {
103         Shown,   //!< column should be always visible
104         Hidden,  //!< column should be always hidden
105         Toggled  //!< it should be possible to show/hide the column with help of popup menu
106   } Appropriate;  //!< appropriate status
107
108   //! Environment variables substitution mode
109   typedef enum {
110         Always, //!< substitute environment variable by it's value if variable exists, and "" otherwise
111         Never,  //!< keep environment variable as is without any substitution
112         Auto    //!< substitute environment variable by it's value if variable exists, and keep it as is otherwise
113   } SubstMode;
114
115   //! object visibility state
116   typedef enum {
117     ShownState,             //!< Object is shown in viewer
118     HiddenState,            //!< Object is hidden in viewer
119     UnpresentableState,     //!< Unpresentable object
120   } VisibilityState;
121
122   //! Header view flags
123   typedef enum {
124     ShowText = 0x001,                //!< Show only text in the header
125     ShowIcon = 0x010,                //!< Show only icon in the header
126     ShowAll  = ShowText | ShowIcon   //!< Show icon and text in the header
127   } HeaderViewFlags;
128
129   //! Type of the custom data (for custom tree model)
130   typedef enum {
131     IdType
132   } CustomDataType;
133   
134   //! Background mode
135   typedef enum { 
136     NoBackground,              // no (invalid) background data
137     ColorBackground,           // single color
138     SimpleGradientBackground,  // simple two-color gradient
139     CustomGradientBackground   // custom (complex) gradient
140   } BackgroundMode;
141
142   //! Texture mode
143   typedef enum { 
144     CenterTexture,             // center texture
145     TileTexture,               // tile texture
146     StretchTexture,            // stretch texture
147   } TextureMode;
148
149   class QTX_EXPORT Localizer
150   {
151   public:
152     Localizer();
153     Localizer( int, const char* );
154     ~Localizer();
155   private:
156     void init( int, const char* );
157   private:
158     int myCategory;
159     QString myOriginalLocale;
160   };
161
162   class QTX_EXPORT CmdLineArgs
163   {
164   public:
165     CmdLineArgs();
166     ~CmdLineArgs();
167     
168     int argc() const;
169     char** argv() const;
170
171   private:
172     int    myArgc;
173     char** myArgv;
174   };
175
176   class QTX_EXPORT BackgroundData
177   {
178   public:
179     BackgroundData();
180     BackgroundData( const QColor& );
181     BackgroundData( int, const QColor&, const QColor& );
182     BackgroundData( const QGradient& );
183     virtual ~BackgroundData();
184
185     bool operator==( const BackgroundData&) const;
186     inline bool operator!=( const BackgroundData& other ) const
187     { return !operator==( other ); }
188
189     bool             isValid() const;
190     
191     BackgroundMode   mode() const;
192     void             setMode( const BackgroundMode );
193     
194     TextureMode      texture( QString& ) const;
195     void             setTexture( const QString&, TextureMode = Qtx::CenterTexture );
196     bool             isTextureShown() const;
197     void             setTextureShown( bool );
198
199     QColor           color() const;
200     void             setColor( const QColor& );
201
202     int              gradient( QColor&, QColor& ) const;
203     void             setGradient( int, const QColor&, const QColor& );
204
205     const QGradient* gradient() const;
206     void             setGradient( const QGradient& );
207   
208   private:
209     BackgroundMode   myMode;
210     TextureMode      myTextureMode;
211     QString          myFileName;
212     QColorList       myColors;
213     int              myGradientType;
214     QGradient        myGradient;
215     bool             myTextureShown;
216   };
217
218   static QString     toQString( const char*, const int = -1 );
219   static QString     toQString( const short*, const int = -1 );
220   static QString     toQString( const unsigned char*, const int = -1 );
221   static QString     toQString( const unsigned short*, const int = -1 );
222
223   static void        setTabOrder( QWidget*, ... );
224   static void        setTabOrder( const QWidgetList& );
225   static void        alignWidget( QWidget*, const QWidget*, const int );
226
227   static void        simplifySeparators( QWidget*, const bool = true );
228
229   static bool        isParent( QObject*, QObject* );
230   static QObject*    findParent( QObject*, const char* );
231
232   static QString     dir( const QString&, const bool = true );
233   static QString     file( const QString&, const bool = true );
234   static QString     extension( const QString&, const bool = false );
235
236   static QString     library( const QString& );
237
238   static QString     tmpDir();
239   static bool        mkDir( const QString& );
240   static bool        rmDir( const QString& );
241   static bool        dos2unix( const QString& );
242   static QString     addSlash( const QString& );
243
244   static QCompleter* pathCompleter( const PathType, const QString& = QString() );
245   static QString     findEnvVar( const QString&, int&, int& );
246   static QString     makeEnvVarSubst( const QString&, const SubstMode = Auto );
247
248   static int         rgbSet( const QColor& );
249   static int         rgbSet( const int, const int, const int );
250
251   static QColor      rgbSet( const int );
252   static void        rgbSet( const int, int&, int&, int& );
253
254   static QColor      scaleColor( const int, const int, const int );
255   static void        scaleColors( const int, QColorList& );
256
257   static QPixmap     scaleIcon( const QPixmap&, const unsigned, const unsigned = 0 );
258   static QImage      grayscale( const QImage& );
259   static QPixmap     grayscale( const QPixmap& );
260   static QImage      transparentImage( const int, const int, const int = -1 );
261   static QPixmap     transparentPixmap( const int, const int, const int = -1 );
262   static QPixmap     composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() );
263
264   static QString     colorToString( const QColor& );
265   static bool        stringToColor( const QString&, QColor& );
266   static QString     biColorToString( const QColor&, const int );
267   static bool        stringToBiColor( const QString&, QColor&, int& );
268   static QColor      mainColorToSecondary( const QColor&, int );
269
270   static QString     gradientToString( const QLinearGradient& );
271   static QString     gradientToString( const QRadialGradient& );
272   static QString     gradientToString( const QConicalGradient& );
273   static bool        stringToLinearGradient( const QString&, QLinearGradient& );
274   static bool        stringToRadialGradient( const QString&, QRadialGradient& );
275   static bool        stringToConicalGradient( const QString&, QConicalGradient& );
276
277   static QString        backgroundToString( const BackgroundData& );
278   static BackgroundData stringToBackground( const QString& );
279
280   static long        versionToId( const QString& );
281
282   static QString     qtDir( const QString& = QString());
283
284   static QFont   stringToFont( const QString& fontDescription );
285
286   static QString     getenv( const QString& envVar );
287
288 #ifndef WIN32
289   static void*       getDisplay();
290   static Qt::HANDLE  getVisual();
291 #endif
292   static void initDefaultSurfaceFormat();
293 };
294
295 #endif