Back to index

salome-gui  6.5.0
QtxColorScale.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:      QtxColorScale.h
00024 // Author:    Sergey TELKOV
00025 //
00026 #ifndef QTXCOLORSCALE_H
00027 #define QTXCOLORSCALE_H
00028 
00029 #include "Qtx.h"
00030 
00031 #include <QFrame>
00032 #include <QList>
00033 
00034 class QTextDocument;
00035 
00036 #ifdef WIN32
00037 #pragma warning( disable:4251 )
00038 #endif
00039 
00040 class QTX_EXPORT QtxColorScale : public QFrame
00041 {
00042   Q_OBJECT
00043 
00044 public:
00046   typedef enum { 
00047     Auto,            
00048     User             
00049   } Mode;
00051   typedef enum { 
00052     None,            
00053     Left,            
00054     Right,           
00055     Center           
00056   } Position;
00058   typedef enum { 
00059     NoDump,          
00060     TitleDump,       
00061     ScaleDump,       
00062     FullDump         
00063   } DumpMode;
00065   typedef enum { 
00066     AtBorder      = 0x001,   
00067     Reverse       = 0x002,   
00068     Integer       = 0x004,   
00069     WrapTitle     = 0x008,   
00070     PreciseFormat = 0x010,   
00071     Transparent   = 0x020    
00072   } Flags;
00073 
00074 public:
00075   QtxColorScale( QWidget* = 0, Qt::WindowFlags = 0 );
00076   QtxColorScale( const int, QWidget* = 0, Qt::WindowFlags = 0 );
00077   virtual ~QtxColorScale();
00078 
00079   double                minimum() const;
00080   double                maximum() const;
00081   void                  range( double&, double& ) const;
00082   int                   dumpMode() const;
00083   int                   labelMode() const;
00084   int                   colorMode() const;
00085   int                   intervalsNumber() const;
00086 
00087   QString               title() const;
00088   QString               format() const;
00089   QString               label( const int ) const;
00090   QColor                color( const int ) const;
00091   void                  labels( QStringList& ) const;
00092   void                  colors( QList<QColor>& ) const;
00093 
00094   int                   labelPosition() const;
00095   int                   titlePosition() const;
00096 
00097   void                  setMinimum( const double );
00098   void                  setMaximum( const double );
00099   void                  setRange( const double, const double );
00100   void                  setDumpMode( const int );
00101   void                  setColorMode( const int );
00102   void                  setLabelMode( const int );
00103   void                  setIntervalsNumber( const int );
00104 
00105   void                  setTitle( const QString& );
00106   void                  setFormat( const QString& );
00107   void                  setLabel( const QString&, const int = -1 );
00108   void                  setColor( const QColor&, const int = -1 );
00109   void                  setLabels( const QStringList& );
00110   void                  setColors( const QList<QColor>& );
00111 
00112   void                  setLabelPosition( const int );
00113   void                  setTitlePosition( const int );
00114 
00115   void                  setFlags( const int );
00116   bool                  testFlags( const int ) const;
00117   void                  clearFlags( const int );
00118 
00119   QPixmap               dump() const;
00120   QPixmap               dump( const int = -1, const int = -1 ) const;
00121   QPixmap               dump( const QColor&, const int = -1, const int = -1 ) const;
00122 
00123   virtual QSize         minimumSizeHint() const;
00124   virtual QSize         sizeHint() const;
00125 
00126   virtual void          show();
00127   virtual void          hide();
00128 
00129 protected:
00130   virtual void          paintEvent( QPaintEvent* );
00131   virtual void          drawContents( QPainter* );
00132 
00133 private:
00134   void                  updateScale();
00135   QString               getFormat() const;
00136   QString               getLabel( const int ) const;
00137   QColor                getColor( const int ) const;
00138   double                getNumber( const int ) const;
00139   QTextDocument*        textDocument( const int ) const;
00140   void                  drawScale( QPainter*, const bool, const int, const int,
00141                                    const int, const int, const bool, const bool, const bool ) const;
00142   void                  drawScale( QPainter*, const QColor&, const bool,
00143                                    const int, const int, const int, const int,
00144                                    const bool, const bool, const bool ) const;
00145   QSize                 calculateSize( const bool, const int,
00146                                        const bool, const bool, const bool ) const;
00147 
00148 private:
00149   double                myMin;             
00150   double                myMax;             
00151   QString               myTitle;           
00152   QString               myFormat;          
00153   QString               myPrecise;         
00154   int                   myInterval;        
00155   int                   myDumpMode;        
00156   int                   myColorMode;       
00157   int                   myLabelMode;       
00158 
00159   QList<QColor>         myColors;          
00160   QList<QString>        myLabels;          
00161 
00162   int                   myFlags;           
00163   int                   myLabelPos;        
00164   int                   myTitlePos;        
00165 };
00166 
00167 #ifdef WIN32
00168 #pragma warning( default:4251 )
00169 #endif
00170 
00171 #endif  // QTXCOLORSCALE_H