Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxColorScale.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:      QtxColorScale.h
23 // Author:    Sergey TELKOV
24 //
25 #ifndef QTXCOLORSCALE_H
26 #define QTXCOLORSCALE_H
27
28 #include "Qtx.h"
29
30 #include <QFrame>
31 #include <QList>
32
33 class QTextDocument;
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 class QTX_EXPORT QtxColorScale : public QFrame
40 {
41   Q_OBJECT
42
43 public:
44   //! Color scale color/label mode.
45   typedef enum { 
46     Auto,            //!< auto
47     User             //!< user defined
48   } Mode;
49   //! Color scale title, label position.
50   typedef enum { 
51     None,            //!< do not draw
52     Left,            //!< draw at the left
53     Right,           //!< draw at the right
54     Center           //!< draw at the center
55   } Position;
56   //! Dump mode.
57   typedef enum { 
58     NoDump,          //!< do not dump
59     TitleDump,       //!< dump title
60     ScaleDump,       //!< dump scale
61     FullDump         //!< dump all
62   } DumpMode;
63   //! Color scale flags (bitwise).
64   typedef enum { 
65     AtBorder      = 0x001,   //!< diplay values at colors boundaries
66     Reverse       = 0x002,   //!< display color scale in reverse order
67     Integer       = 0x004,   //!< round numbers to integer values
68     WrapTitle     = 0x008,   //!< wrap title to several lines
69     PreciseFormat = 0x010,   //!< autodetect decimal point precision for color scale values
70     Transparent   = 0x020    //!< transparent background (not implemented yet!)
71   } Flags;
72
73 public:
74   QtxColorScale( QWidget* = 0, Qt::WindowFlags = 0 );
75   QtxColorScale( const int, QWidget* = 0, Qt::WindowFlags = 0 );
76   virtual ~QtxColorScale();
77
78   double                minimum() const;
79   double                maximum() const;
80   void                  range( double&, double& ) const;
81   int                   dumpMode() const;
82   int                   labelMode() const;
83   int                   colorMode() const;
84   int                   intervalsNumber() const;
85
86   QString               title() const;
87   QString               format() const;
88   QString               label( const int ) const;
89   QColor                color( const int ) const;
90   void                  labels( QStringList& ) const;
91   void                  colors( QList<QColor>& ) const;
92
93   int                   labelPosition() const;
94   int                   titlePosition() const;
95
96   void                  setMinimum( const double );
97   void                  setMaximum( const double );
98   void                  setRange( const double, const double );
99   void                  setDumpMode( const int );
100   void                  setColorMode( const int );
101   void                  setLabelMode( const int );
102   void                  setIntervalsNumber( const int );
103
104   void                  setTitle( const QString& );
105   void                  setFormat( const QString& );
106   void                  setLabel( const QString&, const int = -1 );
107   void                  setColor( const QColor&, const int = -1 );
108   void                  setLabels( const QStringList& );
109   void                  setColors( const QList<QColor>& );
110
111   void                  setLabelPosition( const int );
112   void                  setTitlePosition( const int );
113
114   void                  setFlags( const int );
115   bool                  testFlags( const int ) const;
116   void                  clearFlags( const int );
117
118   QPixmap               dump() const;
119   QPixmap               dump( const int = -1, const int = -1 ) const;
120   QPixmap               dump( const QColor&, const int = -1, const int = -1 ) const;
121
122   virtual QSize         minimumSizeHint() const;
123   virtual QSize         sizeHint() const;
124
125   virtual void          show();
126   virtual void          hide();
127
128 protected:
129   virtual void          paintEvent( QPaintEvent* );
130   virtual void          drawContents( QPainter* );
131
132 private:
133   void                  updateScale();
134   QString               getFormat() const;
135   QString               getLabel( const int ) const;
136   QColor                getColor( const int ) const;
137   double                getNumber( const int ) const;
138   QTextDocument*        textDocument( const int ) const;
139   void                  drawScale( QPainter*, const bool, const int, const int,
140                                    const int, const int, const bool, const bool, const bool ) const;
141   void                  drawScale( QPainter*, const QColor&, const bool,
142                                    const int, const int, const int, const int,
143                                    const bool, const bool, const bool ) const;
144   QSize                 calculateSize( const bool, const int,
145                                        const bool, const bool, const bool ) const;
146
147 private:
148   double                myMin;             //!< lower limit
149   double                myMax;             //!< upper limit
150   QString               myTitle;           //!< title
151   QString               myFormat;          //!< number presentation format
152   QString               myPrecise;         //!< double values precision format
153   int                   myInterval;        //!< number of color scale intervals
154   int                   myDumpMode;        //!< dump mode (QtxColorScale::DumpMode)
155   int                   myColorMode;       //!< color mode (QtxColorScale::Mode)
156   int                   myLabelMode;       //!< label mode (QtxColorScale::Mode)
157
158   QList<QColor>         myColors;          //!< list of colors
159   QList<QString>        myLabels;          //!< list of labels
160
161   int                   myFlags;           //!< color scale flags (QtxColorScale::Flags)
162   int                   myLabelPos;        //!< label position (QtxColorScale::Position)
163   int                   myTitlePos;        //!< title position (QtxColorScale::Position)
164 };
165
166 #ifdef WIN32
167 #pragma warning( default:4251 )
168 #endif
169
170 #endif  // QTXCOLORSCALE_H