Salome HOME
Methods Qtx::scaleColor() and Qtx::scaleColors() were added.
[modules/gui.git] / src / Qtx / QtxColorScale.h
1 // File:      QtxColorScale.h
2 // Author:    Sergey TELKOV
3
4 #ifndef QTXCOLORSCALE_H
5 #define QTXCOLORSCALE_H
6
7 #include "Qtx.h"
8
9 #include <qframe.h>
10 #include <qvaluelist.h>
11
12 #if QT_VER == 3
13 #include <qdockwindow.h>
14 #endif
15
16 class QStyleSheet;
17 class QSimpleRichText;
18
19 #ifdef WIN32
20 #pragma warning( disable:4251 )
21 #endif
22
23 class QTX_EXPORT QtxColorScale : public QFrame
24 {
25           Q_OBJECT
26
27 public:
28           typedef enum { Auto, User } Mode;
29           typedef enum { None, Left, Right, Center } Position;
30           typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode;
31           typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004,
32                                            WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags;
33
34 #if QT_VER == 3
35           class Dock : public QDockWindow
36           {
37       public:
38           Dock( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 );
39           virtual ~Dock();
40           
41           QtxColorScale* colorScale() const;
42           
43           void           activate();
44           void           deactivate();
45           
46           bool           isActive() const;
47           
48           virtual void   show();
49           virtual void   hide();
50           
51           virtual void   resize( int, int );
52           virtual void   setOrientation( Orientation );
53           
54       private:
55           QtxColorScale* myScale;
56           bool           myBlockShow;
57           bool           myBlockResize;
58       };
59
60 private:
61           QtxColorScale( Dock*, const char* = 0, WFlags = 0 );
62 #endif
63
64 public:
65           QtxColorScale( QWidget* = 0, const char* = 0, WFlags = 0 );
66           QtxColorScale( const int, QWidget* = 0, const char* = 0, WFlags = 0 );
67           virtual ~QtxColorScale();
68
69           double                minimum() const;
70           double                maximum() const;
71           void                  range( double&, double& ) const;
72           int                   dumpMode() const;
73           int                   labelMode() const;
74           int                   colorMode() const;
75           int                   intervalsNumber() const;
76
77           QString               title() const;
78           QString               format() const;
79           QString               label( const int ) const;
80           QColor                color( const int ) const;
81           void                  labels( QStringList& ) const;
82           void                  colors( QValueList<QColor>& ) const;
83
84           int                   labelPosition() const;
85           int                   titlePosition() const;
86
87           void                  setMinimum( const double );
88           void                  setMaximum( const double );
89           void                  setRange( const double, const double );
90           void                  setDumpMode( const int );
91           void                  setColorMode( const int );
92           void                  setLabelMode( const int );
93           void                  setIntervalsNumber( const int );
94
95           void                  setTitle( const QString& );
96           void                  setFormat( const QString& );
97           void                  setLabel( const QString&, const int = -1 );
98           void                  setColor( const QColor&, const int = -1 );
99           void                  setLabels( const QStringList& );
100           void                  setColors( const QValueList<QColor>& );
101
102           void                  setLabelPosition( const int );
103           void                  setTitlePosition( const int );
104
105           void                  setFlags( const int );
106           bool                  testFlags( const int ) const;
107           void                  clearFlags( const int );
108
109           QPixmap               dump() const;
110           QPixmap               dump( const int = -1, const int = -1 ) const;
111           QPixmap               dump( const QColor&, const int = -1, const int = -1 ) const;
112
113           virtual QSize         minimumSizeHint() const;
114           virtual QSize         sizeHint() const;
115
116           virtual void          show();
117           virtual void          hide();
118
119 protected:
120           virtual void          drawContents( QPainter* );
121
122 private:
123           void                  updateScale();
124           QString               getFormat() const;
125           QString               getLabel( const int ) const;
126           QColor                getColor( const int ) const;
127           double                getNumber( const int ) const;
128           QSimpleRichText*      simpleRichText( const int ) const;
129           void                  drawScale( QPainter*, const bool, const int, const int,
130                                                                                            const int, const int, const bool, const bool, const bool ) const;
131           void                  drawScale( QPainter*, const QColor&, const bool,
132                                                                                            const int, const int, const int, const int,
133                                                                                            const bool, const bool, const bool ) const;
134           QSize                 calculateSize( const bool, const int,
135                                                                                                      const bool, const bool, const bool ) const;
136
137           friend class Dock;
138
139 private:
140           double                myMin;
141           double                myMax;
142           QString               myTitle;
143           QString               myFormat;
144           QString               myPrecise;
145           int                   myInterval;
146           int                   myDumpMode;
147           int                   myColorMode;
148           int                   myLabelMode;
149
150           QValueList<QColor>    myColors;
151           QValueList<QString>   myLabels;
152
153           Dock*                 myDock;
154           int                   myFlags;
155           int                   myLabelPos;
156           int                   myTitlePos;
157           QStyleSheet*          myStyleSheet;
158 };
159
160 #ifdef WIN32
161 #pragma warning( default:4251 )
162 #endif
163
164 #endif