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
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.
34 #include <dcopclient.h>
35 #include <kactionclasses.h>
37 #include <kpopupmenu.h>
39 #include <kprogress.h>
40 #include <kpushbutton.h>
45 #include "Viewiface.h"
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
62 /// Contructor sets up the parser, too.
63 View(bool, bool &, KPopupMenu
*, QWidget
* parent
=NULL
, const char* name
=NULL
);
64 void setMinMaxDlg(KMinMax
*);
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.
71 /// Clears all functions in the parser and gets default settings.
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.
87 /** Current plot range endge. */
91 /// trace mode stuff, must be accessible in KMinMax
95 /// for areadrawing when printing
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
109 /// Called when the user want to cancel the drawing
111 /// A slider window has been closed
112 void sliderWindowClosed(int);
114 /// Called when the graph should be updated
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();
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
);
145 void setStatusBarText(const QString
&);
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.
176 /// Crosshair support.
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)
187 CDiagr dgr
; ///< Coordinate system
195 double tlgx
, tlgy
, drskalx
, drskaly
;
196 QString tlgxstr
, tlgystr
, drskalxstr
, drskalystr
;
197 double stepWidth
; ///< Absolute step width
200 * There are 4 predefined plot ranges:
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
221 /** Current plot range endge. */
228 /// represents the KPrinter option app-kmplot-printtable.
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
239 ///buffer the current window so all functions don't need to be re-drawed
242 KPopupMenu
*m_popupmenu
;
243 /// is set to true if an integral is calculated
245 ///status of the popup menu
246 char m_popupmenushown
; /// 0==no popup 1==popup 2==popup+trace mode before
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
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