Salome HOME
bd5d988f8c1e715f866eb97f7d7a71a4f48e8edd
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.h
1 #ifndef PLOT2D_VIEWFRAME_H
2 #define PLOT2D_VIEWFRAME_H
3
4 #include "Plot2d_Curve.h"
5 #include <qwidget.h>
6 #include <qintdict.h>
7
8 class Plot2d_Plot2d;
9 class Plot2d_Prs;
10
11 typedef QIntDict<Plot2d_Curve> CurveDict;
12
13 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
14
15   Q_OBJECT
16
17   enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, 
18    ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
19    LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
20 public:
21   /* Construction/destruction */
22   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
23   virtual ~Plot2d_ViewFrame();
24
25   enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
26
27 public:
28   QWidget* getViewWidget();
29
30   /* display */
31   void    DisplayAll();
32   void    EraseAll();
33   void    Repaint();
34
35   void    Display( const Plot2d_Prs* );
36   void    Erase( const Plot2d_Prs*, const bool = false );
37   Plot2d_Prs* CreatePrs( const char* entry = 0 );
38
39   /* operations */
40   void    setTitle( const QString& title );
41   QString getTitle() const { return myTitle; }
42   void    displayCurve( Plot2d_Curve* curve, bool update = false );
43   void    displayCurves( const curveList& curves, bool update = false );
44   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
45   void    eraseCurves( const curveList& curves, bool update = false );
46   int     getCurves( curveList& clist );
47   const   CurveDict& getCurves() { return myCurves; }
48   int     hasCurve( Plot2d_Curve* curve );
49   bool    isVisible( Plot2d_Curve* curve );
50   void    updateCurve( Plot2d_Curve* curve, bool update = false );
51   void    updateLegend( const Plot2d_Prs* prs );
52   void    fitAll();
53   void    fitArea( const QRect& area );
54
55   /* view parameters */
56   void    copyPreferences( Plot2d_ViewFrame* );
57   void    setCurveType( int curveType, bool update = true );
58   int     getCurveType() const { return myCurveType; }
59   void    setCurveTitle( int curveKey, const QString& title );
60   void    showLegend( bool show, bool update = true );
61   void    setLegendPos( int pos );
62   int     getLegendPos() const { return myLegendPos; }
63   void    setMarkerSize( const int size, bool update = true  );
64   int     getMarkerSize() const { return myMarkerSize; }
65   void    setBackgroundColor( const QColor& color );
66   QColor  backgroundColor() const;
67   void    setXGrid( bool xMajorEnabled, const int xMajorMax,
68                     bool xMinorEnabled, const int xMinorMax, bool update = true );
69   void    setYGrid( bool yMajorEnabled, const int yMajorMax,
70                     bool yMinorEnabled, const int yMinorMax,
71                     bool y2MajorEnabled, const int y2MajorMax,
72                     bool y2MinorEnabled, const int y2MinorMax, bool update = true );
73   void    setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
74   QString getTitle( ObjectType type ) const;
75
76   void    setFont( const QFont& font, ObjectType type, bool update = true );
77   void    setHorScaleMode( const int mode, bool update = true );
78   int     getHorScaleMode() const { return myXMode; }
79   void    setVerScaleMode( const int mode, bool update = true );
80   int     getVerScaleMode() const { return myYMode; }
81
82   bool    isModeHorLinear();
83   bool    isModeVerLinear();
84   bool    isLegendShow() { return myShowLegend; };
85
86 protected:
87   int     testOperation( const QMouseEvent& );
88   void    readPreferences();
89   void    writePreferences();
90   QString getInfo( const QPoint& pnt );
91   virtual void wheelEvent( QWheelEvent* );
92
93 public slots:
94   void    onViewPan(); 
95   void    onViewZoom();
96   void    onViewFitAll();
97   void    onViewFitArea();
98   void    onViewGlobalPan(); 
99   void    onSettings();
100   void    onFitData();
101   void    onChangeBackground();
102
103 protected slots:
104   void    plotMousePressed( const QMouseEvent& );
105   void    plotMouseMoved( const QMouseEvent& );
106   void    plotMouseReleased( const QMouseEvent& );
107
108 signals:
109   void    vpModeHorChanged();
110   void    vpModeVerChanged();
111   void    vpCurveChanged();
112   void    contextMenuRequested( QContextMenuEvent *e );
113
114 protected:
115   Plot2d_Plot2d* myPlot;
116   int            myOperation;
117   QPoint         myPnt;
118   CurveDict      myCurves;
119
120   int            myCurveType;
121   bool           myShowLegend;
122   int            myLegendPos;
123   int            myMarkerSize;
124   QColor         myBackground;
125   QString        myTitle, myXTitle, myYTitle, myY2Title;
126   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
127   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
128   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
129   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
130   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
131   int            myXMode, myYMode;
132   double         myXDistance, myYDistance, myYDistance2;
133   bool           mySecondY;
134 };
135
136 class Plot2d_Plot2d : public QwtPlot 
137 {
138 public:
139   Plot2d_Plot2d( QWidget* parent );
140
141   void       replot();
142   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
143   QwtLegend* getLegend() {
144 #if QWT_VERSION < 0x040200
145      return d_legend;
146 #else  
147      return legend(); /* mpv: porting to the Qwt 4.2.0 */
148 #endif
149   }
150   virtual QSize       sizeHint() const;
151   virtual QSizePolicy sizePolicy() const;
152   virtual QSize       minimumSizeHint() const;
153
154 protected:
155   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
156
157 protected:
158   QValueList<QColor> myColors;
159 };
160
161 #endif