-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotwidget.h
215 lines (177 loc) · 7.74 KB
/
plotwidget.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/***************************************************************************
* Copyright (C) 2003-2007 by Oliver Saal *
* http://www.oliver-saal.de/software/afutrainer/ *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#pragma once
#include <qframe.h>
#include <qpoint.h>
#include <qrect.h>
#include <qpen.h>
#include <qbrush.h>
#include <qmap.h>
#include <qfont.h>
class CPlotWidgetPoint;
class CPlotWidgetCurve;
class CPlotWidgetTic;
class CPlotWidget;
class CPlotWidgetPoint : public QPointF
{
public:
CPlotWidgetPoint() { clear(); }
CPlotWidgetPoint(const double x, const double y) : QPointF(x,y) {}
~CPlotWidgetPoint() {}
void clear();
protected:
};
class CPlotWidgetCurve : public QList<CPlotWidgetPoint>
{
public:
CPlotWidgetCurve() { clear(); }
~CPlotWidgetCurve() {}
void clear();
QRectF boundaries() const;
inline void setPen(const QPen& pen) { m_pen = pen; }
inline QPen pen() const { return m_pen; }
inline void setBrush(const QBrush& brush) { m_brush = brush; }
inline QBrush brush() const { return m_brush; }
protected:
QPen m_pen;
QBrush m_brush;
};
class CPlotWidgetTic
{
public:
enum LineType { LineNone, LineShort, LinePlot, LineFull };
enum FillType { FillNone, FillPlot, FillAll };
CPlotWidgetTic() { clear(); }
CPlotWidgetTic(const double dPos, const QString& strText);
CPlotWidgetTic(const double dPos, const double dWidth, const QString& strText);
CPlotWidgetTic(const double dPos, const QPixmap& pixmap);
~CPlotWidgetTic() {}
void clear();
inline void setPen(const QPen& pen) { m_pen = pen; }
inline QPen pen() const { return m_pen; }
inline void setBrush(const QBrush& brush) { m_brush = brush; }
inline QBrush brush() const { return m_brush; }
inline void setFont(const QFont& font) { m_font = font; }
inline QFont font() const { return m_font; }
inline void setFontPen(const QPen& pen) { m_penFont = pen; }
inline QPen fontPen() const { return m_penFont; }
inline void setPos(const double dPos) { m_dPos = dPos; }
inline double pos() const { return m_dPos; }
inline void setWidth(const double dWidth) { m_dWidth = dWidth; }
inline double width() const { return m_dWidth; }
inline void setFillType(const FillType t) { m_fillType = t; }
inline FillType fillType () const { return m_fillType; }
inline void setLineType(const LineType t) { m_lineType = t; }
inline LineType lineType () const { return m_lineType; }
inline void setText(const QString& str) { m_strText = str; }
inline QString text() const { return m_strText; }
inline void setTextFlags (const int iFlags) { m_iTextFlags = iFlags; }
inline int textFlags() const { return m_iTextFlags; }
void paintX (QPainter *pPainter, CPlotWidget *pWidget) const;
void paintY (QPainter *pPainter, CPlotWidget *pWidget) const;
protected:
double m_dPos;
// Beschriftung
QPixmap m_pixmap;
QString m_strText;
QFont m_font;
QPen m_penFont;
int m_iTextFlags;
// Line
QPen m_pen;
LineType m_lineType;
// Background
double m_dWidth;
QBrush m_brush;
FillType m_fillType;
};
class CPlotWidget : public QFrame
{
Q_OBJECT
public:
enum PlotType { PlotPoints, PlotLines, PlotBarsSum, PlotBars };
enum Border { BorderTop=0x01, BorderBottom=0x02, BorderLeft=0x04, BorderRight=0x08 };
CPlotWidget(QWidget *pParent=0);
~CPlotWidget() {}
void clear();
inline void clearCurves() { m_listCurves.clear(); }
inline void appendCurve (const CPlotWidgetCurve& c) { m_listCurves.append(c); }
QRect plotArea() const;
QRectF rectData() const;
inline void setType (const PlotType t) { m_type = t; }
inline PlotType type() const { return m_type; }
inline void setLimitX(const double min, const double max) { m_dLimitXMin = min; m_dLimitXMax = max; m_bLimitAutoX = false; }
inline void setLimitY(const double min, const double max) { m_dLimitYMin = min; m_dLimitYMax = max; m_bLimitAutoY = false; }
inline void setAutoLimitX(const bool bAutoLimit) { m_bLimitAutoX = bAutoLimit; }
inline void setAutoLimitY(const bool bAutoLimit) { m_bLimitAutoY = bAutoLimit; }
inline void setAutoLimitRoundX(const double dRound) { m_dLimitXRound = dRound; }
inline void setAutoLimitRoundY(const double dRound) { m_dLimitYRound = dRound; }
inline void setLabelX(const QString& str) { m_strLabelX = str; }
inline void setLabelY(const QString& str) { m_strLabelY = str; }
inline void setPlotBackground (const QBrush& brush) { m_brushPlotBkg = brush; }
inline void setBorderPen(const QPen& pen) { m_penBorder = pen; }
inline QPen borderPen() const { return m_penBorder; }
inline void setBorder(const int iBorder=BorderLeft|BorderBottom) { m_iBorder = iBorder; }
inline int border() const { return m_iBorder; }
void setBorderDistance(const int iLeft, const int iRight, const int iTop, const int iBottom);
inline void setTicX(const double dTic) { m_dTicX = dTic; }
inline void setTicY(const double dTic) { m_dTicY = dTic; }
inline void setTicXPen(const QPen& pen) { m_penTicX = pen; }
inline void setTicYPen(const QPen& pen) { m_penTicY = pen; }
inline void setTicListX (const QList<CPlotWidgetTic>& list) { m_listTicX = list; }
inline void setTicListY (const QList<CPlotWidgetTic>& list) { m_listTicY = list; }
inline void setBarWidth(const double d) { m_dBarWidth = d; }
inline void setBarOffset(const double d) { m_dBarOffset = d; }
protected:
virtual void paintEvent (QPaintEvent *e);
void updateCache();
QPoint mapToPlot (QPointF p);
friend class CPlotWidgetTic;
protected:
PlotType m_type;
QList<CPlotWidgetCurve> m_listCurves;
double m_dLimitXMin, m_dLimitXMax, m_dLimitYMin, m_dLimitYMax;
double m_dLimitXRound, m_dLimitYRound;
bool m_bLimitAutoX, m_bLimitAutoY;
// Border
QBrush m_brushPlotBkg;
QPen m_penBorder;
int m_iBorder; //!< Logische Verknüpfung aus BorderTop, BorderBottom, BorderLeft, BorderRight
int m_iBorderDistTop;
int m_iBorderDistBottom;
int m_iBorderDistLeft;
int m_iBorderDistRight;
// Tics & Labels
QList<CPlotWidgetTic> m_listTicX;
QList<CPlotWidgetTic> m_listTicY;
double m_dTicX;
QPen m_penTicX;
double m_dTicY;
QPen m_penTicY;
QString m_strLabelX;
QString m_strLabelY;
// Bars
double m_dBarWidth;
double m_dBarOffset;
// Cache
QRect m_rectPlot;
QRectF m_rectData;
};