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