moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kmplot / kmplot / View.h
blobc0ae4aeb3d30a8e205e2e18493a45f41b9e4d334
1 /*
2 * KmPlot - a math. function plotter for the KDE-Desktop
4 * Copyright (C) 1998, 1999 Klaus-Dieter Möller
5 * 2000, 2002 kd.moeller@t-online.de
6 *
7 * This file is part of the KDE Project.
8 * KmPlot is part of the KDE-EDU Project.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #ifndef View_included
27 #define View_included
28 #undef GrayScale
30 // Qt includes
31 #include <qpixmap.h>
33 // KDE includes
34 #include <dcopclient.h>
35 #include <kactionclasses.h>
36 #include <kdebug.h>
37 #include <kpopupmenu.h>
38 #include <kprinter.h>
39 #include <kprogress.h>
40 #include <kpushbutton.h>
43 // local includes
44 #include "diagr.h"
45 #include "Viewiface.h"
46 #include "xparser.h"
48 class XParser;
49 class KMinMax;
50 class KSliderWindow;
52 /**
53 * @short This class contains the plots.
55 * It is the central widget of MainDlg.
56 * @see MainDlg, MainDlg::view
58 class View : public QWidget, virtual public ViewIface
60 Q_OBJECT
61 public:
62 /// Contructor sets up the parser, too.
63 View(bool, bool &, KPopupMenu *, QWidget* parent=NULL, const char* name=NULL );
64 void setMinMaxDlg(KMinMax *);
65 virtual ~View();
67 /// Reimplemented to draw all stuff to the view.
68 void draw(QPaintDevice *, int const);
69 /// Getting all relevant settings using KConfig XT class Settings.
70 void getSettings();
71 /// Clears all functions in the parser and gets default settings.
72 /// @see getSettings
73 void init();
74 /// Finding the minimum or maximum value
75 void findMinMaxValue(Ufkt *, char, bool, double &, double &,const QString &);
76 /// get a y-value from a x-value
77 void getYValue(Ufkt * , char, double , double &,const QString &);
78 /// draw and calculate the area between the graph and the x-axis.
79 void areaUnderGraph(Ufkt *, char const, double &, double &, const QString &, QPainter* );
80 /// the calculation was cancelled by the user
81 bool isCalculationStopped();
83 /// Returns a pointer to the private parser instance m_parser.
84 /// @see m_parser
85 XParser* parser();
87 /** Current plot range endge. */
88 static double xmin;
89 static double xmax;
91 /// trace mode stuff, must be accessible in KMinMax
92 int csmode, csparam;
93 char cstype;
95 /// for areadrawing when printing
96 bool areaDraw;
97 Ufkt * areaUfkt;
98 char areaPMode;
99 double areaMin, areaMax;
100 QString areaParameter;
102 /// Slider controlling parameter values
103 KSliderWindow* sliders[ SLIDER_COUNT ];
104 /// Menu actions for the sliders
105 KToggleAction *mnuSliders[ SLIDER_COUNT ];
106 void updateSliders(); /// show only needed sliders
108 public slots:
109 /// Called when the user want to cancel the drawing
110 void stopDrawing();
111 /// A slider window has been closed
112 void sliderWindowClosed(int);
114 /// Called when the graph should be updated
115 void drawPlot();
116 ///Slots for the three first items in popup menu
117 void mnuCopy_clicked();
118 void mnuMove_clicked();
119 void mnuHide_clicked();
120 void mnuRemove_clicked();
121 void mnuEdit_clicked();
122 ///Slots for the zoom menu
123 void mnuNoZoom_clicked();
124 void mnuRectangular_clicked();
125 void mnuZoomIn_clicked();
126 void mnuZoomOut_clicked();
127 void mnuCenter_clicked();
128 void mnuTrig_clicked();
130 protected slots:
131 void paintEvent(QPaintEvent *);
132 void resizeEvent(QResizeEvent *);
133 /// Updating the cross hair.
134 void mouseMoveEvent(QMouseEvent *);
135 /// Toggles the trace mode if the cursor is near to a plot.
136 void mousePressEvent(QMouseEvent *);
137 /// when a key is pressed and the graph widget has focus
138 void keyPressEvent(QKeyEvent * );
139 /// called when a mouse key is released
140 void mouseReleaseEvent ( QMouseEvent * e );
141 /// Is needed to be reimplement so that the user can stop a preview-drawing
142 bool event( QEvent * e );
144 signals:
145 void setStatusBarText(const QString &);
147 private:
148 /// Print out table with additional information.
149 /// Only for printing.
150 void drawHeaderTable(QPainter *);
151 /// Draw the function plots.
152 void plotfkt(Ufkt *ufkt, QPainter*);
153 /// Gets the greek pi symbol.
154 void setpi(QString *);
155 /// in trace mode checks, if the function is (near by) zero
156 bool root(double *, Ufkt *);
157 ///return the inverted color
158 void invertColor(QColor &, QColor &);
159 /// Restore the mouse cursor when a drawing is finished
160 void restoreCursor();
161 /// Changes the text in the statusbar
162 void setStatusBar(const QString &text, const int id);
163 /// Functions for the progressbar
164 bool stopProgressBar();
165 void startProgressBar(int);
166 void increaseProgressBar();
168 /// The central parser instance.
169 /// @see parser()
170 XParser *m_parser;
172 int w, h;
173 float s;
175 /// @name Crosshair
176 /// Crosshair support.
177 //@{
178 int fcx; ///< x-position of the crosshais (pixel)
179 int fcy; ///< y-position of the crosshais (pixel)
180 float csxpos; ///< y-position of the cross hair (real coordinates)
181 float csypos; ///< x-position of the cross hair (real coordinates)
182 //@}
183 /// trace mode stuff
184 int csflg;
185 bool rootflg;
187 CDiagr dgr; ///< Coordinate system
188 QPoint ref;
189 QRect area,
190 PlotArea;
191 QPixmap hline,
192 vline;
193 QWMatrix wm;
195 double tlgx, tlgy, drskalx, drskaly;
196 QString tlgxstr, tlgystr, drskalxstr, drskalystr;
197 double stepWidth; ///< Absolute step width
199 /** @name Plotrange
200 * There are 4 predefined plot ranges:
201 * @li 0: -8..8
202 * @li 1: -5..5
203 * @li 2: 0..16
204 * @li 3: 0..10
205 * @li 4: custom
207 //@{
208 ///Convert axes range predefinition index to boundaries.
209 void getMinMax(int koord, QString &mini, QString &maxi);
210 /** Handle predefiend axes ranges.
212 * @p koord can have the values 0 to 4 which have the following meanings:
214 * In the last case @p minstr and @p maxstr are evaluated.
216 void coordToMinMax( const int koord, const QString &minStr, const QString &maxStr,
217 double &min, double &max );
218 /// Sets the plot range from Settings
219 void setPlotRange();
220 //@{
221 /** Current plot range endge. */
222 double ymin;
223 double ymax;
224 //@}
225 //@}
227 void setScaling();
228 /// represents the KPrinter option app-kmplot-printtable.
229 /// @see KPrinterDlg
230 bool m_printHeaderTable;
231 /// if stop_calculating is true, the user has canceled drawing of an integral graph
232 bool stop_calculating;
233 /// the background color of the graph
234 QColor backgroundcolor;
235 /// the inverted background color used by the "Fadenkreuz"
236 QColor inverted_backgroundcolor;
237 /// pointer to KMinMax
238 KMinMax *m_minmax;
239 ///buffer the current window so all functions don't need to be re-drawed
240 QPixmap buffer;
241 /// the popup menu
242 KPopupMenu *m_popupmenu;
243 /// is set to true if an integral is calculated
244 bool isDrawing;
245 ///status of the popup menu
246 char m_popupmenushown; /// 0==no popup 1==popup 2==popup+trace mode before
247 /// for zoom-mode
248 QPoint rectangle_point;
249 char zoom_mode; ///0=normal 1=rectangular zoom, 2=zoom in, 3=zoom out ,4=drawing a rectangle, 5=center
250 /// true == modifications not saved
251 bool &m_modified;
252 /// False if KmPlot is started as a program, otherwise true
253 bool const m_readonly;
255 DCOPClient *m_dcop_client;
256 QString m_statusbartext1;
257 QString m_statusbartext2;
258 QString m_statusbartext3;
259 QString m_statusbartext4;
262 #endif // View_included