Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / Qtx.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:      Qtx.h
23 // Author:    Sergey TELKOV
24 //
25 #ifndef QTX_H
26 #define QTX_H
27
28 #if defined WIN32
29 #  if defined QTX_EXPORTS
30 #    define QTX_EXPORT _declspec( dllexport )
31 #  else
32 #    define QTX_EXPORT _declspec( dllimport )
33 #  endif
34 #else
35 #  define QTX_EXPORT  
36 #endif
37
38 #if defined SOLARIS
39 #define bool  int
40 #define false 0
41 #define true  1
42 #endif
43
44 #include <QString>
45 #include <QList>
46 #include <QColor>
47 #include <QImage>
48 #include <QPixmap>
49
50 class QObject;
51 class QWidget;
52 class QCompleter;
53 class QLinearGradient;
54 class QRadialGradient;
55 class QConicalGradient;
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   static QString     toQString( const char*, const int = -1 );
109   static QString     toQString( const short*, const int = -1 );
110   static QString     toQString( const unsigned char*, const int = -1 );
111   static QString     toQString( const unsigned short*, const int = -1 );
112
113   static void        setTabOrder( QWidget*, ... );
114   static void        setTabOrder( const QWidgetList& );
115   static void        alignWidget( QWidget*, const QWidget*, const int );
116
117   static void        simplifySeparators( QWidget*, const bool = true );
118
119   static bool        isParent( QObject*, QObject* );
120   static QObject*    findParent( QObject*, const char* );
121
122   static QString     dir( const QString&, const bool = true );
123   static QString     file( const QString&, const bool = true );
124   static QString     extension( const QString&, const bool = false );
125
126   static QString     library( const QString& );
127
128   static QString     tmpDir();
129   static bool        mkDir( const QString& );
130   static bool        rmDir( const QString& );
131   static bool        dos2unix( const QString& );
132   static QString     addSlash( const QString& );
133
134   static QCompleter* pathCompleter( const PathType, const QString& = QString() );
135
136   static int         rgbSet( const QColor& );
137   static int         rgbSet( const int, const int, const int );
138
139   static QColor      rgbSet( const int );
140   static void        rgbSet( const int, int&, int&, int& );
141
142   static QColor      scaleColor( const int, const int, const int );
143   static void        scaleColors( const int, QColorList& );
144
145   static QPixmap     scaleIcon( const QPixmap&, const unsigned, const unsigned = 0 );
146   static QImage      grayscale( const QImage& );
147   static QPixmap     grayscale( const QPixmap& );
148   static QImage      transparentImage( const int, const int, const int = -1 );
149   static QPixmap     transparentPixmap( const int, const int, const int = -1 );
150   static QPixmap     composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() );
151
152   static QString     colorToString( const QColor& );
153   static bool        stringToColor( const QString&, QColor& );
154
155   static QString     gradientToString( const QLinearGradient& );
156   static QString     gradientToString( const QRadialGradient& );
157   static QString     gradientToString( const QConicalGradient& );
158   static bool        stringToLinearGradient( const QString&, QLinearGradient& );
159   static bool        stringToRadialGradient( const QString&, QRadialGradient& );
160   static bool        stringToConicalGradient( const QString&, QConicalGradient& );
161 };
162
163 #endif