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