Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / Qtx / QtxColorScale.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxColorScale.h
20 // Author:    Sergey TELKOV
21
22 #ifndef QTXCOLORSCALE_H
23 #define QTXCOLORSCALE_H
24
25 #include "Qtx.h"
26
27 #include <qframe.h>
28 #include <qvaluelist.h>
29
30 #if QT_VER == 3
31 #include <qdockwindow.h>
32 #endif
33
34 class QStyleSheet;
35 class QSimpleRichText;
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 /*!
42   \class QtxColorScale
43   Color Scale widget.
44 */
45 class QTX_EXPORT QtxColorScale : public QFrame
46 {
47           Q_OBJECT
48
49 public:
50           typedef enum { Auto, User } Mode;
51           typedef enum { None, Left, Right, Center } Position;
52           typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode;
53           typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004,
54                                            WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags;
55
56 #if QT_VER == 3
57           class Dock : public QDockWindow
58           {
59       public:
60           Dock( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 );
61           virtual ~Dock();
62           
63           QtxColorScale* colorScale() const;
64           
65           void           activate();
66           void           deactivate();
67           
68           bool           isActive() const;
69           
70           virtual void   show();
71           virtual void   hide();
72           
73           virtual void   resize( int, int );
74           virtual void   setOrientation( Orientation );
75           
76       private:
77           QtxColorScale* myScale;
78           bool           myBlockShow;
79           bool           myBlockResize;
80       };
81
82 private:
83           QtxColorScale( Dock*, const char* = 0, WFlags = 0 );
84 #endif
85
86 public:
87           QtxColorScale( QWidget* = 0, const char* = 0, WFlags = 0 );
88           QtxColorScale( const int, QWidget* = 0, const char* = 0, WFlags = 0 );
89           virtual ~QtxColorScale();
90
91           double                minimum() const;
92           double                maximum() const;
93           void                  range( double&, double& ) const;
94           int                   dumpMode() const;
95           int                   labelMode() const;
96           int                   colorMode() const;
97           int                   intervalsNumber() const;
98
99           QString               title() const;
100           QString               format() const;
101           QString               label( const int ) const;
102           QColor                color( const int ) const;
103           void                  labels( QStringList& ) const;
104           void                  colors( QValueList<QColor>& ) const;
105
106           int                   labelPosition() const;
107           int                   titlePosition() const;
108
109           void                  setMinimum( const double );
110           void                  setMaximum( const double );
111           void                  setRange( const double, const double );
112           void                  setDumpMode( const int );
113           void                  setColorMode( const int );
114           void                  setLabelMode( const int );
115           void                  setIntervalsNumber( const int );
116
117           void                  setTitle( const QString& );
118           void                  setFormat( const QString& );
119           void                  setLabel( const QString&, const int = -1 );
120           void                  setColor( const QColor&, const int = -1 );
121           void                  setLabels( const QStringList& );
122           void                  setColors( const QValueList<QColor>& );
123
124           void                  setLabelPosition( const int );
125           void                  setTitlePosition( const int );
126
127           void                  setFlags( const int );
128           bool                  testFlags( const int ) const;
129           void                  clearFlags( const int );
130
131           QPixmap               dump() const;
132           QPixmap               dump( const int = -1, const int = -1 ) const;
133           QPixmap               dump( const QColor&, const int = -1, const int = -1 ) const;
134
135           virtual QSize         minimumSizeHint() const;
136           virtual QSize         sizeHint() const;
137
138           virtual void          show();
139           virtual void          hide();
140
141 protected:
142           virtual void          drawContents( QPainter* );
143
144 private:
145           void                  updateScale();
146           QString               getFormat() const;
147           QString               getLabel( const int ) const;
148           QColor                getColor( const int ) const;
149           double                getNumber( const int ) const;
150           QSimpleRichText*      simpleRichText( const int ) const;
151           void                  drawScale( QPainter*, const bool, const int, const int,
152                                                                                            const int, const int, const bool, const bool, const bool ) const;
153           void                  drawScale( QPainter*, const QColor&, const bool,
154                                                                                            const int, const int, const int, const int,
155                                                                                            const bool, const bool, const bool ) const;
156           QSize                 calculateSize( const bool, const int,
157                                                                                                      const bool, const bool, const bool ) const;
158
159 #if QT_VER == 3
160           friend class QtxColorScale::Dock;
161 #endif
162
163 private:
164           double                myMin;
165           double                myMax;
166           QString               myTitle;
167           QString               myFormat;
168           QString               myPrecise;
169           int                   myInterval;
170           int                   myDumpMode;
171           int                   myColorMode;
172           int                   myLabelMode;
173
174           QValueList<QColor>    myColors;
175           QValueList<QString>   myLabels;
176
177           Dock*                 myDock;
178           int                   myFlags;
179           int                   myLabelPos;
180           int                   myTitlePos;
181           QStyleSheet*          myStyleSheet;
182 };
183
184 #ifdef WIN32
185 #pragma warning( default:4251 )
186 #endif
187
188 #endif