Back to index

salome-gui  6.5.0
Qtx.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      Qtx.h
00024 // Author:    Sergey TELKOV
00025 //
00026 #ifndef QTX_H
00027 #define QTX_H
00028 
00029 #if defined WIN32
00030 #  if defined QTX_EXPORTS || defined qtx_EXPORTS
00031 #    define QTX_EXPORT _declspec( dllexport )
00032 #  else
00033 #    define QTX_EXPORT _declspec( dllimport )
00034 #  endif
00035 #else
00036 #  define QTX_EXPORT  
00037 #endif
00038 
00039 #if defined SOLARIS
00040 #define bool  int
00041 #define false 0
00042 #define true  1
00043 #endif
00044 
00045 #include <QString>
00046 #include <QList>
00047 #include <QColor>
00048 #include <QImage>
00049 #include <QPixmap>
00050 #include <QGradient>
00051 
00052 class QObject;
00053 class QWidget;
00054 class QCompleter;
00055 
00056 typedef QList<int>    QIntList;       
00057 typedef QList<short>  QShortList;     
00058 typedef QList<double> QDoubleList;    
00059 typedef QList<QColor> QColorList;     
00060 
00061 class QTX_EXPORT Qtx
00062 {
00063 public:
00065   typedef enum
00066   {
00067     AlignLeft            = Qt::AlignLeft,            
00068     AlignLeading         = Qt::AlignLeading,         
00069     AlignRight           = Qt::AlignRight,           
00070     AlignTrailing        = Qt::AlignTrailing,        
00071     AlignHCenter         = Qt::AlignHCenter,         
00072     AlignJustify         = Qt::AlignJustify,         
00073     AlignAbsolute        = Qt::AlignAbsolute,        
00074     AlignHorizontal_Mask = Qt::AlignHorizontal_Mask, 
00075 
00076     AlignTop             = Qt::AlignTop,             
00077     AlignBottom          = Qt::AlignBottom,          
00078     AlignVCenter         = Qt::AlignVCenter,         
00079     AlignVertical_Mask   = Qt::AlignVertical_Mask,   
00080 
00081     AlignCenter          = Qt::AlignCenter,          
00082 
00083     AlignOutLeft         = Qt::AlignVCenter  << 2,   
00084     AlignOutRight        = AlignOutLeft      << 2,   
00085     AlignOutTop          = AlignOutRight     << 2,   
00086     AlignOutBottom       = AlignOutTop       << 2    
00087   } AlignmentFlags;
00088 
00090   typedef enum { 
00091     PT_OpenFile,      
00092     PT_SaveFile,      
00093     PT_Directory      
00094   } PathType;
00095 
00097   enum { 
00098     AppropriateRole = Qt::UserRole + 100   
00099   };
00100 
00101   typedef enum {
00102         Shown,   
00103         Hidden,  
00104         Toggled  
00105   } Appropriate;  
00106 
00108   typedef enum {
00109         Always, 
00110         Never,  
00111         Auto    
00112   } SubstMode;
00113 
00115   typedef enum {
00116     ShownState,             
00117     HiddenState,            
00118     UnpresentableState,     
00119   } VisibilityState;
00120 
00122   typedef enum {
00123     ShowText = 0x001,                
00124     ShowIcon = 0x010,                
00125     ShowAll  = ShowText | ShowIcon   
00126   } HeaderViewFlags;
00127 
00129   typedef enum {
00130     IdType
00131   } CustomDataType;
00132   
00134   typedef enum { 
00135     NoBackground,              // no (invalid) background data
00136     ColorBackground,           // single color
00137     SimpleGradientBackground,  // simple two-color gradient
00138     CustomGradientBackground   // custom (complex) gradient
00139   } BackgroundMode;
00140 
00142   typedef enum { 
00143     CenterTexture,             // center texture
00144     TileTexture,               // tile texture
00145     StretchTexture,            // stretch texture
00146   } TextureMode;
00147 
00148   class QTX_EXPORT Localizer
00149   {
00150   public:
00151     Localizer();
00152     ~Localizer();
00153   private:
00154     QString myCurLocale;
00155   };
00156 
00157   class QTX_EXPORT BackgroundData
00158   {
00159   public:
00160     BackgroundData();
00161     BackgroundData( const QColor& );
00162     BackgroundData( int, const QColor&, const QColor& );
00163     BackgroundData( const QGradient& );
00164     virtual ~BackgroundData();
00165 
00166     bool operator==( const BackgroundData&) const;
00167     inline bool operator!=( const BackgroundData& other ) const
00168     { return !operator==( other ); }
00169 
00170     bool             isValid() const;
00171     
00172     BackgroundMode   mode() const;
00173     void             setMode( const BackgroundMode );
00174     
00175     TextureMode      texture( QString& ) const;
00176     void             setTexture( const QString&, TextureMode = Qtx::CenterTexture );
00177     bool             isTextureShown() const;
00178     void             setTextureShown( bool );
00179 
00180     QColor           color() const;
00181     void             setColor( const QColor& );
00182 
00183     int              gradient( QColor&, QColor& ) const;
00184     void             setGradient( int, const QColor&, const QColor& );
00185 
00186     const QGradient* gradient() const;
00187     void             setGradient( const QGradient& );
00188   
00189   private:
00190     BackgroundMode   myMode;
00191     TextureMode      myTextureMode;
00192     QString          myFileName;
00193     QColorList       myColors;
00194     int              myGradientType;
00195     QGradient        myGradient;
00196     bool             myTextureShown;
00197   };
00198 
00199   static QString     toQString( const char*, const int = -1 );
00200   static QString     toQString( const short*, const int = -1 );
00201   static QString     toQString( const unsigned char*, const int = -1 );
00202   static QString     toQString( const unsigned short*, const int = -1 );
00203 
00204   static void        setTabOrder( QWidget*, ... );
00205   static void        setTabOrder( const QWidgetList& );
00206   static void        alignWidget( QWidget*, const QWidget*, const int );
00207 
00208   static void        simplifySeparators( QWidget*, const bool = true );
00209 
00210   static bool        isParent( QObject*, QObject* );
00211   static QObject*    findParent( QObject*, const char* );
00212 
00213   static QString     dir( const QString&, const bool = true );
00214   static QString     file( const QString&, const bool = true );
00215   static QString     extension( const QString&, const bool = false );
00216 
00217   static QString     library( const QString& );
00218 
00219   static QString     tmpDir();
00220   static bool        mkDir( const QString& );
00221   static bool        rmDir( const QString& );
00222   static bool        dos2unix( const QString& );
00223   static QString     addSlash( const QString& );
00224 
00225   static QCompleter* pathCompleter( const PathType, const QString& = QString() );
00226   static QString     findEnvVar( const QString&, int&, int& );
00227   static QString     makeEnvVarSubst( const QString&, const SubstMode = Auto );
00228 
00229   static int         rgbSet( const QColor& );
00230   static int         rgbSet( const int, const int, const int );
00231 
00232   static QColor      rgbSet( const int );
00233   static void        rgbSet( const int, int&, int&, int& );
00234 
00235   static QColor      scaleColor( const int, const int, const int );
00236   static void        scaleColors( const int, QColorList& );
00237 
00238   static QPixmap     scaleIcon( const QPixmap&, const unsigned, const unsigned = 0 );
00239   static QImage      grayscale( const QImage& );
00240   static QPixmap     grayscale( const QPixmap& );
00241   static QImage      transparentImage( const int, const int, const int = -1 );
00242   static QPixmap     transparentPixmap( const int, const int, const int = -1 );
00243   static QPixmap     composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() );
00244 
00245   static QString     colorToString( const QColor& );
00246   static bool        stringToColor( const QString&, QColor& );
00247   static QString     biColorToString( const QColor&, const int );
00248   static bool        stringToBiColor( const QString&, QColor&, int& );
00249   static QColor      mainColorToSecondary( const QColor&, int );
00250 
00251   static QString     gradientToString( const QLinearGradient& );
00252   static QString     gradientToString( const QRadialGradient& );
00253   static QString     gradientToString( const QConicalGradient& );
00254   static bool        stringToLinearGradient( const QString&, QLinearGradient& );
00255   static bool        stringToRadialGradient( const QString&, QRadialGradient& );
00256   static bool        stringToConicalGradient( const QString&, QConicalGradient& );
00257 
00258   static QString        backgroundToString( const BackgroundData& );
00259   static BackgroundData stringToBackground( const QString& );
00260 
00261 #ifndef WIN32
00262   static void*       getDisplay();
00263   static Qt::HANDLE  getVisual();
00264 #endif
00265 };
00266 
00267 #endif