summaryrefslogtreecommitdiffstats
path: root/kmplot/kmplot/diagr.h
blob: 45cae5a69369f353b1695eda20c73937992335f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999  Klaus-Dieter M�ler
*               2000, 2002 kd.moeller@t-online.de
*               
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*
*/
/** @file diagr.h 
 * @brief Contains the CDiagr class. */

#ifndef diagr_included
#define diagr_included

// standard includes
#include <math.h>
#include <stdio.h>

// Qt includes 
#include <qpainter.h>

//@{
/// Some abbreviations for horizontal and vertical lines.
#define Line drawLine
#define Lineh(x1, y, x2) drawLine(x1, y, x2, y)
#define Linev(x, y1, y2) drawLine(x, y1, x, y2) 
//@}

//@{
/// Grid styles.
#define GRID_NONE	0
#define	GRID_LINES	1
#define	GRID_CROSSES	2
#define	GRID_POLAR	3
//@}

/** @short This class manages the core drawing of the axes and the grid. */
class CDiagr
{
public:
	/// Contructor. Members are set to initial values.
	///@see Create()
	CDiagr();
	/// Nothing to do for the destructor.
	~CDiagr();

	/// Sets all members to current values.
	void Create( QPoint Ref,
	               int lx, int ly,
	               double xmin, double xmax,
	               double ymin, double ymax );
	/// Sets the current values for the scaling factors
	void Skal( double ex, double ey );
	/// Draws all requested parts of the diagram (axes, labels, grid e.g.)
	void Plot( QPainter* pDC );
	/// Returns the rectangle around the core of the plot area.
	QRect GetPlotArea() { return PlotArea; }
	/// Returns the rectangle for the frame around the plot. Extra frame is bigger.
	QRect GetFrame() { return m_frame; }

	/** @name Transformations */
	//@{
	/// These functions convert real coordinates to pixel coordinates and vice versa.
	int Transx(double);
	int Transy(double);
	double Transx(int);
	double Transy(int);
	//@}
	
	/** @name Style options
	 * These members hold the current options for line widths and colors
	 */
	//@{
	QRgb frameColor;	///< color of the border frame
	QRgb axesColor;		///< color of the axes
	QRgb gridColor;		///< color of the grid

	uint borderThickness,	///< current line width for the border frame
	     axesLineWidth,	///< current line width for the axes
	     gridLineWidth,	///< current line width for the grid
	     ticWidth,		///< current line width for the tics
	     ticLength,		///< current length of the tic lines
	//@}
	     xclipflg,		///< clipflg is set to 1 if the plot is out of the plot aerea.
	     yclipflg;		///< clipflg is set to 1 if the plot is out of the plot aerea.

         
private:

	/// Draw the coordinate axes.
	void drawAxes(QPainter*);
	/// Draw the grid.
	void drawGrid( QPainter* );
	/// Write labels.
	void drawLabels(QPainter*);
	/// Current grid style.
	int g_mode;

	//@{
	/// Plot range edge.
	double xmin, xmax, ymin, ymax;
	//@}
	//@{
	/// Clip boundage.
	double xmd, ymd;
	//@}
	//@{
	/// Axes tic distance.
	double ex, ey;  
	//@}
	//@{
	///Position of the first tic.      
	double tsx, tsy;
	//@}
	//@{
	/// Screen coordinates of the coordinate system origin.
	double ox, oy;
	//@}
	//@{
	/// Transformation factors.
	/// @see Skal
	double skx, sky;
	//@}
	
	QRect PlotArea;	///< plot area
	QRect m_frame;	///< frame around the plot
};

#endif // diagr_included