Salome HOME
fa81c0d1a4fa67f7605a3b1309584f3d2b3e4fb8
[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 class QTX_EXPORT QtxColorScale : public QFrame
42 {
43           Q_OBJECT
44
45 public:
46           typedef enum { Auto, User } Mode;
47           typedef enum { None, Left, Right, Center } Position;
48           typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode;
49           typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004,
50                                            WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags;
51
52 #if QT_VER == 3
53           class Dock : public QDockWindow
54           {
55       public:
56           Dock( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 );
57           virtual ~Dock();
58           
59           QtxColorScale* colorScale() const;
60           
61           void           activate();
62           void           deactivate();
63           
64           bool           isActive() const;
65           
66           virtual void   show();
67           virtual void   hide();
68           
69           virtual void   resize( int, int );
70           virtual void   setOrientation( Orientation );
71           
72       private:
73           QtxColorScale* myScale;
74           bool           myBlockShow;
75           bool           myBlockResize;
76       };
77
78 private:
79           QtxColorScale( Dock*, const char* = 0, WFlags = 0 );
80 #endif
81
82 public:
83           QtxColorScale( QWidget* = 0, const char* = 0, WFlags = 0 );
84           QtxColorScale( const int, QWidget* = 0, const char* = 0, WFlags = 0 );
85           virtual ~QtxColorScale();
86
87           double                minimum() const;
88           double                maximum() const;
89           void                  range( double&, double& ) const;
90           int                   dumpMode() const;
91           int                   labelMode() const;
92           int                   colorMode() const;
93           int                   intervalsNumber() const;
94
95           QString               title() const;
96           QString               format() const;
97           QString               label( const int ) const;
98           QColor                color( const int ) const;
99           void                  labels( QStringList& ) const;
100           void                  colors( QValueList<QColor>& ) const;
101
102           int                   labelPosition() const;
103           int                   titlePosition() const;
104
105           void                  setMinimum( const double );
106           void                  setMaximum( const double );
107           void                  setRange( const double, const double );
108           void                  setDumpMode( const int );
109           void                  setColorMode( const int );
110           void                  setLabelMode( const int );
111           void                  setIntervalsNumber( const int );
112
113           void                  setTitle( const QString& );
114           void                  setFormat( const QString& );
115           void                  setLabel( const QString&, const int = -1 );
116           void                  setColor( const QColor&, const int = -1 );
117           void                  setLabels( const QStringList& );
118           void                  setColors( const QValueList<QColor>& );
119
120           void                  setLabelPosition( const int );
121           void                  setTitlePosition( const int );
122
123           void                  setFlags( const int );
124           bool                  testFlags( const int ) const;
125           void                  clearFlags( const int );
126
127           QPixmap               dump() const;
128           QPixmap               dump( const int = -1, const int = -1 ) const;
129           QPixmap               dump( const QColor&, const int = -1, const int = -1 ) const;
130
131           virtual QSize         minimumSizeHint() const;
132           virtual QSize         sizeHint() const;
133
134           virtual void          show();
135           virtual void          hide();
136
137 protected:
138           virtual void          drawContents( QPainter* );
139
140 private:
141           void                  updateScale();
142           QString               getFormat() const;
143           QString               getLabel( const int ) const;
144           QColor                getColor( const int ) const;
145           double                getNumber( const int ) const;
146           QSimpleRichText*      simpleRichText( const int ) const;
147           void                  drawScale( QPainter*, const bool, const int, const int,
148                                                                                            const int, const int, const bool, const bool, const bool ) const;
149           void                  drawScale( QPainter*, const QColor&, const bool,
150                                                                                            const int, const int, const int, const int,
151                                                                                            const bool, const bool, const bool ) const;
152           QSize                 calculateSize( const bool, const int,
153                                                                                                      const bool, const bool, const bool ) const;
154
155 #if QT_VER == 3
156           friend class QtxColorScale::Dock;
157 #endif
158
159 private:
160           double                myMin;
161           double                myMax;
162           QString               myTitle;
163           QString               myFormat;
164           QString               myPrecise;
165           int                   myInterval;
166           int                   myDumpMode;
167           int                   myColorMode;
168           int                   myLabelMode;
169
170           QValueList<QColor>    myColors;
171           QValueList<QString>   myLabels;
172
173           Dock*                 myDock;
174           int                   myFlags;
175           int                   myLabelPos;
176           int                   myTitlePos;
177           QStyleSheet*          myStyleSheet;
178 };
179
180 #ifdef WIN32
181 #pragma warning( default:4251 )
182 #endif
183
184 #endif